Search in sources :

Example 91 with MouseEvent

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

the class PerFileConfigurableBase method createComponent.

@NotNull
@Override
public JComponent createComponent() {
    //todo multi-editing, separate project/ide combos _if_ needed by specific configurable (SQL, no Web)
    myPanel = new JPanel(new BorderLayout());
    myTable = new JBTable(myModel = new MyModel<>(param(TARGET_TITLE), param(MAPPING_TITLE))) {

        @Override
        public String getToolTipText(@NotNull MouseEvent event) {
            Point point = event.getPoint();
            int row = rowAtPoint(point);
            int col = columnAtPoint(point);
            if (row != -1 && col == 1) {
                return getToolTipFor((T) getValueAt(convertRowIndexToModel(row), col));
            }
            return super.getToolTipText(event);
        }
    };
    setupPerFileTable();
    JPanel tablePanel = ToolbarDecorator.createDecorator(myTable).disableUpAction().disableDownAction().setAddAction(button -> doAddAction(button)).setRemoveAction(button -> doRemoveAction(button)).setEditAction(button -> doEditAction(button)).setEditActionUpdater(e -> myTable.getSelectedRows().length > 0).createPanel();
    myTable.getEmptyText().setText(param(EMPTY_TEXT).replace("$addShortcut", KeymapUtil.getFirstKeyboardShortcutText(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.ADD))));
    JBLabel label = new JBLabel(param(DESCRIPTION));
    label.setBorder(BorderFactory.createEmptyBorder(TITLED_BORDER_TOP_INSET, TITLED_BORDER_INDENT, TITLED_BORDER_BOTTOM_INSET, 0));
    label.setComponentStyle(UIUtil.ComponentStyle.SMALL);
    JComponent north = createDefaultMappingComponent();
    if (north != null) {
        myPanel.add(north, BorderLayout.NORTH);
    }
    myPanel.add(label, BorderLayout.SOUTH);
    myPanel.add(tablePanel, BorderLayout.CENTER);
    return myPanel;
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) UIUtil(com.intellij.util.ui.UIUtil) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) javax.swing.table(javax.swing.table) LanguagePerFileMappings(com.intellij.lang.LanguagePerFileMappings) PerFileMappingsBase(com.intellij.lang.PerFileMappingsBase) ContainerUtil(com.intellij.util.containers.ContainerUtil) JBLabel(com.intellij.ui.components.JBLabel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JBUI(com.intellij.util.ui.JBUI) Project(com.intellij.openapi.project.Project) SpeedSearchUtil(com.intellij.ui.speedSearch.SpeedSearchUtil) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) PerFileMappings(com.intellij.lang.PerFileMappings) FileUtil(com.intellij.openapi.util.io.FileUtil) ComboBoxAction(com.intellij.openapi.actionSystem.ex.ComboBoxAction) TIntArrayList(gnu.trove.TIntArrayList) CustomComponentAction(com.intellij.openapi.actionSystem.ex.CustomComponentAction) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) Configurable(com.intellij.openapi.options.Configurable) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) com.intellij.ui(com.intellij.ui) Collectors(java.util.stream.Collectors) JBPopup(com.intellij.openapi.ui.popup.JBPopup) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) JBTable(com.intellij.ui.table.JBTable) Nullable(org.jetbrains.annotations.Nullable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ConfigurationException(com.intellij.openapi.options.ConfigurationException) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) MouseEvent(java.awt.event.MouseEvent) JBLabel(com.intellij.ui.components.JBLabel) JBTable(com.intellij.ui.table.JBTable) NotNull(org.jetbrains.annotations.NotNull)

Example 92 with MouseEvent

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

the class FileColorSettingsTable method editCellAt.

@Override
public boolean editCellAt(int row, int column, EventObject e) {
    if (e == null || (e instanceof MouseEvent && ((MouseEvent) e).getClickCount() == 1))
        return false;
    final Object at = getModel().getValueAt(row, column);
    if (!(at instanceof FileColorConfiguration))
        return false;
    final FileColorConfigurationEditDialog dialog = new FileColorConfigurationEditDialog(myManager, ((FileColorConfiguration) at));
    dialog.getScopeComboBox().setEnabled(false);
    dialog.show();
    return false;
}
Also used : MouseEvent(java.awt.event.MouseEvent) EventObject(java.util.EventObject)

Example 93 with MouseEvent

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

the class JdkChooserPanel method showDialog.

private static Sdk showDialog(final Project project, String title, final Component parent, Sdk jdkToSelect) {
    final JdkChooserPanel jdkChooserPanel = new JdkChooserPanel(project);
    jdkChooserPanel.fillList(null, null);
    final MyDialog dialog = jdkChooserPanel.new MyDialog(parent);
    if (title != null) {
        dialog.setTitle(title);
    }
    if (jdkToSelect != null) {
        jdkChooserPanel.selectJdk(jdkToSelect);
    } else {
        ScrollingUtil.ensureSelectionExists(jdkChooserPanel.myList);
    }
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            dialog.clickDefaultButton();
            return true;
        }
    }.installOn(jdkChooserPanel.myList);
    return dialog.showAndGet() ? jdkChooserPanel.getChosenJdk() : null;
}
Also used : MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener)

Example 94 with MouseEvent

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

the class JavaChangeSignatureDialog method createParametersListTable.

@Override
protected ParametersListTable createParametersListTable() {
    return new ParametersListTable() {

        private final EditorTextFieldJBTableRowRenderer myRowRenderer = new EditorTextFieldJBTableRowRenderer(getProject(), JavaChangeSignatureDialog.this.getFileType(), myDisposable) {

            @Override
            protected String getText(JTable table, int row) {
                ParameterTableModelItemBase<ParameterInfoImpl> item = getRowItem(row);
                final String typeText = item.typeCodeFragment.getText();
                final String separator = StringUtil.repeatSymbol(' ', getTypesMaxLength() - typeText.length() + 1);
                String text = typeText + separator + item.parameter.getName();
                final String defaultValue = item.defaultValueCodeFragment.getText();
                String tail = "";
                if (StringUtil.isNotEmpty(defaultValue)) {
                    tail += " default value = " + defaultValue;
                }
                if (item.parameter.isUseAnySingleVariable()) {
                    if (StringUtil.isNotEmpty(defaultValue)) {
                        tail += ";";
                    }
                    tail += " Use any var.";
                }
                if (!StringUtil.isEmpty(tail)) {
                    text += " //" + tail;
                }
                return " " + text;
            }
        };

        @Override
        protected JBTableRowRenderer getRowRenderer(int row) {
            return myRowRenderer;
        }

        @NotNull
        @Override
        protected JBTableRowEditor getRowEditor(final ParameterTableModelItemBase<ParameterInfoImpl> item) {
            return new JBTableRowEditor() {

                private EditorTextField myTypeEditor;

                private EditorTextField myNameEditor;

                private EditorTextField myDefaultValueEditor;

                private JCheckBox myAnyVar;

                @Override
                public void prepareEditor(JTable table, int row) {
                    setLayout(new BorderLayout());
                    final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(item.typeCodeFragment);
                    myTypeEditor = new EditorTextField(document, getProject(), getFileType());
                    myTypeEditor.addDocumentListener(mySignatureUpdater);
                    myTypeEditor.setPreferredWidth(getTable().getWidth() / 2);
                    myTypeEditor.addDocumentListener(new RowEditorChangeListener(0));
                    add(createLabeledPanel("Type:", myTypeEditor), BorderLayout.WEST);
                    myNameEditor = new EditorTextField(item.parameter.getName(), getProject(), getFileType());
                    myNameEditor.addDocumentListener(mySignatureUpdater);
                    myNameEditor.addDocumentListener(new RowEditorChangeListener(1));
                    add(createLabeledPanel("Name:", myNameEditor), BorderLayout.CENTER);
                    new TextFieldCompletionProvider() {

                        @Override
                        protected void addCompletionVariants(@NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result) {
                            final PsiCodeFragment fragment = item.typeCodeFragment;
                            if (fragment instanceof PsiTypeCodeFragment) {
                                final PsiType type;
                                try {
                                    type = ((PsiTypeCodeFragment) fragment).getType();
                                } catch (Exception e) {
                                    return;
                                }
                                final SuggestedNameInfo info = JavaCodeStyleManager.getInstance(myProject).suggestVariableName(VariableKind.PARAMETER, null, null, type);
                                for (String completionVariant : info.names) {
                                    final LookupElementBuilder element = LookupElementBuilder.create(completionVariant);
                                    result.addElement(element.withLookupString(completionVariant.toLowerCase(Locale.ENGLISH)));
                                }
                            }
                        }
                    }.apply(myNameEditor, item.parameter.getName());
                    if (!item.isEllipsisType() && item.parameter.getOldIndex() == -1) {
                        final JPanel additionalPanel = new JPanel(new BorderLayout());
                        final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(item.defaultValueCodeFragment);
                        myDefaultValueEditor = new EditorTextField(doc, getProject(), getFileType());
                        ((PsiExpressionCodeFragment) item.defaultValueCodeFragment).setExpectedType(getRowType(item));
                        myDefaultValueEditor.setPreferredWidth(getTable().getWidth() / 2);
                        myDefaultValueEditor.addDocumentListener(new RowEditorChangeListener(2));
                        additionalPanel.add(createLabeledPanel("Default value:", myDefaultValueEditor), BorderLayout.WEST);
                        if (!isGenerateDelegate()) {
                            myAnyVar = new JCheckBox("&Use Any Var");
                            UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, myAnyVar);
                            DialogUtil.registerMnemonic(myAnyVar, '&');
                            myAnyVar.addActionListener(new ActionListener() {

                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    item.parameter.setUseAnySingleVariable(myAnyVar.isSelected());
                                }
                            });
                            final JPanel anyVarPanel = new JPanel(new BorderLayout());
                            anyVarPanel.add(myAnyVar, BorderLayout.SOUTH);
                            UIUtil.addInsets(anyVarPanel, JBUI.insetsBottom(8));
                            additionalPanel.add(anyVarPanel, BorderLayout.CENTER);
                        //additionalPanel.setPreferredSize(new Dimension(t.getWidth() / 3, -1));
                        }
                        add(additionalPanel, BorderLayout.SOUTH);
                    }
                }

                @Override
                public JBTableRow getValue() {
                    return new JBTableRow() {

                        @Override
                        public Object getValueAt(int column) {
                            switch(column) {
                                case 0:
                                    return item.typeCodeFragment;
                                case 1:
                                    return myNameEditor.getText().trim();
                                case 2:
                                    return item.defaultValueCodeFragment;
                                case 3:
                                    return myAnyVar != null && myAnyVar.isSelected();
                            }
                            return null;
                        }
                    };
                }

                @Override
                public JComponent getPreferredFocusedComponent() {
                    final MouseEvent me = getMouseEvent();
                    if (me == null) {
                        return myTypeEditor.getFocusTarget();
                    }
                    final double x = me.getPoint().getX();
                    return x <= getTypesColumnWidth() ? myTypeEditor.getFocusTarget() : myDefaultValueEditor == null || x <= getNamesColumnWidth() ? myNameEditor.getFocusTarget() : myDefaultValueEditor.getFocusTarget();
                }

                @Override
                public JComponent[] getFocusableComponents() {
                    final List<JComponent> focusable = new ArrayList<>();
                    focusable.add(myTypeEditor.getFocusTarget());
                    focusable.add(myNameEditor.getFocusTarget());
                    if (myDefaultValueEditor != null) {
                        focusable.add(myDefaultValueEditor.getFocusTarget());
                    }
                    if (myAnyVar != null) {
                        focusable.add(myAnyVar);
                    }
                    return focusable.toArray(new JComponent[focusable.size()]);
                }
            };
        }

        @Override
        protected boolean isRowEmpty(int row) {
            ParameterInfoImpl parameter = getRowItem(row).parameter;
            return StringUtil.isEmpty(parameter.getName()) && StringUtil.isEmpty(parameter.getTypeText());
        }
    };
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) Document(com.intellij.openapi.editor.Document) EditorTextFieldJBTableRowRenderer(com.intellij.util.ui.table.EditorTextFieldJBTableRowRenderer) SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo) JBTableRow(com.intellij.util.ui.table.JBTableRow) MouseEvent(java.awt.event.MouseEvent) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) JBTableRowEditor(com.intellij.util.ui.table.JBTableRowEditor) ActionListener(java.awt.event.ActionListener) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder)

Example 95 with MouseEvent

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

the class ConvertToInstanceMethodDialog method createTargetVariableChooser.

@Override
protected JList createTargetVariableChooser() {
    final JList variableChooser = super.createTargetVariableChooser();
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            Point point = e.getPoint();
            int index = variableChooser.locationToIndex(point);
            if (index == -1)
                return false;
            if (!variableChooser.getCellBounds(index, index).contains(point))
                return false;
            doRefactorAction();
            return true;
        }
    }.installOn(variableChooser);
    return variableChooser;
}
Also used : MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener)

Aggregations

MouseEvent (java.awt.event.MouseEvent)918 MouseAdapter (java.awt.event.MouseAdapter)595 Dimension (java.awt.Dimension)183 JPanel (javax.swing.JPanel)174 ActionEvent (java.awt.event.ActionEvent)172 JLabel (javax.swing.JLabel)169 Point (java.awt.Point)143 ActionListener (java.awt.event.ActionListener)123 BorderLayout (java.awt.BorderLayout)119 JScrollPane (javax.swing.JScrollPane)113 JButton (javax.swing.JButton)109 KeyEvent (java.awt.event.KeyEvent)85 ChangeEvent (javax.swing.event.ChangeEvent)85 ChangeListener (javax.swing.event.ChangeListener)83 Insets (java.awt.Insets)79 MouseListener (java.awt.event.MouseListener)72 KeyAdapter (java.awt.event.KeyAdapter)65 JPopupMenu (javax.swing.JPopupMenu)64 JSlider (javax.swing.JSlider)63 GridBagConstraints (java.awt.GridBagConstraints)62