Class GJDial
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JSlider
-
- kcl.waterloo.widget.GJDial
-
- All Implemented Interfaces:
- java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.SwingConstants
- Direct Known Subclasses:
- GJGauge
public class GJDial extends javax.swing.JSlider implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.beans.PropertyChangeListenerGJDialis a subclass of the standard swingJSlider.GJDialprovides 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 thesetAvailableTurnsmethod, e.g. withsetAvailableTurns(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 madegetValue- returns the value calculated from the current dial settings.The following also have suitable getters.
setAvailableTurns(int)- sets the number of turns for the dialsetDisplayValue(true/false)provides a text display of the value in the center of the dialsetLineColor(Color/Paint)- sets the line colorsetFill(Color/Paint)- sets the fill color for the dialsetMajorTickSpacing(int n)- displays n major ticks around the dialsetMinorTickSpacing(int n)- displays n minor ticks around the dialsetText(String)provides a JLabel with the specified string in the center of the dialsetValue(int)- positions the dial (and internal settings as appropriate)Other JSlider methods, e.g.
setMinimumandsetMaximumact as you would expect or are ignored e.g.setExtentso a GJDial should work as a drop-in replacement for a JSlider.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classGJDial.BasicGJDialUI
-
Field Summary
-
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
Constructors Constructor and Description GJDial()Default constructor returns a 100x100 pixel single turn GJDial with no display of the value and no JLabel textGJDial(int diameter, int n)Constructor returns a GjDial with no display of the value and no JLabel textGJDial(int diameter, int n, boolean flag)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddActionListener(java.awt.event.ActionListener listener)java.awt.PaintgetFill()Sets the fill for the dialjava.awt.ColorgetLineColor()java.lang.StringgetText()Returns the JLabel's textdoublegetTheta()intgetTurnCount()Returns the number of turns made - by mouse or programmatically viasetValueGJDial.BasicGJDialUIgetUI()java.lang.StringgetUIClassID()intgetValue()booleanisDisplayValue()Determines if values will be displayed at the center of the dialvoidmouseClicked(java.awt.event.MouseEvent me)voidmouseDragged(java.awt.event.MouseEvent me)voidmouseEntered(java.awt.event.MouseEvent me)voidmouseExited(java.awt.event.MouseEvent me)voidmouseMoved(java.awt.event.MouseEvent me)voidmousePressed(java.awt.event.MouseEvent me)voidmouseReleased(java.awt.event.MouseEvent me)voidpaintComponent(java.awt.Graphics g)voidpropertyChange(java.beans.PropertyChangeEvent evt)voidsetDisplayValue(boolean flag)Displays the current value at the center of the dialvoidsetFill(java.awt.Paint p)Returns the fill for the dialvoidsetLineColor(java.awt.Color LineColor)voidsetMaximum(int val)voidsetMinimum(int val)voidsetText(java.lang.String str)Sets the text for a JLabel displayed at the center of the dial.voidsetValue(int val)voidupdateUI()-
Methods inherited from class javax.swing.JSlider
addChangeListener, createStandardLabels, createStandardLabels, getAccessibleContext, getChangeListeners, getExtent, getInverted, getLabelTable, getMajorTickSpacing, getMaximum, getMinimum, getMinorTickSpacing, getModel, getOrientation, getPaintLabels, getPaintTicks, getPaintTrack, getSnapToTicks, getValueIsAdjusting, imageUpdate, removeChangeListener, setExtent, setFont, setInverted, setLabelTable, setMajorTickSpacing, setMinorTickSpacing, setModel, setOrientation, setPaintLabels, setPaintTicks, setPaintTrack, setSnapToTicks, setUI, setValueIsAdjusting
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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
-
-
-
-
Constructor Detail
-
GJDial
public GJDial()
Default constructor returns a 100x100 pixel single turn GJDial with no display of the value and no JLabel text
-
GJDial
public GJDial(int diameter, int n)Constructor returns a GjDial with no display of the value and no JLabel text- Parameters:
diameter- diameter of the GJDial in pixelsn- number of available turns
-
GJDial
public GJDial(int diameter, int n, boolean flag)Constructor- Parameters:
diameter- diameter of the GJDial in pixelsn- number of available turnsflag- true to display the values as text
-
-
Method Detail
-
addActionListener
public void addActionListener(java.awt.event.ActionListener listener)
-
setMinimum
public void setMinimum(int val)
- Overrides:
setMinimumin classjavax.swing.JSlider- Parameters:
val-
-
setMaximum
public void setMaximum(int val)
- Overrides:
setMaximumin classjavax.swing.JSlider- Parameters:
val-
-
getValue
public int getValue()
- Overrides:
getValuein classjavax.swing.JSlider- Returns:
- the current value of the dial.
-
setValue
public void setValue(int val)
- Overrides:
setValuein classjavax.swing.JSlider- Parameters:
val-
-
getUI
public GJDial.BasicGJDialUI getUI()
- Overrides:
getUIin classjavax.swing.JSlider- Returns:
-
updateUI
public final void updateUI()
- Overrides:
updateUIin classjavax.swing.JSlider
-
getUIClassID
public java.lang.String getUIClassID()
- Overrides:
getUIClassIDin classjavax.swing.JSlider- Returns:
-
getFill
public java.awt.Paint getFill()
Sets the fill for the dial- Returns:
- the Paint object
-
setFill
public void setFill(java.awt.Paint p)
Returns the fill for the dial- Parameters:
p- the Paint object e.g. a Color
-
getTheta
public double getTheta()
-
getTurnCount
public int getTurnCount()
Returns the number of turns made - by mouse or programmatically viasetValue- Returns:
-
setText
public void setText(java.lang.String str)
Sets the text for a JLabel displayed at the center of the dial. Note that this will overlap displayed values ifisDisplayValuetrue,/code>.- Parameters:
str-
-
getText
public java.lang.String getText()
Returns the JLabel's text- Returns:
-
setDisplayValue
public void setDisplayValue(boolean flag)
Displays the current value at the center of the dial- Parameters:
flag-
-
isDisplayValue
public boolean isDisplayValue()
Determines if values will be displayed at the center of the dial- Returns:
-
paintComponent
public void paintComponent(java.awt.Graphics g)
- Overrides:
paintComponentin classjavax.swing.JComponent- Parameters:
g-
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent me)
- Specified by:
mouseClickedin interfacejava.awt.event.MouseListener
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent me)
- Specified by:
mousePressedin interfacejava.awt.event.MouseListener
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent me)
- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent me)
- Specified by:
mouseEnteredin interfacejava.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent me)
- Specified by:
mouseExitedin interfacejava.awt.event.MouseListener
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent me)
- Specified by:
mouseDraggedin interfacejava.awt.event.MouseMotionListener
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent me)
- Specified by:
mouseMovedin interfacejava.awt.event.MouseMotionListener
-
getLineColor
public java.awt.Color getLineColor()
- Returns:
- the LineColor
-
setLineColor
public void setLineColor(java.awt.Color LineColor)
- Parameters:
LineColor- the LineColor to set
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
-
-
DMelt 3.0 © DataMelt by jWork.ORG