Esempio n. 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();
          }
        });
  }
Esempio n. 2
0
  private void updateSliderState() {
    if (!slider.getValueIsAdjusting()) {
      if (useWholeNumbers) {
        int value = ((Number) model.getValue()).intValue();
        slider.setValue(value);
      } else {
        double value = ((Number) model.getValue()).doubleValue();
        int intValue = (int) Math.round(value / stepSize);
        slider.setValue(intValue);
      }

      if (changeListener != null) {
        changeListener.stateChanged(new ChangeEvent(this));
      }
    }
  }
  /** Update date spinner to synchronize with the other spinners */
  private void updateDate() {
    // Get current month and year in int
    int month = ((SpinnerListModel) jspMonth.getModel()).getList().indexOf(jspMonth.getValue());
    int year = ((Integer) spinnerYear.getValue()).intValue();

    // Set a new maximum number of days for the new month and year
    SpinnerNumberModel numberModel = (SpinnerNumberModel) jspDay.getModel();
    numberModel.setMaximum(new Integer(maxDaysInMonth(year, month)));

    // Set a new current day if it exceeds the maximum
    if (((Integer) (numberModel.getValue())).intValue() > maxDaysInMonth(year, month))
      numberModel.setValue(new Integer(maxDaysInMonth(year, month)));

    // Get the current day
    int day = ((Integer) jspDay.getValue()).intValue();

    // Set a new date in the date spinner
    jspDate.setValue(new GregorianCalendar(year, month, day).getTime());
  }
Esempio n. 4
0
  /**
   * Descripción de Método
   *
   * @param e
   */
  public void stateChanged(ChangeEvent e) {
    if (m_setting) {
      return;
    }

    // log.config( "Viewer.stateChanged", e);

    m_setting = true;

    int newPage = 0;

    if (e.getSource() == spinner) {
      newPage = ((Integer) spinnerModel.getValue()).intValue();
    } else // Viewpoint
    {
      Point p = centerScrollPane.getViewport().getViewPosition();

      newPage = Math.round(m_viewPanel.getPageNoAt(p));
    }

    setPage(newPage);
    m_setting = false;
  } // stateChanged
Esempio n. 5
0
 public int getValue() {
   return ((Number) numberModel.getValue()).intValue();
 }
 @Override
 public void stateChanged(ChangeEvent arg0) {
   listener.valueChanged(this, (int) spinnerNumberModel.getValue());
 }