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