Example usage for java.awt.event ActionEvent ActionEvent

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

Introduction

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

Prototype

public ActionEvent(Object source, int id, String command) 

Source Link

Document

Constructs an ActionEvent object.

Usage

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

private void selectionChart(DBBrowserNode selectedNode, MouseEvent e, boolean pressed) {
    OpenChartAction openAction = new OpenChartAction();
    openAction.setChartName(selectedNode.getDBObject().getName());
    openAction.setChartPath(selectedNode.getDBObject().getAbsolutePath());

    if (e.getClickCount() == 2) {
        if (pressed) {
            openAction.actionPerformed(new ActionEvent(e.getSource(), e.getID(), ""));
        }//w  ww  . j  av  a  2 s.  co m

    } else {
        JPopupMenu popupMenu = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem(openAction);
        popupMenu.add(menuItem);

        DeleteChartAction deleteAction = new DeleteChartAction(instance, selectedNode);
        JMenuItem menuItem2 = new JMenuItem(deleteAction);
        popupMenu.add(menuItem2);

        RenameChartAction renameAction = new RenameChartAction(instance, selectedNode);
        JMenuItem menuItem3 = new JMenuItem(renameAction);
        popupMenu.add(menuItem3);

        ExportChartAction exportAction = new ExportChartAction(instance, selectedNode);
        JMenuItem menuItem4 = new JMenuItem(exportAction);
        popupMenu.add(menuItem4);

        Chart chart = ChartUtil.loadChart(selectedNode.getDBObject().getAbsolutePath());
        PreviewChartAction previewHTML5Action = new PreviewChartAction(ChartRunner.GRAPHIC_FORMAT,
                ChartRunner.HTML5_TYPE, I18NSupport.getString("preview.html5"));
        previewHTML5Action.setChart(chart);
        popupMenu.add(previewHTML5Action);
        PreviewChartAction previewFlashAction = new PreviewChartAction(ChartRunner.GRAPHIC_FORMAT,
                ChartRunner.FLASH_TYPE, I18NSupport.getString("preview.flash"));
        previewFlashAction.setChart(chart);
        popupMenu.add(previewFlashAction);
        previewFlashAction.setEnabled(!ChartType.hasNoFlashSupport(chart.getType().getType()));
        PreviewChartAction previewImageAction = new PreviewChartAction(ChartRunner.IMAGE_FORMAT,
                ChartRunner.NO_TYPE, I18NSupport.getString("preview.image"));
        previewImageAction.setChart(chart);
        popupMenu.add(previewImageAction);

        PublishChartAction publishAction = new PublishChartAction(selectedNode.getDBObject().getAbsolutePath());
        JMenuItem menuItem5 = new JMenuItem(publishAction);
        popupMenu.add(menuItem5);

        JMenuItem menuItem6 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject()));
        popupMenu.add(menuItem6);

        JMenuItem menuItem7 = new JMenuItem(new AddToFavoritesAction(selectedNode.getDBObject()));
        popupMenu.add(menuItem7);

        popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
    }
}

From source file:net.sf.jabref.util.Util.java

/**
 * Automatically add links for this set of entries, based on the globally stored list of external file types. The
 * entries are modified, and corresponding UndoEdit elements added to the NamedCompound given as argument.
 * Furthermore, all entries which are modified are added to the Set of entries given as an argument.
 * <p>//  w w  w . j av a2s  .  co m
 * The entries' bibtex keys must have been set - entries lacking key are ignored. The operation is done in a new
 * thread, which is returned for the caller to wait for if needed.
 *
 * @param entries          A collection of BibEntry objects to find links for.
 * @param ce               A NamedCompound to add UndoEdit elements to.
 * @param changedEntries   MODIFIED, optional. A Set of BibEntry objects to which all modified entries is added.
 *                         This is used for status output and debugging
 * @param singleTableModel UGLY HACK. The table model to insert links into. Already existing links are not
 *                         duplicated or removed. This parameter has to be null if entries.count() != 1. The hack has been
 *                         introduced as a bibtexentry does not (yet) support the function getListTableModel() and the
 *                         FileListEntryEditor editor holds an instance of that table model and does not reconstruct it after the
 *                         search has succeeded.
 * @param metaData         The MetaData providing the relevant file directory, if any.
 * @param callback         An ActionListener that is notified (on the event dispatch thread) when the search is finished.
 *                         The ActionEvent has id=0 if no new links were added, and id=1 if one or more links were added. This
 *                         parameter can be null, which means that no callback will be notified.
 * @param diag             An instantiated modal JDialog which will be used to display the progress of the autosetting. This
 *                         parameter can be null, which means that no progress update will be shown.
 * @return the thread performing the autosetting
 */
public static Runnable autoSetLinks(final Collection<BibEntry> entries, final NamedCompound ce,
        final Set<BibEntry> changedEntries, final FileListTableModel singleTableModel, final MetaData metaData,
        final ActionListener callback, final JDialog diag) {
    final Collection<ExternalFileType> types = ExternalFileTypes.getInstance().getExternalFileTypeSelection();
    if (diag != null) {
        final JProgressBar prog = new JProgressBar(JProgressBar.HORIZONTAL, 0, types.size() - 1);
        final JLabel label = new JLabel(Localization.lang("Searching for files"));
        prog.setIndeterminate(true);
        prog.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        diag.setTitle(Localization.lang("Autosetting links"));
        diag.getContentPane().add(prog, BorderLayout.CENTER);
        diag.getContentPane().add(label, BorderLayout.SOUTH);

        diag.pack();
        diag.setLocationRelativeTo(diag.getParent());
    }

    Runnable r = new Runnable() {

        @Override
        public void run() {
            // determine directories to search in
            List<File> dirs = new ArrayList<>();
            List<String> dirsS = metaData.getFileDirectory(Globals.FILE_FIELD);
            for (String dirs1 : dirsS) {
                dirs.add(new File(dirs1));
            }

            // determine extensions
            Collection<String> extensions = new ArrayList<>();
            for (final ExternalFileType type : types) {
                extensions.add(type.getExtension());
            }

            // Run the search operation:
            Map<BibEntry, List<File>> result;
            if (Globals.prefs.getBoolean(JabRefPreferences.AUTOLINK_USE_REG_EXP_SEARCH_KEY)) {
                String regExp = Globals.prefs.get(JabRefPreferences.REG_EXP_SEARCH_EXPRESSION_KEY);
                result = RegExpFileSearch.findFilesForSet(entries, extensions, dirs, regExp);
            } else {
                result = FileUtil.findAssociatedFiles(entries, extensions, dirs);
            }

            boolean foundAny = false;
            // Iterate over the entries:
            for (Entry<BibEntry, List<File>> entryFilePair : result.entrySet()) {
                FileListTableModel tableModel;
                String oldVal = entryFilePair.getKey().getField(Globals.FILE_FIELD);
                if (singleTableModel == null) {
                    tableModel = new FileListTableModel();
                    if (oldVal != null) {
                        tableModel.setContent(oldVal);
                    }
                } else {
                    assert entries.size() == 1;
                    tableModel = singleTableModel;
                }
                List<File> files = entryFilePair.getValue();
                for (File f : files) {
                    f = FileUtil.shortenFileName(f, dirsS);
                    boolean alreadyHas = false;
                    //System.out.println("File: "+f.getPath());
                    for (int j = 0; j < tableModel.getRowCount(); j++) {
                        FileListEntry existingEntry = tableModel.getEntry(j);
                        //System.out.println("Comp: "+existingEntry.getLink());
                        if (new File(existingEntry.link).equals(f)) {
                            alreadyHas = true;
                            break;
                        }
                    }
                    if (!alreadyHas) {
                        foundAny = true;
                        ExternalFileType type;
                        Optional<String> extension = FileUtil.getFileExtension(f);
                        if (extension.isPresent()) {
                            type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension.get());
                        } else {
                            type = new UnknownExternalFileType("");
                        }
                        FileListEntry flEntry = new FileListEntry(f.getName(), f.getPath(), type);
                        tableModel.addEntry(tableModel.getRowCount(), flEntry);

                        String newVal = tableModel.getStringRepresentation();
                        if (newVal.isEmpty()) {
                            newVal = null;
                        }
                        if (ce != null) {
                            // store undo information
                            UndoableFieldChange change = new UndoableFieldChange(entryFilePair.getKey(),
                                    Globals.FILE_FIELD, oldVal, newVal);
                            ce.addEdit(change);
                        }
                        // hack: if table model is given, do NOT modify entry
                        if (singleTableModel == null) {
                            entryFilePair.getKey().setField(Globals.FILE_FIELD, newVal);
                        }
                        if (changedEntries != null) {
                            changedEntries.add(entryFilePair.getKey());
                        }
                    }
                }
            }

            // handle callbacks and dialog
            // FIXME: The ID signals if action was successful :/
            final int id = foundAny ? 1 : 0;
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    if (diag != null) {
                        diag.dispose();
                    }
                    if (callback != null) {
                        callback.actionPerformed(new ActionEvent(this, id, ""));
                    }
                }
            });
        }
    };
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            // show dialog which will be hidden when the task is done
            if (diag != null) {
                diag.setVisible(true);
            }
        }
    });
    return r;
}

From source file:canreg.client.gui.components.PreviewFilePanel.java

private void changeFile() {
    if (fileNameTextField.getText().trim().length() > 0) {
        inFile = new File(fileNameTextField.getText().trim());
        try {//  www  . j  a v a  2  s .  c  om
            // autoDetectAction();
            listener.actionPerformed(new ActionEvent(this, 0, FILE_CHANGED_ACTION));
            numberOfRecordsTextField
                    .setText("" + (canreg.common.Tools.numberOfLinesInFile(inFile.getCanonicalPath()) - 1));
        } catch (IOException ex) {
            Logger.getLogger(PreviewFilePanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        inFile = null;
    }
}

From source file:org.tinymediamanager.ui.tvshows.TvShowPanel.java

/**
 * Inits the./*from w  w w .  ja v  a  2  s  . com*/
 */
private void init() {
    // build menu
    buildMenu();

    // add double click listener
    MouseListener mouseListener = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.getClickCount() == 2 && !e.isConsumed() && e.getButton() == MouseEvent.BUTTON1) {
                actionEdit2.actionPerformed(new ActionEvent(e, 0, ""));
            }
        }
    };
    tree.addMouseListener(mouseListener);
}

From source file:canreg.client.gui.components.FastFilterInternalFrame.java

/**
 * //w ww .  j  a v  a 2 s .  c  o  m
 */
@Action
public void okAction() {
    if (currentSelectionIsNotAdded()) {
        addAction();
    }
    actionListener.actionPerformed(new ActionEvent(this, 0, textPane.getText().trim()));
    this.setVisible(false);
}

From source file:com.diversityarrays.kdxplore.trials.TrialOverviewPanel.java

protected void fireEditCommand(MouseEvent e) {
    ActionEvent event = new ActionEvent(this, ++EVENT_COUNT, EDIT_TRIAL_COMMAND);
    for (ActionListener l : listenerList.getListeners(ActionListener.class)) {
        l.actionPerformed(event);// w  ww  . ja va2  s. c  o m
    }
}

From source file:org.apache.jmeter.visualizers.StatGraphVisualizer.java

@Override
public void actionPerformed(ActionEvent event) {
    boolean forceReloadData = false;
    final Object eventSource = event.getSource();
    if (eventSource == displayButton) {
        actionMakeGraph();/*from  www . ja v a 2  s .c om*/
    } else if (eventSource == saveGraph) {
        saveGraphToFile = true;
        try {
            ActionRouter.getInstance().getAction(ActionNames.SAVE_GRAPHICS, SaveGraphics.class.getName())
                    .doAction(new ActionEvent(this, event.getID(), ActionNames.SAVE_GRAPHICS));
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    } else if (eventSource == saveTable) {
        JFileChooser chooser = FileDialoger.promptToSaveFile("statistics.csv"); //$NON-NLS-1$
        if (chooser == null) {
            return;
        }
        FileWriter writer = null;
        try {
            writer = new FileWriter(chooser.getSelectedFile()); // TODO Charset ?
            CSVSaveService.saveCSVStats(getAllTableData(model, FORMATS), writer,
                    saveHeaders.isSelected() ? getLabels(COLUMNS) : null);
        } catch (IOException e) {
            JMeterUtils.reportErrorToUser(e.getMessage(), "Error saving data");
        } finally {
            JOrphanUtils.closeQuietly(writer);
        }
    } else if (eventSource == chooseForeColor) {
        Color color = JColorChooser.showDialog(null, JMeterUtils.getResString("aggregate_graph_choose_color"), //$NON-NLS-1$
                colorBarGraph);
        if (color != null) {
            colorForeGraph = color;
        }
    } else if (eventSource == syncWithName) {
        graphTitle.setText(namePanel.getName());
    } else if (eventSource == dynamicGraphSize) {
        // if use dynamic graph size is checked, we disable the dimension fields
        if (dynamicGraphSize.isSelected()) {
            graphWidth.setEnabled(false);
            graphHeight.setEnabled(false);
        } else {
            graphWidth.setEnabled(true);
            graphHeight.setEnabled(true);
        }
    } else if (eventSource == columnSelection) {
        if (columnSelection.isSelected()) {
            columnMatchLabel.setEnabled(true);
            applyFilterBtn.setEnabled(true);
            caseChkBox.setEnabled(true);
            regexpChkBox.setEnabled(true);
        } else {
            columnMatchLabel.setEnabled(false);
            applyFilterBtn.setEnabled(false);
            caseChkBox.setEnabled(false);
            regexpChkBox.setEnabled(false);
            // Force reload data
            forceReloadData = true;
        }
    }
    // Not 'else if' because forceReloadData 
    if (eventSource == applyFilterBtn || forceReloadData) {
        if (columnSelection.isSelected() && columnMatchLabel.getText() != null
                && columnMatchLabel.getText().length() > 0) {
            pattern = createPattern(columnMatchLabel.getText());
        } else if (forceReloadData) {
            pattern = null;
            matcher = null;
        }
        if (getFile() != null && getFile().length() > 0) {
            clearData();
            FilePanel filePanel = (FilePanel) getFilePanel();
            filePanel.actionPerformed(event);
        }
    } else if (eventSource instanceof JButton) {
        // Changing color for column
        JButton btn = ((JButton) eventSource);
        if (btn.getName() != null) {
            try {
                BarGraph bar = eltList.get(Integer.parseInt(btn.getName()));
                Color color = JColorChooser.showDialog(null, bar.getLabel(), bar.getBackColor());
                if (color != null) {
                    bar.setBackColor(color);
                    btn.setBackground(bar.getBackColor());
                }
            } catch (NumberFormatException nfe) {
            } // nothing to do
        }
    }
}

From source file:com.mightypocket.ashot.Mediator.java

void executeAction(String actionName) {
    application.getContext().getActionManager().getActionMap(Mediator.class, this).get(actionName)
            .actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null));
}

From source file:net.sf.jabref.EntryEditor.java

public void updateField(final Object source) {
    storeFieldAction.actionPerformed(new ActionEvent(source, 0, ""));
}

From source file:org.apache.jmeter.gui.MainFrame.java

public boolean openJmxFilesFromDragAndDrop(Transferable tr) throws UnsupportedFlavorException, IOException {
    @SuppressWarnings("unchecked")
    List<File> files = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
    if (files.isEmpty()) {
        return false;
    }//from   w  w w . ja  v a 2  s  .com
    File file = files.get(0);
    if (!file.getName().endsWith(".jmx")) {
        log.warn("Importing file:" + file.getName()
                + "from DnD failed because file extension does not end with .jmx");
        return false;
    }

    ActionEvent fakeEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, ActionNames.OPEN);
    LoadDraggedFile.loadProject(fakeEvent, file);

    return true;
}