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:com.opendoorlogistics.core.utils.ui.FileBrowserPanel.java

private static JTextField createTextField(String initialFilename,
        final FilenameChangeListener filenameChangeListener) {
    JTextField textField = new JTextField();
    if (initialFilename != null) {
        textField.setText(initialFilename);
    }//from  w  w  w .  j ava 2 s  .  c om

    if (filenameChangeListener != null) {
        textField.getDocument().addDocumentListener(new DocumentListener() {

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

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

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

            private void fire() {
                filenameChangeListener.filenameChanged(textField.getText());
            }
        });
    }
    return textField;
}

From source file:biomine.bmvis2.pipeline.TextFilterShower.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    JPanel ret = new JPanel();
    final JTextField filterField = new JTextField();
    ret.add(filterField);/*from w  w w . j ava  2  s .c  o m*/
    filterField.getDocument().addDocumentListener(new DocumentListener() {
        private void update() {
            if (filterField.getText().equals(""))
                return;
            if (filterField.getText().equals(TextFilterShower.this.filter))
                return;
            TextFilterShower.this.filter = filterField.getText();
            v.settingsChanged(false);
        }

        public void insertUpdate(DocumentEvent documentEvent) {
            this.update();
        }

        public void removeUpdate(DocumentEvent documentEvent) {
            this.update();
        }

        public void changedUpdate(DocumentEvent documentEvent) {
            this.update();
        }
    });

    return ret;
}

From source file:net.java.sip.communicator.plugin.propertieseditor.SearchField.java

/**
 * Creates an instance <tt>SearchField</tt>.
 * //from w  w  w. j  a va2 s  . co m
 * @param text the text we would like to enter by default
 * @param sorter the sorter which will be used for filtering.
 */
public SearchField(String text, JTable table) {
    super(text);

    this.table = table;

    ComponentUI ui = getUI();

    if (ui instanceof SearchFieldUI) {
        SearchFieldUI searchFieldUI = (SearchFieldUI) ui;

        searchFieldUI.setCallButtonEnabled(false);
        searchFieldUI.setDeleteButtonEnabled(true);
    }

    setBorder(null);
    setDragEnabled(true);
    setOpaque(false);
    setPreferredSize(new Dimension(100, 25));

    InputMap imap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");

    ActionMap amap = getActionMap();
    @SuppressWarnings("serial")
    AbstractAction escapeAction = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            setText("");
        }
    };

    amap.put("escape", escapeAction);

    getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
            filter(getText());
        }

        public void removeUpdate(DocumentEvent e) {
            filter(getText());
        }
    });

    loadSkin();
}

From source file:biomine.bmvis2.pipeline.TextFilterHider.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    JPanel ret = new JPanel();
    final JTextField filterField = new JTextField();
    ret.add(filterField);//from  w  ww  . j a v  a  2 s.c  o m
    filterField.getDocument().addDocumentListener(new DocumentListener() {
        private void update() {
            if (filterField.getText().equals(""))
                return;
            if (filterField.getText().equals(TextFilterHider.this.filter))
                return;
            TextFilterHider.this.filter = filterField.getText();
            v.settingsChanged(false);
        }

        public void insertUpdate(DocumentEvent documentEvent) {
            this.update();
        }

        public void removeUpdate(DocumentEvent documentEvent) {
            this.update();
        }

        public void changedUpdate(DocumentEvent documentEvent) {
            this.update();
        }
    });

    return ret;
}

From source file:i18nplugin.TranslatorEditor.java

private void createGui() {
    setLayout(new FormLayout("fill:min:grow", "fill:min:grow, pref"));
    CellConstraints cc = new CellConstraints();

    // Top//from   w  w  w .j  a  va2 s . c  om
    PanelBuilder topPanel = new PanelBuilder(new FormLayout("fill:10dlu:grow", "pref, 5dlu, fill:pref:grow"));
    topPanel.setBorder(Borders.DLU4_BORDER);
    topPanel.addSeparator(mLocalizer.msg("original", "Original text"), cc.xy(1, 1));

    mOriginal = new JTextArea();
    mOriginal.setWrapStyleWord(false);
    mOriginal.setEditable(false);

    topPanel.add(new JScrollPane(mOriginal), cc.xy(1, 3));

    // Bottom
    PanelBuilder bottomPanel = new PanelBuilder(
            new FormLayout("fill:10dlu:grow", "pref, 5dlu, fill:pref:grow"));
    bottomPanel.setBorder(Borders.DLU4_BORDER);
    bottomPanel.addSeparator(mLocalizer.msg("translation", "Translation"), cc.xy(1, 1));
    mTranslation = new JTextArea();
    mTranslation.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            updateState();
        }

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

        public void removeUpdate(DocumentEvent e) {
            updateState();
        }
    });
    mOriginal.setBackground(mTranslation.getBackground());
    mOriginal.setForeground(mTranslation.getForeground());

    bottomPanel.add(new JScrollPane(mTranslation), cc.xy(1, 3));

    // Splitpane

    final JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    split.setBorder(null);

    split.setTopComponent(topPanel.getPanel());
    split.setBottomComponent(bottomPanel.getPanel());

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            split.setDividerLocation(0.5);
        }
    });

    add(split, cc.xy(1, 1));

    // translation state
    PanelBuilder panel = new PanelBuilder(new FormLayout("pref, 2dlu, fill:10dlu:grow", "pref, 3dlu, pref"));
    panel.setBorder(Borders.DLU4_BORDER);
    panel.addSeparator(mLocalizer.msg("state", "State"), cc.xyw(1, 1, 3));
    mIcon = new JLabel();
    panel.add(mIcon, cc.xy(1, 3));
    mState = new JLabel("-");
    panel.add(mState, cc.xy(3, 3));

    add(panel.getPanel(), cc.xy(1, 2));
}

From source file:com.atlassian.theplugin.idea.config.serverconfig.GenericServerConfigForm.java

public GenericServerConfigForm(final Project project, final UserCfg defaultUser, final Connector tester) {
    this.project = project;
    $$$setupUI$$$();/*from ww  w.j a v  a2s . c  om*/
    testConnection.addActionListener(
            new TestConnectionListener(project, tester, new TestConnectionListener.ServerDataProvider() {
                public ServerData getServer() {
                    synchronized (GenericServerConfigForm.this) {
                        saveData();
                        ServerData.Builder builder = new ServerData.Builder(serverCfg);
                        builder.defaultUser(defaultUser);
                        return builder.build();
                    }
                }
            }, this));
    serverUrl.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            adjustUrl();
        }
    });

    listener = new DocumentListener() {

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

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

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

    useDefault.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            enableDisableUserPassword();
        }
    });

    cbEnabled.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent changeEvent) {

        }
    });

    urlDocumentListener = new DocumentAdapter() {
        protected void textChanged(DocumentEvent documentEvent) {
            enableDisableSever(false);
        }
    };

    serverName.addFocusListener(new FocusAdapter() {
        public void focusLost(final FocusEvent e) {
            if (StringUtils.stripToEmpty(serverName.getText()).length() == 0) {
                serverName.setText(originalServerName);
            }
        }
    });

    enableDisableSever(true);
    enableDisableUserPassword();
}

From source file:fr.free.hd.servers.gui.PhonemView.java

@Override
protected JComponent createControl() {
    final JPanel view = new JPanel(new BorderLayout());

    Collection<Phonem> phonesList = phonemsDAO.getPhonems();
    Map<String, Phonem> mapList = new HashMap<String, Phonem>();
    for (Phonem phonem : phonesList) {
        mapList.put(phonem.getPhonem(), phonem);
    }// ww  w .  j  av  a 2  s .c  o m

    final StatementListModel model = new StatementListModel(mapList);

    printCommand.setModel(model);
    printCommand.setFace(face);
    copyCommand.setModel(model);
    copyCommand.setFace(face);

    list = new JList(model);
    final JScrollPane sp = new JScrollPane(list);
    final JTextField field = new JTextField();
    field.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

    });

    final PhonemListModel phonemModel = new PhonemListModel((List<Phonem>) phonesList);
    final JList phonemList = new JList(phonemModel);
    final JScrollPane spPhonemList = new JScrollPane(phonemList);
    phonemList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        // private int oldIndex = -1;
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() == false) {
                Phonem innerPhonem = (Phonem) phonemModel.getElementAt(phonemList.getSelectedIndex());
                field.setText(field.getText() + innerPhonem.getPhonem());
            }
        }
    });
    phonemList.setCellRenderer(new PhonemListRenderer());
    list.setCellRenderer(new StatementPhonemListRenderer(face));
    list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    list.setVisibleRowCount(1);

    view.add(spPhonemList, BorderLayout.WEST);
    view.add(sp, BorderLayout.CENTER);
    view.add(field, BorderLayout.SOUTH);

    field.requestFocus();

    return view;
}

From source file:com.mirth.connect.connectors.jdbc.DatabaseReader.java

public DatabaseReader() {
    this.parent = PlatformUI.MIRTH_FRAME;

    try {/*from   w  ww.  j a va2s  . c o  m*/
        drivers = this.parent.mirthClient.getDatabaseDrivers();
    } catch (ClientException e) {
        parent.alertThrowable(this, e);
    }

    initComponents();
    initLayout();

    retryCountField.setDocument(new MirthFieldConstraints(0, false, false, true));
    retryIntervalField.setDocument(new MirthFieldConstraints(0, false, false, true));

    drivers.add(0, new DriverInfo(DatabaseReceiverProperties.DRIVER_DEFAULT,
            DatabaseReceiverProperties.DRIVER_DEFAULT, "", ""));
    String[] driverNames = new String[drivers.size()];

    for (int i = 0; i < drivers.size(); i++) {
        driverNames[i] = drivers.get(i).getName();
    }

    databaseDriverCombobox.setModel(new javax.swing.DefaultComboBoxModel(driverNames));
    fetchSizeField.setDocument(new MirthFieldConstraints(9, false, false, true));

    selectTextPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
    updateTextPane.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);

    DocumentListener documentListener = new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
        }

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

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

    selectTextPane.getDocument().addDocumentListener(documentListener);
    updateTextPane.getDocument().addDocumentListener(documentListener);

    parent.setupCharsetEncodingForConnector(encodingCombobox);
}

From source file:jeplus.gui.JPanel_TrnsysProjectFiles.java

/**
 * Creates new form JPanel_EPlusProjectFiles with parameters
 *//*from   ww  w.java 2 s .  c  om*/
public JPanel_TrnsysProjectFiles(JEPlusFrameMain frame, JEPlusProject project) {
    initComponents();
    MainGUI = frame;
    Project = project;

    this.txtGroupID.setText(Project.getProjectID());
    this.txtGroupNotes.setText(Project.getProjectNotes());
    txtDCKDir.setText(Project.getDCKDir());
    if (Project.getDCKTemplate() != null) {
        cboTemplateFile.setModel(new DefaultComboBoxModel(Project.getDCKTemplate().split("\\s*;\\s*")));
    } else {
        cboTemplateFile.setModel(new DefaultComboBoxModel(new String[] { "Select files..." }));
    }
    txtOutputFileNames.setText(Project.getOutputFileNames());
    txtRviDir.setText(Project.getRVIDir());
    if (Project.getRVIFile() != null) {
        cboRviFile.setModel(new DefaultComboBoxModel(new String[] { Project.getRVIFile() }));
    } else {
        cboRviFile.setModel(new DefaultComboBoxModel(new String[] { "Select a file..." }));
    }

    // Set listeners to text fields
    DL = new DocumentListener() {
        Document DocProjID = txtGroupID.getDocument();
        Document DocProjNotes = txtGroupNotes.getDocument();
        Document DocDCKDir = txtDCKDir.getDocument();
        Document DocOutputFiles = txtOutputFileNames.getDocument();
        Document DocRviDir = txtRviDir.getDocument();

        @Override
        public void insertUpdate(DocumentEvent e) {
            Document src = e.getDocument();
            if (src == DocProjID) {
                Project.setProjectID(txtGroupID.getText());
            } else if (src == DocProjNotes) {
                Project.setProjectNotes(txtGroupNotes.getText());
            } else if (src == DocDCKDir) {
                Project.setDCKDir(txtDCKDir.getText());
            } else if (src == DocOutputFiles) {
                Project.setOutputFileNames(txtOutputFileNames.getText());
            } else if (src == DocRviDir) {
                Project.setRVIDir(txtRviDir.getText());
            }
        }

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

        @Override
        public void changedUpdate(DocumentEvent e) {
            // not applicable
        }
    };
    txtGroupID.getDocument().addDocumentListener(DL);
    txtGroupNotes.getDocument().addDocumentListener(DL);
    txtDCKDir.getDocument().addDocumentListener(DL);
    txtOutputFileNames.getDocument().addDocumentListener(DL);
    txtRviDir.getDocument().addDocumentListener(DL);
}

From source file:components.TableFilterDemo.java

public TableFilterDemo() {
    super();//from  ww w . jav  a  2 s .  c om
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    //Create a table with a sorter.
    MyTableModel model = new MyTableModel();
    sorter = new TableRowSorter<MyTableModel>(model);
    table = new JTable(model);
    table.setRowSorter(sorter);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    //For the purposes of this example, better to have a single
    //selection.
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    //When selection changes, provide user with row numbers for
    //both view and model.
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            int viewRow = table.getSelectedRow();
            if (viewRow < 0) {
                //Selection got filtered away.
                statusText.setText("");
            } else {
                int modelRow = table.convertRowIndexToModel(viewRow);
                statusText.setText(String.format("Selected Row in view: %d. " + "Selected Row in model: %d.",
                        viewRow, modelRow));
            }
        }
    });

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Add the scroll pane to this panel.
    add(scrollPane);

    //Create a separate form for filterText and statusText
    JPanel form = new JPanel(new SpringLayout());
    JLabel l1 = new JLabel("Filter Text:", SwingConstants.TRAILING);
    form.add(l1);
    filterText = new JTextField();
    //Whenever filterText changes, invoke newFilter.
    filterText.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            newFilter();
        }

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

        public void removeUpdate(DocumentEvent e) {
            newFilter();
        }
    });
    l1.setLabelFor(filterText);
    form.add(filterText);
    JLabel l2 = new JLabel("Status:", SwingConstants.TRAILING);
    form.add(l2);
    statusText = new JTextField();
    l2.setLabelFor(statusText);
    form.add(statusText);
    SpringUtilities.makeCompactGrid(form, 2, 2, 6, 6, 6, 6);
    add(form);
}