projectviewer
Class ProjectViewer

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byprojectviewer.ProjectViewer
All Implemented Interfaces:
javax.accessibility.Accessible, org.gjt.sp.jedit.gui.DefaultFocusComponent, org.gjt.sp.jedit.EBComponent, java.util.EventListener, java.awt.event.HierarchyListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public final class ProjectViewer
extends javax.swing.JPanel
implements java.awt.event.HierarchyListener, org.gjt.sp.jedit.gui.DefaultFocusComponent, org.gjt.sp.jedit.EBComponent

Main GUI for the project viewer plugin.

Version:
$Id: ProjectViewer.java 9433 2007-04-15 01:45:09Z vanza $
Author:
Marcelo Vanzin (with much code from original version)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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
ProjectViewer(org.gjt.sp.jedit.View aView)
          Create a new ProjectViewer.
 
Method Summary
static void addProjectViewerListener(ProjectViewerListener lstnr, org.gjt.sp.jedit.View view)
          Add a listener for the instance of project viewer of the given view.
static void addProjectViewerListeners(org.gjt.sp.jedit.PluginJAR jar, org.gjt.sp.jedit.View view)
          Adds to the list of listeners for the given view the listeners that have been declared by the given plugin using properties.
static void addToolbarActions(org.gjt.sp.jedit.PluginJAR jar)
          Adds to the list of listeners for the given view the listeners that have been declared by the given plugin using properties.
protected static void cleanViewEntry(org.gjt.sp.jedit.View aView)
          Removes the "viewer entry" related to the given view.
static void fireGroupActivated(VPTGroup grp, org.gjt.sp.jedit.View v)
          Fires an event for the loading of a group.
static void fireGroupAddedEvent(VPTGroup group)
           
static void fireGroupRemovedEvent(VPTGroup group)
           
static void fireNodeMovedEvent(VPTNode moved, VPTGroup oldParent)
           
static void fireNodeSelected(ProjectViewer src, VPTNode node)
           
static void fireProjectAdded(java.lang.Object src, VPTProject p)
          Fires a "project added" event.
static void fireProjectLoaded(java.lang.Object src, VPTProject p, org.gjt.sp.jedit.View v)
          Fires an event for the loading of a project.
static void fireProjectRemoved(java.lang.Object src, VPTProject p)
          Fires a "project removed" event.
 void focusOnDefaultComponent()
           
static VPTNode getActiveNode(org.gjt.sp.jedit.View aView)
          Return the current "active" node (opened project/group) for the view.
static VPTProject getActiveProject(org.gjt.sp.jedit.View aView)
          Return the current active project for the view.
 javax.swing.JTree getCurrentTree()
          Returns the currently active tree.
 java.lang.String getFolderTreeState(VPTNode node)
          Returns a String representing the state of the folder tree.
static ProjectViewer getProjectViewer(org.gjt.sp.jedit.View view)
           
 VPTNode getRoot()
          Returns the root node of the current tree.
 java.util.List getSelectedFilePaths()
          Returns a list of Strings containing the file paths of the selected file and folder nodes.
 VPTNode getSelectedNode()
          Returns the currently selected node in the tree.
 org.gjt.sp.jedit.View getView()
          Returns the View associated with this instance.
static ProjectViewer getViewer(org.gjt.sp.jedit.View view)
          Returns the viewer associated with the given view, or null if none exists.
 void handleMessage(org.gjt.sp.jedit.EBMessage msg)
          Handles an EditBus message.
 void hierarchyChanged(java.awt.event.HierarchyEvent he)
           
static void insertNodeInto(VPTNode child, VPTNode parent)
          Inserts a node in the given parent node (in a sorted position according to VPTNode.findIndexForChild(VPTNode) and notifies folder trees in all instances of ProjectViewer.
static void nodeChanged(VPTNode node)
          Notify all project viewer instances of a change in a node.
static void nodeStructureChanged(VPTNode node)
          Notify all project viewer instances of a change in a node's structure.
static void nodeStructureChangedFlat(VPTNode node)
          Notify all "flat trees" in any project viewer instances of a change in a node's structure.
static void projectRemoved(java.lang.Object src, VPTProject p)
          Notify all "flat trees" in any project viewer instances of a change in a node's structure.
static void registerAction(Action action)
          Adds an action to be shown on the toolbar.
static void removeNodeFromParent(VPTNode child)
          Removes a node from its parent, and notifies all folder trees in all instances of ProjectViewer.
static void removeProjectViewerListener(ProjectViewerListener lstnr, org.gjt.sp.jedit.View view)
          Remove the listener from the list of listeners for the given view.
static void removeProjectViewerListeners(org.gjt.sp.jedit.PluginJAR jar)
          Removes the listeners loaded by the given plugin from the listener list.
static void removeToolbarActions(org.gjt.sp.jedit.PluginJAR jar)
          Removes the project listeners of the given plugin from the list, and from any active project in ProjectViewer.
static void setActiveNode(org.gjt.sp.jedit.View aView, VPTNode n)
          Sets the current active node for the view.
 void setChangingBuffers(boolean flag)
          Method intended for use by classes that manage clicks on the project trees to open buffers in jEdit; by setting this flag to true, the auto-selecting of the new active buffer in jEdit is temporarily disabled, preventing the tree from shifting around when the user is interacting with it.
 void setEnabled(boolean flag)
          Enables or disables the viewer GUI.
 void setFolderTreeState(VPTNode node, java.lang.String state)
          Sets the folder tree state from the given String.
 void setProject(VPTProject p)
          Deprecated. Use setRootNode(VPTNode) instead.
 void setRootNode(VPTNode n)
          Sets the root node of the trees showm by this viewer.
 void setStatus(java.lang.String message)
          Changes jEdit's status bar message for the current view.
static void unregisterAction(Action action)
          Removes an action from the toolbar.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProjectViewer

public ProjectViewer(org.gjt.sp.jedit.View aView)
Create a new ProjectViewer. Only one instance is allowed per view.

Parameters:
aView - The jEdit view where the viewer is to be created.
Throws:
java.lang.UnsupportedOperationException - If a viewer is already instantiated for the given view. `
Method Detail

registerAction

public static void registerAction(Action action)
Adds an action to be shown on the toolbar.


unregisterAction

public static void unregisterAction(Action action)
Removes an action from the toolbar.


removeToolbarActions

public static void removeToolbarActions(org.gjt.sp.jedit.PluginJAR jar)
Removes the project listeners of the given plugin from the list, and from any active project in ProjectViewer.


addToolbarActions

public static void addToolbarActions(org.gjt.sp.jedit.PluginJAR jar)
Adds to the list of listeners for the given view the listeners that have been declared by the given plugin using properties. For global listeners, "view" should be null.


getViewer

public static ProjectViewer getViewer(org.gjt.sp.jedit.View view)
Returns the viewer associated with the given view, or null if none exists.


addProjectViewerListener

public static void addProjectViewerListener(ProjectViewerListener lstnr,
                                            org.gjt.sp.jedit.View view)
Add a listener for the instance of project viewer of the given view. If the given view is null, the listener will be called from all instances.

Additionally, for listeners that are registered for all views, a ProjectViewerEvent is fired when a different view is selected.

Parameters:
lstnr - The listener to add.
view - The view that the lstnr is attached to, or null if the listener wants to be called from all views.

removeProjectViewerListener

public static void removeProjectViewerListener(ProjectViewerListener lstnr,
                                               org.gjt.sp.jedit.View view)
Remove the listener from the list of listeners for the given view. As with the add method, view can be null.


fireProjectLoaded

public static void fireProjectLoaded(java.lang.Object src,
                                     VPTProject p,
                                     org.gjt.sp.jedit.View v)
Fires an event for the loading of a project. Notify all the listeners registered for the given view and listeners registered for all views.

If the view provided is null, only the listeners registered for the null View will receive the event.

Parameters:
src - The viewer that generated the change, or null.
p - The activated project.
v - The view where the change occured, or null.

fireGroupActivated

public static void fireGroupActivated(VPTGroup grp,
                                      org.gjt.sp.jedit.View v)
Fires an event for the loading of a group. Notify all the listeners registered for the given view and listeners registered for all views.

If the view provided is null, only the listeners registered for the null View will receive the event.

Parameters:
grp - The activated group.
v - The view where the change occured, or null.

fireNodeSelected

public static void fireNodeSelected(ProjectViewer src,
                                    VPTNode node)

fireProjectAdded

public static void fireProjectAdded(java.lang.Object src,
                                    VPTProject p)
Fires a "project added" event. All listeners, regardless of the view, are notified of this event.


fireProjectRemoved

public static void fireProjectRemoved(java.lang.Object src,
                                      VPTProject p)
Fires a "project removed" event. All listeners, regardless of the view, are notified of this event.


removeProjectViewerListeners

public static void removeProjectViewerListeners(org.gjt.sp.jedit.PluginJAR jar)
Removes the listeners loaded by the given plugin from the listener list. Meant to be called when said plugin is unloaded by jEdit.


addProjectViewerListeners

public static void addProjectViewerListeners(org.gjt.sp.jedit.PluginJAR jar,
                                             org.gjt.sp.jedit.View view)
Adds to the list of listeners for the given view the listeners that have been declared by the given plugin using properties. For global listeners, "view" should be null.


fireNodeMovedEvent

public static void fireNodeMovedEvent(VPTNode moved,
                                      VPTGroup oldParent)

fireGroupAddedEvent

public static void fireGroupAddedEvent(VPTGroup group)

fireGroupRemovedEvent

public static void fireGroupRemovedEvent(VPTGroup group)

nodeStructureChanged

public static void nodeStructureChanged(VPTNode node)
Notify all project viewer instances of a change in a node's structure.


nodeChanged

public static void nodeChanged(VPTNode node)
Notify all project viewer instances of a change in a node.


insertNodeInto

public static void insertNodeInto(VPTNode child,
                                  VPTNode parent)
Inserts a node in the given parent node (in a sorted position according to VPTNode.findIndexForChild(VPTNode) and notifies folder trees in all instances of ProjectViewer.


nodeStructureChangedFlat

public static void nodeStructureChangedFlat(VPTNode node)
Notify all "flat trees" in any project viewer instances of a change in a node's structure.


removeNodeFromParent

public static void removeNodeFromParent(VPTNode child)
Removes a node from its parent, and notifies all folder trees in all instances of ProjectViewer.


projectRemoved

public static void projectRemoved(java.lang.Object src,
                                  VPTProject p)
Notify all "flat trees" in any project viewer instances of a change in a node's structure. Then, rebuild the project combo boxes.


getProjectViewer

public static ProjectViewer getProjectViewer(org.gjt.sp.jedit.View view)

setActiveNode

public static void setActiveNode(org.gjt.sp.jedit.View aView,
                                 VPTNode n)
Sets the current active node for the view. If a viewer is available for the given view, the root node of the viewer is also changed.

Throws:
java.lang.IllegalArgumentException - If node is not a project or group.
Since:
PV 2.1.0

getActiveNode

public static VPTNode getActiveNode(org.gjt.sp.jedit.View aView)
Return the current "active" node (opened project/group) for the view. Returns null if no active node is known for the view.

Since:
PV 2.1.0

getActiveProject

public static VPTProject getActiveProject(org.gjt.sp.jedit.View aView)
Return the current active project for the view. If no project is active, return null.

Since:
PV 2.1.0

cleanViewEntry

protected static void cleanViewEntry(org.gjt.sp.jedit.View aView)
Removes the "viewer entry" related to the given view. Called by the ProjectPlugin class when a view closed message is received.


setStatus

public void setStatus(java.lang.String message)
Changes jEdit's status bar message for the current view.


getSelectedNode

public VPTNode getSelectedNode()
Returns the currently selected node in the tree.


getSelectedFilePaths

public java.util.List getSelectedFilePaths()
Returns a list of Strings containing the file paths of the selected file and folder nodes. This is mostly a utility method so other plugins/macros can peform actions on a selection of files.


getCurrentTree

public javax.swing.JTree getCurrentTree()
Returns the currently active tree.


getView

public org.gjt.sp.jedit.View getView()
Returns the View associated with this instance.


setRootNode

public void setRootNode(VPTNode n)
Sets the root node of the trees showm by this viewer. The current root is cleaned up before setting the new root (e.g., project files are closed, etc.)

Throws:
java.lang.IllegalArgumentException - If node is not a project or group.
Since:
PV 2.1.0

setProject

public void setProject(VPTProject p)
Deprecated. Use setRootNode(VPTNode) instead.

Sets the given project to be the root of the tree. If "p" is null, then the root node is set to the "VPTRoot" node.


getRoot

public VPTNode getRoot()
Returns the root node of the current tree.


setEnabled

public void setEnabled(boolean flag)
Enables or disables the viewer GUI.


getFolderTreeState

public java.lang.String getFolderTreeState(VPTNode node)
Returns a String representing the state of the folder tree.

Returns:
The state of the tree, starting at the given node, or null if the folderTree is not visible.
See Also:
setFolderTreeState(VPTNode, String)

setFolderTreeState

public void setFolderTreeState(VPTNode node,
                               java.lang.String state)
Sets the folder tree state from the given String.

See Also:
getFolderTreeState(VPTNode)

setChangingBuffers

public void setChangingBuffers(boolean flag)
Method intended for use by classes that manage clicks on the project trees to open buffers in jEdit; by setting this flag to true, the auto-selecting of the new active buffer in jEdit is temporarily disabled, preventing the tree from shifting around when the user is interacting with it.

Since:
PV 2.1.1

handleMessage

public void handleMessage(org.gjt.sp.jedit.EBMessage msg)
Handles an EditBus message.

Specified by:
handleMessage in interface org.gjt.sp.jedit.EBComponent

hierarchyChanged

public void hierarchyChanged(java.awt.event.HierarchyEvent he)
Specified by:
hierarchyChanged in interface java.awt.event.HierarchyListener

focusOnDefaultComponent

public void focusOnDefaultComponent()
Specified by:
focusOnDefaultComponent in interface org.gjt.sp.jedit.gui.DefaultFocusComponent