Class HtmlGridPanel
java.lang.Object
org.opentrafficsim.web.animation.d2.HtmlGridPanel
- All Implemented Interfaces:
ImageObserver
- Direct Known Subclasses:
HtmlAnimationPanel
The VisualizationPanel introduces the gridPanel.
Copyright (c) 2003-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. BSD-style license. See OpenTrafficSim License.
- Author:
- Niels Lang , Peter Jacobs
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intthe DOWN directions for moving/zooming.protected Bounds2dthe extent of this panel.protected NumberFormatthe formatter to use.protected static final ColorgridColor.protected doublethe gridSize for the X-direction in world Units.protected doublethe gridSize for the Y-direction in world Units.protected Bounds2dthe extent of this panel.protected HtmlGraphics2dthe HTMLGraphics2D 'shadow' canvas.protected Dimensionthe last computed Dimension.protected Dimensionthe last stored screen dimensions for zoom-in, zoom-out.protected Doublethe last stored x-scale for zoom-in, zoom-out.protected Doublethe last stored y-scale for zoom-in, zoom-out.static final intthe LEFT directions for moving/zooming.protected Dimensionthe last computed Dimension.protected nl.tudelft.simulation.dsol.animation.d2.RenderableScalethe renderable scale (X/Y ratio) to use.static final intthe RIGHT directions for moving/zooming.protected booleanshow the grid.protected booleanwhether to show a tooltip with the coordinates or not.protected Dimensionthe last computed Dimension.static final intthe UP directions for moving/zooming.protected Point2dthe last known world coordinate of the mouse.static final doublethe ZOOM factor.Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionHtmlGridPanel(Bounds2d extent) constructs a new VisualizationPanel.HtmlGridPanel(Bounds2d homeExtent, Dimension size) constructs a new VisualizationPanel. -
Method Summary
Modifier and TypeMethodDescriptioncomputeVisibleExtent(Bounds2d extent) Computes the visible extent, while preserving zoom scale, otherwise dragging the split screen may pump up the zoom factor.final voidDisplay a tooltip with the last known world coordinates of the mouse, in case the tooltip should be displayed.protected voidAdded to make sure the recursive render-call calls THIS render method instead of a potential super-class defined 'paintComponent' render method.final ColorReturns background.Return the set of drawing commands.final Bounds2dreturns the extent of this panel.final FontgetFont()Returns font.final FontMetricsgetFontMetrics(Font font) Returns font metrics.final intReturns height.final DimensionReturns preferred size.final nl.tudelft.simulation.dsol.animation.d2.RenderableScaleReturns renderable scale.final DimensiongetSize()Returns size.final StringReturns tooltip.final intgetWidth()Returns width.final Point2dReturns world coordinates.final voidhome()resets the panel to its original extent.booleanimageUpdate(Image img, int infoflags, int x, int y, int width, int height) final booleanisDirty()Return whether the panel is dirty.final booleanReturns show grid.final booleanReturns whether panel is showing.final booleanReturns whether to show tooltip.voidDraw the grid.final voidpan(int direction, double percentage) pans the panel in a specified direction.voidrepaint()Repaint the shadow canvas.final voidsetBackground(Color background) Sets background.voidreturns the extent of this panel.final voidSets font.final voidsetPreferredSize(Dimension preferredSize) Sets preferred size.final voidsetRenderableScale(nl.tudelft.simulation.dsol.animation.d2.RenderableScale renderableScale) Sets renderable scale.final voidsetShowGrid(boolean showGrid) Sets show grid.final voidsetShowing(boolean showing) Sets whether panel is showing.final voidsetShowToolTip(boolean showToolTip) Sets whether to show tooltip.final voidSets size.final voidsetToolTipText(String toolTipText) Sets tooltip.final voidsetWorldCoordinate(Point2d point) Set the world coordinates based on a mouse move.final voidshowGrid(boolean bool) show the grid?final voidzoom(double factor) zooms in/out.final 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:
-
DOWN
public static final int DOWNthe DOWN directions for moving/zooming.- See Also:
-
LEFT
public static final int LEFTthe LEFT directions for moving/zooming.- See Also:
-
RIGHT
public static final int RIGHTthe RIGHT directions for moving/zooming.- See Also:
-
ZOOMFACTOR
public static final double ZOOMFACTORthe ZOOM factor.- See Also:
-
GRIDCOLOR
gridColor. -
extent
the extent of this panel. -
homeExtent
the extent of this panel. -
showGrid
protected boolean showGridshow the grid. -
gridSizeX
protected double gridSizeXthe gridSize for the X-direction in world Units. -
gridSizeY
protected double gridSizeYthe gridSize for the Y-direction in world Units. -
formatter
the formatter to use. -
lastDimension
the last computed Dimension. -
lastScreen
the last stored screen dimensions for zoom-in, zoom-out. -
lastXScale
the last stored x-scale for zoom-in, zoom-out. -
lastYScale
the last stored y-scale for zoom-in, zoom-out. -
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. -
renderableScale
protected nl.tudelft.simulation.dsol.animation.d2.RenderableScale renderableScalethe renderable scale (X/Y ratio) to use.
-
-
Constructor Details
-
HtmlGridPanel
constructs a new VisualizationPanel.- Parameters:
extent- the extent to show.
-
HtmlGridPanel
constructs a new VisualizationPanel.- Parameters:
homeExtent- the initial extent.size- 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- the virtual Graphics2D canvas to enable writing to the browser
-
showGrid
public final void showGrid(boolean bool) show the grid?- Parameters:
bool- true/false
-
getExtent
returns the extent of this panel.- Returns:
- Bounds2d
-
setExtent
returns the extent of this panel.- Parameters:
extent- Bounds2d; the new extent
-
setWorldCoordinate
Set the world coordinates based on a mouse move.- Parameters:
point- the x,y world coordinates
-
getWorldCoordinate
Returns world coordinates.- 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 whether to show tooltip.- Returns:
- showToolTip
-
setShowToolTip
public final void setShowToolTip(boolean showToolTip) Sets whether to show tooltip.- Parameters:
showToolTip- set showToolTip
-
pan
public final void pan(int direction, double percentage) pans the panel in a specified direction.- Parameters:
direction- the directionpercentage- the percentage
-
home
public final void home()resets the panel to its original extent. -
isShowGrid
public final boolean isShowGrid()Returns show grid.- Returns:
- Returns the showGrid.
-
setShowGrid
public final void setShowGrid(boolean showGrid) Sets show grid.- Parameters:
showGrid- The showGrid to set.
-
zoom
public final void zoom(double factor) zooms in/out.- Parameters:
factor- The zoom factor
-
zoom
public final void zoom(double factor, int mouseX, int mouseY) zooms in/out.- Parameters:
factor- The zoom factormouseX- x-position of the mouse around which we zoommouseY- 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- the graphics object
-
getRenderableScale
public final nl.tudelft.simulation.dsol.animation.d2.RenderableScale getRenderableScale()Returns renderable scale.- Returns:
- renderableScale
-
setRenderableScale
public final void setRenderableScale(nl.tudelft.simulation.dsol.animation.d2.RenderableScale renderableScale) Sets renderable scale.- Parameters:
renderableScale- set renderableScale
-
repaint
public void repaint()Repaint the shadow canvas. -
getSize
Returns size.- Returns:
- size
-
setSize
Sets size.- Parameters:
size- set size
-
getBackground
Returns background.- Returns:
- background
-
setBackground
Sets background.- Parameters:
background- set background
-
getWidth
public final int getWidth()Returns width.- Returns:
- width
-
getHeight
public final int getHeight()Returns height.- Returns:
- height
-
getPreferredSize
Returns preferred size.- Returns:
- preferredSize
-
setPreferredSize
Sets preferred size.- Parameters:
preferredSize- set preferredSize
-
getToolTipText
Returns tooltip.- Returns:
- toolTipText
-
setToolTipText
Sets tooltip.- Parameters:
toolTipText- set toolTipText
-
isShowing
public final boolean isShowing()Returns whether panel is showing.- Returns:
- showing
-
setShowing
public final void setShowing(boolean showing) Sets whether panel is showing.- Parameters:
showing- set showing
-
getFont
Returns font.- Returns:
- font
-
setFont
Sets font.- Parameters:
font- set font
-
getFontMetrics
Returns font metrics.- Parameters:
font- the font to calculate the fontmetrics for- Returns:
- fontMetrics
-
isDirty
public final boolean isDirty()Return whether the panel is dirty.- Returns:
- dirty
-
imageUpdate
- Specified by:
imageUpdatein interfaceImageObserver
-
computeVisibleExtent
Computes the visible extent, while preserving zoom scale, otherwise dragging the split screen may pump up the zoom factor.- Parameters:
extent- the extent to use- Returns:
- a new extent or empty if parameters are null or screen is invalid (width / height <= 0)
-