Search in sources :

Example 36 with ActionEvent

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

the class SwingUtil method createOnlineHelpButton.

public static JButton createOnlineHelpButton(String url, String toolTipText, CyServiceRegistrar serviceRegistrar) {
    JButton btn = new JButton();
    btn.setToolTipText(toolTipText);
    btn.addActionListener((ActionEvent evt) -> {
        serviceRegistrar.getService(OpenBrowser.class).openURL(url);
    });
    if (LookAndFeelUtil.isAquaLAF()) {
        btn.putClientProperty("JButton.buttonType", "help");
    } else {
        btn.setFont(serviceRegistrar.getService(IconManager.class).getIconFont(22.0f));
        btn.setText(IconManager.ICON_QUESTION_CIRCLE);
        btn.setBorderPainted(false);
        btn.setContentAreaFilled(false);
        btn.setFocusPainted(false);
        btn.setBorder(BorderFactory.createEmptyBorder());
        btn.setMinimumSize(new Dimension(22, 22));
    }
    return btn;
}
Also used : OpenBrowser(org.cytoscape.util.swing.OpenBrowser) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Dimension(java.awt.Dimension)

Example 37 with ActionEvent

use of java.awt.event.ActionEvent in project intellij-community by JetBrains.

the class ProjectSpecificSettingsStep method addInterpreterButton.

private void addInterpreterButton(final JPanel locationPanel, final LabeledComponent<TextFieldWithBrowseButton> location) {
    final JButton interpreterButton = new FixedSizeButton(location);
    if (SystemInfo.isMac && !UIUtil.isUnderDarcula()) {
        interpreterButton.putClientProperty("JButton.buttonType", null);
    }
    interpreterButton.setIcon(PythonIcons.Python.Python);
    interpreterButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final DialogBuilder builder = new DialogBuilder();
            final JPanel panel = new JPanel();
            final LabeledComponent<PythonSdkChooserCombo> interpreterCombo = createInterpreterCombo();
            if (mySdk != null) {
                mySdkCombo.getComboBox().setSelectedItem(mySdk);
            }
            panel.add(interpreterCombo);
            builder.setCenterPanel(panel);
            builder.setTitle("Select Python Interpreter");
            if (builder.showAndGet()) {
                mySdk = (Sdk) mySdkCombo.getComboBox().getSelectedItem();
            }
        }
    });
    locationPanel.add(interpreterButton, BorderLayout.EAST);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 38 with ActionEvent

use of java.awt.event.ActionEvent in project intellij-community by JetBrains.

the class DynamicToolWindowWrapper method createTable.

private JScrollPane createTable(final MutableTreeNode myTreeRoot) {
    ColumnInfo[] columnInfos = { new ClassColumnInfo(myColumnNames[CLASS_OR_ELEMENT_NAME_COLUMN]), new PropertyTypeColumnInfo(myColumnNames[TYPE_COLUMN]) };
    myTreeTableModel = new ListTreeTableModelOnColumns(myTreeRoot, columnInfos);
    myTreeTable = new MyTreeTable(myTreeTableModel);
    new TreeTableSpeedSearch(myTreeTable, new Convertor<TreePath, String>() {

        @Override
        public String convert(TreePath o) {
            final Object node = o.getLastPathComponent();
            if (node instanceof DefaultMutableTreeNode) {
                final Object object = ((DefaultMutableTreeNode) node).getUserObject();
                if (object instanceof DNamedElement) {
                    return ((DNamedElement) object).getName();
                }
            }
            return "";
        }
    });
    DefaultActionGroup group = new DefaultActionGroup();
    group.add(ActionManager.getInstance().getAction(RemoveDynamicAction.GROOVY_DYNAMIC_REMOVE));
    PopupHandler.installUnknownPopupHandler(myTreeTable, group, ActionManager.getInstance());
    final MyColoredTreeCellRenderer treeCellRenderer = new MyColoredTreeCellRenderer();
    myTreeTable.setDefaultRenderer(String.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            if (value instanceof String) {
                try {
                    final PsiType type = JavaPsiFacade.getElementFactory(myProject).createTypeFromText((String) value, null);
                    String shortName = type.getPresentableText();
                    return new JLabel(shortName);
                } catch (IncorrectOperationException e) {
                    LOG.debug("Type cannot be created", e);
                }
                return new JLabel(QuickfixUtil.shortenType((String) value));
            }
            return new JLabel();
        }
    });
    myTreeTable.setTreeCellRenderer(treeCellRenderer);
    myTreeTable.setRootVisible(false);
    myTreeTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    final MyPropertyTypeCellEditor typeCellEditor = new MyPropertyTypeCellEditor();
    typeCellEditor.addCellEditorListener(new CellEditorListener() {

        @Override
        public void editingStopped(ChangeEvent e) {
            final TreeTableTree tree = getTree();
            String newTypeValue = ((MyPropertyTypeCellEditor) e.getSource()).getCellEditorValue();
            if (newTypeValue == null || tree == null) {
                myTreeTable.editingStopped(e);
                return;
            }
            try {
                final PsiType type = JavaPsiFacade.getElementFactory(myProject).createTypeFromText(newTypeValue, null);
                String canonical = type.getCanonicalText();
                if (canonical != null)
                    newTypeValue = canonical;
            } catch (IncorrectOperationException ex) {
            //do nothing in case bad string is entered
            }
            final TreePath editingTypePath = tree.getSelectionPath();
            if (editingTypePath == null)
                return;
            final TreePath editingClassPath = editingTypePath.getParentPath();
            Object oldTypeValue = myTreeTable.getValueAt(tree.getRowForPath(editingTypePath), TYPE_COLUMN);
            if (!(oldTypeValue instanceof String)) {
                myTreeTable.editingStopped(e);
                return;
            }
            final Object editingPropertyObject = myTreeTable.getValueAt(tree.getRowForPath(editingTypePath), CLASS_OR_ELEMENT_NAME_COLUMN);
            final Object editingClassObject = myTreeTable.getValueAt(tree.getRowForPath(editingClassPath), CLASS_OR_ELEMENT_NAME_COLUMN);
            if (!(editingPropertyObject instanceof DItemElement) || !(editingClassObject instanceof DClassElement)) {
                myTreeTable.editingStopped(e);
                return;
            }
            final DItemElement dynamicElement = (DItemElement) editingPropertyObject;
            final String name = dynamicElement.getName();
            final String className = ((DClassElement) editingClassObject).getName();
            if (dynamicElement instanceof DPropertyElement) {
                DynamicManager.getInstance(myProject).replaceDynamicPropertyType(className, name, (String) oldTypeValue, newTypeValue);
            } else if (dynamicElement instanceof DMethodElement) {
                final List<ParamInfo> myPairList = ((DMethodElement) dynamicElement).getPairs();
                DynamicManager.getInstance(myProject).replaceDynamicMethodType(className, name, myPairList, (String) oldTypeValue, newTypeValue);
            }
        }

        @Override
        public void editingCanceled(ChangeEvent e) {
            myTreeTable.editingCanceled(e);
        }
    });
    RefactoringListenerManager.getInstance(myProject).addListenerProvider(new RefactoringElementListenerProvider() {

        @Override
        @Nullable
        public RefactoringElementListener getListener(final PsiElement element) {
            if (element instanceof PsiClass) {
                final String qualifiedName = ((PsiClass) element).getQualifiedName();
                return new RefactoringElementListener() {

                    @Override
                    public void elementMoved(@NotNull PsiElement newElement) {
                        renameElement(qualifiedName, newElement);
                    }

                    @Override
                    public void elementRenamed(@NotNull PsiElement newElement) {
                        renameElement(qualifiedName, newElement);
                    }

                    private void renameElement(String oldClassName, PsiElement newElement) {
                        if (newElement instanceof PsiClass) {
                            final String newClassName = ((PsiClass) newElement).getQualifiedName();
                            final DRootElement rootElement = DynamicManager.getInstance(myProject).getRootElement();
                            final DClassElement oldClassElement = rootElement.getClassElement(oldClassName);
                            final TreeNode oldClassNode = TreeUtil.findNodeWithObject((DefaultMutableTreeNode) myTreeRoot, oldClassElement);
                            DynamicManager.getInstance(myProject).replaceClassName(oldClassElement, newClassName);
                            myTreeTableModel.nodeChanged(oldClassNode);
                        }
                    }
                };
            }
            return null;
        }
    });
    myTreeTable.setDefaultEditor(String.class, typeCellEditor);
    myTreeTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            final int selectionRow = myTreeTable.getTree().getLeadSelectionRow();
            myTreeTable.editCellAt(selectionRow, CLASS_OR_ELEMENT_NAME_COLUMN, event);
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), JComponent.WHEN_FOCUSED);
    myTreeTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            final int selectionRow = myTreeTable.getTree().getLeadSelectionRow();
            myTreeTable.editCellAt(selectionRow, TYPE_COLUMN, event);
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED);
    myTreeTable.getTree().setShowsRootHandles(true);
    myTreeTable.getTableHeader().setReorderingAllowed(false);
    myTreeTable.setPreferredScrollableViewportSize(new Dimension(300, myTreeTable.getRowHeight() * 10));
    myTreeTable.getColumn(myColumnNames[CLASS_OR_ELEMENT_NAME_COLUMN]).setPreferredWidth(200);
    myTreeTable.getColumn(myColumnNames[TYPE_COLUMN]).setPreferredWidth(160);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTreeTable);
    scrollPane.setPreferredSize(JBUI.size(600, 400));
    return scrollPane;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) ColumnInfo(com.intellij.util.ui.ColumnInfo) CellEditorListener(javax.swing.event.CellEditorListener) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) TreeTableTree(com.intellij.ui.treeStructure.treetable.TreeTableTree) TableCellRenderer(javax.swing.table.TableCellRenderer) ListTreeTableModelOnColumns(com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) RefactoringElementListenerProvider(com.intellij.refactoring.listeners.RefactoringElementListenerProvider) ActionListener(java.awt.event.ActionListener) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with ActionEvent

use of java.awt.event.ActionEvent in project intellij-community by JetBrains.

the class SwitchTaskAction method createPopup.

private static ListPopupImpl createPopup(final DataContext dataContext, @Nullable final Runnable onDispose, boolean withTitle) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final Ref<Boolean> shiftPressed = Ref.create(false);
    final Ref<JComponent> componentRef = Ref.create();
    List<TaskListItem> items = project == null ? Collections.<TaskListItem>emptyList() : createPopupActionGroup(project, shiftPressed, PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext));
    final String title = withTitle ? "Switch to Task" : null;
    ListPopupStep<TaskListItem> step = new MultiSelectionListPopupStep<TaskListItem>(title, items) {

        @Override
        public PopupStep<?> onChosen(List<TaskListItem> selectedValues, boolean finalChoice) {
            if (finalChoice) {
                selectedValues.get(0).select();
                return FINAL_CHOICE;
            }
            ActionGroup group = createActionsStep(selectedValues, project, shiftPressed);
            return JBPopupFactory.getInstance().createActionsStep(group, DataManager.getInstance().getDataContext(componentRef.get()), false, false, null, null, true);
        }

        @Override
        public Icon getIconFor(TaskListItem aValue) {
            return aValue.getIcon();
        }

        @NotNull
        @Override
        public String getTextFor(TaskListItem value) {
            return value.getText();
        }

        @Nullable
        @Override
        public ListSeparator getSeparatorAbove(TaskListItem value) {
            return value.getSeparator() == null ? null : new ListSeparator(value.getSeparator());
        }

        @Override
        public boolean hasSubstep(List<TaskListItem> selectedValues) {
            return selectedValues.size() > 1 || selectedValues.get(0).getTask() != null;
        }
    };
    final ListPopupImpl popup = (ListPopupImpl) JBPopupFactory.getInstance().createListPopup(step);
    if (onDispose != null) {
        Disposer.register(popup, new Disposable() {

            @Override
            public void dispose() {
                onDispose.run();
            }
        });
    }
    componentRef.set(popup.getComponent());
    if (items.size() <= 2) {
        return popup;
    }
    popup.setAdText("Press SHIFT to merge with current context");
    popup.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(true);
            popup.setCaption("Merge with Current Context");
        }
    });
    popup.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(false);
            popup.setCaption("Switch to Task");
        }
    });
    popup.registerAction("invoke", KeyStroke.getKeyStroke("shift ENTER"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            popup.handleSelect(true);
        }
    });
    return popup;
}
Also used : Disposable(com.intellij.openapi.Disposable) ActionEvent(java.awt.event.ActionEvent) Project(com.intellij.openapi.project.Project) SimpleActionGroup(com.intellij.tools.SimpleActionGroup) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) LocalChangeList(com.intellij.openapi.vcs.changes.LocalChangeList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 40 with ActionEvent

use of java.awt.event.ActionEvent in project intellij-community by JetBrains.

the class GotoTaskAction method perform.

void perform(final Project project) {
    final Ref<Boolean> shiftPressed = Ref.create(false);
    final ChooseByNamePopup popup = createPopup(project, new GotoTaskPopupModel(project), new TaskItemProvider(project));
    popup.setShowListForEmptyPattern(true);
    popup.setSearchInAnyPlace(true);
    popup.setAlwaysHasMore(true);
    popup.setAdText("<html>Press SHIFT to merge with current context<br/>" + "Pressing " + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_QUICK_JAVADOC)) + " would show task description and comments</html>");
    popup.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(true);
        }
    });
    popup.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(false);
        }
    });
    final DefaultActionGroup group = new DefaultActionGroup(new ConfigureServersAction() {

        @Override
        protected void serversChanged() {
            popup.rebuildList(true);
        }
    });
    final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
    actionToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);
    actionToolbar.updateActionsImmediately();
    actionToolbar.getComponent().setFocusable(false);
    actionToolbar.getComponent().setBorder(null);
    popup.setToolArea(actionToolbar.getComponent());
    popup.setMaximumListSizeLimit(PAGE_SIZE);
    popup.setListSizeIncreasing(PAGE_SIZE);
    showNavigationPopup(new GotoActionCallback<Object>() {

        @Override
        public void elementChosen(ChooseByNamePopup popup, Object element) {
            TaskManager taskManager = TaskManager.getManager(project);
            if (element instanceof TaskPsiElement) {
                Task task = ((TaskPsiElement) element).getTask();
                LocalTask localTask = taskManager.findTask(task.getId());
                if (localTask != null) {
                    taskManager.activateTask(localTask, !shiftPressed.get());
                } else {
                    showOpenTaskDialog(project, task);
                }
            } else if (element == CREATE_NEW_TASK_ACTION) {
                LocalTask localTask = taskManager.createLocalTask(CREATE_NEW_TASK_ACTION.getTaskName());
                showOpenTaskDialog(project, localTask);
            }
        }
    }, null, popup);
}
Also used : Task(com.intellij.tasks.Task) LocalTask(com.intellij.tasks.LocalTask) ActionEvent(java.awt.event.ActionEvent) LocalTask(com.intellij.tasks.LocalTask) TaskPsiElement(com.intellij.tasks.doc.TaskPsiElement) TaskManager(com.intellij.tasks.TaskManager)

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