Package gov.nih.mipav.view
Class ViewJSlider
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JSlider
gov.nih.mipav.view.ViewJSlider
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,SwingConstants
This class extends Java's JSlider to give basic solutions to common slider needs in
image processing tasks. The sliders contain methods for resizing and snapping that
are not present in JSliders by default. Another functional need common to MIPAV sliders
is the ability of the slider to reference a data range that is not displayed to the user.
For example, the MIPAV gui is always zero-based, but many images begin with slice 1. This
operation is represented as a background BoundedRangeModel that is not visible to the user
of a ViewJSlider.
- Author:
- senseneyj
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumprivate classThis class watches for GUI events that require slider marks to be reset.Nested classes/interfaces inherited from class javax.swing.JSlider
JSlider.AccessibleJSliderNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprivate DimensionHolds the old dimension to minimize redrawing of slider tablestatic final Stringprivate doubleprivate doubleThe closest number of pixels that major/minor ticks may be next to each other.static final Stringstatic final Stringstatic final Stringprivate ViewJSlider.SliderTypeRefers to the type of slider being used by MIPAVFields inherited from class javax.swing.JSlider
changeEvent, changeListener, majorTickSpacing, minorTickSpacing, orientation, sliderModel, snapToTicksFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDefault constructorViewJSlider(String type) Creates a horizontal slider with the range and initial value specified by type.ViewJSlider(String type, int maxBound) Creates a horizontal slider with the range and initial value specified by type, but the orientation is explicitly specified.ViewJSlider(String type, int min, int max) Creates a horizontal slider with the range and initial value specified by type, but the min and max are explicitly to create a Boundary Range model.ViewJSlider(String type, int min, int max, int value) Creates a horizontal slider with the range and initial value specified by type, but the min and max are explicitly to create a Boundary Range model.ViewJSlider(String type, int orientation, int min, int max, int value) Creates a horizontal slider with the range and initial value specified by type, but the min and max are explicitly to create a Boundary Range model.ViewJSlider(String type, BoundedRangeModel brm) Creates a horizontal slider with the range and initial value specified by type, but the range model is explicitly specified. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidSets values for minimum allowable tick spacing depending on size of GUI.buildSliderLabels(int intvlMajor) Builds the slider labels for the slider.protected static JLabelcreateLabel(String title) Helper method to create a label with the proper font and font color.private intgetBestTickSpacing(int rangeNeeded, double maxNumTicks) Gets the best tick spacing by finding the value that divides into rangeNeeded with the greatest number that is still less than the maximum number of ticks that are allowed in the rangedoubledoubleintgetValue()private voidInit method that creates slidervoidResize slider The max number of major ticks and max number of minor ticks are determined using width/height of dialog.voidSets defaultsvoidsetMinAllowableMajorTickSpacing(double minAllowableMajorTickSpacing) voidsetMinAllowableMinorTickSpacing(double minAllowableMinorTickSpacing) voidsetValue(int n) Methods inherited from class javax.swing.JSlider
addChangeListener, createChangeListener, createStandardLabels, createStandardLabels, fireStateChanged, getAccessibleContext, getChangeListeners, getExtent, getInverted, getLabelTable, getMajorTickSpacing, getMaximum, getMinimum, getMinorTickSpacing, getModel, getOrientation, getPaintLabels, getPaintTicks, getPaintTrack, getSnapToTicks, getUI, getUIClassID, getValueIsAdjusting, imageUpdate, paramString, removeChangeListener, setExtent, setFont, setInverted, setLabelTable, setMajorTickSpacing, setMaximum, setMinimum, setMinorTickSpacing, setModel, setOrientation, setPaintLabels, setPaintTicks, setPaintTrack, setSnapToTicks, setUI, setValueIsAdjusting, updateLabelUIs, updateUIMethods inherited from class javax.swing.JComponent
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, paintComponent, 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, updateMethods inherited from class java.awt.Container
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, validateTreeMethods inherited from class java.awt.Component
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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
TIME
- See Also:
-
SLICE
- See Also:
-
CONTRAST
- See Also:
-
CUSTOM
- See Also:
-
OPACITY
- See Also:
-
MAGNIFICATION
- See Also:
-
type
Refers to the type of slider being used by MIPAV -
dim
Holds the old dimension to minimize redrawing of slider table -
minAllowableMinorTickSpacing
private double minAllowableMinorTickSpacingThe closest number of pixels that major/minor ticks may be next to each other. Used to set GUI and create labels. -
minAllowableMajorTickSpacing
private double minAllowableMajorTickSpacing
-
-
Constructor Details
-
ViewJSlider
private ViewJSlider()Default constructor -
ViewJSlider
Creates a horizontal slider with the range and initial value specified by type.- Parameters:
type- See ViewJSlider.SliderTypes for possible pre-built types
-
ViewJSlider
Creates a horizontal slider with the range and initial value specified by type, but the orientation is explicitly specified.- Parameters:
type- See ViewJSlider.SliderTypes for possible pre-built typesorientation- @see JSlider
-
ViewJSlider
Creates a horizontal slider with the range and initial value specified by type, but the range model is explicitly specified.- Parameters:
type- See ViewJSlider.SliderTypes for possible pre-built typesbrm- @see JSlider
-
ViewJSlider
Creates a horizontal slider with the range and initial value specified by type, but the min and max are explicitly to create a Boundary Range model.- Parameters:
type- See ViewJSlider.SliderTypes for possible pre-built typesmin- @see JSlidermax- @see JSlider
-
ViewJSlider
Creates a horizontal slider with the range and initial value specified by type, but the min and max are explicitly to create a Boundary Range model. The initial value is also specified.- Parameters:
type- See ViewJSlider.SliderTypes for possible pre-built typesmin- @see JSlidermax- @see JSlidervalue- @see JSlider
-
ViewJSlider
Creates a horizontal slider with the range and initial value specified by type, but the min and max are explicitly to create a Boundary Range model. The initial value and orientation are also specified.- Parameters:
type- See ViewJSlider.SliderTypes for possible pre-built typesorientation- @see JSlidermin- @see JSlidermax- @see JSlidervalue- @see JSlider
-
-
Method Details
-
getValue
public int getValue() -
setValue
public void setValue(int n) -
buildSliderLabels
Builds the slider labels for the slider.- Parameters:
min- Min value of slidermax- Max value of slider.- Returns:
- Slider labels hash.
-
createLabel
Helper method to create a label with the proper font and font color.- Parameters:
title- Text of the label.- Returns:
- New label.
-
init
Init method that creates slider- Parameters:
typeStr- The type of slider to construct
-
setDefaults
public void setDefaults()Sets defaults -
buildMinimumTickSpacing
private void buildMinimumTickSpacing()Sets values for minimum allowable tick spacing depending on size of GUI. -
resizeSlider
public void resizeSlider()Resize slider The max number of major ticks and max number of minor ticks are determined using width/height of dialog. The major tick spacing and minor tick spacing are determined as follows: If the range of slices is less than max major ticks, then display ticks every 1 spacing If it is greater than max major ticks, then determine if the range is a prime number If it is not a prime number, determine the maj tick spacing using the getBestTickSpacing method. If there is room for all minor ticks, then set minor tick spacing to 1. If there is not room, first determine if the maj tick spacing is a prime number. If it is a prime number, set the minor tick spacing to major tick spacing If it is not a prime number, determine the minor tick spacing using the getBestTickSpacing method. If it is a prime number, set the maj tick spacing to 0 Determine the minor tick spacing using the getBestTickSpacing method -
getBestTickSpacing
private int getBestTickSpacing(int rangeNeeded, double maxNumTicks) Gets the best tick spacing by finding the value that divides into rangeNeeded with the greatest number that is still less than the maximum number of ticks that are allowed in the range- Parameters:
rangeNeeded- the range covered by tick marksmaxNumTicks- the number of tick marks that can exist in the range- Returns:
- Best tick spacing value
-
getMinAllowableMinorTickSpacing
public double getMinAllowableMinorTickSpacing() -
setMinAllowableMinorTickSpacing
public void setMinAllowableMinorTickSpacing(double minAllowableMinorTickSpacing) -
getMinAllowableMajorTickSpacing
public double getMinAllowableMajorTickSpacing() -
setMinAllowableMajorTickSpacing
public void setMinAllowableMajorTickSpacing(double minAllowableMajorTickSpacing)
-