ch.sahits.game.graphic.layout
Class Slider

java.lang.Object
  extended by ch.sahits.game.graphic.layout.AbstractSahitsComponent
      extended by ch.sahits.game.graphic.layout.AbstractMultiselectableComponent<String>
          extended by ch.sahits.game.graphic.layout.Slider
All Implemented Interfaces:
ISahitsComponent, IUpdatableComponent

public class Slider
extends AbstractMultiselectableComponent<String>
implements IUpdatableComponent

A slider component. The slider has either all labels painted or just the active

Author:
Andi Hotz, (c) Sahits GmbH, 2011 Created on Jun 12, 2011

Field Summary
private  IIndexChangeListener changeListener
           
private  Polygon handle
           
private  FontMetrics metric
           
private  boolean paintLabels
           
 
Fields inherited from class ch.sahits.game.graphic.layout.AbstractMultiselectableComponent
selectables
 
Fields inherited from class ch.sahits.game.graphic.layout.AbstractSahitsComponent
painter
 
Constructor Summary
Slider(FontMetrics fm)
           
 
Method Summary
 void addChangeListeners(IIndexChangeListener listener)
           
private  int angleToIndex(double angle)
          Compute the closest index from an angle
private  float castIntoRange(int index)
          compute the angle for an index
private  float castValue()
          Cast the selected index into a percentage
private  float castValue(double val)
          Cast the value into a persentage
 Dimension getPreferredSize()
          Retrieve the preferred size of the component.
 void paint(Graphics g)
          Draw the component with the appropriate graphic context.
private  void paintCurrentLabel(Graphics g, int value)
          Paint the label of the closest labeled value over the handle.
private  void paintHorizontalLabel(Graphics g, int value)
          Paint the label over the center of the tracker handle (commonly known as thumb)
private  void paintLabelAt(Graphics g, Label label, Rectangle rect)
          Paint a label a specific position
private  boolean paintLabels()
          Check if the labels are to be painted
private  void paintLabels(Graphics g)
          Print all the labels
 void setBounds(int x, int y, int width, int height)
          Define the measurements of the component
 void setPaintLabels(boolean paintLabels)
          Set the flag to paint the label
 void setSelected(int index)
          set the selected index to specified value.
 void testClick(MouseEvent e)
           
 void testClick(Point p)
          Test if there was a mouse click on the component
private  double valueForXPosition(int x)
           
 
Methods inherited from class ch.sahits.game.graphic.layout.AbstractMultiselectableComponent
add, decSelection, gameRender, gameUpdate, getFont, getItem, getItemCount, getSelected, getSelectedIndex, incSelection, setFont, testKeyPress
 
Methods inherited from class ch.sahits.game.graphic.layout.AbstractSahitsComponent
createVisualBounds, getBounds, getInsets, setInsets
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ch.sahits.game.graphic.display.IUpdatableComponent
gameRender, gameUpdate, testKeyPress
 

Field Detail

metric

private final FontMetrics metric

paintLabels

private boolean paintLabels

handle

private Polygon handle

changeListener

private IIndexChangeListener changeListener
Constructor Detail

Slider

public Slider(FontMetrics fm)
Method Detail

testClick

public void testClick(MouseEvent e)

testClick

public void testClick(Point p)
Description copied from interface: IUpdatableComponent
Test if there was a mouse click on the component

Specified by:
testClick in interface IUpdatableComponent

valueForXPosition

private double valueForXPosition(int x)

castValue

private float castValue()
Cast the selected index into a percentage

Returns:

castValue

private float castValue(double val)
Cast the value into a persentage

Parameters:
val -
Returns:

castIntoRange

private float castIntoRange(int index)
compute the angle for an index

Parameters:
index -
Returns:

angleToIndex

private int angleToIndex(double angle)
Compute the closest index from an angle

Parameters:
angle -
Returns:

paint

public void paint(Graphics g)
Description copied from interface: ISahitsComponent
Draw the component with the appropriate graphic context. Before calling this method make sure it is appropriately initialized.

Specified by:
paint in interface ISahitsComponent

getPreferredSize

public Dimension getPreferredSize()
Description copied from interface: ISahitsComponent
Retrieve the preferred size of the component.

Specified by:
getPreferredSize in interface ISahitsComponent
Returns:

paintLabels

private boolean paintLabels()
Check if the labels are to be painted

Returns:

setPaintLabels

public void setPaintLabels(boolean paintLabels)
Set the flag to paint the label

Parameters:
paintLabels -

paintCurrentLabel

private void paintCurrentLabel(Graphics g,
                               int value)
Paint the label of the closest labeled value over the handle. This makes only sense if the all potential labels are named (evenly spaced)

Parameters:
g -
value -

paintLabelAt

private void paintLabelAt(Graphics g,
                          Label label,
                          Rectangle rect)
Paint a label a specific position

Parameters:
g -
label -
rect -

paintHorizontalLabel

private void paintHorizontalLabel(Graphics g,
                                  int value)
Paint the label over the center of the tracker handle (commonly known as thumb)


paintLabels

private void paintLabels(Graphics g)
Print all the labels

Parameters:
g -

setSelected

public void setSelected(int index)
set the selected index to specified value. If the index is outside of range nothing will happen

Overrides:
setSelected in class AbstractMultiselectableComponent<String>

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Description copied from interface: ISahitsComponent
Define the measurements of the component

Specified by:
setBounds in interface ISahitsComponent
Overrides:
setBounds in class AbstractSahitsComponent
Parameters:
x - position along the x axis
y - position along the y axis
width - of the component
height - of the component

addChangeListeners

public void addChangeListeners(IIndexChangeListener listener)


Copyright © 2011 Sahits GmbH. All Rights Reserved.