private void initInputVerifiers () { InputVerifier iv = new InputVerifier() { @Override public boolean verify (JComponent input) { if (input == panel.startRevisionTextField || input == panel.endRevisionTextField || input == panel.oneRevisionTextField) { JTextComponent comp = (JTextComponent) input; if (comp.getText().trim().isEmpty()) { comp.setText(SVNRevision.HEAD.toString()); } } return true; } }; panel.startRevisionTextField.setInputVerifier(iv); panel.endRevisionTextField.setInputVerifier(iv); panel.oneRevisionTextField.setInputVerifier(iv); }
/** * Creates new form CommObjectTable */ public CommObjectTable() { RootEventBus.getDefault().registerSticky(this); InputVerifier gaVerifier = getGaInputVerifier(); gaEditor = getGaTableCellEditor(gaVerifier); initComponents(); table.setRowHeight(27); // enough space for textfields table.getColumnModel().getColumn(0).setPreferredWidth(30); table.getColumnModel().getColumn(1).setPreferredWidth(150); table.getColumnModel().getColumn(2).setPreferredWidth(120); table.getColumnModel().getColumn(3).setPreferredWidth(60); table.getColumnModel().getColumn(4).setPreferredWidth(150); table.getColumnModel().getColumn(5).setPreferredWidth(150); table.putClientProperty("terminateEditOnFocusLost", true); }
private DefaultCellEditor getGaTableCellEditor(final InputVerifier verifier) { DefaultCellEditor editor = new DefaultCellEditor(new GroupAddressTextField()) { { getComponent().setInputVerifier(verifier); } @Override public boolean stopCellEditing() { if (!verifier.shouldYieldFocus(getComponent())) { return false; } System.out.println("Stopped editing: "+getComponent().getText()); return super.stopCellEditing(); } @Override public JTextField getComponent() { return (JTextField) super.getComponent(); } }; return editor; }
public void callUpdateIfReady() { if (field==null) { // we can't do anything if field is null, just trigger update parent.update(); } else { // we see if this class has a InputVerifier, if it does, we only call update // if it would return true InputVerifier validator = field.getInputVerifier(); if (validator==null || validator.verify(field)) { parent.update(); } } }
private Component makeTextField(final Parameter par) throws NetworkException { final JTextField field = new JTextField(); if (par.getRegister().hasValue()) { field.setText(par.getValue().toString()); } else { field.setText(par.getDefault().toString()); } field.setInputVerifier(new InputVerifier() { private final Pattern pattern = Pattern.compile(par.getPattern()); @Override public boolean verify(JComponent input) { return (pattern.matcher(field.getText()).matches()); } }); return field; }
public void setup(RepositoryFile repositoryFile) { if(repositoryPaths == null) { repositoryPaths = new RepositoryPaths( repositoryFile, workdirPanel.repositoryPathTextField, workdirPanel.browseRepositoryButton, workdirPanel.revisionTextField, workdirPanel.searchRevisionButton, workdirPanel.browseRevisionButton ); String browserPurposeMessage = org.openide.util.NbBundle.getMessage(CheckoutStep.class, "LBL_BrowserMessage"); int browserMode = Browser.BROWSER_SHOW_FILES | Browser.BROWSER_FOLDERS_SELECTION_ONLY; repositoryPaths.setupBehavior(browserPurposeMessage, browserMode, Browser.BROWSER_HELP_ID_CHECKOUT, SvnSearch.SEACRH_HELP_ID_CHECKOUT); } else { repositoryPaths.setRepositoryFile(repositoryFile); } workdirPanel.repositoryPathTextField.setText(repositoryFile.getPath()); refreshWorkingCopy(new RepositoryFile[] {repositoryFile}); if(!repositoryFile.getRevision().equals(SVNRevision.HEAD)) { workdirPanel.revisionTextField.setText(repositoryFile.getRevision().toString()); } else { workdirPanel.revisionTextField.setText(SVNRevision.HEAD.toString()); } workdirPanel.revisionTextField.setInputVerifier(new InputVerifier() { @Override public boolean verify (JComponent input) { if (workdirPanel.revisionTextField.getText().trim().isEmpty()) { workdirPanel.revisionTextField.setText(SVNRevision.HEAD.toString()); } return true; } }); workdirPanel.scanForProjectsCheckBox.setSelected(SvnModuleConfig.getDefault().getShowCheckoutCompleted()); }
public void interactiveNumberInputVerifier() { final JFormattedTextField field = new JFormattedTextField(NumberFormat.getIntegerInstance()) { @Override protected void invalidEdit() { LOG.info("got invalid edit"); super.invalidEdit(); } }; field.setText("20"); try { field.commitEdit(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } InputVerifier verifier = new InputVerifier() { @Override public boolean verify(JComponent input) { boolean result = ((Number) field.getValue()).intValue() < 200; if (!result) LOG.info("in verifier"); return result; } }; field.setInputVerifier(verifier); final JFormattedTextField other = new JFormattedTextField(NumberFormat.getIntegerInstance()); JComponent content = Box.createVerticalBox(); content.add(field); content.add(other); showInFrame(content, ""); }
/** * Creates new form AttackOverviewGui * @param idpType */ public AttackOverviewGui(final IdpType idpType) { initComponents(); controller.setIdp(idpType); if (idpType.equals(IdpType.ANALYZER)) { performAttack.setEnabled(false); sendTokenToAttackerUrl.setEnabled(false); } // set speed for scrolling parameterScrollPane.getVerticalScrollBar().setUnitIncrement(16); AttackParameterKeeper keeper = controller.getServer().getParameterConfiguration(); ObservableList<AttackParameter> list = (ObservableList<AttackParameter>) keeper.getParameterList(); list.addObservableListListener(this); newParameterName.setInputVerifier(new InputVerifier() { final private AttackParameterKeeper parameters = controller.getServer().getParameterConfiguration(); @Override public boolean verify(JComponent jc) { String newName = newParameterName.getText(); boolean contained = parameters.hasParameter(newName); if (contained) { errorLabel.setText(String.format("Parameter '%s' already exist", newName)); } else { errorLabel.setText(""); } return !contained; } }); }
private InputVerifier buildInputVerifier() { return new InputVerifier() { @Override public boolean verify(JComponent component) { return isValid(parseDecimalText()); } }; }
public boolean shouldYieldFocus(JComponent input) { msg = null; boolean result = super.shouldYieldFocus(input); if ((!result) && (msg != null)) { InputVerifier old = input.getInputVerifier(); // Neccecary to prevent endless popups. input.setInputVerifier(null); try { JOptionPane.showMessageDialog(input, msg); } finally { input.setInputVerifier(old); } } return result; }
/** * Creates new form PingerPanel * @param tm */ public PingerPanel(TopicMap tm) { this.tm = tm; isRunning = false; try { maybeTargetButton = new GetTopicButton(); maybeSourceButton = new GetTopicButton(); } catch (Exception e) { return; } initComponents(); InputVerifier verifier = new InputVerifier(){ @Override public boolean verify(JComponent input) { JFormattedTextField tf = (JFormattedTextField)input; int v = Integer.parseInt(tf.getText()); return v >= 0; } }; yearField.setInputVerifier(verifier); monthField.setInputVerifier(verifier); dayField.setInputVerifier(verifier); hoursField.setInputVerifier(verifier); minutesField.setInputVerifier(verifier); secondsField.setInputVerifier(verifier); delayField.setInputVerifier(verifier); toggleExpirationFieldEnabled(); setSetupEnabled(isRunning); }
protected void init() { setInputVerifier(new InputVerifier() { public boolean verify(JComponent input) { if (!(input instanceof AttrSchemeField)) return true; // give up focus return ((AttrSchemeField) input).isEditValid(); } }); }
protected void init() { setInputVerifier(new InputVerifier() { public boolean verify(JComponent input) { if (!(input instanceof AttrIntField)) return true; // give up focus return ((AttrPortField) input).isEditValid(); } }); }
protected void init() { setInputVerifier(new InputVerifier() { public boolean verify(JComponent input) { if (!(input instanceof AttrIntField)) return true; // give up focus return ((AttrIntField) input).isEditValid(); } }); }
/** * The constructor to use. * * @param freeColClient The enclosing {@code FreeColClient}. * @param frame The owner frame. * @param goodsType The {@code GoodsType} to select an amount of. * @param available The amount of goods available. * @param defaultAmount The amount to select to start with. * @param pay If true, check the player has sufficient funds. */ public SelectAmountDialog(FreeColClient freeColClient, JFrame frame, GoodsType goodsType, int available, int defaultAmount, boolean pay) { super(freeColClient, frame); if (pay) { final Player player = getMyPlayer(); final int gold = player.getGold(); int price = player.getMarket().getCostToBuy(goodsType); available = Math.min(available, gold/price); } this.available = available; JTextArea question = Utility.localizedTextArea("selectAmountDialog.text"); List<Integer> values = new ArrayList<>(); int defaultIndex = -1; for (int index = 0; index < amounts.length; index++) { if (amounts[index] < available) { if (amounts[index] == defaultAmount) defaultIndex = index; values.add(amounts[index]); } else { if (available == defaultAmount) defaultIndex = index; values.add(available); break; } } if (defaultAmount > 0 && defaultIndex < 0) { for (int index = 0; index < values.size(); index++) { if (defaultAmount < values.get(index)) { values.add(index, defaultAmount); defaultIndex = index; break; } } } this.comboBox = new JComboBox<>(values.toArray(new Integer[0])); this.comboBox.setEditable(true); if (defaultIndex >= 0) this.comboBox.setSelectedIndex(defaultIndex); this.comboBox.setInputVerifier(new InputVerifier() { @Override @SuppressWarnings("unchecked") public boolean verify(JComponent input) { return verifyWholeBox((JComboBox<Integer>)input); } }); MigPanel panel = new MigPanel(new MigLayout("wrap 1", "", "")); panel.add(question); panel.add(this.comboBox, "wrap 20, growx"); panel.setSize(panel.getPreferredSize()); initializeInputDialog(frame, true, panel, null, "ok", "cancel"); }
public CellEditor(InputVerifier verifier) { super(new JTextField()); this.verifier = verifier; }
/** * Creates and returns a JFormattedTextField configured with SwingX extended * NumberFormat and StrictNumberFormatter. This method is called if * the constructor parameter useStrictFormatter is true. * * Use a static method so that we can do some stuff before calling the * superclass. */ private static JFormattedTextField createFormattedTextFieldX( NumberFormat format) { StrictNumberFormatter formatter = new StrictNumberFormatter( new NumberFormatExt(format)); final JFormattedTextField textField = new JFormattedTextField( formatter); /* * FIXME: I am sure there is a better way to do this, but I don't know * what it is. JTable sets up a binding for the ESCAPE key, but * JFormattedTextField overrides that binding with it's own. Remove the * JFormattedTextField binding. */ InputMap map = textField.getInputMap(); map.put(KeyStroke.getKeyStroke("ESCAPE"), "none"); // while (map != null) { // map.remove(KeyStroke.getKeyStroke("pressed ESCAPE")); // map = map.getParent(); // } /* * Set an input verifier to prevent the cell losing focus when the value * is invalid */ textField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JFormattedTextField ftf = (JFormattedTextField) input; return ftf.isEditValid(); } }); /* * The formatted text field will not call stopCellEditing() until the * value is valid. So do the red border thing here. */ textField.addPropertyChangeListener("editValid", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getNewValue() == Boolean.TRUE) { ((JFormattedTextField) evt.getSource()) .setBorder(new LineBorder(Color.black)); } else { ((JFormattedTextField) evt.getSource()) .setBorder(new LineBorder(Color.red)); } } }); return textField; }
/** * Creates and returns a JFormattedTextField configured with defaults. This * method is called if the contructor useStrictFormatter is false.<p> * * Use a static method so that we can do some stuff before calling the * superclass. */ private static JFormattedTextField createFormattedTextField( NumberFormat formatter) { final JFormattedTextField textField = new JFormattedTextField( new NumberFormatExt(formatter)); /* * FIXME: I am sure there is a better way to do this, but I don't know * what it is. JTable sets up a binding for the ESCAPE key, but * JFormattedTextField overrides that binding with it's own. Remove the * JFormattedTextField binding. */ InputMap map = textField.getInputMap(); map.put(KeyStroke.getKeyStroke("ESCAPE"), "none"); // while (map != null) { // map.remove(KeyStroke.getKeyStroke("pressed ESCAPE")); // map = map.getParent(); // } /* * Set an input verifier to prevent the cell losing focus when the value * is invalid */ textField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JFormattedTextField ftf = (JFormattedTextField) input; return ftf.isEditValid(); } }); /* * The formatted text field will not call stopCellEditing() until the * value is valid. So do the red border thing here. */ textField.addPropertyChangeListener("editValid", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getNewValue() == Boolean.TRUE) { ((JFormattedTextField) evt.getSource()) .setBorder(new LineBorder(Color.black)); } else { ((JFormattedTextField) evt.getSource()) .setBorder(new LineBorder(Color.red)); } } }); return textField; }
/** * Set Input Verifier * @param l verifyer */ @Override public void setInputVerifier (InputVerifier l) { m_textPane.setInputVerifier(l); }
/** * Set Text Input Verifier * @param l */ @Override public void setInputVerifier (InputVerifier l) { m_textArea.setInputVerifier(l); }
@Override public InputVerifier getInputVerifier() { return JBroTableHeader.this.getInputVerifier(); }
@Override public void setInputVerifier( InputVerifier inputVerifier ) { JBroTableHeader.this.setInputVerifier( inputVerifier ); }
/** * Use a static method so that we can do some stuff before calling the * superclass. */ private static JFormattedTextField createFormattedTextField( NumberFormat formatter) { final JFormattedTextField textField = new JFormattedTextField( new NumberEditorNumberFormat(formatter)); /* * FIXME: I am sure there is a better way to do this, but I don't know * what it is. JTable sets up a binding for the ESCAPE key, but * JFormattedTextField overrides that binding with it's own. Remove the * JFormattedTextField binding. */ InputMap map = textField.getInputMap(); while (map != null) { map.remove(KeyStroke.getKeyStroke("pressed ESCAPE")); map = map.getParent(); } /* * Set an input verifier to prevent the cell losing focus when the value * is invalid */ textField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JFormattedTextField ftf = (JFormattedTextField) input; return ftf.isEditValid(); } }); /* * The formatted text field will not call stopCellEditing() until the * value is valid. So do the red border thing here. */ textField.addPropertyChangeListener("editValid", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getNewValue() == Boolean.TRUE) { ((JFormattedTextField) evt.getSource()) .setBorder(new LineBorder(Color.black)); } else { ((JFormattedTextField) evt.getSource()) .setBorder(new LineBorder(Color.red)); } } }); return textField; }
public InputVerifier getInputVerifier() { InstrumentedUILog.add(new Object[] { "JComponent.getInputVerifier" }); return super.getInputVerifier(); }
public void setInputVerifier(InputVerifier arg0) { InstrumentedUILog.add(new Object[] { "JComponent.setInputVerifier" }); super.setInputVerifier(arg0); }
public InputVerifier getInputVerifier() { InstrumentedUILog .add(new Object[] { "JTextComponent.getInputVerifier" }); return super.getInputVerifier(); }
public void setInputVerifier(InputVerifier arg0) { InstrumentedUILog.add(new Object[] { "JTextComponent.setInputVerifier", arg0 }); super.setInputVerifier(arg0); }
public InputVerifier getInputVerifier() { InstrumentedUILog.add(new Object[] { "getInputVerifier" }); return super.getInputVerifier(); }
public void setInputVerifier(InputVerifier arg0) { InstrumentedUILog.add(new Object[] { "setInputVerifier", arg0 }); super.setInputVerifier(arg0); }
FingeringEditor() { super(gui, "Fingering", true); JPanel fingerPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Fingering: "); label.setDisplayedMnemonic(KeyEvent.VK_F); text = new JTextField(); InputVerifier verifier = new InputVerifier() { public boolean verify(JComponent input) { final JTextComponent source = (JTextComponent) input; String text = source.getText(); return text.length() == 0 || text.matches("[1-5-]+"); } }; text.setInputVerifier(verifier); label.setLabelFor(text); fingerPanel.add(label, BorderLayout.WEST); fingerPanel.add(text, BorderLayout.CENTER); okButton = new JButton(UIManager.getString("OptionPane.okButtonText", getLocale())); okButton.addActionListener(this); cancelButton = new JButton(UIManager.getString("OptionPane.cancelButtonText", getLocale())); cancelButton.addActionListener(this); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); buttonPane.add(Box.createHorizontalGlue()); buttonPane.add(cancelButton); buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); buttonPane.add(okButton); Container contentPane = getContentPane(); contentPane.add(fingerPanel, BorderLayout.CENTER); contentPane.add(buttonPane, BorderLayout.PAGE_END); getRootPane().setDefaultButton(okButton); pack(); setLocationRelativeTo(gui); }