Search in sources :

Example 1 with JBTextArea

use of com.intellij.ui.components.JBTextArea in project ExcelReader by obiscr.

the class MySearchReplaceComponent method updateTextComponent.

private boolean updateTextComponent(boolean search) {
    JTextComponent oldComponent = mySearchTextComponent;
    if (oldComponent != null) {
        return false;
    }
    final MyTextComponentWrapper wrapper = mySearchFieldWrapper;
    @NotNull JTextComponent innerTextComponent;
    @NotNull JComponent outerComponent;
    if (myUseSearchField) {
        outerComponent = new SearchTextField(true, this.toString());
        innerTextComponent = ((SearchTextField) outerComponent).getTextEditor();
        innerTextComponent.setBorder(BorderFactory.createEmptyBorder());
    } else {
        innerTextComponent = new JBTextArea() {

            @Override
            public Dimension getPreferredScrollableViewportSize() {
                Dimension defaultSize = super.getPreferredScrollableViewportSize();
                if (mySplitter != null && mySplitter.getSecondComponent() != null && Registry.is("ide.find.expand.search.field.on.typing", true)) {
                    Dimension preferredSize = getPreferredSize();
                    Dimension minimumSize = getMinimumSize();
                    int spaceForLeftPanel = mySplitter.getWidth() - mySplitter.getSecondComponent().getPreferredSize().width - mySplitter.getDividerWidth();
                    int allSearchTextAreaIcons = JBUI.scale(180);
                    int w = spaceForLeftPanel - allSearchTextAreaIcons;
                    w = Math.max(w, minimumSize.width);
                    return new Dimension(Math.min(Math.max(defaultSize.width, preferredSize.width), w), defaultSize.height);
                }
                return defaultSize;
            }
        };
        ((JBTextArea) innerTextComponent).setRows(1);
        ((JBTextArea) innerTextComponent).setColumns(12);
        innerTextComponent.setMinimumSize(new Dimension(150, 0));
        outerComponent = new SearchTextArea(((JBTextArea) innerTextComponent), search);
        myExtraSearchButtons.clear();
        myExtraSearchButtons.addAll(((SearchTextArea) outerComponent).setExtraActions(myEmbeddedSearchActions.toArray(AnAction.EMPTY_ARRAY)));
    }
    UIUtil.addUndoRedoActions(innerTextComponent);
    wrapper.setContent(outerComponent);
    if (search) {
        innerTextComponent.getAccessibleContext().setAccessibleName(FindBundle.message("find.search.accessible.name"));
    } else {
        innerTextComponent.getAccessibleContext().setAccessibleName(FindBundle.message("find.replace.accessible.name"));
    }
    // Display empty text only when focused
    innerTextComponent.putClientProperty("StatusVisibleFunction", (BooleanFunction<JTextComponent>) (c -> c.getText().isEmpty() && c.isFocusOwner()));
    innerTextComponent.putClientProperty(UIUtil.HIDE_EDITOR_FROM_DATA_CONTEXT_PROPERTY, Boolean.TRUE);
    innerTextComponent.setBackground(UIUtil.getTextFieldBackground());
    JComponent finalTextComponent = innerTextComponent;
    innerTextComponent.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(final FocusEvent e) {
            finalTextComponent.repaint();
        }

        @Override
        public void focusLost(final FocusEvent e) {
            finalTextComponent.repaint();
        }
    });
    return true;
}
Also used : SearchTextArea(com.intellij.find.SearchTextArea) JTextComponent(javax.swing.text.JTextComponent) JBTextArea(com.intellij.ui.components.JBTextArea) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JBTextArea

use of com.intellij.ui.components.JBTextArea in project consulo by consulo.

the class PluginHeaderPanel method initComponents.

private void initComponents() {
    myRoot = new JPanel(new VerticalLayout(JBUI.scale(5)));
    myRoot.setOpaque(false);
    myIconLabel = new JBLabel();
    myName = new JBTextArea();
    myName.setBorder(JBUI.Borders.empty());
    myName.setOpaque(false);
    myName.setLineWrap(true);
    myName.setWrapStyleWord(true);
    myName.setEditable(false);
    myName.setBorder(JBUI.Borders.empty(0, 5));
    myName.setFont(UIUtil.getLabelFont(UIUtil.FontSize.BIGGER));
    myInstallButton = new JButton();
    myInstallButton.setOpaque(false);
    JPanel nameWrapper = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, true, true));
    nameWrapper.setOpaque(false);
    nameWrapper.add(myName);
    myRoot.add(new BorderLayoutPanel().addToLeft(myIconLabel).addToCenter(nameWrapper).andTransparent());
    myRoot.add(new BorderLayoutPanel().addToRight(myInstallButton).andTransparent());
    myExperimentalLabel = new JBLabel();
    myRoot.add(new BorderLayoutPanel().addToRight(myExperimentalLabel).andTransparent());
    myDownloadsPanel = new JPanel(new HorizontalLayout(JBUI.scale(5)));
    myDownloadsPanel.setOpaque(false);
    myDownloadsPanel.add(myDownloads = new JBLabel());
    myDownloadsPanel.add(myRating = new RatesPanel());
    myRating.setVisible(PluginDescriptionPanel.ENABLED_STARS);
    myRoot.add(new BorderLayoutPanel().andTransparent().addToRight(myDownloadsPanel));
    myUpdated = new JBLabel();
    myDownloads.setForeground(JBColor.GRAY);
    myUpdated.setForeground(JBColor.GRAY);
    final Font smallFont = UIUtil.getLabelFont(UIUtil.FontSize.SMALL);
    myDownloads.setFont(smallFont);
    myUpdated.setFont(smallFont);
    myRoot.setVisible(false);
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) VerticalLayout(com.intellij.ui.components.panels.VerticalLayout) JBTextArea(com.intellij.ui.components.JBTextArea) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) HorizontalLayout(com.intellij.ui.components.panels.HorizontalLayout)

Example 3 with JBTextArea

use of com.intellij.ui.components.JBTextArea in project consulo by consulo.

the class FindPopupPanel method initComponents.

private void initComponents() {
    myTitleLabel = new JBLabel(FindBundle.message("find.in.path.dialog.title"), UIUtil.ComponentStyle.REGULAR);
    RelativeFont.BOLD.install(myTitleLabel);
    myInfoLabel = new JBLabel("", UIUtil.ComponentStyle.SMALL);
    myLoadingDecorator = new LoadingDecorator(new JLabel(EmptyIcon.ICON_16), getDisposable(), 250, true, new AsyncProcessIcon("FindInPathLoading"));
    myLoadingDecorator.setLoadingText("");
    ItemListener liveResultsPreviewUpdateListener = __ -> scheduleResultsUpdate();
    myCbFileFilter = createCheckBox("find.popup.filemask", "FileFilter");
    myCbFileFilter.addItemListener(__ -> {
        if (myCbFileFilter.isSelected()) {
            myFileMaskField.setEnabled(true);
            if (myCbFileFilter.getClientProperty("dontRequestFocus") == null) {
                IdeFocusManager.getInstance(myProject).requestFocus(myFileMaskField, true);
                myFileMaskField.getEditor().selectAll();
            }
        } else {
            myFileMaskField.setEnabled(false);
            if (myCbFileFilter.getClientProperty("dontRequestFocus") == null) {
                IdeFocusManager.getInstance(myProject).requestFocus(mySearchComponent, true);
            }
        }
    });
    myCbFileFilter.addItemListener(liveResultsPreviewUpdateListener);
    myFileMaskField = new ComboBox<String>() {

        @Override
        public Dimension getPreferredSize() {
            int width = 0;
            int buttonWidth = 0;
            Component[] components = getComponents();
            for (Component component : components) {
                Dimension size = component.getPreferredSize();
                int w = size != null ? size.width : 0;
                if (component instanceof JButton) {
                    buttonWidth = w;
                }
                width += w;
            }
            ComboBoxEditor editor = getEditor();
            if (editor != null) {
                Component editorComponent = editor.getEditorComponent();
                if (editorComponent != null) {
                    FontMetrics fontMetrics = editorComponent.getFontMetrics(editorComponent.getFont());
                    width = Math.max(width, fontMetrics.stringWidth(String.valueOf(getSelectedItem())) + buttonWidth);
                    // Let's reserve some extra space for just one 'the next' letter
                    width += fontMetrics.stringWidth("m");
                }
            }
            Dimension size = super.getPreferredSize();
            Insets insets = getInsets();
            width += insets.left + insets.right;
            size.width = MathUtil.clamp(width, JBUIScale.scale(80), JBUIScale.scale(500));
            return size;
        }
    };
    myFileMaskField.setEditable(true);
    myFileMaskField.setMaximumRowCount(8);
    myFileMaskField.addActionListener(__ -> scheduleResultsUpdate());
    Component editorComponent = myFileMaskField.getEditor().getEditorComponent();
    if (editorComponent instanceof EditorTextField) {
        final EditorTextField etf = (EditorTextField) editorComponent;
        etf.addDocumentListener(new DocumentListener() {

            @Override
            public void documentChanged(@Nonnull com.intellij.openapi.editor.event.DocumentEvent event) {
                onFileMaskChanged();
            }
        });
    } else {
        if (editorComponent instanceof JTextComponent) {
            ((JTextComponent) editorComponent).getDocument().addDocumentListener(new DocumentAdapter() {

                @Override
                protected void textChanged(@Nonnull DocumentEvent e) {
                    onFileMaskChanged();
                }
            });
        } else {
            assert false;
        }
    }
    AnAction myShowFilterPopupAction = new MyShowFilterPopupAction();
    myFilterContextButton = new ActionButton(myShowFilterPopupAction, myShowFilterPopupAction.getTemplatePresentation(), ActionPlaces.UNKNOWN, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE) {

        @Override
        public int getPopState() {
            int state = super.getPopState();
            if (state != ActionButtonComponent.NORMAL)
                return state;
            return mySelectedContextName.equals(FindInProjectUtil.getPresentableName(FindModel.SearchContext.ANY)) ? ActionButtonComponent.NORMAL : ActionButtonComponent.PUSHED;
        }
    };
    myShowFilterPopupAction.registerCustomShortcutSet(myShowFilterPopupAction.getShortcutSet(), this);
    ToggleAction pinAction = new MyPinAction();
    ActionButton pinButton = new ActionButton(pinAction, pinAction.getTemplatePresentation(), ActionPlaces.UNKNOWN, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE);
    DefaultActionGroup tabOptionsGroup = new DefaultActionGroup() {

        {
            Presentation presentation = getTemplatePresentation();
            presentation.setText(FindBundle.message("find.popup.show.tab.options"));
            presentation.setIcon(AllIcons.General.GearPlain);
            setPopup(true);
            setShortcutSet(CustomShortcutSet.fromString("alt ctrl DOWN"));
            add(new MySkipTabWithOneUsageAction());
            add(new MyOpenResultsInNewTabAction());
        }
    };
    ActionButton tabOptionsButton = new ActionButton(tabOptionsGroup, tabOptionsGroup.getTemplatePresentation(), ActionPlaces.UNKNOWN, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE);
    DumbAwareAction.create(event -> tabOptionsButton.click()).registerCustomShortcutSet(tabOptionsGroup.getShortcutSet(), this);
    myOKButton = new JButton(FindBundle.message("find.popup.find.button"));
    myReplaceAllButton = new JButton(FindBundle.message("find.popup.replace.all.button"));
    myReplaceSelectedButton = new JButton(FindBundle.message("find.popup.replace.selected.button", 0));
    myOkActionListener = __ -> doOK(true);
    myReplaceAllButton.addActionListener(__ -> doOK(false));
    myReplaceSelectedButton.addActionListener(e -> {
        int rowToSelect = myResultsPreviewTable.getSelectionModel().getMinSelectionIndex();
        Map<Integer, Usage> usages = getSelectedUsages();
        if (usages == null) {
            return;
        }
        CommandProcessor.getInstance().executeCommand(myProject, () -> {
            for (Map.Entry<Integer, Usage> entry : usages.entrySet()) {
                try {
                    ReplaceInProjectManager.getInstance(myProject).replaceUsage(entry.getValue(), myHelper.getModel(), Collections.emptySet(), false);
                    ((DefaultTableModel) myResultsPreviewTable.getModel()).removeRow(entry.getKey());
                } catch (FindManager.MalformedReplacementStringException ex) {
                    if (!ApplicationManager.getApplication().isUnitTestMode()) {
                        Messages.showErrorDialog(this, ex.getMessage(), FindBundle.message("find.replace.invalid.replacement.string.title"));
                    }
                    break;
                }
            }
            ApplicationManager.getApplication().invokeLater(() -> {
                if (myResultsPreviewTable.getRowCount() > rowToSelect) {
                    myResultsPreviewTable.getSelectionModel().setSelectionInterval(rowToSelect, rowToSelect);
                }
                ScrollingUtil.ensureSelectionExists(myResultsPreviewTable);
            });
        }, FindBundle.message("find.replace.command"), null);
    });
    myOKButton.addActionListener(myOkActionListener);
    TouchbarDataKeys.putDialogButtonDescriptor(myOKButton, 0, true);
    boolean enterAsOK = Registry.is("ide.find.enter.as.ok", false);
    new MyEnterAction(enterAsOK).registerCustomShortcutSet(new CustomShortcutSet(ENTER), this);
    DumbAwareAction.create(__ -> processCtrlEnter()).registerCustomShortcutSet(new CustomShortcutSet(ENTER_WITH_MODIFIERS), this);
    DumbAwareAction.create(__ -> myReplaceAllButton.doClick()).registerCustomShortcutSet(new CustomShortcutSet(REPLACE_ALL), this);
    myReplaceAllButton.setToolTipText(KeymapUtil.getKeystrokeText(REPLACE_ALL));
    List<Shortcut> navigationKeyStrokes = new ArrayList<>();
    KeyStroke viewSourceKeyStroke = KeymapUtil.getKeyStroke(CommonShortcuts.getViewSource());
    if (viewSourceKeyStroke != null && !Comparing.equal(viewSourceKeyStroke, ENTER_WITH_MODIFIERS) && !Comparing.equal(viewSourceKeyStroke, ENTER)) {
        navigationKeyStrokes.add(new KeyboardShortcut(viewSourceKeyStroke, null));
    }
    KeyStroke editSourceKeyStroke = KeymapUtil.getKeyStroke(CommonShortcuts.getEditSource());
    if (editSourceKeyStroke != null && !Comparing.equal(editSourceKeyStroke, ENTER_WITH_MODIFIERS) && !Comparing.equal(editSourceKeyStroke, ENTER)) {
        navigationKeyStrokes.add(new KeyboardShortcut(editSourceKeyStroke, null));
    }
    if (!navigationKeyStrokes.isEmpty()) {
        DumbAwareAction.create(e -> navigateToSelectedUsage(e)).registerCustomShortcutSet(new CustomShortcutSet(navigationKeyStrokes.toArray(Shortcut.EMPTY_ARRAY)), this);
    }
    mySearchComponent = new JBTextArea();
    mySearchComponent.setColumns(25);
    mySearchComponent.setRows(1);
    mySearchComponent.getAccessibleContext().setAccessibleName(FindBundle.message("find.search.accessible.name"));
    myReplaceComponent = new JBTextArea();
    myReplaceComponent.setColumns(25);
    myReplaceComponent.setRows(1);
    myReplaceComponent.getAccessibleContext().setAccessibleName(FindBundle.message("find.replace.accessible.name"));
    mySearchTextArea = new SearchTextArea(mySearchComponent, true);
    myReplaceTextArea = new SearchTextArea(myReplaceComponent, false);
    mySearchTextArea.setMultilineEnabled(Registry.is("ide.find.as.popup.allow.multiline"));
    myReplaceTextArea.setMultilineEnabled(Registry.is("ide.find.as.popup.allow.multiline"));
    AnAction caseSensitiveAction = createAction("find.popup.case.sensitive", "CaseSensitive", AllIcons.Actions.MatchCase, AllIcons.Actions.MatchCaseHovered, AllIcons.Actions.MatchCaseSelected, myCaseSensitiveState, () -> !myHelper.getModel().isReplaceState() || !myPreserveCaseState.get());
    AnAction wholeWordsAction = createAction("find.whole.words", "WholeWords", AllIcons.Actions.Words, AllIcons.Actions.WordsHovered, AllIcons.Actions.WordsSelected, myWholeWordsState, () -> !myRegexState.get());
    AnAction regexAction = createAction("find.regex", "Regex", AllIcons.Actions.Regex, AllIcons.Actions.RegexHovered, AllIcons.Actions.RegexSelected, myRegexState, () -> !myHelper.getModel().isReplaceState() || !myPreserveCaseState.get());
    List<Component> searchExtraButtons = mySearchTextArea.setExtraActions(caseSensitiveAction, wholeWordsAction, regexAction);
    AnAction preserveCaseAction = createAction("find.options.replace.preserve.case", "PreserveCase", AllIcons.Actions.PreserveCase, AllIcons.Actions.PreserveCaseHover, AllIcons.Actions.PreserveCaseSelected, myPreserveCaseState, () -> !myRegexState.get() && !myCaseSensitiveState.get());
    List<Component> replaceExtraButtons = myReplaceTextArea.setExtraActions(preserveCaseAction);
    myExtraActions.addAll(Arrays.asList(caseSensitiveAction, wholeWordsAction, regexAction, preserveCaseAction));
    Pair<FindPopupScopeUI.ScopeType, JComponent>[] scopeComponents = myScopeUI.getComponents();
    myScopeDetailsPanel = new JPanel(new CardLayout());
    myScopeDetailsPanel.setBorder(JBUI.Borders.emptyBottom(UIUtil.isUnderDefaultMacTheme() ? 0 : 3));
    List<AnAction> scopeActions = new ArrayList<>(scopeComponents.length);
    for (Pair<FindPopupScopeUI.ScopeType, JComponent> scopeComponent : scopeComponents) {
        FindPopupScopeUI.ScopeType scopeType = scopeComponent.first;
        scopeActions.add(new MySelectScopeToggleAction(scopeType));
        myScopeDetailsPanel.add(scopeType.name, scopeComponent.second);
    }
    myScopeSelectionToolbar = createToolbar(scopeActions.toArray(AnAction.EMPTY_ARRAY));
    myScopeSelectionToolbar.setMinimumButtonSize(ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE);
    mySelectedScope = scopeComponents[0].first;
    myResultsPreviewTableModel = createTableModel();
    myResultsPreviewTable = new JBTable(myResultsPreviewTableModel) {

        @Override
        public Dimension getPreferredScrollableViewportSize() {
            return new Dimension(getWidth(), 1 + getRowHeight() * 4);
        }
    };
    myResultsPreviewTable.setFocusable(false);
    myResultsPreviewTable.getEmptyText().setShowAboveCenter(false);
    myResultsPreviewTable.setShowColumns(false);
    myResultsPreviewTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    myResultsPreviewTable.setShowGrid(false);
    myResultsPreviewTable.setIntercellSpacing(JBUI.emptySize());
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(@Nonnull MouseEvent event) {
            if (event.getSource() != myResultsPreviewTable)
                return false;
            navigateToSelectedUsage(null);
            return true;
        }
    }.installOn(myResultsPreviewTable);
    myResultsPreviewTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            myResultsPreviewTable.transferFocus();
        }
    });
    applyFont(JBFont.label(), myResultsPreviewTable);
    JComponent[] tableAware = { mySearchComponent, myReplaceComponent, myReplaceSelectedButton };
    for (JComponent component : tableAware) {
        ScrollingUtil.installActions(myResultsPreviewTable, false, component);
    }
    ActionListener helpAction = __ -> HelpManager.getInstance().invokeHelp("reference.dialogs.findinpath");
    registerKeyboardAction(helpAction, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    registerKeyboardAction(helpAction, KeyStroke.getKeyStroke(KeyEvent.VK_HELP, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    KeymapManager keymapManager = KeymapManager.getInstance();
    Keymap activeKeymap = keymapManager != null ? keymapManager.getActiveKeymap() : null;
    if (activeKeymap != null) {
        ShortcutSet findNextShortcutSet = new CustomShortcutSet(activeKeymap.getShortcuts("FindNext"));
        ShortcutSet findPreviousShortcutSet = new CustomShortcutSet(activeKeymap.getShortcuts("FindPrevious"));
        DumbAwareAction findNextAction = DumbAwareAction.create(event -> {
            int selectedRow = myResultsPreviewTable.getSelectedRow();
            if (selectedRow >= 0 && selectedRow < myResultsPreviewTable.getRowCount() - 1) {
                myResultsPreviewTable.setRowSelectionInterval(selectedRow + 1, selectedRow + 1);
                ScrollingUtil.ensureIndexIsVisible(myResultsPreviewTable, selectedRow + 1, 1);
            }
        });
        DumbAwareAction findPreviousAction = DumbAwareAction.create(event -> {
            int selectedRow = myResultsPreviewTable.getSelectedRow();
            if (selectedRow > 0 && selectedRow <= myResultsPreviewTable.getRowCount() - 1) {
                myResultsPreviewTable.setRowSelectionInterval(selectedRow - 1, selectedRow - 1);
                ScrollingUtil.ensureIndexIsVisible(myResultsPreviewTable, selectedRow - 1, 1);
            }
        });
        for (JComponent component : tableAware) {
            findNextAction.registerCustomShortcutSet(findNextShortcutSet, component);
            findPreviousAction.registerCustomShortcutSet(findPreviousShortcutSet, component);
        }
    }
    myUsagePreviewTitle = new SimpleColoredComponent();
    myUsagePreviewTitle.setBorder(JBUI.Borders.empty(3, 8, 4, 8));
    myUsageViewPresentation = new UsageViewPresentation();
    myUsagePreviewPanel = new UsagePreviewPanel(myProject, myUsageViewPresentation, Registry.is("ide.find.as.popup.editable.code")) {

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(myResultsPreviewTable.getWidth(), Math.max(getHeight(), getLineHeight() * 15));
        }
    };
    Disposer.register(myDisposable, myUsagePreviewPanel);
    final Runnable updatePreviewRunnable = () -> {
        if (Disposer.isDisposed(myDisposable))
            return;
        int[] selectedRows = myResultsPreviewTable.getSelectedRows();
        final List<UsageInfo> selection = new SmartList<>();
        String file = null;
        for (int row : selectedRows) {
            Object value = myResultsPreviewTable.getModel().getValueAt(row, 0);
            UsageInfoAdapter adapter = (UsageInfoAdapter) value;
            file = adapter.getPath();
            if (adapter.isValid()) {
                selection.addAll(Arrays.asList(adapter.getMergedInfos()));
            }
        }
        myReplaceSelectedButton.setText(FindBundle.message("find.popup.replace.selected.button", selection.size()));
        FindInProjectUtil.setupViewPresentation(myUsageViewPresentation, myHelper.getModel().clone());
        myUsagePreviewPanel.updateLayout(selection);
        myUsagePreviewTitle.clear();
        if (myUsagePreviewPanel.getCannotPreviewMessage(selection) == null && file != null) {
            myUsagePreviewTitle.append(PathUtil.getFileName(file), SimpleTextAttributes.REGULAR_ATTRIBUTES);
            VirtualFile virtualFile = VfsUtil.findFileByIoFile(new File(file), true);
            String locationPath = virtualFile == null ? null : getPresentablePath(myProject, virtualFile.getParent(), 120);
            if (locationPath != null) {
                myUsagePreviewTitle.append(spaceAndThinSpace() + locationPath, new SimpleTextAttributes(STYLE_PLAIN, UIUtil.getContextHelpForeground()));
            }
        }
    };
    myResultsPreviewTable.getSelectionModel().addListSelectionListener(e -> {
        if (e.getValueIsAdjusting() || Disposer.isDisposed(myPreviewUpdater))
            return;
        // todo[vasya]: remove this dirty hack of updating preview panel after clicking on Replace button
        myPreviewUpdater.addRequest(updatePreviewRunnable, 50);
    });
    DocumentAdapter documentAdapter = new DocumentAdapter() {

        @Override
        protected void textChanged(@Nonnull DocumentEvent e) {
            if (myDialog == null)
                return;
            if (e.getDocument() == mySearchComponent.getDocument()) {
                scheduleResultsUpdate();
            }
            if (e.getDocument() == myReplaceComponent.getDocument()) {
                applyTo(myHelper.getModel());
                if (myHelper.getModel().isRegularExpressions()) {
                    myComponentValidator.updateInfo(getValidationInfo(myHelper.getModel()));
                }
                ApplicationManager.getApplication().invokeLater(updatePreviewRunnable);
            }
        }
    };
    mySearchComponent.getDocument().addDocumentListener(documentAdapter);
    myReplaceComponent.getDocument().addDocumentListener(documentAdapter);
    mySearchRescheduleOnCancellationsAlarm = new Alarm();
    JBSplitter splitter = new OnePixelSplitter(true, .33f);
    splitter.setSplitterProportionKey(SPLITTER_SERVICE_KEY);
    splitter.getDivider().setBackground(OnePixelDivider.BACKGROUND);
    JBScrollPane scrollPane = new JBScrollPane(myResultsPreviewTable) {

        @Override
        public Dimension getMinimumSize() {
            Dimension size = super.getMinimumSize();
            size.height = myResultsPreviewTable.getPreferredScrollableViewportSize().height;
            return size;
        }
    };
    scrollPane.setBorder(JBUI.Borders.empty());
    splitter.setFirstComponent(scrollPane);
    JPanel bottomPanel = new JPanel(new MigLayout("flowx, ins 4 4 4 4, fillx, hidemode 3, gap 0"));
    bottomPanel.add(tabOptionsButton);
    myOKHintLabel = new JBLabel("");
    myOKHintLabel.setEnabled(false);
    myNavigationHintLabel = new JBLabel("");
    myNavigationHintLabel.setEnabled(false);
    myNavigationHintLabel.setFont(JBUI.Fonts.smallFont());
    Insets insets = myOKButton.getInsets();
    String btnGapLeft = "gapleft " + Math.max(0, JBUIScale.scale(12) - insets.left - insets.right);
    bottomPanel.add(myNavigationHintLabel, btnGapLeft);
    bottomPanel.add(Box.createHorizontalGlue(), "growx, pushx");
    bottomPanel.add(myOKHintLabel);
    bottomPanel.add(myOKButton, btnGapLeft);
    bottomPanel.add(myReplaceAllButton, btnGapLeft);
    bottomPanel.add(myReplaceSelectedButton, btnGapLeft);
    myCodePreviewComponent = myUsagePreviewPanel.createComponent();
    JPanel previewPanel = new JPanel(new BorderLayout());
    previewPanel.add(myUsagePreviewTitle, BorderLayout.NORTH);
    previewPanel.add(myCodePreviewComponent, BorderLayout.CENTER);
    splitter.setSecondComponent(previewPanel);
    JPanel scopesPanel = new JPanel(new MigLayout("flowx, gap 26, ins 0"));
    scopesPanel.add(myScopeSelectionToolbar.getComponent());
    scopesPanel.add(myScopeDetailsPanel, "growx, pushx");
    setLayout(new MigLayout("flowx, ins 4, gap 0, fillx, hidemode 3"));
    myTitlePanel = new JPanel(new MigLayout("flowx, ins 0, gap 0, fillx, filly"));
    myTitlePanel.add(myTitleLabel, "gapright 4");
    myTitlePanel.add(myInfoLabel);
    myTitlePanel.add(myLoadingDecorator.getComponent(), "w 24, wmin 24");
    myTitlePanel.add(Box.createHorizontalGlue(), "growx, pushx");
    add(myTitlePanel, "sx 2, growx, growx, growy");
    add(myCbFileFilter);
    add(myFileMaskField, "gapleft 4, gapright 16");
    if (Registry.is("ide.find.as.popup.allow.pin") || ApplicationManager.getApplication().isInternal()) {
        myIsPinned.set(UISettings.getInstance().getPinFindInPath());
        JPanel twoButtons = new JPanel(new MigLayout("flowx, ins 0, gap 4, fillx, hidemode 3"));
        twoButtons.add(myFilterContextButton);
        JComponent separatorComponent = (JComponent) Box.createRigidArea(new JBDimension(1, 24));
        separatorComponent.setOpaque(true);
        separatorComponent.setBackground(JBUI.CurrentTheme.CustomFrameDecorations.separatorForeground());
        twoButtons.add(separatorComponent);
        twoButtons.add(pinButton);
        add(twoButtons, "wrap");
    } else {
        add(myFilterContextButton, "wrap");
    }
    mySearchTextArea.setBorder(new CompoundBorder(JBUI.Borders.customLine(JBUI.CurrentTheme.BigPopup.searchFieldBorderColor(), 1, 0, 1, 0), JBUI.Borders.empty(1, 0, 2, 0)));
    add(mySearchTextArea, "pushx, growx, sx 10, pad 0 -4 0 4, gaptop 4, wrap");
    myReplaceTextArea.setBorder(new CompoundBorder(JBUI.Borders.customLine(JBUI.CurrentTheme.BigPopup.searchFieldBorderColor(), 0, 0, 1, 0), JBUI.Borders.empty(1, 0, 2, 0)));
    add(myReplaceTextArea, "pushx, growx, sx 10, pad 0 -4 0 4, wrap");
    add(scopesPanel, "sx 10, pushx, growx, ax left, wrap, gaptop 4, gapbottom 4");
    add(splitter, "pushx, growx, growy, pushy, sx 10, wrap, pad -4 -4 4 4");
    add(bottomPanel, "pushx, growx, dock south, sx 10");
    MnemonicHelper.init(this);
    List<Component> focusOrder = new ArrayList<>();
    focusOrder.add(mySearchComponent);
    focusOrder.add(myReplaceComponent);
    focusOrder.addAll(searchExtraButtons);
    focusOrder.addAll(replaceExtraButtons);
    focusOrder.add(myCbFileFilter);
    ContainerUtil.addAll(focusOrder, focusableComponents(myScopeDetailsPanel));
    focusOrder.add(editorComponent);
    ContainerUtil.addAll(focusOrder, focusableComponents(bottomPanel));
    setFocusCycleRoot(true);
    setFocusTraversalPolicy(new ListFocusTraversalPolicy(focusOrder));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TableCellRenderer(javax.swing.table.TableCellRenderer) Border(javax.swing.border.Border) IdeFrameEx(com.intellij.openapi.wm.ex.IdeFrameEx) CompoundBorder(javax.swing.border.CompoundBorder) FileUtil(com.intellij.openapi.util.io.FileUtil) Disposer(consulo.disposer.Disposer) com.intellij.openapi.project(com.intellij.openapi.project) TouchbarDataKeys(com.intellij.ui.mac.TouchbarDataKeys) WindowManager(com.intellij.openapi.wm.WindowManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) HelpManager(com.intellij.openapi.help.HelpManager) DimensionService(com.intellij.openapi.util.DimensionService) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) PopupState(com.intellij.ui.popup.util.PopupState) com.intellij.util.ui(com.intellij.util.ui) Image(consulo.ui.image.Image) com.intellij.util(com.intellij.util) RelativePoint(com.intellij.ui.awt.RelativePoint) FontUtil.spaceAndThinSpace(com.intellij.util.FontUtil.spaceAndThinSpace) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) java.util(java.util) KeymapManager(com.intellij.openapi.keymap.KeymapManager) UsageInfo(com.intellij.usageView.UsageInfo) GlobalSearchScopeUtil(com.intellij.psi.search.GlobalSearchScopeUtil) TextWithMnemonic(com.intellij.openapi.util.text.TextWithMnemonic) ScratchUtil(com.intellij.ide.scratch.ScratchUtil) CommonBundle(com.intellij.CommonBundle) ALT_DOWN_MASK(java.awt.event.InputEvent.ALT_DOWN_MASK) DocumentEvent(javax.swing.event.DocumentEvent) Nullable(javax.annotation.Nullable) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.find(com.intellij.find) JBPopup(com.intellij.openapi.ui.popup.JBPopup) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) com.intellij.openapi.ui(com.intellij.openapi.ui) ShowUsagesAction(com.intellij.find.actions.ShowUsagesAction) Pair(com.intellij.openapi.util.Pair) UsageViewBundle(com.intellij.usageView.UsageViewBundle) Navigatable(com.intellij.pom.Navigatable) Logger(consulo.logging.Logger) IdeFrame(com.intellij.openapi.wm.IdeFrame) AllIcons(com.intellij.icons.AllIcons) ReadTask(com.intellij.openapi.progress.util.ReadTask) JBIterable(com.intellij.util.containers.JBIterable) JBUIScale(com.intellij.ui.scale.JBUIScale) ModalityState(com.intellij.openapi.application.ModalityState) Disposable(consulo.disposer.Disposable) UniqueVFilePathBuilder(com.intellij.openapi.fileEditor.UniqueVFilePathBuilder) Keymap(com.intellij.openapi.keymap.Keymap) JBLabel(com.intellij.ui.components.JBLabel) JBTextArea(com.intellij.ui.components.JBTextArea) VfsPresentationUtil(com.intellij.openapi.vfs.newvfs.VfsPresentationUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PatternSyntaxException(java.util.regex.PatternSyntaxException) SoftReference(com.intellij.reference.SoftReference) DefaultTableModel(javax.swing.table.DefaultTableModel) ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) com.intellij.ui(com.intellij.ui) JBScrollPane(com.intellij.ui.components.JBScrollPane) Reference(java.lang.ref.Reference) ListPopup(com.intellij.openapi.ui.popup.ListPopup) IdeGlassPaneImpl(com.intellij.openapi.wm.impl.IdeGlassPaneImpl) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Contract(org.jetbrains.annotations.Contract) List(java.util.List) JBPanel(com.intellij.ui.components.JBPanel) java.awt.event(java.awt.event) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) Pattern(java.util.regex.Pattern) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) ActionToolbarImpl(com.intellij.openapi.actionSystem.impl.ActionToolbarImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TargetAWT(consulo.awt.TargetAWT) ProgressIndicatorUtils(com.intellij.openapi.progress.util.ProgressIndicatorUtils) ContainerUtil(com.intellij.util.containers.ContainerUtil) CTRL_DOWN_MASK(java.awt.event.InputEvent.CTRL_DOWN_MASK) IdeEventQueue(com.intellij.ide.IdeEventQueue) ReplaceInProjectManager(com.intellij.find.replaceInProject.ReplaceInProjectManager) Comparing(com.intellij.openapi.util.Comparing) STYLE_PLAIN(com.intellij.ui.SimpleTextAttributes.STYLE_PLAIN) LocalizeValue(consulo.localize.LocalizeValue) UsagePreviewPanel(com.intellij.usages.impl.UsagePreviewPanel) PropertyKey(org.jetbrains.annotations.PropertyKey) WeakReference(java.lang.ref.WeakReference) Nonnull(javax.annotation.Nonnull) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) MigLayout(net.miginfocom.swing.MigLayout) com.intellij.usages(com.intellij.usages) UISettings(com.intellij.ide.ui.UISettings) JTextComponent(javax.swing.text.JTextComponent) CommandProcessor(com.intellij.openapi.command.CommandProcessor) JBTable(com.intellij.ui.table.JBTable) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) MnemonicHelper(com.intellij.openapi.MnemonicHelper) VfsUtil(com.intellij.openapi.vfs.VfsUtil) javax.swing(javax.swing) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) UsagePreviewPanel(com.intellij.usages.impl.UsagePreviewPanel) JTextComponent(javax.swing.text.JTextComponent) JBTable(com.intellij.ui.table.JBTable) ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) JBLabel(com.intellij.ui.components.JBLabel) List(java.util.List) CompoundBorder(javax.swing.border.CompoundBorder) DocumentEvent(javax.swing.event.DocumentEvent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) JBScrollPane(com.intellij.ui.components.JBScrollPane) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultTableModel(javax.swing.table.DefaultTableModel) JTextComponent(javax.swing.text.JTextComponent) java.awt.event(java.awt.event) Pair(com.intellij.openapi.util.Pair) Nonnull(javax.annotation.Nonnull) MigLayout(net.miginfocom.swing.MigLayout) JBTextArea(com.intellij.ui.components.JBTextArea) RelativePoint(com.intellij.ui.awt.RelativePoint) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeymapManager(com.intellij.openapi.keymap.KeymapManager) Keymap(com.intellij.openapi.keymap.Keymap)

Example 4 with JBTextArea

use of com.intellij.ui.components.JBTextArea in project sonarlint-intellij by SonarSource.

the class RuleConfigurationPanel method createTextParam.

private void createTextParam(RulesTreeNode.Rule rule, JPanel panel, GridBagConstraints constraints, RulesTreeNode.RuleParam param) {
    addParamLabel(panel, constraints, param);
    addTextField(rule, panel, constraints, param, new JBTextArea());
}
Also used : JBTextArea(com.intellij.ui.components.JBTextArea)

Example 5 with JBTextArea

use of com.intellij.ui.components.JBTextArea in project midpoint-studio by Evolveum.

the class AbstractOpTreePanel method initLayout.

private void initLayout() {
    JBSplitter splitter = new OnePixelSplitter(false);
    add(splitter, BorderLayout.CENTER);
    List<TreeTableColumnDefinition<String, ?>> columns = new ArrayList<>();
    columns.add(new TreeTableColumnDefinition<>("Item", 150, o -> null));
    columns.add(new TreeTableColumnDefinition<>("Variable", 400, o -> null, new ExpansionSensitiveTableCellRenderer()));
    this.variables = MidPointUtils.createTable2(new DefaultTreeTableModel(new DefaultMutableTreeTableNode(), Arrays.asList("Item", "Variable")), MidPointUtils.createTableColumnModel(columns), false);
    this.variables.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.variables.addTreeSelectionListener(this::variablesSelectionChanged);
    this.variables.addHighlighter(new AbstractHighlighter() {

        @Override
        protected Component doHighlight(Component component, ComponentAdapter adapter) {
            int row = adapter.convertRowIndexToModel(adapter.row);
            TreePath pathForRow = variables.getPathForRow(row);
            Node node = (Node) pathForRow.getLastPathComponent();
            if (adapter.isSelected()) {
                component.setBackground(variables.getSelectionBackground());
            } else if (node.getBackgroundColor() == null) {
                component.setBackground(variables.getBackground());
            } else {
                component.setBackground(node.getBackgroundColor());
            }
            return component;
        }
    });
    TableColumn column = this.variables.getColumnModel().getColumn(1);
    column.setCellRenderer(new ExpansionSensitiveTableCellRenderer());
    JComponent mainToolbar = initMainToolbar();
    splitter.setFirstComponent(MidPointUtils.createBorderLayoutPanel(mainToolbar, new JBScrollPane(this.variables), null));
    JPanel left = new BorderLayoutPanel();
    splitter.setSecondComponent(left);
    DefaultActionGroup group = new DefaultActionGroup();
    variablesDisplayAs = new FormatComboboxAction() {

        @Override
        public void setFormat(Format format) {
            super.setFormat(format);
            variableDisplayAsChanged(format);
        }
    };
    group.add(variablesDisplayAs);
    variablesWrapText = new SimpleCheckboxAction("Wrap text") {

        @Override
        public void onStateChange() {
            variablesValue.setLineWrap(isSelected());
            variablesValue.invalidate();
        }
    };
    group.add(variablesWrapText);
    ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("TraceViewVariablesToolbar", group, true);
    toolbar.setTargetComponent(this);
    left.add(toolbar.getComponent(), BorderLayout.NORTH);
    variablesValue = new JBTextArea();
    left.add(MidPointUtils.borderlessScrollPane(variablesValue), BorderLayout.CENTER);
}
Also used : Arrays(java.util.Arrays) AllIcons(com.intellij.icons.AllIcons) DefaultTreeTableModel(org.jdesktop.swingx.treetable.DefaultTreeTableModel) MidPointProjectNotifier(com.evolveum.midpoint.studio.impl.MidPointProjectNotifier) CheckboxAction(com.intellij.openapi.actionSystem.ex.CheckboxAction) FormattingContext(com.evolveum.midpoint.studio.impl.trace.FormattingContext) ViewingState(com.evolveum.midpoint.studio.ui.trace.ViewingState) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ArrayList(java.util.ArrayList) JBTextArea(com.intellij.ui.components.JBTextArea) DefaultMutableTreeTableNode(org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) Project(com.intellij.openapi.project.Project) TreeTableNode(org.jdesktop.swingx.treetable.TreeTableNode) Format(com.evolveum.midpoint.studio.impl.trace.Format) ComboBoxAction(com.intellij.openapi.actionSystem.ex.ComboBoxAction) Logger(com.intellij.openapi.diagnostic.Logger) DumbAware(com.intellij.openapi.project.DumbAware) SimpleCheckboxAction(com.evolveum.midpoint.studio.ui.SimpleCheckboxAction) TreeTableColumnDefinition(com.evolveum.midpoint.studio.ui.TreeTableColumnDefinition) AbstractHighlighter(org.jdesktop.swingx.decorator.AbstractHighlighter) TreePath(javax.swing.tree.TreePath) JBSplitter(com.intellij.ui.JBSplitter) TableColumn(javax.swing.table.TableColumn) ComponentAdapter(org.jdesktop.swingx.decorator.ComponentAdapter) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Node(com.evolveum.midpoint.studio.ui.trace.entry.Node) JXTreeTable(org.jdesktop.swingx.JXTreeTable) JBScrollPane(com.intellij.ui.components.JBScrollPane) OpNode(com.evolveum.midpoint.schema.traces.OpNode) MidPointUtils(com.evolveum.midpoint.studio.util.MidPointUtils) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) List(java.util.List) OnePixelSplitter(com.intellij.ui.OnePixelSplitter) NotNull(org.jetbrains.annotations.NotNull) MessageBus(com.intellij.util.messages.MessageBus) MidPointProjectNotifierAdapter(com.evolveum.midpoint.studio.impl.MidPointProjectNotifierAdapter) javax.swing(javax.swing) DefaultMutableTreeTableNode(org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode) TreeTableNode(org.jdesktop.swingx.treetable.TreeTableNode) Node(com.evolveum.midpoint.studio.ui.trace.entry.Node) OpNode(com.evolveum.midpoint.schema.traces.OpNode) ArrayList(java.util.ArrayList) DefaultMutableTreeTableNode(org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode) Format(com.evolveum.midpoint.studio.impl.trace.Format) ComponentAdapter(org.jdesktop.swingx.decorator.ComponentAdapter) TreeTableColumnDefinition(com.evolveum.midpoint.studio.ui.TreeTableColumnDefinition) DefaultTreeTableModel(org.jdesktop.swingx.treetable.DefaultTreeTableModel) OnePixelSplitter(com.intellij.ui.OnePixelSplitter) JBTextArea(com.intellij.ui.components.JBTextArea) TableColumn(javax.swing.table.TableColumn) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) SimpleCheckboxAction(com.evolveum.midpoint.studio.ui.SimpleCheckboxAction) TreePath(javax.swing.tree.TreePath) AbstractHighlighter(org.jdesktop.swingx.decorator.AbstractHighlighter) JBSplitter(com.intellij.ui.JBSplitter) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Aggregations

JBTextArea (com.intellij.ui.components.JBTextArea)15 JBScrollPane (com.intellij.ui.components.JBScrollPane)7 NotNull (org.jetbrains.annotations.NotNull)4 SimpleCheckboxAction (com.evolveum.midpoint.studio.ui.SimpleCheckboxAction)3 JTextComponent (javax.swing.text.JTextComponent)3 AllIcons (com.intellij.icons.AllIcons)2 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)2 JBLabel (com.intellij.ui.components.JBLabel)2 BorderLayoutPanel (com.intellij.util.ui.components.BorderLayoutPanel)2 java.awt (java.awt)2 List (java.util.List)2 javax.swing (javax.swing)2 OpNode (com.evolveum.midpoint.schema.traces.OpNode)1 MidPointProjectNotifier (com.evolveum.midpoint.studio.impl.MidPointProjectNotifier)1 MidPointProjectNotifierAdapter (com.evolveum.midpoint.studio.impl.MidPointProjectNotifierAdapter)1 Format (com.evolveum.midpoint.studio.impl.trace.Format)1 FormattingContext (com.evolveum.midpoint.studio.impl.trace.FormattingContext)1 TreeTableColumnDefinition (com.evolveum.midpoint.studio.ui.TreeTableColumnDefinition)1 ViewingState (com.evolveum.midpoint.studio.ui.trace.ViewingState)1 Node (com.evolveum.midpoint.studio.ui.trace.entry.Node)1