JIDE 3.5.15

com.jidesoft.gauge
Class AbstractGauge<AxisType>

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.jidesoft.gauge.AbstractGauge<AxisType>
All Implemented Interfaces:
ResizableComponent, GaugeModelListener, ImageObserver, MenuContainer, Serializable, EventListener
Direct Known Subclasses:
Bullet, Dial

public abstract class AbstractGauge<AxisType>
extends JComponent
implements GaugeModelListener, ResizableComponent

An abstract superclass for gauge components. A Dial is a Gauge component and we are introducing a new Gauge component called Bullet.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String DEFAULT_NEEDLE_NAME
           
static String PROPERTY_BACKGROUND_PAINT
           
static String PROPERTY_RESIZE_FONTS
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
AbstractGauge()
           
 
Method Summary
protected abstract  Point2D calculatePixelPoint2D(AxisType axis, double value)
           
protected  Positionable createPositionable(Double value)
          When the supplied value is a double and we need to create a Positionable object this method is called to create that object.
protected  boolean drawRotatedStringIfWithinBounds(Graphics g, Font f, String s, float x, float y, double rotation)
           
protected  boolean drawStringIfWithinBounds(Graphics2D g, String s, float x, float y)
          Paints a string but only if the whole of the string will be visible according to the bounds of the component
 void gaugeChanged(GaugeModelEvent e)
          This is the method of the GaugeModelListener interface
protected  Color getAncestorBackground()
           
 Paint getBackgroundPaint()
          We would like to provide the ability to get/set a Paint as the background rather than just a Color, so we provide that ability through this property.
 Dimension getFontComparisonSize()
          Returns the component size used for comparison when font resizing is switched on
 float getFontSizeRatio()
          Returns the current font size ratio, when auto-resizing fonts
 GaugeModel getModel()
           
 Double getValue()
           
 Double getValue(String needleName)
           
 boolean isAllowTickLabelOverlap()
          Returns the property that specifies whether tick labels are allowed to overlap
 boolean isResizeFonts()
          Return a boolean to indicate whether fonts are being auto-resized.
 boolean isShadowVisible()
           
protected  String longestTickLabel(Collection<Tick> ticks, FontMetrics fm)
           
 void setAllowTickLabelOverlap(boolean allowTickLabelOverlap)
          Normally you would not want your tick labels to overlap, but this property provides for this as a possibility.
 void setBackgroundPaint(Paint background)
          Specify the background to use for this gauge.
 void setFontComparisonSize(Dimension fontComparisonSize)
          Specify the size that will be used to determine the new font size when resizing.
protected  void setFontSizeRatio(float fontSizeRatio)
           
 void setModel(GaugeModel model)
           
 void setResizeFonts(boolean resizeFonts)
          Specify whether to automatically resize fonts
 void setShadowVisible(boolean shadowVisible)
           
 void setValue(Double value)
          Set the value of the gauge
 void setValue(int value)
           
 void setValue(String needleName, Double value)
          Set the value of the specified needle
 void setValue(String needleName, double value, boolean fireUpdate)
          Set the value of the specified needle
 void setValue(String needleName, int value)
          Set the value of the specified needle
 void setValue(String needleName, Positionable pos)
          Set the value of the specified needle
abstract  void setValue(String needleName, Positionable pos, boolean fireUpdate)
           
 Font tickLabelFontForAxis(AbstractNumericGaugeAxis axis)
          Returns the tick label font to be used for the supplied axis.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.jidesoft.chart.ResizableComponent
addComponentListener
 

Field Detail

DEFAULT_NEEDLE_NAME

public static final String DEFAULT_NEEDLE_NAME
See Also:
Constant Field Values

PROPERTY_BACKGROUND_PAINT

public static final String PROPERTY_BACKGROUND_PAINT
See Also:
Constant Field Values

PROPERTY_RESIZE_FONTS

public static final String PROPERTY_RESIZE_FONTS
See Also:
Constant Field Values
Constructor Detail

AbstractGauge

public AbstractGauge()
Method Detail

gaugeChanged

public void gaugeChanged(GaugeModelEvent e)
This is the method of the GaugeModelListener interface

Specified by:
gaugeChanged in interface GaugeModelListener
Parameters:
e - the GaugeModelEvent

getModel

public GaugeModel getModel()

setModel

public void setModel(GaugeModel model)

getValue

public Double getValue()
Returns:
the current value of the gauge

getValue

public Double getValue(String needleName)

createPositionable

protected Positionable createPositionable(Double value)
When the supplied value is a double and we need to create a Positionable object this method is called to create that object. By default, it creates a RealPosition but if necessary you can override the method to create an instance of a different class.

Parameters:
value - the double that we need to convert to a Positionable object
Returns:
a Positionable object

setValue

public void setValue(int value)

setValue

public void setValue(Double value)
Set the value of the gauge

Parameters:
value - the new value

setValue

public void setValue(String needleName,
                     Double value)
Set the value of the specified needle

Parameters:
needleName - the needle whose value we are setting
value - the value of the needle

setValue

public void setValue(String needleName,
                     int value)
Set the value of the specified needle

Parameters:
needleName - the needle whose value we are setting
value - the value of the needle

setValue

public void setValue(String needleName,
                     Positionable pos)
Set the value of the specified needle

Parameters:
needleName - the needle whose value we are setting
pos - a Positionable object that carries the value of the needle (and possibly other information too)

setValue

public void setValue(String needleName,
                     double value,
                     boolean fireUpdate)
Set the value of the specified needle

Parameters:
needleName - the needle whose value we are setting
value - the value of the needle
fireUpdate - specify whether an update event should be fired on the model

setValue

public abstract void setValue(String needleName,
                              Positionable pos,
                              boolean fireUpdate)

calculatePixelPoint2D

protected abstract Point2D calculatePixelPoint2D(AxisType axis,
                                                 double value)

isShadowVisible

public boolean isShadowVisible()

setShadowVisible

public void setShadowVisible(boolean shadowVisible)

setResizeFonts

public void setResizeFonts(boolean resizeFonts)
Specify whether to automatically resize fonts

Parameters:
resizeFonts - whether to automatically resize fonts

isResizeFonts

public boolean isResizeFonts()
Return a boolean to indicate whether fonts are being auto-resized.

Specified by:
isResizeFonts in interface ResizableComponent
Returns:
a boolean to indicate whether fonts are being auto-resized.

getFontComparisonSize

public Dimension getFontComparisonSize()
Returns the component size used for comparison when font resizing is switched on

Returns:
the component size used for comparison when font resizing is switched on

setFontComparisonSize

public void setFontComparisonSize(Dimension fontComparisonSize)
Specify the size that will be used to determine the new font size when resizing. In effect, this property calibrates the font resizing, but is used only if the resizeFonts property is also set to true. If you don't set the property explicitly then it will be set at the size that this component is first shown.

Parameters:
fontComparisonSize - a component size for which tick labels will be shown at their specified size

getFontSizeRatio

public float getFontSizeRatio()
Returns the current font size ratio, when auto-resizing fonts

Returns:
the computed font size ratio

setFontSizeRatio

protected void setFontSizeRatio(float fontSizeRatio)

tickLabelFontForAxis

public Font tickLabelFontForAxis(AbstractNumericGaugeAxis axis)
Returns the tick label font to be used for the supplied axis. This depends on both the size of the Dial component (assuming resizeFonts is switched on) and the font supplied by the axis.

Parameters:
axis - the axis of interest
Returns:
a Font whose size style is determined by the axis and size determined by the size of this dial

getBackgroundPaint

public Paint getBackgroundPaint()
We would like to provide the ability to get/set a Paint as the background rather than just a Color, so we provide that ability through this property. However, if the property has not been set with a Paint instance, then this method returns a Color instance by internally calling Component.getBackground() instead.

Returns:
a Paint instance (which may be a Color)

setBackgroundPaint

public void setBackgroundPaint(Paint background)
Specify the background to use for this gauge. This is like the setBackground() method of JComponent, except that you can supply a Paint instance rather than just a Color. This opens up the possibilities with gradient effects.

Parameters:
background - the background Paint

getAncestorBackground

protected Color getAncestorBackground()

longestTickLabel

protected String longestTickLabel(Collection<Tick> ticks,
                                  FontMetrics fm)

drawStringIfWithinBounds

protected boolean drawStringIfWithinBounds(Graphics2D g,
                                           String s,
                                           float x,
                                           float y)
Paints a string but only if the whole of the string will be visible according to the bounds of the component

Parameters:
g - the Graphics context
s - the string to draw
x - the bottom left x coordinate of the drawn string
y - the bottom left y coordinate of the drawn string
Returns:
a boolean to indicate whether the string was actually drawn

drawRotatedStringIfWithinBounds

protected boolean drawRotatedStringIfWithinBounds(Graphics g,
                                                  Font f,
                                                  String s,
                                                  float x,
                                                  float y,
                                                  double rotation)
Parameters:
g - the Graphics context into which to draw
s - the string to draw
x - the x coordinate of the centre of where the string should be drawn
y - the y coordinate of the centre of where the string should be drawn
rotation - the rotation to use, in radians
Returns:
a boolean to indicate whether the string was drawn

isAllowTickLabelOverlap

public boolean isAllowTickLabelOverlap()
Returns the property that specifies whether tick labels are allowed to overlap

Returns:
the property that specifies whether tick labels are allowed to overlap

setAllowTickLabelOverlap

public void setAllowTickLabelOverlap(boolean allowTickLabelOverlap)
Normally you would not want your tick labels to overlap, but this property provides for this as a possibility. The default value is false, but you could set it true to perhaps configure the appearance of a fixed size dial.

Parameters:
allowTickLabelOverlap - specify whether tick labels are allowed to overlap

JIDE 3.5.15