Example usage for javax.swing.event DocumentListener DocumentListener

List of usage examples for javax.swing.event DocumentListener DocumentListener

Introduction

In this page you can find the example usage for javax.swing.event DocumentListener DocumentListener.

Prototype

DocumentListener

Source Link

Usage

From source file:ChangeTrackingTest.java

public ColorFrame() {
    setTitle("ChangeTrackingTest");

    DocumentListener listener = new DocumentListener() {
        public void insertUpdate(DocumentEvent event) {
            setColor();/*w  ww .j  a v a 2 s .  co m*/
        }

        public void removeUpdate(DocumentEvent event) {
            setColor();
        }

        public void changedUpdate(DocumentEvent event) {
        }
    };

    panel = new JPanel();

    panel.add(new JLabel("Red:"));
    redField = new JTextField("255", 3);
    panel.add(redField);
    redField.getDocument().addDocumentListener(listener);

    panel.add(new JLabel("Green:"));
    greenField = new JTextField("255", 3);
    panel.add(greenField);
    greenField.getDocument().addDocumentListener(listener);

    panel.add(new JLabel("Blue:"));
    blueField = new JTextField("255", 3);
    panel.add(blueField);
    blueField.getDocument().addDocumentListener(listener);

    add(panel);
    pack();
}

From source file:com.palantir.ptoss.cinch.swing.JPasswordFieldWiringHarness.java

public static Collection<Binding> bindJPasswordField(final BindableModel model, final JPasswordField pwdField,
        final Method getter, final Method setter) {
    pwdField.getDocument().addDocumentListener(new DocumentListener() {
        public void removeUpdate(DocumentEvent e) {
            updateModel();/*from   w ww .  ja v  a  2  s  .  c  o m*/
        }

        public void insertUpdate(DocumentEvent e) {
            updateModel();
        }

        public void changedUpdate(DocumentEvent e) {
            updateModel();
        }

        private void updateModel() {
            try {
                setter.invoke(model, pwdField.getPassword());
            } catch (Exception ex) {
                Wiring.logger.error("exception in JPasswordField binding", ex);
            }
        }
    });
    Binding binding = new Binding() {
        public <T extends Enum<?> & ModelUpdate> void update(T... changed) {
            try {
                char[] charArray = (char[]) getter.invoke(model);
                if (charArray == null) {
                    charArray = new char[0];
                }
                if (!Arrays.equals(charArray, pwdField.getPassword())) {
                    pwdField.setText(String.valueOf(charArray));
                }
            } catch (Exception ex) {
                Wiring.logger.error("exception in JPasswordField binding", ex);
            }
        }
    };
    model.bind(binding);
    return Collections.singleton(binding);
}

From source file:coreferenceresolver.gui.MainGUI.java

/**
 * Creates new form MainGUI//from   www.j  a  v  a 2  s  . c om
 */
public MainGUI() throws IOException {
    initComponents();
    defaulPath = FileUtils.readFileToString(new File(".\\src\\coreferenceresolver\\gui\\defaultpath"));
    markupBtn.setEnabled(false);
    testBtn.setEnabled(false);
    trainingBtn.setEnabled(false);
    applyClassifierBtn.setEnabled(false);
    inputFilePathTF.getDocument().addDocumentListener(new DocumentListener() {
        // implement the methods
        public void changedUpdate(DocumentEvent e) {

        }

        public void removeUpdate(DocumentEvent e) {
            if (e.getDocument().getLength() == 0) {
                markupBtn.setEnabled(false);
                testBtn.setEnabled(false);
                trainingBtn.setEnabled(false);
                applyClassifierBtn.setEnabled(false);
            }
        }

        public void insertUpdate(DocumentEvent e) {
            markupBtn.setEnabled(true);
            if (markupFilePathTF.getText() != null && !markupFilePathTF.getText().equals("")) {
                testBtn.setEnabled(true);
                trainingBtn.setEnabled(true);
            }
            if (testingFilePathTF.getText() != null && !testingFilePathTF.getText().equals("")
                    && trainingFilePathTF.getText() != null && !trainingFilePathTF.getText().equals("")) {
                applyClassifierBtn.setEnabled(true);
            }
        }
    });

    markupFilePathTF.getDocument().addDocumentListener(new DocumentListener() {
        // implement the methods
        public void changedUpdate(DocumentEvent e) {

        }

        public void removeUpdate(DocumentEvent e) {
            if (e.getDocument().getLength() == 0) {
                testBtn.setEnabled(false);
                trainingBtn.setEnabled(false);
            }
        }

        public void insertUpdate(DocumentEvent e) {
            if (inputFilePathTF.getText() != null && !inputFilePathTF.getText().equals("")) {
                testBtn.setEnabled(true);
                trainingBtn.setEnabled(true);
            }
        }
    });

    testingFilePathTF.getDocument().addDocumentListener(new DocumentListener() {
        // implement the methods
        public void changedUpdate(DocumentEvent e) {

        }

        public void removeUpdate(DocumentEvent e) {
            if (e.getDocument().getLength() == 0) {
                applyClassifierBtn.setEnabled(false);
            }
        }

        public void insertUpdate(DocumentEvent e) {
            if (trainingFilePathTF.getText() != null && !trainingFilePathTF.getText().equals("")
                    && inputFilePathTF.getText() != null && !inputFilePathTF.getText().equals("")) {
                applyClassifierBtn.setEnabled(true);
            }
        }
    });

    trainingFilePathTF.getDocument().addDocumentListener(new DocumentListener() {
        // implement the methods
        public void changedUpdate(DocumentEvent e) {

        }

        public void removeUpdate(DocumentEvent e) {
            if (e.getDocument().getLength() == 0) {
                applyClassifierBtn.setEnabled(false);
            }
        }

        public void insertUpdate(DocumentEvent e) {
            if (testingFilePathTF.getText() != null && !testingFilePathTF.getText().equals("")
                    && inputFilePathTF.getText() != null && !inputFilePathTF.getText().equals("")) {
                applyClassifierBtn.setEnabled(true);
            }
        }
    });

    inputFilePathTF.setText(defaulPath + File.separatorChar + "input_test.txt");
    markupFilePathTF.setText(defaulPath + File.separatorChar + "input_test.txt.markup");
    trainingFilePathTF.setText(defaulPath + File.separatorChar + "train.arff");
    testingFilePathTF.setText(defaulPath + File.separatorChar + "test.arff");

}

From source file:bazaar4idea.ui.BzrPullDialog.java

public BzrPullDialog(Project project) {
    super(project, false);
    this.project = project;
    hgRepositorySelector.setTitle("Select repository to pull changesets for");
    hgRepositorySelector.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onChangeRepository();/* w  w w  .  j  av  a2  s .  co m*/
        }
    });
    DocumentListener documentListener = new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            onChangePullSource();
        }

        public void removeUpdate(DocumentEvent e) {
            onChangePullSource();
        }

        public void changedUpdate(DocumentEvent e) {
            onChangePullSource();
        }
    };
    sourceTxt.getDocument().addDocumentListener(documentListener);
    setTitle("Pull");
    init();
}

From source file:com.openbravo.pos.reports.JParamsCustomer.java

/** Creates new form JParamsCustomer */
public JParamsCustomer() {

    initComponents();/* www .  j a  v a 2 s  .c o m*/

    jTextField1.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            currentcustomer = null;
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            currentcustomer = null;
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            currentcustomer = null;
        }
    });
}

From source file:com.mirth.connect.client.ui.editors.MessageBuilder.java

public MessageBuilder(MirthEditorPane p) {
    parent = p;/*from   w w w. j  av a  2 s  .c o  m*/
    initComponents();
    variableTextField.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent arg0) {
        }

        public void insertUpdate(DocumentEvent arg0) {
            updateTable();
            parent.modified = true;
        }

        public void removeUpdate(DocumentEvent arg0) {
            updateTable();
            parent.modified = true;
        }
    });

    mappingTextField.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent arg0) {
        }

        public void insertUpdate(DocumentEvent arg0) {
            parent.modified = true;
        }

        public void removeUpdate(DocumentEvent arg0) {
            parent.modified = true;
        }
    });

    defaultValueTextField.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent arg0) {
        }

        public void insertUpdate(DocumentEvent arg0) {
            parent.modified = true;
        }

        public void removeUpdate(DocumentEvent arg0) {
            parent.modified = true;
        }
    });

    regularExpressionsScrollPane.addMouseListener(new java.awt.event.MouseAdapter() {

        public void mouseClicked(java.awt.event.MouseEvent evt) {
            deselectRows();
        }
    });
    deleteButton.setEnabled(false);
}

From source file:uipackage.MainFrame.java

/**
 * Creates new form MainFrame/* w  w w .  j  ava 2 s  .  co  m*/
 */
public MainFrame() {
    initComponents();
    console.getDocument().addDocumentListener(new DocumentListener() { // LISTENER EDITTEXT

        @Override
        public void insertUpdate(DocumentEvent e) {
            if (g != null) { // IF NOT GRAPH WINDOW CREATED DONT DO NOTHING
                try {
                    //TEXTO MODIFICADO
                    int last = console.getLineCount() - 1;
                    String[] lines = console.getText().split("\\n");
                    g.updateData(lines[last - 1], sensorNumber);
                } catch (InterruptedException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }

    });
}

From source file:com.mirth.connect.connectors.vm.ChannelWriter.java

public ChannelWriter() {
    parent = PlatformUI.MIRTH_FRAME;/*w  ww . ja  va  2 s.  c  o m*/
    initComponents();

    channelIdField.setToolTipText("<html>The destination channel's unique global id.</html>");
    channelIdField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateField();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateField();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateField();
        }

    });

    class CustomTableCellEditor extends TextFieldCellEditor {

        @Override
        protected boolean valueChanged(String value) {
            if ((value.length() == 0 || checkUniqueProperty(value))) {
                return false;
            }

            parent.setSaveEnabled(true);
            return true;
        }

        protected boolean checkUniqueProperty(String property) {
            boolean exists = false;

            for (int rowIndex = 0; rowIndex < mapVariablesTable.getRowCount(); rowIndex++) {
                if (mapVariablesTable.getValueAt(rowIndex, 0) != null
                        && ((String) mapVariablesTable.getValueAt(rowIndex, 0)).equalsIgnoreCase(property)) {
                    exists = true;
                }
            }

            return exists;
        }
    }

    mapVariablesTable.getColumnModel().getColumn(0).setCellEditor(new CustomTableCellEditor());
    mapVariablesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    mapVariablesTable.setToolTipText(
            "The following map variables will be included in the source map of the destination channel's message.");

    mapVariablesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            if (mapVariablesTable.getRowCount() > 0) {
                deleteButton.setEnabled(true);
            } else {
                deleteButton.setEnabled(false);
            }
        }
    });
}

From source file:bazaar4idea.ui.BzrPushDialog.java

public BzrPushDialog(Project project) {
    super(project, false);
    this.project = project;
    hgRepositorySelectorComponent.setTitle("Select repository to push from");
    hgRepositorySelectorComponent.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateRepository();/* ww w  .  ja v  a  2 s .co  m*/
        }
    });

    revisionCbx.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            update();
        }
    });

    DocumentListener documentListener = new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            update();
        }

        public void removeUpdate(DocumentEvent e) {
            update();
        }

        public void changedUpdate(DocumentEvent e) {
            update();
        }
    };

    repositoryTxt.getDocument().addDocumentListener(documentListener);
    revisionTxt.getDocument().addDocumentListener(documentListener);

    setTitle("Push");
    init();
}

From source file:com.igormaznitsa.sciareto.ui.editors.TextEditor.java

public TextEditor(@Nonnull final Context context, @Nullable File file) throws IOException {
    super();/*from   w w  w.  ja va 2 s  . c  om*/
    this.editor = new JTextArea();
    this.title = new TabTitle(context, this, file);

    this.editor.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(@Nonnull final DocumentEvent e) {
            if (!ignoreChange) {
                title.setChanged(true);
            }
        }

        @Override
        public void removeUpdate(@Nonnull final DocumentEvent e) {
            if (!ignoreChange) {
                title.setChanged(true);
            }
        }

        @Override
        public void changedUpdate(@Nonnull final DocumentEvent e) {
            if (!ignoreChange) {
                title.setChanged(true);
            }
        }
    });

    setViewportView(this.editor);

    loadContent(file);
}