geofasc.swing
public abstract class AbstractFigure extends JPanel implements ChangeListener, ContainerListener
AbstractFigure
serves as the abstract base class for all
components visualizing 2-dimensional geometric figures like rectangle, circle
or line segments.
AbstractFigure
and its sub-classes provide an object-oriented
and Swing-compliant approach to (geometric) figures: Actually, any figure can
be drawn by calling a draw
-method on a Graphics
object.
But figures drawn that way can not be treated and accessed as objects/
components and no distinction between them is possible in object-oriented
manner.
Since an AbstractFigure
is abstract it can not be seen as
specific figure. It rather represents the rectangular bounding box of a
specific figure and provides access for reading its size and location (in
fact it delegates the calls to FigureModel
, see there for more
explanations). Of course, arranging figures is most meaningful on a common
parent component with a null-layout but is also possible with any other
layout even besides other Swing components. Moreover this class provides
access for the common visual properties of a figure like its line color.
Note, that an AbstractFigure
's properties must not mapped
one-to-one to its corresponding Swing properties. That means that, for
example a rectangle figure, can have another size than its visualizing
component. This distinction is necessary to be compatible with the layout
managers that might resize components themselves.FigureModel
,
DefaultFigureModel
,
FigureUI
,
BasicFigureUI
,
Serialized FormJComponent.AccessibleJComponent
Component.BaselineResizeBehavior
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
AbstractFigure()
Constructs a new
AbstractFigure at (x,y)
-location (0,0) . |
AbstractFigure(int x,
int y)
Constructs a new
AbstractFigure at the given location. |
Modifier and Type | Method and Description |
---|---|
void |
componentAdded(ContainerEvent e)
Overridden for automatically calling methods
JComponent.revalidate() and
Component.repaint() if a child component is added to this figure and the
figure has been already displayed. |
void |
componentRemoved(ContainerEvent e)
Overridden for automatically calling methods
JComponent.revalidate() and
Component.repaint() if a child component is removed from this figure and
the figure has been already displayed. |
Rectangle |
getFigureBounds()
|
Rectangle |
getFigureBounds(Rectangle bounds)
|
double |
getFigureDirection()
|
Color |
getFigureFillColor()
|
int |
getFigureHeight()
|
Color |
getFigureLineColor()
|
Point |
getFigureLocation()
|
int |
getFigureLocationX()
|
int |
getFigureLocationY()
|
Dimension |
getFigureSize()
|
int |
getFigureWidth()
|
Dimension |
getMinimumSize() |
FigureModel |
getModel()
Returns the data model of this figure.
|
Dimension |
getPreferredSize() |
FigureUI |
getUI() |
String |
getUIClassID() |
boolean |
isFigureFilled()
|
boolean |
isSelfContainerListener()
Returns whether this figure is its own container listener.
|
void |
moveFigureLocationBy(int pixels)
|
void |
moveFigureLocationBy(int dx,
int dy)
|
void |
moveFigureLocationBy(Point dPoint)
|
void |
moveFigureLocationXBy(int dx)
|
void |
moveFigureLocationYBy(int dy)
|
void |
setFigureDirection(double direction)
|
void |
setFigureFillColor(Color fillColor)
|
void |
setFigureFilled(boolean isFilled)
|
void |
setFigureLineColor(Color lineColor)
|
void |
setFigureLocation(int x,
int y)
|
void |
setFigureLocation(Point p)
|
void |
setFigureLocationX(int x)
|
void |
setFigureLocationY(int y)
|
void |
setMaximumSize(Dimension maximumSize) |
void |
setModel(FigureModel model)
Sets the model of this figure.
|
void |
setSelfContainerListener(boolean b)
Sets this figure as its own container listener.
|
void |
setUI(FigureUI ui)
Sets the look and feel (L&F) object that renders this figure.
|
void |
stateChanged(ChangeEvent e) |
void |
turnFigureDirectionBy(double dDirection)
|
void |
turnFigureDirectionTo(double direction)
|
void |
updateUI() |
getAccessibleContext, setUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public AbstractFigure()
AbstractFigure
at (x,y)
-location (0,0)
.public AbstractFigure(int x, int y)
AbstractFigure
at the given location.x
- the initial x-location of this figurey
- the initial y-location of this figurepublic void componentAdded(ContainerEvent e)
JComponent.revalidate()
and
Component.repaint()
if a child component is added to this figure and the
figure has been already displayed.
Actually this has to be done manually calling the mentioned methods for
efficiency reasons (e.g., adding multiple components to this figure). To
do more efficiently call setSelfContainerListener(boolean)
with
false
to deactivate this figure as its own container
listener, then add the components and fo revalidating as well as
repainting manually.componentAdded
in interface ContainerListener
public void componentRemoved(ContainerEvent e)
JComponent.revalidate()
and
Component.repaint()
if a child component is removed from this figure and
the figure has been already displayed.
Actually this has to be done manually calling the mentioned methods for
efficiency reasons (e.g., removing multiple or all child components of
this figure). To do more efficiently call
setSelfContainerListener(boolean)
with false
to
deactivate this figure as its own container listener, then remove the
components and do validating as well as repainting manually.componentRemoved
in interface ContainerListener
public Dimension getMinimumSize()
getMinimumSize
in class JComponent
public FigureModel getModel()
FigureModel
public Dimension getPreferredSize()
getPreferredSize
in class JComponent
public String getUIClassID()
getUIClassID
in class JPanel
public void setMaximumSize(Dimension maximumSize)
setMaximumSize
in class JComponent
public void setModel(FigureModel model)
model
- the new modelpublic void setSelfContainerListener(boolean b)
b
- true or falsecomponentAdded(ContainerEvent)
,
componentRemoved(ContainerEvent)
public void setUI(FigureUI ui)
ui
- the new L&F objectpublic void stateChanged(ChangeEvent e)
stateChanged
in interface ChangeListener
public double getFigureDirection()
public Rectangle getFigureBounds()
public Color getFigureLineColor()
public Color getFigureFillColor()
public int getFigureHeight()
public Point getFigureLocation()
public int getFigureLocationX()
public int getFigureLocationY()
public Dimension getFigureSize()
public int getFigureWidth()
public boolean isFigureFilled()
public boolean isSelfContainerListener()
componentAdded(ContainerEvent)
,
componentRemoved(ContainerEvent)
,
setSelfContainerListener(boolean)
public void moveFigureLocationBy(int pixels)
public void moveFigureLocationBy(int dx, int dy)
public void moveFigureLocationBy(Point dPoint)
public void moveFigureLocationXBy(int dx)
public void moveFigureLocationYBy(int dy)
public void setFigureDirection(double direction)
public void setFigureFillColor(Color fillColor)
public void setFigureFilled(boolean isFilled)
public void setFigureLineColor(Color lineColor)
public void setFigureLocation(int x, int y)
public void setFigureLocation(Point p)
public void setFigureLocationX(int x)
public void setFigureLocationY(int y)
public void turnFigureDirectionTo(double direction)
public void turnFigureDirectionBy(double dDirection)