Package cnuphys.splot.plot
Class GraphicsUtilities
java.lang.Object
cnuphys.splot.plot.GraphicsUtilities
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BasicStroke
A stroke used for highlight drawing.static final BasicStroke
A stroke used for highlight drawing.static final BasicStroke
Another stroke used for highlight drawing.static final BasicStroke
Another stroke used for highlight drawing.static Color
One default color for highlighted drawing.static Color
Second default color for highlighted drawing.static final BasicStroke
A stroke used for common dashed lines.static final BasicStroke
Hashtable of strokes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
centerComponent
(Component component) Center a component.static void
centerComponent
(Component component, int dh, int dv) Center a component.static Color
colorFromHex
(String hex) Obtain a color from a hex string in common internet format #rrggbbaa.static String
colorToHex
(Color color) Get the hex format of the color in the form #rrggbbaastatic void
Draws an arrow on the given Graphics2D contextstatic void
Draws an arrow on the given Graphics2D contextstatic void
Draw a simple cross symbol.static void
drawDownTriangle
(Graphics g, int x, int y, int s2, Color lc, Color fc) Draw a simple down triangle symbol.static void
drawHighlightedArc
(Graphics g, int x, int y, int width, int height, int startAngle, int arcAngle, Color color1, Color color2) static void
drawHighlightedLine
(Graphics g, int x1, int y1, int x2, int y2, Color color1, Color color2) static void
Draws a highlighted rectangle using default colors.static void
drawHighlightedOval
(Graphics g, Rectangle r, Color color1, Color color2) Draws a highlighted oval.static void
drawHighlightedPolyline
(Graphics g, int[] x, int[] y, int n) Draws a highlighted polyline (set of unclosed points) using default colors.static void
drawHighlightedPolyline
(Graphics g, int[] x, int[] y, int n, Color color1, Color color2) Draws a highlighted polyline (set of unclosed points).static void
Draws a highlighted rectangle using default colors.static void
drawHighlightedRectangle
(Graphics g, Rectangle r, Color color1, Color color2) Draws a highlighted rectangle.static void
drawHighlightedShape
(Graphics g, Shape shape) Draws a highlighted shape using default colors.static void
drawHighlightedShape
(Graphics g, Shape shape, Color color1, Color color2) Draws a highlighted shape.static void
Draw a simple oval symbol.static void
drawRectangle
(Graphics g, int x, int y, int w2, int h2, Color lc, Color fc) Draw a simple rectangle symbol.static void
drawRotatedText
(Graphics2D g, String s, Font font, int x, int y, double angleDegrees) Draw rotated text.static void
drawRotatedText
(Graphics2D g, String s, Font font, int xo, int yo, int delX, int delY, double angleDegrees) Draw rotated text.static void
drawSimple3DDiamond
(Graphics g, Rectangle r, Color fc, boolean outsie) Draw a 3d diamond.static void
drawSimple3DOval
(Graphics g, Rectangle r, Color fc, Color ic, boolean outsie) Draw an oval with a 3D etching.static void
drawSimple3DRect
(Graphics g, int x, int y, int w, int h, boolean outsie) Draw a 3d "etching" around a rectangular area..static void
drawSimple3DRect
(Graphics g, int x, int y, int w, int h, Color fc, boolean outsie) Draw a 3d rectangle.static void
drawSimple3DRect
(Graphics g, Rectangle r, Color fc, boolean outsie) Draw a 3d rectangle.static void
drawStyleLine
(Graphics g, Color lineColor, float lineWidth, LineStyle lineStyle, int x1, int y1, int x2, int y2) Draw a styled linestatic void
drawUpTriangle
(Graphics g, int x, int y, int s2, Color lc, Color fc) Draw a simple up triangle symbol.static void
Draw a simple "X" symbol.static void
fillAndFrameRect
(Graphics g, Rectangle r, Color fill, Color frame) Fill and frame a rectanglestatic BufferedImage
return an image resulting from offscreen drawing.static BufferedImage
Obtain a buffer big enough for offscreen drawing.static BufferedImage
Obtain a translucent buffer big enough for offscreen drawing.static Container
static Stroke
Gets a stroke appropriate for the line width and line type.static void
Initialize the look and feel.static void
static Rectangle
Compute a minimal clip from the intersection of the bounds of the current clip and a rectanglestatic void
paintComponentOnImage
(Component c, BufferedImage image) Paints the component on an existing image.static boolean
pointOnLine
(int px, int py, int startx, int starty, int endx, int endy) Returnstrue
if the point is on the line, with an amount of slop controlled by the class constantSELECTRES
.static boolean
pointOnLine
(Point p, Point start, Point end) Returnstrue
if the point is on the line, with an amount of slop controlled by the class constantSELECTRES
.static Rectangle
rectangleARFixed
(Rectangle r, Point p0, Point p) Get a rectangle with the same apsect ratio.static void
rectangleARFixedAdjust
(Rectangle r, Point p0, Point p) Adjust a second point so that the rectangle it forms with the first point matches an aspect ratio of a given rectangle.static Rectangle
rectangleFromPoints
(Point p1, Point p2) Given two points, return the rectanglestatic Point[]
rectangleToPoints
(Rectangle rect) Create four points corresponding to the corners of a rectangle.static Dimension
screenFraction
(double fraction) Returns a dimension that is a specified fraction of the screen size.static void
setSizeMini
(JComponent component) Set component to mini size variant.static void
setSizeSmall
(JComponent component) Set component to small size variant.static void
setSquareButton
(JButton button) Set button for square style.static void
setTexturedButton
(JButton button) Set button for textured style.void
sizeToScreen
(JFrame frame, double fractionalSize) Size and center a JFrame relative to the screen.
-
Field Details
-
highlightColor1
One default color for highlighted drawing. -
highlightColor2
Second default color for highlighted drawing. -
dash1
A stroke used for highlight drawing. -
dash2
Another stroke used for highlight drawing. -
dash1_2
A stroke used for highlight drawing. -
dash2_2
Another stroke used for highlight drawing. -
simpleDash
A stroke used for common dashed lines. -
simpleDash2
-
strokes
Hashtable of strokes. As strokes are created, they are cached so that they aren't created over and over again. There should not be many--each linewidth and solid or dashed combination--probably no more than six or eight.
-
-
Constructor Details
-
GraphicsUtilities
public GraphicsUtilities()
-
-
Method Details
-
setSizeSmall
Set component to small size variant. Probably only works on Mac.- Parameters:
component
- the component to change size
-
setSizeMini
Set component to mini size variant. Probably only works on Mac.- Parameters:
component
- the component to change size
-
setSquareButton
Set button for square style. For mac so you don't have to use those wasteful oval buttons when space is tight- Parameters:
button
- the button to change style
-
setTexturedButton
Set button for textured style. For mac so you don't have to use those wasteful oval buttons when space is tight- Parameters:
button
- the button to change style
-
minClip
Compute a minimal clip from the intersection of the bounds of the current clip and a rectangle- Parameters:
currentClip
- the current cliprect
- the rectangle of interest- Returns:
- the intersection bounding rect, or
null
-
getStroke
Gets a stroke appropriate for the line width and line type. Try the hash table first, if not found create the Stroke and place it in the hashtable for future use.- Parameters:
lineWidth
- the desired line width in pixels.lineStyle
- the desired line style.- Returns:
- the appropriate stroke.
-
rectangleToPoints
Create four points corresponding to the corners of a rectangle. Useful for item selection points.- Parameters:
rect
- the rectangle in question.- Returns:
- points corresponding to the corners.
-
getComponentTranslucentImageBuffer
Obtain a translucent buffer big enough for offscreen drawing.- Parameters:
c
- the component being rendered offscreen.- Returns:
- a translucent buffer big enough for offscreen drawing.
-
getComponentImageBuffer
Obtain a buffer big enough for offscreen drawing. This does not do the drawing.- Parameters:
c
- the component to be rendered offscreen.- Returns:
- an image big enough for the job.
-
paintComponentOnImage
Paints the component on an existing image.- Parameters:
c
- the component to paint.image
- the image to paint on, already created.
-
getComponentImage
return an image resulting from offscreen drawing.- Parameters:
c
- the component being rendered.- Returns:
- an image upon which the component was drawn.
-
centerComponent
Center a component.- Parameters:
component
- The Component to center
-
centerComponent
Center a component.- Parameters:
component
- The Component to center.dh
- offset from horizontal center.dv
- offset from vertical center.
-
screenFraction
Returns a dimension that is a specified fraction of the screen size. This is useful, for example, to make a farme 85% of the screen.- Parameters:
fraction
- the fraction desired, e.g., 0.85. No check for reasonableness is made.- Returns:
- the requested dimension.
-
rectangleARFixedAdjust
Adjust a second point so that the rectangle it forms with the first point matches an aspect ratio of a given rectangle. Useful for rubber banding when you want to preserve the aspect ratio.- Parameters:
r
- the rectangle whose aspect ration will be mayched.p0
- anchor pointp
- will be adjusted so that p0, p form a rectangle with the same aspected ratio as r.
-
rectangleARFixed
Get a rectangle with the same apsect ratio. Useful for rubber banding when you want to preserve the sapect ratio. -
rectangleFromPoints
Given two points, return the rectangle- Parameters:
p1
- one pointp2
- the other point- Returns:
- the rectangle created from two points
-
sizeToScreen
Size and center a JFrame relative to the screen.- Parameters:
frame
- the frame to size.fractionalSize
- the fraction desired of the screen--e.g., 0.85 for 85%.
-
drawSimple3DOval
Draw an oval with a 3D etching.- Parameters:
g
- the Graphics context.r
- the bounding rectangle.fc
- an optional fill color.ic
- an optional inner fill color.outsie
- iftrue
, the 3D effect is "out", otherwise "in".
-
drawSimple3DRect
Draw a 3d "etching" around a rectangular area..- Parameters:
g
- the Graphics context.x
- the left of the rectangle.y
- the top of the rectangle.w
- the width of the rectangle.h
- the height of the rectangle.outsie
- iftrue
, the 3D effect is "out", otherwise "in".
-
drawSimple3DRect
public static void drawSimple3DRect(Graphics g, int x, int y, int w, int h, Color fc, boolean outsie) Draw a 3d rectangle.- Parameters:
g
- the Graphics context.x
- the left of the rectangle.y
- the top of the rectangle.w
- the width of the rectangle.h
- the height of the rectangle.fc
- the fill color (if null, no fill).outsie
- iftrue
, the 3D effect is "out", otherwise "in".
-
drawSimple3DRect
Draw a 3d rectangle.- Parameters:
g
- the Graphics context.r
- the rectangle.fc
- the fill color.outsie
- iftrue
, the 3D effect is "out", otherwise "in".
-
fillAndFrameRect
Fill and frame a rectangle- Parameters:
g
- the Graphics context.r
- the bounding rectangle.fill
- the fill color.frame
- the frame (line) color.
-
drawSimple3DDiamond
Draw a 3d diamond.- Parameters:
g
- the Graphics context.r
- the bounding rectangle.fc
- the fill color.outsie
- iftrue
, the 3D effect is "out", otherwise "in".
-
drawRectangle
Draw a simple rectangle symbol.- Parameters:
g
- the Graphics context.x
- the horizontal center.y
- the vertical center.w2
- the half width.h2
- the half height.lc
- the line color.fc
- the fill color.
-
drawOval
Draw a simple oval symbol.- Parameters:
g
- the Graphics context.x
- the horizontal center.y
- the vertical center.w2
- the half width.h2
- the half height.lc
- the line color.fc
- the fill color.
-
drawUpTriangle
Draw a simple up triangle symbol.- Parameters:
g
- the Graphics context.x
- the horizontal center.y
- the vertical center.s2
- the half width.lc
- the line color.fc
- the fill color.
-
drawDownTriangle
Draw a simple down triangle symbol.- Parameters:
g
- the Graphics context.x
- the horizontal center.y
- the vertical center.s2
- the half width.lc
- the line color.fc
- the fill color.
-
drawCross
Draw a simple cross symbol.- Parameters:
g
- the Graphics context.x
- the horizontal center.y
- the vertical center.s2
- the half width.lc
- the line color.
-
drawX
Draw a simple "X" symbol.- Parameters:
g
- the Graphics context.x
- the horizontal center.y
- the vertical center.s2
- the half width.lc
- the line color.
-
drawHighlightedRectangle
Draws a highlighted rectangle using default colors.- Parameters:
g
- the graphics context.r
- the rectangle being highlighted.
-
drawHighlightedRectangle
Draws a highlighted rectangle.- Parameters:
g
- the graphics context.r
- the rectangle being highlighted.color1
- one color for the alternating dash.color2
- the other color for the alternating dash.
-
drawHighlightedLine
public static void drawHighlightedLine(Graphics g, int x1, int y1, int x2, int y2, Color color1, Color color2) - Parameters:
g
-x1
-y1
-x2
-y2
-color1
-color2
-
-
drawHighlightedArc
-
drawHighlightedOval
Draws a highlighted rectangle using default colors.- Parameters:
g
- the graphics context.r
- the rectangle bounding the oval being highlighted.
-
drawHighlightedOval
Draws a highlighted oval.- Parameters:
g
- the graphics context.r
- the rectangle bounding the oval being highlighted.color1
- one color for the alternating dash.color2
- the other color for the alternating dash.
-
drawHighlightedPolyline
Draws a highlighted polyline (set of unclosed points) using default colors.- Parameters:
g
- the graphics context.x
- the x coordinate array.y
- the y coordinate array.n
- the number of points to draw.
-
drawHighlightedPolyline
public static void drawHighlightedPolyline(Graphics g, int[] x, int[] y, int n, Color color1, Color color2) Draws a highlighted polyline (set of unclosed points).- Parameters:
g
- the graphics context.x
- the x coordinate array.y
- the y coordinate array.n
- the number of points to draw.color1
- one color for the alternating dash.color2
- the other color for the alternating dash.
-
drawHighlightedShape
Draws a highlighted shape using default colors.- Parameters:
g
- the graphics context.shape
- the shape being highlighted.
-
drawHighlightedShape
Draws a highlighted shape.- Parameters:
g
- the graphics context.shape
- the shape being highlighted.color1
- one color for the alternating dash.color2
- the other color for the alternating dash.
-
pointOnLine
public static boolean pointOnLine(int px, int py, int startx, int starty, int endx, int endy) Returnstrue
if the point is on the line, with an amount of slop controlled by the class constantSELECTRES
.- Parameters:
px
- the x coordinate of the point to test.py
- the y coordinate of the point to test.startx
- the x coordinate of the start of the line.starty
- the y coordinate of the start of the line.endx
- the x coordinate of the end of the line.endy
- the y coordinate of the end of the line.- Returns:
true
if the point is on the line.
-
pointOnLine
Returnstrue
if the point is on the line, with an amount of slop controlled by the class constantSELECTRES
.- Parameters:
p
- the point to test.start
- the start of the line.end
- the end of the line.- Returns:
true
if the point is on the line.
-
drawRotatedText
public static void drawRotatedText(Graphics2D g, String s, Font font, int x, int y, double angleDegrees) Draw rotated text.- Parameters:
g
- the Graphics context.s
- the text to draw.x
- the x pixel coordinate of baseline.y
- the y pixel coordinate of baseline.angleDegrees
- the angle of rotation in decimal degrees.
-
drawRotatedText
public static void drawRotatedText(Graphics2D g, String s, Font font, int xo, int yo, int delX, int delY, double angleDegrees) Draw rotated text.- Parameters:
g
- the Graphics context.s
- the text to draw.xo
- the x pixel coordinate of rotation point.yo
- the y pixel coordinate of rotation point.delX
- unrotated offset from rotation anchordelY
- unrotated offset from rotation anchorangleDegrees
- the angle of rotation in decimal degrees.
-
drawArrow
Draws an arrow on the given Graphics2D context- Parameters:
g1
- The Graphics context to draw onx
- The x location of the "tail" of the arrowy
- The y location of the "tail" of the arrowxx
- The x location of the "head" of the arrowyy
- The y location of the "head" of the arrow
-
drawArrow
public static void drawArrow(Graphics g1, int x, int y, int xx, int yy, boolean highlight, Color c1, Color c2) Draws an arrow on the given Graphics2D context- Parameters:
g1
- The Graphics context to draw onx
- The x location of the "tail" of the arrowy
- The y location of the "tail" of the arrowxx
- The x location of the "head" of the arrowyy
- The y location of the "head" of the arrow
-
drawStyleLine
public static void drawStyleLine(Graphics g, Color lineColor, float lineWidth, LineStyle lineStyle, int x1, int y1, int x2, int y2) Draw a styled line- Parameters:
g
- the graphics contextstyle
- the stylex1
- starting xy1
- starting yx2
- ending xy2
- ending y
-
colorToHex
Get the hex format of the color in the form #rrggbbaa- Parameters:
color
- the color to convert- Returns:
- the hex string for the color
-
colorFromHex
Obtain a color from a hex string in common internet format #rrggbbaa. The "#" and the aa are optional- Parameters:
hex
- the hex string- Returns:
- the corresponding color or black on error.
-
getParentContainer
-
initializeLookAndFeel
public static void initializeLookAndFeel()Initialize the look and feel.- Parameters:
desiredLnf
- the desired look and feel.
-
main
-