Update ooo320-m1
[ooovba.git] / odk / examples / DevelopersGuide / OfficeDev / DesktopEnvironment / StatusView.java
bloba0a9798dc6cc0fc75f79111fcb55f665e430a3fe
1 /*************************************************************************
3 * $RCSfile: StatusView.java,v $
5 * $Revision: 1.4 $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:40:19 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 // __________ Imports __________
43 import com.sun.star.uno.UnoRuntime;
45 import java.awt.*;
46 import javax.swing.*;
47 import java.lang.String;
49 // __________ Implementation __________
51 /**
52 * Implement a view to show status informations
53 * of currently loaded document of a document view.
54 * It use seperate listener threads to get this informations
55 * and actualize it automaticly if frame broadcast changes of
56 * his contained document.
57 * Threads are neccessary to prevent this view against deadlocks.
58 * These deadlocks can occure if a listener will be notified
59 * by the office in an "oneway" method and try to call back
60 * to the office by using a synchronous method.
61 * UNO must guarantee order of all these calls ... and if
62 * the source of arrived event holds a mutex and our synchronous
63 * call needs this mutex too => a deadlock occure.
64 * Why? UNO had created a new thread for our synchronous call
65 * inside the office process and so exist different threads
66 * for this constallation.
68 * @author Andreas Schlüns
69 * @created 20.06.2002 15:08
71 public class StatusView extends JPanel
72 implements IShutdownListener
74 // ____________________
76 /**
77 * const
78 * These URL's describe available feature states.
80 public static final String FEATUREURL_FONT = "slot:10007";
81 public static final String FEATUREURL_SIZE = "slot:10015";
82 public static final String FEATUREURL_BOLD = "slot:10009";
83 public static final String FEATUREURL_ITALIC = "slot:10008";
84 public static final String FEATUREURL_UNDERLINE = "slot:10014";
86 // ____________________
88 /**
89 * const
90 * These values are used to show current state of showed feature.
92 public static final String FONT_OFF = "unknown" ;
93 public static final String SIZE_OFF = "0.0" ;
94 public static final String BOLD_OFF = "-" ;
95 public static final String ITALIC_OFF = "-" ;
96 public static final String UNDERLINE_OFF = "-" ;
98 public static final String FONT_ON = "" ;
99 public static final String SIZE_ON = "" ;
100 public static final String BOLD_ON = "X" ;
101 public static final String ITALIC_ON = "X" ;
102 public static final String UNDERLINE_ON = "X" ;
104 // ____________________
107 * @member mlaFontValue shows status of font name
108 * @member mlaSizeValue shows status of font size
109 * @member mlaBoldValue shows status of font style bold
110 * @member mlaUnderlineValue shows status of font style underline
111 * @member mlaItalicValue shows status of font style italic
113 * @member maFontListener threadsafe(!) helper to listen for status event which describe font name
114 * @member maSizeListener threadsafe(!) helper to listen for status event which describe font size
115 * @member maBoldListener threadsafe(!) helper to listen for status event which describe font style bold
116 * @member maUnderlineListener threadsafe(!) helper to listen for status event which describe font style underline
117 * @member maItalicListener threadsafe(!) helper to listen for status event which describe font style italic
119 private JLabel m_laFontValue ;
120 private JLabel m_laSizeValue ;
121 private JLabel m_laBoldValue ;
122 private JLabel m_laUnderlineValue ;
123 private JLabel m_laItalicValue ;
125 private StatusListener m_aFontListener ;
126 private StatusListener m_aSizeListener ;
127 private StatusListener m_aBoldListener ;
128 private StatusListener m_aUnderlineListener ;
129 private StatusListener m_aItalicListener ;
131 // ____________________
134 * ctor
135 * Create view controls on startup and initialize it with default values.
136 * Filling of view items can be done by special set-methods.
137 * We don't start listening here! see setFrame() for that ...
139 StatusView()
141 this.setLayout(new GridBagLayout());
143 GridBagConstraints aConstraint = new GridBagConstraints();
144 aConstraint.anchor = GridBagConstraints.NORTHWEST;
145 aConstraint.insets = new Insets(2,2,2,2);
146 aConstraint.gridy = 0;
147 aConstraint.gridx = 0;
149 JLabel laFont = new JLabel("Font" );
150 JLabel laSize = new JLabel("Size" );
151 JLabel laBold = new JLabel("Bold" );
152 JLabel laUnderline = new JLabel("Underline");
153 JLabel laItalic = new JLabel("Italic" );
155 m_laFontValue = new JLabel();
156 m_laSizeValue = new JLabel();
157 m_laBoldValue = new JLabel();
158 m_laUnderlineValue = new JLabel();
159 m_laItalicValue = new JLabel();
161 aConstraint.gridx = 0;
162 this.add( laFont, aConstraint );
163 aConstraint.gridx = 1;
164 this.add( m_laFontValue, aConstraint );
166 ++aConstraint.gridy;
168 aConstraint.gridx = 0;
169 this.add( laSize, aConstraint );
170 aConstraint.gridx = 1;
171 this.add( m_laSizeValue, aConstraint );
173 ++aConstraint.gridy;
175 aConstraint.gridx = 0;
176 this.add( laSize, aConstraint );
177 aConstraint.gridx = 1;
178 this.add( m_laSizeValue, aConstraint );
180 ++aConstraint.gridy;
182 aConstraint.gridx = 0;
183 this.add( laBold, aConstraint );
184 aConstraint.gridx = 1;
185 this.add( m_laBoldValue, aConstraint );
187 ++aConstraint.gridy;
189 aConstraint.gridx = 0;
190 this.add( laUnderline, aConstraint );
191 aConstraint.gridx = 1;
192 this.add( m_laUnderlineValue, aConstraint );
194 ++aConstraint.gridy;
196 aConstraint.gridx = 0;
197 this.add( laItalic, aConstraint );
198 aConstraint.gridx = 1;
199 this.add( m_laItalicValue, aConstraint );
201 m_laFontValue.setEnabled (false);
202 m_laSizeValue.setEnabled (false);
203 m_laBoldValue.setEnabled (false);
204 m_laItalicValue.setEnabled (false);
205 m_laUnderlineValue.setEnabled(false);
207 m_laFontValue.setText (FONT_OFF );
208 m_laSizeValue.setText (SIZE_OFF );
209 m_laBoldValue.setText (BOLD_OFF );
210 m_laItalicValue.setText (ITALIC_OFF );
211 m_laUnderlineValue.setText(UNDERLINE_OFF);
214 // ____________________
217 * Set new frame for this view and start listening for events imedatly.
218 * We create one status listener for every control we whish to update.
219 * And because the environment of the frame can be changed - these
220 * listener refresh himself internaly for frame action events too.
221 * So we register it as such frame action listener only here.
222 * Rest is done automaticly ...
224 * @param xFrame
225 * will be used as source of possible status events
227 public void setFrame(com.sun.star.frame.XFrame xFrame)
229 if (xFrame==null)
230 return;
232 // create some listener on given frame for available status events
233 // Created listener instances will register herself on this frame and
234 // show her received informations automaticly on setted UI controls.
235 m_aFontListener = new StatusListener(m_laFontValue ,FONT_ON ,FONT_OFF ,xFrame, FEATUREURL_FONT );
236 m_aSizeListener = new StatusListener(m_laSizeValue ,SIZE_ON ,SIZE_OFF ,xFrame, FEATUREURL_SIZE );
237 m_aBoldListener = new StatusListener(m_laBoldValue ,BOLD_ON ,BOLD_OFF ,xFrame, FEATUREURL_BOLD );
238 m_aItalicListener = new StatusListener(m_laItalicValue ,ITALIC_ON ,ITALIC_OFF ,xFrame, FEATUREURL_ITALIC );
239 m_aUnderlineListener = new StatusListener(m_laUnderlineValue,UNDERLINE_ON,UNDERLINE_OFF,xFrame, FEATUREURL_UNDERLINE);
241 m_aFontListener.startListening();
242 m_aSizeListener.startListening();
243 m_aBoldListener.startListening();
244 m_aItalicListener.startListening();
245 m_aUnderlineListener.startListening();
248 // ____________________
251 * If this java application shutdown - we must cancel all current existing
252 * listener connections. Otherwhise the office will run into some
253 * DisposedExceptions if it tries to use these forgotten listener references.
254 * And of course it can die doing that.
255 * We are registered at a central object to be informed if the VM will exit.
256 * So we can react.
258 public void shutdown()
260 m_aFontListener.shutdown();
261 m_aSizeListener.shutdown();
262 m_aBoldListener.shutdown();
263 m_aItalicListener.shutdown();
264 m_aUnderlineListener.shutdown();
266 m_aFontListener = null;
267 m_aSizeListener = null;
268 m_aBoldListener = null;
269 m_aItalicListener = null;
270 m_aUnderlineListener = null;