package textbender.a.u.locusPoint; // Copyright 2006-2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.awt.*; import java.beans.*; import java.rmi.*; import java.rmi.server.*; import javax.swing.*; import textbender.a.r.page.*; import textbender.g.beans.*; import textbender.g.hold.*; import textbender.g.lang.*; import textbender.g.util.logging.*; /** Button model to enable/disable the shadow pointer. */ public @ThreadRestricted("AWT event dispatch") final class EnableButton extends JToggleButton.ToggleButtonModel implements PropertyChangeListenerR { /** Constructs an EnableButton. It (the button itself) is disabled * if the page cannot support a shadow pointer. * * @param pV context * @param spool for internal holds. When unwound, this instance * will become disabled, and will release its internal holds. * * @throws RemoteException if creation fails * in communication with desk daemon */ @ThreadRestricted("AWT event dispatch") public EnableButton( PageVisit pV, Spool spool ) throws RemoteException { assert java.awt.EventQueue.isDispatchThread(); pageVisit = pV; setEnabled( !pageVisit.isPageSilent() ); // button not pressable in silent pages, because locus-pointer inactive there UnicastRemoteObject.exportObject( this, /*port, anonymous*/0 ); locusPoint = PageDaemons.i().connections().hostServiceRegistry().getService( LocusPoint.class ); locusPoint.addPropertyChangeListener( "enabled", EnableButton.this ); spool.add( new Hold() { public @ThreadSafe void release() { try{ locusPoint.disabledPropertyChangeListener( "enabled", EnableButton.this ); } catch( RemoteException x ) { LoggerX.i(getClass()).warning( x.toString() ); }} }); super.setSelected( locusPoint.isEnabled() ); // fire up } // - B u t t o n - M o d e l ---------------------------------------------------------- public void setSelected( boolean selected ) { assert java.awt.EventQueue.isDispatchThread(); try { locusPoint.setEnabled( selected ); } catch( RemoteException x ){ pageVisit.user().logAndShow( x ); } } // - P r o p e r t y - C h a n g e - L i s t e n e r - R ------------------------------ public @ThreadSafe void propertyChange( final PropertyChangeEvent e ) { EventQueue.invokeLater( new Runnable() { public void run() // in AWT event dispatch thread { EnableButton.super.setSelected( (Boolean)e.getNewValue() ); } }); } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private final PageVisit pageVisit; private final LocusPoint locusPoint; }