|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component net.sourceforge.webcompmath.draw.Drawable net.sourceforge.webcompmath.draw.Grid
public class Grid
A Grid object draws a graph paper-like grid on a Canvas. The pixel width and height between adjacent grid lines is specified as a parameter to the constructer, or through the access methods "setXSP(double)" and "setYSP(double)". Note that in PIXEL_BASED mode the spacing will be scaled to between PIX_MIN and PIX_MAX (20 and 80, respectively, by default). The color of the grid lines can be set, and defaults to (220, 220, 220).
In COORD_BASED mode, you directly specify the horizontal and vertical spacing of the grid. As you zoom out, the grid lines get closer together. Grid will avoid overlapping grid lines, always keeping at least the width of the grid lines as spacing between the lines.
Grid also supports a DOTS style, where the lines of the grid are replaced by dots drawn at the points where the grid lines would have intersected.
This class was originally written by Gabriel Weinstock (with some modifications by David Eck, and later enhancement by Tom Downey)
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
static int |
COORD_BASED
Indicates that the mode of the grid is coordinate based. |
static int |
CROSS_HATCH
The style of the grid is a cross hatch of vertical and horizontal lines |
static int |
DOTS
The style of the grid is an array of dots |
static int |
PIXEL_BASED
Indicates that the mode of the grid is pixel based. |
Fields inherited from class net.sourceforge.webcompmath.draw.Drawable |
---|
canvas, coords |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
Grid()
Create a Grid object with x and y spacing 1.0. |
|
Grid(double xspace,
double yspace)
Create a Grid object with spacing specified. |
Method Summary | |
---|---|
void |
draw(java.awt.Graphics g,
boolean coordsch)
Draws the grid if an update is required. |
java.awt.Color |
getColor()
Access method which returns the Color of the grid lines. |
int |
getGridStyle()
Get the style of the grid, either CROSS_HATCH or DOTS. |
float |
getLineWidth()
Get the width of the grid lines (or dots), in pixels. |
int |
getMode()
Get the mode of the grid, either PIXEL_BASED or COORD_BASED. |
double |
getXSP()
Access method to return the x spacing used between grid lines. |
double |
getYSP()
Access method to return the y spacing used between grid lines |
void |
setColor(java.awt.Color c)
Method to set the Color used to draw grid lines. |
void |
setGridStyle(int gridStyle)
Set the style of the grid, either CROSS_HATCH or DOTS. |
void |
setLineWidth(float lineWidth)
Set the width of the grid lines (or dots), in pixels, from 0 to 5. |
void |
setMode(int mode)
Set the mode of the grid, either PIXEL_BASED or COORD_BASED. |
void |
setXSP(double x)
Method to set the x spacing between grid lines. |
void |
setYSP(double y)
Method to set the y spacing between grid lines. |
Methods inherited from class net.sourceforge.webcompmath.draw.Drawable |
---|
getVisible, needsRedraw, setOwnerData, setVisible |
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, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, 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, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int PIXEL_BASED
public static final int COORD_BASED
public static final int CROSS_HATCH
public static final int DOTS
Constructor Detail |
---|
public Grid()
public Grid(double xspace, double yspace)
xspace
- x spacingyspace
- y spacingMethod Detail |
---|
public java.awt.Color getColor()
public void setColor(java.awt.Color c)
c
- grid colorpublic double getXSP()
public double getYSP()
public void setXSP(double x)
x
- x spacingpublic void setYSP(double y)
y
- y spacingpublic int getGridStyle()
public void setGridStyle(int gridStyle)
gridStyle
- The gridStyle to set.public float getLineWidth()
public void setLineWidth(float lineWidth)
lineWidth
- The lineWidth to set.public int getMode()
public void setMode(int mode)
mode
- The mode to set.public void draw(java.awt.Graphics g, boolean coordsch)
draw
in class Drawable
g
- the Graphics contextcoordsch
- boolean describing whether coordinates have changed
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |