private JPanel createParametersPanel() {
    JPanel parametersPanel = new JPanel();
    parametersPanel.setBorder(BorderFactory.createTitledBorder(dataLayer.getString("PARAMETERS")));

    GridLayout parametersPanelLayout = new GridLayout(0, 3);
    parametersPanelLayout.setHgap(10);
    parametersPanelLayout.setVgap(5);
    parametersPanel.setLayout(parametersPanelLayout);
    //
    // -- DELAY ------------------------------------------------------------
    JLabel delayName = new JLabel(dataLayer.getString("DELAY") + ":");
    delayName.setFont(fontBold);
    parametersPanel.add(delayName);

    // create formatter
    RegexFormatter delayFormatter = new RegexFormatter(Validator.DELAY_PATTERN);
    delayFormatter.setAllowsInvalid(true); // allow to enter invalid value for short time
    delayFormatter.setCommitsOnValidEdit(true); // value is immedeatly published to textField
    delayFormatter.setOverwriteMode(false); // do not overwrite charracters

    jTextFieldDelay = new JFormattedTextField(delayFormatter);
    jTextFieldDelay.setText("" + cable.getDelay());
    jTextFieldDelay.setToolTipText(dataLayer.getString("REQUIRED_FORMAT_IS") + " 1-99");
    // add decorator that paints wrong input icon
    parametersPanel.add(new JLayer<JFormattedTextField>(jTextFieldDelay, layerUI));

    JLabel delayTip = new JLabel("1-99");
    parametersPanel.add(delayTip);

    // --  ------------------------------------------------------------
    return parametersPanel;
  }
  public void initialize(Instrument instrument) {
    ExpireTimeSpinnerModel model = new ExpireTimeSpinnerModel(instrument);
    this.setModel(model);

    JFormattedTextField textField = ((DateEditor) this.getEditor()).getTextField();
    textField.setValue(model._value);
    textField.addFocusListener(
        new FocusListener() {
          public void focusGained(FocusEvent e) {}

          public void focusLost(FocusEvent e) {
            ExpireTimeSpinnerModel model = (ExpireTimeSpinnerModel) getModel();
            JFormattedTextField textField = ((DateEditor) getEditor()).getTextField();
            try {
              DateTime newTime = DateTime.fromDate((Date) getValue());
              if (newTime.compareTo(model.getEndTime()) > 0) {
                textField.setValue(model.getEndTime());
              } else if (newTime.compareTo(model.getBeginTime()) < 0) {
                textField.setValue(model.getBeginTime());
              } else if (DeliveryHoliday.instance.isHoliday(newTime)) {
                textField.setValue(model.getNextAvaliableTime(newTime));
              }
            } catch (IllegalArgumentException exception) // the input maybe out of datetime range
            {
              textField.setValue(model.getEndTime());
            }
          }
        });
  }
Esempio n. 3
0
  /**
   * Lets the user know that the text they entered is bad. Returns true if the user elects to revert
   * to the last good value. Otherwise, returns false, indicating that the user wants to continue
   * editing.
   */
  protected boolean userSaysRevert() {
    Toolkit.getDefaultToolkit().beep();
    ftf.selectAll();
    Object[] options = {"Editar", "Revertir"};
    String mensaje = "El valor debe ser ";
    if (minimum != null && maximum != null)
      mensaje += "mayor a " + minimum + " y menor a " + maximum;
    else {
      if (minimum != null) mensaje += "mayor a " + minimum;
      if (maximum != null) mensaje += "menor a " + maximum;
    }
    int answer =
        JOptionPane.showOptionDialog(
            SwingUtilities.getWindowAncestor(ftf),
            mensaje + ".\n" + "¿Deseas editar el número " + "o revertir los cambios?",
            "Valor ingresado no válido",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.ERROR_MESSAGE,
            null,
            options,
            options[1]);

    if (answer == 1) { // Revert!
      ftf.setValue(ftf.getValue());
      return true;
    }
    return false;
  }
Esempio n. 4
0
 public Quiz getQuizFromContents() {
   List<Question> questions = new ArrayList<Question>();
   for (QuestionEditor editor : questionEditorList) {
     questions.add(editor.getQuestionFromContents());
   }
   return new Quiz(titleTxt.getText(), authorTxt.getText(), questions);
 }
Esempio n. 5
0
 protected void load() {
   nameField.setText(data.name);
   costField.setValue(data.cost);
   colorBox.setSelectedItem(data.color);
   charField.setValue(data.text);
   weightField.setValue(data.weight);
   spellBox.setSelectedItem(data.spell);
 }
 protected final String getValueString() {
   if (inputField.isEditValid())
     try {
       inputField.commitEdit();
     } catch (Exception e) {
     }
   return inputField.getText();
 }
Esempio n. 7
0
 private void setContents(Quiz quiz) {
   removeAllContent();
   titleTxt.setText(quiz.getTitle());
   authorTxt.setText(quiz.getAuthor());
   for (Question question : quiz.getQuestionList()) {
     addQuestion(question);
   }
 }
Esempio n. 8
0
 // Override to invoke setValue on the formatted text field.
 @Override
 public Component getTableCellEditorComponent(
     JTable table, Object value, boolean isSelected, int row, int column) {
   JFormattedTextField ftf1 =
       (JFormattedTextField)
           super.getTableCellEditorComponent(table, value, isSelected, row, column);
   ftf1.setValue(new Float(value.toString()));
   return ftf1;
 }
Esempio n. 9
0
 @Override
 public Component getTableCellEditorComponent(
     JTable table, Object value, boolean isSelected, int row, int column) {
   JFormattedTextField ftf = (JFormattedTextField) getComponent();
   ftf.setFormatterFactory(null);
   ftf.setValue(value);
   ftf.setFormatterFactory(formatterFactory);
   return super.getTableCellEditorComponent(table, value, isSelected, row, column);
 }
Esempio n. 10
0
 public void readValues() {
   portTextField.setValue(getPortFromOptionsFile());
   memoryTextField.setValue(getMemoryLimitFromOptionsFile());
   contextPathComboBox.setSelectedItem(getContextPathFromOptionsFile());
   int httpsPort = getHttpsPortFromOptionsFile();
   boolean httpsEnabled = httpsPort != 0;
   httpsPortTextField.setValue(httpsEnabled ? httpsPort : 443);
   httpsPortTextField.setEnabled(httpsEnabled);
   httpsPortCheckBox.setSelected(httpsEnabled);
 }
Esempio n. 11
0
 /** Performs "1-point" calibration updating the offset but not the slope. */
 private void updateCalibrationOffset() {
   try {
     double rate = (Double) rateField_.getValue();
     // bypass cached positions in positions_ in case they aren't current
     double currentScanner = positions_.getUpdatedPosition(micromirrorDeviceKey_, Directions.Y);
     double currentPiezo = positions_.getUpdatedPosition(piezoImagingDeviceKey_);
     double newOffset = currentPiezo - rate * currentScanner;
     offsetField_.setValue((Double) newOffset);
   } catch (Exception ex) {
     MyDialogUtils.showError(ex);
   }
 }
Esempio n. 12
0
  /** Create the frame */
  public DateTimer() {
    super();
    setTitle("v14 CountDown");
    getContentPane().setLayout(null);
    setBounds(100, 100, 500, 375);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JLabel finishtimeLabel = new JLabel();
    finishtimeLabel.setText("CountDown Time");
    finishtimeLabel.setBounds(10, 36, 119, 15);
    getContentPane().add(finishtimeLabel);
    finishtime =
        new JFormattedTextField(
            new DateFormatter(new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa", Locale.ENGLISH)));
    finishtime.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {}
        });

    finishtime.setValue(new Date());
    finishtime.setBounds(135, 34, 187, 19);
    getContentPane().add(finishtime);

    final JButton startButton = new JButton();
    startButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            startCount();
          }
        });
    startButton.setText("Start!!!");
    startButton.setBounds(334, 31, 111, 25);
    getContentPane().add(startButton);

    countLabel = new JLabel();
    countLabel.setHorizontalAlignment(SwingConstants.CENTER);
    countLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    countLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 14));
    countLabel.setBorder(new LineBorder(Color.black, 1, false));
    countLabel.setText("Countdown not Started");
    countLabel.setBounds(10, 162, 435, 47);
    getContentPane().add(countLabel);

    final JLabel credits = new JLabel();
    credits.setHorizontalAlignment(SwingConstants.RIGHT);
    credits.setText("");
    credits.setBounds(253, 328, 237, 15);
    getContentPane().add(credits);
  }
Esempio n. 13
0
 public void setParameters(ProblemDescriptors descriptors) {
   if (descriptors == null) {
     problemSizeEdit.setText("");
     stockLengthEdit.setText("");
     orderLengthLowerBoundEdit.setText("");
     orderLengthUpperBoundEdit.setText("");
     averageDemandEdit.setText("");
   } else {
     problemSizeEdit.setValue(descriptors.getSize());
     stockLengthEdit.setValue(descriptors.getStockLength());
     orderLengthLowerBoundEdit.setValue(descriptors.getOrderLengthLowerBound());
     orderLengthUpperBoundEdit.setValue(descriptors.getOrderLengthUpperBound());
     averageDemandEdit.setValue(descriptors.getAverageDemand());
   }
 }
Esempio n. 14
0
  // Override to check whether the edit is valid,
  // setting the value if it is and complaining if
  // it isn't.  If it's OK for the editor to go
  // away, we need to invoke the superclass's version
  // of this method so that everything gets cleaned up.
  @Override
  public boolean stopCellEditing() {
    JFormattedTextField ftf1 = (JFormattedTextField) getComponent();
    if (ftf1.isEditValid()) {
      try {
        ftf1.commitEdit();
      } catch (java.text.ParseException exc) {
      }

    } else { // text is invalid
      if (!userSaysRevert()) { // user wants to edit
        return false; // don't let the editor go away
      }
    }
    return super.stopCellEditing();
  }
Esempio n. 15
0
 public boolean verify(JComponent input) {
   if (input instanceof JFormattedTextField) {
     JFormattedTextField ftf = (JFormattedTextField) input;
     JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
     if (formatter != null) {
       String text = ftf.getText();
       try {
         formatter.stringToValue(text);
         return true;
       } catch (ParseException pe) {
         return false;
       }
     }
   }
   return true;
 }
Esempio n. 16
0
 protected void save() {
   data.name = nameField.getText();
   try {
     costField.commitEdit();
     data.cost = ((Long) costField.getValue()).intValue();
   } catch (ParseException e) {
     data.cost = 0;
   }
   data.color = colorBox.getSelectedItem().toString();
   data.text = charField.getText();
   data.weight = Float.parseFloat(weightField.getText());
   if (spellBox.getSelectedItem() != null) {
     data.spell = spellBox.getSelectedItem().toString();
   }
   data.setPath(Editor.getStore().getActive().get("id"));
 }
Esempio n. 17
0
 @Override
 protected void copyValuesFromFieldsToLocal() {
   // get delay from text field
   try {
     this.delay = Integer.parseInt(jTextFieldDelay.getText());
   } catch (NumberFormatException ex) {
   }
 }
Esempio n. 18
0
 @Override
 public JTextField getUserInputComponent() {
   inputField = new JFormattedTextField();
   if (variable.getValue() != null) {
     inputField.setText("" + variable.getValue());
   }
   return inputField;
 }
Esempio n. 19
0
  /**
   * Affiche les cases de la grille grâce à des JTextField pour les cases à remplir et des JLabel
   * pour les indices de somme dans le JPanel pan
   *
   * @param pan
   * @throws NumberFormatException
   */
  public void affichCase(JPanel pan) throws NumberFormatException {
    if (this.n != 0) {
      bloc.setValue(null);
      try {
        MaskFormatter format = new MaskFormatter("#");
        bloc = new JFormattedTextField(format);
      } catch (ParseException e2) {

      }
      pan.add(bloc);
      bloc.setHorizontalAlignment(SwingConstants.CENTER);
      bloc.addKeyListener(
          new KeyAdapter() {
            public void keyReleased(KeyEvent e) {
              try {
                if (Integer.valueOf(bloc.getText()) == n) {
                  Utilitaire.score -= juste;
                  juste = 1;
                  Utilitaire.score += juste;
                } else {
                  Utilitaire.score -= juste;
                  juste = 0;
                  Utilitaire.score += juste;
                }
              } catch (NumberFormatException e1) {

              }
            }
          });
    } else {
      Utilitaire.score -= juste;
      juste = 1;
      Utilitaire.score += juste;
      if (sX != 0)
        if (sY != 0) block.setText(String.format("%2d\\%2d", sX, sY));
        else block.setText(String.format("%2d\\  ", sX));
      else if (sY != 0) block.setText(String.format("  \\%2d", sY));

      block.setHorizontalAlignment(SwingConstants.CENTER);
      block.setBorder(null);
      block.setOpaque(true);
      block.setBackground(Color.BLACK);
      block.setForeground(Color.WHITE);
      pan.add(block);
    }
  }
Esempio n. 20
0
  public void acessaTecladoNumerico(
      JFormattedTextField campoAtual, JFormattedTextField proximoCampo) {

    if (Inicio.isMobile()) {
      campoAtual.setBackground(new Color(255, 255, 190));
      TelaTecladoNumerico tela = new TelaTecladoNumerico(null, true, campoAtual, proximoCampo);
      tela.setVisible(true);
    }
  }
Esempio n. 21
0
 @Override
 public boolean stopCellEditing() {
   JFormattedTextField ftf = (JFormattedTextField) getComponent();
   if (ftf.isEditValid()) {
     try {
       ftf.commitEdit();
     } catch (java.text.ParseException exc) {
       // nothing to do
     }
   } else {
     if (!askEditOrRevert(ftf, null)) {
       return false;
     } else {
       ftf.setValue(ftf.getValue());
     }
   }
   return super.stopCellEditing();
 }
Esempio n. 22
0
 // Override to ensure that the value remains an Float.
 @Override
 public Object getCellEditorValue() {
   JFormattedTextField ftf1 = (JFormattedTextField) getComponent();
   Object o = ftf1.getValue();
   if (o instanceof Float) {
     return o;
   } else if (o instanceof Number) {
     return new Float(((Number) o).intValue());
   } else {
     if (DEBUG) {
       System.out.println("getCellEditorValue: o isn't a Number");
     }
     try {
       return floatFormat.parseObject(o.toString());
     } catch (ParseException exc) {
       System.err.println("getCellEditorValue: can't parse o: " + o);
       return null;
     }
   }
 }
Esempio n. 23
0
 /**
  * Moves piezo and slice together. Specify the factor by which the step size is multiplied by
  * (e.g. +/- 1).
  *
  * @param factor
  */
 private void stepPiezoAndGalvo(double factor) {
   try {
     double piezoPos = positions_.getUpdatedPosition(piezoImagingDeviceKey_);
     piezoPos += (factor * (Double) piezoDeltaField_.getValue());
     positions_.setPosition(piezoImagingDeviceKey_, piezoPos, true);
     double galvoPos = computeGalvoFromPiezo(piezoPos);
     positions_.setPosition(micromirrorDeviceKey_, Directions.Y, galvoPos, true);
   } catch (Exception ex) {
     MyDialogUtils.showError(ex);
   }
 }
Esempio n. 24
0
 private int getPort() throws SettingsException {
   int port;
   try {
     port = ((Number) portTextField.getValue()).intValue();
     if (port < 1 || port > 65535) {
       throw new Exception();
     }
   } catch (Exception x) {
     throw new SettingsException("Please specify a valid port number.", x);
   }
   return port;
 }
Esempio n. 25
0
 private int getMemoryLimit() throws SettingsException {
   int memoryLimit;
   try {
     memoryLimit = ((Number) memoryTextField.getValue()).intValue();
     if (memoryLimit < 5) {
       throw new Exception();
     }
   } catch (Exception x) {
     throw new SettingsException("Please specify a valid memory limit.", x);
   }
   return memoryLimit;
 }
Esempio n. 26
0
  public ProblemDescriptors getParameters() {
    if (Utils.isEmpty(problemSizeEdit.getText())
        || Utils.isEmpty(stockLengthEdit.getText())
        || Utils.isEmpty(orderLengthLowerBoundEdit.getText())
        || Utils.isEmpty(orderLengthUpperBoundEdit.getText())
        || Utils.isEmpty(averageDemandEdit.getText())) {
      return null;
    }

    int problemSize = ((Number) problemSizeEdit.getValue()).intValue();
    int stockLength = ((Number) stockLengthEdit.getValue()).intValue();
    double orderLengthLowerBound = ((Number) orderLengthLowerBoundEdit.getValue()).doubleValue();
    double orderLengthUpperBound = ((Number) orderLengthUpperBoundEdit.getValue()).doubleValue();
    int averageDemand = ((Number) averageDemandEdit.getValue()).intValue();

    ProblemDescriptors descriptors =
        new ProblemDescriptors(
            problemSize, stockLength, orderLengthLowerBound, orderLengthUpperBound, averageDemand);

    return descriptors;
  }
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == submit) {
     if (rb1.isSelected()) {
       JFrame frame = Application.getFrame();
       if (typeCodes.isEmpty()) {
         JOptionPane.showMessageDialog(
             frame,
             "Please select at least one toponym type.",
             "Error",
             JOptionPane.ERROR_MESSAGE);
       } else {
         Application.getMainCitiesPanel(this, typeCodes, 0, 0.0);
       }
     } else if (rb2.isSelected()) {
       JFrame frame = Application.getFrame();
       try {
         nCities = new Integer(nCitiesField.getText());
         if (nCities <= 0) throw new NumberFormatException();
         typeCodes = new ArrayList<String>();
         Application.getMainCitiesPanel(this, typeCodes, nCities, 0.0);
       } catch (NumberFormatException ex) {
         JOptionPane.showMessageDialog(
             frame, "Please enter a positive integer number.", "Error", JOptionPane.ERROR_MESSAGE);
       }
     } else {
       JFrame frame = Application.getFrame();
       try {
         Double dist = new Double(distField.getText());
         if (dist <= 0) throw new NumberFormatException();
         typeCodes = new ArrayList<String>();
         Application.getMainCitiesPanel(this, typeCodes, 0, dist);
       } catch (NumberFormatException ex) {
         JOptionPane.showMessageDialog(
             frame, "Please enter a positive number.", "Error", JOptionPane.ERROR_MESSAGE);
       }
     }
   } else {
     Application.getOptionPanel(this, countryName);
   }
 }
Esempio n. 28
0
    /** Constructs cell editor. */
    public CellEditor() {
      super(new JFormattedTextField());
      final JFormattedTextField ftf = (JFormattedTextField) getComponent();

      // Set GUI behaviour of text field
      ftf.setValue(null);
      ftf.setHorizontalAlignment(JTextField.LEADING);
      ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);

      // Set that one click on cell is enough for editing
      setClickCountToStart(1);

      // Special handling code for ENTER
      ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
      ftf.getActionMap()
          .put(
              "check",
              new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                  if (!ftf.isEditValid()) {
                    if (askEditOrRevert(ftf, null)) {
                      ftf.setValue(ftf.getValue());
                      ftf.postActionEvent();
                    }
                  } else
                    try {
                      ftf.commitEdit();
                      ftf.postActionEvent();
                    } catch (java.text.ParseException exc) {
                      // nothing to do
                    }
                }
              });
    }
  public Job getEditingJob() {
    Job job = new Job();

    job.setId(id);
    job.setName(jobNameTextField.getText());
    job.setEnabled(enabledCheckBox.isSelected());
    if (scheduledRadioButton.isSelected()) {
      job.setIntervalUnit(Job.getUnits()[intervalUnitComboBox.getSelectedIndex()]);
      job.setIntervalPeriod(parseInt(intervalFormattedTextField.getText()));
    }

    return job;
  }
  @Override
  protected void paintComponent(Graphics graphics) {
    int width = getWidth() - getInsets().left - getInsets().right;
    int height = getHeight() - getInsets().top - getInsets().bottom;

    Graphics2D g2d = (Graphics2D) graphics;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(backgroundColor);

    g2d.fillRoundRect(getInsets().left, getInsets().top, width, height, 8, 8);

    super.paintComponent(
        graphics); // To change body of overridden methods use File | Settings | File Templates.
  }