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

The following examples show how to use javax.swing.JFormattedTextField#setValue() . 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: SingleIntegerFieldOptionsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Sets integer number format to JFormattedTextField instance,
 * sets value of JFormattedTextField instance to object's field value,
 * synchronizes object's field value with the value of JFormattedTextField instance.
 *
 * @param textField  JFormattedTextField instance
 * @param owner      an object whose field is synchronized with {@code textField}
 * @param property   object's field name for synchronization
 */
public static void setupIntegerFieldTrackingValue(final JFormattedTextField textField,
                                                  final InspectionProfileEntry owner,
                                                  final String property) {
    NumberFormat formatter = NumberFormat.getIntegerInstance();
    formatter.setParseIntegerOnly(true);
    textField.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(formatter)));
    textField.setValue(getPropertyValue(owner, property));
    final Document document = textField.getDocument();
    document.addDocumentListener(new DocumentAdapter() {
        @Override
        public void textChanged(DocumentEvent e) {
            try {
                textField.commitEdit();
                setPropertyValue(owner, property,
                        ((Number) textField.getValue()).intValue());
            } catch (ParseException e1) {
                // No luck this time
            }
        }
    });
}
 
Example 2
Source File: EditLogControlPanel.java    From VanetSim with GNU General Public License v3.0 6 votes vote down vote up
public void setFilePath(JFormattedTextField textField){
	//begin with creation of new file
	JFileChooser fc = new JFileChooser();
	//set directory and ".log" filter
	fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
	fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	fc.setFileFilter(logFileFilter_);
	
	int status = fc.showDialog(this, Messages.getString("EditLogControlPanel.approveButton"));
	
	if(status == JFileChooser.APPROVE_OPTION){
			textField.setValue(fc.getSelectedFile().getAbsolutePath());
			textField.setToolTipText(fc.getSelectedFile().getAbsolutePath());
			textField.setCaretPosition(textField.getText().length());
	}
}
 
Example 3
Source File: IntegerEditor.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public IntegerEditor(int min, int max) {
    super(new JFormattedTextField());
    ftf = (JFormattedTextField) getComponent();
    minimum = new Integer(min);
    maximum = new Integer(max);

    // Set up the editor for the integer cells.
    integerFormat = NumberFormat.getIntegerInstance();
    NumberFormatter intFormatter = new NumberFormatter(integerFormat);
    intFormatter.setFormat(integerFormat);
    intFormatter.setMinimum(minimum);
    intFormatter.setMaximum(maximum);

    ftf.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
    ftf.setValue(minimum);
    ftf.setHorizontalAlignment(JTextField.TRAILING);
    ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);

    // React when the user presses Enter while the editor is
    // active. (Tab is handled as specified by
    // JFormattedTextField's focusLostBehavior property.)
    ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
    ftf.getActionMap().put("check", new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (!ftf.isEditValid()) { // The text is invalid.
                if (userSaysRevert()) { // reverted
                    ftf.postActionEvent(); // inform the editor
                }
            } else
                try { // The text is valid,
                    ftf.commitEdit(); // so use it.
                    ftf.postActionEvent(); // stop editing
                } catch (java.text.ParseException exc) {
                }
        }
    });
}
 
Example 4
Source File: Continuous1BandBasicForm.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private JFormattedTextField getNumberTextField(double value) {
    final NumberFormatter formatter = new NumberFormatter(new DecimalFormat("0.0############"));
    formatter.setValueClass(Double.class); // to ensure that double values are returned
    final JFormattedTextField numberField = new JFormattedTextField(formatter);
    numberField.setValue(value);
    final Dimension preferredSize = numberField.getPreferredSize();
    preferredSize.width = 70;
    numberField.setPreferredSize(preferredSize);
    return numberField;
}
 
Example 5
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 6
Source File: IntegerEditor.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
{
	JFormattedTextField textField =
			(JFormattedTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);
	textField.setValue(value);
	return textField;
}
 
Example 7
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 8
Source File: ClassDialogue.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
protected Component getComponent(Class<?> c, Object o) throws IllegalArgumentException, IllegalAccessException {
  switch (noChilds.indexOf(c.getName())) {
  case 0:
    return new JTextField(String.valueOf(o));
  case 1:
  case 2:
    JFormattedTextField numberField = createNumberField(Integer.class, Integer.MIN_VALUE, Integer.MAX_VALUE);
    numberField.setValue(o);
    return numberField;
  case 3:
  case 4:
    return new JCharField(o);
  case 5:
  case 6:
    return new JCheckBox("", (boolean) o);
  case 7:
    return new JTextField(new String((char[]) o));
  case 8:
    return new JTextField(new String(((Type) o).getInternalName()));
  }
  if (Number.class.isAssignableFrom(c) || (c.isPrimitive() && !char.class.isAssignableFrom(c))) {
    try {
      return getNumberInput(o);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  throw new RuntimeException();
}
 
Example 9
Source File: IntegerPropertyCellEditor.java    From openAGV with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellEditorComponent(
    JTable table, Object value, boolean isSelected, int row, int column) {

  JFormattedTextField textField = (JFormattedTextField) getComponent();
  setValue(value);

  if (property().getValue() instanceof Integer) {
    textField.setValue(new Integer((int) property().getValue()));
  }

  return fComponent;
}
 
Example 10
Source File: RSUPanel.java    From VanetSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor. Creating GUI items.
 */
public RSUPanel(){
	setLayout(new GridBagLayout());
	
	// global layout settings
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.BOTH;
	c.anchor = GridBagConstraints.PAGE_START;
	c.weightx = 0.5;
	c.gridx = 0;
	c.gridy = 0;
	c.gridheight = 1;
	c.gridwidth = 2;
	
	// Radio buttons to select mode
	ButtonGroup group = new ButtonGroup();
	addRSU_ = new JRadioButton(Messages.getString("RSUPanel.addRSU")); //$NON-NLS-1$
	addRSU_.setActionCommand("addRSU"); //$NON-NLS-1$;
	addRSU_.setSelected(true);
	group.add(addRSU_);
	++c.gridy;
	add(addRSU_,c);
	addRSU_.addActionListener(this);
	
	deleteRSU_ = new JRadioButton(Messages.getString("RSUPanel.deleteRSU")); //$NON-NLS-1$
	deleteRSU_.setActionCommand("deleteRSU"); //$NON-NLS-1$
	group.add(deleteRSU_);
	++c.gridy;
	add(deleteRSU_,c);
	deleteRSU_.addActionListener(this);
	
	c.gridwidth = 1;
	c.insets = new Insets(5,5,5,5);
	
	//textfields
	c.gridx = 0;
	rsuLabel_ = new JLabel(Messages.getString("RSUPanel.radius")); //$NON-NLS-1$
	++c.gridy;
	add(rsuLabel_,c);		
	rsuRadius_ = new JFormattedTextField(NumberFormat.getIntegerInstance());
	rsuRadius_.setValue(500);

	rsuRadius_.setPreferredSize(new Dimension(60,20));
	c.gridx = 1;
	add(rsuRadius_,c);
	
	c.gridx = 0;
	c.gridwidth = 2;
	++c.gridy;
	add(ButtonCreator.getJButton("deleteAll.png", "clearRSUs", Messages.getString("RSUPanel.btnClearRSUs"), this),c);
	
	deleteNote_ = new TextAreaLabel(Messages.getString("RSUPanel.noteDelete")); //$NON-NLS-1$
	++c.gridy;
	c.gridx = 0;
	add(deleteNote_, c);
	deleteNote_.setVisible(false);
	
	addNote_ = new TextAreaLabel(Messages.getString("RSUPanel.noteAdd")); //$NON-NLS-1$
	++c.gridy;
	c.gridx = 0;
	add(addNote_, c);
	addNote_.setVisible(true);
	
	
	//to consume the rest of the space
	c.weighty = 1.0;
	++c.gridy;
	JPanel space = new JPanel();
	space.setOpaque(false);
	add(space, c);
}
 
Example 11
Source File: BorrowIFrame.java    From LibraryManagementSystem with MIT License 4 votes vote down vote up
public BorrowIFrame() {
	super();
	setIconifiable(true);							// ���ô������С������������
	setClosable(true);								// ���ô���ɹرգ���������
	setTitle("������Ϣ���");						// ���ô�����⣭��������
	setBounds(100, 30, 500, 250);

	//������ͷͼƬ
	final JLabel logoLabel = new JLabel();
	ImageIcon readerAddIcon=CreateIcon.add("tback.jpg");
	logoLabel.setIcon(readerAddIcon);
	logoLabel.setOpaque(true);
	logoLabel.setBackground(Color.white);
	logoLabel.setPreferredSize(new Dimension(400, 60));
	getContentPane().add(logoLabel, BorderLayout.NORTH);

	//����һ�������������
	final JPanel panel = new JPanel();
	panel.setLayout(new FlowLayout());
	getContentPane().add(panel);

	//�������������Ƕ�����1,���ڷ��÷ǰ�ť���
	final JPanel panel_1 = new JPanel();
	final GridLayout gridLayout = new GridLayout(0, 4);
	gridLayout.setVgap(15);
	gridLayout.setHgap(10);
	panel_1.setLayout(gridLayout);
	panel_1.setPreferredSize(new Dimension(450, 100));
	panel.add(panel_1);

	final JLabel label_2 = new JLabel();
	label_2.setText("�������ڣ�");
	panel_1.add(label_2);
	borrowDate = new JFormattedTextField();
	borrowDate.setValue("XXXX-XX-XX");
	borrowDate.addKeyListener(new DateListener());
	panel_1.add(borrowDate);
	
	final JLabel label_3 = new JLabel();
	label_3.setText("��     �ţ�");
	panel_1.add(label_3);
	id = new JTextField();
	id.setDocument(new MyDocument(256));
	panel_1.add(id);
	
	final JLabel label_4 = new JLabel();
	label_4.setText("�鱾��� ��");
	panel_1.add(label_4);
	bid = new JTextField();
	bid.setDocument(new MyDocument(256));
	panel_1.add(bid);
	
	final JLabel label_5 = new JLabel();
	label_5.setText("���߱�ţ�");
	panel_1.add(label_5);
	rid = new JTextField();
	rid.setDocument(new MyDocument(256));
	panel_1.add(rid);
	
	final JLabel label_6 = new JLabel();
	label_6.setText("����Ա���֣�");
	panel_1.add(label_6);
	name = new JTextField();
	name.setDocument(new MyDocument(256));
	panel_1.add(name);

	//����������Ƕ��һ�����ڷ��Ű�ť�����
	final JPanel panel_2 = new JPanel();
	panel_2.setPreferredSize(new Dimension(450, 100));
	panel.add(panel_2);
	
	final JRadioButton radioButton1 = new JRadioButton();

	//�����������
	final JButton submit = new JButton();
	panel_2.add(submit);
	submit.setText("�ύ");
	submit.addActionListener((ActionListener) new ButtonAddListener(radioButton1));
	
	//�����������
	final JButton back = new JButton();
	panel_2.add(back);
	back.setText("����");
	back.addActionListener(new CloseActionListener());

	setVisible(true);
}
 
Example 12
Source File: ReturnIFrame.java    From LibraryManagementSystem with MIT License 4 votes vote down vote up
public ReturnIFrame() {
	super();
	setIconifiable(true);							// ���ô������С������������
	setClosable(true);								// ���ô���ɹرգ���������
	setTitle("��ӹ黹��Ϣ");						// ���ô�����⣭��������
	setBounds(100, 50, 500, 225);

	//������ͷͼƬ
	final JLabel logoLabel = new JLabel();
	ImageIcon readerAddIcon=CreateIcon.add("tback.jpg");
	logoLabel.setIcon(readerAddIcon);
	logoLabel.setOpaque(true);
	logoLabel.setBackground(Color.white);
	logoLabel.setPreferredSize(new Dimension(400, 60));
	getContentPane().add(logoLabel, BorderLayout.NORTH);

	//����һ�������������
	final JPanel panel = new JPanel();
	panel.setLayout(new FlowLayout());
	getContentPane().add(panel);

	//�������������Ƕ�����1,���ڷ��÷ǰ�ť���
	final JPanel panel_1 = new JPanel();
	final GridLayout gridLayout = new GridLayout(2, 2);
	gridLayout.setVgap(20);
	panel_1.setLayout(gridLayout);
	panel.add(panel_1);

	final JLabel label_2 = new JLabel();
	label_2.setText("���ļ�¼��ţ�");
	panel_1.add(label_2);
	id = new JTextField(10);
	id.setDocument(new MyDocument(256));
	panel_1.add(id);
	
	final JLabel label_3 = new JLabel();
	label_3.setText("�黹���ڣ�");
	panel_1.add(label_3);
	return_date = new JFormattedTextField();
	return_date.setValue("XXXX-XX-XX");
	return_date.addKeyListener(new DateListener());
	panel_1.add(return_date);
	
	//����������Ƕ��һ�����ڷ��Ű�ť�����
	final JPanel panel_2 = new JPanel();
	panel_2.setPreferredSize(new Dimension(450, 100));
	panel.add(panel_2);
	
	final JRadioButton radioButton1 = new JRadioButton();

	//�����������
	final JButton submit = new JButton();
	panel_2.add(submit);
	submit.setText("�ύ");
	submit.addActionListener((ActionListener) new ButtonAddListener(radioButton1));
	
	//�����������
	final JButton back = new JButton();
	panel_2.add(back);
	back.setText("����");
	back.addActionListener(new CloseActionListener());

	setVisible(true);
}
 
Example 13
Source File: IntegerEditor.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
public IntegerEditor(int min, int max)
{
	super(new JFormattedTextField());
	ftf = (JFormattedTextField) getComponent();
	minimum = min;
	maximum = max;

	//Set up the editor for the integer cells.
	integerFormat = NumberFormat.getIntegerInstance();
	NumberFormatter intFormatter = new NumberFormatter(integerFormat);
	intFormatter.setFormat(integerFormat);
	intFormatter.setMinimum(minimum);
	intFormatter.setMaximum(maximum);

	ftf.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
	ftf.setValue(minimum);
	ftf.setHorizontalAlignment(SwingConstants.TRAILING);
	ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);

	//React when the user presses Enter while the editor is
	//active.  (Tab is handled as specified by
	//JFormattedTextField's focusLostBehavior property.)
	ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
	ftf.getActionMap().put("check", new AbstractAction()
	{

		@Override
		public void actionPerformed(ActionEvent e)
		{
			if (!ftf.isEditValid())
			{ //The text is invalid.
				if (userSaysRevert())
				{ //reverted
					ftf.postActionEvent(); //inform the editor
				}
			}
			else
			{
				try
				{ //The text is valid,
					ftf.commitEdit(); //so use it.
					ftf.postActionEvent(); //stop editing
				}
				catch (java.text.ParseException exc)
				{
				}
			}
		}

	});
}
 
Example 14
Source File: SlowPanel.java    From VanetSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor, creating GUI items.
 */
public SlowPanel(){
	setLayout(new GridBagLayout());
	
	// global layout settings
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.BOTH;
	c.anchor = GridBagConstraints.PAGE_START;
	c.weightx = 0.5;
	c.gridx = 0;
	c.gridy = 0;
	c.gridheight = 1;
	c.gridwidth = 2;
	
	
	c.gridwidth = 1;
	c.insets = new Insets(5,5,5,5);

	c.gridx = 0;
	timeToPseudonymChangeLabel_ = new JLabel(Messages.getString("SlowPanel.timeToPseudonymChange")); //$NON-NLS-1$
	++c.gridy;
	add(timeToPseudonymChangeLabel_,c);		
	timeToPseudonymChange_ = new JFormattedTextField(NumberFormat.getIntegerInstance());
	timeToPseudonymChange_.setValue(3000);

	timeToPseudonymChange_.setPreferredSize(new Dimension(60,20));
	c.gridx = 1;
	timeToPseudonymChange_.addFocusListener(this);
	add(timeToPseudonymChange_,c);
	
	c.gridx = 0;
	slowSpeedLimitLabel_ = new JLabel(Messages.getString("SlowPanel.speedLimit")); //$NON-NLS-1$
	++c.gridy;
	add(slowSpeedLimitLabel_,c);		
	slowSpeedLimit_ = new JFormattedTextField(NumberFormat.getIntegerInstance());
	slowSpeedLimit_.setValue(30);

	slowSpeedLimit_.setPreferredSize(new Dimension(60,20));
	c.gridx = 1;
	slowSpeedLimit_.addFocusListener(this);
	add(slowSpeedLimit_,c);
	
	c.gridx = 0;
	enableSlowLabel_ = new JLabel(Messages.getString("SlowPanel.enable")); //$NON-NLS-1$
	++c.gridy;
	add(enableSlowLabel_,c);		
	enableSlow_ = new JCheckBox();
	enableSlow_.setSelected(false);
	enableSlow_.setActionCommand("enableSlow"); //$NON-NLS-1$
	c.gridx = 1;
	enableSlow_.addFocusListener(this);
	add(enableSlow_,c);
	enableSlow_.addActionListener(this);	
	
	
	//to consume the rest of the space
	c.weighty = 1.0;
	++c.gridy;
	JPanel space = new JPanel();
	space.setOpaque(false);
	add(space, c);
}
 
Example 15
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 16
Source File: AttackerPanel.java    From VanetSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor, creating GUI items.
 */
public AttackerPanel(){
	setLayout(new GridBagLayout());
	
	// global layout settings
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.BOTH;
	c.anchor = GridBagConstraints.PAGE_START;
	c.weightx = 0.5;
	c.gridx = 0;
	c.gridy = 0;
	c.gridheight = 1;
	c.gridwidth = 2;
	
	// Radio buttons to select mode
	ButtonGroup group = new ButtonGroup();
	addDeleteAttackRSU_ = new JRadioButton(Messages.getString("AttackerPanel.addAttackRSU")); //$NON-NLS-1$
	addDeleteAttackRSU_.setActionCommand("addAttackRSU"); //$NON-NLS-1$
	addDeleteAttackRSU_.addActionListener(this);
	addDeleteAttackRSU_.setSelected(true);
	group.add(addDeleteAttackRSU_);
	++c.gridy;
	add(addDeleteAttackRSU_,c);
	
	selectUnselectAttackerVehicle_ = new JRadioButton(Messages.getString("AttackerPanel.selectAttackerVehicle")); //$NON-NLS-1$
	selectUnselectAttackerVehicle_.setActionCommand("selectAttackerVehicle"); //$NON-NLS-1$
	selectUnselectAttackerVehicle_.addActionListener(this);
	group.add(selectUnselectAttackerVehicle_);
	++c.gridy;
	add(selectUnselectAttackerVehicle_,c);
	
	selectUnselectAttackedVehicle_ = new JRadioButton(Messages.getString("AttackerPanel.selectAttackedVehicle")); //$NON-NLS-1$
	selectUnselectAttackedVehicle_.setActionCommand("selectAttackedVehicle"); //$NON-NLS-1$
	selectUnselectAttackedVehicle_.addActionListener(this);
	group.add(selectUnselectAttackedVehicle_);
	++c.gridy;
	add(selectUnselectAttackedVehicle_,c);
	
	c.gridwidth = 1;
	c.insets = new Insets(5,5,5,5);
	
	//Radius of the Attacker-RSU
	c.gridx = 0;
	arsuRadiusLabel_ = new JLabel(Messages.getString("AttackPanel.radius")); //$NON-NLS-1$
	++c.gridy;
	add(arsuRadiusLabel_,c);		
	arsuRadius_ = new JFormattedTextField(NumberFormat.getIntegerInstance());
	arsuRadius_.setValue(100);

	arsuRadius_.setPreferredSize(new Dimension(60,20));
	c.gridx = 1;
	add(arsuRadius_,c);

	//Button to delete all attackers
	c.gridx = 0;
	c.gridwidth = 2;
	++c.gridy;
	add(ButtonCreator.getJButton("deleteAll.png", "clearAttackers", Messages.getString("AttackerPanel.btnClearAttackers"), this),c);
	
	attackerNote_ = new TextAreaLabel(Messages.getString("AttackerPanel.noteAttackers")); //$NON-NLS-1$
	++c.gridy;
	c.gridx = 0;
	add(attackerNote_, c);
	attackerNote_.setVisible(true);
	
	//to consume the rest of the space
	c.weighty = 1.0;
	++c.gridy;
	JPanel space = new JPanel();
	space.setOpaque(false);
	add(space, c);
			
	//end of GUI
}
 
Example 17
Source File: ResourcesPanel.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
private void checkNonNegativeRange(JFormattedTextField field, int min, int max) {
	if (((Number)field.getValue()).intValue() < 0)
		field.setValue(min);
	else if (((Number)field.getValue()).intValue() > 100)
		field.setValue(max);
}
 
Example 18
Source File: ResourcesPanel.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
private void checkNonNegative(JFormattedTextField field, int defaultValue) {
	if (((Number)field.getValue()).intValue() < 0)
		field.setValue(defaultValue);
}
 
Example 19
Source File: IntegerEditor.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    JFormattedTextField ftf = (JFormattedTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);
    ftf.setValue(value);
    return ftf;
}
 
Example 20
Source File: ProxyPanel.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
private void checkNonNegativeRange(JFormattedTextField field, int min, int max) {
	if (((Number)field.getValue()).intValue() < min)
		field.setValue(min);
	else if (((Number)field.getValue()).intValue() > max)
		field.setValue(max);
}