sgtplot
Class Layer
- java.lang.Object
-
- java.awt.Component
-
- sgtplot.Layer
-
- All Implemented Interfaces:
- java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Cloneable, LayerControl
- Direct Known Subclasses:
- DataGroupLayer, PlotLayer
public class Layer extends java.awt.Component implements java.lang.Cloneable, LayerControl
ALayercontains a singleGraphobject and multipleLayerChildobjects. There can be manyLayerobjects associated with eachPaneobject and theLayerobjects can shareTransformandAxisobjects, but are not required to. TheLayeris also where keys related toColor, Vectors, and Lines are attached. The can be at most one key of each type attached to aLayer.The
Layerobject transforms physical coordinates to device coordinates. All objects that attach to aLayeruse physical coordinates. The exception to this is theGraphobject (and its children), since these objects transform user coordinates to physical coordinates.The following is a simple example of using the
Pane,Layer, andSGLabelobjects together. In this example, thePaneandLayerobjects are created such that, in the absence of any resizing, 100 pixels is equal to 1.0 physical units. Two labels are created, the first contains the current time and is located in the bottom left of theLayer. The second label is a title that is positioned near the top and centered.Pane pane; Layer layer; SGLabel title; SGLabel label; GeoDate stime; ... // // Instantiate Pane, Layer, and GeoDate objects. // pane = new Pane("test pane", new Dimension(400, 300)); pane.setLayout(new StackedLayout()); layer = new Layer("Test Layer", new Dimension2D(4.0, 3.0)); stime = new GeoDate(); // // Instatiate an SGLabel object as label, set its text to the // current time and position it near the lower-left corner // of the layer. // label = new SGLabel("test", stime.toString(), new Point2D.Double(0.05, 0.05)); // // Set properties for label. // label.setAlign(SGLabel.BOTTOM, SGLabel.LEFT); label.setColor(Color.magenta); label.setHeightP(0.15); label.setFont(new Font("Dialog", Font.PLAIN, 10)); // // Add label to layer. // layer.addChild(label); // // Instatiate an SGLabel object as title, set its text and position // it near the top of the layer and centered. Set the properties // for title. // title = new SGLabel("title", "SciGraph Test!", new Point2D.Double(2.125, 2.9)); title.setAlign(SGLabel.TOP, SGLabel.CENTER); title.setHeightP(0.25); title.setFont(new Font("Helvetica", Font.BOLD, 14)); // // Add title to layer and add layer to pane. // layer.addChild(title); pane.add(layer);
-
-
Field Summary
-
Constructor Summary
Constructors Constructor and Description Layer()Default constructor forLayer.Layer(java.lang.String id)Create aLayerobject.Layer(java.lang.String id, Dimension2D psize)Create aLayerobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddChild(LayerChild child)Add aLayerChildto theLayer.java.util.EnumerationchildElements()Create aEnumerationfor theLayerChild's associated with theLayer.java.util.IteratorchildIterator()Layercopy()Copy theLayerand its attached classes.voiddraw(org.freehep.graphics2d.VectorGraphics g)Draw the Layer and its attached classes.voiddrawDraggableItems(org.freehep.graphics2d.VectorGraphics g)Used internally by sgtplot.LayerChildfindChild(java.lang.String id)FindLayerChildinLayer.Rectangle2D.DoublegetBoundsP()Get theLayerbounds in physical coordinates.LayerChildgetChild(java.lang.String labid)Get a child associated with theLayer.LayerChild[]getChildren()GraphgetGraph()Get theGraphattached to the layer.java.lang.StringgetId()Get theLayeridentifier.java.lang.ObjectgetObjectAt(int x, int y)Find object associated with a MOUSE_DOWN event.java.lang.ObjectgetObjectAt(int x, int y, boolean check)Find object associated with a MOUSE_DOWN event.java.lang.ObjectgetObjectAt(java.awt.Point pt, boolean check)Find object associated with a MOUSE_DOWN event.java.lang.Object[]getObjectsAt(int x, int y, boolean check)Find objects associated with a MOUSE_DOWN event.AbstractPanegetPane()Get thePanetheLayeris associated with.Dimension2DgetSizeP()Get theLayersize in physical coordinates.doublegetXDtoP(int xd)Transform device units to physical for the x direction.intgetXPtoD(double xp)Transform physical units to device for x coordinate.doublegetXPtoD2(double xp)Transform physical units to device for x coordinate.doublegetYDtoP(int yd)Transform device units to physical for the y direction.intgetYPtoD(double yp)Transform physcial units to device for y coordinate.doublegetYPtoD2(double yp)Transform physcial units to device for y coordinate.booleanisChildAttached(LayerChild child)Tests if aLayerChildis attached to theLayer.booleanisDataInLayer(java.lang.String id)Checks to see if a data id matches that data attached to theGraph.voidmodified(java.lang.String mess)Used internally by sgtplot.voidremoveAllChildren()Remove allLayerChildobjects from theLayer.voidremoveChild(LayerChild child)Remove aLayerChildobject from theLayer.voidremoveChild(java.lang.String labid)Remove aLayerChildobject from theLayer.voidsetBounds(int x, int y, int w, int h)Set the bounds of theLayerin device units.voidsetBounds(java.awt.Rectangle bnds)Set the bounds of theLayerin device units.booleansetGraph(Graph gr)Associate a graph with the layer.voidsetId(java.lang.String id)Set theLayeridentifier.voidsetLocation(int x, int y)Set the location of theLayerin device units.voidsetLocation(java.awt.Point pt)Set the location of theLayerin device units.voidsetPane(AbstractPane p)Set thePanetheLayeris associated with.voidsetSize(java.awt.Dimension sze)Set the size of theLayerin device units.voidsetSize(int w, int h)Set the size of theLayerin device units.voidsetSizeP(Dimension2D psize)Set the size of theLayerin physical coordinates.java.lang.StringtoString()Get aStringrepresentation of theLayer.-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMinimumSize, setName, setPreferredSize, setVisible, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
-
-
-
-
Constructor Detail
-
Layer
public Layer(java.lang.String id)
Create aLayerobject. TheLayeris created with a default width and height equal to 1.0.- Parameters:
id- identifier for Layer
-
Layer
public Layer(java.lang.String id, Dimension2D psize)Create aLayerobject. TheLayeris created with the specified dimensions and identifier.- Parameters:
id- identifier for Layerpsize- The physical dimensions of the Layer
-
Layer
public Layer()
Default constructor forLayer. TheLayeris created with an empty identifier and a width and height equal to 1.0f.
-
-
Method Detail
-
setSize
public void setSize(java.awt.Dimension sze)
Set the size of theLayerin device units.- Overrides:
setSizein classjava.awt.Component- Parameters:
sze- dimension of theLayer
-
setSize
public void setSize(int w, int h)Set the size of theLayerin device units.- Overrides:
setSizein classjava.awt.Component- Parameters:
w- width of theLayerh- height of theLayer
-
setLocation
public void setLocation(java.awt.Point pt)
Set the location of theLayerin device units.- Overrides:
setLocationin classjava.awt.Component- Parameters:
pt- location of theLayer
-
setLocation
public void setLocation(int x, int y)Set the location of theLayerin device units.- Overrides:
setLocationin classjava.awt.Component- Parameters:
x- horizontal location of theLayery- vertical location of theLayer
-
setBounds
public void setBounds(int x, int y, int w, int h)Set the bounds of theLayerin device units.- Overrides:
setBoundsin classjava.awt.Component- Parameters:
x- horizontal location of theLayery- vertical location of theLayerw- width of theLayerh- height of theLayer
-
setBounds
public void setBounds(java.awt.Rectangle bnds)
Set the bounds of theLayerin device units.- Overrides:
setBoundsin classjava.awt.Component- Parameters:
bnds- bounds of theLayer
-
getXPtoD
public int getXPtoD(double xp)
Transform physical units to device for x coordinate.- Parameters:
xp- x physical coordinate- Returns:
- x device coordinate
- Since:
- 2.0
-
getYPtoD
public int getYPtoD(double yp)
Transform physcial units to device for y coordinate.- Parameters:
yp- y physical coordinate- Returns:
- y device coordinate
- Since:
- 2.0
-
getXPtoD2
public double getXPtoD2(double xp)
Transform physical units to device for x coordinate.- Parameters:
xp- x physical coordinate- Returns:
- x device coordinate
- Since:
- 3.0
-
getYPtoD2
public double getYPtoD2(double yp)
Transform physcial units to device for y coordinate.- Parameters:
yp- y physical coordinate- Returns:
- y device coordinate
- Since:
- 3.0
-
getXDtoP
public double getXDtoP(int xd)
Transform device units to physical for the x direction.- Parameters:
xd- device x coordinate- Returns:
- physical x coordinate
-
getYDtoP
public double getYDtoP(int yd)
Transform device units to physical for the y direction.- Parameters:
yd- device y coordinate- Returns:
- physical y coordinate
-
copy
public Layer copy()
Copy theLayerand its attached classes.- Returns:
- copy
-
draw
public void draw(org.freehep.graphics2d.VectorGraphics g) throws PaneNotFoundExceptionDraw the Layer and its attached classes.- Specified by:
drawin interfaceLayerControl- Parameters:
g- graphics context- Throws:
PaneNotFoundException- if a pane object is not found
-
drawDraggableItems
public void drawDraggableItems(org.freehep.graphics2d.VectorGraphics g) throws PaneNotFoundExceptionDescription copied from interface:LayerControlUsed internally by sgtplot.- Specified by:
drawDraggableItemsin interfaceLayerControl- Parameters:
g- Graphics object.- Throws:
PaneNotFoundException- Pane not found.
-
setGraph
public boolean setGraph(Graph gr)
Associate a graph with the layer. Only one graph or its children may be attached to a layer. Multiple graphs are created by using multiple layers.- Parameters:
gr- graph- Returns:
- True if attachment was succesful
- See Also:
Graph
-
getGraph
public Graph getGraph()
Get theGraphattached to the layer.- Returns:
- Reference to the
Graph.
-
addChild
public void addChild(LayerChild child)
Add aLayerChildto theLayer. EachLayercan contain as many children as needed.
-
removeChild
public void removeChild(LayerChild child) throws ChildNotFoundException
Remove aLayerChildobject from theLayer.- Parameters:
child- AChildLayerobject associated with theLayer- Throws:
ChildNotFoundException- The child is not associated with theLayer- See Also:
SGLabel,LineKey,ColorKey,Ruler
-
removeChild
public void removeChild(java.lang.String labid) throws ChildNotFoundExceptionRemove aLayerChildobject from theLayer.- Parameters:
labid- An identifier for aLayerChildassociated with theLayer- Throws:
ChildNotFoundException- The child is not associated with theLayer- See Also:
SGLabel,LineKey,ColorKey,Ruler
-
findChild
public LayerChild findChild(java.lang.String id)
FindLayerChildinLayer.- Parameters:
id- LayerChild identifier- Returns:
- LayerChild
- Since:
- 3.0
-
isChildAttached
public boolean isChildAttached(LayerChild child)
Tests if aLayerChildis attached to theLayer.- Parameters:
child- LayerChild to test- Returns:
- true if attached to Layer
- Since:
- 2.0
-
removeAllChildren
public void removeAllChildren()
Remove allLayerChildobjects from theLayer.
-
getChild
public LayerChild getChild(java.lang.String labid) throws ChildNotFoundException
Get a child associated with theLayer.- Parameters:
labid- ALayerChildobject identifier- Returns:
- layerChild with id
- Throws:
ChildNotFoundException- The child is not associated with theLayer- See Also:
SGLabel,LineKey,ColorKey,Ruler
-
childElements
public java.util.Enumeration childElements()
Create aEnumerationfor theLayerChild's associated with theLayer.
-
childIterator
public java.util.Iterator childIterator()
- Since:
- 3.0
-
getChildren
public LayerChild[] getChildren()
- Since:
- 3.0
-
setSizeP
public void setSizeP(Dimension2D psize)
Set the size of theLayerin physical coordinates.- Parameters:
psize- The physical size of theLayer.
-
getSizeP
public Dimension2D getSizeP()
Get theLayersize in physical coordinates. This returns the physical coordinate size of theLayer.- Returns:
- A
Dimension2Dcontaining the physical size of theLayer. - See Also:
Dimension2D
-
getBoundsP
public Rectangle2D.Double getBoundsP()
Get theLayerbounds in physical coordinates. The origin of the bounding rectangle, for aLayer, is always (0,0).- Returns:
- A
Rectangle2D.Doublecontaining the physical bounds of theLayer. - See Also:
Rectangle2D.Double
-
getId
public java.lang.String getId()
Get theLayeridentifier.- Specified by:
getIdin interfaceLayerControl- Returns:
- The identifier.
-
setId
public void setId(java.lang.String id)
Set theLayeridentifier.- Parameters:
id- identifier
-
setPane
public void setPane(AbstractPane p)
Set thePanetheLayeris associated with. This method is called byPanewhen thePane.addmethod is exectued.- Specified by:
setPanein interfaceLayerControl- Parameters:
p- ThePane
-
getPane
public AbstractPane getPane()
Get thePanetheLayeris associated with.- Returns:
- Refence to the
Pane
-
modified
public void modified(java.lang.String mess)
Used internally by sgtplot.- Parameters:
mess- message- Since:
- 2.0
-
getObjectAt
public java.lang.Object getObjectAt(int x, int y, boolean check)Find object associated with a MOUSE_DOWN event. The getObjectAt method scans through all the objects associated with the layer to find one whose bounding box contains the mouse location. This method should not be called by a user.- Parameters:
pt- device coordinatescheck- if true requires that object isSelectable- Returns:
- object at location
-
getObjectAt
public java.lang.Object getObjectAt(int x, int y)Find object associated with a MOUSE_DOWN event. The getObjectAt method scans through all the objects associated with the layer to find one whose bounding box contains the mouse location. This method should not be called by a user.- Parameters:
pt- device coordinates- Returns:
- object at location
-
getObjectAt
public java.lang.Object getObjectAt(java.awt.Point pt, boolean check)Find object associated with a MOUSE_DOWN event. The getObjectAt method scans through all the objects associated with the layer to find one whose bounding box contains the mouse location. This method should not be called by a user.- Parameters:
pt- device coordinatescheck- if true requires that object isSelectable- Returns:
- object at location
-
getObjectsAt
public java.lang.Object[] getObjectsAt(int x, int y, boolean check)Find objects associated with a MOUSE_DOWN event. The getObjecstAt method scans through all the objects associated with the layer to find those whose bounding box contains the mouse location. This method should not be called by a user.- Parameters:
x- mouse coordinatey- mouse coordinatecheck- if selectable- Returns:
- object array
- Since:
- 3.0
-
toString
public java.lang.String toString()
Get aStringrepresentation of theLayer.- Overrides:
toStringin classjava.awt.Component- Returns:
Stringrepresentation
-
isDataInLayer
public boolean isDataInLayer(java.lang.String id)
Checks to see if a data id matches that data attached to theGraph.- Parameters:
id- data identifier- Returns:
- true if data is in layer
- Since:
- 2.0
-
-
DMelt 3.0 © DataMelt by jWork.ORG