Class JDrawEditor

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
fr.esrf.tangoatk.widget.util.jdraw.JDrawEditor
All Implemented Interfaces:
DropTargetListener, ActionListener, ComponentListener, KeyListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener
Direct Known Subclasses:
TangoSynopticHandler

The graph editor/viewer component.
See Also:
  • Field Details

    • MODE_EDIT

      public static final int MODE_EDIT
      Editor is in classic edition mode
      See Also:
    • MODE_EDIT_GROUP

      public static final int MODE_EDIT_GROUP
      Group edition mode, this is a restricted edition mode (no undo possible)
      See Also:
    • MODE_PLAY

      public static final int MODE_PLAY
      Play mode, play object according to their value , in this mode no contextual menu is displayed
      See Also:
    • MODE_LIB

      public static final int MODE_LIB
      Library mode, allow only selection and clipboard
      See Also:
    • CREATE_RECTANGLE

      public static final int CREATE_RECTANGLE
      Creation mode of the editor
      See Also:
    • CREATE_LINE

      public static final int CREATE_LINE
      Creation mode of the editor
      See Also:
    • CREATE_ELLIPSE

      public static final int CREATE_ELLIPSE
      Creation mode of the editor
      See Also:
    • CREATE_POLYLINE

      public static final int CREATE_POLYLINE
      Creation mode of the editor
      See Also:
    • CREATE_LABEL

      public static final int CREATE_LABEL
      Creation mode of the editor
      See Also:
    • CREATE_SPLINE

      public static final int CREATE_SPLINE
      Creation mode of the editor
      See Also:
    • CREATE_CLIPBOARD

      public static final int CREATE_CLIPBOARD
      Creation mode of the editor
      See Also:
    • CREATE_RRECTANGLE

      public static final int CREATE_RRECTANGLE
      Creation mode of the editor
      See Also:
    • CREATE_IMAGE

      public static final int CREATE_IMAGE
      Creation mode of the editor
      See Also:
    • CREATE_SWINGOBJECT

      public static final int CREATE_SWINGOBJECT
      Creation mode of the editor
      See Also:
    • CREATE_AXIS

      public static final int CREATE_AXIS
      Creation mode of the editor
      See Also:
    • CREATE_BAR

      public static final int CREATE_BAR
      Creation mode of the editor
      See Also:
    • CREATE_SLIDER

      public static final int CREATE_SLIDER
      Creation mode of the editor
      See Also:
    • CREATE_ROTATABLELABEL

      public static final int CREATE_ROTATABLELABEL
      Creation mode of the editor
      See Also:
  • Constructor Details

    • JDrawEditor

      public JDrawEditor(int mode)
      Contruct a JDraw editor in the specified mode.
      Parameters:
      mode - Mode of the editor
      See Also:
  • Method Details

    • setGridVisible

      public void setGridVisible(boolean b)
      Shows or hide the grid.
      Parameters:
      b - True to show the grid, false otherwise.
    • isGridVisible

      public boolean isGridVisible()
      Returns:
      whether the grid is visible.
    • setGridSize

      public void setGridSize(int size)
      Sets the grid step size.
      Parameters:
      size - Grid size (pixel)
    • getGridSize

      public int getGridSize()
      Returns:
      the current gid size.
      See Also:
    • setAlignToGrid

      public void setAlignToGrid(boolean b)
      When enabled, all moved control points and objects will be aligned to the grid.
      Parameters:
      b - True to align object to grid , false otherwise.
    • isAlignToGrid

      public boolean isAlignToGrid()
      Returns:
      whether object and control point are aligned to the grid.
      See Also:
    • getMode

      public int getMode()
      Returns:
      the mode of the editor.
    • selectObject

      public void selectObject(JDObject obj)
      Select the specified object. Does not fire selectionChanged().
      Parameters:
      obj - Object to be selected.
    • unselectObject

      public void unselectObject(JDObject obj)
      Unselect the specified object. Does not fire selectionChanged().
      Parameters:
      obj - Object to be deselected.
    • isSelected

      public boolean isSelected(JDObject obj)
      Parameters:
      obj - JDObject
      Returns:
      whether the specified object is selected.
      See Also:
    • selectObjects

      public void selectObjects(JDObject[] objs)
      Selects all specified objects.
      Parameters:
      objs - Array of JDObject to be selected.
    • getObjectNumber

      public int getObjectNumber()
      Returns:
      number of object
    • getObjectAt

      public JDObject getObjectAt(int idx)
      Parameters:
      idx - Object index.
      Returns:
      the JDObject at the specified position.
    • getObjects

      public Vector getObjects()
      Used for read only purpose , vector should not be modified by this way.
      Returns:
      Vector of objects
    • getSelectedObjects

      public Vector getSelectedObjects()
      Used for read only purpose , vector should not be modified by this way.
      Returns:
      Vector of selected objects
    • unselectAll

      public void unselectAll()
      Unselect all object
    • selectAll

      public void selectAll()
      Select all object
    • selectNotVisible

      public void selectNotVisible()
      Select non visible items
    • create

      public void create(int what)
      Sets the editor in creation mode.
      Parameters:
      what - Object to be created
      See Also:
    • create

      public void create(int what, String param)
      Sets the editor in creation mode.
      Parameters:
      what - Object to be created
      param - Optional parameters (used for JDSwingObject className)
      See Also:
    • getSelectionLength

      public int getSelectionLength()
      Returns:
      number of selected object
    • showPropertyWindow

      public void showPropertyWindow()
      Shows the property window
    • showTransformWindow

      public void showTransformWindow()
      Shows the property window
    • showBrowserWindow

      public void showBrowserWindow()
      Shows the object browser
    • showGroupEditorWindow

      public void showGroupEditorWindow()
      Shows the group editor dialog
    • generateJavaClasses

      public void generateJavaClasses(String dirName) throws IOException
      Generates java classes from the selection.
      Parameters:
      dirName - Directory where to generate files
      Throws:
      IOException - In case of failure
      See Also:
    • showGroupJavaWindow

      public void showGroupJavaWindow()
      Shows the java generation file selection box
    • copySelection

      public void copySelection()
      Copy selection to clipboard
    • pasteClipboard

      public void pasteClipboard(int x, int y, boolean fromOrigin)
      Paste the selection at the specified pos.
      Parameters:
      x - Up left corner x coordinate
      y - Up left corner y coordinate
      fromOrigin - Get coordinates from Top Left corner of clipboard
    • scaleSelection

      public void scaleSelection(double rx, double ry)
      Scale selection around the selection center.
      Parameters:
      rx - Horizontal sace ratio.
      ry - Vertical sace ratio.
    • cutSelection

      public void cutSelection()
      Move the selection to clipboard
    • deleteSelection

      public void deleteSelection()
      Delete selection from the draw
    • showSaveDialog

      public void showSaveDialog(String defaultDir)
      Show the file selection box and call saveFile if a file is selected. Trigger valueChanged() if a file is selected to be saved.
      Parameters:
      defaultDir - default directory
      See Also:
    • saveFile

      public void saveFile(String fileName) throws IOException
      Save the current drawing to a file.
      Parameters:
      fileName - File name
      Throws:
      IOException - Exception containing error message when failed.
    • getSaveString

      public StringBuffer getSaveString()
    • instantSave

      public void instantSave(String defaultDir)
      Save the current drawing to the file (Ask for filename if no filename has been previously set)
      Parameters:
      defaultDir - Default directory
    • loadFromStream

      protected void loadFromStream(InputStreamReader inp) throws IOException
      Load a jdraw grpahics input stream reader into the editor. Available only for play mode. The .jlx and .g files are not supported. This method is only called by TangoSynopticHandler which is in fact in Play mode.
      Parameters:
      inp - opened for the synoptic resource
      Throws:
      IOException - Exception containing error message when failed.
      See Also:
    • setRootPaths

      public void setRootPaths(String[] paths)
      CLASSPATH used for loading image (for netbeans plugins)
      Parameters:
      paths - List of path used for searching image
    • getRootPaths

      public String[] getRootPaths()
    • loadFile

      public void loadFile(String fileName) throws IOException
      Load a jdraw grpahics file into the editor Trigger valueChanged() if a file is selected to be loaded.
      Parameters:
      fileName - File name
      Throws:
      IOException - Exception containing error message when failed.
      See Also:
    • loadFile

      public void loadFile(String fileName, boolean clearUndoBuffer) throws IOException
      Load a jdraw grpahics file into the editor Trigger valueChanged() if a file is selected to be loaded.
      Parameters:
      fileName - File name
      clearUndoBuffer - true to clear the undo buffer
      Throws:
      IOException - Exception containing error message when failed.
      See Also:
    • showOpenDialog

      public void showOpenDialog(String defaultDir)
      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
      See Also:
    • frontSelection

      public void frontSelection()
      bring selected object to foreground
    • backSelection

      public void backSelection()
      send selected object to background
    • groupSelection

      public void groupSelection()
      group selected objects
    • ungroupSelection

      public void ungroupSelection()
      ungroup selected object
    • zoomIn

      public void zoomIn()
      Zoom In the graph
    • zoomOut

      public void zoomOut()
      Zoom Out the graph
    • getZoomFactorPercent

      public int getZoomFactorPercent()
      Returns:
      the zoom factor in percent
    • getZoomFactor

      public int getZoomFactor()
      Returns:
      the zoom factor value.
      See Also:
    • setZoomFactor

      public void setZoomFactor(int z)
      Sets the zoom factor. Does not have effect if autoZoom is enabled.
      Parameters:
      z - ZoomFactor ( -1=33% , 0=50% , 1=100% , 2=200% )
      See Also:
    • setAutoZoom

      public void setAutoZoom(boolean b)
      Sets the auto zoom. When auto zoom is enabled, the drawing area follows the window size. This works only in MODE_PLAY.
      Parameters:
      b - True to enable auto zoom, false otherwise.
      See Also:
    • setAutoZoomFactor

      public void setAutoZoomFactor(double ratio)
      Sets the initial autoZoom factor. This allows to start the player (PLAY_MOE) with an arbitrary size.
      Parameters:
      ratio - Zoom factor
    • isAutoZoom

      public boolean isAutoZoom()
      Returns:
      true is auto zoom is enabled, false otherwise.
      See Also:
    • isAutoZoomAsked

      public boolean isAutoZoomAsked()
      Returns:
      true if auto zoom asked in jdw file, false otherwise
      See Also:
    • translateSelection

      public void translateSelection(int x, int y)
      Translate selected Object
      Parameters:
      x - X translation
      y - Y translation
    • canUndo

      public boolean canUndo()
      Returns:
      undo state
    • canRedo

      public boolean canRedo()
      Returns:
      redo state
    • getLastActionName

      public String getLastActionName()
      Returns:
      name of the last action
    • getNextActionName

      public String getNextActionName()
      Returns:
      name of the action that can be redone
    • undo

      public void undo()
      Undo the last action
    • redo

      public void redo()
      Redo last canceled action
    • clearUndo

      public void clearUndo()
      Clear the undo buffer
    • aligntopSelection

      public void aligntopSelection()
      Align selection to top
    • alignleftSelection

      public void alignleftSelection()
      Align selection to left
    • alignbottomSelection

      public void alignbottomSelection()
      Align selection to bottom
    • alignrightSelection

      public void alignrightSelection()
      Align selection to right
    • addEditorListener

      public void addEditorListener(JDrawEditorListener l)
      Add an JDrawEditor listener.
      Parameters:
      l - Editor listener.
      See Also:
    • removeEditorListener

      public void removeEditorListener(JDrawEditorListener l)
      Remove an JDrawEditor listener.
      Parameters:
      l - Editor listener.
      See Also:
    • clearEditorListener

      public void clearEditorListener()
      Clears the JDrawEditor listener list.
      See Also:
    • getNeedToSaveState

      public boolean getNeedToSaveState()
      Returns:
      true if the drawing has been modofied and need to be saved
    • getFileName

      public String getFileName()
      Returns:
      the name of the last loaded file
    • addObject

      public void addObject(JDObject o)
      Add an object to the drawing. If you want to add dynamcaly object to this editor (in PLAY_MODE) , You should call initPlayer() after all objects are inserted.
      Parameters:
      o - Object to add
      See Also:
    • clearObjects

      public void clearObjects()
      Clear all object
    • setTranslation

      public void setTranslation(int x, int y)
      Set a global translation for the drawing area
      Parameters:
      x - X translation
      y - Y translation
    • computePreferredSize

      public void computePreferredSize()
      Compute the optimal size of the components and trigger sizeChanged()
    • setPreferredSize

      public void setPreferredSize(Dimension d)
      Overrides:
      setPreferredSize in class JComponent
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • getMinimumSize

      public Dimension getMinimumSize()
      Overrides:
      getMinimumSize in class JComponent
    • initPlayer

      public void initPlayer()
      Inits the player, This function should be called only if you want to build dynamicaly a graph with addObject(). Call it after all objects are inserted in the Editor. The call to this function is not absolutly needed. Call it only if you want to PLAY JDSwingObject or if you want to animate objects.
      See Also:
    • getObjectsOfClass

      public Vector getObjectsOfClass(Class theClass)
      Parameters:
      theClass - JDObject subclass
      Returns:
      all objects of the specified class present in the drawing area.
    • getObjectsByName

      public Vector getObjectsByName(String name, boolean recurseGroup)
      Parameters:
      name - JDObject name (Case sensitive)
      recurseGroup - true to perform a deep search whithin group, false otherwise.
      Returns:
      all objects having the given name present in the drawing area.
    • convertToPolyline

      public void convertToPolyline()
      Convert the selected objects to JDPolyline.
    • raiseObject

      public void raiseObject()
      Raise selected object.
    • lowerObject

      public void lowerObject()
      Move down selected object.
    • getInteractiveObjects

      public Vector getInteractiveObjects()
      Returns:
      all object that have the "User interaction" flag enabled.
    • setStatusLabel

      public void setStatusLabel(JLabel label)
      Sets the status label where are printed creation information.
      Parameters:
      label - Label
    • canPaste

      public boolean canPaste()
      Returns:
      true if the clipboard contains valid data
    • keyPressed

      public void keyPressed(KeyEvent e)
      Specified by:
      keyPressed in interface KeyListener
    • keyReleased

      public void keyReleased(KeyEvent e)
      Specified by:
      keyReleased in interface KeyListener
    • keyTyped

      public void keyTyped(KeyEvent e)
      Specified by:
      keyTyped in interface KeyListener
    • 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
    • mouseClicked

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

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

      public void mousePressedEditorB1(MouseEvent e)
    • mousePressedEditorB3

      public void mousePressedEditorB3(MouseEvent e)
    • mousePressedPlayerB1

      public void mousePressedPlayerB1(MouseEvent e)
    • mousePressedPlayerB3

      public void mousePressedPlayerB3(MouseEvent e)
    • mousePressed

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

      public void componentResized(ComponentEvent e)
      Specified by:
      componentResized in interface ComponentListener
    • componentMoved

      public void componentMoved(ComponentEvent e)
      Specified by:
      componentMoved in interface ComponentListener
    • componentShown

      public void componentShown(ComponentEvent e)
      Specified by:
      componentShown in interface ComponentListener
    • componentHidden

      public void componentHidden(ComponentEvent e)
      Specified by:
      componentHidden in interface ComponentListener
    • dragEnter

      public void dragEnter(DropTargetDragEvent dtde)
      Specified by:
      dragEnter in interface DropTargetListener
    • dragOver

      public void dragOver(DropTargetDragEvent dtde)
      Specified by:
      dragOver in interface DropTargetListener
    • dropActionChanged

      public void dropActionChanged(DropTargetDragEvent dtde)
      Specified by:
      dropActionChanged in interface DropTargetListener
    • dragExit

      public void dragExit(DropTargetEvent dte)
      Specified by:
      dragExit in interface DropTargetListener
    • drop

      public void drop(DropTargetDropEvent dtde)
      Specified by:
      drop in interface DropTargetListener
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Specified by:
      actionPerformed in interface ActionListener
    • paintObjects

      public void paintObjects(Graphics g)
      Paints all JDObjects of the components.
      Parameters:
      g - Graphics
    • paintSelection

      public void paintSelection(Graphics g)
      Paints selection area and control points.
      Parameters:
      g - Graphics
    • paint

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

      public void repaint(Rectangle r)
      Repaint the specified rectangle.
      Overrides:
      repaint in class JComponent
      Parameters:
      r - Rectangle to be repainted ('not zoomed' coordinates).
    • resetNeedToSave

      public void resetNeedToSave()
      Reset need to save bit to false
    • addToMenu

      public void addToMenu(JMenuItem newItem)