Search in sources :

Example 31 with ActionEvent

use of java.awt.event.ActionEvent in project kotlin by JetBrains.

the class MoveKotlinTopLevelDeclarationsDialog method initFileChooser.

private void initFileChooser(@Nullable KtFile targetFile, @NotNull Set<KtNamedDeclaration> elementsToMove, @NotNull List<KtFile> sourceFiles) {
    final PsiDirectory sourceDir = sourceFiles.get(0).getParent();
    assert sourceDir != null : sourceFiles.get(0).getVirtualFile().getPath();
    fileChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            KotlinFileChooserDialog dialog = new KotlinFileChooserDialog("Choose Containing File", myProject);
            File targetFile = new File(getTargetFilePath());
            PsiFile targetPsiFile = KotlinRefactoringUtilKt.toPsiFile(targetFile, myProject);
            if (targetPsiFile instanceof KtFile) {
                dialog.select((KtFile) targetPsiFile);
            } else {
                PsiDirectory targetDir = KotlinRefactoringUtilKt.toPsiDirectory(targetFile.getParentFile(), myProject);
                if (targetDir == null) {
                    targetDir = sourceDir;
                }
                dialog.selectDirectory(targetDir);
            }
            dialog.showDialog();
            KtFile selectedFile = dialog.isOK() ? dialog.getSelected() : null;
            if (selectedFile != null) {
                fileChooser.setText(selectedFile.getVirtualFile().getPath());
            }
        }
    });
    String initialTargetPath = targetFile != null ? targetFile.getVirtualFile().getPath() : sourceFiles.get(0).getVirtualFile().getParent().getPath() + "/" + MoveUtilsKt.guessNewFileName(elementsToMove);
    fileChooser.setText(initialTargetPath);
}
Also used : KotlinFileChooserDialog(org.jetbrains.kotlin.idea.refactoring.ui.KotlinFileChooserDialog) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) KtFile(org.jetbrains.kotlin.psi.KtFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File)

Example 32 with ActionEvent

use of java.awt.event.ActionEvent in project EnrichmentMapApp by BaderLab.

the class AddRanksDialog method createButtonPanel.

private JPanel createButtonPanel() {
    okButton = new JButton(new AbstractAction("OK") {

        public void actionPerformed(ActionEvent e) {
            if (validateDuplicateRankName()) {
                loadRanksAndClose();
            }
        }
    });
    JButton cancelButton = new JButton(new AbstractAction("Cancel") {

        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    JPanel buttonPanel = LookAndFeelUtil.createOkCancelPanel(okButton, cancelButton);
    LookAndFeelUtil.setDefaultOkCancelKeyStrokes(getRootPane(), okButton.getAction(), cancelButton.getAction());
    getRootPane().setDefaultButton(okButton);
    okButton.setEnabled(false);
    return buttonPanel;
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) AbstractAction(javax.swing.AbstractAction)

Example 33 with ActionEvent

use of java.awt.event.ActionEvent in project EnrichmentMapApp by BaderLab.

the class PostAnalysisPanelMediator method showDialog.

@SuppressWarnings("serial")
public void showDialog(Component parent, CyNetworkView netView) {
    final EnrichmentMap map = emManager.getEnrichmentMap(netView.getModel().getSUID());
    invokeOnEDT(() -> {
        final PostAnalysisInputPanel panel = panelFactory.create(map);
        final JDialog dialog = new JDialog(swingApplication.getJFrame(), "Add Signature Gene Sets", ModalityType.APPLICATION_MODAL);
        dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        JButton helpButton = SwingUtil.createOnlineHelpButton(EnrichmentMapBuildProperties.USER_MANUAL_URL, "Online Manual...", serviceRegistrar);
        JButton resetButton = new JButton("Reset");
        resetButton.addActionListener(e -> panel.reset());
        JButton closeButton = new JButton(new AbstractAction("Close") {

            @Override
            public void actionPerformed(ActionEvent e) {
                dialog.dispose();
            }
        });
        JButton runButton = new JButton(new AbstractAction("Add") {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (panel.isReady()) {
                    Optional<PostAnalysisParameters> params = buildPostAnalysisParameters(panel, map, dialog);
                    if (params.isPresent()) {
                        addGeneSets(netView, params.get());
                        dialog.dispose();
                    } else {
                        JOptionPane.showMessageDialog(panel, "Could not run post analysis.", "EnrichmentMap: Error", JOptionPane.WARNING_MESSAGE);
                    }
                }
            }
        });
        JPanel buttonPanel = LookAndFeelUtil.createOkCancelPanel(runButton, closeButton, helpButton, resetButton);
        dialog.getContentPane().add(panel, BorderLayout.CENTER);
        dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
        LookAndFeelUtil.setDefaultOkCancelKeyStrokes(dialog.getRootPane(), runButton.getAction(), closeButton.getAction());
        dialog.getRootPane().setDefaultButton(runButton);
        dialog.pack();
        dialog.setLocationRelativeTo(swingApplication.getJFrame());
        dialog.setVisible(true);
    });
}
Also used : JPanel(javax.swing.JPanel) Optional(java.util.Optional) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 34 with ActionEvent

use of java.awt.event.ActionEvent in project EnrichmentMapApp by BaderLab.

the class PostAnalysisSignatureDiscoveryPanel method createSignatureDiscoveryGMTPanel.

/**
     * @return Panel for choosing and loading GMT and SignatureGMT Geneset-Files 
     */
private JPanel createSignatureDiscoveryGMTPanel() {
    signatureDiscoveryGMTFileNameTextField = new JFormattedTextField();
    signatureDiscoveryGMTFileNameTextField.setColumns(15);
    signatureDiscoveryGMTFileNameTextField.setToolTipText(Messages.GMT_INSTRUCTION);
    final Color textFieldForeground = signatureDiscoveryGMTFileNameTextField.getForeground();
    signatureDiscoveryGMTFileNameTextField.addPropertyChangeListener("value", (PropertyChangeEvent e) -> {
        // if the text is red set it back to black as soon as the user starts typing
        signatureDiscoveryGMTFileNameTextField.setForeground(textFieldForeground);
    });
    JButton selectSigGMTFileButton = new JButton("Browse...");
    selectSigGMTFileButton.setToolTipText(Messages.GMT_INSTRUCTION);
    selectSigGMTFileButton.setActionCommand("Signature Discovery");
    selectSigGMTFileButton.addActionListener((ActionEvent evt) -> {
        parentPanel.chooseGMTFile(signatureDiscoveryGMTFileNameTextField);
    });
    JLabel filterLabel = new JLabel("Filter:");
    filterTextField = new JFormattedTextField();
    filterTextField.setColumns(4);
    filterTextField.setHorizontalAlignment(JTextField.RIGHT);
    filterTextField.addPropertyChangeListener("value", (PropertyChangeEvent e) -> {
        StringBuilder message = new StringBuilder("The value you have entered is invalid.\n");
        Number number = (Number) filterTextField.getValue();
        PostAnalysisFilterType filterType = getFilterType();
        Optional<Double> value = PostAnalysisInputPanel.validateAndGetFilterValue(number, filterType, message);
        savedFilterValues.put(filterType, value.orElse(filterType.defaultValue));
        if (!value.isPresent()) {
            filterTextField.setValue(filterType.defaultValue);
            JOptionPane.showMessageDialog(application.getJFrame(), message.toString(), "Parameter out of bounds", JOptionPane.WARNING_MESSAGE);
        }
    });
    // Types of filters:
    // 1. filter by percent, i.e. the overlap between the signature geneset and EM geneset
    //    has to be X percentage of the EM set it overlaps with for at least one geneset in the enrichment map.
    // 2. filter by number, i.e. the overlap between the signature geneset and EM geneset
    //    has to be X genes of the EM set it overlaps with for at least one geneset in the enrichment map.
    // 3. filter by specificity, i.e looking for the signature genesets that are more specific than other genesets
    //    for instance a drug A that targets only X and Y as opposed to drug B that targets X,y,L,M,N,O,P.
    filterTypeCombo = new JComboBox<>();
    // default
    filterTypeCombo.addItem(PostAnalysisFilterType.NO_FILTER);
    //		filterTypeCombo.addItem(PostAnalysisFilterType.MANN_WHIT_TWO_SIDED);
    //		filterTypeCombo.addItem(PostAnalysisFilterType.MANN_WHIT_GREATER);
    //		filterTypeCombo.addItem(PostAnalysisFilterType.MANN_WHIT_LESS);
    filterTypeCombo.addItem(PostAnalysisFilterType.HYPERGEOM);
    filterTypeCombo.addItem(PostAnalysisFilterType.NUMBER);
    filterTypeCombo.addItem(PostAnalysisFilterType.PERCENT);
    filterTypeCombo.addItem(PostAnalysisFilterType.SPECIFIC);
    filterTypeCombo.addActionListener(e -> {
        updateFilterTextField();
    });
    updateFilterTextField();
    //TODO: Maybe move loading SigGMT to File-selection Event add load button
    JButton loadButton = new JButton();
    loadButton.setText("Load Gene Sets");
    loadButton.addActionListener(e -> {
        String filePath = (String) signatureDiscoveryGMTFileNameTextField.getValue();
        if (filePath == null || PostAnalysisInputPanel.checkFile(filePath).equals(Color.RED)) {
            String message = "Signature GMT file name not valid.\n";
            signatureDiscoveryGMTFileNameTextField.setForeground(Color.RED);
            JOptionPane.showMessageDialog(application.getJFrame(), message, "Post Analysis Known Signature", JOptionPane.WARNING_MESSAGE);
            return;
        }
        if (!EnrichmentMapParameters.checkFile(filePath)) {
            String message = "Signature GMT does not exist.\n";
            signatureDiscoveryGMTFileNameTextField.setForeground(Color.RED);
            JOptionPane.showMessageDialog(application.getJFrame(), message, "Post Analysis Known Signature", JOptionPane.WARNING_MESSAGE);
            return;
        }
        FilterMetric filterMetric = createFilterMetric();
        LoadSignatureSetsActionListener action = loadSignatureSetsActionListenerFactory.create(new File(filePath), filterMetric, parentPanel.getEnrichmentMap());
        action.setGeneSetCallback(gs -> {
            this.signatureGenesets = gs;
        });
        action.setFilteredSignatureSetsCallback(selected -> {
            availSigSetsModel.clear();
            selectedSigSetsModel.clear();
            for (String name : selected) availSigSetsModel.addElement(name);
            update();
        });
        action.actionPerformed(null);
    });
    makeSmall(signatureDiscoveryGMTFileNameTextField, selectSigGMTFileButton);
    makeSmall(filterLabel, filterTypeCombo, filterTextField);
    makeSmall(loadButton);
    JPanel panel = new JPanel();
    panel.setBorder(LookAndFeelUtil.createTitledBorder("SigGMT File (contains signature-genesets)"));
    final GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(!LookAndFeelUtil.isAquaLAF());
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.CENTER, true).addGroup(layout.createSequentialGroup().addComponent(signatureDiscoveryGMTFileNameTextField, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(selectSigGMTFileButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createSequentialGroup().addComponent(filterLabel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(filterTypeCombo, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(filterTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(loadButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(signatureDiscoveryGMTFileNameTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(selectSigGMTFileButton)).addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(filterLabel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(filterTypeCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(filterTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(loadButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
    if (LookAndFeelUtil.isAquaLAF())
        panel.setOpaque(false);
    return panel;
}
Also used : JPanel(javax.swing.JPanel) PropertyChangeEvent(java.beans.PropertyChangeEvent) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) JFormattedTextField(javax.swing.JFormattedTextField) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) FilterMetric(org.baderlab.csplugins.enrichmentmap.task.postanalysis.FilterMetric) LoadSignatureSetsActionListener(org.baderlab.csplugins.enrichmentmap.actions.LoadSignatureSetsActionListener) GroupLayout(javax.swing.GroupLayout) File(java.io.File)

Example 35 with ActionEvent

use of java.awt.event.ActionEvent in project EnrichmentMapApp by BaderLab.

the class CardDialog method createButtonPanel.

@SuppressWarnings("serial")
private JPanel createButtonPanel() {
    finishButton = new JButton(new AbstractAction(params.getFinishButtonText()) {

        public void actionPerformed(ActionEvent e) {
            currentPage.finish();
        }
    });
    JButton cancelButton = new JButton(new AbstractAction("Cancel") {

        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);
        }
    });
    AbstractButton[] additional = params.getAdditionalButtons();
    if (additional != null) {
        for (AbstractButton button : additional) {
            button.addActionListener(e -> {
                currentPage.extraButtonClicked(e.getActionCommand());
            });
        }
    }
    JPanel buttonPanel = LookAndFeelUtil.createOkCancelPanel(finishButton, cancelButton, additional);
    LookAndFeelUtil.setDefaultOkCancelKeyStrokes(dialog.getRootPane(), finishButton.getAction(), cancelButton.getAction());
    dialog.getRootPane().setDefaultButton(finishButton);
    return buttonPanel;
}
Also used : JPanel(javax.swing.JPanel) AbstractButton(javax.swing.AbstractButton) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) AbstractAction(javax.swing.AbstractAction)

Aggregations

ActionEvent (java.awt.event.ActionEvent)3561 ActionListener (java.awt.event.ActionListener)2755 JButton (javax.swing.JButton)1116 JPanel (javax.swing.JPanel)961 JLabel (javax.swing.JLabel)606 JMenuItem (javax.swing.JMenuItem)550 Dimension (java.awt.Dimension)531 AbstractAction (javax.swing.AbstractAction)510 BorderLayout (java.awt.BorderLayout)381 GridBagConstraints (java.awt.GridBagConstraints)301 GridBagLayout (java.awt.GridBagLayout)292 Insets (java.awt.Insets)288 JScrollPane (javax.swing.JScrollPane)274 BoxLayout (javax.swing.BoxLayout)262 JTextField (javax.swing.JTextField)262 FlowLayout (java.awt.FlowLayout)257 JCheckBox (javax.swing.JCheckBox)242 JMenu (javax.swing.JMenu)217 Point (java.awt.Point)203 ImageIcon (javax.swing.ImageIcon)191