org.openide.windows
Class TopComponent

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--org.openide.windows.TopComponent
All Implemented Interfaces:
Accessible, Externalizable, ImageObserver, MenuContainer, Serializable
Direct Known Subclasses:
CloneableTopComponent, ExplorerPanel

public class TopComponent
extends JComponent
implements Externalizable, Accessible

Embeddable visual component to be displayed in the IDE. This is the basic unit of display in the IDE--windows should not be created directly, but rather use this class. A top component may correspond to a single window, but may also be a tab (e.g.) in a window. It may be docked or undocked, have selected nodes, supply actions, etc. Important serialization note: Serialization of this TopComponent is designed in a way that it's not desired to override writeReplace method. If you would like to resolve to something, please implement readResolve() method directly on your top component.

See Also:
Serialized Form

Inner Class Summary
static interface TopComponent.Cloneable
          Each top component that wishes to be cloned should implement this interface, so CloneAction can check it and call the cloneComponent method.
static class TopComponent.NodeName
          This class provides the connection between the node name and a name of the component.
static interface TopComponent.Registry
          Registry of all top components.
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent
 
Field Summary
static int CLOSE_EACH
          Behavior in which a top component closed (by the user) in one workspace will be removed from every workspace.
static int CLOSE_LAST
          Behavior in which a top component closed (by the user) in one workspace may be left in other workspaces.
 
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
TopComponent()
          Create a top component.
TopComponent(DataObject obj)
          Create a top component associated with a data object.
 
Method Summary
 boolean canClose(Workspace workspace, boolean last)
          This method is called when top component is about to close.
 boolean close()
          Closes the top component on current workspace.
 boolean close(Workspace workspace)
          Closes the top component on given workspace, if closeOperation is set to CLOSE_LAST.
protected  void closeNotify()
          Called only when top component was closed so that now it is closed on all workspaces in the system.
protected  void componentActivated()
          Called when this component is activated.
protected  void componentDeactivated()
          Called when this component is deactivated.
 AccessibleContext getAccessibleContext()
           
 Node[] getActivatedNodes()
          Get the set of activated nodes in this component.
 int getCloseOperation()
          Get the current close mode for this component.
 HelpCtx getHelpCtx()
          Get the help context for this component.
 Image getIcon()
           
static TopComponent.Registry getRegistry()
          Getter for class that allows obtaining of information about components.
 SystemAction[] getSystemActions()
          Get the system actions which will appear in the popup menu of this component.
 UndoRedo getUndoRedo()
          Get the undo/redo support for this component.
 boolean isOpened()
          Finds out if this top component is opened at least on one workspace.
 boolean isOpened(Workspace workspace)
          Finds out whether this top component is opened or not on specified workspace.
 void open()
          Show the component on current workspace.
 void open(Workspace workspace)
          Show the component on given workspace.
protected  void openNotify()
          Called only when top component was closed on all workspaces before and now is opened for the first time on some workspace.
 void readExternal(ObjectInput in)
          Deserialize this top component.
 void requestFocus()
          Request focus for the window holding this top component.
 void requestVisible()
          Set this component visible but not selected or focused if possible.
 void setActivatedNodes(Node[] nodes)
          Set the set of activated nodes in this component.
 void setCloseOperation(int closeOperation)
          Set the close mode for the component.
 void setIcon(Image icon)
          Set the icon of this top component.
 void setName(String name)
          Set the name of this top component.
 void writeExternal(ObjectOutput out)
          Serialize this top component.
protected  Object writeReplace()
          Delegates instance of replacer class to be serialized instead of top component itself.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, 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, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLOSE_EACH

public static final int CLOSE_EACH
Behavior in which a top component closed (by the user) in one workspace will be removed from every workspace. Also, close() is called. This is appropriate for top components such as Editor panes which the user expects to really close (and prompt to save) when closed in any workspace.

CLOSE_LAST

public static final int CLOSE_LAST
Behavior in which a top component closed (by the user) in one workspace may be left in other workspaces. Only when the last remaining manifestation in any workspace is closed will the object be deleted using close(). Appropriate for components containing no user data, for which closing the component is only likely to result from the user's wanting to remove it from active view (on the current workspace).
Constructor Detail

TopComponent

public TopComponent()
Create a top component.

TopComponent

public TopComponent(DataObject obj)
Create a top component associated with a data object. Currently the data object is used to set the component's name (which will be updated according to the object's node delegate) by installing NodeName inner class and attaching it to the node delegate.
Parameters:
obj - the data object
Method Detail

getRegistry

public static final TopComponent.Registry getRegistry()
Getter for class that allows obtaining of information about components. It allows to find out which component is selected, which nodes are currently or has been activated and list of all components.
Returns:
the registry of components

getActivatedNodes

public final Node[] getActivatedNodes()
Get the set of activated nodes in this component.
Returns:
the activated nodes for this component

setActivatedNodes

public final void setActivatedNodes(Node[] nodes)
Set the set of activated nodes in this component.
Parameters:
nodes - activated nodes for this component

getUndoRedo

public UndoRedo getUndoRedo()
Get the undo/redo support for this component. The default implementation returns a dummy support that cannot undo anything.
Returns:
undoable edit for this component

open

public void open()
Show the component on current workspace. Note that this method only makes it visible, but does not give it focus. Implemented via call to open(null).
See Also:
requestFocus()

open

public void open(Workspace workspace)
Show the component on given workspace. If given workspace is not active, component will be shown only after given workspace will become visible. Note that this method only makes it visible, but does not give it focus.
Parameters:
workspace - Workspace on which component should be opened. Parameter can be null -> means current workspace.
See Also:
requestFocus()

isOpened

public final boolean isOpened()
Finds out if this top component is opened at least on one workspace.
Returns:
true if given top component is opened on at least one workspace, false otherwise

isOpened

public final boolean isOpened(Workspace workspace)
Finds out whether this top component is opened or not on specified workspace.
Returns:
true if given top component is opened on given workspace, false otherwise

close

public final boolean close()
Closes the top component on current workspace. First asks canClose() method to see if it is possible to close now. If canClose() returns false, component will not be closed. Semantics of this method depends on top component's closeOperation state. If closeOperation is set to CLOSE_LAST (default), top component will be closed only on current workspace. If it is set to CLOSE_EACH, if will be closed on all workspaces at once.
Returns:
true if top component was succesfully closed, false if top component for some reason refused to close.

close

public final boolean close(Workspace workspace)
Closes the top component on given workspace, if closeOperation is set to CLOSE_LAST. If it is set to CLOSE_EACH, given parameter will be ignored and component will be closed on all workspaces at once.
Parameters:
workspace - Workspace on which component should be closed.
Returns:
true if top component was succesfully closed, false if top component for some reason refused to close.

canClose

public boolean canClose(Workspace workspace,
                        boolean last)
This method is called when top component is about to close. Allows subclasses to decide if top component is ready for closing or not.
Default implementation always return true.
Parameters:
workspace - the workspace on which we are about to close or null which means that component will be closed on all workspaces where it is opened (CLOSE_EACH mode)
last - true if this is last workspace where top component is opened, false otherwise. If close operation is set to CLOSE_EACH, then this param is always true
Returns:
true if top component is ready to close, false otherwise.

openNotify

protected void openNotify()
Called only when top component was closed on all workspaces before and now is opened for the first time on some workspace. The intent is to provide subclasses information about TopComponent's life cycle across all existing workspaces. Subclasses will usually perform initializing tasks here.

closeNotify

protected void closeNotify()
Called only when top component was closed so that now it is closed on all workspaces in the system. The intent is to provide subclasses information about TopComponent's life cycle across workspaces. Subclasses will usually perform cleaning tasks here.

getSystemActions

public SystemAction[] getSystemActions()
Get the system actions which will appear in the popup menu of this component.

Subclasses are encouraged to override this method to specify their own sets of actions.

Remember to call the super method when overriding and add your actions to the superclass' ones (in some order),? because the default implementation provides support for standard component actions like save, close, and clone.

Returns:
system actions for this component

setCloseOperation

public final void setCloseOperation(int closeOperation)
Set the close mode for the component.
Parameters:
mode - one of CLOSE_EACH or CLOSE_LAST
Throws:
IllegalArgumentException - if an unrecognized close mode was supplied
See Also:
close()

getCloseOperation

public final int getCloseOperation()
Get the current close mode for this component.
Returns:
one of CLOSE_EACH or CLOSE_LAST

componentActivated

protected void componentActivated()
Called when this component is activated. This happens when the parent window of this component gets focus (and this component is the preferred one in it), or when this component is selected in its window (and its window was already focussed). Override this method to perform some special action on component activation: typically, set performers for relevant actions. Remember to call the super method. The default implementation does nothing.

componentDeactivated

protected void componentDeactivated()
Called when this component is deactivated. This happens when the parent window of this component loses focus (and this component is the preferred one in the parent), or when this component loses preference in the parent window (and the parent window is focussed). Override this method to perform some special action on component deactivation: typically, unset performers for relevant actions. Remember to call the super method. The default implementation does nothing.

requestFocus

public void requestFocus()
Request focus for the window holding this top component. Also makes the component preferred in that window. The component will not be automatically opened first if it is not already.
Overrides:
requestFocus in class JComponent

requestVisible

public void requestVisible()
Set this component visible but not selected or focused if possible. If focus is in other container (multitab) or other pane (split) in the same container it makes this component only visible eg. it selects tab with this component. If focus is in the same container (multitab) or in the same pane (split) it has the same effect as requestFocus().

setName

public void setName(String name)
Set the name of this top component. The default implementation just notifies the window manager.
Overrides:
setName in class Component
Parameters:
displayName - the new display name

setIcon

public void setIcon(Image icon)
Set the icon of this top component. The icon will be used for the component's representation on the screen, e.g. in a multiwindow's tab. The default implementation just notifies the window manager.
Parameters:
icon - New components' icon.

getIcon

public Image getIcon()
Returns:
The icon of the top component

getHelpCtx

public HelpCtx getHelpCtx()
Get the help context for this component. Subclasses should generally override this to return specific help.
Returns:
the help context

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Serialize this top component. Subclasses wishing to store state must call the super method, then write to the stream.
Specified by:
writeExternal in interface Externalizable
Parameters:
out - the stream to serialize to

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Deserialize this top component. Subclasses wishing to store state must call the super method, then read from the stream.
Specified by:
readExternal in interface Externalizable
Parameters:
in - the stream to deserialize from

writeReplace

protected Object writeReplace()
                       throws ObjectStreamException
Delegates instance of replacer class to be serialized instead of top component itself. Replacer class calls writeExternal and constructor, readExternal and readResolve methods properly, so 8 any top component can behave like any other externalizable object. Subclasses can override this method to perform their serialization differentrly

getAccessibleContext

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


Built on December 12 2001.  |  Portions Copyright 1997-2001 Sun Microsystems, Inc. All rights reserved.