Java Code Examples for javax.swing.text.NumberFormatter#setAllowsInvalid()

The following examples show how to use javax.swing.text.NumberFormatter#setAllowsInvalid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentsFactory.java    From MercuryTrade with MIT License 6 votes vote down vote up
public JFormattedTextField getIntegerTextField(Integer min, Integer max, Integer value) {
    NumberFormat format = NumberFormat.getInstance();
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setValueClass(Integer.class);
    formatter.setMinimum(min);
    formatter.setMaximum(max);
    formatter.setAllowsInvalid(true);
    formatter.setCommitsOnValidEdit(false);

    JFormattedTextField field = new JFormattedTextField(formatter);
    field.setValue(value);
    field.setFont(REGULAR_FONT.deriveFont(scale * 18));
    field.setFocusLostBehavior(JFormattedTextField.PERSIST);
    field.setForeground(AppThemeColor.TEXT_DEFAULT);
    field.setCaretColor(AppThemeColor.TEXT_DEFAULT);
    field.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(AppThemeColor.BORDER, 1),
            BorderFactory.createLineBorder(AppThemeColor.TRANSPARENT, 3)
    ));
    field.setBackground(AppThemeColor.HEADER);
    return field;
}
 
Example 2
Source File: ClassDialogue.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public static JFormattedTextField createNumberField(Class<?> type, Object minValue, Object maxValue) {
  NumberFormat format = NumberFormat.getInstance();
  format.setGroupingUsed(false);
  format.setMaximumFractionDigits(10);
  NumberFormatter formatter = new NumberFormatter(format);
  formatter.setValueClass(type);
  formatter.setMinimum((Comparable) minValue);
  formatter.setMaximum((Comparable) maxValue);
  formatter.setAllowsInvalid(false);
  formatter.setCommitsOnValidEdit(true);
  formatter.setOverwriteMode(true);
  JFormattedTextField jftf = new JFormattedTextField(formatter);
  return jftf;
}
 
Example 3
Source File: MuleRemoteDebuggerConfPanel.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
    NumberFormat format = NumberFormat.getInstance();
    format.setGroupingUsed(false);
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setValueClass(Integer.class);
    formatter.setMaximum(65535);
    formatter.setAllowsInvalid(false);
    formatter.setCommitsOnValidEdit(true);
    portTextField = new JFormattedTextField(formatter);
    jvmPortTextField = new JFormattedTextField(formatter);

    appsMap = new JBTable(new ModulesTableModel());

}
 
Example 4
Source File: TileQuantityPanel.java    From Carcassonne with Eclipse Public License 2.0 5 votes vote down vote up
private void createTextField(int initialQuantity) {
    NumberFormatter formatter = new NumberFormatter(NumberFormat.getIntegerInstance());
    formatter.setMinimum(0);
    formatter.setMaximum(99);
    formatter.setAllowsInvalid(false);
    formatter.setCommitsOnValidEdit(true);
    textField = new JFormattedTextField(formatter);
    setQuantity(initialQuantity);
    add(textField, BorderLayout.SOUTH);
}
 
Example 5
Source File: AddBookView.java    From protobuf-converter with MIT License 5 votes vote down vote up
public AddBookView(final JFrame windowFrame) {
	form = new JPanel();
	form.setLayout(null);
	form.setBounds(0, 210, 250, 250);

	titleLable = new JLabel("Title");
	titleLable.setBounds(10, 10, 80, 25);
	form.add(titleLable);

	titleText = new JTextField(20);
	titleText.setBounds(80, 10, 160, 25);
	form.add(titleText);

	authorLabel = new JLabel("Author");
	authorLabel.setBounds(10, 40, 80, 25);
	form.add(authorLabel);
	authorText = new JTextField(20);
	authorText.setBounds(80, 40, 160, 25);
	form.add(authorText);

	pageLabel = new JLabel("Pages");
	pageLabel.setBounds(10, 70, 80, 25);
	form.add(pageLabel);
	NumberFormatter numberFormatter = new NumberFormatter(NumberFormat.getIntegerInstance());
	numberFormatter.setValueClass(Integer.class);
	numberFormatter.setAllowsInvalid(false);
	numberFormatter.setMinimum(1);
	pageText = new JFormattedTextField(numberFormatter);
	pageText.setBounds(80, 70, 160, 25);
	form.add(pageText);

	addButton = new JButton("Add");
	addButton.setBounds(160, 100, 80, 25);
	form.add(addButton);
	addButton.addActionListener(this);

	windowFrame.add(form);
}
 
Example 6
Source File: PreferencesDialog.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
private NumberFormatter getPortValueFormatter() {
    NumberFormat plainIntegerFormat = NumberFormat.getInstance();
    plainIntegerFormat.setGroupingUsed(false);                      // no commas

    NumberFormatter portFormatter = new NumberFormatter(plainIntegerFormat);
    portFormatter.setValueClass(Integer.class);
    portFormatter.setAllowsInvalid(false);
    portFormatter.setMinimum(0);
    portFormatter.setMaximum(65535);
    return portFormatter;
}
 
Example 7
Source File: Config.java    From BeanStack with Apache License 2.0 4 votes vote down vote up
public Config() {
      settings = new LinkedHashMap<>();
      // These put()s determine the order shown on the settings screen
// Note that the default values are documented on the website, so update accordingly
      put("enable", true);
      put("apikey", "none");
      put("classblacklist", "");
put("hashtrace", true);
put("issuepercve", false);
      put("debug", false);
      put("logdups", false);
      put("issuetitle", "Stack Trace Fingerprint Found");
      put("apiurl", "https://beanstack.io/api/");

      // NOTE: when editing these names, also update the documentation!
      readableNames = new LinkedHashMap<>();
      readableNames.put("enable", "Enable Lookups");
      readableNames.put("apiurl", "API URL");
      readableNames.put("issuetitle", "Issue Title");
      readableNames.put("debug", "Print Debug Messages to Stdout");
      readableNames.put("logdups", "Log Duplicates");
      readableNames.put("apikey", "API Key");
      readableNames.put("classblacklist", "Blacklisted Class Prefixes");
readableNames.put("issuepercve", "Create an issue for each CVE*");
      readableNames.put("hashtrace", "Hash traces before submission*");

      for (String key: settings.keySet()) {
          //callbacks.saveExtensionSetting(key, null); // purge saved settings
          String value = GlobalVars.callbacks.loadExtensionSetting(key);
          if (GlobalVars.callbacks.loadExtensionSetting(key) != null) {
              putRaw(key, value);
          }
      }

      NumberFormat format = NumberFormat.getInstance();
      onlyInt = new NumberFormatter(format);
      onlyInt.setValueClass(Integer.class);
      onlyInt.setMinimum(-1);
      onlyInt.setMaximum(Integer.MAX_VALUE);
      onlyInt.setAllowsInvalid(false);
  }
 
Example 8
Source File: MessageSamplerGui.java    From BotServiceStressToolkit with MIT License 4 votes vote down vote up
private void init() { // WARNING: called from ctor so must not be overridden
						// (i.e. must be private or final)
	// Standard setup
	setLayout(new BorderLayout(0, 5));
	setBorder(makeBorder());
	add(makeTitlePanel(), BorderLayout.NORTH); // Add the standard title

	JPanel mainPanel = new JPanel();
	add(mainPanel, BorderLayout.CENTER);

	numOfResponsesExpectedLabel = new javax.swing.JLabel(NUMBER_OF_RESPONSES_EXPECTED_LABEL);

	messageTextTextArea.setColumns(20);
	messageTextTextArea.setRows(5);
	messageTextAreaScrollPane.setViewportView(messageTextTextArea);

	NumberFormat format = new DecimalFormat("#0");
	NumberFormatter formatter = new NumberFormatter(format);
	formatter.setValueClass(Integer.class);
	formatter.setMinimum(0);
	formatter.setMaximum(MAX_RESPONSES_ALLOWED);
	formatter.setAllowsInvalid(false);
	formatter.setCommitsOnValidEdit(true);

	numOfResponsesExpectedTextField = new javax.swing.JFormattedTextField(formatter);
	numOfResponsesExpectedLabel.setText(NUMBER_OF_RESPONSES_EXPECTED_LABEL);
	messageTextLabel.setText(MESSAGE_TEXT_LABEL);
	messageTextFormatLabel.setText(MESSAGE_TEXT_FORMAT_LABEL);
	localeLabel.setText(LOCALE_LABEL);

	javax.swing.GroupLayout layout = new javax.swing.GroupLayout(mainPanel);
	mainPanel.setLayout(layout);

	layout.setHorizontalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
					.createSequentialGroup().addGroup(layout
							.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
									.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
									.addComponent(messageTextLabel, javax.swing.GroupLayout.Alignment.LEADING,
											javax.swing.GroupLayout.DEFAULT_SIZE,
											javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(messageTextFormatLabel, javax.swing.GroupLayout.Alignment.LEADING,
											javax.swing.GroupLayout.DEFAULT_SIZE,
											javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(localeLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
											javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
							.addComponent(numOfResponsesExpectedLabel))
					.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
							.addComponent(localeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 244,
									javax.swing.GroupLayout.PREFERRED_SIZE)
							.addComponent(numOfResponsesExpectedTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
									244, javax.swing.GroupLayout.PREFERRED_SIZE)
							.addComponent(messageTextFormatTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 244,
									javax.swing.GroupLayout.PREFERRED_SIZE)
							.addComponent(messageTextAreaScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 585,
									javax.swing.GroupLayout.PREFERRED_SIZE))
					.addGap(0, 469, Short.MAX_VALUE)));
	layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
			.createSequentialGroup().addContainerGap()
			.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addComponent(messageTextAreaScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE,
							javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addGroup(layout.createSequentialGroup().addGap(30, 30, 30).addComponent(messageTextLabel)))
			.addGap(10, 10, 10)
			.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(messageTextFormatLabel).addComponent(messageTextFormatTextField,
							javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
							javax.swing.GroupLayout.PREFERRED_SIZE))
			.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
			.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(localeLabel).addComponent(localeTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
							javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
			.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
			.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(numOfResponsesExpectedLabel).addComponent(numOfResponsesExpectedTextField,
							javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
							javax.swing.GroupLayout.PREFERRED_SIZE))
			.addContainerGap(540, Short.MAX_VALUE)));
}
 
Example 9
Source File: ConversationUpdateSamplerGui.java    From BotServiceStressToolkit with MIT License 4 votes vote down vote up
private void init() { // WARNING: called from ctor so must not be overridden
						// (i.e. must be private or final)
	// Standard setup
	setLayout(new BorderLayout(0, 5));
	setBorder(makeBorder());
	add(makeTitlePanel(), BorderLayout.NORTH); // Add the standard title

	JPanel mainPanel = new JPanel();
	add(mainPanel, BorderLayout.CENTER);

	numOfResponsesExpectedLabel = new javax.swing.JLabel();
	membersAddedLabel = new javax.swing.JLabel();

	NumberFormat format = new DecimalFormat("#0");
	NumberFormatter formatter = new NumberFormatter(format);
	formatter.setValueClass(Integer.class);
	formatter.setMinimum(0);
	formatter.setMaximum(MAX_RESPONSES_ALLOWED);
	formatter.setAllowsInvalid(false);
	formatter.setCommitsOnValidEdit(true);

	numOfResponsesExpectedTextField = new javax.swing.JFormattedTextField(formatter);
	membersAddedTextField = new javax.swing.JTextField();

	numOfResponsesExpectedLabel.setText(NUMBER_OF_RESPONSES_EXPECTED_LABEL);
	membersAddedLabel.setText(MEMBERS_ADDED_LABEL);

	javax.swing.GroupLayout layout = new javax.swing.GroupLayout(mainPanel);
	mainPanel.setLayout(layout);
	layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGroup(layout
					.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
							.addGroup(layout.createSequentialGroup().addComponent(numOfResponsesExpectedLabel)
									.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
											javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(numOfResponsesExpectedTextField,
											javax.swing.GroupLayout.PREFERRED_SIZE, 327,
											javax.swing.GroupLayout.PREFERRED_SIZE))
							.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
									layout.createSequentialGroup().addComponent(membersAddedLabel)
											.addGap(42, 42, 42).addComponent(membersAddedTextField,
													javax.swing.GroupLayout.PREFERRED_SIZE, 327,
													javax.swing.GroupLayout.PREFERRED_SIZE))))
					.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
	layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup().addGap(32, 32, 32)
					.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
							.addComponent(numOfResponsesExpectedLabel).addComponent(numOfResponsesExpectedTextField,
									javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
									javax.swing.GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
							.addComponent(membersAddedLabel).addComponent(membersAddedTextField,
									javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
									javax.swing.GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)));
}
 
Example 10
Source File: EventSamplerGui.java    From BotServiceStressToolkit with MIT License 4 votes vote down vote up
private void init() {
	// Standard setup
	setLayout(new BorderLayout(0, 5));
	setBorder(makeBorder());
	add(makeTitlePanel(), BorderLayout.NORTH); // Add the standard title

	JPanel mainPanel = new JPanel();
	add(mainPanel, BorderLayout.CENTER);

	numOfResponsesExpectedLabel = new javax.swing.JLabel(NUMBER_OF_RESPONSES_EXPECTED_LABEL);
	
	channeldataTextArea.setColumns(20);
	channeldataTextArea.setRows(5);
	channeldataAreaScrollPane.setViewportView(channeldataTextArea);
	
	NumberFormat format = new DecimalFormat("#0");
	NumberFormatter formatter = new NumberFormatter(format);
	formatter.setValueClass(Integer.class);
	formatter.setMinimum(0);
	formatter.setMaximum(MAX_RESPONSES_ALLOWED);
	formatter.setAllowsInvalid(false);
	formatter.setCommitsOnValidEdit(true);

	numOfResponsesExpectedTextField = new javax.swing.JFormattedTextField(formatter);
	numOfResponsesExpectedLabel.setText(NUMBER_OF_RESPONSES_EXPECTED_LABEL);
	channeldataLabel.setText(CHANNELDATA_LABEL);
	eventNameLabel.setText(EVENT_NAME_LABEL);
	
	javax.swing.GroupLayout layout = new javax.swing.GroupLayout(mainPanel);
	mainPanel.setLayout(layout);

	layout.setHorizontalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
					.createSequentialGroup().addGroup(layout
							.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
									.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
									.addComponent(channeldataLabel, javax.swing.GroupLayout.Alignment.LEADING,
											javax.swing.GroupLayout.DEFAULT_SIZE,
											javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(eventNameLabel, javax.swing.GroupLayout.Alignment.LEADING,
											javax.swing.GroupLayout.DEFAULT_SIZE,
											javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
							.addComponent(numOfResponsesExpectedLabel))
					.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
							.addComponent(eventNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 244,
									javax.swing.GroupLayout.PREFERRED_SIZE)
							.addComponent(numOfResponsesExpectedTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
									244, javax.swing.GroupLayout.PREFERRED_SIZE)
							.addComponent(channeldataAreaScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 585,
									javax.swing.GroupLayout.PREFERRED_SIZE))
					.addGap(0, 469, Short.MAX_VALUE)));
	layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
			.createSequentialGroup().addContainerGap()
			.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addComponent(channeldataAreaScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE,
							javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addGroup(layout.createSequentialGroup().addGap(30, 30, 30).addComponent(channeldataLabel)))
			.addGap(10, 10, 10)
			.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(eventNameLabel).addComponent(eventNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
							javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
			.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
			.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(numOfResponsesExpectedLabel).addComponent(numOfResponsesExpectedTextField,
							javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
							javax.swing.GroupLayout.PREFERRED_SIZE))
			.addContainerGap(540, Short.MAX_VALUE)));
}
 
Example 11
Source File: ConversionPanel.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
ConversionPanel(Converter myController, String myTitle, Unit[] myUnits, ConverterRangeModel myModel) {
    if (MULTICOLORED) {
        setOpaque(true);
        setBackground(new Color(0, 255, 255));
    }
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(myTitle),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // Save arguments in instance variables.
    controller = myController;
    units = myUnits;
    title = myTitle;
    sliderModel = myModel;

    // Create the text field format, and then the text field.
    numberFormat = NumberFormat.getNumberInstance();
    numberFormat.setMaximumFractionDigits(2);
    NumberFormatter formatter = new NumberFormatter(numberFormat);
    formatter.setAllowsInvalid(false);
    formatter.setCommitsOnValidEdit(true);// seems to be a no-op --
    // aha -- it changes the value property but doesn't cause the result to
    // be parsed (that happens on focus loss/return, I think).
    //
    textField = new JFormattedTextField(formatter);
    textField.setColumns(10);
    textField.setValue(new Double(sliderModel.getDoubleValue()));
    textField.addPropertyChangeListener(this);

    // Add the combo box.
    unitChooser = new JComboBox();
    for (int i = 0; i < units.length; i++) { // Populate it.
        unitChooser.addItem(units[i].description);
    }
    unitChooser.setSelectedIndex(0);
    sliderModel.setMultiplier(units[0].multiplier);
    unitChooser.addActionListener(this);

    // Add the slider.
    slider = new JSlider(sliderModel);
    sliderModel.addChangeListener(this);

    // Make the text field/slider group a fixed size
    // to make stacked ConversionPanels nicely aligned.
    JPanel unitGroup = new JPanel() {
        public Dimension getMinimumSize() {
            return getPreferredSize();
        }

        public Dimension getPreferredSize() {
            return new Dimension(150, super.getPreferredSize().height);
        }

        public Dimension getMaximumSize() {
            return getPreferredSize();
        }
    };
    unitGroup.setLayout(new BoxLayout(unitGroup, BoxLayout.PAGE_AXIS));
    if (MULTICOLORED) {
        unitGroup.setOpaque(true);
        unitGroup.setBackground(new Color(0, 0, 255));
    }
    unitGroup.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
    unitGroup.add(textField);
    unitGroup.add(slider);

    // Create a subpanel so the combo box isn't too tall
    // and is sufficiently wide.
    JPanel chooserPanel = new JPanel();
    chooserPanel.setLayout(new BoxLayout(chooserPanel, BoxLayout.PAGE_AXIS));
    if (MULTICOLORED) {
        chooserPanel.setOpaque(true);
        chooserPanel.setBackground(new Color(255, 0, 255));
    }
    chooserPanel.add(unitChooser);
    chooserPanel.add(Box.createHorizontalStrut(100));

    // Put everything together.
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
    add(unitGroup);
    add(chooserPanel);
    unitGroup.setAlignmentY(TOP_ALIGNMENT);
    chooserPanel.setAlignmentY(TOP_ALIGNMENT);
}
 
Example 12
Source File: IsotopePeakScannerSetupDialog.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
@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);
  cmpPreview.setSelected(false); // i want to have the checkbox below the pattern settings
  // 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();
}