Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javax/ide/view/DefaultViewable.java


1   package javax.ide.view;
2   
3   import java.beans.PropertyChangeListener;
4   import javax.ide.util.IconDescription;
5   import javax.ide.view.Viewable;
6   import javax.swing.event.SwingPropertyChangeSupport;
7   
8   
9   /**
10   * <code>DefaultViewable</code>s are objects that map directly to visible
11   * GUI elements that users can select such as a menu items, nodes in
12   * the project explorer, etc..
13   */
14  public class DefaultViewable implements Viewable
15  {
16  
17    private boolean _visible = true;
18    private SwingPropertyChangeSupport _propertyChangeSupport;
19  
20    //----------------------------------------------------------------------------
21    // Public methods.
22    //----------------------------------------------------------------------------
23  
24    /**
25     *  Get a short descriptive label that can be shown to the user.
26     *  @return A short descriptive label.
27     */
28    public String getLabel()
29    {
30      return "nolabel";
31    }
32  
33    /*-
34     * Viewable method.
35     */
36    public String getToolTip()
37    {
38      return getLabel();
39    }
40  
41    /*-
42     * Viewable method.
43     */
44    public IconDescription getIcon()
45    {
46      return null;
47    }
48  
49    /*-
50     * Viewable interface method. Returns <code>true</code> by default.
51     */
52    public boolean isVisible()
53    {
54      return _visible;
55    }
56    
57    /*-
58     * Viewable interface method.
59     */
60    public void setVisible( boolean visible )
61    {
62      final Boolean oldVal = new Boolean( _visible );
63      _visible = visible;
64      firePropertyChange( PROP_VISIBLE, oldVal, new Boolean( _visible ) );
65    }
66    
67    /*-
68     * Viewable interface method.
69     */
70    public void addPropertyChangeListener( PropertyChangeListener listener )
71    {
72      if ( _propertyChangeSupport == null )
73      {
74        _propertyChangeSupport = new SwingPropertyChangeSupport( this );
75      }
76      _propertyChangeSupport.addPropertyChangeListener( listener );
77    }
78  
79    /*-
80     * Viewable interface method.
81     */
82    public void removePropertyChangeListener( PropertyChangeListener listener )
83    {
84      if ( _propertyChangeSupport != null )
85      {
86        _propertyChangeSupport.removePropertyChangeListener( listener );
87      }
88    }
89  
90    //---------------------------------------------------------------------------
91    // Object methods.
92    //---------------------------------------------------------------------------
93    public String toString()
94    {
95      return getLabel();
96    }
97  
98    //---------------------------------------------------------------------------
99    // Protected methods.
100   //---------------------------------------------------------------------------
101 
102 
103   /**
104    * Fire the property change event. Fires the event for property 
105    * <code>name</code> only if the <code>oldVal</code> is different from the 
106    * <code>newVal</code>.
107    * @param name The property name.
108    * @param oldVal The current value of the specified property.
109    * @param newVal The new value of the specified property.
110    */
111   protected void firePropertyChange( String name, Object oldVal, Object newVal )
112   {
113     if ( _propertyChangeSupport != null )
114     {
115       if ( oldVal == null || newVal == null || !oldVal.equals( newVal ))
116       {
117         _propertyChangeSupport.firePropertyChange( name, oldVal, newVal );
118       }
119     }
120   }
121 }