All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsWidget, LogicalStructure, HasDrawEndHandlers, HasDrawStartHandlers, HasClearHandlers, HasClickHandlers, HasDoubleClickHandlers, HasDragMoveHandlers, HasDragRepositionMoveHandlers, HasDragRepositionStartHandlers, HasDragRepositionStopHandlers, HasDragResizeMoveHandlers, HasDragResizeStartHandlers, HasDragResizeStopHandlers, HasDragStartHandlers, HasDragStopHandlers, HasDropHandlers, HasDropMoveHandlers, HasDropOutHandlers, HasDropOverHandlers, HasFocusChangedHandlers, HasHoverHandlers, HasHoverHiddenHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseStillDownHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasMovedHandlers, HasParentMovedHandlers, HasResizedHandlers, HasRightMouseDownHandlers, HasRuleContextChangedHandlers, HasScrolledHandlers, HasShowContextMenuHandlers, HasVisibilityChangedHandlers

public class Gauge extends DrawPane
The Gauge widget class implements a graphical speedometer-style gauge for displaying a measurement by means of a needle on a dial. The dial is divided into sectors, each having its own color and value.

NOTE: you must load the standard Drawing module before you can use Gauge.

  • Constructor Details

  • Method Details

    • getOrCreateRef

      public static Gauge getOrCreateRef(JavaScriptObject jsObj)
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, Canvas defaults)
      Changes the defaults for Canvas AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - Canvas defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, FormItem defaults)
      Changes the defaults for FormItem AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - FormItem defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • create

      protected JavaScriptObject create()
      Overrides:
      create in class DrawPane
    • setBorderColor

      public Gauge setBorderColor(String borderColor) throws IllegalStateException
      Color for gauge sector borders.
      Parameters:
      borderColor - New borderColor value. Default value is "#333333"
      Returns:
      Gauge instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getBorderColor

      public String getBorderColor()
      Color for gauge sector borders.
      Returns:
      Current borderColor value. Default value is "#333333"
      See Also:
    • setBorderWidth

      public Gauge setBorderWidth(int borderWidth) throws IllegalStateException
      Pixel width for gauge sector borders.
      Parameters:
      borderWidth - New borderWidth value. Default value is 1
      Returns:
      Gauge instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getBorderWidth

      public int getBorderWidth()
      Pixel width for gauge sector borders.
      Returns:
      Current borderWidth value. Default value is 1
      See Also:
    • setDialRadius

      public Gauge setDialRadius(float dialRadius)
      Deprecated.
      Radius in pixels of the dial.

      If this method is called after the component has been drawn/initialized: All DrawItems currently associated with this Gauge are destroyed and new DrawItems are created instead.
      Parameters:
      dialRadius - Radius in pixels of the dial. Default value is 150
      Returns:
      Gauge instance, for chaining setter calls
    • getDialRadius

      public float getDialRadius()
      Deprecated.
      Radius in pixels of the dial.
      Returns:
      Current dialRadius value. Default value is 150
    • setDialRadius

      public Gauge setDialRadius(double dialRadius)
      Radius in pixels of the dial.

      If this method is called after the component has been drawn/initialized: All DrawItems currently associated with this Gauge are destroyed and new DrawItems are created instead.
      Parameters:
      dialRadius - Radius in pixels of the dial. Default value is 150
      Returns:
      Gauge instance, for chaining setter calls
    • getDialRadiusAsDouble

      public double getDialRadiusAsDouble()
      Radius in pixels of the dial.
      Returns:
      Current dialRadius value. Default value is 150
    • setDrawnClockwise

      public Gauge setDrawnClockwise(boolean drawnClockwise)
      Whether the sectors are drawn clockwise, and increasing the value causes the needle to move clockwise.

      If this method is called after the component has been drawn/initialized: Sets the drawnClockwise property and redraws the gauge.
      Parameters:
      drawnClockwise - whether the sectors are drawn clockwise. Default value is true
      Returns:
      Gauge instance, for chaining setter calls
    • getDrawnClockwise

      public boolean getDrawnClockwise()
      Whether the sectors are drawn clockwise, and increasing the value causes the needle to move clockwise.
      Returns:
      Current drawnClockwise value. Default value is true
    • setFontSize

      public Gauge setFontSize(int fontSize) throws IllegalStateException
      Font size of sector labels. Must be at least 3.
      Parameters:
      fontSize - New fontSize value. Default value is 11
      Returns:
      Gauge instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getFontSize

      public int getFontSize()
      Font size of sector labels. Must be at least 3.
      Returns:
      Current fontSize value. Default value is 11
      See Also:
    • setLabelPrefix

      public Gauge setLabelPrefix(String labelPrefix)
      The label prefix.

      If this method is called after the component has been drawn/initialized: Sets the labelPrefix property and re-creates all sector labels.
      Parameters:
      labelPrefix - the new label prefix. Default value is ""
      Returns:
      Gauge instance, for chaining setter calls
      See Also:
    • getLabelPrefix

      public String getLabelPrefix()
      The label prefix.
      Returns:
      Current labelPrefix value. Default value is ""
      See Also:
    • setLabelSuffix

      public Gauge setLabelSuffix(String labelSuffix)
      The label suffix.

      If this method is called after the component has been drawn/initialized: Sets the labelSuffix property and re-creates all sector labels.
      Parameters:
      labelSuffix - the new label suffix. Default value is "%"
      Returns:
      Gauge instance, for chaining setter calls
      See Also:
    • getLabelSuffix

      public String getLabelSuffix()
      The label suffix.
      Returns:
      Current labelSuffix value. Default value is "%"
      See Also:
    • setMaxValue

      public Gauge setMaxValue(float maxValue)
      Deprecated.
      The maximum dial value.

      If this method is called after the component has been drawn/initialized: Sets the maximum dial value, rescaling all sectors and the dial value.

      See setValueRange to set both minValue and maxValue together.

      Parameters:
      maxValue - the new maximum dial value. Must be at least 1 greater than the minimum dial value. If maxValue is not at least 1 greater than the minimum value, then it is set to 1 + minValue. Default value is 100
      Returns:
      Gauge instance, for chaining setter calls
    • getMaxValue

      public float getMaxValue()
      Deprecated.
      The maximum dial value.
      Returns:
      Current maxValue value. Default value is 100
    • setMaxValue

      public Gauge setMaxValue(double maxValue)
      The maximum dial value.

      If this method is called after the component has been drawn/initialized: Sets the maximum dial value, rescaling all sectors and the dial value.

      See setValueRange to set both minValue and maxValue together.

      Parameters:
      maxValue - the new maximum dial value. Must be at least 1 greater than the minimum dial value. If maxValue is not at least 1 greater than the minimum value, then it is set to 1 + minValue. Default value is 100
      Returns:
      Gauge instance, for chaining setter calls
    • getMaxValueAsDouble

      public double getMaxValueAsDouble()
      The maximum dial value.
      Returns:
      Current maxValue value. Default value is 100
    • setMinValue

      public Gauge setMinValue(float minValue)
      Deprecated.
      The minimum dial value.

      If this method is called after the component has been drawn/initialized: Sets the minimum dial value, rescaling all sectors and the dial value.

      See setValueRange to set both minValue and maxValue together.

      Parameters:
      minValue - the new minimum dial value. Must be at least 1 less than the maximum dial value. If minValue is not at least 1 less than the maximum value, then it is set to maxValue - 1. Default value is 0
      Returns:
      Gauge instance, for chaining setter calls
    • getMinValue

      public float getMinValue()
      Deprecated.
      The minimum dial value.
      Returns:
      Current minValue value. Default value is 0
    • setMinValue

      public Gauge setMinValue(double minValue)
      The minimum dial value.

      If this method is called after the component has been drawn/initialized: Sets the minimum dial value, rescaling all sectors and the dial value.

      See setValueRange to set both minValue and maxValue together.

      Parameters:
      minValue - the new minimum dial value. Must be at least 1 less than the maximum dial value. If minValue is not at least 1 less than the maximum value, then it is set to maxValue - 1. Default value is 0
      Returns:
      Gauge instance, for chaining setter calls
    • getMinValueAsDouble

      public double getMinValueAsDouble()
      The minimum dial value.
      Returns:
      Current minValue value. Default value is 0
    • getNeedle

      public DrawItem getNeedle() throws IllegalStateException
      AutoChild representing the needle shape that points to the gauge's current value. Default is to use a DrawTriangle.

      This component is an AutoChild named "needle". For an overview of how to use and configure AutoChildren, see Using AutoChildren.

      Returns:
      Current needle value. Default value is null
      Throws:
      IllegalStateException - if this widget has not yet been rendered.
    • setNumMajorTicks

      public Gauge setNumMajorTicks(int numMajorTicks)
      The number of major tick lines.

      If this method is called after the component has been drawn/initialized: Sets the number of major tick lines.

      NOTE: To divide the dial into n regions, you will need n + 1 ticks. For example, if the minimum value is 0 and the maximum value is 100, then to place major tick lines at 0, 10, 20, 30, ..., 90, 100, you need 11 (10 + 1) major ticks.

      Parameters:
      numMajorTicks - the number of major tick lines to draw. Must be either 0 or an integer greater than or equal to 2. Default value is 0
      Returns:
      Gauge instance, for chaining setter calls
    • getNumMajorTicks

      public int getNumMajorTicks()
      The number of major tick lines.
      Returns:
      Current numMajorTicks value. Default value is 0
    • setNumMinorTicks

      public Gauge setNumMinorTicks(int numMinorTicks)
      The number of minor tick lines.

      If this method is called after the component has been drawn/initialized: Sets the number of minor tick lines.

      NOTE: To divide the dial into n regions, you will need n + 1 ticks. For example, if the minimum value is 0 and the maximum value is 100, then to place minor tick lines at 0, 1, 2, 3, 4, 5, ..., 99, 100, you need 101 (100 + 1) minor ticks.

      Parameters:
      numMinorTicks - the number of minor tick lines to draw. Must be either 0 or an integer greater than or equal to 2. Default value is 0
      Returns:
      Gauge instance, for chaining setter calls
    • getNumMinorTicks

      public int getNumMinorTicks()
      The number of minor tick lines.
      Returns:
      Current numMinorTicks value. Default value is 0
    • setPivotPoint

      public Gauge setPivotPoint(Point pivotPoint)
      The pivot point of the needle.

      If this method is called after the component has been drawn/initialized: All DrawItems currently associated with this Gauge are destroyed and new DrawItems are created instead.

      The pivot point is set by default by choosing 1/2 of width and 70% of height of the Gauge. See pivotPointHeight

      Parameters:
      pivotPoint - The pivot point of the needle. Default value is null
      Returns:
      Gauge instance, for chaining setter calls
    • getPivotPoint

      public Point getPivotPoint()
      The pivot point of the needle.
      Returns:
      Current pivotPoint value. Default value is null
    • setPivotPointHeight

      public Gauge setPivotPointHeight(int pivotPointHeight) throws IllegalStateException
      Default height of the pivotPoint if no specific pivotPoint is specified.

      Can be specified as a numeric pixel value, or a String percentage value.

      Parameters:
      pivotPointHeight - New pivotPointHeight value. Default value is "70%"
      Returns:
      Gauge instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • getPivotPointHeight

      public int getPivotPointHeight()
      Default height of the pivotPoint if no specific pivotPoint is specified.

      Can be specified as a numeric pixel value, or a String percentage value.

      Returns:
      Current pivotPointHeight value. Default value is "70%"
    • setPivotPointHeight

      public Gauge setPivotPointHeight(String pivotPointHeight) throws IllegalStateException
      Default height of the pivotPoint if no specific pivotPoint is specified.

      Can be specified as a numeric pixel value, or a String percentage value.

      Parameters:
      pivotPointHeight - New pivotPointHeight value. Default value is "70%"
      Returns:
      Gauge instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • getPivotPointHeightAsString

      public String getPivotPointHeightAsString()
      Default height of the pivotPoint if no specific pivotPoint is specified.

      Can be specified as a numeric pixel value, or a String percentage value.

      Returns:
      Current pivotPointHeight value. Default value is "70%"
    • getPivotShape

      public DrawItem getPivotShape() throws IllegalStateException
      AutoChild representing the shape drawn at the pivotPoint (where all sectors of the gauge meet).

      This component is an AutoChild named "pivotShape". For an overview of how to use and configure AutoChildren, see Using AutoChildren.

      Returns:
      Current pivotShape value. Default value is null
      Throws:
      IllegalStateException - if this widget has not yet been rendered.
    • setSectorColors

      public Gauge setSectorColors(String... sectorColors) throws IllegalStateException
      Array of preset fill colors used by the default implementation of getDefaultFillColor() to initialize the fill color of new sectors.

      The default array of colors is:

      #AFFFFF #008080 #AAAFFF #FF0000 #FFCC99 #800080
      Parameters:
      sectorColors - New sectorColors value. Default value is [ "#AFFFFF", "#008080", "#AAAFFF", "#FF0000", "#FFCC99", "#800080" ]
      Returns:
      Gauge instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getSectorColors

      public String[] getSectorColors()
      Array of preset fill colors used by the default implementation of getDefaultFillColor() to initialize the fill color of new sectors.

      The default array of colors is:

      #AFFFFF #008080 #AAAFFF #FF0000 #FFCC99 #800080
      Returns:
      Current sectorColors value. Default value is [ "#AFFFFF", "#008080", "#AAAFFF", "#FF0000", "#FFCC99", "#800080" ]
      See Also:
    • setSectors

      public Gauge setSectors(GaugeSector... sectors)
      The GaugeSectors contained in this Gauge. If this this property is not specified, the gauge will be created with a default sector filling the gauge.

      If this method is called after the component has been drawn/initialized: Sets the sectors for this gauge.
      Parameters:
      sectors - the sectors to show on the gauge. Default value is null
      Returns:
      Gauge instance, for chaining setter calls
    • getSectors

      public GaugeSector[] getSectors()
      The GaugeSectors contained in this Gauge. If this this property is not specified, the gauge will be created with a default sector filling the gauge.
      Returns:
      Current sectors value. Default value is null
    • getSectorShape

      public DrawSector getSectorShape()
      Note : This API is non-functional (always returns null) and exists only to make you aware that this MultiAutoChild exists. See Using AutoChildren for details.

      MultiAutoChild representing the sectors drawn to show different segments of the gauge.

      Returns:
      null
    • getTickLine

      public DrawItem getTickLine()
      Note : This API is non-functional (always returns null) and exists only to make you aware that this MultiAutoChild exists. See Using AutoChildren for details.

      MultiAutoChild representing the tick marks drawn along the circumference of the gauge. Default is to use DrawLine.

      Returns:
      null
    • setValue

      public Gauge setValue(float value)
      Deprecated.
      The current value on the dial.

      If this method is called after the component has been drawn/initialized: Sets the value on the dial that the needle is displaying.
      Parameters:
      value - the new dial value. Must be between minValue and maxValue. Default value is 0
      Returns:
      Gauge instance, for chaining setter calls
    • getValue

      public float getValue()
      Deprecated.
      The current value on the dial.
      Returns:
      Current value value. Default value is 0
    • setValue

      public Gauge setValue(double value)
      The current value on the dial.

      If this method is called after the component has been drawn/initialized: Sets the value on the dial that the needle is displaying.
      Parameters:
      value - the new dial value. Must be between minValue and maxValue. Default value is 0
      Returns:
      Gauge instance, for chaining setter calls
    • getValueAsDouble

      public double getValueAsDouble()
      The current value on the dial.
      Returns:
      Current value value. Default value is 0
    • getValueLabel

      public DrawLabel getValueLabel()
      Note : This API is non-functional (always returns null) and exists only to make you aware that this MultiAutoChild exists. See Using AutoChildren for details.

      MultiAutoChild representing the labels used to different data points on the gauge.

      Returns:
      null
    • addSector

      public int addSector(GaugeSector newSector)
      Adds a new sector.
      Parameters:
      newSector - the new GaugeSector or the new sector's value. This is formatted with formatLabelContents() to get its label.
      Returns:
      the index of the newly-added sector.
    • addSector

      public int addSector(double newSector)
      Adds a new sector.
      Parameters:
      newSector - the new GaugeSector or the new sector's value. This is formatted with formatLabelContents() to get its label.
      Returns:
      the index of the newly-added sector.
    • getNumSectors

      public int getNumSectors()
      Gets the number of sectors.
      Returns:
      the number of sectors on this gauge.
    • getSectorFillColor

      public String getSectorFillColor(int sectorIndex)
      Gets the fill color of the sector at index sectorIndex.
      Parameters:
      sectorIndex - index of the target sector.
      Returns:
      the fill color of the sector at sectorIndex. See CSSColor
      See Also:
    • getSectorLabelContents

      public String getSectorLabelContents(int sectorIndex)
      Gets the label contents of the label for the sector at sectorIndex.
      Parameters:
      sectorIndex - index of the target sector.
      Returns:
      the label contents of the sector's label.
    • getSectorValue

      public float getSectorValue(int sectorIndex)
      Deprecated.
      Gets the value of the sector at sectorIndex.
      Parameters:
      sectorIndex - index of the target sector.
      Returns:
      the value of the sector at sectorIndex.
    • getSectorValueAsDouble

      public double getSectorValueAsDouble(int sectorIndex)
      Gets the value of the sector at sectorIndex.
      Parameters:
      sectorIndex - index of the target sector.
      Returns:
      the value of the sector at sectorIndex.
    • reformatLabelContents

      public void reformatLabelContents()
      Resets the contents of all labels. This involves calling formatLabelContents() to get the label contents for each corresponding value and repositioning the label.
    • removeSector

      public void removeSector(int sectorIndex)
      Removes the sector at sectorIndex.

      NOTE: There must always be one sector and it is not possible to remove the sole remaining sector. Calling this method to attempt to remove the sole remaining sector is a no-op.

      Parameters:
      sectorIndex - the index of the sector to remove.
    • setSectorFillColor

      public void setSectorFillColor(int sectorIndex, String fillColor)
      Sets the fill color of the sector at sectorIndex.
      Parameters:
      sectorIndex - index of the target sector.
      fillColor - the new fill color. See CSSColor
      See Also:
    • setValueRange

      public void setValueRange(double minValue, double maxValue)
      Sets the minimum and maximum dial values, rescaling all sectors and the dial value.
      Parameters:
      minValue - the new minimum dial value
      maxValue - the new maximum dial value
    • setDefaultProperties

      public static void setDefaultProperties(Gauge gaugeProperties)
      Class level method to set the default properties of this class. If set, then all existing and subsequently created instances of this class will automatically have default properties corresponding to the properties set on the SmartGWT class instance passed to this function before its underlying SmartClient JS object was created. This is a powerful feature that eliminates the need for users to create a separate hierarchy of subclasses that only alter the default properties of this class. Can also be used for skinning / styling purposes.

      Note: This method is intended for setting default attributes only and will affect all instances of the underlying class (including those automatically generated in JavaScript). This method should not be used to apply standard EventHandlers or override methods for a class - use a custom subclass instead. Calling this method after instances have been created can result in undefined behavior, since it bypasses any setters and a class instance may have already examined a particular property and not be expecting any changes through this route.

      Parameters:
      gaugeProperties - properties that should be used as new defaults when instances of this class are created
      See Also:
    • onInit

      protected void onInit()
      Overrides:
      onInit in class Canvas
    • formatLabelContents

      protected String formatLabelContents(float value)
      Formats a value as a string to be used as the contents of a DrawLabel. The default implementation prepends labelPrefix and appends labelSuffix to value.

      NOTE: This is an override point. If a subclass overrides this, then whenever it changes the way that values are formatted, it should call Gauge.reformatLabelContents.

      Parameters:
      value - the value to format.
      Returns:
      label contents.
    • getDefaultFillColor

      protected String getDefaultFillColor(int sectorIndex)
      Gets the default fill color for the sector at index sectorIndex. The default implementation cycles through sectorColors using modular arithmetic.

      Note: This is an override point.

      Parameters:
      sectorIndex - index of the target sector.
      Returns:
      a fill color.
    • setLogicalStructure

      public LogicalStructureObject setLogicalStructure(GaugeLogicalStructure s)
      Setter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
    • getLogicalStructure

      public LogicalStructureObject getLogicalStructure()
      Getter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
      Specified by:
      getLogicalStructure in interface LogicalStructure
      Overrides:
      getLogicalStructure in class DrawPane