Class TLcdGXYDragRectangleController

All Implemented Interfaces:
ILcdUndoableSource, ILcdStatusSource, ILcdGXYController, KeyListener, MouseListener, MouseMotionListener, Serializable, EventListener
Direct Known Subclasses:
TLcdGXYSelectController, TLcdGXYSelectController2, TLcdGXYZoomController

public class TLcdGXYDragRectangleController extends ALcdGXYSmartController implements MouseListener, MouseMotionListener
This is an ILcdGXYController that interprets mouse events for dragging a rectangle on a ILcdGXYView. Redefine trigger for implementing specific behavior with the "created" java.awt.Rectangle given as argument.
See Also:
  • Field Details

  • Constructor Details

    • TLcdGXYDragRectangleController

      public TLcdGXYDragRectangleController()
    • TLcdGXYDragRectangleController

      public TLcdGXYDragRectangleController(boolean aRegisterInstance)
      Deprecated.
      use the constructor without parameters.
  • Method Details

    • setTraceOn

      public void setTraceOn(boolean aTraceOn)
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Enables tracing for this class instance. Calling this method with either true or false as argument automatically turns off tracing for all other class instances for which setTraceOn has not been called. If the argument is false then only the informative, warning and error log messages are recorded.
      Overrides:
      setTraceOn in class ALcdGXYSmartController
      Parameters:
      aTraceOn - if true then all log messages are recorded for this instance. If false, then only the informative, warning and error log messages are recorded.
    • isTraceOn

      public boolean isTraceOn()
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Returns true if tracing is enabled for this class.
      Overrides:
      isTraceOn in class ALcdGXYSmartController
      Returns:
      true if tracing is enabled for this class, false otherwise.
    • setGhostLineWidth

      public void setGhostLineWidth(int aGhostLineWidth)
      Parameters:
      aGhostLineWidth - the line width of the dragged rectangle
    • getGhostLineWidth

      public int getGhostLineWidth()
      See Also:
    • setGhostColor

      public void setGhostColor(Color aGhostColor)
      Parameters:
      aGhostColor - the Color of the dragged rectangle
    • getGhostColor

      public Color getGhostColor()
      Returns:
      the Color of the dragged rectangle.
    • setForceToSquare

      public void setForceToSquare(boolean aForceToSquare)
      Parameters:
      aForceToSquare - if true, force the rectangle to be a square.
    • isForceToSquare

      public boolean isForceToSquare()
      Returns:
      true, if this TLcdGXYDragRectangleController force the rectangle to be a square. Default value if false.
    • setDragCentered

      public void setDragCentered(boolean aDragCentered)
      Parameters:
      aDragCentered - if true, the center of the dragged rectangle will stay where the mouse has been pressed. If false, it will be at the center of the rectangle defined by where the mouse has been pressed, and it current location. Default value if true.
    • isDragCentered

      public boolean isDragCentered()
      See Also:
    • setRepaintOnReleased

      public void setRepaintOnReleased(boolean aRepaintOnReleased)
      Parameters:
      aRepaintOnReleased - if true, this TLcdGXYDragRectangleController will repaint the ILcdGXYView on mouseReleased. Default if true.
    • isRepaintOnReleased

      public boolean isRepaintOnReleased()
      See Also:
    • setXORMode

      public void setXORMode(boolean aXORMode)
      Sets if the dragged rectangle should be drawn in XOR mode.
      Parameters:
      aXORMode - if true, the dragged rectangle is drawn in XORMode. If false, the rectangle is drawn using the graphics' paint mode.
    • isXORMode

      public boolean isXORMode()
      Returns if the dragged rectangle is drawn in XOR mode.
      Returns:
      true if the dragged rectangle is drawn in XORMode. false if the rectangle is drawn using the graphics' paint mode.
      See Also:
    • setXORModeColor

      public void setXORModeColor(Color aXORModeColor)
      Sets the XOR mode color of the dragged rectangle. Only applies to the XOR mode.
      Parameters:
      aXORModeColor - the new color to use
      See Also:
    • getXORModelColor

      public Color getXORModelColor()
      Returns the XOR mode color of the dragged rectangle. Only applies to the XOR mode.
      Returns:
      the XOR mode color of the dragged rectangle
      See Also:
    • isHaloEnabled

      public boolean isHaloEnabled()
      Returns if the dragged rectangle is painted with a halo.
      Returns:
      true if the dragged rectangle is painted with a halo
      See Also:
    • setHaloEnabled

      public void setHaloEnabled(boolean aHaloEnabled)
      Sets if the dragged rectangle should be painted with a halo. A halo is an outline of constant width and color around shapes or text, which is typically drawn in a contrasting color to ensure that the shapes or text are clearly visible on any background.
      Note that the halo functionality cannot be combined with XOR mode painting.
      Parameters:
      aHaloEnabled - if true, the dragged rectangle is drawn with a halo
      See Also:
    • getHaloColor

      public Color getHaloColor()
      Returns the color of the dragged rectangle's halo.
      Returns:
      the color of the dragged rectangle's halo
      See Also:
    • setHaloColor

      public void setHaloColor(Color aColor)
      Sets the color of the dragged rectangle's halo.
      Parameters:
      aColor - the new halo color to use. If the halo is enabled, the dragged rectangle will be outlined on both sides using this color.
      See Also:
    • getHaloThickness

      public int getHaloThickness()
      Returns the dragged rectangle's halo thickness.
      Returns:
      the current halo thickness in pixels
      See Also:
    • setHaloThickness

      public void setHaloThickness(int aThickness)
      Sets the thickness of the dragged rectangle's halo
      Parameters:
      aThickness - the new halo thickness in pixels
    • getCurrentRectangle

      public Rectangle getCurrentRectangle()
      Returns:
      the current dragged rectangle as a java.awt.Rectangle Do not attempt to keep reference of or change the returned Rectangle. Make a copy if necessary.
    • getMouseDraggedSensitivity

      public int getMouseDraggedSensitivity()
      This property defines the mouse dragged sensitivity. When a rectangle is dragged with a height or width smaller than the mouse pressed sensitivity it is not taken into account for painting. Note that trigger(java.awt.event.MouseEvent, java.awt.Rectangle) is invoked, regardless the sensitivity.
      See Also:
    • setMouseDraggedSensitivity

      public void setMouseDraggedSensitivity(int aMouseDraggedSensitivity)
      Sets the minimal width or height that a user needs to drag the mouse before the rectangle is taken into account for painting. Note that trigger(java.awt.event.MouseEvent, java.awt.Rectangle) is invoked, regardless the sensitivity.
      Parameters:
      aMouseDraggedSensitivity - The new sensitivity, in pixels.
      See Also:
    • drawGhost

      protected void drawGhost(int aX, int aY, int aWidth, int aHeight, Graphics aGraphics)
      Draws the given rectangle on aGraphics. Can be redefined.
    • mouseMoved

      public void mouseMoved(MouseEvent me)
      No operation
      Specified by:
      mouseMoved in interface MouseMotionListener
      Overrides:
      mouseMoved in class ALcdGXYSmartController
    • doPanGXYView

      protected void doPanGXYView(int aDeltaX, int aDeltaY)
      Description copied from class: ALcdGXYSmartController
      Performs the pan of this ILcdGXYController ILcdGXYView
      Overrides:
      doPanGXYView in class ALcdGXYSmartController
      Parameters:
      aDeltaX - delta along the X axis, in AWT pixels
      aDeltaY - delta along the Y axis, in AWT pixels
    • doZoomGXYView

      protected void doZoomGXYView(double aDoubleFactor)
      Description copied from class: ALcdGXYSmartController
      Performs the zoom of this ILcdGXYController ILcdGXYView
      Overrides:
      doZoomGXYView in class ALcdGXYSmartController
      Parameters:
      aDoubleFactor - zoom factor with which to multiply the view's scale
    • mouseDragged

      public void mouseDragged(MouseEvent me)
      Specified by:
      mouseDragged in interface MouseMotionListener
      Overrides:
      mouseDragged in class ALcdGXYSmartController
    • adaptRectangle

      protected void adaptRectangle(MouseEvent me, int aXPressed, int aYPressed)
      Adapts the rectangle to span the area that is marked by the coordinates the location of the mouse, and another position taking into account the properties forceToSquare and dragCentered.
      Parameters:
      me -
      aXPressed -
      aYPressed -
    • paint

      public void paint(Graphics aGraphics)
      Draws a rectangle on the given graphics if ALcdGXYSmartController.isDragging() returns true and if the rectangle is larger as getMouseDraggedSensitivity().
      Specified by:
      paint in interface ILcdGXYController
      Overrides:
      paint in class ALcdGXYController
      Parameters:
      aGraphics - The graphics to draw on.
    • mousePressed

      public void mousePressed(MouseEvent me)
      Specified by:
      mousePressed in interface MouseListener
      Overrides:
      mousePressed in class ALcdGXYSmartController
    • lastXPressed

      public int lastXPressed()
      Returns:
      the x coordinate where the last mousePressed occurred. This value is only valid between a mousePressed and a following mouseReleased. Then it is set to -1.
    • lastYPressed

      public int lastYPressed()
      Returns:
      the y coordinate where the last mousePressed occurred. This value is only valid between a mousePressed and a following mouseReleased. Then it is set to -1.
    • lastXReleased

      public int lastXReleased()
      Returns:
      the x coordinate where the last mouseReleased occurred. This value is only valid between a mouseReleased and a following mousePressed. Then it is set to -1.
    • lastYReleased

      public int lastYReleased()
      Returns:
      the y coordinate where the last mouseReleased occurred. This value is only valid between a mouseReleased and a following mousePressed. Then it is set to -1.
    • mouseReleased

      public void mouseReleased(MouseEvent me)
      Specified by:
      mouseReleased in interface MouseListener
      Overrides:
      mouseReleased in class ALcdGXYSmartController
    • trigger

      public void trigger(MouseEvent aMouseEvent, Rectangle aRectangleDragged)
      This method is called on mouseReleased. It can be redefined to implement specific behavior with the "created" java.awt.Rectangle given as argument.

      Extensions might want to verify if the given rectangle is larger as the drag sensitivity, e.g.:

      
       aRectangleDragged.width  >= getMouseDraggedSensitivity() ||
       aRectangleDragged.height >= getMouseDraggedSensitivity()
       
      Parameters:
      aMouseEvent - the MouseEvent received on mouseReleased.
      aRectangleDragged - the dragged java.awt.Rectangle. Do not reuse this instance directly, make a copy instead.
    • undo

      public void undo()