Package com.bc.ceres.swing.figure
Class AbstractFigure
- java.lang.Object
-
- com.bc.ceres.swing.figure.AbstractFigure
-
- All Implemented Interfaces:
Figure
,Restorable
,Cloneable
- Direct Known Subclasses:
AbstractHandle
,AbstractPointFigure
,AbstractShapeFigure
,DefaultFigureCollection
public abstract class AbstractFigure extends Object implements Figure
Base class for allFigure
implementations.Provides support for the following properties:
selectable
,selected
,normalStyle
,selectedStyle
.- Since:
- Ceres 0.10
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.bc.ceres.swing.figure.Figure
Figure.Rank
-
-
Field Summary
Fields Modifier and Type Field Description protected static Figure[]
NO_FIGURES
protected static Handle[]
NO_HANDLES
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractFigure()
protected
AbstractFigure(FigureStyle normalStyle, FigureStyle selectedStyle)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChangeListener(FigureChangeListener listener)
Adds a new change listener to this figure.boolean
addFigure(int index, Figure figure)
Adds a child figure at the given index to this figure.boolean
addFigure(Figure figure)
Adds a child figure to this figure.protected boolean
addFigureImpl(int index, Figure figure)
The default implementation throws an [@code IllegalStateException}.protected boolean
addFigureImpl(Figure figure)
Figure[]
addFigures(Figure... figures)
Adds a child figure at the given index to this figure.protected Figure[]
addFiguresImpl(Figure[] figures)
void
addSegment(int index, double[] segment)
Adds the segment at the given vertex index.Object
clone()
boolean
contains(Figure figure)
The default implementation returnsfalse
.Handle[]
createHandles(int selectionStage)
The default implementation returns an empty array.Object
createMemento()
The default implementation returns [@code null}.protected Handle[]
createScaleHandles(double distance)
void
dispose()
Disposes this figure.protected void
fireFigureChanged()
protected void
fireFigureChanged(FigureChangeEvent event)
protected void
fireFiguresAdded(Figure... figures)
protected void
fireFiguresRemoved(Figure... figures)
FigureChangeListener[]
getChangeListeners()
FigureStyle
getEffectiveStyle()
Figure
getFigure(int index)
The default implementation throws an [@code IllegalStateException}.Figure
getFigure(Point2D p, AffineTransform m2v)
The default implementation returnsnull
.int
getFigureCount()
The default implementation returns0
.int
getFigureIndex(Figure figure)
The default implementation returns0
.Figure[]
getFigures()
The default implementation returns an empty array.Figure[]
getFigures(Shape shape)
The default implementation returns an empty array.protected FigureStyle
getHandleStyle()
int
getMaxSelectionStage()
The default implementation returns zero.FigureStyle
getNormalStyle()
double[]
getSegment(int index)
Gets the segment at the given vertex index.protected FigureStyle
getSelectedHandleStyle()
FigureStyle
getSelectedStyle()
boolean
isSelectable()
The default implementation returnsfalse
.boolean
isSelected()
Tests if the figure is selected.void
move(double dx, double dy)
Moves the figure by the given delta in model coordinates.Figure[]
removeAllFigures()
Removes all child figures from this figure.void
removeChangeListener(FigureChangeListener listener)
Removes a change listener from this figure.boolean
removeFigure(Figure figure)
Removes a child figure from this figure.protected boolean
removeFigureImpl(Figure figure)
The default implementation throws an [@code IllegalStateException}.Figure[]
removeFigures(Figure... figures)
Removes the given child figures from this figure.protected Figure[]
removeFiguresImpl()
protected Figure[]
removeFiguresImpl(Figure[] figures)
void
removeSegment(int index)
Removes the segment at the given vertex index.void
rotate(Point2D point, double theta)
Rotates the figure by the given angle.void
scale(Point2D point, double sx, double sy)
Scales the figure by the given scale factors.void
setMemento(Object memento)
The default implementation does nothing.void
setNormalStyle(FigureStyle normalStyle)
Sets the style used for the "normal" state of the figure.void
setSegment(int index, double[] segment)
Sets the segment at the given vertex index.void
setSelectable(boolean selectable)
void
setSelected(boolean selected)
Sets the selected state.void
setSelectedStyle(FigureStyle selectedStyle)
Sets the style used for the "selected" state of the figure.
-
-
-
Constructor Detail
-
AbstractFigure
protected AbstractFigure()
-
AbstractFigure
protected AbstractFigure(FigureStyle normalStyle, FigureStyle selectedStyle)
-
-
Method Detail
-
isSelectable
public boolean isSelectable()
The default implementation returnsfalse
.- Specified by:
isSelectable
in interfaceFigure
- Returns:
- Always
false
.
-
setSelectable
public void setSelectable(boolean selectable)
-
isSelected
public boolean isSelected()
Description copied from interface:Figure
Tests if the figure is selected.- Specified by:
isSelected
in interfaceFigure
- Returns:
true
, if so.
-
setSelected
public void setSelected(boolean selected)
Description copied from interface:Figure
Sets the selected state.- Specified by:
setSelected
in interfaceFigure
- Parameters:
selected
- The selected state.
-
getNormalStyle
public FigureStyle getNormalStyle()
- Specified by:
getNormalStyle
in interfaceFigure
- Returns:
- The style used for the "normal" state of the figure.
-
setNormalStyle
public void setNormalStyle(FigureStyle normalStyle)
Description copied from interface:Figure
Sets the style used for the "normal" state of the figure.- Specified by:
setNormalStyle
in interfaceFigure
- Parameters:
normalStyle
- The style used for the "normal" state of the figure.
-
getSelectedStyle
public FigureStyle getSelectedStyle()
- Specified by:
getSelectedStyle
in interfaceFigure
- Returns:
- The style used for the "selected" state of the figure.
-
setSelectedStyle
public void setSelectedStyle(FigureStyle selectedStyle)
Description copied from interface:Figure
Sets the style used for the "selected" state of the figure.- Specified by:
setSelectedStyle
in interfaceFigure
- Parameters:
selectedStyle
- The style used for the "selected" state of the figure.
-
getEffectiveStyle
public FigureStyle getEffectiveStyle()
- Specified by:
getEffectiveStyle
in interfaceFigure
- Returns:
- The effective style used for the current state of the figure.
-
contains
public boolean contains(Figure figure)
The default implementation returnsfalse
.
-
getFigureCount
public int getFigureCount()
The default implementation returns0
.- Specified by:
getFigureCount
in interfaceFigure
- Returns:
- Always
0
.
-
getFigureIndex
public int getFigureIndex(Figure figure)
The default implementation returns0
.- Specified by:
getFigureIndex
in interfaceFigure
- Parameters:
figure
- The child figure to look up.- Returns:
- Always
0
.
-
getFigure
public Figure getFigure(Point2D p, AffineTransform m2v)
The default implementation returnsnull
.
-
getFigures
public Figure[] getFigures(Shape shape)
The default implementation returns an empty array.- Specified by:
getFigures
in interfaceFigure
- Parameters:
shape
- The shape defining the area in which the figures must be contained.- Returns:
- Always an empty array.
-
getFigures
public Figure[] getFigures()
The default implementation returns an empty array.- Specified by:
getFigures
in interfaceFigure
- Returns:
- Always an empty array.
-
addFigure
public boolean addFigure(Figure figure)
Description copied from interface:Figure
Adds a child figure to this figure.
-
addFigure
public boolean addFigure(int index, Figure figure)
Description copied from interface:Figure
Adds a child figure at the given index to this figure.
-
addFigures
public Figure[] addFigures(Figure... figures)
Description copied from interface:Figure
Adds a child figure at the given index to this figure.- Specified by:
addFigures
in interfaceFigure
- Parameters:
figures
- The array of new child figures.- Returns:
- The array of child figures that actually have been added.
-
removeFigure
public boolean removeFigure(Figure figure)
Description copied from interface:Figure
Removes a child figure from this figure.- Specified by:
removeFigure
in interfaceFigure
- Parameters:
figure
- The new child figure.- Returns:
true
, if the child has been removed.
-
removeFigures
public Figure[] removeFigures(Figure... figures)
Description copied from interface:Figure
Removes the given child figures from this figure.- Specified by:
removeFigures
in interfaceFigure
- Parameters:
figures
- The array of child figures to remove.- Returns:
- The array of child figures that actually have been removed.
-
removeAllFigures
public Figure[] removeAllFigures()
Description copied from interface:Figure
Removes all child figures from this figure.- Specified by:
removeAllFigures
in interfaceFigure
- Returns:
- The array of child figures that actually have been removed.
-
getFigure
public Figure getFigure(int index)
The default implementation throws an [@code IllegalStateException}.
-
addFigureImpl
protected boolean addFigureImpl(int index, Figure figure)
The default implementation throws an [@code IllegalStateException}.- Parameters:
index
- The index.figure
- The figure.- Returns:
- Does never return normally.
-
addFigureImpl
protected boolean addFigureImpl(Figure figure)
-
removeFigureImpl
protected boolean removeFigureImpl(Figure figure)
The default implementation throws an [@code IllegalStateException}.- Parameters:
figure
- The figure.- Returns:
- Does never return normally.
-
removeFiguresImpl
protected Figure[] removeFiguresImpl()
-
move
public void move(double dx, double dy)
Description copied from interface:Figure
Moves the figure by the given delta in model coordinates.
-
scale
public void scale(Point2D point, double sx, double sy)
Description copied from interface:Figure
Scales the figure by the given scale factors.
-
rotate
public void rotate(Point2D point, double theta)
Description copied from interface:Figure
Rotates the figure by the given angle.
-
getSegment
public double[] getSegment(int index)
Description copied from interface:Figure
Gets the segment at the given vertex index.- Specified by:
getSegment
in interfaceFigure
- Parameters:
index
- The vertex index.- Returns:
- The segment coordinates. X is the first element, Y the second.
-
setSegment
public void setSegment(int index, double[] segment)
Description copied from interface:Figure
Sets the segment at the given vertex index.- Specified by:
setSegment
in interfaceFigure
- Parameters:
index
- The vertex index.segment
- The segment coordinates. X is the first element, Y the second.
-
addSegment
public void addSegment(int index, double[] segment)
Description copied from interface:Figure
Adds the segment at the given vertex index.- Specified by:
addSegment
in interfaceFigure
- Parameters:
index
- The vertex index.segment
- The segment coordinates. X is the first element, Y the second.
-
removeSegment
public void removeSegment(int index)
Description copied from interface:Figure
Removes the segment at the given vertex index.- Specified by:
removeSegment
in interfaceFigure
- Parameters:
index
- The vertex index.
-
getMaxSelectionStage
public int getMaxSelectionStage()
The default implementation returns zero.- Specified by:
getMaxSelectionStage
in interfaceFigure
- Returns:
- Always
0
.
-
createHandles
public Handle[] createHandles(int selectionStage)
The default implementation returns an empty array. Clients should override in order to create an array of handles suitable for the given selection stage.- Specified by:
createHandles
in interfaceFigure
- Parameters:
selectionStage
- The selection stage.1 <= selectionLevel <=
getMaxSelectionStage()
- Returns:
- The array of handles.
-
createMemento
public Object createMemento()
The default implementation returns [@code null}. Clients should override in order to produce something more meaningful.- Specified by:
createMemento
in interfaceRestorable
- Returns:
- Always
null
.
-
setMemento
public void setMemento(Object memento)
The default implementation does nothing. Clients should override in order to evaluate the passed inmemento
. object.- Specified by:
setMemento
in interfaceRestorable
- Parameters:
memento
- A memento object.
-
addChangeListener
public void addChangeListener(FigureChangeListener listener)
Description copied from interface:Figure
Adds a new change listener to this figure.- Specified by:
addChangeListener
in interfaceFigure
- Parameters:
listener
- The listener.
-
removeChangeListener
public void removeChangeListener(FigureChangeListener listener)
Description copied from interface:Figure
Removes a change listener from this figure.- Specified by:
removeChangeListener
in interfaceFigure
- Parameters:
listener
- The listener.
-
getChangeListeners
public FigureChangeListener[] getChangeListeners()
- Specified by:
getChangeListeners
in interfaceFigure
- Returns:
- The array of all change listeners registered with this figure.
-
dispose
public void dispose()
Description copied from interface:Figure
Disposes this figure. Indicates that it will no longer be used.
-
clone
public Object clone()
-
fireFiguresAdded
protected void fireFiguresAdded(Figure... figures)
-
fireFiguresRemoved
protected void fireFiguresRemoved(Figure... figures)
-
fireFigureChanged
protected void fireFigureChanged()
-
fireFigureChanged
protected void fireFigureChanged(FigureChangeEvent event)
-
createScaleHandles
protected Handle[] createScaleHandles(double distance)
-
getHandleStyle
protected FigureStyle getHandleStyle()
-
getSelectedHandleStyle
protected FigureStyle getSelectedHandleStyle()
-
-