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:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,javax.accessibility.Accessible
,javax.swing.SwingConstants
public class ViewJSlider extends javax.swing.JSlider
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ViewJSlider.SliderType
private class
ViewJSlider.ViewJSliderResizeTool
This class watches for GUI events that require slider marks to be reset.-
Nested classes/interfaces inherited from class javax.swing.JSlider
javax.swing.JSlider.AccessibleJSlider
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONTRAST
static java.lang.String
CUSTOM
private java.awt.Dimension
dim
Holds the old dimension to minimize redrawing of slider tablestatic java.lang.String
MAGNIFICATION
private double
minAllowableMajorTickSpacing
private double
minAllowableMinorTickSpacing
The closest number of pixels that major/minor ticks may be next to each other.static java.lang.String
OPACITY
static java.lang.String
SLICE
static java.lang.String
TIME
private ViewJSlider.SliderType
type
Refers to the type of slider being used by MIPAV-
Fields inherited from class javax.swing.JSlider
changeEvent, changeListener, majorTickSpacing, minorTickSpacing, orientation, sliderModel, snapToTicks
-
Fields inherited from class javax.swing.JComponent
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
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ViewJSlider()
Default constructorViewJSlider(java.lang.String type)
Creates a horizontal slider with the range and initial value specified by type.ViewJSlider(java.lang.String type, int maxBound)
Creates a horizontal slider with the range and initial value specified by type, but the orientation is explicitly specified.ViewJSlider(java.lang.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(java.lang.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(java.lang.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(java.lang.String type, javax.swing.BoundedRangeModel brm)
Creates a horizontal slider with the range and initial value specified by type, but the range model is explicitly specified.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
buildMinimumTickSpacing()
Sets values for minimum allowable tick spacing depending on size of GUI.protected java.util.Hashtable<java.lang.Integer,javax.swing.JLabel>
buildSliderLabels(int intvlMajor)
Builds the slider labels for the slider.protected static javax.swing.JLabel
createLabel(java.lang.String title)
Helper method to create a label with the proper font and font color.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 rangedouble
getMinAllowableMajorTickSpacing()
double
getMinAllowableMinorTickSpacing()
int
getValue()
private void
init(java.lang.String typeStr)
Init method that creates slidervoid
resizeSlider()
Resize slider The max number of major ticks and max number of minor ticks are determined using width/height of dialog.void
setDefaults()
Sets defaultsvoid
setMinAllowableMajorTickSpacing(double minAllowableMajorTickSpacing)
void
setMinAllowableMinorTickSpacing(double minAllowableMinorTickSpacing)
void
setValue(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, updateUI
-
Methods 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, update
-
Methods 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, validateTree
-
Methods 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 Detail
-
TIME
public static final java.lang.String TIME
- See Also:
- Constant Field Values
-
SLICE
public static final java.lang.String SLICE
- See Also:
- Constant Field Values
-
CONTRAST
public static final java.lang.String CONTRAST
- See Also:
- Constant Field Values
-
CUSTOM
public static final java.lang.String CUSTOM
- See Also:
- Constant Field Values
-
OPACITY
public static final java.lang.String OPACITY
- See Also:
- Constant Field Values
-
MAGNIFICATION
public static final java.lang.String MAGNIFICATION
- See Also:
- Constant Field Values
-
type
private ViewJSlider.SliderType type
Refers to the type of slider being used by MIPAV
-
dim
private java.awt.Dimension dim
Holds the old dimension to minimize redrawing of slider table
-
minAllowableMinorTickSpacing
private double minAllowableMinorTickSpacing
The 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 Detail
-
ViewJSlider
private ViewJSlider()
Default constructor
-
ViewJSlider
public ViewJSlider(java.lang.String type)
Creates a horizontal slider with the range and initial value specified by type.- Parameters:
type
- See ViewJSlider.SliderTypes for possible pre-built types
-
ViewJSlider
public ViewJSlider(java.lang.String type, int maxBound)
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 Also:
JSlider
-
ViewJSlider
public ViewJSlider(java.lang.String type, javax.swing.BoundedRangeModel brm)
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 Also:
JSlider
-
ViewJSlider
public ViewJSlider(java.lang.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.- Parameters:
type
- See ViewJSlider.SliderTypes for possible pre-built typesmin
-max
-- See Also:
JSlider
,JSlider
-
ViewJSlider
public ViewJSlider(java.lang.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. The initial value is also specified.- Parameters:
type
- See ViewJSlider.SliderTypes for possible pre-built typesmin
-max
-value
-- See Also:
JSlider
,JSlider
,JSlider
-
ViewJSlider
public ViewJSlider(java.lang.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. The initial value and orientation are also specified.- Parameters:
type
- See ViewJSlider.SliderTypes for possible pre-built typesorientation
-min
-max
-value
-- See Also:
JSlider
,JSlider
,JSlider
,JSlider
-
-
Method Detail
-
getValue
public int getValue()
- Overrides:
getValue
in classjavax.swing.JSlider
-
setValue
public void setValue(int n)
- Overrides:
setValue
in classjavax.swing.JSlider
-
buildSliderLabels
protected java.util.Hashtable<java.lang.Integer,javax.swing.JLabel> buildSliderLabels(int intvlMajor)
Builds the slider labels for the slider.- Parameters:
min
- Min value of slidermax
- Max value of slider.- Returns:
- Slider labels hash.
-
createLabel
protected static javax.swing.JLabel createLabel(java.lang.String title)
Helper method to create a label with the proper font and font color.- Parameters:
title
- Text of the label.- Returns:
- New label.
-
init
private void init(java.lang.String typeStr)
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)
-
-