javax.swing.InputVerifier Java Examples

The following examples show how to use javax.swing.InputVerifier. 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: RevertModifications.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: ScrOptions.java    From PolyGlot with MIT License 6 votes vote down vote up
/**
 * Creates new form ScrOptions
 *
 * @param _core
 */
public ScrOptions(DictCore _core) {
    super(_core, false);
    
    initComponents();
    setOptions();
    final ScrOptions optionsParent = this;
    
    // TODO: Either finish night mode or remove references to it.
    chkNightMode.setVisible(false);
    
    txtRevisionNumbers.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            try {
                Integer.parseInt(((JTextField)input).getText());
            } catch (NumberFormatException e) {
                // user error
                // IOHandler.writeErrorLog(e);
                InfoBox.warning("Bad Input", "Please provide an integer (number) value.", optionsParent);
                return false;
            }
            return true;
        }
    });
}
 
Example #3
Source File: HintTextField.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 * 
 * @param hint the hint text
 * @param required true, if the field should be marked as required
 * @param verifier input verifier, or null if none needed
 */
public HintTextField(String hint, boolean required, InputVerifier verifier) {
	this.hint = hint;
	this.required = required;
	this.verifier = verifier;
	addListeners();
	setAttributes();
	validateField();
}
 
Example #4
Source File: CheckoutStep.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #5
Source File: AttackOverviewGui.java    From OpenID-Attacker with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
        }
    });
}
 
Example #6
Source File: PingerPanel.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #7
Source File: SelectAmountDialog.java    From freecol with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
            }
        });
    JPanel 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");
}