Search in sources :

Example 16 with NumberFormatter

use of javax.swing.text.NumberFormatter in project chordatlas by twak.

the class AlignTool method getUI.

@Override
public void getUI(JPanel p) {
    p.setLayout(new ListDownLayout());
    JButton w = new JButton("save alignment");
    w.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            toAlign.save();
        }
    });
    JButton swap = new JButton("swap");
    swap.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Vector3f tmp = alignMarkers[0];
            alignMarkers[0] = alignMarkers[1];
            alignMarkers[1] = tmp;
            tweed.enqueue(new Runnable() {

                @Override
                public void run() {
                    doAlign();
                }
            });
        }
    });
    JFormattedTextField tf = new JFormattedTextField(new NumberFormatter());
    tf.setValue(vOffset);
    tf.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            vOffset = ((Number) tf.getValue()).doubleValue();
            doAlign();
        }
    });
    p.add(w);
    p.add(swap);
    p.add(new JLabel("height offset:"));
    p.add(tf);
}
Also used : ListDownLayout(org.twak.utils.ui.ListDownLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Vector3f(com.jme3.math.Vector3f) JButton(javax.swing.JButton) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) NumberFormatter(javax.swing.text.NumberFormatter)

Example 17 with NumberFormatter

use of javax.swing.text.NumberFormatter in project java-swing-tips by aterai.

the class MainPanel method makeFFactory.

private static DefaultFormatterFactory makeFFactory(DecimalFormatSymbols dfs) {
    DecimalFormat format = new DecimalFormat("0.00", dfs);
    NumberFormatter displayFormatter = new NumberFormatter(format);
    displayFormatter.setValueClass(Double.class);
    NumberFormatter editFormatter = new NumberFormatter(format);
    editFormatter.setValueClass(Double.class);
    return new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter);
}
Also used : DecimalFormat(java.text.DecimalFormat) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) NumberFormatter(javax.swing.text.NumberFormatter)

Example 18 with NumberFormatter

use of javax.swing.text.NumberFormatter in project java-swing-tips by aterai.

the class WarningSpinner method makeFFactory.

private static DefaultFormatterFactory makeFFactory(SpinnerNumberModel m) {
    // , dfs);
    NumberFormat format = new DecimalFormat("####0");
    NumberFormatter editFormatter = new NumberFormatter(format) {

        // @Override protected DocumentFilter getDocumentFilter() {
        // return new IntegerDocumentFilter();
        // }
        @Override
        public Object stringToValue(String text) throws ParseException {
            try {
                Long.parseLong(text);
            } catch (NumberFormatException ex) {
                throw (ParseException) new ParseException(ex.getMessage(), 0).initCause(ex);
            }
            Object o = format.parse(text);
            if (o instanceof Long) {
                Long val = (Long) format.parse(text);
                Long max = (Long) m.getMaximum();
                Long min = (Long) m.getMinimum();
                if (max.compareTo(val) < 0 || min.compareTo(val) > 0) {
                    throw new ParseException("out of bounds", 0);
                }
                return val;
            }
            throw new ParseException("not Long", 0);
        }
    };
    // editFormatter.setAllowsInvalid(false);
    // editFormatter.setCommitsOnValidEdit(true);
    editFormatter.setValueClass(Long.class);
    NumberFormatter displayFormatter = new NumberFormatter(format);
    return new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter);
}
Also used : DecimalFormat(java.text.DecimalFormat) ParseException(java.text.ParseException) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) NumberFormat(java.text.NumberFormat) NumberFormatter(javax.swing.text.NumberFormatter)

Example 19 with NumberFormatter

use of javax.swing.text.NumberFormatter in project scylla by bptlab.

the class NumberField method getFormatter.

/**
 * @return The formatter that is used for my component.
 * Can be overridden to change/add properties.
 */
protected NumberFormatter getFormatter() {
    formatter = new NumberFormatter(getFormat());
    formatter.setValueClass(getDataTypeClass());
    return formatter;
}
Also used : NumberFormatter(javax.swing.text.NumberFormatter)

Example 20 with NumberFormatter

use of javax.swing.text.NumberFormatter in project vcell by virtualcell.

the class MovingBoundarySolverOptionsPanel method getFrontTrackingPanel.

private JPanel getFrontTrackingPanel() {
    JPanel panel = new JPanel(new GridBagLayout());
    panel.setBorder(BorderFactory.createTitledBorder(GuiConstants.TAB_PANEL_BORDER, "Front Tracking"));
    int gridy = 0;
    GridBagConstraints gbc = new java.awt.GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new java.awt.Insets(4, 4, 4, 4);
    gbc.anchor = GridBagConstraints.LINE_END;
    panel.add(new JLabel("Front To Volume Nodes Ratio"), gbc);
    textFieldFrontToNodeRatio = new JFormattedTextField(DecimalFormat.getInstance());
    gbc = new java.awt.GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.insets = new java.awt.Insets(4, 4, 4, 4);
    panel.add(textFieldFrontToNodeRatio, gbc);
    ++gridy;
    gbc = new java.awt.GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new java.awt.Insets(4, 4, 4, 4);
    gbc.anchor = GridBagConstraints.LINE_END;
    panel.add(new JLabel("Front Redistribution Method"), gbc);
    gbc = new java.awt.GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.insets = new java.awt.Insets(4, 4, 4, 4);
    panel.add(comboBoxRedistMode, gbc);
    ++gridy;
    gbc = new java.awt.GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new java.awt.Insets(4, 4, 4, 4);
    gbc.anchor = GridBagConstraints.LINE_END;
    panel.add(new JLabel("Full Redistribution Mode"), gbc);
    gbc = new java.awt.GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.insets = new java.awt.Insets(4, 4, 4, 4);
    panel.add(comboBoxRedistVersion, gbc);
    ++gridy;
    gbc = new java.awt.GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new java.awt.Insets(4, 4, 4, 4);
    gbc.anchor = GridBagConstraints.LINE_END;
    panel.add(new JLabel("Redistribution Frequency"), gbc);
    NumberFormatter integerFormatter = new NumberFormatter(NumberFormat.getInstance());
    integerFormatter.setValueClass(Integer.class);
    integerFormatter.setMinimum(1);
    integerFormatter.setMaximum(Integer.MAX_VALUE);
    textFieldRedistributionFrequency = new JFormattedTextField(integerFormatter);
    gbc = new java.awt.GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.insets = new java.awt.Insets(4, 4, 4, 4);
    textFieldRedistributionFrequency.setToolTipText("integer only");
    panel.add(textFieldRedistributionFrequency, gbc);
    comboBoxRedistMode.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            // TODO Auto-generated method stub
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (c instanceof JLabel) {
                JLabel lbl = (JLabel) c;
                lbl.setText(((RedistributionMode) value).getLabel());
            }
            return c;
        }
    });
    comboBoxRedistVersion.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            // TODO Auto-generated method stub
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (c instanceof JLabel) {
                JLabel lbl = (JLabel) c;
                lbl.setText(((RedistributionVersion) value).getLabel());
            }
            return c;
        }
    });
    comboBoxExtrapolationMethod.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            // TODO Auto-generated method stub
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (c instanceof JLabel) {
                JLabel lbl = (JLabel) c;
                lbl.setText(((ExtrapolationMethod) value).getLabel());
            }
            return c;
        }
    });
    return panel;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) RedistributionMode(cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionMode) GridBagLayout(java.awt.GridBagLayout) RedistributionVersion(cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) GridBagConstraints(java.awt.GridBagConstraints) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) ExtrapolationMethod(cbit.vcell.solvers.mb.MovingBoundarySolverOptions.ExtrapolationMethod) Component(java.awt.Component) NumberFormatter(javax.swing.text.NumberFormatter)

Aggregations

NumberFormatter (javax.swing.text.NumberFormatter)26 JFormattedTextField (javax.swing.JFormattedTextField)10 NumberFormat (java.text.NumberFormat)9 DefaultFormatterFactory (javax.swing.text.DefaultFormatterFactory)9 DecimalFormat (java.text.DecimalFormat)8 JLabel (javax.swing.JLabel)4 ParseException (java.text.ParseException)3 JButton (javax.swing.JButton)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 JPanel (javax.swing.JPanel)2 Border (javax.swing.border.Border)2 ExtrapolationMethod (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.ExtrapolationMethod)1 RedistributionMode (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionMode)1 RedistributionVersion (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 ColoredListCellRenderer (com.intellij.ui.ColoredListCellRenderer)1 DocumentAdapter (com.intellij.ui.DocumentAdapter)1