Class NetEditor

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
fr.esrf.tangoatk.widget.util.interlock.NetEditor
All Implemented Interfaces:
MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener
Direct Known Subclasses:
DjNetViewer, ItlkNetEditor

public class NetEditor extends JComponent implements MouseListener, MouseMotionListener
Network Editor component class. This class can be subclassed to create specific editor or viewer (not editable) component.
See Also:
  • Field Details

    • CREATE_NONE

      public static final int CREATE_NONE
      Selection mode (no creation)
      See Also:
    • CREATE_BUBBLE

      public static final int CREATE_BUBBLE
      Editor is in bubble creation mode
      See Also:
    • CREATE_TEXT

      public static final int CREATE_TEXT
      Editor is in text creation mode (Free label)
      See Also:
  • Constructor Details

    • 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(JFrame parent)
      Contruct a Network Editor.
      Parameters:
      parent - Parent frame
  • Method Details

    • 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:
    • setFileExtension

      public void setFileExtension(String ext)
      Sets the file extension for this editor.
      Parameters:
      ext - File extension
    • getFileExtension

      public String getFileExtension()
      Returns:
      the file extension of this editor
    • loadFile

      public void loadFile(String fileName) throws IOException
      Load a Network file (net or xpss format) into the editor. Trigger sizeChanged() and valueChanged() on success.
      Parameters:
      fileName - filename to load
      Throws:
      IOException - in case of failure (Contains the error message)
      See Also:
    • showOpenFileDialog

      public void showOpenFileDialog(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:
    • saveNetFile

      public void saveNetFile(String fileName) throws IOException
      Save the editor content to a net file.
      Parameters:
      fileName - filename to save
      Throws:
      IOException - in case of failure
    • showSaveFileDialog

      public void showSaveFileDialog(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:
    • saveCurrent

      public void saveCurrent(String defaultDir)
      Save the current scheme.
      Parameters:
      defaultDir - default directory for filebox if no filename has been set.
      See Also:
    • 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:
    • 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:
    • 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()
      Returns:
      undo state
    • getUndoActionName

      public String getUndoActionName()
      Returns:
      the name of the last action performed
    • getRedoActionName

      public String getRedoActionName()
      Returns:
      the name of the last action undone
    • canRedo

      public boolean canRedo()
      Returns:
      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:
    • removeEditorListener

      public void removeEditorListener(NetEditorListener l)
      Remove a NetEditor listener.
      Parameters:
      l - Editor listener.
      See Also:
    • clearEditorListener

      public void clearEditorListener()
      Clears the NetEditor listener list.
      See Also:
    • 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:
    • getFileName

      public 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.
      Parameters:
      dlg - NetEditor dialog
    • setNetObjectDialog

      public void setNetObjectDialog(NetObjectDlg dlg)
      Sets the object properties dialog. Allows to build a custoimized Object editon dialog.
      Parameters:
      dlg - NetObjectDlg Dialog
    • setMoveableBubble

      public void setMoveableBubble(boolean b)
      Allow the user to move bubble object even when the editor is not editable
      Parameters:
      b - Moveable flag
    • getParentFrame

      public JFrame getParentFrame()
      Returns:
      the parent frame or null
    • setGridSize

      public void setGridSize(Dimension d)
      Sets the grid size of this NetEditor.
      Parameters:
      d - Grid dimension
    • getGridSize

      public Dimension getGridSize()
      Returns:
      current grid size.
    • mouseDragged

      public void mouseDragged(MouseEvent e)
      Specified by:
      mouseDragged in interface MouseMotionListener
    • mouseMoved

      public void mouseMoved(MouseEvent e)
      Specified by:
      mouseMoved in interface MouseMotionListener
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent e)
      Specified by:
      mouseExited in interface MouseListener
    • mouseClickedB3

      public void mouseClickedB3(MouseEvent e)
    • mouseClickedB1

      public void mouseClickedB1(MouseEvent e)
    • mouseClicked

      public void mouseClicked(MouseEvent e)
      Specified by:
      mouseClicked in interface MouseListener
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Specified by:
      mouseReleased in interface MouseListener
    • mousePressedB1

      public void mousePressedB1(MouseEvent e)
    • mousePressedB3

      public void mousePressedB3(MouseEvent e)
    • mousePressed

      public void mousePressed(MouseEvent e)
      Specified by:
      mousePressed in interface MouseListener
    • paintLinks

      public void paintLinks(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

      public void paintObjects(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:
    • paint

      public void paint(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 JComponent
      Parameters:
      g - Graphics object
      See Also: