Example #1
1
  private void initSlider(SpinnerNumberModel model) {
    Number min = ((Number) model.getMinimum());
    Number max = ((Number) model.getMaximum());
    Number value = ((Number) model.getValue());

    Number stepSizeNumber = model.getStepSize();
    useWholeNumbers = stepSizeNumber instanceof Integer;

    if (useWholeNumbers) {
      slider = new JSlider(min.intValue(), max.intValue(), value.intValue());
      slider.setMinorTickSpacing(stepSizeNumber.intValue());
    } else {
      stepSize = stepSizeNumber.doubleValue();
      int minimum = (int) Math.round(min.doubleValue() / stepSize);
      int maximum = (int) Math.round(max.doubleValue() / stepSize);
      int intValue = (int) Math.round(value.doubleValue() / stepSize);
      slider = new JSlider(minimum, maximum, intValue);
      slider.setMinorTickSpacing(stepSizeNumber.intValue());
    }

    Dimension size = slider.getPreferredSize();
    size = new Dimension((int) (size.getWidth() * .60), (int) size.getHeight());
    slider.setPreferredSize(size);
    slider.setSnapToTicks(true);
    slider.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            updateSpinnerState();
          }
        });
  }
Example #2
0
  @Override
  public Object getNextValue() {
    Object ret = getValue();
    long num = ((Number) ret).longValue();

    Unit unit = SizeFormatter.getBestUnit(num);
    long add = getStep(num, unit);

    long newV;
    if (nm.getMaximum() != null) {

      newV = (long) Math.min(((Number) nm.getMaximum()).longValue(), num + add);
    } else {
      newV = (long) (num + add);
    }
    Unit newUnit = SizeFormatter.getBestUnit((long) newV);
    if (newUnit == unit) {
      if (newV == num) {
        beep();
      }
      return newV;
    }

    newV = newUnit.getBytes1024() * 1;

    if (newV == num) {
      beep();
    }
    return newV;
  }