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