Java Code Examples for javax.swing.JFormattedTextField#addPropertyChangeListener()

The following examples show how to use javax.swing.JFormattedTextField#addPropertyChangeListener() . 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: NewGameDialog.java    From lizzie with GNU General Public License v3.0 5 votes vote down vote up
private void initContentPanel() {
  GridLayout gridLayout = new GridLayout(5, 2, 4, 4);
  contentPanel.setLayout(gridLayout);

  checkBoxPlayerIsBlack =
      new JCheckBox(resourceBundle.getString("NewGameDialog.PlayBlack"), true);
  checkBoxPlayerIsBlack.addChangeListener(evt -> togglePlayerIsBlack());
  textFieldWhite = new JTextField();
  textFieldBlack = new JTextField();
  textFieldKomi = new JFormattedTextField(FORMAT_KOMI);
  textFieldHandicap = new JFormattedTextField(FORMAT_HANDICAP);
  textFieldHandicap.setEnabled(false);
  textFieldHandicap.addPropertyChangeListener(evt -> modifyHandicap());

  contentPanel.add(checkBoxPlayerIsBlack);

  chkNewGame = new JCheckBox(resourceBundle.getString("NewGameDialog.NewGame"), false);
  chkNewGame.addChangeListener(evt -> toggleNewGame());
  contentPanel.add(chkNewGame);
  contentPanel.add(new JLabel(resourceBundle.getString("NewGameDialog.Black")));
  contentPanel.add(textFieldBlack);
  contentPanel.add(new JLabel(resourceBundle.getString("NewGameDialog.White")));
  contentPanel.add(textFieldWhite);
  contentPanel.add(new JLabel(resourceBundle.getString("NewGameDialog.Komi")));
  contentPanel.add(textFieldKomi);
  contentPanel.add(new JLabel(resourceBundle.getString("NewGameDialog.Handicap")));
  contentPanel.add(textFieldHandicap);

  textFieldKomi.setEnabled(true);

  dialogPane.add(contentPanel, BorderLayout.CENTER);
}
 
Example 2
Source File: EditSettingsControlPanel.java    From VanetSim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the panel which is shown when beacon sending is enabled.
 * 
 * @return the beacon panel
 */
private final JPanel createBeaconPanel(){
	JPanel panel = new JPanel();
	panel.setOpaque(false);
	panel.setLayout(new GridBagLayout());
	
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.BOTH;
	c.anchor = GridBagConstraints.PAGE_START;
	c.weightx = 1;
	c.gridx = 0;
	c.gridy = 0;
	c.gridheight = 1;
	c.insets = new Insets(5,0,5,0);
	
	JLabel jLabel1 = new JLabel(Messages.getString("EditSettingsControlPanel.beaconInterval")); //$NON-NLS-1$
	panel.add(jLabel1,c);		
	beaconInterval_ = new JFormattedTextField(NumberFormat.getIntegerInstance());
	beaconInterval_.setPreferredSize(new Dimension(60,20));
	beaconInterval_.setValue(240);
	beaconInterval_.addPropertyChangeListener("value", this); //$NON-NLS-1$
	c.gridx = 1;
	c.weightx = 0;
	panel.add(beaconInterval_,c);
	
	
	c.gridx = 0;
	c.gridwidth = 2;
	++c.gridy;
	globalInfrastructureCheckBox_ = new JCheckBox(Messages.getString("EditSettingsControlPanel.enableInfrastructure"), true); //$NON-NLS-1$
	globalInfrastructureCheckBox_.addItemListener(this);
	// Disabled as it's not yet implemented
	// beaconPanel_.add(globalInfrastructureCheckBox_,c);
	
	return panel;
}
 
Example 3
Source File: EditSettingsControlPanel.java    From VanetSim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the panel which is shown when mix zones are enabled.
 * 
 * @return the mix zones panel
 */
private final JPanel createMixPanel(){
	JPanel panel = new JPanel();
	panel.setOpaque(false);
	panel.setLayout(new GridBagLayout());
	
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.BOTH;
	c.anchor = GridBagConstraints.PAGE_START;
	c.weightx = 1;
	c.gridx = 0;
	c.gridy = 0;
	c.gridheight = 1;
	c.insets = new Insets(5,0,5,0);
	
	JLabel jLabel1 = new JLabel(Messages.getString("EditSettingsControlPanel.mixZoneSize")); //$NON-NLS-1$
	panel.add(jLabel1,c);		
	mixZoneRadius_ = new JFormattedTextField(NumberFormat.getIntegerInstance());
	mixZoneRadius_.setPreferredSize(new Dimension(60,20));
	mixZoneRadius_.setValue(100);
	mixZoneRadius_.addPropertyChangeListener("value", this); //$NON-NLS-1$
	c.gridx = 1;
	c.weightx = 0;
	panel.add(mixZoneRadius_,c);
	
	c.gridx = 0;
	c.gridwidth = 2;
	++c.gridy;
	fallbackInMixZonesCheckBox_ = new JCheckBox(Messages.getString("EditSettingsControlPanel.fallbackCommunicationInMixZones"), true); //$NON-NLS-1$
	fallbackInMixZonesCheckBox_.addItemListener(this);
	panel.add(fallbackInMixZonesCheckBox_,c);
	
	++c.gridy;
	fallbackInMixZonesPanel_ = createMixFallBackPanel();
	panel.add(fallbackInMixZonesPanel_,c);
	
	return panel;
}
 
Example 4
Source File: BasicDatePickerUI.java    From microba with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected void installComponents() {
	field = new JFormattedTextField(createFormatterFactory());
	field.setValue(peer.getDate());
	field.setFocusLostBehavior(peer.getFocusLostBehavior());
	field.setEditable(peer.isFieldEditable());
	field.setToolTipText(peer.getToolTipText());
	// button
	button = new JButton();
	button.setFocusable(false);
	button.setMargin(new Insets(0, 0, 0, 0));
	button.setToolTipText(peer.getToolTipText());

	setSimpeLook(false);
	// calendar
	calendarPane = new CalendarPane(peer.getStyle());
	calendarPane.setShowTodayButton(peer.isShowTodayButton());
	calendarPane.setFocusLostBehavior(JFormattedTextField.REVERT);
	calendarPane.setFocusCycleRoot(true);
	calendarPane.setBorder(BorderFactory.createEmptyBorder(1, 3, 0, 3));
	calendarPane.setStripTime(false);
	calendarPane.setLocale(peer.getLocale());
	calendarPane.setZone(peer.getZone());
	calendarPane.setFocusable(peer.isDropdownFocusable());
	calendarPane.setColorOverrideMap(peer.getColorOverrideMap());
	// popup
	popup = new JPopupMenu();
	popup.setLayout(new BorderLayout());
	popup.add(calendarPane, BorderLayout.CENTER);
	popup.setLightWeightPopupEnabled(true);
	// add
	peer.setLayout(new BorderLayout());

	switch (peer.getPickerStyle()) {
	case DatePicker.PICKER_STYLE_FIELD_AND_BUTTON:
		peer.add(field, BorderLayout.CENTER);
		peer.add(button, BorderLayout.EAST);
		break;
	case DatePicker.PICKER_STYLE_BUTTON:
		peer.add(button, BorderLayout.EAST);
		break;
	}

	peer.revalidate();
	peer.repaint();

	componentListener = new ComponentListener();

	button.addActionListener(componentListener);
	field.addPropertyChangeListener(componentListener);

	calendarPane.addPropertyChangeListener(componentListener);
	calendarPane.addCommitListener(componentListener);
	calendarPane.addActionListener(componentListener);

	peerDateChanged(peer.getDate());
}
 
Example 5
Source File: AppearancePanel.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
private void initGui() {
	overwriteCheck = new JCheckBox();
	noTexturesCheck = new JCheckBox();
	generateUniqueCheck = new JCheckBox();
	exportAll = new JRadioButton();
	noExport = new JRadioButton();

	ButtonGroup expAppRadio = new ButtonGroup();
	expAppRadio.add(noExport);
	expAppRadio.add(exportAll);

	pathLabel = new JLabel();
	pathText = new JTextField();
	browseButton = new JButton();

	useBuckets = new JCheckBox();
	DecimalFormat bucketsFormat = new DecimalFormat("########");
	bucketsFormat.setMaximumIntegerDigits(8);
	bucketsFormat.setMinimumIntegerDigits(1);		
	noOfBuckets = new JFormattedTextField(bucketsFormat);

	PopupMenuDecorator.getInstance().decorate(pathText, noOfBuckets);
	
	browseButton.addActionListener(e -> {
		String path = browseFile(Language.I18N.getString("pref.export.appearance.label.absPath"), pathText.getText());
		if (!path.isEmpty())
			pathText.setText(path);
	});

	setLayout(new GridBagLayout());
	{
		exportBlock = new JPanel();
		add(exportBlock, GuiUtil.setConstraints(0,0,1.0,0.0,GridBagConstraints.BOTH,5,0,5,0));
		exportBlock.setBorder(BorderFactory.createTitledBorder(""));
		exportBlock.setLayout(new GridBagLayout());
		{
			exportAll.setIconTextGap(10);
			noTexturesCheck.setIconTextGap(10);
			noExport.setIconTextGap(10);
			overwriteCheck.setIconTextGap(10);
			generateUniqueCheck.setIconTextGap(10);
			int lmargin = (int) (exportAll.getPreferredSize().getWidth()) + 11;
			{
				exportBlock.add(exportAll, GuiUtil.setConstraints(0, 0, 0, 1, GridBagConstraints.BOTH, 0, 5, 0, 5));
				exportBlock.add(overwriteCheck, GuiUtil.setConstraints(0, 1, 1, 1, GridBagConstraints.BOTH, 0, lmargin, 0, 5));
				exportBlock.add(generateUniqueCheck, GuiUtil.setConstraints(0, 2, 1, 1, GridBagConstraints.BOTH, 0, lmargin, 0, 5));
				exportBlock.add(noTexturesCheck, GuiUtil.setConstraints(0, 3, 1, 1, GridBagConstraints.BOTH, 0, lmargin, 0, 5));
				exportBlock.add(noExport, GuiUtil.setConstraints(0, 4, 0, 1, GridBagConstraints.BOTH, 0, 5, 0, 5));
			}
		}

		pathBlock = new JPanel();
		add(pathBlock, GuiUtil.setConstraints(0,1,1.0,0.0,GridBagConstraints.BOTH,5,0,5,0));
		pathBlock.setBorder(BorderFactory.createTitledBorder(""));
		pathBlock.setLayout(new GridBagLayout());
		{
			pathBlock.add(pathLabel, GuiUtil.setConstraints(0, 0, 0, 0, GridBagConstraints.BOTH, 0, 5, 0, 5));
			pathBlock.add(pathText, GuiUtil.setConstraints(1, 0, 1, 1, GridBagConstraints.BOTH, 0, 5, 0, 5));
			pathBlock.add(browseButton, GuiUtil.setConstraints(2, 0, 0, 1, GridBagConstraints.BOTH, 0, 5, 0, 5));

			Box box = Box.createHorizontalBox();
			box.add(useBuckets);
			box.add(Box.createHorizontalStrut(5));
			box.add(noOfBuckets);
			useBuckets.setIconTextGap(10);
			pathBlock.add(box, GuiUtil.setConstraints(0, 1, 2, 1, 0, 0, GridBagConstraints.BOTH, 5, 5, 5, 5));
		}

	}

	noExport.addActionListener(e -> setEnabledTextureExport());
	exportAll.addActionListener(e -> setEnabledTextureExport());
	overwriteCheck.addActionListener(e -> {if (overwriteCheck.isSelected()) noTexturesCheck.setSelected(false); });
	noTexturesCheck.addActionListener(e -> {if (noTexturesCheck.isSelected()) overwriteCheck.setSelected(false); });
	useBuckets.addActionListener(e -> noOfBuckets.setEnabled(useBuckets.isSelected()));
	
	noOfBuckets.addPropertyChangeListener(evt -> {
		if (((Number)noOfBuckets.getValue()).intValue() < 0)
			noOfBuckets.setValue(-((Number)noOfBuckets.getValue()).intValue());
	});
}
 
Example 6
Source File: EditSettingsControlPanel.java    From VanetSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the panel which is shown when communication is enabled.
 * 
 * @return the communication panel
 */
private final JPanel createCommunicationPanel(){
	JPanel panel = new JPanel();
	panel.setOpaque(false);
	panel.setLayout(new GridBagLayout());
	
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.BOTH;
	c.anchor = GridBagConstraints.PAGE_START;
	c.weightx = 1;
	c.gridx = 0;
	c.gridy = 0;
	c.gridheight = 1;
	c.insets = new Insets(5,0,5,0);
	
	JLabel jLabel1 = new JLabel(Messages.getString("EditSettingsControlPanel.communicationInterval")); //$NON-NLS-1$
	panel.add(jLabel1,c);		
	communicationInterval_ = new JFormattedTextField(NumberFormat.getIntegerInstance());
	communicationInterval_.setPreferredSize(new Dimension(60,20));
	communicationInterval_.setValue(160);
	communicationInterval_.addPropertyChangeListener("value", this); //$NON-NLS-1$
	c.gridx = 1;
	c.weightx = 0;
	panel.add(communicationInterval_,c);

	c.gridx = 0;
	c.gridwidth = 2;
	++c.gridy;
	beaconsCheckBox_ = new JCheckBox(Messages.getString("EditSettingsControlPanel.enableBeacons"), true); //$NON-NLS-1$
	beaconsCheckBox_.addItemListener(this);
	panel.add(beaconsCheckBox_,c);
	
	++c.gridy;
	c.insets = new Insets(0,10,0,0);
	beaconPanel_ = createBeaconPanel();
	panel.add(beaconPanel_,c);
	
	++c.gridy;
	c.insets = new Insets(5,0,5,0);
	mixZonesCheckBox_ = new JCheckBox(Messages.getString("EditSettingsControlPanel.enableMixZones"), true); //$NON-NLS-1$
	mixZonesCheckBox_.addItemListener(this);
	panel.add(mixZonesCheckBox_,c);
	
	++c.gridy;
	c.insets = new Insets(0,10,0,0);
	mixZonePanel_ = createMixPanel();
	panel.add(mixZonePanel_,c);		
	
	TextAreaLabel jlabel1 = new TextAreaLabel(Messages.getString("EditSettingsControlPanel.intervalNote1") + SimulationMaster.TIME_PER_STEP +  Messages.getString("EditSettingsControlPanel.intervalNote2")); //$NON-NLS-1$ //$NON-NLS-2$
	++c.gridy;
	c.gridx = 0;
	c.gridwidth = 2;
	c.insets = new Insets(15,0,5,0);
	panel.add(jlabel1, c);
	return panel;
}