Class HTMLGridPanel
java.lang.Object
nl.tudelft.simulation.dsol.web.animation.D2.HTMLGridPanel
- All Implemented Interfaces:
ImageObserver
- Direct Known Subclasses:
HTMLAnimationPanel
public class HTMLGridPanel extends Object implements ImageObserver
The GridPanel introduces the gridPanel.
Copyright (c) 2002-2020 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://simulation.tudelft.nl/dsol/3.0/license.html.
- Author:
- Niels Lang , Peter Jacobs
-
Field Summary
Fields Modifier and Type Field Description static intDOWNthe DOWN directions for moving/zooming.protected Rectangle2Dextentthe extent of this panel.protected NumberFormatformatterthe formatter to use.protected static ColorGRIDCOLORgridColor.protected doublegridSizethe gridSize in world Units.protected Rectangle2DhomeExtentthe extent of this panel.protected HTMLGraphics2DhtmlGraphics2Dthe HTMLGraphics2D 'shadow' canvas.protected DimensionlastDimensionthe last computed Dimension.static intLEFTthe LEFT directions for moving/zooming.protected DimensionpreferredSizethe last computed Dimension.static intRIGHTthe RIGHT directions for moving/zooming.protected booleanshowGridshow the grid.protected booleanshowToolTipwhether to show a tooltip with the coordinates or not.protected Dimensionsizethe last computed Dimension.static intUPthe UP directions for moving/zooming.protected Point2DworldCoordinatethe last known world coordinate of the mouse.static doubleZOOMFACTORthe ZOOM factor.Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors Constructor Description HTMLGridPanel(Rectangle2D extent)constructs a new GridPanel.HTMLGridPanel(Rectangle2D extent, Dimension size)constructs a new GridPanel. -
Method Summary
Modifier and Type Method Description voiddisplayWorldCoordinateToolTip()Display a tooltip with the last known world coordinates of the mouse, in case the tooltip should be displayed.protected voiddrawGrid(Graphics g)Added to make sure the recursive render-call calls THIS render method instead of a potential super-class defined 'paintComponent' render method.ColorgetBackground()StringgetDrawingCommands()Return the set of drawing commands.Rectangle2DgetExtent()returns the extent of this panel.FontgetFont()FontMetricsgetFontMetrics(Font font)intgetHeight()DimensiongetPreferredSize()DimensiongetSize()StringgetToolTipText()intgetWidth()Point2DgetWorldCoordinate()voidhome()resets the panel to its original extent.booleanimageUpdate(Image img, int infoflags, int x, int y, int width, int height)booleanisDirty()booleanisShowGrid()booleanisShowing()booleanisShowToolTip()voidpaintComponent(HTMLGraphics2D g)Draw the grid.voidpan(int direction, double percentage)pans the panel in a specified direction.voidrepaint()Repaint the shadow canvas.voidsetBackground(Color background)voidsetFont(Font font)voidsetPreferredSize(Dimension preferredSize)voidsetShowGrid(boolean showGrid)voidsetShowing(boolean showing)voidsetShowToolTip(boolean showToolTip)voidsetSize(Dimension size)voidsetToolTipText(String toolTipText)voidsetWorldCoordinate(Point2D point)Set the world coordinates based on a mouse move.voidshowGrid(boolean bool)show the grid?voidzoom(double factor)zooms in/out.voidzoom(double factor, int mouseX, int mouseY)zooms in/out.
-
Field Details
-
UP
public static final int UPthe UP directions for moving/zooming.- See Also:
- Constant Field Values
-
DOWN
public static final int DOWNthe DOWN directions for moving/zooming.- See Also:
- Constant Field Values
-
LEFT
public static final int LEFTthe LEFT directions for moving/zooming.- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHTthe RIGHT directions for moving/zooming.- See Also:
- Constant Field Values
-
ZOOMFACTOR
public static final double ZOOMFACTORthe ZOOM factor.- See Also:
- Constant Field Values
-
GRIDCOLOR
gridColor. -
extent
the extent of this panel. -
homeExtent
the extent of this panel. -
showGrid
protected boolean showGridshow the grid. -
gridSize
protected double gridSizethe gridSize in world Units. -
formatter
the formatter to use. -
lastDimension
the last computed Dimension. -
size
the last computed Dimension. -
preferredSize
the last computed Dimension. -
worldCoordinate
the last known world coordinate of the mouse. -
showToolTip
protected boolean showToolTipwhether to show a tooltip with the coordinates or not. -
htmlGraphics2D
the HTMLGraphics2D 'shadow' canvas.
-
-
Constructor Details
-
HTMLGridPanel
constructs a new GridPanel.- Parameters:
extent- Rectangle2D; the extent to show.
-
HTMLGridPanel
constructs a new GridPanel.- Parameters:
extent- Rectangle2D; the initial extent.size- Dimension; the size of the panel in pixels.
-
-
Method Details
-
getDrawingCommands
Return the set of drawing commands.- Returns:
- the set of drawing commands
-
paintComponent
Draw the grid.- Parameters:
g- HTMLGraphics2D; the virtual Graphics2D canvas to enable writing to the browser
-
showGrid
public final void showGrid(boolean bool)show the grid?- Parameters:
bool- boolean; true/false
-
getExtent
returns the extent of this panel.- Returns:
- Rectangle2D
-
setWorldCoordinate
Set the world coordinates based on a mouse move.- Parameters:
point- Point2D; the x,y world coordinates
-
getWorldCoordinate
- Returns:
- worldCoordinate
-
displayWorldCoordinateToolTip
public final void displayWorldCoordinateToolTip()Display a tooltip with the last known world coordinates of the mouse, in case the tooltip should be displayed. -
isShowToolTip
public final boolean isShowToolTip()- Returns:
- showToolTip
-
setShowToolTip
public final void setShowToolTip(boolean showToolTip)- Parameters:
showToolTip- boolean; set showToolTip
-
pan
public final void pan(int direction, double percentage)pans the panel in a specified direction.- Parameters:
direction- int; the directionpercentage- double; the percentage
-
home
public final void home()resets the panel to its original extent. -
isShowGrid
public final boolean isShowGrid()- Returns:
- Returns the showGrid.
-
setShowGrid
public final void setShowGrid(boolean showGrid)- Parameters:
showGrid- boolean; The showGrid to set.
-
zoom
public final void zoom(double factor)zooms in/out.- Parameters:
factor- double; The zoom factor
-
zoom
public final void zoom(double factor, int mouseX, int mouseY)zooms in/out.- Parameters:
factor- double; The zoom factormouseX- int; x-position of the mouse around which we zoommouseY- int; y-position of the mouse around which we zoom
-
drawGrid
Added to make sure the recursive render-call calls THIS render method instead of a potential super-class defined 'paintComponent' render method.- Parameters:
g- Graphics; the graphics object
-
repaint
public void repaint()Repaint the shadow canvas. -
getSize
- Returns:
- size
-
setSize
- Parameters:
size- Dimension; set size
-
getBackground
- Returns:
- background
-
setBackground
- Parameters:
background- Color; set background
-
getWidth
public final int getWidth()- Returns:
- width
-
getHeight
public final int getHeight()- Returns:
- height
-
getPreferredSize
- Returns:
- preferredSize
-
setPreferredSize
- Parameters:
preferredSize- Dimension; set preferredSize
-
getToolTipText
- Returns:
- toolTipText
-
setToolTipText
- Parameters:
toolTipText- String; set toolTipText
-
isShowing
public final boolean isShowing()- Returns:
- showing
-
setShowing
public final void setShowing(boolean showing)- Parameters:
showing- boolean; set showing
-
getFont
- Returns:
- font
-
setFont
- Parameters:
font- Font; set font
-
getFontMetrics
- Parameters:
font- Font; the font to calculate the fontmetrics for- Returns:
- fontMetrics
-
isDirty
public final boolean isDirty()- Returns:
- dirty
-
imageUpdate
- Specified by:
imageUpdatein interfaceImageObserver
-