Class 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
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • 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 table
      static 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
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
      • Fields 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

      Constructors 
      Modifier Constructor Description
      private ViewJSlider()
      Default constructor
        ViewJSlider​(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 range
      double getMinAllowableMajorTickSpacing()  
      double getMinAllowableMinorTickSpacing()  
      int getValue()  
      private void init​(java.lang.String typeStr)
      Init method that creates slider
      void 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 defaults
      void 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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 types
        orientation -
        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 types
        brm -
        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 types
        min -
        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 types
        min -
        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 types
        orientation -
        min -
        max -
        value -
        See Also:
        JSlider, JSlider, JSlider, JSlider
    • Method Detail

      • getValue

        public int getValue()
        Overrides:
        getValue in class javax.swing.JSlider
      • setValue

        public void setValue​(int n)
        Overrides:
        setValue in class javax.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 slider
        max - 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 marks
        maxNumTicks - 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)