simtools.diagram
Class DiagramSelection

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Rectangle2D
          extended by java.awt.Rectangle
              extended by simtools.diagram.DiagramSelection
All Implemented Interfaces:
java.awt.Shape, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
ShapesContainer.GraphicSelection, TestComponent.TestSelection

public class DiagramSelection
extends java.awt.Rectangle

This class is used to define a selection area on a diagram

Version:
1.1 2001
Author:
Claude Cazenave
See Also:
DiagramComponent, Serialized Form

Nested Class Summary
 class DiagramSelection.ShapeHorizontalPositionComparator
          Sort shapes according their horizontal position.
 class DiagramSelection.ShapeVerticalPositionComparator
          Sort shapes according their vertical position.
 
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Float
 
Field Summary
 
Fields inherited from class java.awt.Rectangle
height, width, x, y
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
Constructor Summary
DiagramSelection()
          Creates a new empty diagram selection
 
Method Summary
protected  boolean add(DiagramSelectedShape dss)
          Adds a selected shape if it is not already selected
protected  boolean addAllShapes()
          Add all the shapes to the selection By overriding this method, one can use an other iterator on the shapes.
 void addListener(DiagramSelectionListener dcpl)
          Adds a new Listener on component selection
 boolean addPoint(int ox, int oy)
          Adds one shape to the selection at a given point.
protected  boolean addShapeAt(int ox, int oy)
          The first shape which contains the given coordinates is added to the selected shapes list.
protected  boolean addShapesInside()
          All the shapes which are inside the selection area By overriding this method, one can use an other iterator on the shapes.
 void alignSelection()
          Aligns the selected shapes
 void alignSelectionHCenter()
          Align the content of the selection on its horizontal barycentre
 void alignSelectionToBottom()
          Align the content of the selection on the bottom of the lowest shape
 void alignSelectionToLeft()
          Align the content of the selection on the left of the leftmost shape
 void alignSelectionToRight()
          Align the content of the selection on the right of the rightmost shape
 void alignSelectionToTop()
          Align the content of the selection on the top of the highest shape
 void alignSelectionVCenter()
          Align the content of the selection on its vertical barycentre
 void bringSelectionForward()
          Brings the selected shapes one step closer to the top of the display
 void bringSelectionToFront()
          Brings the selected shapes to the top of the display
 int checkResizeWay(int x, int y)
          Check if resize or translate is required This implementation can resize elements if the selection contains only one component that is not a DiagramConnection nor a DiagramConnector but a Resizable or a LineInterface object
protected  void clear()
          Removes all the selected shapes
 java.awt.Shape copyConnectionShape(java.awt.Shape s, DiagramConnector in, DiagramConnector out)
          Copies a connection shape This implementation creates nothing By overriding this method, specif shapes can be managed
 java.util.Vector copySelection(java.awt.Point p)
          Creates a copy of the selected shapes.
 java.awt.Shape copyShape(java.awt.Shape s)
          To copy a shape only Rectangle shapes are copied By overriding this method, specif shapes can be managed
 void deleteSelection()
          Deletes the selected shapes
 void deleteShape(java.awt.Shape s)
          Deletse a shape By overriding this method, one can use an other iterator on the shapes.
 void distributeSelectionHorizontally()
          Distributes the selected shapes so there is equal horizontal distance between the edges of all them
 void distributeSelectionVertically()
          Distributes the selected shapes so there is equal vertical distance between the edges of all them
 DiagramComponent getComponent()
          Gets the component using this diagram selection.
 int getGrid()
          Gets the grid step for translation computation
 DiagramSelectedShape getSelectedShape(int i)
          Gets the nth DiagramSelectedShape in the selection
 DiagramSelectedShape getSelectedShape(java.awt.Shape s)
          Checks if one shape is selected
 java.awt.Shape getSelectedShapeAt(int ox, int oy)
          Checks if a shape already selected contains a given point
 java.util.Vector getSelection()
          Gets a list of selected diagram elements
 java.awt.Shape getShape(int i)
          Gets the nth shape in the selection
 int getShapeCount()
          Gets the amount of shape in the selection
 java.awt.Point getShapeOrigin(java.awt.Shape s, java.awt.Point p)
          Computes shape origin before its move for a rectangle the top-left point coordinate is returned for a default shape the top-left point coordinate of its bounds is returned By overriding this method, specif shapes can be managed
 int gridPosition(int v)
          Gets the grid nearest position
 boolean isEmpty()
          Checks if the selection is empty
 boolean isSelected(int ox, int oy)
          Checks if a shape already selected contains a given point
 boolean isSelected(java.awt.Shape s)
          Checks if one shape is selected
 boolean isSizing()
          Checks if the selection is defined by a rectangle shape and the user is modifiing its size
protected  void propagate()
          Propagates to listeners
 void removeAllListeners()
          Removes all Listeners on component selection
 void removeListener(DiagramSelectionListener dcpl)
          Removes a Listener on component selection
 void removeShapeAt(int i)
          Removes one shape
 void resizeSelection(int dx, int dy, int way)
          Resize the selection This implementation can resize elements if the selection contains only one component and if this component is not a DaigramConnection nor a DiagramConnector but a Resizable object
 void resizeShape(java.awt.Shape s, int dx, int dy)
          Resizes a shape By overriding this method, specif shapes can be managed
 boolean selectAll()
          Selects all the shapes.
 boolean selectArea(int ox, int oy, int w, int h)
          Selects shapes inside an area Previous selected shapes are unselected.
 boolean selectAreaEnd()
          End of the definition of the area size The area rectangle is no more needed Selected shapes are the one computed at the previous call of selectArea
 boolean selectPoint(int ox, int oy)
          Selects one shape at the given point.
 void sendSelectionBackward()
          Sends the selected shapes one step deeper in the document
 void sendSelectionToBack()
          Sends the selected shapes to the bottom of the document
 void setGrid(int grid)
          Sets the grid step for translation computation
 void setShapes(java.util.Vector v)
          Sets shapes which can be selected (test only)
 void translateConnectionShape(java.awt.Shape s, DiagramConnector c, int dx, int dy)
          Translates a shape connected to an other one This implementation translates nothing By overriding this method, specif shapes can be managed
 void translateSelection(int dx, int dy)
          Translates the selected shapes
 void translateShape(java.awt.Shape s, int dx, int dy)
          Translates a shape only Rectangle shapes are translated By overriding this method, specif shapes can be managed
 void unselect()
          Empties the selection
 
Methods inherited from class java.awt.Rectangle
add, add, add, contains, contains, contains, contains, createIntersection, createUnion, equals, getBounds, getBounds2D, getHeight, getLocation, getSize, getWidth, getX, getY, grow, inside, intersection, intersects, move, outcode, reshape, resize, setBounds, setBounds, setLocation, setLocation, setRect, setSize, setSize, toString, translate, union
 
Methods inherited from class java.awt.geom.Rectangle2D
add, add, add, contains, contains, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, setRect, union
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.Shape
contains, contains, contains, contains, getPathIterator, getPathIterator, intersects, intersects
 

Constructor Detail

DiagramSelection

public DiagramSelection()
Creates a new empty diagram selection

Method Detail

getComponent

public DiagramComponent getComponent()
Gets the component using this diagram selection. Its an optional feture depending on the implementation

Returns:
the component or null if not available

propagate

protected void propagate()
Propagates to listeners


addListener

public void addListener(DiagramSelectionListener dcpl)
Adds a new Listener on component selection


removeListener

public void removeListener(DiagramSelectionListener dcpl)
Removes a Listener on component selection


removeAllListeners

public void removeAllListeners()
Removes all Listeners on component selection


setShapes

public void setShapes(java.util.Vector v)
Sets shapes which can be selected (test only)

Parameters:
v - the list of diagram selectable shapes

isSelected

public boolean isSelected(java.awt.Shape s)
Checks if one shape is selected

Parameters:
s - the shape
Returns:
true if it is selected

getSelectedShape

public DiagramSelectedShape getSelectedShape(java.awt.Shape s)
Checks if one shape is selected

Parameters:
s - the shape
Returns:
the selected shape or null if not selected

isSelected

public boolean isSelected(int ox,
                          int oy)
Checks if a shape already selected contains a given point

Parameters:
ox - point coordinate along X axis
oy - point coordinate along Y axis
Returns:
true if a selected shapes exists at these coordinates

getSelectedShapeAt

public java.awt.Shape getSelectedShapeAt(int ox,
                                         int oy)
Checks if a shape already selected contains a given point

Parameters:
ox - point coordinate along X axis
oy - point coordinate along Y axis
Returns:
the selected shape if one exists at these coordinates

isEmpty

public boolean isEmpty()
Checks if the selection is empty

Overrides:
isEmpty in class java.awt.Rectangle
Returns:
true if the selection is empty

isSizing

public boolean isSizing()
Checks if the selection is defined by a rectangle shape and the user is modifiing its size


unselect

public void unselect()
Empties the selection


selectPoint

public boolean selectPoint(int ox,
                           int oy)
Selects one shape at the given point. Previous selected shapes are unselected.

Parameters:
ox - point coordinate along X axis
oy - point coordinate along Y axis
Returns:
true if a shape is added

selectAll

public boolean selectAll()
Selects all the shapes. Previous selected shapes are unselected.

Returns:
true if a shape is added

getShapeCount

public int getShapeCount()
Gets the amount of shape in the selection

Returns:
the shape count

getShape

public java.awt.Shape getShape(int i)
Gets the nth shape in the selection

Parameters:
i - shape number
Returns:
the shape

getSelectedShape

public DiagramSelectedShape getSelectedShape(int i)
Gets the nth DiagramSelectedShape in the selection

Parameters:
i - shape number
Returns:
the DiagramSelectedShape

removeShapeAt

public void removeShapeAt(int i)
Removes one shape

Parameters:
i - the shape number

addPoint

public boolean addPoint(int ox,
                        int oy)
Adds one shape to the selection at a given point. Previous selected shapes are kept.

Parameters:
ox - point coordinate along X axis
oy - point coordinate along Y axis
Returns:
true if a shape is added

selectArea

public boolean selectArea(int ox,
                          int oy,
                          int w,
                          int h)
Selects shapes inside an area Previous selected shapes are unselected.

Parameters:
ox - origin along X axis
oy - origin along Y axis
w - area width
h - area height
Returns:
true if a shape is added

selectAreaEnd

public boolean selectAreaEnd()
End of the definition of the area size The area rectangle is no more needed Selected shapes are the one computed at the previous call of selectArea

Returns:
true if the area was sizing

setGrid

public void setGrid(int grid)
Sets the grid step for translation computation

Parameters:
gris - the gid step

getGrid

public int getGrid()
Gets the grid step for translation computation

Returns:
the grid step

gridPosition

public int gridPosition(int v)
Gets the grid nearest position

Parameters:
v - a coordinate
Returns:
the nearest grid position for this coordiante

getSelection

public java.util.Vector getSelection()
Gets a list of selected diagram elements


copySelection

public java.util.Vector copySelection(java.awt.Point p)
Creates a copy of the selected shapes.

Parameters:
p - the selection origin
Returns:
a vector of shape

deleteSelection

public void deleteSelection()
Deletes the selected shapes


alignSelection

public void alignSelection()
Aligns the selected shapes


checkResizeWay

public int checkResizeWay(int x,
                          int y)
Check if resize or translate is required This implementation can resize elements if the selection contains only one component that is not a DiagramConnection nor a DiagramConnector but a Resizable or a LineInterface object

Parameters:
x - the mouse location
y - the mouse location
Returns:
0 if no resize else the resize way 1=N, 2=NE,..

resizeSelection

public void resizeSelection(int dx,
                            int dy,
                            int way)
Resize the selection This implementation can resize elements if the selection contains only one component and if this component is not a DaigramConnection nor a DiagramConnector but a Resizable object

Parameters:
dx - resize value on X axis
dy - resize value on Y axis
way - the resize way : 1=N, 2=NE, ...

translateSelection

public void translateSelection(int dx,
                               int dy)
Translates the selected shapes


bringSelectionToFront

public void bringSelectionToFront()
Brings the selected shapes to the top of the display


bringSelectionForward

public void bringSelectionForward()
Brings the selected shapes one step closer to the top of the display


sendSelectionBackward

public void sendSelectionBackward()
Sends the selected shapes one step deeper in the document


sendSelectionToBack

public void sendSelectionToBack()
Sends the selected shapes to the bottom of the document


alignSelectionToTop

public void alignSelectionToTop()
Align the content of the selection on the top of the highest shape


alignSelectionToBottom

public void alignSelectionToBottom()
Align the content of the selection on the bottom of the lowest shape


alignSelectionToLeft

public void alignSelectionToLeft()
Align the content of the selection on the left of the leftmost shape


alignSelectionToRight

public void alignSelectionToRight()
Align the content of the selection on the right of the rightmost shape


alignSelectionVCenter

public void alignSelectionVCenter()
Align the content of the selection on its vertical barycentre


alignSelectionHCenter

public void alignSelectionHCenter()
Align the content of the selection on its horizontal barycentre


distributeSelectionHorizontally

public void distributeSelectionHorizontally()
Distributes the selected shapes so there is equal horizontal distance between the edges of all them


distributeSelectionVertically

public void distributeSelectionVertically()
Distributes the selected shapes so there is equal vertical distance between the edges of all them


getShapeOrigin

public java.awt.Point getShapeOrigin(java.awt.Shape s,
                                     java.awt.Point p)
Computes shape origin before its move for a rectangle the top-left point coordinate is returned for a default shape the top-left point coordinate of its bounds is returned By overriding this method, specif shapes can be managed

Parameters:
s - the shape
p - a Point to put coordinates into (if null then a new Point is returned)
Returns:
a Point with coordinates

translateShape

public void translateShape(java.awt.Shape s,
                           int dx,
                           int dy)
Translates a shape only Rectangle shapes are translated By overriding this method, specif shapes can be managed

Parameters:
s - the shape
dx - x translation
dy - y translation

resizeShape

public void resizeShape(java.awt.Shape s,
                        int dx,
                        int dy)
Resizes a shape By overriding this method, specif shapes can be managed

Parameters:
s - the resizable shape
dx - x resizing
dy - y resizing

translateConnectionShape

public void translateConnectionShape(java.awt.Shape s,
                                     DiagramConnector c,
                                     int dx,
                                     int dy)
Translates a shape connected to an other one This implementation translates nothing By overriding this method, specif shapes can be managed

Parameters:
s - the shape
c - the connector
dx - x translation
dy - y translation

copyShape

public java.awt.Shape copyShape(java.awt.Shape s)
To copy a shape only Rectangle shapes are copied By overriding this method, specif shapes can be managed

Parameters:
s - the shape
Returns:
a copy

copyConnectionShape

public java.awt.Shape copyConnectionShape(java.awt.Shape s,
                                          DiagramConnector in,
                                          DiagramConnector out)
Copies a connection shape This implementation creates nothing By overriding this method, specif shapes can be managed

Parameters:
s - the shape
in - the input connector
out - the output connector
Returns:
a copy

deleteShape

public void deleteShape(java.awt.Shape s)
Deletse a shape By overriding this method, one can use an other iterator on the shapes.

Parameters:
s - the shape

clear

protected void clear()
Removes all the selected shapes


add

protected boolean add(DiagramSelectedShape dss)
Adds a selected shape if it is not already selected

Returns:
true if shape is added

addAllShapes

protected boolean addAllShapes()
Add all the shapes to the selection By overriding this method, one can use an other iterator on the shapes.


addShapeAt

protected boolean addShapeAt(int ox,
                             int oy)
The first shape which contains the given coordinates is added to the selected shapes list. By overriding this method, one can use an other iterator on the shapes.

Parameters:
ox - the x coordinate
oy - the y coordinate

addShapesInside

protected boolean addShapesInside()
All the shapes which are inside the selection area By overriding this method, one can use an other iterator on the shapes.