Search
Pointers

The pointers represent needles or similar type of indicators within the scale. They are used to visualize a current measurement within the scale. The most important member of the pointer object is its Value. The pointer is automatically adjusted by its containing scale so that it points to the scale location, corresponding to its value.

The size of the pointer is defined by the PointerWidth and PointerHeight properties. These properties can express the size as relative or absolute value. The location of the pointer can be adjusted through the PointerOffset property and its alignment in a linear scale can be specified through the Alignment property.

The pointer can be made interactive by setting the IsInteractive property to true. Clicking with the mouse within a scale causes all its interactive pointers to be adjusted to the value corresponding to the clicked point. A pointer can be made discrete by setting IsDiscrete to true. The value of a discrete pointer is always integer.

Usage

The sample code below illustrates how to define and add pointers to an existing scale:

Java  Copy Code

Pointer pointer = new Pointer();
pointer.setIsInteractive(true);
scale.addPointer(pointer);

Custom Appearance

The appearance of the pointer can be customized by using the PrepaintPointer and PaintPointer events. The following example demonstrates an oval gauge with a compass needle type of pointer:

Java  Copy Code

OvalGauge gauge = new OvalGauge();
  
OvalScale ovalScale = new OvalScale();
ovalScale.setFill(new SolidBrush(new Color(0, 0, 0,0)));
ovalScale.setStroke(new Pen(new Color(0, 0, 0, 0)));
ovalScale.setMinValue(0);
ovalScale.setMaxValue(360);
ovalScale.getMajorTickSettings().setShowTicks(false);
ovalScale.getMajorTickSettings().setShowLabels(false);
ovalScale.getMajorTickSettings().setShowTicks(false);
ovalScale.getMajorTickSettings().setShowLabels(false);

Pointer pointer = new Pointer();
pointer.setPointerWidth(new Length(200, LengthType.Relative));
pointer.setPointerHeight(new Length(20, LengthType.Relative));
pointer.setPointerOffset(new Length(90, LengthType.Relative));
pointer.setIsInteractive(true);
pointer.setShape(PointerShape.Custom);
ovalScale.getPointers().add(pointer);
gauge.getScales().add(ovalScale);

ovalGauge.addBaseGaugeListener(new BaseGaugeAdapter() 
{
   
   @Override
   public void paintPointer(CustomPaintEvent e)
   {
     RenderContext context = e.getContext();
     VisualElement element = e.getElement();
     double width = element.getActualWidth();
     double height = element.getActualHeight();

     PathFigure figure = new PathFigure("M0.5, 0 L1, 0.5 L0.5, 1 Z");
     figure.setFill(Utils.radialGradient(new Point2D.Double(0.5, 0.1), 
       new float[]{0, 0.3F, 1.0F}, new Color[]{new Color(193,0,0,1), new Color(255,0,0,1), new Color(102,0,0,1)}));
     figure.setStroke(new Pen(new Color(32,32,32,1)));
     e.paintVisualElement(figure, new XDimension2D.Double(width, height));

     PathFigure figure1 = new PathFigure("M0.5, 0 L0, 0.5 L0.5, 1 Z");
     figure1.setFill(Utils.radialGradient(new Point2D.Double(0.5, 0.1), 
       new float[]{0F, 0.3F, 1F}, new Color[]{ new Color(193,193,193,1), 
       new Color(204,204,204,1), new Color(102,102,102,1)}));
       
     figure.setStroke( new Pen(new Color(32,32,32,1)));
     e.paintVisualElement(figure1, new XDimension2D.Double(width, height));

     context.getGraphics().setColor(Color.GRAY);
     context.getGraphics().fillArc((int)width/2, (int)height/2, (int)width,
       (int)height, 0, 360);
     context.getGraphics().setColor(new Color(32,32,32,1));
     context.getGraphics().drawArc((int)width/2, (int)height/2, (int)width,
         (int)height, 0, 360);
  }  
      
});

The above gauge will look similar to the following image: