uk.co.ist.mwt
Class Scale

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--uk.co.ist.mwt.ShadowedComponent
                          |
                          +--uk.co.ist.mwt.Scale

public class Scale
extends ShadowedComponent

A Scale mimics the Scale capabilities of a Motif XmScale; it does not implement the layout part. If you want a Scale with children a la Motif, use a ScalePanel.

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
static int kUndefined
          A constant to say that a resource setting is undefined.
 
Fields inherited from class uk.co.ist.mwt.ShadowedComponent
shadowDrawer
 
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
 
Constructor Summary
Scale()
          Creates a scale with a normal shadow thickness
 
Method Summary
protected  void calculateClickableRects()
          Calculate the rectangles /aboveRect/ and /belowRect/ which, if clicked, cause a 'page up' or 'page down' action in the scale
protected  void calculateRectangles()
          Calculate the various rectangles which define the sections of this scale
protected  void drawThumbRect(java.awt.Graphics g)
          Draw the thumb rectangle, assuming the value is valid
protected  void drawValueDisplay(java.awt.Graphics g)
          Draw the value display, if necessary, assuming the rectangle set up for it is OK
 int getDecimalPoints()
          Gets the number of digits to the right of the decimal point if we've decided to show the value
 int getMaximum()
          Gets the maximum value for the scale
 int getMinimum()
          Gets the minimum value for the scale
 java.awt.Dimension getMinimumSize()
          Finds out the smallest possible size for the scale
 int getMultiple()
          What is the multiple's value? (The multiple is the amount (in terms of the maximum and minimum values) that the scale will move its thumb when a non-thumb place in the scale is clicked.) Because the multiple, if it has never been set, is dynamically calculated, all access to it should be through this method - even from inside this class.
protected  java.awt.Rectangle getNewSliderRect()
          Calculates the rectangle for the 'trough'
protected  java.awt.Rectangle getNewThumbRect()
          Calculate the rectangle for the thumb, assuming the sliderRect is correct
protected  java.awt.Rectangle getNewValueRect()
          Calculate the rectangle for the value display, assuming the sliderRect and the thumbRect are correct
 java.awt.Dimension getPreferredSize()
          Finds out the size the scale would like to be
 boolean getShowValue()
          Tells you whether this scale is showing its value
 int getValue()
          Gets the value of the scale
protected  java.awt.Dimension getValueSize(boolean realVal)
          Finds out how much space we need to alot to the value
 boolean getVertical()
          Accessor for the current orientation
 boolean isMaxTopRight()
          Returns whether the top/right part of the scale is where its maximum value is
 void onMouseDown(int x, int y)
          Event handler to start tracking mouse movements on mousedown; decides whether the button press is the start of a drag, or part of a paging action (ie.
 void onMouseDragged(int x, int y)
          Handles drags by updating the current value
 void onMouseUp(int x, int y)
          Event handler to work out what to do when the user releases the mouse button; if we were dragging, then set the value to the appropriate value.
 void paintComponent(java.awt.Graphics g)
          Draws the scale
protected  void processMouseEvent(java.awt.event.MouseEvent e)
          Event handler delegating mouse events to other handlers...
protected  void processMouseMotionEvent(java.awt.event.MouseEvent e)
          Event handler delegating mouse events to other handlers...
protected  void resetValue(int pos)
          Updates the value, using a particular pixel position in the trough (a y value if vertical, an x value if horizontal)
 void setBounds(int x, int y, int width, int height)
          Changes the size/position of the scale
 void setDecimalPoints(int dp)
          Sets the number of digits to the right of the decimal point if we've decided to show the value
 void setMaximum(int max)
          Sets the maximum value for the scale
 void setMaxTopRight(boolean mtr)
          Sets the scale up so that the minimum value is on the right/at the bottom (as appropriate for the orientation).
 void setMinimum(int min)
          Sets the minimum value for the scale
 void setMultiple(int mult)
          Sets the multiple's value.
 void setShowValue(boolean whether)
          Tell the scale to display its current value
 void setValue(int val)
          Sets the current value of the scale, rounded up or down to the minimum or maximum if appropriate
 void setVertical(boolean vert)
          Sets the current orientation to vertical (or horizontal, of course)
protected  void sliderMovedRedraw()
          Do a repaint, assuming that the slider has moved
protected  java.lang.String valueStr()
          Method to get the string representation of the value of the scale
 
Methods inherited from class uk.co.ist.mwt.ShadowedComponent
draw3DRect, draw3DRect, draw3DRect, draw3DRect, drawShadow, drawShadow, getBottomShadowColor, getShadowThickness, getTopShadowColor, setBottomShadowColor, setShadowThickness, setTopShadowColor
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, processComponentKeyEvent, processFocusEvent, processKeyEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setCursor, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

kUndefined

public static final int kUndefined
A constant to say that a resource setting is undefined.
Constructor Detail

Scale

public Scale()
Creates a scale with a normal shadow thickness
Method Detail

setVertical

public void setVertical(boolean vert)
Sets the current orientation to vertical (or horizontal, of course)
See Also:
getVertical()

getVertical

public boolean getVertical()
Accessor for the current orientation
Returns:
true if this scale is vertical, false otherwise
See Also:
setVertical(boolean)

setShowValue

public void setShowValue(boolean whether)
Tell the scale to display its current value
See Also:
setDecimalPoints(int), getShowValue()

getShowValue

public boolean getShowValue()
Tells you whether this scale is showing its value
Returns:
true if it is, false otherwise
See Also:
setShowValue(boolean)

setDecimalPoints

public void setDecimalPoints(int dp)
Sets the number of digits to the right of the decimal point if we've decided to show the value
See Also:
setShowValue(boolean)

getDecimalPoints

public int getDecimalPoints()
Gets the number of digits to the right of the decimal point if we've decided to show the value
See Also:
setDecimalPoints(int)

setValue

public void setValue(int val)
Sets the current value of the scale, rounded up or down to the minimum or maximum if appropriate
See Also:
getValue()

getValue

public int getValue()
Gets the value of the scale
See Also:
setValue(int)

setMaxTopRight

public void setMaxTopRight(boolean mtr)
Sets the scale up so that the minimum value is on the right/at the bottom (as appropriate for the orientation).

isMaxTopRight

public boolean isMaxTopRight()
Returns whether the top/right part of the scale is where its maximum value is
Returns:
true if the maximum is in the top or right, false otherwise

setMaximum

public void setMaximum(int max)
Sets the maximum value for the scale

getMaximum

public int getMaximum()
Gets the maximum value for the scale

setMinimum

public void setMinimum(int min)
Sets the minimum value for the scale

getMinimum

public int getMinimum()
Gets the minimum value for the scale

setMultiple

public void setMultiple(int mult)
Sets the multiple's value. (The multiple is the amount (in terms of the maximum and minimum values) that the scale will move its thumb when a non-thumb place in the scale is clicked.)

getMultiple

public int getMultiple()
What is the multiple's value? (The multiple is the amount (in terms of the maximum and minimum values) that the scale will move its thumb when a non-thumb place in the scale is clicked.) Because the multiple, if it has never been set, is dynamically calculated, all access to it should be through this method - even from inside this class.

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Changes the size/position of the scale
Overrides:
setBounds in class java.awt.Component

paintComponent

public void paintComponent(java.awt.Graphics g)
Draws the scale
Overrides:
paintComponent in class javax.swing.JComponent

getPreferredSize

public java.awt.Dimension getPreferredSize()
Finds out the size the scale would like to be
Overrides:
getPreferredSize in class javax.swing.JComponent

getMinimumSize

public java.awt.Dimension getMinimumSize()
Finds out the smallest possible size for the scale
Overrides:
getMinimumSize in class javax.swing.JComponent

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent e)
Event handler delegating mouse events to other handlers...
Overrides:
processMouseEvent in class java.awt.Component
See Also:
onMouseDown(int, int), onMouseUp(int, int)

processMouseMotionEvent

protected void processMouseMotionEvent(java.awt.event.MouseEvent e)
Event handler delegating mouse events to other handlers...
Overrides:
processMouseMotionEvent in class javax.swing.JComponent
See Also:
onMouseDragged(int, int)

onMouseDown

public void onMouseDown(int x,
                        int y)
Event handler to start tracking mouse movements on mousedown; decides whether the button press is the start of a drag, or part of a paging action (ie. the user has clicked in the trough)

onMouseUp

public void onMouseUp(int x,
                      int y)
Event handler to work out what to do when the user releases the mouse button; if we were dragging, then set the value to the appropriate value. If this was just a click, see if we should be moving the scale by a page increment. Otherwise ignore the event.

onMouseDragged

public void onMouseDragged(int x,
                           int y)
Handles drags by updating the current value

resetValue

protected void resetValue(int pos)
Updates the value, using a particular pixel position in the trough (a y value if vertical, an x value if horizontal)

getValueSize

protected java.awt.Dimension getValueSize(boolean realVal)
Finds out how much space we need to alot to the value

calculateRectangles

protected void calculateRectangles()
Calculate the various rectangles which define the sections of this scale

getNewSliderRect

protected java.awt.Rectangle getNewSliderRect()
Calculates the rectangle for the 'trough'

getNewThumbRect

protected java.awt.Rectangle getNewThumbRect()
Calculate the rectangle for the thumb, assuming the sliderRect is correct

getNewValueRect

protected java.awt.Rectangle getNewValueRect()
Calculate the rectangle for the value display, assuming the sliderRect and the thumbRect are correct

calculateClickableRects

protected void calculateClickableRects()
Calculate the rectangles /aboveRect/ and /belowRect/ which, if clicked, cause a 'page up' or 'page down' action in the scale

drawThumbRect

protected void drawThumbRect(java.awt.Graphics g)
Draw the thumb rectangle, assuming the value is valid

drawValueDisplay

protected void drawValueDisplay(java.awt.Graphics g)
Draw the value display, if necessary, assuming the rectangle set up for it is OK

sliderMovedRedraw

protected void sliderMovedRedraw()
Do a repaint, assuming that the slider has moved

valueStr

protected java.lang.String valueStr()
Method to get the string representation of the value of the scale