Class LightTable

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class LightTable extends JLayeredPane
A LightTable is a container that places an invisible drawing table on top of another component and allows that component to become a drawing surface. When activated, the LightTable listens for mouse events on the surface and draws rubber-band lines according to one of various drawing modes. It then reports the results of the drawing operation via a change event.
Since:
3.1.2
Author:
Peter Hollemans
See Also:
  • Constructor Details

    • LightTable

      public LightTable(JComponent component)
      Creates a new table using the specified component as the base layer. The stroke is set to the default basic stroke and the drawing mode to point mode. By default the table is inactive.
      Parameters:
      component - the component to use as a base layer.
  • Method Details

    • addDoubleClickListener

      public void addDoubleClickListener(MouseListener listener)
      Since:
      3.8.1
    • getComponent

      public JComponent getComponent()
      Gets the component used as a base layer for this table.
    • doLayout

      public void doLayout()
      Overrides:
      doLayout in class Container
    • setForeground

      public void setForeground(Color color)
      Overrides:
      setForeground in class JComponent
    • setBackground

      public void setBackground(Color color)
      Overrides:
      setBackground in class JComponent
    • addMouseListener

      public void addMouseListener(MouseListener l)
      Overrides the parent to add the listener to the base layer component.
      Overrides:
      addMouseListener in class Component
    • addMouseMotionListener

      public void addMouseMotionListener(MouseMotionListener l)
      Overrides the parent to add the listener to the base layer component.
      Overrides:
      addMouseMotionListener in class Component
    • removeChangeListener

      public void removeChangeListener(ChangeListener listener)
      Removes the specified change listener from the listeners list.
    • addChangeListener

      public void addChangeListener(ChangeListener listener)
      Adds a change listener to the listeners list. A change event is fired when the light table detects the finished drawing. The finished shape may be retrieved using getShape.
    • getActive

      public boolean getActive()
      Gets the light table activity mode.
    • setActive

      public void setActive(boolean flag)
      Sets the light table active or inactive.
    • getCursor

      public Cursor getCursor()
      Gets the cursor appropriate for the current drawing mode.
      Overrides:
      getCursor in class Component
      Returns:
      the appropriate cursor.
    • getDrawingMode

      public LightTable.Mode getDrawingMode()
      Gets the drawing mode.
    • setDrawingMode

      public void setDrawingMode(LightTable.Mode mode)
      Sets the drawing mode to the specified mode.
    • getShape

      public Shape getShape()
      Gets the current user shape. The shape differs depending on the drawing mode as follows:
      • Mode.POINT = Line2D
      • Mode.LINE = Line2D
      • Mode.POLYLINE = GeneralPath
      • Mode.BOX = Rectangle2D
      • Mode.BOX_ZOOM = Rectangle2D
      • Mode.CIRCLE = Ellipse2D
      • Mode.GENERAL_PATH = Line2D
      • Mode.IMAGE = Line2D
      • Mode.IMAGE_TRANSLATE = Line2D
      • Mode.IMAGE_ROTATE = Line2D
      Returns:
      the current user shape or null if not available.
    • main

      public static void main(String[] argv)
      Tests this class.
      Parameters:
      argv - the array of command line parameters.