com.softsynth.view
Class CustomFader

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by com.softsynth.view.CustomFader
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class CustomFader
extends java.awt.Canvas
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

Our own horizontal fader (scrollbar), subclass of canvas, which uses CustomFaderListener interface to communicate with parent. This fader is very similar to a Scrollbar except that it will jump to a value if clicked while holding down the SHIFT key.

To use this class, choose either the AWT 1.0.2 version of CustomFader package com.softsynth.view102, or the AWT 1.1 version in package com.softsynth.view111. Example of using a CustomFader:

// A new fader with parent, with default value 50, visible of 10, min value 0, max value 100
myFader = new CustomFader(CustomFader.HORIZONTAL, 50, 10, 0, 100);

// Assumes "this" is a class that implements CustomFaderListener
myFader.addCustomFaderListener( this );

// set the increment that the value will jump when user clicks inside fader
myFader.setBlockIncrement(10);

// set the increment that the value will jump when user clicks on arrows of fader
myFader.setUnitIncrement(1);

// add it to layout
add(myFader);

...


Parent must implement the CustomFaderListener interface. This requires defining public void customFaderValueChanged(CustomFader jsb) to be notified of the fader's value changing.
Example:
 public void customFaderValueChanged(Object fader, int value)
 {
        System.out.println("Value = " + value);
 }
This was written to provide a more consistent, less buggy Scrollbar substitute.

Author:
Nick Didkovsky and Phil Burk, SoftSynth.com, All Rights Reserved
See Also:
Serialized Form

Field Summary
static int HORIZONTAL
           
static int VERTICAL
           
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CustomFader(int orientation, int val, int visible, int min, int max)
          Constructor with initial value, visible, min value, max value.
 
Method Summary
 void addCustomFaderListener(CustomFaderListener listener)
          Add a listener to receive value change events.
 int getBlockIncrement()
           
 int getLineIncrement()
           
 int getValue()
           
 int getVisibleAmount(int amount)
           
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void paint(java.awt.Graphics g)
           
 void removeCustomFaderListener(CustomFaderListener listener)
           
 void setBlockIncrement(int v)
          Set how much the value jumps when click to left or high of slider.
 void setUnitIncrement(int v)
          Set how much the value jumps when click on an arrow.
 void setValue(int v)
           
 void setValues(int val, int min, int max)
          Set current value, minimum value, maximum value of fader
 void setVisibleAmount(int amount)
           
 void update(java.awt.Graphics g)
           
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HORIZONTAL

public static final int HORIZONTAL
See Also:
Constant Field Values

VERTICAL

public static final int VERTICAL
See Also:
Constant Field Values
Constructor Detail

CustomFader

public CustomFader(int orientation,
                   int val,
                   int visible,
                   int min,
                   int max)
Constructor with initial value, visible, min value, max value. LineIncrement defaults to 1, PageIncrement defaults to 10 (see setUnitIncrement() and setBlockIncrement() below)

Method Detail

addCustomFaderListener

public void addCustomFaderListener(CustomFaderListener listener)
Add a listener to receive value change events.


removeCustomFaderListener

public void removeCustomFaderListener(CustomFaderListener listener)

setValues

public void setValues(int val,
                      int min,
                      int max)
Set current value, minimum value, maximum value of fader


getValue

public int getValue()
Returns:
Scrollbar's current value

setBlockIncrement

public void setBlockIncrement(int v)
Set how much the value jumps when click to left or high of slider. Default is 10


getBlockIncrement

public int getBlockIncrement()

setUnitIncrement

public void setUnitIncrement(int v)
Set how much the value jumps when click on an arrow. Default is 1


getLineIncrement

public int getLineIncrement()

getVisibleAmount

public int getVisibleAmount(int amount)

setVisibleAmount

public void setVisibleAmount(int amount)

setValue

public void setValue(int v)

update

public void update(java.awt.Graphics g)
Overrides:
update in class java.awt.Canvas

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Canvas

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener