Search in sources :

Example 21 with NumberFormatter

use of javax.swing.text.NumberFormatter in project mzmine2 by mzmine.

the class IsotopePeakScannerSetupDialog method addDialogComponents.

@Override
protected void addDialogComponents() {
    super.addDialogComponents();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    pnlChart = new EChartPanel(chart);
    pnlChart.setPreferredSize(new Dimension((int) (screenSize.getWidth() / 3), (int) (screenSize.getHeight() / 3)));
    pnlPreview.add(pnlChart, BorderLayout.CENTER);
    // get components
    cmpAutoCarbon = (OptionalModuleComponent) this.getComponentForParameter(IsotopePeakScannerParameters.autoCarbonOpt);
    cmpAutoCarbonCbx = (JCheckBox) cmpAutoCarbon.getComponent(0);
    cmpPreview = (JCheckBox) this.getComponentForParameter(IsotopePeakScannerParameters.showPreview);
    // i want to have the checkbox below the pattern settings
    cmpPreview.setSelected(false);
    // but it should be disabled by default. Thats why it's hardcoded here.
    // get parameters
    pElement = parameterSet.getParameter(IsotopePeakScannerParameters.element);
    pMinIntensity = parameterSet.getParameter(IsotopePeakScannerParameters.minPatternIntensity);
    pCharge = parameterSet.getParameter(IsotopePeakScannerParameters.charge);
    pMergeWidth = parameterSet.getParameter(IsotopePeakScannerParameters.mergeWidth);
    pAutoCarbon = parameterSet.getParameter(IsotopePeakScannerParameters.autoCarbonOpt);
    autoCarbonParameters = pAutoCarbon.getEmbeddedParameters();
    pMinC = autoCarbonParameters.getParameter(AutoCarbonParameters.minCarbon);
    pMaxC = autoCarbonParameters.getParameter(AutoCarbonParameters.maxCarbon);
    pMinSize = autoCarbonParameters.getParameter(AutoCarbonParameters.minPatternSize);
    // set up gui
    form = new NumberFormatter(NumberFormat.getInstance());
    form.setValueClass(Integer.class);
    form.setFormat(new DecimalFormat("0"));
    form.setAllowsInvalid(true);
    form.setMinimum(minC);
    form.setMaximum(maxC);
    btnPrevPattern = new JButton("Previous");
    btnPrevPattern.addActionListener(this);
    btnPrevPattern.setMinimumSize(btnPrevPattern.getPreferredSize());
    btnPrevPattern.setEnabled(cmpAutoCarbonCbx.isSelected());
    txtCurrentPatternIndex = new JFormattedTextField(form);
    txtCurrentPatternIndex.addActionListener(this);
    txtCurrentPatternIndex.setText(String.valueOf((minC + maxC) / 2));
    txtCurrentPatternIndex.setPreferredSize(new Dimension(50, 25));
    txtCurrentPatternIndex.setEditable(true);
    txtCurrentPatternIndex.setEnabled(cmpAutoCarbonCbx.isSelected());
    btnNextPattern = new JButton("Next");
    btnNextPattern.addActionListener(this);
    btnNextPattern.setPreferredSize(btnNextPattern.getMinimumSize());
    btnNextPattern.setEnabled(cmpAutoCarbonCbx.isSelected());
    chart = ChartFactory.createXYBarChart("Isotope pattern preview", "m/z", false, "Abundance", new XYSeriesCollection(new XYSeries("")));
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.getXYPlot().setDomainGridlinePaint(Color.GRAY);
    chart.getXYPlot().setRangeGridlinePaint(Color.GRAY);
    pnlPreviewButtons.add(btnPrevPattern);
    pnlPreviewButtons.add(txtCurrentPatternIndex);
    pnlPreviewButtons.add(btnNextPattern);
    pack();
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) EChartPanel(net.sf.mzmine.chartbasics.gui.swing.EChartPanel) DecimalFormat(java.text.DecimalFormat) JButton(javax.swing.JButton) JFormattedTextField(javax.swing.JFormattedTextField) Dimension(java.awt.Dimension) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) NumberFormatter(javax.swing.text.NumberFormatter)

Example 22 with NumberFormatter

use of javax.swing.text.NumberFormatter in project pcgen by PCGen.

the class Utils method buildIntegerField.

/**
	 * <p>Builds a formatted text field with specified min and max</p>
	 * 
	 * @param min minimum value
	 * @param max maximum value
	 * @return JFormattedTextField
	 */
public static JFormattedTextField buildIntegerField(int min, int max) {
    java.text.NumberFormat numberFormat = java.text.NumberFormat.getIntegerInstance();
    NumberFormatter formatter = new NumberFormatter(numberFormat);
    formatter.setMinimum(min);
    formatter.setMaximum(max);
    final JFormattedTextField returnValue = new JFormattedTextField(formatter);
    returnValue.setColumns(3);
    returnValue.addPropertyChangeListener(new PropertyChangeListener() {

        Border m_originalBorder = returnValue.getBorder();

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName() != null && evt.getPropertyName().equals("editValid")) {
                if (evt.getNewValue() != null && evt.getNewValue() instanceof Boolean) {
                    if (((Boolean) evt.getNewValue()).booleanValue()) {
                        returnValue.setBorder(m_originalBorder);
                    } else {
                        returnValue.setBorder(BorderFactory.createLineBorder(Color.red));
                    }
                }
            }
        }
    });
    return returnValue;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) JFormattedTextField(javax.swing.JFormattedTextField) Border(javax.swing.border.Border) NumberFormatter(javax.swing.text.NumberFormatter)

Example 23 with NumberFormatter

use of javax.swing.text.NumberFormatter in project pcgen by PCGen.

the class CheckDialog method initDC.

/**
	 * <p>
	 * Initializes the DC value
	 * </p>
	 *
	 */
private void initDC() {
    NumberFormatter formatter = new NumberFormatter(new DecimalFormat("##"));
    formatter.setValueClass(Integer.class);
    m_dc = new JFormattedTextField(formatter);
    m_dc.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT);
    m_dc.setValue(m_defaultDC);
    JLabel label = new JLabel("DC:");
    label.setAlignmentX(Component.RIGHT_ALIGNMENT);
    addComponent(m_dc, label);
}
Also used : DecimalFormat(java.text.DecimalFormat) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) NumberFormatter(javax.swing.text.NumberFormatter)

Example 24 with NumberFormatter

use of javax.swing.text.NumberFormatter in project BoofCV by lessthanoptimal.

the class BoofSwingUtil method createTextField.

public static JFormattedTextField createTextField(double current, double min, double max) {
    NumberFormat format = NumberFormat.getInstance();
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setValueClass(Double.class);
    if (!Double.isNaN(min))
        formatter.setMinimum(min);
    if (!Double.isNaN(max))
        formatter.setMaximum(max);
    formatter.setAllowsInvalid(true);
    // formatter.setCommitsOnValidEdit(true);
    JFormattedTextField field = new JFormattedTextField(formatter);
    field.setHorizontalAlignment(JTextField.RIGHT);
    field.setValue(current);
    return field;
}
Also used : NumberFormat(java.text.NumberFormat) NumberFormatter(javax.swing.text.NumberFormatter)

Example 25 with NumberFormatter

use of javax.swing.text.NumberFormatter in project mzmine2 by mzmine.

the class ScatterPlotBottomPanel method actionPerformed.

public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    if (command.equals("DATA_CHANGE")) {
        ScatterPlotAxisSelection optionX = (ScatterPlotAxisSelection) comboX.getSelectedItem();
        ScatterPlotAxisSelection optionY = (ScatterPlotAxisSelection) comboY.getSelectedItem();
        if ((optionX == null) || (optionY == null))
            return;
        String foldText = foldXvalues[comboFold.getSelectedIndex()];
        int foldValue = Integer.parseInt(foldText);
        if (foldValue <= 0)
            foldValue = 2;
        chart.setDisplayedAxes(optionX, optionY, foldValue);
        return;
    }
    if (command.equals("LABEL_ITEMS")) {
        chart.setItemLabels(labeledItems.isSelected());
    }
    if (command.equals("SEARCH")) {
        SearchDefinitionType searchType = (SearchDefinitionType) comboSearchDataType.getSelectedItem();
        String searchRegex = txtSearchField.getText();
        Number minValue = ((Number) minSearchField.getValue());
        if (minValue == null)
            minValue = 0;
        Number maxValue = ((Number) maxSearchField.getValue());
        if (maxValue == null)
            maxValue = 0;
        Range<Double> searchRange = Range.closed(minValue.doubleValue(), maxValue.doubleValue());
        try {
            SearchDefinition newSearch = new SearchDefinition(searchType, searchRegex, searchRange);
            chart.updateSearchDefinition(newSearch);
        } catch (PatternSyntaxException pe) {
            MZmineCore.getDesktop().displayErrorMessage(window, "The regular expression's syntax is invalid: " + pe);
        }
        return;
    }
    if (command.equals("SEARCH_DATA_TYPE")) {
        SearchDefinitionType searchType = (SearchDefinitionType) comboSearchDataType.getSelectedItem();
        switch(searchType) {
            case MASS:
                minSearchField.setVisible(true);
                maxSearchField.setVisible(true);
                labelRange.setVisible(true);
                txtSearchField.setVisible(false);
                NumberFormat mzFormatter = MZmineCore.getConfiguration().getMZFormat();
                Range<Double> mzRange = peakList.getRowsMZRange();
                DefaultFormatterFactory mzFormatFac = new DefaultFormatterFactory(new NumberFormatter(mzFormatter));
                minSearchField.setFormatterFactory(mzFormatFac);
                minSearchField.setValue(mzRange.lowerEndpoint());
                maxSearchField.setFormatterFactory(mzFormatFac);
                maxSearchField.setValue(mzRange.upperEndpoint());
                break;
            case RT:
                minSearchField.setVisible(true);
                maxSearchField.setVisible(true);
                labelRange.setVisible(true);
                txtSearchField.setVisible(false);
                NumberFormat rtFormatter = MZmineCore.getConfiguration().getRTFormat();
                Range<Double> rtRange = peakList.getRowsRTRange();
                DefaultFormatterFactory rtFormatFac = new DefaultFormatterFactory(new NumberFormatter(rtFormatter));
                minSearchField.setFormatterFactory(rtFormatFac);
                minSearchField.setValue(rtRange.lowerEndpoint());
                maxSearchField.setFormatterFactory(rtFormatFac);
                maxSearchField.setValue(rtRange.upperEndpoint());
                break;
            case NAME:
                minSearchField.setVisible(false);
                maxSearchField.setVisible(false);
                labelRange.setVisible(false);
                txtSearchField.setVisible(true);
                break;
        }
        return;
    }
}
Also used : SearchDefinitionType(net.sf.mzmine.util.SearchDefinitionType) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) SearchDefinition(net.sf.mzmine.util.SearchDefinition) PatternSyntaxException(java.util.regex.PatternSyntaxException) NumberFormat(java.text.NumberFormat) 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