Ejemplo 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();
          }
        });
  }
Ejemplo n.º 2
0
 public void setValue(String value) {
   if (useWholeNumbers) {
     model.setValue(Integer.valueOf(value));
   } else {
     model.setValue(Double.valueOf(value));
   }
 }
Ejemplo n.º 3
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;
  }
Ejemplo n.º 4
0
 public String getValueAsString() {
   if (useWholeNumbers) {
     return model.getNumber().toString();
   } else {
     return numberFormat.format(model.getNumber().doubleValue());
   }
 }
  /** Performs the action of loading a session from a file. */
  public void actionPerformed(ActionEvent e) {
    DataModel dataModel = getDataEditor().getSelectedDataModel();

    if (!(dataModel instanceof DataSet)) {
      JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Must be a tabular data set.");
      return;
    }

    this.dataSet = (DataSet) dataModel;

    SpinnerNumberModel spinnerNumberModel = new SpinnerNumberModel(getNumLags(), 0, 20, 1);
    JSpinner jSpinner = new JSpinner(spinnerNumberModel);
    jSpinner.setPreferredSize(jSpinner.getPreferredSize());

    spinnerNumberModel.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            SpinnerNumberModel model = (SpinnerNumberModel) e.getSource();
            setNumLags(model.getNumber().intValue());
          }
        });

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    Box b = Box.createVerticalBox();
    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Number of time lags: "));
    b1.add(Box.createHorizontalGlue());
    b1.add(Box.createHorizontalStrut(15));
    b1.add(jSpinner);
    b1.setBorder(new EmptyBorder(10, 10, 10, 10));
    b.add(b1);

    panel.add(b, BorderLayout.CENTER);

    EditorWindow editorWindow = new EditorWindow(panel, "Create time series data", "Save", true);
    DesktopController.getInstance().addEditorWindow(editorWindow);
    editorWindow.setVisible(true);

    editorWindow.addInternalFrameListener(
        new InternalFrameAdapter() {
          public void internalFrameClosed(InternalFrameEvent e) {
            EditorWindow window = (EditorWindow) e.getSource();

            if (!window.isCanceled()) {
              if (dataSet.isContinuous()) {
                createContinuousTimeSeriesData();
              } else if (dataSet.isDiscrete()) {
                createDiscreteTimeSeriesData();
              } else {
                JOptionPane.showMessageDialog(
                    JOptionUtils.centeringComp(),
                    "Data set must be either continuous or discrete.");
              }
            }
          }
        });
  }
 private void actualizarCantidadPisos() {
   if (mdlTorre.getSelectedItem() != null) {
     Torre t = (Torre) mdlTorre.getSelectedItem();
     int max = t.getCantidadPisos();
     mdlPiso.setValue((Integer) 1);
     mdlPiso.setMaximum(max);
   }
 }
Ejemplo n.º 7
0
 private void spiSideStateChanged(
     javax.swing.event.ChangeEvent evt) { // GEN-FIRST:event_spiSideStateChanged
   if (rbClockwise.isSelected()) {
     angle = 360 / snmSide.getNumber().doubleValue();
   } else {
     angle = -360 / snmSide.getNumber().doubleValue();
   }
   lblAngle.setText(angle + "°");
 } // GEN-LAST:event_spiSideStateChanged
Ejemplo n.º 8
0
 @Override
 public void stateChanged(ChangeEvent e) {
   // a quick way of setting end of day, just set hours to 24
   if (hourModel.getNumber().longValue() == 24) {
     hourModel.setValue(23);
     minuteModel.setValue(59);
     secondModel.setValue(59);
   }
 }
Ejemplo n.º 9
0
 private void rbAntiClockwiseActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_rbAntiClockwiseActionPerformed
   if (rbClockwise.isSelected()) {
     angle = 360 / snmSide.getNumber().doubleValue();
   } else {
     angle = -360 / snmSide.getNumber().doubleValue();
   }
   lblAngle.setText(angle + "°");
 } // GEN-LAST:event_rbAntiClockwiseActionPerformed
Ejemplo n.º 10
0
  /**
   * Returns the time since the beginning of the day in milliseconds that this Chooser represents.
   */
  public long getTime() {
    long time = 0;

    time += secondModel.getNumber().longValue() * 1000;
    time += minuteModel.getNumber().longValue() * 60 * 1000;
    time += hourModel.getNumber().longValue() * 60 * 60 * 1000;

    return time;
  }
Ejemplo n.º 11
0
 private void jButton1ActionPerformed(ActionEvent evt) { // event OK!
   if (hexboard != null) hexboard.setVisible(false);
   SpinnerNumberModel model = (SpinnerNumberModel) jSpinner1.getModel();
   int size = model.getNumber().intValue();
   initHexboard(size);
   jFrame1.setVisible(false);
   String strategy1 = (String) jComboBox1.getSelectedItem();
   String strategy2 = (String) jComboBox2.getSelectedItem();
   controller.startNewGameAction(size, strategy1, strategy2);
 } //
Ejemplo n.º 12
0
  /**
   * Sets the time based upon the number of miliseconds given
   *
   * @param msPastMidnight
   */
  public TimeChooser(long msPastMidnight) {
    this();
    // Turn to seconds
    msPastMidnight = msPastMidnight / 1000;

    // set hours
    hourModel.setValue((int) (msPastMidnight / 3600));
    minuteModel.setValue((int) (msPastMidnight % 3600 / 60));
    secondModel.setValue((int) (msPastMidnight % 60));
  }
Ejemplo n.º 13
0
        public void actionPerformed(ActionEvent evt) {

          // clear selection
          list.getListComponent().clearSelection();

          int from = fromSpinnerModel.getNumber().intValue();
          int to = toSpinnerModel.getNumber().intValue();

          try {
            ExpressionFormat format = new ExpressionFormat(textField.getText());

            // pad episode numbers with zeros (e.g. %02d) so all numbers have the same number of
            // digits
            NumberFormat numberFormat = NumberFormat.getIntegerInstance();
            numberFormat.setMinimumIntegerDigits(max(2, Integer.toString(max(from, to)).length()));
            numberFormat.setGroupingUsed(false);

            List<String> names = new ArrayList<String>();

            int min = min(from, to);
            int max = max(from, to);

            for (int i = min; i <= max; i++) {
              Bindings bindings = new SimpleBindings();

              // strings
              bindings.put("i", numberFormat.format(i));

              // numbers
              bindings.put("index", i);
              bindings.put("from", from);
              bindings.put("to", to);

              names.add(format.format(bindings, new StringBuffer()).toString());
            }

            if (signum(to - from) < 0) {
              Collections.reverse(names);
            }

            // try to match title from the first five names
            Collection<String> title =
                new SeriesNameMatcher()
                    .matchAll(
                        (names.size() < 5 ? names : names.subList(0, 4)).toArray(new String[0]));

            list.setTitle(title.isEmpty() ? "List" : title.iterator().next());

            list.getModel().clear();
            list.getModel().addAll(names);
          } catch (Exception e) {
            UILogger.log(Level.WARNING, ExceptionUtilities.getMessage(e), e);
          }
        }
  public void updateRegulatorsOptions() {

    Integer value = (Integer) numRegulators_.getModel().getValue();
    if ((Integer) numRegulators_.getModel().getValue()
        > (Integer) subnetSize_.getModel().getValue())
      value = (Integer) subnetSize_.getModel().getValue();

    SpinnerNumberModel model = (SpinnerNumberModel) numRegulators_.getModel();
    model.setMinimum(1);
    model.setMaximum((Integer) subnetSize_.getModel().getValue());
    model.setStepSize(1);
    model.setValue(value);
  }
Ejemplo n.º 15
0
  private void updateSpinnerState() {
    int value = slider.getValue();

    if (useWholeNumbers) {
      model.setValue(new Integer(value));
    } else {
      double doubleValue = value * stepSize;
      model.setValue(new Double(doubleValue));
    }

    if (changeListener != null) {
      changeListener.stateChanged(new ChangeEvent(this));
    }
  }
Ejemplo n.º 16
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));
      }
    }
  }
Ejemplo n.º 17
0
  /** Update interface to reflect values of the current AstAxisLabel. */
  protected void updateFromAstAxisLabels() {
    //  Nothing in this method should change astAxisLabels, but
    //  we'll switch off the ChangeListener anyway.
    astAxisLabels.removeChangeListener(this);

    xShowLabel.setSelected(astAxisLabels.getXShown());
    if (!inhibitXDocumentListener) {
      xTextField.setText(astAxisLabels.getXLabel());
    }

    yShowLabel.setSelected(astAxisLabels.getYShown());
    if (!inhibitYDocumentListener) {
      yTextField.setText(astAxisLabels.getYLabel());
    }

    xTextField.setTextFont(astAxisLabels.getFont());
    yTextField.setTextFont(astAxisLabels.getFont());
    fontControls.setFont(astAxisLabels.getFont());
    xTextField.setTextColour(astAxisLabels.getColour());
    yTextField.setTextColour(astAxisLabels.getColour());
    colourIcon.setMainColour(astAxisLabels.getColour());
    colourButton.repaint();

    xSpinnerModel.setValue(new Double(astAxisLabels.getXGap()));
    ySpinnerModel.setValue(new Double(astAxisLabels.getYGap()));

    if (astAxisLabels.getXEdge() == AstAxisLabels.BOTTOM) {
      xEdge.setSelectedItem("BOTTOM");
    } else {
      xEdge.setSelectedItem("TOP");
    }
    if (astAxisLabels.getYEdge() == AstAxisLabels.LEFT) {
      yEdge.setSelectedItem("LEFT");
    } else {
      yEdge.setSelectedItem("RIGHT");
    }

    xUnits.setSelected(astAxisLabels.getShowXUnits());
    yUnits.setSelected(astAxisLabels.getShowYUnits());

    astAxisLabels.setXState(true);
    astAxisLabels.setYState(true);

    astAxisLabels.addChangeListener(this);
  }
Ejemplo n.º 18
0
  private void initComponents() {

    sparklinePanel = new JPanel();

    FormLayout layout = new FormLayout("d", "d");
    sparklinePanel.setLayout(layout);

    model = new SpinnerNumberModel();

    model.setValue(DateUtils.getCurrentYear());
    model.setStepSize(1);

    yearSpinner = new JSpinner(model);

    JSpinner.NumberEditor editor = new JSpinner.NumberEditor(yearSpinner, "####");
    yearSpinner.setEditor(editor);
    yearSpinner.setEnabled(false);
  }
  public void init() {
    setup("Circumference of a Circle");
    SpinnerNumberModel snm = (SpinnerNumberModel) (n.getModel());
    snm.setMinimum(new Integer(3));

    north.setLayout(new BorderLayout());
    north.add("West", choice);
    JPanel east = new JPanel();
    east.add(new JLabel(" n="));
    east.add(n);
    north.add("East", east);

    south.remove(choice);

    contentpane.add("North", north);

    contentpane.add("Center", graph = new CircleCircumferenceGraph(this, N));
    if (getParameter("originX") != null) {
      graph.originX = Double.parseDouble(getParameter("originX"));
    }
    if (getParameter("originY") != null) {
      graph.originY = Double.parseDouble(getParameter("originY"));
    }
    if (getParameter("zoom") != null) {
      graph.zoom += Integer.parseInt(getParameter("zoom"));
    }

    stat2.setVisible(true);

    // choice = new Choice();
    choice.addItem("Inscribed Polygon");
    choice.addItem("Circumscribed Polygon");
    choice.addItem("Show Both");
    choice.addItem("Show Sequences");
    // choice.addItem("Newton-Cotes Rule");
    choice.setSelectedItem(getParameter("type"));

    graph.repaint();
    splash = new SplashPanel(new CircleCircumferenceGraph(this, N));
    splash.graph.originX = graph.originX;
    splash.graph.originY = graph.originY;
    splash.graph.zoom = graph.zoom;
    getContentPane().add(splash);
  }
Ejemplo n.º 20
0
  /**
   * Constructs and returns a worker thread which can perform a match as specified by the current
   * state of this component.
   *
   * @return new worker thread
   * @throws RuntimeException if the current state does not fully specify a multi query job; such
   *     exceptions will have comprehensible messages
   */
  private MatchWorker createMatchWorker() {

    /* Acquire state from this panel's GUI components. */
    String sUrl = urlField_.getText();
    if (sUrl == null || sUrl.trim().length() == 0) {
      throw new IllegalArgumentException("No " + service_.getName() + " URL given");
    }
    URL serviceUrl;
    try {
      serviceUrl = new URL(sUrl);
    } catch (MalformedURLException e) {
      throw (IllegalArgumentException)
          new IllegalArgumentException("Bad " + service_.getName() + " URL syntax: " + sUrl)
              .initCause(e);
    }
    ConeErrorPolicy erract = (ConeErrorPolicy) erractSelector_.getSelectedItem();
    TopcatModel tcModel = tcModel_;
    if (tcModel == null) {
      throw new NullPointerException("No table selected");
    }
    final StarTable inTable = tcModel.getApparentStarTable();
    int[] rowMap = tcModel.getViewModel().getRowMap();
    ColumnData raData = raSelector_.getColumnData();
    ColumnData decData = decSelector_.getColumnData();
    ColumnData srData = srSelector_.getColumnData();
    if (raData == null) {
      throw new NullPointerException("No RA column given");
    }
    if (decData == null) {
      throw new NullPointerException("No Dec column given");
    }
    Number parNum = parallelModel_.getNumber();
    int parallelism = parNum == null ? 1 : parNum.intValue();
    MulticoneMode mcMode = (MulticoneMode) modeSelector_.getSelectedItem();
    StarTableFactory tfact = ControlWindow.getInstance().getTableFactory();

    /* Assemble objects based on this information. */
    ConeSearcher searcher = service_.createSearcher(serviceUrl, tfact);
    Coverage coverage = coverageModel_.isSelected() ? service_.getCoverage(serviceUrl) : null;
    DatasQuerySequenceFactory qsf = new DatasQuerySequenceFactory(raData, decData, srData, rowMap);
    ConeMatcher matcher =
        mcMode.createConeMatcher(searcher, erract, inTable, qsf, coverage, parallelism);
    ResultHandler resultHandler =
        mcMode.createResultHandler(this, tfact.getStoragePolicy(), tcModel, inTable);

    /* Create MatchWorker encapsulating all of this. */
    MatchWorker worker = new MatchWorker(matcher, resultHandler, tcModel, inTable);

    /* Perform post-construction configuration of constituent objects
     * as required. */
    qsf.setMatchWorker(worker);
    resultHandler.setMatchWorker(worker);

    /* Return worker thread. */
    return worker;
  }
  public Apartamento nuevoApartamento() {
    Torre torre = (Torre) mdlTorre.getSelectedItem();
    int piso = mdlPiso.getNumber().intValue();
    String telefono = txtTelefono.getText();
    String citofono = txtCitofono.getText();
    String placa = txtPlaca.getText();

    Apartamento a = new Apartamento(torre, placa, piso, citofono, telefono);
    return a;
  }
Ejemplo n.º 22
0
  /** 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());
  }
Ejemplo n.º 23
0
 public void addChangeListener(final IIntValueChangedListener listener) {
   ChangeListener changeListener =
       new ChangeListener() {
         @Override
         public void stateChanged(ChangeEvent e) {
           listener.valueChanged(getValue());
         }
       };
   listenerMap.put(listener, changeListener);
   numberModel.addChangeListener(changeListener);
 }
Ejemplo n.º 24
0
  @Override
  public void stateChanged(final ChangeEvent e) {
    logger.entering(BudgetOverviewPanel.class.getName(), "stateChanged");

    if (e.getSource() == yearSpinner) {
      int year = (Integer) model.getNumber();

      budgetPanel.setBudgetYear(year);
    }

    logger.exiting(BudgetOverviewPanel.class.getName(), "stateChanged");
  }
  private void spnTonnageStateChanged(
      javax.swing.event.ChangeEvent evt) { // GEN-FIRST:event_spnTonnageStateChanged
    javax.swing.SpinnerNumberModel n = (SpinnerNumberModel) spnTonnage.getModel();
    javax.swing.JComponent editor = spnTonnage.getEditor();
    javax.swing.JFormattedTextField tf =
        ((javax.swing.JSpinner.DefaultEditor) editor).getTextField();

    // get the value from the text box, if it's valid.
    try {
      spnTonnage.commitEdit();
    } catch (java.text.ParseException pe) {
      // Edited value is invalid, spinner.getValue() will return
      // the last valid value, you could revert the spinner to show that:
      if (editor instanceof javax.swing.JSpinner.DefaultEditor) {
        tf.setValue(spnTonnage.getValue());
      }
      return;
    }

    CurAmmo = n.getNumber().intValue();
  } // GEN-LAST:event_spnTonnageStateChanged
  /** Builds the panel. */
  public void setup() {
    SpinnerNumberModel model =
        new SpinnerNumberModel(this.params.getInt("numTimeLags", 1), 0, Integer.MAX_VALUE, 1);
    JSpinner jSpinner = new JSpinner(model);
    jSpinner.setPreferredSize(jSpinner.getPreferredSize());

    model.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            SpinnerNumberModel model = (SpinnerNumberModel) e.getSource();
            params.set("numTimeLags", model.getNumber().intValue());
          }
        });

    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Number of lags: "));
    b1.add(Box.createHorizontalGlue());
    b1.add(Box.createHorizontalStrut(15));
    b1.add(jSpinner);
    b1.setBorder(new EmptyBorder(10, 10, 10, 10));
    add(b1, BorderLayout.CENTER);
  }
Ejemplo n.º 27
0
    public Object getPropertyValue() {
      GregorianCalendar result = new GregorianCalendar();

      result.setTimeZone(timezone);

      result.set(Calendar.YEAR, year.getNumber().intValue());
      int mi = 0;
      String ms = month.getValue().toString();
      for (int i = 0; i < MONTH_STRINGS.length; i++) {
        if (MONTH_STRINGS[i].equals(ms)) {
          mi = i;
          break;
        }
      }
      result.set(Calendar.MONTH, mi);
      result.set(Calendar.DATE, day.getNumber().intValue());
      result.set(Calendar.HOUR_OF_DAY, hour.getNumber().intValue());
      result.set(Calendar.MINUTE, min.getNumber().intValue());
      result.set(Calendar.SECOND, sec.getNumber().intValue());

      return result;
    }
Ejemplo n.º 28
0
  public void update() {
    // find & set index of selected trigger
    Play instruction = (Play) inst;
    int handleVal = Integer.parseInt(instruction.handleVal());
    handleModel.setValue(Integer.valueOf(handleVal));

    // loop flag
    loop.setSelectedItem(instruction.brkVal());

    // wavbreak flags
    int flags = instruction.getWaveBrkFlags();
    wavbrk1.setSelected((flags & 0x01) != 0);
    wavbrk2.setSelected((flags & 0x02) != 0);
  }
Ejemplo n.º 29
0
  public LineBorderEditor() {

    initialize();

    color = new ColorHolder();
    setCaption(getEditorLocaleString("Line"));
    assignValueToParameters();

    rounded = new JCheckBox(getEditorLocaleString("Rounded_corners"));
    rounded.setSelected(roundedCorners);
    rounded.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            roundedCorners = rounded.isSelected();
            fireChange();
          }
        });

    thickModel = new SpinnerNumberModel(thickness, MIN_THICK, MAX_THICK, 1);
    SpinPane thickPane = new SpinPane(thickModel, getEditorLocaleString("Thickness"));
    thickModel.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            thickness = thickModel.getNumber().intValue();
            fireChange();
          }
        });

    JButton bColor = new JButton(getEditorLocaleString("Color"));
    ColorChooseAction colorChooseAction =
        new ColorChooseAction(color, getEditorLocaleString("Color"), this);
    colorChooseAction.addPropertyChangeListener(this);
    bColor.addActionListener(colorChooseAction);

    setLayout(new BorderLayout());
    JPanel pane = new JPanel(new GridLayout(1, 2));
    pane.add(getCenteredPane(rounded));
    pane.add(getCenteredPane(thickPane));
    JPanel paneTotal = new JPanel(new GridLayout(2, 1));
    paneTotal.add(pane);
    paneTotal.add(getCenteredPane(bColor));
    add(paneTotal, BorderLayout.NORTH);

    refreshInterface();
  }
Ejemplo n.º 30
0
  /** update instruction if GUI changes */
  void guiChanged() {
    Play instruction = (Play) PlayEditor.this.inst;

    instruction.setHandle(handleModel.getNumber().intValue());

    instruction.setBrk((String) loop.getSelectedItem());

    int flag = 0;
    if (wavbrk1.isSelected()) {
      flag |= 0x01;
    }
    if (wavbrk2.isSelected()) {
      flag |= 0x02;
    }
    instruction.setWaveBrkFlags(flag);

    // tell the world
    updated();
  }