Class BlobPanel2

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public abstract class BlobPanel2 extends JComponent
Component which allows the user to draw a blob using the mouse. You drag the mouse around to cover patches of the component; you can create several separate or overlapping blobs by doing several click-drag sequences. If you drag off the window the currently-dragged region will be ditched. Clicking with the right button removes the most recently-added blob. Resizing the window clears any existing blobs (since it's not obvious how or if to resize the blobs). Try it, it's easy.
Since:
8 Jul 2004
Author:
Mark Taylor (Starlink)
See Also:
  • Field Details

  • Constructor Details

    • BlobPanel2

      public BlobPanel2()
      Constructor.
  • Method Details

    • getBlob

      public Shape getBlob()
      Returns the currently-defined blob.
      Returns:
      shape drawn
    • setBlob

      public void setBlob(Shape blob)
      Sets the currently-defined blob.
      Parameters:
      blob - shape to be displayed and played around with by the user
    • clear

      public void clear()
      Resets the current blob to an empty shape.
    • getBlobAction

      public Action getBlobAction()
      Returns the action which is used to start and stop blob drawing. Invoking the action toggles the activity status of this panel, and when invoked for deactivation (that is after a blob has been drawn) then blobCompleted(java.awt.Shape) is called.
      Returns:
      activation toggle action
    • setActive

      public void setActive(boolean active)
      Sets whether this panel is active (visible, accepting mouse gestures, drawing shapes) or inactive (invisible).
      Parameters:
      active - true to select activeness
    • setListening

      public void setListening(boolean isListening)
      Changes whether this component is listening to mouse gestures to modify the shape. This method is called by setActive, but may be called independently of it as well.
      Parameters:
      isListening - whether mouse gestures can affect current shape
    • isActive

      public boolean isActive()
      Indicates whether this blob is currently active.
      Returns:
      true iff this blob is active (visible and drawing)
    • blobCompleted

      protected abstract void blobCompleted(Shape blob)
      Invoked when this component's action is invoked to terminate a blob drawing session. Implementations of this method are expected to clear up by calling setActive(false) when the blob representation is no longer required.
      Parameters:
      blob - completed shape
    • setColors

      public void setColors(Color fillColor, Color pathColor)
      Sets the colours which will be used for drawing the blob.
      Parameters:
      fillColor - colour which fills the blob area
      pathColor - colour which delineates the blob region
    • paintComponent

      protected void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent