Example usage for java.awt.event ActionEvent ACTION_PERFORMED

List of usage examples for java.awt.event ActionEvent ACTION_PERFORMED

Introduction

In this page you can find the example usage for java.awt.event ActionEvent ACTION_PERFORMED.

Prototype

int ACTION_PERFORMED

To view the source code for java.awt.event ActionEvent ACTION_PERFORMED.

Click Source Link

Document

This event id indicates that a meaningful action occurred.

Usage

From source file:org.tinymediamanager.ui.tvshows.dialogs.TvShowEpisodeChooserDialog.java

public TvShowEpisodeChooserDialog(TvShowEpisode ep, MediaScraper mediaScraper) {
    super(BUNDLE.getString("tvshowepisode.choose"), "episodeChooser"); //$NON-NLS-1$
    setBounds(5, 5, 600, 400);//from   w w w.  ja va  2s  . com

    this.episode = ep;
    this.mediaScraper = mediaScraper;
    this.metadata = new MediaEpisode(mediaScraper.getId());
    episodeEventList = new ObservableElementList<>(
            GlazedLists.threadSafeList(new BasicEventList<TvShowEpisodeChooserModel>()),
            GlazedLists.beanConnector(TvShowEpisodeChooserModel.class));
    sortedEpisodes = new SortedList<>(GlazedListsSwing.swingThreadProxyList(episodeEventList),
            new EpisodeComparator());

    getContentPane().setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("590px:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("200dlu:grow"),
                    FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("fill:37px"),
                    FormSpecs.RELATED_GAP_ROWSPEC, }));
    {
        JSplitPane splitPane = new JSplitPane();
        getContentPane().add(splitPane, "2, 2, fill, fill");

        JPanel panelLeft = new JPanel();
        panelLeft.setLayout(new FormLayout(
                new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("150dlu:grow"),
                        FormSpecs.RELATED_GAP_COLSPEC, },
                new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                        FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                        FormSpecs.RELATED_GAP_ROWSPEC, }));

        textField = EnhancedTextField.createSearchTextField();
        panelLeft.add(textField, "2, 2, fill, default");
        textField.setColumns(10);

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setMinimumSize(new Dimension(200, 23));
        panelLeft.add(scrollPane, "2, 4, fill, fill");
        splitPane.setLeftComponent(panelLeft);

        MatcherEditor<TvShowEpisodeChooserModel> textMatcherEditor = new TextComponentMatcherEditor<>(textField,
                new TvShowEpisodeChooserModelFilterator());
        FilterList<TvShowEpisodeChooserModel> textFilteredEpisodes = new FilterList<>(sortedEpisodes,
                textMatcherEditor);
        AdvancedTableModel<TvShowEpisodeChooserModel> episodeTableModel = GlazedListsSwing
                .eventTableModelWithThreadProxyList(textFilteredEpisodes, new EpisodeTableFormat());
        DefaultEventSelectionModel<TvShowEpisodeChooserModel> selectionModel = new DefaultEventSelectionModel<>(
                textFilteredEpisodes);
        selectedEpisodes = selectionModel.getSelected();

        selectionModel.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) {
                    return;
                }
                // display first selected episode
                if (!selectedEpisodes.isEmpty()) {
                    TvShowEpisodeChooserModel episode = selectedEpisodes.get(0);
                    taPlot.setText(episode.getOverview());
                } else {
                    taPlot.setText("");
                }
                taPlot.setCaretPosition(0);
            }
        });

        table = new JTable(episodeTableModel);
        table.setSelectionModel(selectionModel);
        scrollPane.setViewportView(table);

        JPanel panelRight = new JPanel();
        panelRight.setLayout(new FormLayout(
                new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("150dlu:grow"),
                        FormSpecs.RELATED_GAP_COLSPEC, },
                new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                        FormSpecs.RELATED_GAP_ROWSPEC, }));
        JScrollPane scrollPane_1 = new JScrollPane();
        panelRight.add(scrollPane_1, "2, 2, fill, fill");
        splitPane.setRightComponent(panelRight);

        taPlot = new JTextArea();
        taPlot.setEditable(false);
        taPlot.setWrapStyleWord(true);
        taPlot.setLineWrap(true);
        scrollPane_1.setViewportView(taPlot);
        splitPane.setDividerLocation(300);

    }
    JPanel bottomPanel = new JPanel();
    getContentPane().add(bottomPanel, "2, 4, fill, top");

    bottomPanel.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.LABEL_COMPONENT_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, RowSpec.decode("25px"),
                    FormFactory.RELATED_GAP_ROWSPEC, }));

    JPanel buttonPane = new JPanel();
    bottomPanel.add(buttonPane, "5, 2, fill, fill");
    EqualsLayout layout = new EqualsLayout(5);
    layout.setMinWidth(100);
    buttonPane.setLayout(layout);
    final JButton okButton = new JButton(BUNDLE.getString("Button.ok")); //$NON-NLS-1$
    okButton.setToolTipText(BUNDLE.getString("tvshow.change"));
    okButton.setIcon(IconManager.APPLY);
    buttonPane.add(okButton);
    okButton.setActionCommand("OK");
    okButton.addActionListener(this);

    JButton cancelButton = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$
    cancelButton.setToolTipText(BUNDLE.getString("edit.discard"));
    cancelButton.setIcon(IconManager.CANCEL);
    buttonPane.add(cancelButton);
    cancelButton.setActionCommand("Cancel");
    cancelButton.addActionListener(this);

    // column widths
    table.getColumnModel().getColumn(0).setMaxWidth(50);
    table.getColumnModel().getColumn(1).setMaxWidth(50);

    SearchTask task = new SearchTask();
    task.execute();

    MouseListener mouseListener = new MouseListener() {

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2 && !e.isConsumed() && e.getButton() == MouseEvent.BUTTON1) {
                actionPerformed(new ActionEvent(okButton, ActionEvent.ACTION_PERFORMED, "OK"));
            }
        }

    };
    table.addMouseListener(mouseListener);
}

From source file:org.wings.SAbstractButton.java

/**
 * Fire an ActionEvent at each registered listener.
 *
 * @param event supplied ActionEvent//from w  ww . j  a v a  2 s  .co m
 */
protected void fireActionPerformed(ActionEvent event) {
    // Guaranteed to return a non-null array
    Object[] listeners = getListenerList();
    ActionEvent e = null;
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == ActionListener.class) {
            if (e == null) {
                String actionCommand = event.getActionCommand();
                if (actionCommand == null) {
                    actionCommand = getActionCommand();
                }
                e = new ActionEvent(SAbstractButton.this, ActionEvent.ACTION_PERFORMED, actionCommand,
                        event.getWhen(), event.getModifiers());
            }
            ((ActionListener) listeners[i + 1]).actionPerformed(e);
        }
    }
}

From source file:org.wings.SAbstractButton.java

/**
 * Simulates an click on the Button//  w ww.j  a va  2s. c  o m
 */
public void doClick() {
    setSelected(!isSelected());

    fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, getActionCommand()));
}

From source file:org.wings.SAbstractButton.java

public void fireFinalEvents() {
    requestFocus();/*from  w w w  .ja  v  a2s .  c o m*/
    super.fireFinalEvents();
    fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, getActionCommand()));
    if (buttonGroup != null)
        buttonGroup.fireDelayedFinalEvents();
}

From source file:org.wings.SForm.java

/**
 * Fire a ActionEvent at each registered listener.
 *//*from  w w  w .j a  v a  2 s . c o m*/
protected void fireActionPerformed(String pActionCommand) {
    ActionEvent e = null;
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == ActionListener.class) {
            // lazy create ActionEvent
            if (e == null) {
                e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, pActionCommand);
            }
            ((ActionListener) listeners[i + 1]).actionPerformed(e);
        }
    }
}

From source file:pl.otros.logview.gui.message.editor.MessageColorizerBrowser.java

public MessageColorizerBrowser(OtrosApplication otrosApplication) {
    super(new BorderLayout());
    this.container = otrosApplication.getAllPluginables().getMessageColorizers();
    this.otrosApplication = otrosApplication;

    toolBar = new JToolBar();
    editor = new MessageColorizerEditor(container, otrosApplication.getStatusObserver());
    JLabel noEditable = new JLabel("Selected MessageColorizer is not editable.", SwingConstants.CENTER);
    JLabel nothingSelected = new JLabel("Nothing selected", SwingConstants.CENTER);

    listModel = new PluginableElementListModel<MessageColorizer>(container);
    jList = new JList(listModel);
    jList.setCellRenderer(new PluginableElementNameListRenderer());
    cardLayout = new CardLayout();
    contentPanel = new JPanel(cardLayout);
    contentPanel.add(editor, CARD_LAYOUT_EDITOR);
    contentPanel.add(noEditable, CARD_LAYOUT_NOT_EDITABLE);
    contentPanel.add(nothingSelected, CARD_LAYOUT_NO_SELECTED);
    cardLayout.show(contentPanel, CARD_LAYOUT_NOT_EDITABLE);
    JSplitPane mainSplitPane = new JSplitPane(SwingConstants.VERTICAL, new JScrollPane(jList), contentPanel);
    mainSplitPane.setDividerLocation(220);

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

        @Override//w  ww.  j  a  v a  2 s .  c om
        public void valueChanged(ListSelectionEvent e) {
            showSelected();
            enableDisableButtonsForSelectedColorizer();
        }

    });

    jList.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_DELETE) {
                ActionEvent actionEvent = new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, "");
                deleteAction.actionPerformed(actionEvent);
            }
        }
    });

    JButton createNew = new JButton("Create new", Icons.ADD);
    createNew.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            saveAsButton.setEnabled(false);
            createNew();
        }
    });

    saveButton = new JButton("Save and use", Icons.DISK);
    saveButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            try {
                PropertyPatternMessageColorizer mc = editor.createMessageColorizer();
                File selectedFile = null;
                String f = mc.getFile();
                if (StringUtils.isNotBlank(f)) {
                    selectedFile = new File(mc.getFile());
                } else {
                    int response = chooser.showSaveDialog(MessageColorizerBrowser.this);
                    if (response != JFileChooser.APPROVE_OPTION) {
                        return;
                    }
                    selectedFile = chooser.getSelectedFile();
                    if (!selectedFile.getName().endsWith(".pattern")) {
                        selectedFile = new File(selectedFile.getParentFile(),
                                selectedFile.getName() + ".pattern");
                    }
                }
                removeMessageColorizerWithNullFile();
                applyMessageColorizer(selectedFile);
                saveMessageColorizer(selectedFile);
                jList.setSelectedValue(mc, true);
            } catch (ConfigurationException e1) {
                String errorMessage = String.format("Can't save message colorizer: %s", e1.getMessage());
                LOGGER.severe(errorMessage);
                MessageColorizerBrowser.this.otrosApplication.getStatusObserver().updateStatus(errorMessage,
                        StatusObserver.LEVEL_ERROR);
            }
        }
    });

    saveAsButton = new JButton("Save as", Icons.DISK_PLUS);
    saveAsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                int response = chooser.showSaveDialog(MessageColorizerBrowser.this);
                if (response != JFileChooser.APPROVE_OPTION) {
                    return;
                }
                File selectedFile = chooser.getSelectedFile();
                selectedFile = chooser.getSelectedFile();
                if (!selectedFile.getName().endsWith(".pattern")) {
                    selectedFile = new File(selectedFile.getParentFile(), selectedFile.getName() + ".pattern");
                }
                removeMessageColorizerWithNullFile();
                applyMessageColorizer(selectedFile);
                saveMessageColorizer(selectedFile);
                jList.setSelectedValue(editor.createMessageColorizer(), true);
            } catch (ConfigurationException e1) {
                String errorMessage = String.format("Can't save message colorizer: %s", e1.getMessage());
                LOGGER.severe(errorMessage);
                MessageColorizerBrowser.this.otrosApplication.getStatusObserver().updateStatus(errorMessage,
                        StatusObserver.LEVEL_ERROR);
            }
        }
    });

    useButton = new JButton("Use without saving");
    useButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                removeMessageColorizerWithNullFile();
                applyMessageColorizer(File.createTempFile("messageColorizer", "pattern"));
            } catch (Exception e) {
                LOGGER.severe("Cannot create message colorizer: " + e.getMessage());
            }

        }
    });

    deleteAction = new DeleteSelected(otrosApplication);
    deleteButton = new JButton(deleteAction);

    toolBar.setFloatable(false);
    toolBar.add(createNew);
    toolBar.add(saveButton);
    toolBar.add(saveAsButton);
    toolBar.add(useButton);
    toolBar.add(deleteButton);
    enableDisableButtonsForSelectedColorizer();
    initFileChooser();
    this.add(mainSplitPane);
    this.add(toolBar, BorderLayout.SOUTH);
}

From source file:tvbrowser.ui.filter.dlgs.EditFilterDlg.java

public EditFilterDlg(JFrame parent, FilterList filterList, UserFilter filter) {

    super(parent, true);

    UiUtilities.registerForClosing(this);

    mFilterList = filterList;//from   w  w  w.  j  av a 2s .  co  m
    mParent = parent;
    mFilter = filter;

    JPanel contentPane = (JPanel) getContentPane();
    contentPane.setLayout(new BorderLayout(7, 7));
    contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    if (filter == null) {
        setTitle(mLocalizer.msg("titleNew", "Create filter"));
    } else {
        setTitle(mLocalizer.msg("titleEdit", "Edit filter {0}", filter.toString()));
        mFilterName = filter.toString();
    }

    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS));

    mFilterNameTF = new JTextField(new PlainDocument() {

        public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
            str = str.replaceAll("[\\p{Punct}&&[^_]]", "_");
            super.insertString(offset, str, a);
        }
    }, "", 30);

    mFilterNameTF.getDocument().addDocumentListener(this);
    JPanel panel = new JPanel(new BorderLayout(7, 7));
    panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0));
    panel.add(new JLabel(mLocalizer.msg("filterName", "Filter name:")), BorderLayout.WEST);
    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(mFilterNameTF, BorderLayout.WEST);
    panel.add(panel1, BorderLayout.CENTER);
    northPanel.add(panel);

    mFilterRuleTF = new JTextField();
    mFilterRuleTF.getDocument().addDocumentListener(this);
    mFilterRuleTF.addCaretListener(this);
    panel = new JPanel(new BorderLayout(7, 7));
    panel1 = new JPanel(new BorderLayout());
    panel.add(new JLabel(mLocalizer.msg("ruleString", "Filter rule:")), BorderLayout.WEST);
    JLabel exampleLb = new JLabel(
            mLocalizer.msg("ruleExample", "example: component1 or (component2 and not component3)"));
    Font f = exampleLb.getFont();
    exampleLb.setFont(new Font(f.getName(), Font.ITALIC | Font.PLAIN, f.getSize()));
    panel1.add(exampleLb, BorderLayout.WEST);
    panel.add(panel1, BorderLayout.CENTER);
    northPanel.add(panel);
    northPanel.add(mFilterRuleTF);
    mFilterRuleErrorLb = new JLabel();
    mFilterRuleErrorLb.setForeground(Color.red);
    panel = new JPanel(new BorderLayout(7, 7));
    panel.add(mFilterRuleErrorLb, BorderLayout.WEST);
    mColLb = new JLabel("0");
    panel.add(mColLb, BorderLayout.EAST);
    northPanel.add(panel);

    JPanel filterComponentsPanel = new JPanel(new BorderLayout(7, 7));
    filterComponentsPanel.add(DefaultComponentFactory.getInstance().createSeparator(
            mLocalizer.msg("componentsTitle", "Available filter components:")), BorderLayout.NORTH);
    JPanel btnPanel = new JPanel(new BorderLayout());
    panel1 = new JPanel(new GridLayout(0, 1, 0, 7));

    mNewBtn = new JButton(mLocalizer.msg("newButton", "new"));
    mEditBtn = new JButton(Localizer.getLocalization(Localizer.I18N_EDIT));
    mRemoveBtn = new JButton(Localizer.getLocalization(Localizer.I18N_DELETE));

    mNewBtn.addActionListener(this);
    mEditBtn.addActionListener(this);
    mRemoveBtn.addActionListener(this);

    panel1.add(mNewBtn);
    panel1.add(mEditBtn);
    panel1.add(mRemoveBtn);

    btnPanel.add(panel1, BorderLayout.NORTH);

    mComponentTableModel = new FilterTableModel();

    mRuleTableBox = new JTable(mComponentTableModel);
    mRuleTableBox.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            updateBtns();
        }
    });

    mRuleTableBox.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() >= 2) {
                int row = mRuleTableBox.rowAtPoint(e.getPoint());

                if (mRuleTableBox.getSelectedRow() == row && mEditBtn.isEnabled()) {
                    actionPerformed(new ActionEvent(mEditBtn, ActionEvent.ACTION_PERFORMED,
                            mEditBtn.getActionCommand()));
                }
            }
        }
    });

    mRuleTableBox.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    mRuleTableBox.setShowGrid(false);
    mRuleTableBox.setShowVerticalLines(true);
    mRuleTableBox.getColumnModel().getColumn(0).setPreferredWidth(125);
    mRuleTableBox.getColumnModel().getColumn(1).setPreferredWidth(320);
    //    mRuleTableBox.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    // Dispatchs the KeyEvent to the RootPane for Closing the Dialog.
    // Needed for Java 1.4.
    mRuleTableBox.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                mRuleTableBox.getRootPane().dispatchEvent(e);
            }
        }
    });

    JPanel ruleListBoxPanel = new JPanel(new BorderLayout());
    ruleListBoxPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0));
    ruleListBoxPanel.add(new JScrollPane(mRuleTableBox), BorderLayout.CENTER);

    filterComponentsPanel.add(btnPanel, BorderLayout.EAST);
    filterComponentsPanel.add(ruleListBoxPanel, BorderLayout.CENTER);

    ButtonBarBuilder2 bottomBar = Utilities.createFilterButtonBar();

    mOkBtn = new JButton(Localizer.getLocalization(Localizer.I18N_OK));
    mOkBtn.addActionListener(this);
    getRootPane().setDefaultButton(mOkBtn);

    mCancelBtn = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL));
    mCancelBtn.addActionListener(this);

    bottomBar.addButton(new JButton[] { mOkBtn, mCancelBtn });

    contentPane.add(northPanel, BorderLayout.NORTH);
    contentPane.add(filterComponentsPanel, BorderLayout.CENTER);
    contentPane.add(bottomBar.getPanel(), BorderLayout.SOUTH);

    if (mFilter != null) {
        mFilterNameTF.setText(mFilter.toString());
        mFilterRuleTF.setText(mFilter.getRule());
    }

    FilterComponent[] fc = FilterComponentList.getInstance().getAvailableFilterComponents();

    Arrays.sort(fc, new FilterComponent.NameComparator());

    for (FilterComponent element : fc) {
        mComponentTableModel.addElement(element);
    }

    updateBtns();

    Settings.layoutWindow("editFilterDlg", this, new Dimension(600, 300));
    setVisible(true);
}

From source file:us.daveread.basicquery.BasicQuery.java

/**
 * Copy the selected data cells to the clipboard
 */// w  ww  . j  a va2 s.  c  om
private void copySelectionToClipboard() {
    Action objlCopy;

    try {
        objlCopy = TransferHandler.getCopyAction();
        objlCopy.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_PERFORMED,
                (String) objlCopy.getValue(Action.NAME), EventQueue.getMostRecentEventTime(), 0));
    } catch (Throwable any) {
        LOGGER.error("Failed to copy data to clipboard", any);
        JOptionPane.showMessageDialog(this,
                Resources.getString("errClipboardCopyDataText", any.getClass().getName(),
                        any.getMessage() != null ? any.getMessage() : ""),
                Resources.getString("errClipboardCopyDataTitle"), JOptionPane.ERROR_MESSAGE);
    }
}