gpl.fredy.ui
Class Gauge

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by gpl.fredy.ui.Gauge
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class Gauge
extends java.awt.Canvas

"Gauge" is a simple control, used to display a range of values using a "meter" format.

Accessible Attributes:

 MinimumValue      Low end of the scale
 MaximumValue      High end of the scale
 CurrentValue      Current setting (where the Pointer points)
 CriticalThreshold Percentage of MaxValue at which we start drawing using the Critical color
 WarningThreshold  Percentage of MaxValue at which we start drawing using the Warning color
 Legend            What we're measuring (e.g., Speed)
 Units             What units we're using (e.g., MPH)
 

Attributes not yet publically accessible (next version, perhaps):

 MinimumAngle  Angle at which Minimum Value will be drawn
 MaximumAngle  Angle at which Maximum Value will be drawn
 Margin        Distance between the Scale and the Component's bounds() rect
 Separation    Distance between Gauge subobjects (e.g, between Pointer and Scale)
 CriticalColor Color used to draw the Critical Section of the Scale(e.g., Color.red)
 WarningColor  Color used to draw the Warning Section of the Scale
 NormalColor   Color used to draw the Normal Section of the Scale
 InternalColor Color used to draw the interior of the Scale
 PenRadius     Used to determine thickness of Pointer and Scale
 Draw3D        Should the background be drawn as a raised rectangle?
 TickSize      How long (in pixels) is a BigTick?
 BigTick       Interval starting at Minimum at which BigTicks will be drawn
 LittleTick    Interval starting at Minimum at which LittleTicks will be drawn
 

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
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
 
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
Gauge()
          Constructs a Gauge object.
Gauge(int min, int max)
          Constructs a Gauge object with specified Min and Max.
Gauge(int min, int max, float warn, float crit, java.lang.String newLegend, java.lang.String newUnits)
          Constructs a Gauge with the specified Min, Max, Legend, and Units values.
 
Method Summary
 void drawBackground(java.awt.Graphics g)
          If Draw3d is set, draw the background as a filled 3D rect in the current Background Color.
 void drawPointer(java.awt.Graphics g)
          drawPointer draws the Pivot and the Pointer
 void drawScale(java.awt.Graphics g)
          drawScale draws the ScaleArc itself, and the tick-marks
 void drawStrings(java.awt.Graphics g)
          drawStrings draws the Legend, Units, Min, and Max.
 void drawTick(java.awt.Graphics g, int where, int offset)
          drawTick draws one tick-mark from center of scale-arc _INWARDS_
 double getCriticalThreshold()
           
 int getCurrent()
           
 int getMaximum()
           
 int getMinimum()
           
 java.awt.Color getValColor(int val)
          getValColor returns the color associated with the region into which the value falls.
 double getWarningThreshold()
           
protected  void init()
          init() sets Guage's attributes to a "sane" set of initial values.
 java.awt.Point mapValToPoint(int val)
          mapValToPoint returns a Point on the Scale for the specified value
 java.awt.Point mapValToPoint(int val, int radius)
          mapValToPoint returns a Point "radius" units from the Pivit for the specified value
 java.awt.Dimension minimumSize()
          A Gauge wants to be no smaller than (100,100)
 boolean mouseDown(java.awt.Event evt, int x, int y)
           
 boolean mouseDrag(java.awt.Event evt, int x, int y)
           
 boolean mouseUp(java.awt.Event evt, int x, int y)
           
 void paint(java.awt.Graphics g)
          paint() paints in this order: Background (includes Internal area) Scale (includes TickMarks) Strings (Legend, Units, Min, Max) Pointer (inlcudes Pivot)
 java.awt.Dimension preferredSize()
          Gauges prefer their minSize.
 void repaint()
           
 void repaint(int x, int y, int w, int h)
           
 void repaint(long when)
           
 void repaint(long when, int x, int y, int w, int h)
           
 void reshape(int x, int y, int w, int h)
           
 void setCriticalThreshold(float newCritPcnt)
          Change the Gauge's Critical Threshold.
 void setCurrent(int newCurr)
          Change the Gauge's Current Value (the value the pointer points at)
 void setLegend(java.lang.String newLegend)
          Change the Gauge's Legend (what this Gauge is measuring; e.g., Speed or Swap Rate)
 void setMaximum(int max)
          Change the Gauge's Maximum Value
 void setMinimum(int min)
          Change the Gauge's Minimum Value
 void setSize(java.awt.Dimension dim)
           
 void setSize(int w, int h)
          When resized, recalculate where everything lives.
 void setUnits(java.lang.String newUnits)
          Change the Gauge's Units (what Value is measured in; e.g., KPH or PPM)
 void setWarningThreshold(float newWarnPcnt)
          Change the Gauge's Warning Threshold.
 java.lang.String toString()
           
 void update(java.awt.Graphics g)
          At update(); draw into an off-screen image and put up the whole image.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, 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, 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, mouseEnter, mouseExit, mouseMove, move, nextFocus, paintAll, paramString, postEvent, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setVisible, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Gauge

public Gauge()
Constructs a Gauge object. Uses all default values.

See Also:
init()

Gauge

public Gauge(int min,
             int max)
Constructs a Gauge object with specified Min and Max.

Parameters:
min - Minimum Gauge value
max - Maximum Gauge Value
See Also:
init()

Gauge

public Gauge(int min,
             int max,
             float warn,
             float crit,
             java.lang.String newLegend,
             java.lang.String newUnits)
Constructs a Gauge with the specified Min, Max, Legend, and Units values.

Parameters:
min - Minimum Value
max - Maximum Value
warn - Percentage of Max of start of Warning area
crit - Percentage of Max of start of Critical area
newLegend - Gauge Legend
newUnits - Gauge Units
Method Detail

init

protected void init()
init() sets Guage's attributes to a "sane" set of initial values.

Defaults are:

  Minimum         = 0
  Maximum         = 200
  Current         = Minimum
  Legend          = "Velocity"
  Units           = "KPH"
  WarningThresh   = 0.7
  CriticalThresh  = 0.9
  CriticalColor   = Color.red
  WarningColor    = Color.yellow
  InternalColor   = Color.black
  NormalColor     = getForeground()
  ForegroundColor = Color.white
  BackgroundColor = Color.gray
  Font            = "Courier", BOLD, 18
  


setLegend

public void setLegend(java.lang.String newLegend)
Change the Gauge's Legend (what this Gauge is measuring; e.g., Speed or Swap Rate)

Parameters:
newLegend - Legend's new value

setUnits

public void setUnits(java.lang.String newUnits)
Change the Gauge's Units (what Value is measured in; e.g., KPH or PPM)

Parameters:
newUnits - Units's new value

setMinimum

public void setMinimum(int min)
Change the Gauge's Minimum Value

Parameters:
min - New Minimum

getMinimum

public int getMinimum()

setMaximum

public void setMaximum(int max)
Change the Gauge's Maximum Value

Parameters:
max - New Maximum

getMaximum

public int getMaximum()

setCurrent

public void setCurrent(int newCurr)
Change the Gauge's Current Value (the value the pointer points at)

Parameters:
newCurr - New Current

getCurrent

public int getCurrent()

setWarningThreshold

public void setWarningThreshold(float newWarnPcnt)
Change the Gauge's Warning Threshold. This is the percentage of the Maximum Value at which the Warning Region begins.

Parameters:
newWarnPercnt - New Warning Threshold

getWarningThreshold

public double getWarningThreshold()

setCriticalThreshold

public void setCriticalThreshold(float newCritPcnt)
Change the Gauge's Critical Threshold. This is the percentage of the Maximum Value at which the Critical Region begins.

Parameters:
newCritPercnt - New Critical Threshold

getCriticalThreshold

public double getCriticalThreshold()

update

public void update(java.awt.Graphics g)
At update(); draw into an off-screen image and put up the whole image. This clears up any flickering.

Overrides:
update in class java.awt.Canvas

drawBackground

public void drawBackground(java.awt.Graphics g)
If Draw3d is set, draw the background as a filled 3D rect in the current Background Color. Otherwise, draw a flat rect.


drawTick

public void drawTick(java.awt.Graphics g,
                     int where,
                     int offset)
drawTick draws one tick-mark from center of scale-arc _INWARDS_

Parameters:
where - Value at which to draw the tick-mark
offset - How long to make the tick-mark

drawScale

public void drawScale(java.awt.Graphics g)
drawScale draws the ScaleArc itself, and the tick-marks


drawStrings

public void drawStrings(java.awt.Graphics g)
drawStrings draws the Legend, Units, Min, and Max.


getValColor

public java.awt.Color getValColor(int val)
getValColor returns the color associated with the region into which the value falls.

Parameters:
val - value of interest

mapValToPoint

public java.awt.Point mapValToPoint(int val)
mapValToPoint returns a Point on the Scale for the specified value


mapValToPoint

public java.awt.Point mapValToPoint(int val,
                                    int radius)
mapValToPoint returns a Point "radius" units from the Pivit for the specified value


drawPointer

public void drawPointer(java.awt.Graphics g)
drawPointer draws the Pivot and the Pointer


setSize

public void setSize(int w,
                    int h)
When resized, recalculate where everything lives.

Rules for resizing a Gauge:

Overrides:
setSize in class java.awt.Component

setSize

public void setSize(java.awt.Dimension dim)
Overrides:
setSize in class java.awt.Component
See Also:
Component.resize(int,int)

reshape

public void reshape(int x,
                    int y,
                    int w,
                    int h)
Overrides:
reshape in class java.awt.Component
See Also:
Component.resize(int,int)

minimumSize

public java.awt.Dimension minimumSize()
A Gauge wants to be no smaller than (100,100)

Overrides:
minimumSize in class java.awt.Component

preferredSize

public java.awt.Dimension preferredSize()
Gauges prefer their minSize.

Overrides:
preferredSize in class java.awt.Component
See Also:
minimumSize()

paint

public void paint(java.awt.Graphics g)
paint() paints in this order:
  1. Background (includes Internal area)
  2. Scale (includes TickMarks)
  3. Strings (Legend, Units, Min, Max)
  4. Pointer (inlcudes Pivot)

Overrides:
paint in class java.awt.Canvas

repaint

public void repaint()
Overrides:
repaint in class java.awt.Component

repaint

public void repaint(long when)
Overrides:
repaint in class java.awt.Component

repaint

public void repaint(int x,
                    int y,
                    int w,
                    int h)
Overrides:
repaint in class java.awt.Component

repaint

public void repaint(long when,
                    int x,
                    int y,
                    int w,
                    int h)
Overrides:
repaint in class java.awt.Component

mouseDown

public boolean mouseDown(java.awt.Event evt,
                         int x,
                         int y)
Overrides:
mouseDown in class java.awt.Component

mouseDrag

public boolean mouseDrag(java.awt.Event evt,
                         int x,
                         int y)
Overrides:
mouseDrag in class java.awt.Component

mouseUp

public boolean mouseUp(java.awt.Event evt,
                       int x,
                       int y)
Overrides:
mouseUp in class java.awt.Component

toString

public java.lang.String toString()
Overrides:
toString in class java.awt.Component