Example usage for javax.swing JTextField addActionListener

List of usage examples for javax.swing JTextField addActionListener

Introduction

In this page you can find the example usage for javax.swing JTextField addActionListener.

Prototype

public synchronized void addActionListener(ActionListener l) 

Source Link

Document

Adds the specified action listener to receive action events from this textfield.

Usage

From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java

private JPanel getModelNamePanel(final ModelGraph graph, final ViewState state) {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.setBorder(new EtchedBorder());
    panel.add(new JLabel("ModelName:"), BorderLayout.NORTH);
    JTextField field = new JTextField(graph.getModel().getModelName(), 50);
    field.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (!graph.getModel().getModelName().equals(e.getActionCommand())) {
                // GuiUtils.updateGraphModelName(getState(),
                // graph.getModel().getModelId(), e.getActionCommand());
                graph.getModel().setModelName(e.getActionCommand());
                DefaultPropView.this.notifyListeners();
                DefaultPropView.this.refreshView(state);
            }/*from www  .  j a va2  s.c  o m*/
        }

    });
    panel.add(field, BorderLayout.CENTER);
    return panel;
}

From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java

private JPanel getInstanceClassPanel(final ModelGraph graph, final ViewState state) {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.setBorder(new EtchedBorder());
    panel.add(new JLabel("InstanceClass:"), BorderLayout.NORTH);
    JTextField field = new JTextField(graph.getModel().getInstanceClass(), 50);
    field.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (graph.getModel().getInstanceClass() == null
                    || !graph.getModel().getInstanceClass().equals(e.getActionCommand())) {
                graph.getModel().setInstanceClass(e.getActionCommand());
                DefaultPropView.this.notifyListeners();
                DefaultPropView.this.refreshView(state);
            }//w  ww. j a  va  2 s.c o m
        }

    });
    panel.add(field, BorderLayout.CENTER);
    return panel;
}

From source file:org.broad.igv.cbio.FilterGeneNetworkUI.java

private void add() {
    final AttributeFilter row = new AttributeFilter();

    row.getDelRow().addActionListener(new ActionListener() {
        @Override//from w  w w  .j ava 2  s .co  m
        public void actionPerformed(ActionEvent e) {
            remove(row);
        }
    });

    row.getAddRow().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            add();
        }
    });
    contentPane.add(row.getPanel());

    //We want to refresh the
    RefreshListener listener = new RefreshListener();

    row.getAttrName().addActionListener(listener);
    for (JTextField text : new JTextField[] { row.minVal, row.maxVal }) {
        text.addActionListener(listener);
        text.addFocusListener(listener);
    }

    //Set the status of being last
    if (filterRows.size() >= 1) {
        filterRows.get(filterRows.size() - 1).setIsLast(false);
    }
    filterRows.add(row);

    int numRows = filterRows.size();
    filterRows.get(numRows - 1).setIsLast(true);
    filterRows.get(0).setShowDel(numRows >= 2);

    validate();

}

From source file:org.executequery.gui.browser.ConnectionPanel.java

private void formatTextField(JTextField textField) {
    textField.setActionCommand(CONNECT_ACTION_COMMAND);
    textField.addActionListener(this);
}

From source file:qic.ui.ManualPanel.java

@SuppressWarnings("serial")
public ManualPanel(Main main) {
    super(new BorderLayout(5, 5));

    table.setDoubleBuffered(true);//from  w w  w  . ja va  2 s. co m

    JTextField searchTf = new JTextField(100);
    JButton runBtn = new JButton("Run");
    runBtn.setPreferredSize(new Dimension(200, 10));
    JLabel invalidTermsLblLbl = new JLabel();
    invalidTermsLblLbl.setFont(invalidTermsLblLbl.getFont().deriveFont(Font.BOLD));
    JLabel invalidTermsLbl = new JLabel();
    invalidTermsLbl.setForeground(Color.RED);
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS));
    JLabel searchLbl = new JLabel(" Search: ");
    searchLbl.setFont(searchLbl.getFont().deriveFont(Font.BOLD));
    northPanel.add(searchLbl);
    northPanel.add(searchTf);
    northPanel.add(invalidTermsLblLbl);
    northPanel.add(invalidTermsLbl);
    northPanel.add(runBtn);
    this.add(northPanel, BorderLayout.NORTH);

    List<String> searchList = Util.loadSearchList(MANUAL_TXT_FILENAME);
    searchList.stream().forEach(searchJListModel::addElement);
    searchJList.setModel(searchJListModel);

    searchJList.addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            searchTf.setText(trimToEmpty(searchJList.getSelectedValue()));
        }
    });
    searchJList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                int index = searchJList.locationToIndex(evt.getPoint());
                if (index != -1) {
                    String search = trimToEmpty(searchJListModel.getElementAt(index));
                    searchTf.setText(search);
                    runBtn.doClick();
                }
            }
        }
    });

    searchJList.getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "doSomething");
    searchJList.getActionMap().put("doSomething", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int selectedIndex = searchJList.getSelectedIndex();
            if (selectedIndex != -1) {
                searchJListModel.remove(selectedIndex);
            }
        }
    });

    ActionListener runCommand = e -> {
        String tfText = searchTf.getText().trim();
        if (!tfText.isEmpty()) {
            Worker<Command> worker = new Worker<Command>(() -> {
                runBtn.setEnabled(false);
                Command result = null;
                try {
                    result = runQuery(main, tfText);
                } catch (Exception ex) {
                    runBtn.setEnabled(true);
                    SwingUtil.showError(ex);
                }
                return result;
            }, command -> {
                if (command != null) {
                    if (command.invalidSearchTerms.isEmpty()) {
                        addDataToTable(command);
                        saveSearchToList(tfText);
                        invalidTermsLbl.setText("");
                        invalidTermsLblLbl.setText("");
                        if (getBooleanProperty(MANUAL_AUTO_VERIFY, false)) {
                            long sleep = Config.getLongProperty(Config.MANUAL_AUTO_VERIFY_SLEEP, 5000);
                            table.runAutoVerify(sleep);
                        }
                    } else {
                        String invalidTermsStr = command.invalidSearchTerms.stream().collect(joining(", "));
                        invalidTermsLbl.setText(invalidTermsStr + " ");
                        invalidTermsLblLbl.setText(" Invalid: ");
                    }
                }
                runBtn.setEnabled(true);
            });
            worker.execute();
        }
    };

    searchTf.addActionListener(runCommand);
    runBtn.addActionListener(runCommand);

    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(table),
            new JScrollPane(searchJList));

    this.add(splitPane, BorderLayout.CENTER);
}

From source file:qic.ui.QicFrame.java

public QicFrame(Main main, String query) {
    super("QIC Search - Simple GUI");
    setLayout(new BorderLayout(5, 5));

    RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
    textArea.setText("Enter a command in the textfield then press Enter..");
    textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
    textArea.setCodeFoldingEnabled(true);
    RTextScrollPane sp = new RTextScrollPane(textArea);

    JTextField searchTf = new JTextField(100);
    JButton runBtn = new JButton("Run");
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS));
    northPanel.add(searchTf);/*from  w  w w . ja  va 2s.  c om*/
    northPanel.add(runBtn);
    getContentPane().add(northPanel, BorderLayout.NORTH);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(screenSize.width - 50, screenSize.height - 50);
    setLocationRelativeTo(null);

    searchTf.setText("search bo tmpsc ");
    if (query != null) {
        searchTf.setText(query);
    }

    JTable table = new JTable();
    table.setDefaultRenderer(List.class, new MultiLineTableCellRenderer());

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Table", new JScrollPane(table));
    tabbedPane.addTab("JSON", new JScrollPane(sp));

    BeanPropertyTableModel<SearchResultItem> model = new BeanPropertyTableModel<>(SearchResultItem.class);
    model.setOrderedProperties(asList("id", "buyout", "item", "seller", "reqs", "mods", "q", "APS", "PDPS",
            "EDPS", "DPS", "ele", "phys", "ar", "ev", "ES", "blk", "crit", "lvl"));
    table.setModel(model);
    setColumnWidths(table.getColumnModel(), asList(1, 15, 280, 230, 50, 420));

    getContentPane().add(tabbedPane, BorderLayout.CENTER);

    ActionListener runCommand = e -> {
        String tfText = searchTf.getText();

        Worker<Command> pathNotesWorker = new Worker<Command>(() -> runQuery(main, tfText), command -> {
            String json = command.toJson();
            textArea.setText(json);
            model.setData(command.itemResults);
        }, ex -> {
            String stackTrace = ExceptionUtils.getStackTrace(ex);
            textArea.setText(stackTrace);
            showError(ex);
        });
        pathNotesWorker.execute();
    };

    searchTf.addActionListener(runCommand);
    runBtn.addActionListener(runCommand);

    table.getSelectionModel().addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            int selectedRow = table.getSelectedRow();
            if (selectedRow > -1) {
                SearchResultItem searchResultItem = model.getData().get(selectedRow);
                SwingUtil.copyToClipboard(searchResultItem.wtb());
            }
        }
    });

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:savant.plugin.ToolSettingsPanel.java

private void addField(ToolArgument arg, JTextField field, GridBagConstraints gbc) {
    field.addActionListener(executeListener);
    field.getDocument().addDocumentListener(new EditListener(arg));
    field.setMinimumSize(field.getPreferredSize());
    addWidget(arg, field, gbc);/*ww w  .  ja va 2 s.c o m*/
}

From source file:savant.snp.SNPFinderPlugin.java

private void setupGUI(JPanel panel) {

    // add a toolbar
    JToolBar tb = new JToolBar();
    tb.setName("SNP Finder Toolbar");

    // add an ON/OFF checkbox
    JLabel lab_on = new JLabel("On/Off: ");
    JCheckBox cb_on = new JCheckBox();
    cb_on.setSelected(isSNPFinderOn);//  w  w w  .  java 2 s  .  c  om

    // what to do when a user clicks the checkbox
    cb_on.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // switch the SNP finder on/off
            setIsOn(!isSNPFinderOn);
            addMessage("Turning SNP finder " + (isSNPFinderOn ? "on" : "off"));
        }
    });
    // add a  Bookmarking ON/OFF checkbox
    JLabel lab_bm = new JLabel("Add Bookmarks: ");
    JCheckBox cb_bm = new JCheckBox();
    cb_bm.setSelected(addBookmarks);

    // what to do when a user clicks the checkbox
    cb_bm.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // switch the SNP finder on/off
            setBookmarking(!addBookmarks);
            addMessage("Turning Bookmarking " + (addBookmarks ? "on" : "off"));
        }
    });

    JLabel lab_sp = new JLabel("Heterozygosity: ");
    //add snp prior textfield
    final JTextField snpPriorField = new JTextField(String.valueOf(snpPrior), 4);
    snpPriorField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                setSNPPrior(Double.valueOf(snpPriorField.getText()));
            } catch (NumberFormatException ex) {
                snpPriorField.setText(String.valueOf(snpPrior));
            }
        }
    });
    int tfwidth = 35;
    int tfheight = 22;
    snpPriorField.setPreferredSize(new Dimension(tfwidth, tfheight));
    snpPriorField.setMaximumSize(new Dimension(tfwidth, tfheight));
    snpPriorField.setMinimumSize(new Dimension(tfwidth, tfheight));

    // add a sensitivity slider
    JLabel lab_confidence = new JLabel("Confidence: ");
    final JSlider sens_slider = new JSlider(0, 50);
    sens_slider.setValue(confidence);
    final JLabel lab_confidence_status = new JLabel("" + sens_slider.getValue());

    // what to do when a user slides the slider
    sens_slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            // set the snp finder's sensitivity
            lab_confidence_status.setText("" + sens_slider.getValue());
            setSensitivity(sens_slider.getValue());
        }
    });
    // don't report the new setting until the user stops sliding
    sens_slider.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            addMessage("Changed confidence to " + confidence);
        }
    });

    // add a transparency slider
    JLabel lab_trans = new JLabel("Transparency: ");
    final JSlider trans_slider = new JSlider(0, 100);
    trans_slider.setValue(transparency);
    final JLabel lab_transparency_status = new JLabel("" + trans_slider.getValue());

    // what to do when a user slides the slider
    trans_slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            // set the snp finder's transparency
            lab_transparency_status.setText("" + trans_slider.getValue());
            setTransparency(trans_slider.getValue());
        }
    });

    // don't report the new setting until the user stops sliding
    trans_slider.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            addMessage("Changed transparency to " + transparency);
        }
    });

    // add the components to the GUI
    panel.setLayout(new BorderLayout());
    tb.add(lab_on);
    tb.add(cb_on);
    tb.add(lab_bm);
    tb.add(cb_bm);
    tb.add(new JToolBar.Separator());
    tb.add(lab_sp);
    tb.add(snpPriorField);
    tb.add(new JToolBar.Separator());
    tb.add(lab_confidence);
    tb.add(sens_slider);
    tb.add(lab_confidence_status);

    tb.add(new JToolBar.Separator());

    tb.add(lab_trans);
    tb.add(trans_slider);
    tb.add(lab_transparency_status);

    panel.add(tb, BorderLayout.NORTH);

    // add a text area to the GUI
    info = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(info);
    panel.add(scrollPane, BorderLayout.CENTER);

}