Class ViewJSlider

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants

public class ViewJSlider extends 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:
  • Field Details

  • Constructor Details

    • ViewJSlider

      private ViewJSlider()
      Default constructor
    • ViewJSlider

      public ViewJSlider(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(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 JSlider
    • ViewJSlider

      public 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.
      Parameters:
      type - See ViewJSlider.SliderTypes for possible pre-built types
      brm - @see JSlider
    • ViewJSlider

      public 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.
      Parameters:
      type - See ViewJSlider.SliderTypes for possible pre-built types
      min - @see JSlider
      max - @see JSlider
    • ViewJSlider

      public 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. The initial value is also specified.
      Parameters:
      type - See ViewJSlider.SliderTypes for possible pre-built types
      min - @see JSlider
      max - @see JSlider
      value - @see JSlider
    • ViewJSlider

      public 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. The initial value and orientation are also specified.
      Parameters:
      type - See ViewJSlider.SliderTypes for possible pre-built types
      orientation - @see JSlider
      min - @see JSlider
      max - @see JSlider
      value - @see JSlider
  • Method Details

    • getValue

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

      public void setValue(int n)
      Overrides:
      setValue in class JSlider
    • buildSliderLabels

      protected Hashtable<Integer,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 JLabel createLabel(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(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)