public class GJDial
extends javax.swing.JSlider
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.beans.PropertyChangeListener
GJDial
is a subclass of the standard swing
JSlider
.
GJDial
provides a rotating dial instead of a slider to change
the settings of the widget. By default the dial covers the range between the
minimum and maximum in a single turn - equivalent to the sweep length of the
JSlider. However, the number of turns available can be set programmatically
using the setAvailableTurns
method, e.g. with
setAvailableTurns(10)
the each rotation would cover 1/10th of
the range of the GJDial.
Dials are circular and will be drawn at the center of the GJDial's bounds with a diameter determined from the lesser of the width and the height - so it makes sense generally to specify square sizes.
The following methods are specific to GJDial or have been overridden.
getTurnCount
- returns the number of turns made
getValue
- returns the value calculated from the current dial
settings.
The following also have suitable getters.
setAvailableTurns(int)
- sets the number of turns for the
dial
setDisplayValue(true/false)
provides a text display of the value
in the center of the dial
setLineColor(Color/Paint)
- sets the line color
setFill(Color/Paint)
- sets the fill color for the dial
setMajorTickSpacing(int n)
- displays n major ticks around the
dial
setMinorTickSpacing(int n)
- displays n minor ticks around the
dial
setText(String)
provides a JLabel with the specified string in
the center of the dial
setValue(int)
- positions the dial (and internal settings as
appropriate)
Other JSlider methods, e.g. setMinimum
and
setMaximum
act as you would expect or are ignored e.g.
setExtent
so a GJDial should work as a drop-in replacement for a
JSlider.
Modifier and Type | Class and Description |
---|---|
static class |
GJDial.BasicGJDialUI |
javax.swing.JSlider.AccessibleJSlider
javax.swing.JComponent.AccessibleJComponent
changeEvent, changeListener, majorTickSpacing, minorTickSpacing, orientation, sliderModel, snapToTicks
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Constructor and Description |
---|
GJDial()
Default constructor returns a 100x100 pixel single turn GJDial with no
display of the value and no JLabel text
|
GJDial(int diameter,
int n)
Constructor returns a GjDial with no display of the value and no JLabel
text
|
GJDial(int diameter,
int n,
boolean flag)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addActionListener(java.awt.event.ActionListener listener) |
java.awt.Paint |
getFill()
Sets the fill for the dial
|
java.awt.Color |
getLineColor() |
java.lang.String |
getText()
Returns the JLabel's text
|
double |
getTheta() |
int |
getTurnCount()
Returns the number of turns made - by mouse or programmatically via
setValue |
GJDial.BasicGJDialUI |
getUI() |
java.lang.String |
getUIClassID() |
int |
getValue() |
boolean |
isDisplayValue()
Determines if values will be displayed at the center of the dial
|
void |
mouseClicked(java.awt.event.MouseEvent me) |
void |
mouseDragged(java.awt.event.MouseEvent me) |
void |
mouseEntered(java.awt.event.MouseEvent me) |
void |
mouseExited(java.awt.event.MouseEvent me) |
void |
mouseMoved(java.awt.event.MouseEvent me) |
void |
mousePressed(java.awt.event.MouseEvent me) |
void |
mouseReleased(java.awt.event.MouseEvent me) |
void |
paintComponent(java.awt.Graphics g) |
void |
propertyChange(java.beans.PropertyChangeEvent evt) |
void |
setDisplayValue(boolean flag)
Displays the current value at the center of the dial
|
void |
setFill(java.awt.Paint p)
Returns the fill for the dial
|
void |
setLineColor(java.awt.Color LineColor) |
void |
setMaximum(int val) |
void |
setMinimum(int val) |
void |
setText(java.lang.String str)
Sets the text for a JLabel displayed at the center of the dial.
|
void |
setValue(int val) |
void |
updateUI() |
addChangeListener, createChangeListener, createStandardLabels, createStandardLabels, fireStateChanged, getAccessibleContext, getChangeListeners, getExtent, getInverted, getLabelTable, getMajorTickSpacing, getMaximum, getMinimum, getMinorTickSpacing, getModel, getOrientation, getPaintLabels, getPaintTicks, getPaintTrack, getSnapToTicks, getValueIsAdjusting, imageUpdate, paramString, removeChangeListener, setExtent, setFont, setInverted, setLabelTable, setMajorTickSpacing, setMinorTickSpacing, setModel, setOrientation, setPaintLabels, setPaintTicks, setPaintTrack, setSnapToTicks, setUI, setValueIsAdjusting, updateLabelUIs
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public GJDial()
public GJDial(int diameter, int n)
diameter
- diameter of the GJDial in pixelsn
- number of available turnspublic GJDial(int diameter, int n, boolean flag)
diameter
- diameter of the GJDial in pixelsn
- number of available turnsflag
- true to display the values as textpublic void addActionListener(java.awt.event.ActionListener listener)
public void setMinimum(int val)
setMinimum
in class javax.swing.JSlider
val
- public void setMaximum(int val)
setMaximum
in class javax.swing.JSlider
val
- public int getValue()
getValue
in class javax.swing.JSlider
public void setValue(int val)
setValue
in class javax.swing.JSlider
val
- public GJDial.BasicGJDialUI getUI()
getUI
in class javax.swing.JSlider
public final void updateUI()
updateUI
in class javax.swing.JSlider
public java.lang.String getUIClassID()
getUIClassID
in class javax.swing.JSlider
public java.awt.Paint getFill()
public void setFill(java.awt.Paint p)
p
- the Paint object e.g. a Colorpublic double getTheta()
public int getTurnCount()
setValue
public void setText(java.lang.String str)
isDisplayValuetrue,/code>.
str
- public java.lang.String getText()
public void setDisplayValue(boolean flag)
flag
- public boolean isDisplayValue()
public void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
g
- public void mouseClicked(java.awt.event.MouseEvent me)
mouseClicked
in interface java.awt.event.MouseListener
public void mousePressed(java.awt.event.MouseEvent me)
mousePressed
in interface java.awt.event.MouseListener
public void mouseReleased(java.awt.event.MouseEvent me)
mouseReleased
in interface java.awt.event.MouseListener
public void mouseEntered(java.awt.event.MouseEvent me)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent me)
mouseExited
in interface java.awt.event.MouseListener
public void mouseDragged(java.awt.event.MouseEvent me)
mouseDragged
in interface java.awt.event.MouseMotionListener
public void mouseMoved(java.awt.event.MouseEvent me)
mouseMoved
in interface java.awt.event.MouseMotionListener
public java.awt.Color getLineColor()
public void setLineColor(java.awt.Color LineColor)
LineColor
- the LineColor to setpublic void propertyChange(java.beans.PropertyChangeEvent evt)
propertyChange
in interface java.beans.PropertyChangeListener