1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // __________ Imports __________ 25 26 import com.sun.star.uno.UnoRuntime; 27 28 import java.awt.*; 29 import javax.swing.*; 30 import java.lang.String; 31 32 // __________ Implementation __________ 33 34 /** 35 * Implement a view to show status informations 36 * of currently loaded document of a document view. 37 * It use seperate listener threads to get this informations 38 * and actualize it automaticly if frame broadcast changes of 39 * his contained document. 40 * Threads are neccessary to prevent this view against deadlocks. 41 * These deadlocks can occure if a listener will be notified 42 * by the office in an "oneway" method and try to call back 43 * to the office by using a synchronous method. 44 * UNO must guarantee order of all these calls ... and if 45 * the source of arrived event holds a mutex and our synchronous 46 * call needs this mutex too => a deadlock occure. 47 * Why? UNO had created a new thread for our synchronous call 48 * inside the office process and so exist different threads 49 * for this constallation. 50 * 51 * @author Andreas Schlüns 52 * @created 20.06.2002 15:08 53 */ 54 public class StatusView extends JPanel 55 implements IShutdownListener 56 { 57 // ____________________ 58 59 /** 60 * const 61 * These URL's describe available feature states. 62 */ 63 public static final String FEATUREURL_FONT = "slot:10007"; 64 public static final String FEATUREURL_SIZE = "slot:10015"; 65 public static final String FEATUREURL_BOLD = "slot:10009"; 66 public static final String FEATUREURL_ITALIC = "slot:10008"; 67 public static final String FEATUREURL_UNDERLINE = "slot:10014"; 68 69 // ____________________ 70 71 /** 72 * const 73 * These values are used to show current state of showed feature. 74 */ 75 public static final String FONT_OFF = "unknown" ; 76 public static final String SIZE_OFF = "0.0" ; 77 public static final String BOLD_OFF = "-" ; 78 public static final String ITALIC_OFF = "-" ; 79 public static final String UNDERLINE_OFF = "-" ; 80 81 public static final String FONT_ON = "" ; 82 public static final String SIZE_ON = "" ; 83 public static final String BOLD_ON = "X" ; 84 public static final String ITALIC_ON = "X" ; 85 public static final String UNDERLINE_ON = "X" ; 86 87 // ____________________ 88 89 /** 90 * @member mlaFontValue shows status of font name 91 * @member mlaSizeValue shows status of font size 92 * @member mlaBoldValue shows status of font style bold 93 * @member mlaUnderlineValue shows status of font style underline 94 * @member mlaItalicValue shows status of font style italic 95 * 96 * @member maFontListener threadsafe(!) helper to listen for status event which describe font name 97 * @member maSizeListener threadsafe(!) helper to listen for status event which describe font size 98 * @member maBoldListener threadsafe(!) helper to listen for status event which describe font style bold 99 * @member maUnderlineListener threadsafe(!) helper to listen for status event which describe font style underline 100 * @member maItalicListener threadsafe(!) helper to listen for status event which describe font style italic 101 */ 102 private JLabel m_laFontValue ; 103 private JLabel m_laSizeValue ; 104 private JLabel m_laBoldValue ; 105 private JLabel m_laUnderlineValue ; 106 private JLabel m_laItalicValue ; 107 108 private StatusListener m_aFontListener ; 109 private StatusListener m_aSizeListener ; 110 private StatusListener m_aBoldListener ; 111 private StatusListener m_aUnderlineListener ; 112 private StatusListener m_aItalicListener ; 113 114 // ____________________ 115 116 /** 117 * ctor 118 * Create view controls on startup and initialize it with default values. 119 * Filling of view items can be done by special set-methods. 120 * We don't start listening here! see setFrame() for that ... 121 */ StatusView()122 StatusView() 123 { 124 this.setLayout(new GridBagLayout()); 125 126 GridBagConstraints aConstraint = new GridBagConstraints(); 127 aConstraint.anchor = GridBagConstraints.NORTHWEST; 128 aConstraint.insets = new Insets(2,2,2,2); 129 aConstraint.gridy = 0; 130 aConstraint.gridx = 0; 131 132 JLabel laFont = new JLabel("Font" ); 133 JLabel laSize = new JLabel("Size" ); 134 JLabel laBold = new JLabel("Bold" ); 135 JLabel laUnderline = new JLabel("Underline"); 136 JLabel laItalic = new JLabel("Italic" ); 137 138 m_laFontValue = new JLabel(); 139 m_laSizeValue = new JLabel(); 140 m_laBoldValue = new JLabel(); 141 m_laUnderlineValue = new JLabel(); 142 m_laItalicValue = new JLabel(); 143 144 aConstraint.gridx = 0; 145 this.add( laFont, aConstraint ); 146 aConstraint.gridx = 1; 147 this.add( m_laFontValue, aConstraint ); 148 149 ++aConstraint.gridy; 150 151 aConstraint.gridx = 0; 152 this.add( laSize, aConstraint ); 153 aConstraint.gridx = 1; 154 this.add( m_laSizeValue, aConstraint ); 155 156 ++aConstraint.gridy; 157 158 aConstraint.gridx = 0; 159 this.add( laSize, aConstraint ); 160 aConstraint.gridx = 1; 161 this.add( m_laSizeValue, aConstraint ); 162 163 ++aConstraint.gridy; 164 165 aConstraint.gridx = 0; 166 this.add( laBold, aConstraint ); 167 aConstraint.gridx = 1; 168 this.add( m_laBoldValue, aConstraint ); 169 170 ++aConstraint.gridy; 171 172 aConstraint.gridx = 0; 173 this.add( laUnderline, aConstraint ); 174 aConstraint.gridx = 1; 175 this.add( m_laUnderlineValue, aConstraint ); 176 177 ++aConstraint.gridy; 178 179 aConstraint.gridx = 0; 180 this.add( laItalic, aConstraint ); 181 aConstraint.gridx = 1; 182 this.add( m_laItalicValue, aConstraint ); 183 184 m_laFontValue.setEnabled (false); 185 m_laSizeValue.setEnabled (false); 186 m_laBoldValue.setEnabled (false); 187 m_laItalicValue.setEnabled (false); 188 m_laUnderlineValue.setEnabled(false); 189 190 m_laFontValue.setText (FONT_OFF ); 191 m_laSizeValue.setText (SIZE_OFF ); 192 m_laBoldValue.setText (BOLD_OFF ); 193 m_laItalicValue.setText (ITALIC_OFF ); 194 m_laUnderlineValue.setText(UNDERLINE_OFF); 195 } 196 197 // ____________________ 198 199 /** 200 * Set new frame for this view and start listening for events imedatly. 201 * We create one status listener for every control we whish to update. 202 * And because the environment of the frame can be changed - these 203 * listener refresh himself internaly for frame action events too. 204 * So we register it as such frame action listener only here. 205 * Rest is done automaticly ... 206 * 207 * @param xFrame 208 * will be used as source of possible status events 209 */ setFrame(com.sun.star.frame.XFrame xFrame)210 public void setFrame(com.sun.star.frame.XFrame xFrame) 211 { 212 if (xFrame==null) 213 return; 214 215 // create some listener on given frame for available status events 216 // Created listener instances will register herself on this frame and 217 // show her received informations automaticly on setted UI controls. 218 m_aFontListener = new StatusListener(m_laFontValue ,FONT_ON ,FONT_OFF ,xFrame, FEATUREURL_FONT ); 219 m_aSizeListener = new StatusListener(m_laSizeValue ,SIZE_ON ,SIZE_OFF ,xFrame, FEATUREURL_SIZE ); 220 m_aBoldListener = new StatusListener(m_laBoldValue ,BOLD_ON ,BOLD_OFF ,xFrame, FEATUREURL_BOLD ); 221 m_aItalicListener = new StatusListener(m_laItalicValue ,ITALIC_ON ,ITALIC_OFF ,xFrame, FEATUREURL_ITALIC ); 222 m_aUnderlineListener = new StatusListener(m_laUnderlineValue,UNDERLINE_ON,UNDERLINE_OFF,xFrame, FEATUREURL_UNDERLINE); 223 224 m_aFontListener.startListening(); 225 m_aSizeListener.startListening(); 226 m_aBoldListener.startListening(); 227 m_aItalicListener.startListening(); 228 m_aUnderlineListener.startListening(); 229 } 230 231 // ____________________ 232 233 /** 234 * If this java application shutdown - we must cancel all current existing 235 * listener connections. Otherwhise the office will run into some 236 * DisposedExceptions if it tries to use these forgotten listener references. 237 * And of course it can die doing that. 238 * We are registered at a central object to be informed if the VM will exit. 239 * So we can react. 240 */ shutdown()241 public void shutdown() 242 { 243 m_aFontListener.shutdown(); 244 m_aSizeListener.shutdown(); 245 m_aBoldListener.shutdown(); 246 m_aItalicListener.shutdown(); 247 m_aUnderlineListener.shutdown(); 248 249 m_aFontListener = null; 250 m_aSizeListener = null; 251 m_aBoldListener = null; 252 m_aItalicListener = null; 253 m_aUnderlineListener = null; 254 } 255 } 256