Ejemplo n.º 1
0
  public void setPaintLabel(boolean paintLabel) {
    logger.finest("set Paint Label " + paintLabel);
    this.paintLabel = paintLabel;
    valueAt0 = rangeSlider.getValueAt(0);
    valueAt1 = rangeSlider.getValueAt(1);

    double precision = 1.0;
    divisor = 1.0 / precision;
    totalLength = (ranges[1] - ranges[0]);
    majorTicksDouble = totalLength / NUM_MAJOR_TICKS;
    minorTicksDouble = totalLength / NUM_MINOR_TICKS;
    intmin = (int) Math.floor(ranges[0] * divisor);
    intmax = (int) Math.ceil(ranges[1] * divisor);
    initialize(
        attributeName,
        DEFAULT_ORIENTATION,
        DEFAULT_NUMBER_OF_THUMBS,
        intmin, // 0
        intmax, // 598
        (int) (majorTicksDouble * divisor), // 120
        (int) (minorTicksDouble * divisor), // ~60
        divisor);
    rangeSlider.setValueAt(0, valueAt0);
    rangeSlider.setValueAt(1, valueAt1);
    titleValues =
        Double.toString(valueAt0) + "       " + title + "       " + Double.toString(valueAt1);
    rangeSlider.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createRaisedBevelBorder(),
            titleValues,
            TitledBorder.CENTER,
            TitledBorder.ABOVE_TOP));
  }
Ejemplo n.º 2
0
 /**
  * Returns and integer array of the selected values on the two thumbs
  *
  * @return
  */
 public int[] getValue() {
   int numThumbs = rangeSlider.getNumberOfThumbs();
   int[] arrayReturnValues = new int[numThumbs];
   for (int i = 0; i < numThumbs; i++) {
     arrayReturnValues[i] = rangeSlider.getValueAt(i);
   }
   return arrayReturnValues;
 }
Ejemplo n.º 3
0
 /**
  * put your documentation comment here
  *
  * @param minMax
  */
 public void setMinMaxValue(double[] minMax) {
   logger.finest("Set up ranges in slider...");
   if (minMax == null) {
     return;
   }
   if ((divideResults == false && attChanged == false)) {
     double precision = 1.0;
     divisor = 1.0 / precision;
     divideResults = true;
     totalLength = (minMax[1] - minMax[0]);
     majorTicksDouble = totalLength / NUM_MAJOR_TICKS;
     minorTicksDouble = totalLength / NUM_MINOR_TICKS;
     int minVal = (int) Math.floor(minMax[0] * divisor);
     int maxVal = (int) Math.ceil(minMax[1] * divisor);
     initialize(
         attributeName,
         DEFAULT_ORIENTATION,
         DEFAULT_NUMBER_OF_THUMBS,
         minVal, // 0
         maxVal, // 598
         (int) (majorTicksDouble * divisor), // 120
         (int) (minorTicksDouble * divisor), // ~60
         divisor);
     logger.finest("After initialize.");
     attChanged = true;
     rangesChanged = true;
     titleChanged = false; // 100
     rangeSlider.setValueAt(0, minVal);
     rangeSlider.setValueAt(1, maxVal);
     if ((title != null)) {
       titleValues =
           Double.toString(rangeSlider.getValueAt(0) / divisor)
               + "       "
               + title
               + "       "
               + Double.toString(rangeSlider.getValueAt(1) / divisor);
       rangeSlider.setBorder(
           BorderFactory.createTitledBorder(
               BorderFactory.createRaisedBevelBorder(),
               titleValues,
               TitledBorder.CENTER,
               TitledBorder.ABOVE_TOP));
     }
   } else {
     if (titleChanged == false && title != null) {
       rangesChanged = true;
     } else {
       rangesChanged = false;
     }
     ranges = minMax;
     intmin = (int) Math.floor(minMax[0] * divisor);
     intmax = (int) Math.ceil(minMax[1] * divisor);
     rangeSlider.setValueAt(0, intmin);
     rangeSlider.setValueAt(1, intmax);
   }
   repaint();
 }
Ejemplo n.º 4
0
 /**
  * put your documentation comment here
  *
  * @param s
  */
 public void setTitle(String s) {
   if (s == null) {
     return;
   }
   if (!title.equals(s) || title.equals(RangeSlider.DEFAULT_TITLE)) {
     title = s;
     titleChanged = true;
     if (divideResults == false && rangesChanged == false) {
       double precision = 1.0;
       divisor = 1.0 / precision;
       divideResults = true;
       totalLength = (ranges[1] - ranges[0]);
       majorTicksDouble = totalLength / NUM_MAJOR_TICKS;
       minorTicksDouble = totalLength / NUM_MINOR_TICKS;
       int minVal = (int) Math.floor(ranges[0] * divisor);
       int maxVal = (int) Math.ceil(ranges[1] * divisor);
       initialize(
           attributeName,
           DEFAULT_ORIENTATION,
           DEFAULT_NUMBER_OF_THUMBS,
           minVal,
           maxVal, // 598
           (int) (majorTicksDouble * divisor), // 120
           (int) (minorTicksDouble * divisor), // ~60
           divisor);
       rangeSlider.setValueAt(0, minVal);
       rangeSlider.setValueAt(1, maxVal);
       logger.finest("After initialize in setTitle.");
       attChanged = true;
       rangesChanged = true;
       titleChanged = false;
       // repaint();
       // set the border name to include variable name and maximum and
       // minimum numbers.
       // if ((rangeSlider != null)){
       titleValues =
           Double.toString(rangeSlider.getValueAt(0) / divisor)
               + "           "
               + title
               + "           "
               + Double.toString(rangeSlider.getValueAt(1) / divisor);
       rangeSlider.setBorder(
           BorderFactory.createTitledBorder(
               BorderFactory.createRaisedBevelBorder(),
               titleValues,
               TitledBorder.CENTER,
               TitledBorder.ABOVE_TOP));
       // }else {
       // titleValues = title;
       // }
       repaint();
     } else {
       attChanged = false;
     }
   }
 }
Ejemplo n.º 5
0
 /**
  * put your documentation comment here
  *
  * @return
  */
 public double[] getValueDoubles() {
   int numThumbs = rangeSlider.getNumberOfThumbs();
   double[] arrayReturnValues = new double[numThumbs];
   for (int i = 0; i < numThumbs; i++) {
     if (divideResults) {
       arrayReturnValues[i] = (rangeSlider.getValueAt(i) / divisor);
     } else {
       arrayReturnValues[i] = rangeSlider.getValueAt(i);
     }
   }
   return arrayReturnValues;
 }
Ejemplo n.º 6
0
 /**
  * put your documentation comment here
  *
  * @param s
  */
 public void setUnits(String s) {
   units = s;
   for (int i = 0; i < numberOfThumbs; i++) {
     double valueAdjusted = rangeSlider.getValueAt(i) / divisor;
     try {
       // sliderNumberDisplayed[i].setText("	" +
       // Double.toString(valueAdjusted));
       // + " " + getUnits());
       rangeSlider.setToolTipText(Double.toString(valueAdjusted));
     } catch (NumberFormatException ex) {
       ex.printStackTrace();
     }
   }
   repaint();
 }
Ejemplo n.º 7
0
 /**
  * put your documentation comment here
  *
  * @param ce
  */
 public void stateChanged(ChangeEvent ce) {
   MultiSlider slider = (MultiSlider) ce.getSource();
   toolTip = " ";
   for (int i = 0; i < numberOfThumbs; i++) {
     double valueAdjusted = slider.getValueAt(i) / divisor;
     try {
       // sliderNumberDisplayed[i].setText("	" +
       // Double.toString(valueAdjusted));
       // + " " + getUnits());
       if (i == rangeSlider.getCurrentThumbIndex()) {
         toolTip = Double.toString(rangeSlider.getValueAt(i) / divisor);
       }
       // toolTip = toolTip +
       // Double.toString((double)rangeSlider.getValueAt
       // (i)/divisor) + " ";
       if (i == 0) {
         titleValues =
             Double.toString(valueAdjusted)
                 + "           "
                 + title
                 + "           "
                 + Double.toString(rangeSlider.getValueAt(1) / divisor);
       } else {
         titleValues =
             Double.toString(rangeSlider.getValueAt(0) / divisor)
                 + "           "
                 + title
                 + "           "
                 + Double.toString(valueAdjusted);
       }
       rangeSlider.setBorder(
           BorderFactory.createTitledBorder(
               BorderFactory.createRaisedBevelBorder(),
               titleValues,
               TitledBorder.CENTER,
               TitledBorder.ABOVE_TOP));
       if (!rangeSlider.getValueIsAdjusting() || valueAdjusting) {
         fireChangeEvent();
       }
     } catch (NumberFormatException ex) {
       ex.printStackTrace();
     }
   }
   rangeSlider.setToolTipText(toolTip);
   // rangeSlider.setCurrentThumbColor(Color.blue);
 }
Ejemplo n.º 8
0
 /**
  * put your documentation comment here
  *
  * @param fc
  */
 public void setFontColor(Color fc) {
   fontColor = fc;
   rangeSlider.setForeground(fontColor);
   for (int i = 0; i < numberOfThumbs; i++) {
     sliderNumberDisplayed[i].setForeground(fontColor);
   }
   repaint();
 }
Ejemplo n.º 9
0
 /**
  * put your documentation comment here
  *
  * @param rangeTitle
  */
 public void setRangeTitle(Object[] rangeTitle) {
   logger.finest("set range and title...");
   if (rangeTitle == null) {
     return;
   }
   logger.finest((String) rangeTitle[0]);
   ranges = (double[]) rangeTitle[1];
   logger.finest("ranges " + ranges[0]);
   if (title != (String) rangeTitle[0]) {
     logger.finest("initialize..." + (String) rangeTitle[0]);
     title = (String) rangeTitle[0];
     double precision = 1.0;
     divisor = 1.0 / precision;
     totalLength = (ranges[1] - ranges[0]);
     majorTicksDouble = totalLength / NUM_MAJOR_TICKS;
     minorTicksDouble = totalLength / NUM_MINOR_TICKS;
     intmin = (int) Math.floor(ranges[0] * divisor);
     intmax = (int) Math.ceil(ranges[1] * divisor);
     initialize(
         attributeName,
         DEFAULT_ORIENTATION,
         DEFAULT_NUMBER_OF_THUMBS,
         intmin, // 0
         intmax, // 598
         (int) (majorTicksDouble * divisor), // 120
         (int) (minorTicksDouble * divisor), // ~60
         divisor);
     rangeSlider.setValueAt(0, intmin);
     rangeSlider.setValueAt(1, intmax);
     titleValues =
         Double.toString(intmin) + "           " + title + "           " + Double.toString(intmax);
     rangeSlider.setBorder(
         BorderFactory.createTitledBorder(
             BorderFactory.createRaisedBevelBorder(),
             titleValues,
             TitledBorder.CENTER,
             TitledBorder.ABOVE_TOP));
   } else {
     intmin = (int) Math.floor(ranges[0] * divisor);
     intmax = (int) Math.ceil(ranges[1] * divisor);
     rangeSlider.setValueAt(0, intmin);
     rangeSlider.setValueAt(1, intmax);
   }
   repaint();
 }
Ejemplo n.º 10
0
 /**
  * If labels are a value other than a double, this method converts and sets the new labels in the
  * corect format
  *
  * @param divisor
  * @param sliderMinimum
  * @param sliderMaximum
  */
 private void generateNewLabels(double divisor, int sliderMinimum, int sliderMaximum) {
   Hashtable convertedLabels = new Hashtable();
   int j = 0;
   for (int i = sliderMinimum; i < sliderMaximum; i += divisor, j++) {
     createSliderLabel(convertedLabels, i, divisor);
   }
   // Now, convert and explicitly add our terminating value
   createSliderLabel(convertedLabels, sliderMaximum, divisor);
   rangeSlider.setLabelTable(convertedLabels);
 }
Ejemplo n.º 11
0
 /**
  * put your documentation comment here
  *
  * @return
  */
 public int getMinorTickSpacing() {
   return rangeSlider.getMinorTickSpacing();
 }
Ejemplo n.º 12
0
 /**
  * put your documentation comment here
  *
  * @param tt
  */
 @Override
 public void setToolTipText(String tt) {
   toolTip = tt;
   rangeSlider.setToolTipText(toolTip);
   repaint();
 }
Ejemplo n.º 13
0
 /**
  * put your documentation comment here
  *
  * @param min
  */
 public void setMinimum(int min) {
   rangeSlider.setMinimum(min);
   repaint();
 }
Ejemplo n.º 14
0
 /**
  * put your documentation comment here
  *
  * @param min
  */
 public void setMinValue(double min) {
   int intmin = (int) (min * divisor);
   rangeSlider.setValueAt(0, intmin);
 }
Ejemplo n.º 15
0
 /**
  * put your documentation comment here
  *
  * @return
  */
 public int getMinimum() {
   return rangeSlider.getMinimum();
 }
Ejemplo n.º 16
0
 /**
  * put your documentation comment here
  *
  * @return
  */
 public int getNumberOfThumbs() {
   return rangeSlider.getNumberOfThumbs();
 }
Ejemplo n.º 17
0
 /**
  * put your documentation comment here
  *
  * @param minorTick
  */
 public void setMinorTickSpacing(int minorTick) {
   rangeSlider.setMinorTickSpacing(minorTick);
   repaint();
 }
Ejemplo n.º 18
0
 /**
  * put your documentation comment here
  *
  * @param sc
  */
 public void setSliderColor(Color sc) {
   sliderColor = sc;
   rangeSlider.setBackground(sliderColor);
   sliderPanel.setBackground(sliderColor);
   repaint();
 }
Ejemplo n.º 19
0
 /**
  * put your documentation comment here
  *
  * @param max
  */
 public void setMaximum(int max) {
   logger.finest("MAX = " + max);
   rangeSlider.setMaximum(max);
   repaint();
 }
Ejemplo n.º 20
0
 /**
  * put your documentation comment here
  *
  * @param max
  */
 public void setMaxValue(double max) {
   int intmax = (int) (max * divisor);
   rangeSlider.setValueAt(1, intmax);
 }
Ejemplo n.º 21
0
 /**
  * put your documentation comment here
  *
  * @param numThumbs
  */
 public void setNumberOfThumbs(int numThumbs) {
   rangeSlider.setNumberOfThumbs(numThumbs);
   repaint();
 }
Ejemplo n.º 22
0
 // ============================ METHODS
 // ========================================== //
 private void initialize(
     String attributeName,
     int orientationConstant,
     int numberOfThumbs,
     int sliderMinimum,
     int sliderMaximum,
     int majorTicks,
     int minorTicks,
     double divisor) {
   logger.finest("Inside initialize.");
   removeAll();
   this.attributeName = attributeName;
   this.numberOfThumbs = numberOfThumbs;
   this.orientationConstant = orientationConstant;
   this.sliderMinimum = sliderMinimum;
   this.sliderMaximum = sliderMaximum;
   this.majorTicks = majorTicks;
   this.minorTicks = minorTicks;
   // MTW. We should do be careful about poorly-initialized data
   if (divisor == 0.0) {
     System.err.println("RangeSlider.initialize(), divisor is 0.0, defaulting to 1");
     divisor = 1;
   }
   this.divisor = divisor;
   setLayout(new BorderLayout());
   // this.sliderPanel = new JPanel();
   // this.labelPanel = new JPanel();
   rangeSlider = new MultiSlider();
   int height = 80;
   int width = 425;
   Dimension sliderSize = new Dimension(width, height);
   rangeSlider.setPreferredSize(sliderSize);
   rangeSlider.setPaintTicks(true);
   rangeSlider.setPaintLabels(paintLabel);
   rangeSlider.setBounded(true);
   rangeSlider.setOrientation(orientationConstant);
   rangeSlider.setMaximum(sliderMaximum);
   rangeSlider.setMinimum(sliderMinimum);
   rangeSlider.setMajorTickSpacing(majorTicks);
   rangeSlider.setMinorTickSpacing(minorTicks);
   rangeSlider.setPaintLabels(paintLabel);
   rangeSlider.setNumberOfThumbs(numberOfThumbs);
   rangeSlider.setToolTipText(toolTip);
   rangeSlider.setForeground(fontColor);
   rangeSlider.setBackground(sliderColor);
   add(rangeSlider);
   // sliderPanel.setBackground(sliderColor);
   // sliderPanel.add(rangeSlider);
   // Identify whether this slider needs special labels
   if (divisor != 1) {
     generateNewLabels(divisor, sliderMinimum, sliderMaximum);
   }
   // labelPanel.setBackground(labelPanelColor);
   // labelPanel.setVisible(true);
   /*
    * sliderNumberDisplayed = new JLabel[numberOfThumbs]; for (int i = 0; i
    * < numberOfThumbs; i++) { sliderNumberDisplayed[i] = new JLabel();
    * sliderNumberDisplayed
    * [i].setHorizontalAlignment(SwingConstants.CENTER);
    * sliderNumberDisplayed[i].setForeground(fontColor);
    * sliderNumberDisplayed
    * [i].setText(Double.toString((double)rangeSlider.getValueAt
    * (i)/divisor)); // + " " + getUnits());
    * labelPanel.add(sliderNumberDisplayed[i]); }
    */
   // setBackground(getLabelPanelColor());
   setVisible(true);
   // add(sliderPanel);
   // add(sliderPanel, BorderLayout.CENTER);
   // add(labelPanel, BorderLayout.SOUTH);
   rangeSlider.addChangeListener(new RangeSliderHandler());
 }