Search in sources :

Example 1 with SearchTextArea

use of com.intellij.find.SearchTextArea 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)

Aggregations

SearchTextArea (com.intellij.find.SearchTextArea)1 JBTextArea (com.intellij.ui.components.JBTextArea)1 JTextComponent (javax.swing.text.JTextComponent)1 NotNull (org.jetbrains.annotations.NotNull)1