1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
/*************************************************************************
*
* $RCSfile: CustomizeView.java,v $
*
* $Revision: 1.3 $
*
* last change: $Author: hr $ $Date: 2003/06/30 15:33:34 $
*
* The Contents of this file are made available subject to the terms of
* the BSD license.
*
* Copyright (c) 2003 by Sun Microsystems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Sun Microsystems, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*************************************************************************/
package OfficeDev.samples.DesktopEnvironment;
// __________ Imports __________
// interfaces
import com.sun.star.frame.XStatusListener;
import com.sun.star.frame.XFrameActionListener;
// UI classes
import java.awt.*;
import javax.swing.*;
// events
import com.sun.star.frame.FrameActionEvent;
import com.sun.star.frame.FrameAction;
import com.sun.star.lang.EventObject;
// base classes/helper
import java.lang.String;
import java.awt.event.*;
import java.awt.*;
import com.sun.star.uno.UnoRuntime;
// __________ Implementation __________
/**
* Makes it possible to change some states of currently loaded
* document (e.g. enable/disable menubar, toolbar, objectbar)
*
* @author Andreas Schlüns
* @created 20.06.2002 09:28
*/
public class CustomizeView extends JPanel
implements IShutdownListener
{
// ____________________
// const
/**
* These const URL's describe feature for toggling some properties of loaded document.
* Dispatch it with the corresponding parameter to the frame.
*/
private static final String FEATUREURL_MENUBAR = "slot:6661" ;
private static final String FEATUREURL_TOOLBAR = "slot:5909" ;
private static final String FEATUREURL_OBJECTBAR = "slot:5905" ;
private static final String FEATUREPROP_MENUBAR = "MenuBarVisible" ;
private static final String FEATUREPROP_TOOLBAR = "ToolBarVisible" ;
private static final String FEATUREPROP_OBJECTBAR = "ObjectBarVisible" ;
private static final String ACTION_MENUBAR = "toogle_menu" ;
private static final String ACTION_TOOLBAR = "toogle_toolbar" ;
private static final String ACTION_OBJECTBAR = "toogle_objectbar" ;
private static final String MENUBAR_ON = "menubar on" ;
private static final String TOOLBAR_ON = "toolbar on" ;
private static final String OBJECTBAR_ON = "objectbar on" ;
private static final String MENUBAR_OFF = "menubar off" ;
private static final String TOOLBAR_OFF = "toolbar off" ;
private static final String OBJECTBAR_OFF = "objectbar off" ;
// ____________________
// member
/**
* @member m_cbMenuBar reference to checkbox for toggling menubar
* @member m_cbToolBar reference to checkbox for toggling toolbar
* @member m_cbObjectBar reference to checkbox for toggling objectbar
*
* @member m_aMenuBarListener listener for status events of the menu bar
* @member m_aToolBarListener listener for status events of the tool bar
* @member m_aObjectBarListener listener for status events of the object bar
*/
private JCheckBox m_cbMenuBar ;
private JCheckBox m_cbToolBar ;
private JCheckBox m_cbObjectBar ;
private StatusListener m_aMenuBarListener ;
private StatusListener m_aToolBarListener ;
private StatusListener m_aObjectBarListener;
// ____________________
/**
* ctor
* Create view controls on startup and initialize it.
* We don't start listening here. see setFrame()!
*/
CustomizeView()
{
this.setLayout(new GridLayout(3,0));
m_cbMenuBar = new JCheckBox(MENUBAR_OFF , false);
m_cbToolBar = new JCheckBox(TOOLBAR_OFF , false);
m_cbObjectBar = new JCheckBox(OBJECTBAR_OFF, false);
m_cbMenuBar.setEnabled (false);
m_cbToolBar.setEnabled (false);
m_cbObjectBar.setEnabled(false);
m_cbMenuBar.setActionCommand (ACTION_MENUBAR );
m_cbToolBar.setActionCommand (ACTION_TOOLBAR );
m_cbObjectBar.setActionCommand(ACTION_OBJECTBAR);
this.add(m_cbMenuBar );
this.add(m_cbToolBar );
this.add(m_cbObjectBar);
}
// ____________________
/**
* set new frame for this view
* We start listening for frame action/status and click events instandly.
* If an event occure we use it to synchronize our controls
* with states of a (my be) new document view of this frame.
*
* @param xFrame
* the reference to the frame, which provides the
* possibility to get the required status informations
*
* Attention: We don't accept new frames here.
* We get one after startup and work with him.
* That's it!
*/
public void setFrame(com.sun.star.frame.XFrame xFrame)
{
if (xFrame==null)
return;
// be listener for click events
// They will toogle the UI controls.
ClickListener aMenuBarHandler = new ClickListener(FEATUREURL_MENUBAR ,FEATUREPROP_MENUBAR ,xFrame);
ClickListener aToolBarHandler = new ClickListener(FEATUREURL_TOOLBAR ,FEATUREPROP_TOOLBAR ,xFrame);
ClickListener aObjectBarHandler = new ClickListener(FEATUREURL_OBJECTBAR,FEATUREPROP_OBJECTBAR,xFrame);
m_cbMenuBar.addActionListener (aMenuBarHandler );
m_cbToolBar.addActionListener (aToolBarHandler );
m_cbObjectBar.addActionListener(aObjectBarHandler);
// be frame action listener
// The callback will update listener connections
// for status updates automaticly!
m_aMenuBarListener = new StatusListener(m_cbMenuBar ,MENUBAR_ON ,MENUBAR_OFF ,xFrame, FEATUREURL_MENUBAR );
m_aToolBarListener = new StatusListener(m_cbToolBar ,TOOLBAR_ON ,TOOLBAR_OFF ,xFrame, FEATUREURL_TOOLBAR );
m_aObjectBarListener = new StatusListener(m_cbObjectBar,OBJECTBAR_ON,OBJECTBAR_OFF,xFrame, FEATUREURL_OBJECTBAR);
m_aMenuBarListener.startListening();
m_aToolBarListener.startListening();
m_aObjectBarListener.startListening();
}
// ____________________
/**
* react for click events of the used check boxes
* We use our internal set dispatch objects to
* call it. This calls toogle the menu/object- or toolbar.
* Note: Because we are listener status events too - hopefully
* we get a notification, if toogling was successfully or not.
* We use this information to update our check boxes again.
* But such update doesn't force (hopefully) an action event. Otherwhise
* we can produce a never ending recursion!
*
* @param aEvent
* describes the used check box and his current state
* we can use to dispatch the right URL to the office
*/
class ClickListener implements ActionListener,
com.sun.star.lang.XEventListener
{
/// URL, to toogle the requested UI item
String m_sURL;
/// name of the property which must be used in combination with the URL
String m_sProp;
/// we must use this frame to dispatch a request
com.sun.star.frame.XFrame m_xFrame;
//_____________________
/**
* ctor
* It initialize an instance of this clas only.
*/
ClickListener( String sURL ,
String sProp ,
com.sun.star.frame.XFrame xFrame )
{
m_sURL = sURL ;
m_sProp = sProp ;
m_xFrame = xFrame;
}
//_____________________
/**
* callback for action events
* Such events occure if somehwere click the
* JCheckBox control on which we are registered.
* Such events doesn't occure if we set it programmaticly
* (e.g. if we get status events to -> see class StatusListener too)
*
* @param aEvent
* describes the check box and his state
* we can use to toogle the requested office
* ressource.
*/
public void actionPerformed(ActionEvent aEvent)
{
synchronized(this)
{
if (m_xFrame==null)
return;
}
// define parameters for following dispatch
boolean bState = ((JCheckBox)aEvent.getSource()).isSelected();
// prepare the dispatch
com.sun.star.util.URL aURL = FunctionHelper.parseURL(m_sURL);
if (aURL==null)
return;
com.sun.star.beans.PropertyValue[] lProperties = new com.sun.star.beans.PropertyValue[1];
lProperties[0] = new com.sun.star.beans.PropertyValue();
lProperties[0].Name = m_sProp;
lProperties[0].Value = new Boolean(bState);
// execute (dispatch) it into the frame
if (m_xFrame==null)
return;
FunctionHelper.execute(m_xFrame,aURL,lProperties,null);
}
// ____________________
/**
* callback for disposing events
* Internaly we save a reference to an office frame.
* Of course he can die and inform us then. We should react
* and forget his reference.
*
* @param aEvent
* describes the source which fire this event
* Must be our internal saved frame. Otherwhise
* somewhere know us without a registration ...
*/
public void disposing(com.sun.star.lang.EventObject aEvent)
{
synchronized(this)
{
m_xFrame = null;
}
}
}
// ____________________
/**
* If this java application shutdown - we must cancel all current existing
* listener connections. Otherwhise the office will run into some
* DisposedExceptions if it tries to use these forgotten listener references.
* And of course it can die doing that.
* We are registered at a central object to be informed if the VM will exit.
* So we can react.
*/
public void shutdown()
{
m_aMenuBarListener.shutdown();
m_aToolBarListener.shutdown();
m_aObjectBarListener.shutdown();
m_aMenuBarListener = null;
m_aToolBarListener = null;
m_aObjectBarListener = null;
}
}
|