Search in sources :

Example 51 with DocumentListener

use of javax.swing.event.DocumentListener in project jabref by JabRef.

the class AutoCompleteSupport method install.

/**
     * Inits the autocompletion popup. After this method is called, further input in the specified textbox will be
     * autocompleted.
     */
public void install() {
    // ActionListeners for navigating the suggested autocomplete items with the arrow keys
    final ActionListener upAction = new MoveAction(-1);
    final ActionListener downAction = new MoveAction(1);
    // ActionListener hiding the autocomplete popup
    final ActionListener hidePopupAction = e -> popup.setVisible(false);
    // ActionListener accepting the currently selected item as the autocompletion
    final ActionListener acceptAction = e -> {
        E itemToInsert = renderer.getSelectedItem();
        if (itemToInsert == null) {
            return;
        }
        String toInsert = autoCompleter.getAutoCompleteText(itemToInsert);
        if (!autoCompleter.isSingleUnitField()) {
            int priv = textComp.getText().length() - 1;
            while ((priv >= 0) && !Character.isWhitespace(textComp.getText().charAt(priv)) && (textComp.getText().charAt(priv) != ',')) {
                priv--;
            }
            textComp.setText(textComp.getText().substring(0, priv + 1) + toInsert);
        } else {
            textComp.setText(toInsert);
        }
        textComp.setCaretPosition(textComp.getText().length());
        popup.setVisible(false);
    };
    // Create popup
    popup.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.LIGHT_GRAY));
    popup.setPopupSize(textComp.getWidth(), 200);
    popup.setLayout(new BorderLayout());
    popup.setFocusable(false);
    popup.setRequestFocusEnabled(false);
    popup.add(renderer.init(acceptAction));
    // Listen for changes to the text -> update autocomplete suggestions
    textComp.getDocument().addDocumentListener(new DocumentListener() {

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

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

        @Override
        public void changedUpdate(DocumentEvent e) {
        // Do nothing
        }
    });
    // Listen for up/down arrow keys -> move currently selected item up or down
    // We have to reimplement this function here since we cannot be sure that a simple list will be used to display the items
    // So better let the renderer decide what to do.
    // (Moreover, the list does not have the focus so probably would not recognize the keystrokes in the first place.)
    textComp.registerKeyboardAction(downAction, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), JComponent.WHEN_FOCUSED);
    textComp.registerKeyboardAction(upAction, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), JComponent.WHEN_FOCUSED);
    // Listen for ESC key -> hide popup
    textComp.registerKeyboardAction(hidePopupAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    // Listen to focus events -> select all the text on gaining the focus
    this.textComp.addFocusListener(new ComboBoxEditorFocusHandler());
    // Listen for ENTER key if popup is visible -> accept current autocomplete suggestion
    popup.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            textComp.registerKeyboardAction(acceptAction, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            textComp.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
        // Do nothing
        }
    });
}
Also used : Color(java.awt.Color) JComponent(javax.swing.JComponent) KeyStroke(javax.swing.KeyStroke) ActionListener(java.awt.event.ActionListener) DocumentListener(javax.swing.event.DocumentListener) AutoCompleter(org.jabref.logic.autocompleter.AutoCompleter) JPopupMenu(javax.swing.JPopupMenu) BorderFactory(javax.swing.BorderFactory) PopupMenuListener(javax.swing.event.PopupMenuListener) KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) JTextComponent(javax.swing.text.JTextComponent) FocusAdapter(java.awt.event.FocusAdapter) List(java.util.List) AbstractAction(javax.swing.AbstractAction) PopupMenuEvent(javax.swing.event.PopupMenuEvent) FocusEvent(java.awt.event.FocusEvent) BorderLayout(java.awt.BorderLayout) DocumentEvent(javax.swing.event.DocumentEvent) DocumentListener(javax.swing.event.DocumentListener) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout) PopupMenuListener(javax.swing.event.PopupMenuListener) DocumentEvent(javax.swing.event.DocumentEvent) PopupMenuEvent(javax.swing.event.PopupMenuEvent)

Example 52 with DocumentListener

use of javax.swing.event.DocumentListener in project pcgen by PCGen.

the class DiceBagView method initComponents.

/**
	 * <p>Initializes the view and all components, and starts the bag in
	 * editing mode.  It sets the size ({@code pack()}) of the
	 * internal frame, but does <b>not</b> show the frame.</p>
	 *
	 *
	 */
private void initComponents() {
    /*
		 *     /////////////////////////////////
		 *     // Expr [             ] [roll] //
		 *     // |RESULT            | [edit] //
		 *     /////////////////////////////////
		 *     //  [ expr ] [ expr ] [ expr ] //
		 *     //  [ expr ] [ expr ] [ expr ] //
		 *     //  [ expr ] [ expr ] [ expr ] //
		 *     //  [ expr ] [ expr ] [ expr ] //
		 *     //  [ expr ] [ expr ] [ expr ] //
		 *     //  [ expr ] [ expr ] [ expr ] //
		 *     /////////////////////////////////
		 */
    // Set basic properties
    setTitle(m_bag.getName());
    setResizable(true);
    setClosable(true);
    setMaximizable(true);
    setIconifiable(true);
    // Assure main panes content borderlayout
    getContentPane().setLayout(new BorderLayout());
    //Create all JPanels
    m_top = new JPanel();
    m_topTop = new JPanel();
    m_topBottom = new JPanel();
    m_center = new JPanel();
    //Set Layout managers for all panels
    m_top.setLayout(new GridLayout(2, 1));
    m_topTop.setLayout(new BoxLayout(m_topTop, BoxLayout.X_AXIS));
    m_topBottom.setLayout(new BoxLayout(m_topBottom, BoxLayout.X_AXIS));
    m_center.setLayout(new DiceBagGridLayout(0, 3, DiceBagGridLayout.MANAGE_BY_COLUMNS, 75, 100));
    m_center.setBorder(new EmptyBorder(5, 5, 5, 5));
    //Rolling mode controls
    m_rollButton = new JButton("Roll");
    m_rollButton.setActionCommand("ROLL");
    m_rollButton.addActionListener(m_bagListener);
    m_exprResult = new JLabel(" ");
    m_exprResult.setMinimumSize(new Dimension(50, m_exprResult.getMinimumSize().height));
    m_exprResult.setPreferredSize(new Dimension(50, m_exprResult.getPreferredSize().height));
    m_exprResult.setMaximumSize(new Dimension(Integer.MAX_VALUE, m_exprResult.getMaximumSize().height));
    m_editButton = new JButton("Edit");
    m_editButton.setActionCommand("EDIT");
    m_editButton.addActionListener(m_bagListener);
    m_diceButtons = new ArrayList<>();
    m_exprField = new JTextField();
    m_exprFieldLabel = new JLabel("Roll Expr: ");
    //Components for editing mode
    m_table = new JTable(m_tableModel);
    m_scrollPane = new JScrollPane(m_table);
    /*
		 * stop editing button
		 * delete selected button
		 * move up button
		 * move down button
		 */
    m_stopEditing = new JButton("Stop Editing");
    m_stopEditing.setActionCommand("STOP_EDITING");
    m_stopEditing.addActionListener(m_bagListener);
    m_deleteSelected = new JButton("Delete");
    m_deleteSelected.setActionCommand("DELETE");
    m_deleteSelected.addActionListener(m_bagListener);
    m_moveUp = new JButton("Move up");
    m_moveUp.setActionCommand("MOVE_UP");
    m_moveUp.addActionListener(m_bagListener);
    m_moveDown = new JButton("Move down");
    m_moveDown.setActionCommand("MOVE_DOWN");
    m_moveDown.addActionListener(m_bagListener);
    m_nameField = new JTextField();
    m_nameFieldLabel = new JLabel("Name: ");
    m_nameField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            m_bag.setName(m_nameField.getText());
            setTitle(m_nameField.getText());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            m_bag.setName(m_nameField.getText());
            setTitle(m_nameField.getText());
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        // TODO:  Method doesn't do anything?
        }
    });
    setFrameIcon(Icons.gmgen_icon.getImageIcon());
    //Start in rolling mode
    setupRollingMode();
    //Size and position the window
    pack();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) DocumentListener(javax.swing.event.DocumentListener) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) EmptyBorder(javax.swing.border.EmptyBorder)

Example 53 with DocumentListener

use of javax.swing.event.DocumentListener in project beast-mcmc by beast-dev.

the class TaxonSetPanel method initPanel.

protected void initPanel(Action addTaxonSetAction, Action removeTaxonSetAction) {
    JScrollPane scrollPane1 = new JScrollPane(taxonSetsTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    ActionPanel actionPanel1 = new ActionPanel(false);
    actionPanel1.setAddAction(addTaxonSetAction);
    actionPanel1.setRemoveAction(removeTaxonSetAction);
    addTaxonSetAction.setEnabled(false);
    removeTaxonSetAction.setEnabled(false);
    JPanel controlPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    controlPanel1.add(actionPanel1);
    // Excluded Taxon List
    excludedTaxaTableModel = new TaxaTableModel(false);
    excludedTaxaTable = new JTable(excludedTaxaTableModel);
    excludedTaxaTable.getColumnModel().getColumn(0).setCellRenderer(new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));
    excludedTaxaTable.getColumnModel().getColumn(0).setMinWidth(20);
    excludedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            excludedTaxaTableSelectionChanged();
        }
    });
    JScrollPane scrollPane2 = new JScrollPane(excludedTaxaTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    includedTaxonSetsComboBox = new JComboBox(new String[] { TAXON.toLowerCase() + "..." });
    excludedTaxonSetsComboBox = new JComboBox(new String[] { TAXON.toLowerCase() + "..." });
    includedTaxaLabel.setText("");
    excludedTaxaLabel.setText("");
    Box panel1 = new Box(BoxLayout.X_AXIS);
    panel1.add(new JLabel("Select: "));
    panel1.setOpaque(false);
    excludedTaxonSetsComboBox.setOpaque(false);
    panel1.add(excludedTaxonSetsComboBox);
    // Included Taxon List
    includedTaxaTableModel = new TaxaTableModel(true);
    includedTaxaTable = new JTable(includedTaxaTableModel);
    includedTaxaTable.getColumnModel().getColumn(0).setCellRenderer(new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));
    includedTaxaTable.getColumnModel().getColumn(0).setMinWidth(20);
    includedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent evt) {
            includedTaxaTableSelectionChanged();
        }
    });
    includedTaxaTable.doLayout();
    JScrollPane scrollPane3 = new JScrollPane(includedTaxaTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    Box panel2 = new Box(BoxLayout.X_AXIS);
    panel2.add(new JLabel("Select: "));
    panel2.setOpaque(false);
    includedTaxonSetsComboBox.setOpaque(false);
    panel2.add(includedTaxonSetsComboBox);
    Icon includeIcon = null, excludeIcon = null;
    try {
        includeIcon = new ImageIcon(IconUtils.getImage(BeautiApp.class, "images/include.png"));
        excludeIcon = new ImageIcon(IconUtils.getImage(BeautiApp.class, "images/exclude.png"));
    } catch (Exception e) {
    // do nothing
    }
    JPanel buttonPanel = createAddRemoveButtonPanel(includeTaxonAction, includeIcon, "Include selected " + TAXA.toLowerCase() + " in the " + TAXON.toLowerCase(), excludeTaxonAction, excludeIcon, "Exclude selected " + TAXA.toLowerCase() + " from the " + TAXON.toLowerCase(), BoxLayout.Y_AXIS);
    taxonSetEditingPanel = new JPanel();
    taxonSetEditingPanel.setBorder(BorderFactory.createTitledBorder(""));
    taxonSetEditingPanel.setOpaque(false);
    taxonSetEditingPanel.setLayout(new GridBagLayout());
    excludedTaxaSearchField.setColumns(12);
    excludedTaxaSearchField.putClientProperty("JTextField.variant", "search");
    excludedTaxaSearchField.putClientProperty("Quaqua.TextField.style", "search");
    excludedTaxaSearchField.putClientProperty("Quaqua.TextField.sizeVariant", "small");
    includedTaxaSearchField.setColumns(12);
    includedTaxaSearchField.putClientProperty("JTextField.variant", "search");
    includedTaxaSearchField.putClientProperty("Quaqua.TextField.style", "search");
    includedTaxaSearchField.putClientProperty("Quaqua.TextField.sizeVariant", "small");
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0.5;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(3, 6, 3, 0);
    taxonSetEditingPanel.add(excludedTaxaSearchField, c);
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 0.5;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 6, 0, 0);
    taxonSetEditingPanel.add(scrollPane2, c);
    c.gridx = 0;
    c.gridy = 2;
    c.weightx = 0.5;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 6, 3, 0);
    taxonSetEditingPanel.add(excludedTaxaLabel, c);
    c.gridx = 0;
    c.gridy = 3;
    c.weightx = 0.5;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 6, 3, 0);
    taxonSetEditingPanel.add(panel1, c);
    c.gridx = 1;
    c.gridy = 0;
    c.weightx = 0;
    c.weighty = 1;
    c.gridheight = 4;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(12, 2, 12, 4);
    taxonSetEditingPanel.add(buttonPanel, c);
    c.gridx = 2;
    c.gridy = 0;
    c.weightx = 0.5;
    c.weighty = 0;
    c.gridheight = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(3, 0, 3, 6);
    taxonSetEditingPanel.add(includedTaxaSearchField, c);
    c.gridx = 2;
    c.gridy = 1;
    c.weightx = 0.5;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 0, 0, 6);
    taxonSetEditingPanel.add(scrollPane3, c);
    c.gridx = 2;
    c.gridy = 2;
    c.weightx = 0.5;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 0, 3, 6);
    taxonSetEditingPanel.add(includedTaxaLabel, c);
    c.gridx = 2;
    c.gridy = 3;
    c.weightx = 0.5;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 0, 3, 6);
    taxonSetEditingPanel.add(panel2, c);
    JPanel panel3 = new JPanel();
    panel3.setOpaque(false);
    panel3.setLayout(new GridBagLayout());
    c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0.5;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 0, 2, 12);
    panel3.add(scrollPane1, c);
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 0;
    c.weighty = 0;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(2, 0, 0, 12);
    panel3.add(actionPanel1, c);
    c.gridx = 1;
    c.gridy = 0;
    c.weightx = 0.5;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 0, 0, 0);
    panel3.add(taxonSetEditingPanel, c);
    setOpaque(false);
    setBorder(new BorderUIResource.EmptyBorderUIResource(new Insets(12, 12, 12, 12)));
    setLayout(new BorderLayout(0, 0));
    add(panel3, BorderLayout.CENTER);
    //		taxonSetsTable.addMouseListener(new MouseAdapter() {
    //			public void mouseClicked(MouseEvent e) {
    //				if (e.getClickCount() == 2) {
    //					JTable target = (JTable)e.getSource();
    //					int row = target.getSelectedRow();
    //					taxonSetsTableDoubleClicked(row);
    //				}
    //			}
    //		});
    includedTaxaSearchField.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
            selectIncludedTaxa(includedTaxaSearchField.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            selectIncludedTaxa(includedTaxaSearchField.getText());
        }

        public void insertUpdate(DocumentEvent e) {
            selectIncludedTaxa(includedTaxaSearchField.getText());
        }
    });
    excludedTaxaSearchField.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
            selectExcludedTaxa(excludedTaxaSearchField.getText());
        }

        public void removeUpdate(DocumentEvent e) {
            selectExcludedTaxa(excludedTaxaSearchField.getText());
        }

        public void insertUpdate(DocumentEvent e) {
            selectExcludedTaxa(excludedTaxaSearchField.getText());
        }
    });
    includedTaxaTable.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                includeSelectedTaxa();
            }
        }
    });
    excludedTaxaTable.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                excludeSelectedTaxa();
            }
        }
    });
    includedTaxaTable.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent focusEvent) {
            excludedTaxaTable.clearSelection();
        }
    });
    excludedTaxaTable.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent focusEvent) {
            includedTaxaTable.clearSelection();
        }
    });
    includedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (!includedSelectionChanging) {
                if (includedTaxonSetsComboBox.getSelectedIndex() != 0) {
                    includedTaxonSetsComboBox.setSelectedIndex(0);
                }
                includedTaxaSearchField.setText("");
            }
        }
    });
    includedTaxonSetsComboBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            includedSelectionChanging = true;
            includedTaxaTable.clearSelection();
            if (includedTaxonSetsComboBox.getSelectedIndex() > 0) {
                String taxaName = includedTaxonSetsComboBox.getSelectedItem().toString();
                if (!taxaName.endsWith("...")) {
                    Taxa taxa = options.getTaxa(taxaName);
                    if (taxa != null) {
                        for (int i = 0; i < taxa.getTaxonCount(); i++) {
                            Taxon taxon = taxa.getTaxon(i);
                            int index = includedTaxa.indexOf(taxon);
                            includedTaxaTable.getSelectionModel().addSelectionInterval(index, index);
                        }
                    }
                }
            }
            includedSelectionChanging = false;
        }
    });
    excludedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (!excludedSelectionChanging) {
                if (excludedTaxonSetsComboBox.getSelectedIndex() != 0) {
                    excludedTaxonSetsComboBox.setSelectedIndex(0);
                }
                excludedTaxaSearchField.setText("");
            }
        }
    });
    excludedTaxonSetsComboBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            excludedSelectionChanging = true;
            excludedTaxaTable.clearSelection();
            if (excludedTaxonSetsComboBox.getSelectedIndex() > 0) {
                String taxaName = excludedTaxonSetsComboBox.getSelectedItem().toString();
                if (!taxaName.endsWith("...")) {
                    Taxa taxa = options.getTaxa(taxaName);
                    if (taxa != null) {
                        for (int i = 0; i < taxa.getTaxonCount(); i++) {
                            Taxon taxon = taxa.getTaxon(i);
                            int index = excludedTaxa.indexOf(taxon);
                            excludedTaxaTable.getSelectionModel().addSelectionInterval(index, index);
                        }
                    }
                }
            }
            excludedSelectionChanging = false;
        }
    });
    includedTaxaTable.doLayout();
    excludedTaxaTable.doLayout();
}
Also used : DocumentListener(javax.swing.event.DocumentListener) BorderUIResource(javax.swing.plaf.BorderUIResource) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Taxa(dr.evolution.util.Taxa) TableRenderer(jam.table.TableRenderer) Taxon(dr.evolution.util.Taxon) DocumentEvent(javax.swing.event.DocumentEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionPanel(jam.panels.ActionPanel)

Example 54 with DocumentListener

use of javax.swing.event.DocumentListener in project processdash by dtuma.

the class FileSystemLOCDiffPanel method buildConfigPanel.

private Component buildConfigPanel() {
    DocumentListener dl = (DocumentListener) EventHandler.create(DocumentListener.class, this, "recalculateEnablement");
    compareOption = new JRadioButton(getRes("Compare_Two"));
    countOneOption = new JRadioButton(getRes("Count_One"));
    compareOption.setSelected(true);
    new OptionCoordinator();
    fileAPrompt = new JLabel(getRes("Compare_A"));
    fileA = new JTextField();
    fileA.getDocument().addDocumentListener(dl);
    browseA = new JButton(resources.getDlgString("Browse"));
    browseA.addActionListener(this);
    fileB = new JTextField();
    fileB.getDocument().addDocumentListener(dl);
    browseB = new JButton(resources.getDlgString("Browse"));
    browseB.addActionListener(this);
    countIdentical = new JCheckBox(resources.getString("Dialog.Count_Unchanged"));
    countIdentical.setEnabled(false);
    fileBBox = BoxUtils.vbox(hbox(getRes("Compare_B"), GLUE), 5, hbox(PAD, fileB, 5, browseB), GLUE, hbox(PAD, countIdentical, GLUE), GLUE);
    return BoxUtils.vbox(hbox(GLUE, compareOption, GLUE, countOneOption, GLUE), GLUE, hbox(fileAPrompt, 150, GLUE), 5, hbox(PAD, fileA, 5, browseA), GLUE, fileBBox);
}
Also used : JCheckBox(javax.swing.JCheckBox) DocumentListener(javax.swing.event.DocumentListener) JRadioButton(javax.swing.JRadioButton) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField)

Example 55 with DocumentListener

use of javax.swing.event.DocumentListener in project processdash by dtuma.

the class TimeCardDialog method buildTopPanel.

private Component buildTopPanel() {
    Box result = Box.createHorizontalBox();
    result.add(new JLabel(resources.getString("Time_Card.Month_Label") + " "));
    // We have to build our own month name array because the "official"
    // one contains 13 month names, the last one empty for Gregorian
    // Calendars
    String[] monthNames = new String[12];
    String[] officialMonthNames = (new DateFormatSymbols()).getMonths();
    for (int i = 12; i-- > 0; ) monthNames[i] = officialMonthNames[i];
    monthField = new JComboBox(monthNames);
    dontGrow(monthField);
    monthField.setSelectedIndex(model.getMonth() - Calendar.JANUARY);
    monthField.setMaximumRowCount(12);
    result.add(monthField);
    monthField.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            recalc();
        }
    });
    yearField = new JTextField(5);
    dontGrow(yearField);
    yearField.setText(Integer.toString(model.getYear()));
    result.add(yearField);
    yearField.getDocument().addDocumentListener(new DocumentListener() {

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

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

        public void changedUpdate(DocumentEvent e) {
            recalc();
        }
    });
    result.add(Box.createHorizontalGlue());
    result.add(new JLabel(resources.getString("Time_Format.Label") + " "));
    formatType = new JComboBox();
    formatType.addItem(format(75, HOURS_MINUTES));
    formatType.addItem(format(75, HOURS));
    formatType.addItem(format(75, MINUTES));
    dontGrow(formatType);
    result.add(formatType);
    formatType.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            redraw();
        }
    });
    result.add(Box.createHorizontalGlue());
    hideColumns = new JCheckBox();
    result.add(new JLabel(" " + resources.getString("Time_Card.Hide_Empty_Columns_Label") + " "));
    result.add(hideColumns);
    hideColumns.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            resizeColumns();
        }
    });
    result.add(Box.createHorizontalGlue());
    JButton closeButton = new JButton(resources.getString("Close"));
    dontGrow(closeButton);
    result.add(Box.createVerticalStrut(closeButton.getPreferredSize().height + 4));
    result.add(closeButton);
    closeButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            frame.setVisible(false);
        }
    });
    return result;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) DateFormatSymbols(java.text.DateFormatSymbols)

Aggregations

DocumentListener (javax.swing.event.DocumentListener)55 DocumentEvent (javax.swing.event.DocumentEvent)53 ActionEvent (java.awt.event.ActionEvent)19 ActionListener (java.awt.event.ActionListener)17 JTextField (javax.swing.JTextField)14 JPanel (javax.swing.JPanel)12 JButton (javax.swing.JButton)11 JLabel (javax.swing.JLabel)9 JCheckBox (javax.swing.JCheckBox)8 ZapTextField (org.zaproxy.zap.utils.ZapTextField)7 Dimension (java.awt.Dimension)6 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)5 GridBagLayout (java.awt.GridBagLayout)5 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)4 BorderLayout (java.awt.BorderLayout)4 GridBagConstraints (java.awt.GridBagConstraints)4 KeyEvent (java.awt.event.KeyEvent)4 JTextArea (javax.swing.JTextArea)4 DocumentAdapter (com.intellij.ui.DocumentAdapter)3 Insets (java.awt.Insets)3