JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.swing.gauge
Class GaugeUtil

java.lang.Object
  |
  +--com.klg.jclass.swing.gauge.GaugeUtil

public class GaugeUtil
extends Object

This class contains common methods for performing linear transformations.


Constructor Summary
GaugeUtil()
           
 
Method Summary
static double angleToValue(double angle, double startValue, double stopValue, double startAngle, double stopAngle)
          Given an angle, returns the closest circular scale value.
static double arcAngle(double startAngle, double stopAngle)
          Java uses the notion of startAngle and arcAngle to draw arcs, so this method returns the arcAngle from startAngle and stopAngle.
static double clamp(double value, double min, double max)
          Clamp value between min and max
static void createLegendPopulatorRenderer(com.klg.jclass.swing.gauge.JCGauge gauge, com.klg.jclass.swing.gauge.JCScale scale)
          Creates a LegendPopulatorRenderer for a given gauge and scale.
static double distanceBetweenAngles(double a1, double a2)
          Returns the difference of two angles.
static void drawCircleForCircularScale(Graphics g, com.klg.jclass.swing.gauge.JCCircularScale cscale, Color foreground, double value, double inner_extent, double outer_extent)
          Draws a filled circle based on a circular scale based on the value, inner_extent, and outer_extent.
static void drawCircleForLinearScale(Graphics g, com.klg.jclass.swing.gauge.JCLinearScale lscale, Color foreground, double value, double inner_extent, double outer_extent)
          Draws a filled circle based on a linear scale based on the value, inner_extent, and outer_extent.
static void drawCircularPolygon(Graphics g, com.klg.jclass.swing.gauge.JCCircularScale cscale, Color foreground, double inner_extent, double outer_extent, double width, double value, boolean is_reversed, boolean polygonIsCentered, com.klg.jclass.swing.gauge.JCPolygon polygon)
          Draw a polygon given a circular scale, inner and outer extent, its width, a value on the scale at which to draw, and various other attributes.
static void drawLinearPolygon(Graphics g, com.klg.jclass.swing.gauge.JCLinearScale lscale, Color foreground, double inner_extent, double outer_extent, double width, double value, boolean is_reversed, boolean polygonIsCentered, com.klg.jclass.swing.gauge.JCPolygon polygon)
          Draw a polygon given a linear scale, inner and outer extent, its width, a value on the scale at which to draw, and various other attributes.
static double fromRadians(double radians)
          Converts radians to degrees.
static int[] getCircleForCircularScale(com.klg.jclass.swing.gauge.JCCircularScale cscale, double value, double inner_extent, double outer_extent)
          Get a circle based on a circular scale based on the value, inner_extent, and outer_extent.
static int[] getCircleForLinearScale(com.klg.jclass.swing.gauge.JCLinearScale lscale, double value, double inner_extent, double outer_extent, Rectangle bounds)
          Get the center position and the radius of a circle based on a linear scale based on the value, inner_extent, and outer_extent.
static Polygon getCircularPolygon(com.klg.jclass.swing.gauge.JCCircularScale cscale, double inner_extent, double outer_extent, double width, double value, boolean is_reversed, boolean polygonIsCentered, com.klg.jclass.swing.gauge.JCPolygon polygon)
          Get a polygon position and contour given a circular scale, inner and outer extent, its width, a value on the scale at which to draw, and various other attributes.
static Polygon getLinearPolygon(com.klg.jclass.swing.gauge.JCLinearScale lscale, double inner_extent, double outer_extent, double width, double value, boolean is_reversed, boolean polygonIsCentered, com.klg.jclass.swing.gauge.JCPolygon polygon, Rectangle bounds)
          Get the contour of a polygon and its position given a linear scale, inner and outer extent, its width, a value on the scale at which to draw, and various other attributes.The xpoints[0], ypoints[0] from Polygon return the position of polygon.
static double normalizeAngle(double angle)
          Returns the angle between 0° and 360° corresponding to the inputted angle
static double pointToAngle(double x, double y, double x_orig, double y_orig)
          Returns an angle given a point and the origin.
static double positionToValue(int pos, double startValue, double stopValue, int startPos, int stopPos)
          Given a position, returns the closest linear scale value.
static Polygon rotate(Polygon p, double degrees)
          2D rotation of points.
static Polygon scale(Polygon p, double xAmount, double yAmount)
          Scales an object.
static double toRadians(double degrees)
          Converts degrees to radians.
static Polygon translate(Polygon p, int xamount, int yamount)
          Translate a 2D polygon.
static Polygon translateContour(Polygon input)
           
static double valueToAngle(double value, double start_value, double stop_value, double start_angle, double stop_angle)
          Converts a double value to an angle in degrees.
static int valueToPosition(double value, double start_value, double stop_value, int start_pos, int stop_pos)
          Converts a double value to an position in pixels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GaugeUtil

public GaugeUtil()
Method Detail

clamp

public static double clamp(double value,
                           double min,
                           double max)
Clamp value between min and max

Parameters:
value - The value to be clamped
min - The min the value can be
max - The max the value can be
Returns:
The clamped value

valueToAngle

public static double valueToAngle(double value,
                                  double start_value,
                                  double stop_value,
                                  double start_angle,
                                  double stop_angle)
Converts a double value to an angle in degrees. start_value and stop_value are the min and max values for a given circular range (very often these are the min and max values of a circular scale). start_angle and stop_angle are the starting and stopping angle for the range.

Parameters:
value - The value to be transformed
start_value - The start value of the circular range
stop_value - The stop value of the circular range
start_angle - The start angle of the circular range
stop_angle - The stop angle of the circular range

valueToPosition

public static int valueToPosition(double value,
                                  double start_value,
                                  double stop_value,
                                  int start_pos,
                                  int stop_pos)
Converts a double value to an position in pixels. start_value and stop_value are the min and max values for a given linear range (very often these are the min and max values of a linear scale). start_pos and stop_pos are the starting and stopping position for the range.

Parameters:
value - The value to be transformed
start_value - The start value of the linear range
stop_value - The stop value of the linear range
start_pos - The start angle of the linear range
stop_pos - The stop angle of the linear range

pointToAngle

public static double pointToAngle(double x,
                                  double y,
                                  double x_orig,
                                  double y_orig)
Returns an angle given a point and the origin.

Parameters:
x - The x-coordinate of the point
y - The y-coordinate of the point
x_orig - The x-coordinate of the origin
y_orig - The x-coordinate of the origin

angleToValue

public static double angleToValue(double angle,
                                  double startValue,
                                  double stopValue,
                                  double startAngle,
                                  double stopAngle)
Given an angle, returns the closest circular scale value.

Parameters:
angle - An angle
startValue - The circular scale's start value
stopValue - The circular scale's stop value
startAngle - The circular scale's start angle
stopAngle - The circular scale's stop angle
Returns:
The closest scale value corresponding to the given angle

positionToValue

public static double positionToValue(int pos,
                                     double startValue,
                                     double stopValue,
                                     int startPos,
                                     int stopPos)
Given a position, returns the closest linear scale value.

Parameters:
pos - A position
startValue - The linear scale's start value
stopValue - The liner scale's stop value
startPos - The linear scale's starting position
stopPos - The linear scale's stoping position
Returns:
The closest scale value corresponding to the given position

distanceBetweenAngles

public static double distanceBetweenAngles(double a1,
                                           double a2)
Returns the difference of two angles.

Parameters:
a1 - An angle
a2 - An angle
Returns:
The difference of the two angles

arcAngle

public static double arcAngle(double startAngle,
                              double stopAngle)
Java uses the notion of startAngle and arcAngle to draw arcs, so this method returns the arcAngle from startAngle and stopAngle.

Parameters:
startAngle -
stopAngle -

normalizeAngle

public static double normalizeAngle(double angle)
Returns the angle between 0° and 360° corresponding to the inputted angle

Parameters:
angle - Any angle
Returns:
An angle between 0° and 360°

toRadians

public static double toRadians(double degrees)
Converts degrees to radians.

Parameters:
degrees -
Returns:
The input angle converted to radians

fromRadians

public static double fromRadians(double radians)
Converts radians to degrees.

Parameters:
radians - The radians to be converted to degrees
Returns:
The input angle converted to degrees

scale

public static Polygon scale(Polygon p,
                            double xAmount,
                            double yAmount)
Scales an object. Amounts greater than one increase its size, amounts less than one decrease its size.

Parameters:
p - the input polygon
xAmount - the amount by which the width is to be scaled
yAmount - the amount by which the height is to be scaled
Returns:
A new, scaled polygon

rotate

public static Polygon rotate(Polygon p,
                             double degrees)
2D rotation of points.

Parameters:
p - The input polygon
degrees - The number of degrees to rotate this polygon
Returns:
A new, rotated polygon

translate

public static Polygon translate(Polygon p,
                                int xamount,
                                int yamount)
Translate a 2D polygon.

Parameters:
p - The input polygon
xamount - The amount by which the polygon will be shifted horizontally
yamount - The amount by which the polygon will be shifted vertically
Returns:
a new, translated polygon

getCircularPolygon

public static Polygon getCircularPolygon(com.klg.jclass.swing.gauge.JCCircularScale cscale,
                                         double inner_extent,
                                         double outer_extent,
                                         double width,
                                         double value,
                                         boolean is_reversed,
                                         boolean polygonIsCentered,
                                         com.klg.jclass.swing.gauge.JCPolygon polygon)
Get a polygon position and contour given a circular scale, inner and outer extent, its width, a value on the scale at which to draw, and various other attributes.

Parameters:
cscale - The circular scale used to base the polygon drawing on
inner_extent - The inner extent of the polygon (based on the radius radius of the circular scale).
outer_extent - The outer extent of the polygon (based on the radius radius of the circular scale).
width - The width of the polygon (in pixels)
value - The value along the scale at which to draw (it must be between the scale's min and max)
is_reversed - Is the polygon reversed?
polygonIsCentered - If the polygon is centered, place it midway between the inner and outer extent. Otherwise, place the polygon origin at left extent.
polygon - The polygon to draw. The JCPolygon class is a class that extends Polygon. It contains a method to get a bounding rectangle around a polygon.
Returns:
Polygon

drawCircularPolygon

public static void drawCircularPolygon(Graphics g,
                                       com.klg.jclass.swing.gauge.JCCircularScale cscale,
                                       Color foreground,
                                       double inner_extent,
                                       double outer_extent,
                                       double width,
                                       double value,
                                       boolean is_reversed,
                                       boolean polygonIsCentered,
                                       com.klg.jclass.swing.gauge.JCPolygon polygon)
Draw a polygon given a circular scale, inner and outer extent, its width, a value on the scale at which to draw, and various other attributes.

Parameters:
g - The graphics context on which to draw
cscale - The circular scale used to base the polygon drawing on
foreground - The foreground color of the polygon
inner_extent - The inner extent of the polygon (based on the radius radius of the circular scale).
outer_extent - The outer extent of the polygon (based on the radius radius of the circular scale).
width - The width of the polygon (in pixels)
value - The value along the scale at which to draw (it must be between the scale's min and max)
is_reversed - Is the polygon reversed?
polygonIsCentered - If the polygon is centered, place it midway between the inner and outer extent. Otherwise, place the polygon origin at left extent.
polygon - The polygon to draw. The JCPolygon class is a class that extends Polygon. It contains a method to get a bounding rectangle around a polygon.

getLinearPolygon

public static Polygon getLinearPolygon(com.klg.jclass.swing.gauge.JCLinearScale lscale,
                                       double inner_extent,
                                       double outer_extent,
                                       double width,
                                       double value,
                                       boolean is_reversed,
                                       boolean polygonIsCentered,
                                       com.klg.jclass.swing.gauge.JCPolygon polygon,
                                       Rectangle bounds)
Get the contour of a polygon and its position given a linear scale, inner and outer extent, its width, a value on the scale at which to draw, and various other attributes.The xpoints[0], ypoints[0] from Polygon return the position of polygon. The points xpoints[1], ypoints[1]... return the contour of the polygon.

Parameters:
lscale - The linear scale used to base the polygon drawing on
inner_extent - The inner extent of the polygon (based on the radius radius of the circular scale).
outer_extent - The outer extent of the polygon (based on the radius radius of the circular scale).
width - The width of the polygon (in pixels)
value - The value along the scale at which to draw (it must be between the scale's min and max)
is_reversed - Is the polygon reversed?
polygonIsCentered - If the polygon is centered, place it midway between the inner and outer extent. Otherwise, place the polygon origin at left extent.
polygon - The polygon to draw. The JCPolygon class is a class that extends Polygon. It contains a method to get a bounding rectangle around a polygon.
bounds - The reference rectangle for contour. For drawing used lscale.getScaleSize(). For image mapping use lscale.getBounds()
Returns:
Polygon The absolute position and contour of the polygon

drawLinearPolygon

public static void drawLinearPolygon(Graphics g,
                                     com.klg.jclass.swing.gauge.JCLinearScale lscale,
                                     Color foreground,
                                     double inner_extent,
                                     double outer_extent,
                                     double width,
                                     double value,
                                     boolean is_reversed,
                                     boolean polygonIsCentered,
                                     com.klg.jclass.swing.gauge.JCPolygon polygon)
Draw a polygon given a linear scale, inner and outer extent, its width, a value on the scale at which to draw, and various other attributes.

Parameters:
g - The graphics context on which to draw
lscale - The linear scale used to base the polygon drawing on
foreground - The foreground color of the polygon
inner_extent - The inner extent of the polygon (based on the radius radius of the circular scale).
outer_extent - The outer extent of the polygon (based on the radius radius of the circular scale).
width - The width of the polygon (in pixels)
value - The value along the scale at which to draw (it must be between the scale's min and max)
is_reversed - Is the polygon reversed?
polygonIsCentered - If the polygon is centered, place it midway between the inner and outer extent. Otherwise, place the polygon origin at left extent.
polygon - The polygon to draw. The JCPolygon class is a class that extends Polygon. It contains a method to get a bounding rectangle around a polygon.

getCircleForCircularScale

public static int[] getCircleForCircularScale(com.klg.jclass.swing.gauge.JCCircularScale cscale,
                                              double value,
                                              double inner_extent,
                                              double outer_extent)
Get a circle based on a circular scale based on the value, inner_extent, and outer_extent.

Parameters:
cscale - The circular scale used to determine radius & position
value - The value on the scale at which this circle will be drawn
inner_extent - The inner extent as a fraction of the radius
outer_extent - The outer extent as a fraction of the radius
Returns:
int[] The absolute(x,y) position of center and radius

drawCircleForCircularScale

public static void drawCircleForCircularScale(Graphics g,
                                              com.klg.jclass.swing.gauge.JCCircularScale cscale,
                                              Color foreground,
                                              double value,
                                              double inner_extent,
                                              double outer_extent)
Draws a filled circle based on a circular scale based on the value, inner_extent, and outer_extent.

Parameters:
g - The graphics context on which to draw
cscale - The circular scale used to determine radius & position
foreground - The foreground color of the circle
value - The value on the scale at which this circle will be drawn
inner_extent - The inner extent as a fraction of the radius
outer_extent - The outer extent as a fraction of the radius

getCircleForLinearScale

public static int[] getCircleForLinearScale(com.klg.jclass.swing.gauge.JCLinearScale lscale,
                                            double value,
                                            double inner_extent,
                                            double outer_extent,
                                            Rectangle bounds)
Get the center position and the radius of a circle based on a linear scale based on the value, inner_extent, and outer_extent.

Parameters:
lscale - The linear scale used to determine radius & position
value - The value on the scale at which this circle will be drawn
inner_extent - The inner extent as a fraction of the radius
outer_extent - The outer extent as a fraction of the radius
bounds - Rectangle The reference rectangle for contour. For drawing used lscale.getScaleSize(). For image mapping use lscale.getBounds()
Returns:
int[] The returned array contains the absolute center position (x, y) and the radius of the circle

drawCircleForLinearScale

public static void drawCircleForLinearScale(Graphics g,
                                            com.klg.jclass.swing.gauge.JCLinearScale lscale,
                                            Color foreground,
                                            double value,
                                            double inner_extent,
                                            double outer_extent)
Draws a filled circle based on a linear scale based on the value, inner_extent, and outer_extent.

Parameters:
g - The graphics context on which to draw
lscale - The linear scale used to determine position and width/height
foreground - The foreground color of the circle
value - The value on the scale at which this circle will be drawn
inner_extent - The inner extent as a fraction of the width/height
outer_extent - The outer extent as a fraction of the width/height

createLegendPopulatorRenderer

public static void createLegendPopulatorRenderer(com.klg.jclass.swing.gauge.JCGauge gauge,
                                                 com.klg.jclass.swing.gauge.JCScale scale)
Creates a LegendPopulatorRenderer for a given gauge and scale.

Parameters:
gauge - The gauge whose legend needs a PopulatorRenderer
scale - The scale whose ranges need to be part of a legend.

translateContour

public static Polygon translateContour(Polygon input)
Parameters:
input - Polygon to be translated
Returns:
a Polygon that includes all the points of the input polygon excepts the first point, the pairs (x,y) beeing translated to the that point

Copyright © 2004 Quest Software Inc..
All rights reserved.