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 allFigureimplementations.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_FIGURESprotected static Handle[]NO_HANDLES
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractFigure()protectedAbstractFigure(FigureStyle normalStyle, FigureStyle selectedStyle)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChangeListener(FigureChangeListener listener)Adds a new change listener to this figure.booleanaddFigure(int index, Figure figure)Adds a child figure at the given index to this figure.booleanaddFigure(Figure figure)Adds a child figure to this figure.protected booleanaddFigureImpl(int index, Figure figure)The default implementation throws an [@code IllegalStateException}.protected booleanaddFigureImpl(Figure figure)Figure[]addFigures(Figure... figures)Adds a child figure at the given index to this figure.protected Figure[]addFiguresImpl(Figure[] figures)voidaddSegment(int index, double[] segment)Adds the segment at the given vertex index.Objectclone()booleancontains(Figure figure)The default implementation returnsfalse.Handle[]createHandles(int selectionStage)The default implementation returns an empty array.ObjectcreateMemento()The default implementation returns [@code null}.protected Handle[]createScaleHandles(double distance)voiddispose()Disposes this figure.protected voidfireFigureChanged()protected voidfireFigureChanged(FigureChangeEvent event)protected voidfireFiguresAdded(Figure... figures)protected voidfireFiguresRemoved(Figure... figures)FigureChangeListener[]getChangeListeners()FigureStylegetEffectiveStyle()FiguregetFigure(int index)The default implementation throws an [@code IllegalStateException}.FiguregetFigure(Point2D p, AffineTransform m2v)The default implementation returnsnull.intgetFigureCount()The default implementation returns0.intgetFigureIndex(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 FigureStylegetHandleStyle()intgetMaxSelectionStage()The default implementation returns zero.FigureStylegetNormalStyle()double[]getSegment(int index)Gets the segment at the given vertex index.protected FigureStylegetSelectedHandleStyle()FigureStylegetSelectedStyle()booleanisSelectable()The default implementation returnsfalse.booleanisSelected()Tests if the figure is selected.voidmove(double dx, double dy)Moves the figure by the given delta in model coordinates.Figure[]removeAllFigures()Removes all child figures from this figure.voidremoveChangeListener(FigureChangeListener listener)Removes a change listener from this figure.booleanremoveFigure(Figure figure)Removes a child figure from this figure.protected booleanremoveFigureImpl(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)voidremoveSegment(int index)Removes the segment at the given vertex index.voidrotate(Point2D point, double theta)Rotates the figure by the given angle.voidscale(Point2D point, double sx, double sy)Scales the figure by the given scale factors.voidsetMemento(Object memento)The default implementation does nothing.voidsetNormalStyle(FigureStyle normalStyle)Sets the style used for the "normal" state of the figure.voidsetSegment(int index, double[] segment)Sets the segment at the given vertex index.voidsetSelectable(boolean selectable)voidsetSelected(boolean selected)Sets the selected state.voidsetSelectedStyle(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:
isSelectablein interfaceFigure- Returns:
- Always
false.
-
setSelectable
public void setSelectable(boolean selectable)
-
isSelected
public boolean isSelected()
Description copied from interface:FigureTests if the figure is selected.- Specified by:
isSelectedin interfaceFigure- Returns:
true, if so.
-
setSelected
public void setSelected(boolean selected)
Description copied from interface:FigureSets the selected state.- Specified by:
setSelectedin interfaceFigure- Parameters:
selected- The selected state.
-
getNormalStyle
public FigureStyle getNormalStyle()
- Specified by:
getNormalStylein interfaceFigure- Returns:
- The style used for the "normal" state of the figure.
-
setNormalStyle
public void setNormalStyle(FigureStyle normalStyle)
Description copied from interface:FigureSets the style used for the "normal" state of the figure.- Specified by:
setNormalStylein interfaceFigure- Parameters:
normalStyle- The style used for the "normal" state of the figure.
-
getSelectedStyle
public FigureStyle getSelectedStyle()
- Specified by:
getSelectedStylein interfaceFigure- Returns:
- The style used for the "selected" state of the figure.
-
setSelectedStyle
public void setSelectedStyle(FigureStyle selectedStyle)
Description copied from interface:FigureSets the style used for the "selected" state of the figure.- Specified by:
setSelectedStylein interfaceFigure- Parameters:
selectedStyle- The style used for the "selected" state of the figure.
-
getEffectiveStyle
public FigureStyle getEffectiveStyle()
- Specified by:
getEffectiveStylein 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:
getFigureCountin interfaceFigure- Returns:
- Always
0.
-
getFigureIndex
public int getFigureIndex(Figure figure)
The default implementation returns0.- Specified by:
getFigureIndexin 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:
getFiguresin 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:
getFiguresin interfaceFigure- Returns:
- Always an empty array.
-
addFigure
public boolean addFigure(Figure figure)
Description copied from interface:FigureAdds a child figure to this figure.
-
addFigure
public boolean addFigure(int index, Figure figure)Description copied from interface:FigureAdds a child figure at the given index to this figure.
-
addFigures
public Figure[] addFigures(Figure... figures)
Description copied from interface:FigureAdds a child figure at the given index to this figure.- Specified by:
addFiguresin 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:FigureRemoves a child figure from this figure.- Specified by:
removeFigurein 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:FigureRemoves the given child figures from this figure.- Specified by:
removeFiguresin 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:FigureRemoves all child figures from this figure.- Specified by:
removeAllFiguresin 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:FigureMoves the figure by the given delta in model coordinates.
-
scale
public void scale(Point2D point, double sx, double sy)
Description copied from interface:FigureScales the figure by the given scale factors.
-
rotate
public void rotate(Point2D point, double theta)
Description copied from interface:FigureRotates the figure by the given angle.
-
getSegment
public double[] getSegment(int index)
Description copied from interface:FigureGets the segment at the given vertex index.- Specified by:
getSegmentin 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:FigureSets the segment at the given vertex index.- Specified by:
setSegmentin 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:FigureAdds the segment at the given vertex index.- Specified by:
addSegmentin 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:FigureRemoves the segment at the given vertex index.- Specified by:
removeSegmentin interfaceFigure- Parameters:
index- The vertex index.
-
getMaxSelectionStage
public int getMaxSelectionStage()
The default implementation returns zero.- Specified by:
getMaxSelectionStagein 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:
createHandlesin 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:
createMementoin 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:
setMementoin interfaceRestorable- Parameters:
memento- A memento object.
-
addChangeListener
public void addChangeListener(FigureChangeListener listener)
Description copied from interface:FigureAdds a new change listener to this figure.- Specified by:
addChangeListenerin interfaceFigure- Parameters:
listener- The listener.
-
removeChangeListener
public void removeChangeListener(FigureChangeListener listener)
Description copied from interface:FigureRemoves a change listener from this figure.- Specified by:
removeChangeListenerin interfaceFigure- Parameters:
listener- The listener.
-
getChangeListeners
public FigureChangeListener[] getChangeListeners()
- Specified by:
getChangeListenersin interfaceFigure- Returns:
- The array of all change listeners registered with this figure.
-
dispose
public void dispose()
Description copied from interface:FigureDisposes 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()
-
-