Package javax.swing

Examples of javax.swing.JFormattedTextField$CancelAction


                .getText("nextMonth")));
        jbNextYear.setToolTipText(GanttProject.getToolTip(language
                .getText("nextYear")));

        ddd = new GanttDialogDateDay(date, language);
        jtDate = new JFormattedTextField(new SimpleDateFormat("MMM yyyy"));
        jtDate.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GregorianCalendar tmp = new GregorianCalendar();
                tmp.setTime((Date) jtDate.getValue());
                changeDate(tmp);
View Full Code Here


            gBC3.insets = new Insets(2, 2, 2, 2);

            UIUtil.jGridBagAdd(sizePanel, new JLabel("Size:"), gBC3, GridBagConstraints.REMAINDER);

            UIUtil.jGridBagAdd(sizePanel, fontSize = new JFormattedTextField(new Integer(4)), gBC3, GridBagConstraints.REMAINDER);

            fontSize.getDocument().addDocumentListener(new DocumentListener() {


View Full Code Here

   */
  public AutoCommitSpinner(SpinnerModel model) {
    super(model);   
    JComponent editor = getEditor();
    if (editor instanceof JSpinner.DefaultEditor) {
      final JFormattedTextField textField = ((JSpinner.DefaultEditor)editor).getTextField();     
      SwingTools.addAutoSelectionOnFocusGain(textField);
     
      // Commit text during edition
      if (textField.getFormatterFactory() instanceof DefaultFormatterFactory) {
        DefaultFormatterFactory formatterFactory = (DefaultFormatterFactory)textField.getFormatterFactory();
        JFormattedTextField.AbstractFormatter defaultFormatter = formatterFactory.getDefaultFormatter();
        if (defaultFormatter instanceof DefaultFormatter) {
          ((DefaultFormatter)defaultFormatter).setCommitsOnValidEdit(true);
        }
        if (defaultFormatter instanceof NumberFormatter) {
          final NumberFormatter numberFormatter = (NumberFormatter)defaultFormatter;
          final DecimalFormat defaultFormat = (DecimalFormat)numberFormatter.getFormat();
          final DecimalFormat noGroupingFormat = (DecimalFormat)defaultFormat.clone();
          noGroupingFormat.setGroupingUsed(false);
          // Create a delegate of default formatter to change value returned by getFormat
          NumberFormatter editFormatter = new NumberFormatter() {
              @Override
              public Format getFormat() {
                // Use a different format depending on whether the text field has focus or not
                if (textField.hasFocus()) {
                  // No grouping when text field has focus
                  return noGroupingFormat;
                } else {
                  return defaultFormat;
                }
              }
           
              @Override
              public boolean getCommitsOnValidEdit() {
                return true;
              }
             
              @SuppressWarnings("unchecked")
              @Override
              public Comparable getMaximum() {
                return numberFormatter.getMaximum();
              }
             
              @SuppressWarnings("unchecked")
              @Override
              public Comparable getMinimum() {
                return numberFormatter.getMinimum();
              }
             
              @SuppressWarnings("unchecked")
              @Override
              public void setMaximum(Comparable maximum) {
                numberFormatter.setMaximum(maximum);
              }
             
              @SuppressWarnings("unchecked")
              @Override
              public void setMinimum(Comparable minimum) {
                numberFormatter.setMinimum(minimum);
              }
             
              @Override
              public Class<?> getValueClass() {
                return numberFormatter.getValueClass();
              }
            };
          textField.setFormatterFactory(new DefaultFormatterFactory(editFormatter));
        }
      }
    }
  }
View Full Code Here

  /**
   * Creates a nullable spinner from <code>model</code>.
   */
  public NullableSpinner(NullableSpinnerNumberModel model) {
    super(model);
    final JFormattedTextField textField = ((DefaultEditor)getEditor()).getTextField();
    final JFormattedTextField.AbstractFormatter defaultFormatter = textField.getFormatter();
    // Change formatted text field formatter to enable the edition of empty values
    textField.setFormatterFactory(new JFormattedTextField.AbstractFormatterFactory() {
        @Override
        public JFormattedTextField.AbstractFormatter getFormatter(JFormattedTextField tf) {
          return new NumberFormatter () {
              @Override
              public boolean getCommitsOnValidEdit() {
View Full Code Here

  private void createToolTipTextFields(UserPreferences preferences,
                                       final PlanController controller) {
    this.toolTipEditableTextFields = new HashMap<PlanController.EditableProperty, JFormattedTextField>();
    Font toolTipFont = UIManager.getFont("ToolTip.font");
    for (final PlanController.EditableProperty editableProperty : PlanController.EditableProperty.values()) {
      final JFormattedTextField textField = new JFormattedTextField() {
          @Override
          public Dimension getPreferredSize() {
            // Enlarge preferred size of one pixel
            Dimension preferredSize = super.getPreferredSize();
            return new Dimension(preferredSize.width + 1, preferredSize.height);
          }
        };
      updateToolTipTextFieldFormatterFactory(textField, editableProperty, preferences);
      textField.setFont(toolTipFont);
      textField.setOpaque(false);
      textField.setBorder(null);
      if (controller != null) {
        // Add a listener to notify changes to controller
        textField.getDocument().addDocumentListener(new DocumentListener() {
            public void changedUpdate(DocumentEvent ev) {
              try {
                textField.commitEdit();
                controller.updateEditableProperty(editableProperty, textField.getValue());
              } catch (ParseException ex) {
                controller.updateEditableProperty(editableProperty, null);
              }
            }
   
View Full Code Here

    toolTipPropertiesPanel.setBackground(toolTip.getBackground());
    toolTipPropertiesPanel.setForeground(toolTip.getForeground());

    // Add labels and text fields to tool tip panel
    for (int i = 0; i < toolTipEditedProperties.length; i++) {
      JFormattedTextField textField = this.toolTipEditableTextFields.get(toolTipEditedProperties [i]);
      textField.setValue(toolTipPropertyValues [i]);
      JLabel label = new JLabel(this.preferences.getLocalizedString(PlanComponent.class,
          toolTipEditedProperties [i].name() + ".editablePropertyLabel.text") + " ");
      label.setFont(textField.getFont());
      JLabel unitLabel = null;
      if (toolTipEditedProperties [i] == PlanController.EditableProperty.ANGLE
          || toolTipEditedProperties [i] == PlanController.EditableProperty.ARC_EXTENT) {
        unitLabel = new JLabel(this.preferences.getLocalizedString(PlanComponent.class, "degreeLabel.text"));
      } else if (this.preferences.getLengthUnit() != LengthUnit.INCH) {
        unitLabel = new JLabel(" " + this.preferences.getLengthUnit().getName());
      }
     
      JPanel labelTextFieldPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
      labelTextFieldPanel.setOpaque(false);
     
      labelTextFieldPanel.add(label);
      labelTextFieldPanel.add(textField);
      if (unitLabel != null) {
        unitLabel.setFont(textField.getFont());
        labelTextFieldPanel.add(unitLabel);
      }
      toolTipPropertiesPanel.add(labelTextFieldPanel, new GridBagConstraints(
          0, i, 1, 1, 0, 0, GridBagConstraints.LINE_START, GridBagConstraints.NONE,
          new Insets(0, 0, 0, 0), 0, 0));
View Full Code Here

    this.latitudeLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences, CompassPanel.class, "latitudeLabel.text"));
    final SpinnerNumberModel latitudeSpinnerModel = new SpinnerNumberModel(new Float(0), new Float(-90), new Float(90), new Float(5));
    this.latitudeSpinner = new JSpinner(latitudeSpinnerModel);
    // Change positive / negative notation by North / South
    JFormattedTextField textField = ((DefaultEditor)this.latitudeSpinner.getEditor()).getTextField();
    NumberFormatter numberFormatter = (NumberFormatter)((DefaultFormatterFactory)textField.getFormatterFactory()).getDefaultFormatter();
    numberFormatter.setFormat(new DecimalFormat("N ##0.000;S ##0.000"));
    textField.setFormatterFactory(new DefaultFormatterFactory(numberFormatter));
    SwingTools.addAutoSelectionOnFocusGain(textField);
    latitudeSpinnerModel.setValue(controller.getLatitudeInDegrees());
    final PropertyChangeListener latitudeChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          latitudeSpinnerModel.setValue((Float)ev.getNewValue());
        }
      };
    controller.addPropertyChangeListener(CompassController.Property.LATITUDE_IN_DEGREES, latitudeChangeListener);
    latitudeSpinnerModel.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent ev) {
          controller.removePropertyChangeListener(CompassController.Property.LATITUDE_IN_DEGREES, latitudeChangeListener);
          controller.setLatitudeInDegrees(((Number)latitudeSpinnerModel.getValue()).floatValue());
          controller.addPropertyChangeListener(CompassController.Property.LATITUDE_IN_DEGREES, latitudeChangeListener);
        }
      });
   
    this.longitudeLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences, CompassPanel.class, "longitudeLabel.text"));
    final SpinnerNumberModel longitudeSpinnerModel = new SpinnerNumberModel(new Float(0), new Float(-180), new Float(180), new Float(5));
    this.longitudeSpinner = new JSpinner(longitudeSpinnerModel);
    // Change positive / negative notation by East / West
    textField = ((DefaultEditor)this.longitudeSpinner.getEditor()).getTextField();
    numberFormatter = (NumberFormatter)((DefaultFormatterFactory)textField.getFormatterFactory()).getDefaultFormatter();
    numberFormatter.setFormat(new DecimalFormat("E ##0.000;W ##0.000"));
    textField.setFormatterFactory(new DefaultFormatterFactory(numberFormatter));
    SwingTools.addAutoSelectionOnFocusGain(textField);
    longitudeSpinnerModel.setValue(controller.getLongitudeInDegrees());
    final PropertyChangeListener longitudeChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
          longitudeSpinnerModel.setValue((Float)ev.getNewValue());
View Full Code Here

  /**
   * Displays this panel in a modal dialog box.
   */
  public void displayView(View parentView) {
    JFormattedTextField northDirectionTextField =
        ((JSpinner.DefaultEditor)this.northDirectionSpinner.getEditor()).getTextField();
    if (SwingTools.showConfirmDialog((JComponent)parentView,
            this, this.dialogTitle, northDirectionTextField) == JOptionPane.OK_OPTION
        && this.controller != null) {
      this.controller.modifyCompass();
View Full Code Here

        this.wallOrientationLabel.setVisible(false);
      }
      dialog.dispose();
    }

    JFormattedTextField thicknessTextField =
        ((JSpinner.DefaultEditor)thicknessSpinner.getEditor()).getTextField();
    if (SwingTools.showConfirmDialog((JComponent)parentView,
            this, this.dialogTitle, thicknessTextField) == JOptionPane.OK_OPTION) {
      this.controller.modifyWalls();
    }
View Full Code Here

  /**
   * Displays this panel in a modal dialog box.
   */
  public void displayView(View parentView) {
    JFormattedTextField observerFieldOfViewSpinnerTextField =
        ((JSpinner.DefaultEditor)this.observerFieldOfViewSpinner.getEditor()).getTextField();
    if (SwingTools.showConfirmDialog((JComponent)parentView,
            this, this.dialogTitle, observerFieldOfViewSpinnerTextField) == JOptionPane.OK_OPTION
        && this.controller != null) {
      this.controller.modify3DAttributes();
View Full Code Here

TOP

Related Classes of javax.swing.JFormattedTextField$CancelAction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.