Examples of InputVerifier


Examples of javax.swing.InputVerifier

            }

        });

        /* get an input verifier for mac addresses */
        InputVerifier macInputVerifier = new InputVerifier() {
            @Override
            public boolean verify(JComponent input) {
                try{
                    @SuppressWarnings("unused")
                    MACAddress addr = new MACAddress(((JTextField)input).getText());
                } catch (Exception e) {
                    return false;
                }
                return true;
            }

            /*
             * (non-Javadoc)
             * @see javax.swing.InputVerifier#shouldYieldFocus(javax.swing.JComponent)
             */
            public boolean shouldYieldFocus(JComponent input){
                if(!verify(input)){
                    ((JTextField)input).setBackground(Color.RED);
                    return false;
                } else {
                    ((JTextField)input).setBackground(Color.WHITE);
                    return true;
                }
            }
        };

        /* set the input verifier for the MAC text fields */
        this.macDestAddrTextField.setInputVerifier(macInputVerifier);

        /* write destination MAC address to the hardware */
        this.macDestAddrTextField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateDestMac();
            }
        });

        /* set the input verifier for the source MAC address */
        this.macSrcAddrTextField.setInputVerifier(macInputVerifier);

        /* write the source mac address to the hardware */
        this.macSrcAddrTextField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateSrcMac();
            }
        });

        /* get an input verifier for integers */
        InputVerifier integerInputVerifier = new InputVerifier() {
            @Override
            public boolean verify(JComponent input) {
                try{
                    Integer.parseInt(((JTextField)input).getText());
                } catch (Exception e) {
                    return false;
                }
                return true;
            }

            /*
             * (non-Javadoc)
             * @see javax.swing.InputVerifier#shouldYieldFocus(javax.swing.JComponent)
             */
            public boolean shouldYieldFocus(JComponent input){
                if(!verify(input)){
                    ((JTextField)input).setBackground(Color.RED);
                    return false;
                } else {
                    ((JTextField)input).setBackground(Color.WHITE);
                    return true;
                }
            }
        };

        /* set the graph num points input verifier */
        this.graphSizeTextField.setInputVerifier(integerInputVerifier);

        /* add action listener to set graph size */
        this.graphSizeTextField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateGraphSizes();
            }
        });

        /* Set udp destination port text field input verifier */
        this.udpDestPortTextField.setInputVerifier(integerInputVerifier);

        /* set the action listener */
        this.udpDestPortTextField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateUdpDestField();
            }
        });

        /* Set udp Source port text field input verifier */
        this.udpSrcPortTextField.setInputVerifier(integerInputVerifier);

        /* set the action listener */
        this.udpSrcPortTextField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateUdpSrcField();
            }
        });

        /* create an IP address input verifier */
        InputVerifier ipInputVerifier = new InputVerifier() {
            @Override
            public boolean verify(JComponent input) {
                try{
                    new IPAddress(((JTextField)input).getText());
                } catch (Exception e) {
View Full Code Here

Examples of javax.swing.InputVerifier

     * integer input.
     * @return JTextField
     */
    public static JTextField createIntegerTextField() {
        JTextField textField = new NumericTextField();
        textField.setInputVerifier(new InputVerifier() {
            @Override
            public boolean verify(JComponent input) {
                try {
                    Integer.parseInt(((JTextField) input).getText());
                    return true;
View Full Code Here

Examples of javax.swing.InputVerifier

     * or decimal input.
     * @return JTextField
     */
    public static JTextField createDecimalTextField() {
        JTextField textField = new NumericTextField();
        textField.setInputVerifier(new InputVerifier() {
            @Override
            public boolean verify(JComponent input) {
                try {
                    Double.parseDouble(((JTextField) input).getText());
                    return true;
View Full Code Here

Examples of javax.swing.InputVerifier

                    updateModel();
                }
            }
        });

        textComponent.setInputVerifier(new InputVerifier() {

            public boolean verify(JComponent c) {
                updateModel();
                // release focus after coloring the field...
                return true;
View Full Code Here

Examples of javax.swing.InputVerifier

        this.undoableListener = new JTextFieldUndoListener(this);
        this.textComponent.getDocument().addUndoableEditListener(this.undoableListener);

        if (checkOnFocusLost) {
            textComponent.setInputVerifier(new InputVerifier() {

                public boolean verify(JComponent c) {
                    updateModel();
                    // release focus after coloring the field...
                    return true;
View Full Code Here

Examples of javax.swing.InputVerifier

      comp.setBackground(Color.red);
      //Ugly work-around: with 1.4 stackoverflow will occur when trying to show
      //the dialog as this will try to get focus from the component and this
      //method will be called again and so on. Thus we temporarily deactivate
      //the input verifier here:
      InputVerifier v = comp.getInputVerifier();
      comp.setInputVerifier(null);
      JOptionPane.showMessageDialog(comp, SequenceTextField.ILLEGAL_INPUT_MESSAGE, SequenceTextField.ILLEGAL_INPUT_TITLE,
                                    JOptionPane.ERROR_MESSAGE);
      comp.setInputVerifier(v);
      comp.requestFocus();
View Full Code Here

Examples of javax.swing.InputVerifier

  /** A generic listener class that will validate on an event */
  public static class VerifierListener implements ActionListener {
      public void actionPerformed(ActionEvent e){
        JComponent c = (JComponent)e.getSource();
        InputVerifier v = c.getInputVerifier();
        if (v != null) // on init, it is null
          v.verify(c);
      }
View Full Code Here

Examples of javax.swing.InputVerifier

/**
* On pressing enter key, check any unvalidated component
*/ 
  public void onOk() {
    if (dirtyComponent != null) {
      InputVerifier verifier = dirtyComponent.getInputVerifier();
      if (!verifier.shouldYieldFocus(dirtyComponent))
        return;
    }
    super.onOk();
  }
View Full Code Here

Examples of javax.swing.InputVerifier

public class DateInputVerifierTest extends TestCase {
 
  public void testVerifier() {
   
    InputVerifier verifier = new JXDatePickerInputVerifier();

    //Data V�lida
    JXDatePicker picker = new JXDatePicker();
    picker.setInputVerifier(verifier);
    assertTrue(picker.getInputVerifier().shouldYieldFocus(picker));
View Full Code Here

Examples of javax.swing.InputVerifier

        Sysout.printInstructions( instructions );

        JFrame frame = new JFrame();
        frame.getContentPane().setLayout(new FlowLayout());
        JTextField tf1 = new JTextField(10);
        tf1.setInputVerifier(new InputVerifier() {
                public boolean verify(JComponent input) {
                    System.err.println("verify on " + input);
                    verifier_called = true;
                    return true;
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.