com.groovemanager.gui.custom
Class ScaleNum

java.lang.Object
  extended by com.groovemanager.gui.custom.CustomComposite
      extended by com.groovemanager.gui.custom.ScaleNum

public class ScaleNum
extends CustomComposite

This CustomComposite consists of a number displayed on a button. The value of the number can be changed by selecting and moving with the mouse, by double-clicking and entering it manually or by selecting the Composite and using the Up/Down-Arrows or the PageUp/PageDown-Keys. The idea was to create an alternative to Scale for integer user input

Author:
Manu Robledo

Field Summary
private  org.eclipse.swt.widgets.Button button
          The button showing the current value
private  int dcTime
          The double click time
private  int def
          Minimum value
private  boolean editing
          true if the Text field for user input is currently shown, false otherwise
private  int lastChange
          Temporary variables
private  int lastClick
          Temporary variables
private  int lastMove
          Temporary variables
private  int lastX
          Temporary variables
private  org.eclipse.swt.custom.StackLayout layout
          The layout used to show either the button or the text field
private  int max
          Minimum value
private  int min
          Minimum value
private static int MOUSE_OFFSET
          Number of pixels the mouse has to be moved up or down to change the value
private  boolean mousedown
          Indicates, if the mouse button is currently pressed or not
private  boolean readonly
          Indicates whether this Composite has been created with READ_ONLY style or not
private  int selection
          Minimum value
private  double speed
          A value for the speed of the mouse movement
private  org.eclipse.swt.widgets.Text userInput
          Text field for user-input of the value; shown when double-clicking
 
Constructor Summary
ScaleNum(org.eclipse.swt.widgets.Composite parent, int style)
          Construct a new ScaleNum
 
Method Summary
 void addSelectionListener(org.eclipse.swt.events.SelectionListener listener)
          Add a SelectionListener that will be notified of value changes
private  void checkMinMax()
          Internal methodd for keeping the values for minimum, maximum, default and the current value in a consistent state
protected  org.eclipse.swt.widgets.Composite createComposite(org.eclipse.swt.widgets.Composite parent, int style)
          This method is to be overwritten by concrete subclasses to create the real contents of this CustomComposite
private  void finishEditing()
          Hide the text field
 int getDefault()
          Get the default value
protected  int[] getListenerTypes()
          For all types of listeners that should be possible to add to this Composite directly, the corresponding SWT.* constant should be contained in the returned Array.
 int getMaximum()
          Get the maximum value
 int getMinimum()
          Get the minimum value
protected  int getPossibleStyles()
          Get a combination of all allowed SWT.* style constants
 int getSelection()
          Get the current value
protected  void notifyListeners(int time)
          Notify the registered SelectionListeners of a value change
 void setAll(int defaultSelected, int minimum, int maximum)
          Set the minimum, maximum and default value.
 void setDefault(int d)
          Set the default value
 void setDefaultAndSelection(int i)
          Set the default value and the current value to the specified value
 void setMaximum(int m)
          Set the maximum value
 void setMinimum(int m)
          Set the minimum value
 void setSelection(int s)
          Set the current value
protected  void setSelection(int s, boolean updateText)
          Internal method for value change
private  void startEditing()
          Show the text field for user input
private  void startMouseDrag()
          Indicates that a mouse dragging has been started for changing the value
private  void stopMouseDrag()
          Indicates that mouse dragging has been stopped
 
Methods inherited from class com.groovemanager.gui.custom.CustomComposite
addListener, checkStyle, getComposite, getData, getListeners, getParent, removeListener, setData, setLayoutData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

button

private org.eclipse.swt.widgets.Button button
The button showing the current value


dcTime

private final int dcTime
The double click time


def

private int def
Minimum value


editing

private boolean editing
true if the Text field for user input is currently shown, false otherwise


lastChange

private int lastChange
Temporary variables


lastClick

private int lastClick
Temporary variables


lastMove

private int lastMove
Temporary variables


lastX

private int lastX
Temporary variables


layout

private org.eclipse.swt.custom.StackLayout layout
The layout used to show either the button or the text field


max

private int max
Minimum value


min

private int min
Minimum value


MOUSE_OFFSET

private static final int MOUSE_OFFSET
Number of pixels the mouse has to be moved up or down to change the value

See Also:
Constant Field Values

mousedown

private boolean mousedown
Indicates, if the mouse button is currently pressed or not


readonly

private boolean readonly
Indicates whether this Composite has been created with READ_ONLY style or not


selection

private int selection
Minimum value


speed

private double speed
A value for the speed of the mouse movement


userInput

private org.eclipse.swt.widgets.Text userInput
Text field for user-input of the value; shown when double-clicking

Constructor Detail

ScaleNum

public ScaleNum(org.eclipse.swt.widgets.Composite parent,
                int style)
Construct a new ScaleNum

Parameters:
parent - The parent Composite
style - Combination of SWT.* style constants. Allowed values are:
SWT.FLAT: For flat appearance
SWT.READ_ONLY: For the user not being able to change the value
SWT.BORDER: For surrounding this Composite with a border
SWT.LEFT, SWT.CENTER or SWT.RIGHT: For specification of this Composite´s alignment
Method Detail

addSelectionListener

public void addSelectionListener(org.eclipse.swt.events.SelectionListener listener)
Add a SelectionListener that will be notified of value changes

Parameters:
listener - The SelectionListener to add

checkMinMax

private void checkMinMax()
Internal methodd for keeping the values for minimum, maximum, default and the current value in a consistent state


createComposite

protected org.eclipse.swt.widgets.Composite createComposite(org.eclipse.swt.widgets.Composite parent,
                                                            int style)
Description copied from class: CustomComposite
This method is to be overwritten by concrete subclasses to create the real contents of this CustomComposite

Specified by:
createComposite in class CustomComposite
Parameters:
parent - The parent Composite under which this Composite should be created
style - Combination of valid SWT.* style constants
Returns:
The new created main composite

finishEditing

private void finishEditing()
Hide the text field


getDefault

public int getDefault()
Get the default value

Returns:
The default value

getListenerTypes

protected int[] getListenerTypes()
Description copied from class: CustomComposite
For all types of listeners that should be possible to add to this Composite directly, the corresponding SWT.* constant should be contained in the returned Array.

Specified by:
getListenerTypes in class CustomComposite
Returns:
An Array of SWT.* constants defining the set of listeners types applicable to this Composite

getMaximum

public int getMaximum()
Get the maximum value

Returns:
The maximum value

getMinimum

public int getMinimum()
Get the minimum value

Returns:
The minimum value

getPossibleStyles

protected int getPossibleStyles()
Description copied from class: CustomComposite
Get a combination of all allowed SWT.* style constants

Specified by:
getPossibleStyles in class CustomComposite
Returns:
A combination of all allowed style constants, for example SWT.BORDER | SWT.LEFT | SWT.BORDER

getSelection

public int getSelection()
Get the current value

Returns:
The current value

notifyListeners

protected void notifyListeners(int time)
Notify the registered SelectionListeners of a value change

Parameters:
time - The time at which this event was generated

setAll

public void setAll(int defaultSelected,
                   int minimum,
                   int maximum)
Set the minimum, maximum and default value. The vcurrent value will be set to the default value.

Parameters:
defaultSelected - The default value
minimum - The minimum value
maximum - The maximum value

setDefault

public void setDefault(int d)
Set the default value

Parameters:
d - The default value

setDefaultAndSelection

public void setDefaultAndSelection(int i)
Set the default value and the current value to the specified value

Parameters:
i - The new value

setMaximum

public void setMaximum(int m)
Set the maximum value

Parameters:
m - The maximum value

setMinimum

public void setMinimum(int m)
Set the minimum value

Parameters:
m - The minimum value

setSelection

public void setSelection(int s)
Set the current value

Parameters:
s - The current value

setSelection

protected void setSelection(int s,
                            boolean updateText)
Internal method for value change

Parameters:
s - The new value
updateText - true, if the content of the Text field should also be updated, false otherwise. This parameter is for avoiding endless loops of change notifications going on between this ScaleNum and its text field.

startEditing

private void startEditing()
Show the text field for user input


startMouseDrag

private void startMouseDrag()
Indicates that a mouse dragging has been started for changing the value


stopMouseDrag

private void stopMouseDrag()
Indicates that mouse dragging has been stopped