fr.esrf.tangoatk.widget.util.interlock
Class NetEditor

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by fr.esrf.tangoatk.widget.util.interlock.NetEditor
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener

public class NetEditor
extends javax.swing.JComponent
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

Network Editor component class. This class can be subclassed to create specific editor or viewer (not editable) component.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int CREATE_BUBBLE
          Editor is in bubble creation mode
static int CREATE_LINK
          Editor is in link creation mode
static int CREATE_NONE
          Selection mode (no creation)
static int CREATE_TEXT
          Editor is in text creation mode (Free label)
 
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
NetEditor()
          Contruct a Network Editor.
NetEditor(javax.swing.JFrame parent)
          Contruct a Network Editor.
 
Method Summary
 void addEditorListener(NetEditorListener l)
          Add a NetEditor listener.
 boolean addObject(NetObject obj)
          Add a NetObject to the editor.
 boolean canRedo()
          Get redo state
 boolean canUndo()
          Get undo state
 void clearEditorListener()
          Clears the NetEditor listener list.
 void clearObjects()
          Clear all object in the editor.
 void computePreferredSize()
          Ask the editor to recompute it size.
 void copySelection()
          copy current selection to the clipboard
 NetObject createBubbleObject(int x, int y)
          Called when the editor adds a bubble object to the network.
 void cutSelection()
          move selection to clipbaord
 void deleteSelection()
          delete current selection
 boolean getAntialiasFont()
          Returns true if Anti-Aliased fonts are used, false otherwise
 java.lang.String getFileExtension()
          Returns the file extension of this editor
 java.lang.String getFileName()
          Returns the file name of the last laoded/saved net/xpss file
 java.awt.Dimension getGridSize()
          Returns current grid size.
 boolean getNeedToSaveState()
          Returns true if the scheme has been modified and need to be saved
 NetObject getNetObjectAt(int i)
          Returns the NetObject at the specified index.
 int getNetObjectNumber()
          Returns the number of NetObject in the editor
 javax.swing.JFrame getParentFrame()
          Returns the parent frame or null
 java.lang.String getRedoActionName()
          Get the name of the last action undone
 java.lang.String getUndoActionName()
          Get the name of the last action performed
 boolean isEditable()
          Returns true is this NetEditor is editable.
 boolean isShowingArrow()
          Returns true if the editor is displaying arrow with link.
 void loadFile(java.lang.String fileName)
          Load a Network file (net or xpss format) into the editor.
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseClickedB1(java.awt.event.MouseEvent e)
           
 void mouseClickedB3(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mousePressedB1(java.awt.event.MouseEvent e)
           
 void mousePressedB3(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void newAll()
          Clear the whole editor.Clipbaord remains unchanged.
 void paint(java.awt.Graphics g)
          Paint the component.
 void paintLinks(java.awt.Graphics2D g2)
          Paint link of the scheme.
 void paintObjects(java.awt.Graphics2D g2)
          Paint object of the scheme.
 void pasteSelection()
          paste clipboard
 void redo()
          Redo last canceled action
 void removeEditorListener(NetEditorListener l)
          Remove a NetEditor listener.
 void removeObject(NetObject obj)
          Remove a NetObject from the editor.
 void saveCurrent(java.lang.String defaultDir)
          Save the current scheme.
 void saveNetFile(java.lang.String fileName)
          Save the editor content to a net file.
 void selectAll()
          Select all objects in the editor.
 void setAntialiasFont(boolean b)
          Sets anti aliased font usage.
 void setCreateMode(int type)
          Sets editor in creation mode.
 void setEditable(boolean b)
          Sets the specified boolean to indicate whether or not this NetEditor should be editable.
 void setFileExtension(java.lang.String ext)
          Sets the file extension for this editor.
 void setGridSize(java.awt.Dimension d)
          Sets the grid size of this NetEditor.
 void setMoveableBubble(boolean b)
          Allow the user to move bubble object even when the editor is not editable
 void setNetEditorDialog(NetEditorDlg dlg)
          Sets the global option dialog.
 void setNetObjectDialog(NetObjectDlg dlg)
          Sets the object properties dialog.
 void setShowArrow(boolean b)
          Draws arrow with link.
 void showOpenFileDialog(java.lang.String defaultDir, NetFileFilter filter)
          Show the file selection box and call loadFile if a file is selected.
 void showOptionDialog()
          Display the global option dialog
 void showSaveFileDialog(java.lang.String defaultDir, NetFileFilter filter)
          Show the file selection box and call saveNetFile if a file is selected.
 void undo()
          Undo the last action
 void unselectAll()
          Unselect all objects in the editor.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, 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, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, 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, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, 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, 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, isFocusable, 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, processFocusEvent, 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, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CREATE_NONE

public static final int CREATE_NONE
Selection mode (no creation)

See Also:
Constant Field Values

CREATE_BUBBLE

public static final int CREATE_BUBBLE
Editor is in bubble creation mode

See Also:
Constant Field Values

CREATE_TEXT

public static final int CREATE_TEXT
Editor is in text creation mode (Free label)

See Also:
Constant Field Values

CREATE_LINK

public static final int CREATE_LINK
Editor is in link creation mode

See Also:
Constant Field Values
Constructor Detail

NetEditor

public NetEditor()
Contruct a Network Editor. It is preferable to use the constructor that gets the parent Frame else all dialogs will appear at the center of screen instead of the center of the parent component.


NetEditor

public NetEditor(javax.swing.JFrame parent)
Contruct a Network Editor.

Parameters:
parent - Parent frame
Method Detail

setEditable

public void setEditable(boolean b)
Sets the specified boolean to indicate whether or not this NetEditor should be editable. When set to false, it paints objects according to their color and they cannot be selected ,copied, deleted or moved.

Parameters:
b - the boolean to be set
See Also:
isEditable

isEditable

public boolean isEditable()
Returns true is this NetEditor is editable.

Returns:
Mode value
See Also:
setEditable(boolean)

setFileExtension

public void setFileExtension(java.lang.String ext)
Sets the file extension for this editor.

Parameters:
ext - File extension

getFileExtension

public java.lang.String getFileExtension()
Returns the file extension of this editor


loadFile

public void loadFile(java.lang.String fileName)
              throws java.io.IOException
Load a Network file (net or xpss format) into the editor. Trigger sizeChanged() and valueChanged() on success.

Parameters:
fileName - filename to load
Throws:
java.io.IOException - in case of failure (Contains the error message)
See Also:
NetEditorListener.sizeChanged(fr.esrf.tangoatk.widget.util.interlock.NetEditor, java.awt.Dimension), NetEditorListener.valueChanged(fr.esrf.tangoatk.widget.util.interlock.NetEditor)

showOpenFileDialog

public void showOpenFileDialog(java.lang.String defaultDir,
                               NetFileFilter filter)
Show the file selection box and call loadFile if a file is selected. Trigger valueChanged() if a file is selected to be loaded.

Parameters:
defaultDir - default directory
filter - File filter, if null is specified a file filter is created with the file extension.
See Also:
loadFile(java.lang.String), setFileExtension(java.lang.String), NetEditorListener.valueChanged(fr.esrf.tangoatk.widget.util.interlock.NetEditor), NetEditorListener.sizeChanged(fr.esrf.tangoatk.widget.util.interlock.NetEditor, java.awt.Dimension), NetFileFilter.NetFileFilter(java.lang.String, java.lang.String[])

saveNetFile

public void saveNetFile(java.lang.String fileName)
                 throws java.io.IOException
Save the editor content to a net file.

Parameters:
fileName - filename to save
Throws:
java.io.IOException - in case of failure

showSaveFileDialog

public void showSaveFileDialog(java.lang.String defaultDir,
                               NetFileFilter filter)
Show the file selection box and call saveNetFile if a file is selected. Trigger valueChanged() if a file is selected to be saved.

Parameters:
defaultDir - default directory
filter - File filter, if null is specified a file filter is created with the default file extension.
See Also:
NetEditorListener.valueChanged(fr.esrf.tangoatk.widget.util.interlock.NetEditor), saveNetFile(java.lang.String), setFileExtension(java.lang.String)

saveCurrent

public void saveCurrent(java.lang.String defaultDir)
Save the current scheme.

Parameters:
defaultDir - default directory for filebox if no filename has been set.
See Also:
NetEditorListener.valueChanged(fr.esrf.tangoatk.widget.util.interlock.NetEditor), saveNetFile(java.lang.String)

setAntialiasFont

public void setAntialiasFont(boolean b)
Sets anti aliased font usage. Performance can be lower on certain system when using AA fonts.

Parameters:
b - True to use Anti-Aliased font

getAntialiasFont

public boolean getAntialiasFont()
Returns true if Anti-Aliased fonts are used, false otherwise

Returns:
Anti-Aliased fonts usage

unselectAll

public void unselectAll()
Unselect all objects in the editor. Does not repaint.


selectAll

public void selectAll()
Select all objects in the editor. Does not repaint.


newAll

public void newAll()
Clear the whole editor.Clipbaord remains unchanged.


setShowArrow

public void setShowArrow(boolean b)
Draws arrow with link.

Parameters:
b - True to enable arrow.

isShowingArrow

public boolean isShowingArrow()
Returns true if the editor is displaying arrow with link.

Returns:
arrow mode

setCreateMode

public void setCreateMode(int type)
Sets editor in creation mode. Does not have any effects if the editor is not editable. To create bubble object, createBubbleObject() is called.

Parameters:
type - Type of object to be created
See Also:
CREATE_NONE, CREATE_BUBBLE, CREATE_TEXT, CREATE_LINK, createBubbleObject(int, int)

createBubbleObject

public NetObject createBubbleObject(int x,
                                    int y)
Called when the editor adds a bubble object to the network. It you override this function , Do not return an Object which override NetObject, else the editor will reconvert them to NetObject during clipboard , undo or file loading operation. This function is provided to customize the editor and create bubbles with a set of extensions and various default value. If null is returned no object is added to the network.

Parameters:
x - X coordinates (GRID coordinates)
y - Y coordinates (GRID coordinates)
Returns:
Created NetObject or null to ignore
See Also:
setCreateMode(int)

cutSelection

public void cutSelection()
move selection to clipbaord


copySelection

public void copySelection()
copy current selection to the clipboard


pasteSelection

public void pasteSelection()
paste clipboard


deleteSelection

public void deleteSelection()
delete current selection


canUndo

public boolean canUndo()
Get undo state


getUndoActionName

public java.lang.String getUndoActionName()
Get the name of the last action performed


getRedoActionName

public java.lang.String getRedoActionName()
Get the name of the last action undone


canRedo

public boolean canRedo()
Get redo state


undo

public void undo()
Undo the last action


redo

public void redo()
Redo last canceled action


addEditorListener

public void addEditorListener(NetEditorListener l)
Add a NetEditor listener.

Parameters:
l - Editor listener.
See Also:
NetEditorListener

removeEditorListener

public void removeEditorListener(NetEditorListener l)
Remove a NetEditor listener.

Parameters:
l - Editor listener.
See Also:
NetEditorListener

clearEditorListener

public void clearEditorListener()
Clears the NetEditor listener list.

See Also:
NetEditorListener

getNeedToSaveState

public boolean getNeedToSaveState()
Returns true if the scheme has been modified and need to be saved


computePreferredSize

public void computePreferredSize()
Ask the editor to recompute it size.

See Also:
NetEditorListener.sizeChanged(fr.esrf.tangoatk.widget.util.interlock.NetEditor, java.awt.Dimension)

getFileName

public java.lang.String getFileName()
Returns the file name of the last laoded/saved net/xpss file


getNetObjectAt

public NetObject getNetObjectAt(int i)
Returns the NetObject at the specified index.

Parameters:
i - Object index
Returns:
NetObject

removeObject

public void removeObject(NetObject obj)
Remove a NetObject from the editor.

Parameters:
obj - Object to be removed

addObject

public boolean addObject(NetObject obj)
Add a NetObject to the editor.

Parameters:
obj - Object to be added
Returns:
true if the object has been succesfully added.

clearObjects

public void clearObjects()
Clear all object in the editor.


getNetObjectNumber

public int getNetObjectNumber()
Returns the number of NetObject in the editor


showOptionDialog

public void showOptionDialog()
Display the global option dialog


setNetEditorDialog

public void setNetEditorDialog(NetEditorDlg dlg)
Sets the global option dialog. Allows to build a customized Editor option dialog.


setNetObjectDialog

public void setNetObjectDialog(NetObjectDlg dlg)
Sets the object properties dialog. Allows to build a custoimized Object editon dialog.


setMoveableBubble

public void setMoveableBubble(boolean b)
Allow the user to move bubble object even when the editor is not editable


getParentFrame

public javax.swing.JFrame getParentFrame()
Returns the parent frame or null


setGridSize

public void setGridSize(java.awt.Dimension d)
Sets the grid size of this NetEditor.

Parameters:
d - Grid dimension

getGridSize

public java.awt.Dimension getGridSize()
Returns current grid size.


mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseClickedB3

public void mouseClickedB3(java.awt.event.MouseEvent e)

mouseClickedB1

public void mouseClickedB1(java.awt.event.MouseEvent e)

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mousePressedB1

public void mousePressedB1(java.awt.event.MouseEvent e)

mousePressedB3

public void mousePressedB3(java.awt.event.MouseEvent e)

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

paintLinks

public void paintLinks(java.awt.Graphics2D g2)
Paint link of the scheme. Called by paint() before paintObjects(). You can override it to custom the link painting. Here is an example code for painting all links (Note that this code not handle link selection when the editor is editable):

  public void paintLinks(Graphics2D g2) {
    g2.setColor(Color.black);
    for (int i = 0; i < getNetObjectNumber() ; i++) {
      NetObject o = getNetObjectAt(i);
      for (int j = 0; j < o.getChildrenNumber() ; j++ ) {
        o.paintLink(g2,o.getChildAt(j),true);
      }
    }
  }

Parameters:
g2 - Graphics object
See Also:
paintObjects(java.awt.Graphics2D)

paintObjects

public void paintObjects(java.awt.Graphics2D g2)
Paint object of the scheme. Called by paint() after paintLinks(). You can override it to custom the object painting.

  public void paintObjects(Graphics2D g2) {
    for (int i = 0; i < getNetObjectNumber() ; i++)
      getNetObjectAt(i).paint(g2);
  }

Parameters:
g2 - Graphics object
See Also:
paintLinks(java.awt.Graphics2D)

paint

public void paint(java.awt.Graphics g)
Paint the component. It is not recommended to override paint(). If you want to custom link and object painting , it is preferable to override paintLinks() and paintObjects().

Overrides:
paint in class javax.swing.JComponent
Parameters:
g - Graphics object
See Also:
paintLinks(java.awt.Graphics2D), paintObjects(java.awt.Graphics2D)