org.openide.explorer 6.5.22 1

org.openide.explorer.propertysheet
Class PropertyPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.openide.explorer.propertysheet.PropertyPanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class PropertyPanel
extends JComponent
implements Accessible

PropertyPanel is a generic GUI component for displaying and editing a JavaBeans™ property or any compatible getter/setter pair for which there is a property editor available, in accordance with the JavaBeans specification. It makes it possible to instantiate an appropriate GUI component for a property and provides the plumbing between user interation with the gui component and calls to the getter/setter pair to update the value.

The simplest way to use PropertyPanel is by driving it from an instance of PropertySupport.Reflection. To do that, simply pass the name of the property and an object with a getter/setter pair matching that property to the PropertySupport.Reflection's constructor, and pass the resulting instance of PropertySupport.Reflection to the PropertyPanel constructor.

A more efficient approach is to implement Node.Property or pass an existing Node.Property object to the PropertyPanel's constructor or PropertyPanel.setProperty - thus bypassing the use of reflection to locate the getter and setter.

A note on uses of Node.Property and PropertyModel: PropertyPanel was originally designed to work with instances of PropertyModel, and has since been rewritten to be driven by instances of Node.Property. The main reason for this is simplification - there is considerable overlap between PropertyModel and Node.Property; particularly, DefaultPropertyModel and PropertySupport.Reflection effectively are two ways of doing exactly the same thing.

Use of PropertyModel is still supported, but discouraged except under special circumstances. The one significant difference between Node.Property and PropertyModel is that PropertyModel permits listening for changes.

It is generally accepted that GUI components whose contents unexpectedly change due to events beyond their control does not tend to lead to quality, usable user interfaces. However, there are cases where a UI will, for example, contain several components and modification to one should immediately be reflected in the other. For such a case, use of PropertyModel is still supported. For other cases, it makes more sense to use BeanNode and for the designer of the UI to make a design choice as to how to handle (if at all) unexpected changes happening to properties it is displaying. If all you need to do is display or edit a property, use one of the constructors that takes a Node.Property object or use setProperty. PropertyModel will be deprecated at some point in the future, when a suitable replacement more consistent with Node.Property is created.

PropertyModel and displays an editor component for it.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int PREF_CUSTOM_EDITOR
          Constant defining a preference for rendering the value.
static int PREF_INPUT_STATE
          Constant defining a preference for rendering the value.
static int PREF_READ_ONLY
          Constant defining a preference for rendering the value.
static int PREF_TABLEUI
          Constant defining a preference for a borderless UI suitable for use in a table
static String PROP_MODEL
          Name of the 'model' property.
static String PROP_PREFERENCES
          Name of the 'preferences' property.
static String PROP_PROPERTY_EDITOR
          Deprecated. - the property editor is re-fetched from the underlying property object as needed. It is up to the property object to cache or not cache the property editor. This property will no longer be fired.
static String PROP_STATE
          Name of property 'state' that describes the state of the embeded PropertyEditor.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PropertyPanel()
          Creates new PropertyPanel backed by a dummy property
PropertyPanel(Node.Property p)
          Create a new property panel for displaying/editing the specified property
PropertyPanel(Node.Property p, int preferences)
          Create a new property panel for the specified property with the specified preferences.
PropertyPanel(Object bean, String propertyName, int preferences)
          Creates new PropertyPanel with DefaultPropertyModel
PropertyPanel(PropertyModel model, int preferences)
          Creates a new PropertyPanel.
 
Method Summary
 void addNotify()
          Overridden to install the inner component that will display the property
 void doLayout()
           
protected  void firePropertyChange(String nm, Object old, Object nue)
          Overridden to catch changes in those client properties that are relevant to PropertyPanel
 AccessibleContext getAccessibleContext()
           
 Dimension getMinimumSize()
           
 PropertyModel getModel()
          Get the property model associated with this property panel.
 int getPreferences()
          Returns the preferences set for this property panel.
 Dimension getPreferredSize()
           
 Node.Property getProperty()
          Fetch the property that this PropertyPanel displays.
 PropertyEditor getPropertyEditor()
          Deprecated. The property panel does not cache the property editor, and depending on its state, it may not consistently return the same property editor instance on repeated calls. The current implementation will do so for editable states, but there is no guarantee this will remain so in the future.
 Object getState()
          Getter for the state of the property editor.
 boolean isChangeImmediate()
          Getter for property changeImmediate.
 boolean isFocusable()
          Overridden to return false in cases that the preferences specify a read-only state
 void layout()
           
 void paint(Graphics g)
           
protected  void processFocusEvent(FocusEvent fe)
           
 void removeNotify()
          Overridden to dispose the component that actually displays the property and any state information associated with it
 void requestFocus()
          Overridden to do nothing in a read only state, since some custom property editors (File chooser) are capable of receiving focus even if they are disabled, effectively making focus disappear
 void setBackground(Color c)
           
 void setChangeImmediate(boolean changeImmediate)
          Setter for property changeImmediate.
 void setEnabled(boolean enabled)
          Sets whether or not this component is enabled.
 void setForeground(Color c)
           
 void setModel(PropertyModel model)
          Setter for property model.
 void setPreferences(int preferences)
          Setter for visual preferences in displaying of the value of the property.
 void setProperty(Node.Property p)
          Set or change the property this PropertyPanel will display
 String toString()
          Overridden to provide information from the embedded property renderer if not in custom editor mode
 void updateValue()
          If the editor is ExPropertyEditor it tries to change the getState property to PropertyEnv.STATE_VALID state.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PREF_READ_ONLY

public static final int PREF_READ_ONLY
Constant defining a preference for rendering the value. Value should be displayed in read-only mode.

See Also:
Constant Field Values

PREF_CUSTOM_EDITOR

public static final int PREF_CUSTOM_EDITOR
Constant defining a preference for rendering the value. Value should be displayed in custom editor.

See Also:
Constant Field Values

PREF_INPUT_STATE

public static final int PREF_INPUT_STATE
Constant defining a preference for rendering the value. Value should be displayed in editor only.

See Also:
Constant Field Values

PREF_TABLEUI

public static final int PREF_TABLEUI
Constant defining a preference for a borderless UI suitable for use in a table

See Also:
Constant Field Values

PROP_PREFERENCES

public static final String PROP_PREFERENCES
Name of the 'preferences' property.

See Also:
Constant Field Values

PROP_MODEL

public static final String PROP_MODEL
Name of the 'model' property.

See Also:
Constant Field Values

PROP_PROPERTY_EDITOR

public static final String PROP_PROPERTY_EDITOR
Deprecated. - the property editor is re-fetched from the underlying property object as needed. It is up to the property object to cache or not cache the property editor. This property will no longer be fired.
Name of the read-only property 'propertyEditor'.

See Also:
Constant Field Values

PROP_STATE

public static final String PROP_STATE
Name of property 'state' that describes the state of the embeded PropertyEditor.

Since:
2.20
See Also:
PropertyEnv.getState(), Constant Field Values
Constructor Detail

PropertyPanel

public PropertyPanel()
Creates new PropertyPanel backed by a dummy property


PropertyPanel

public PropertyPanel(Object bean,
                     String propertyName,
                     int preferences)
Creates new PropertyPanel with DefaultPropertyModel

Parameters:
preferences - the preferences that affect how this propertypanel will operate
bean - The instance of bean
propertyName - The name of the property to be displayed

PropertyPanel

public PropertyPanel(PropertyModel model,
                     int preferences)
Creates a new PropertyPanel. While not quite deprecated, do not use this constructor if your intention is to display a Node.Property object; use the constructor that takes a Node.Property object directly instead.

Parameters:
model - The model to display
See Also:
PropertyModel

PropertyPanel

public PropertyPanel(Node.Property p,
                     int preferences)
Create a new property panel for the specified property with the specified preferences.

Parameters:
p -
preferences -

PropertyPanel

public PropertyPanel(Node.Property p)
Create a new property panel for displaying/editing the specified property

Parameters:
p - A Property object for this node to represent
See Also:
Node.Property
Method Detail

setBackground

public void setBackground(Color c)
Overrides:
setBackground in class JComponent

setForeground

public void setForeground(Color c)
Overrides:
setForeground in class JComponent

doLayout

public void doLayout()
Overrides:
doLayout in class Container

layout

public void layout()
Overrides:
layout in class Container

getMinimumSize

public Dimension getMinimumSize()
Overrides:
getMinimumSize in class JComponent

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class JComponent

firePropertyChange

protected void firePropertyChange(String nm,
                                  Object old,
                                  Object nue)
Overridden to catch changes in those client properties that are relevant to PropertyPanel

Overrides:
firePropertyChange in class Component

isFocusable

public boolean isFocusable()
Overridden to return false in cases that the preferences specify a read-only state

Overrides:
isFocusable in class Component

requestFocus

public void requestFocus()
Overridden to do nothing in a read only state, since some custom property editors (File chooser) are capable of receiving focus even if they are disabled, effectively making focus disappear

Overrides:
requestFocus in class JComponent

processFocusEvent

protected void processFocusEvent(FocusEvent fe)
Overrides:
processFocusEvent in class Component

addNotify

public void addNotify()
Overridden to install the inner component that will display the property

Overrides:
addNotify in class JComponent

removeNotify

public void removeNotify()
Overridden to dispose the component that actually displays the property and any state information associated with it

Overrides:
removeNotify in class JComponent

getPreferences

public int getPreferences()
Returns the preferences set for this property panel. The preferences determine such things as read-only mode and whether an inline or custom editor is displayed

Returns:
The preferences

setPreferences

public void setPreferences(int preferences)
Setter for visual preferences in displaying of the value of the property.

Parameters:
preferences - PREF_XXXX constants

getModel

public PropertyModel getModel()
Get the property model associated with this property panel. Note that while the PropertyModel usages of PropertyPanel are not yet deprecated, the preferred and more efficient use of PropertyPanel is directly with a Node.Property instance rather than a PropertyModel.

Note: This method is primarily here for backward compatibility, and the single use case where it is truly desirable to have a GUI component which reflects changes made by some source other than itself. If you have used one of the constructors which takes a Node.Property instance or the setProperty method, this method will return a PropertyModel instance generated for the underlying Node.Property object. In such a case, the PropertyModel instance thus obtained will not fire changes due to changes made by calling setValue on the Node.Property. For details on why this is the case, see issue 37779.

Returns:
Either the PropertyModel set in the constructor or via setModel, or a generated instance of PropertyModel which wraps the Node.Property which was set in the constructor or via setProperty.

setModel

public void setModel(PropertyModel model)
Setter for property model. Note that while the PropertyModel usages of PropertyPanel are not yet deprecated, the preferred and more efficient use of PropertyPanel is directly with a Node.Property instance rather than a PropertyModel. The PropertyPanel will either construct a wrapper Node.Property instance or find the underlying Node.Property instance, and use that to drive its infrastructure. The only remaining use case for PropertyModel here is if the component needs to listen for changes in the underlying value which do not originate in this PropertyPanel.

Parameters:
model - New model.

setProperty

public final void setProperty(Node.Property p)
Set or change the property this PropertyPanel will display

Parameters:
p - the Property

getProperty

public final Node.Property getProperty()
Fetch the property that this PropertyPanel displays. For cases where the PropertyPanel was initialized with an instance of PropertyModel, the return value of this method is not officially defined.

Returns:
the property

getState

public final Object getState()
Getter for the state of the property editor. The editor can be in not valid states just if it implements the ExPropertyEditor and changes state by the setState method of the PropertyEnv environment.

Returns:
PropertyEnv.STATE_VALID if the editor is not the ExPropertyEditor one or other constant from PropertyEnv.STATE_* that was assigned to PropertyEnv
Since:
2.20

updateValue

public void updateValue()
If the editor is ExPropertyEditor it tries to change the getState property to PropertyEnv.STATE_VALID state. This may be vetoed, in such case a warning is presented to the user and the getState will still return the original value (different from STATE_VALID).

Also updates the value if org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor is used.


getPropertyEditor

public PropertyEditor getPropertyEditor()
Deprecated. The property panel does not cache the property editor, and depending on its state, it may not consistently return the same property editor instance on repeated calls. The current implementation will do so for editable states, but there is no guarantee this will remain so in the future.

Getter for current property editor depending on the model. It may be null if it is not possible to obtain a property editor.

Note: When not in custom editor mode, PropertyPanel does not cache the editor supplied by the property. If the PropertyPanel was initialized from an instance of (deprecated) DefaultPropertyModel, a different instance of the property editor may be constructed and returned for each call. Client code must take this into account. . For cases of initialization via a Node.Property object, it is up to the supplied Property to cache or not cache the property editor returned from getPropertyEditor() as suits its needs.

Returns:
the property editor or null

setEnabled

public void setEnabled(boolean enabled)
Sets whether or not this component is enabled. all panel components gets disabled when enabled parameter is set false

Overrides:
setEnabled in class JComponent
Parameters:
enabled - flag defining the action.

isChangeImmediate

public boolean isChangeImmediate()
Getter for property changeImmediate. If this is true the changes made in the property editor are immediately propagated to the value of the property (to the property model).

Returns:
Value of property changeImmediate.

setChangeImmediate

public void setChangeImmediate(boolean changeImmediate)
Setter for property changeImmediate. IF this is true the changes made in the property editor are immediately propagated to the value of the property (to the property model).

Parameters:
changeImmediate - New value of property changeImmediate.

toString

public String toString()
Overridden to provide information from the embedded property renderer if not in custom editor mode

Overrides:
toString in class Component

paint

public void paint(Graphics g)
Overrides:
paint in class JComponent

getAccessibleContext

public AccessibleContext getAccessibleContext()
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JComponent

org.openide.explorer 6.5.22 1

Built on July 11 2007.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.