Search in sources :

Example 1 with UiNotifyConnector

use of com.intellij.util.ui.update.UiNotifyConnector in project intellij-community by JetBrains.

the class AbstractTreeUi method init.

protected void init(@NotNull AbstractTreeBuilder builder, @NotNull JTree tree, @NotNull DefaultTreeModel treeModel, AbstractTreeStructure treeStructure, @Nullable Comparator<NodeDescriptor> comparator, boolean updateIfInactive) {
    myBuilder = builder;
    myTree = tree;
    myTreeModel = treeModel;
    myActivityMonitor = UiActivityMonitor.getInstance();
    myActivityId = new UiActivity.AsyncBgOperation("TreeUi" + this);
    addModelListenerToDianoseAccessOutsideEdt();
    TREE_NODE_WRAPPER = builder.createSearchingTreeNodeWrapper();
    myTree.setModel(myTreeModel);
    setRootNode((DefaultMutableTreeNode) treeModel.getRoot());
    myTreeStructure = treeStructure;
    myNodeDescriptorComparator = comparator;
    myUpdateIfInactive = updateIfInactive;
    UIUtil.invokeLaterIfNeeded(new TreeRunnable("AbstractTreeUi.init") {

        @Override
        public void perform() {
            if (!wasRootNodeInitialized()) {
                if (myRootNode.getChildCount() == 0) {
                    insertLoadingNode(myRootNode, true);
                }
            }
        }
    });
    myExpansionListener = new MyExpansionListener();
    myTree.addTreeExpansionListener(myExpansionListener);
    mySelectionListener = new MySelectionListener();
    myTree.addTreeSelectionListener(mySelectionListener);
    setUpdater(getBuilder().createUpdater());
    myProgress = getBuilder().createProgressIndicator();
    Disposer.register(getBuilder(), getUpdater());
    if (myProgress != null) {
        Disposer.register(getBuilder(), new Disposable() {

            @Override
            public void dispose() {
                myProgress.cancel();
            }
        });
    }
    final UiNotifyConnector uiNotify = new UiNotifyConnector(tree, new Activatable() {

        @Override
        public void showNotify() {
            myShowing = true;
            myWasEverShown = true;
            if (canInitiateNewActivity()) {
                activate(true);
            }
        }

        @Override
        public void hideNotify() {
            myShowing = false;
            if (canInitiateNewActivity()) {
                deactivate();
            }
        }
    });
    Disposer.register(getBuilder(), uiNotify);
    myTree.addFocusListener(myFocusListener);
}
Also used : Disposable(com.intellij.openapi.Disposable) Activatable(com.intellij.util.ui.update.Activatable) UiActivity(com.intellij.ide.UiActivity) UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector)

Example 2 with UiNotifyConnector

use of com.intellij.util.ui.update.UiNotifyConnector in project intellij-community by JetBrains.

the class LookupImpl method addListeners.

private void addListeners() {
    myEditor.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            if (!myChangeGuard && !myFinishing) {
                hideLookup(false);
            }
        }
    }, this);
    final CaretListener caretListener = new CaretAdapter() {

        @Override
        public void caretPositionChanged(CaretEvent e) {
            if (!myChangeGuard && !myFinishing) {
                hideLookup(false);
            }
        }
    };
    final SelectionListener selectionListener = new SelectionListener() {

        @Override
        public void selectionChanged(final SelectionEvent e) {
            if (!myChangeGuard && !myFinishing) {
                hideLookup(false);
            }
        }
    };
    final EditorMouseListener mouseListener = new EditorMouseAdapter() {

        @Override
        public void mouseClicked(EditorMouseEvent e) {
            e.consume();
            hideLookup(false);
        }
    };
    myEditor.getCaretModel().addCaretListener(caretListener);
    myEditor.getSelectionModel().addSelectionListener(selectionListener);
    myEditor.addEditorMouseListener(mouseListener);
    Disposer.register(this, new Disposable() {

        @Override
        public void dispose() {
            myEditor.getCaretModel().removeCaretListener(caretListener);
            myEditor.getSelectionModel().removeSelectionListener(selectionListener);
            myEditor.removeEditorMouseListener(mouseListener);
        }
    });
    JComponent editorComponent = myEditor.getContentComponent();
    if (editorComponent.isShowing()) {
        Disposer.register(this, new UiNotifyConnector(editorComponent, new Activatable() {

            @Override
            public void showNotify() {
            }

            @Override
            public void hideNotify() {
                hideLookup(false);
            }
        }));
    }
    myList.addListSelectionListener(new ListSelectionListener() {

        private LookupElement oldItem = null;

        @Override
        public void valueChanged(@NotNull ListSelectionEvent e) {
            if (!myUpdating) {
                final LookupElement item = getCurrentItem();
                fireCurrentItemChanged(oldItem, item);
                oldItem = item;
            }
        }
    });
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            setFocusDegree(FocusDegree.FOCUSED);
            markSelectionTouched();
            if (clickCount == 2) {
                CommandProcessor.getInstance().executeCommand(myProject, () -> finishLookup(NORMAL_SELECT_CHAR), "", null);
            }
            return true;
        }
    }.installOn(myList);
}
Also used : Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) Activatable(com.intellij.util.ui.update.Activatable) ListSelectionEvent(javax.swing.event.ListSelectionEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) RelativePoint(com.intellij.ui.awt.RelativePoint) ListSelectionListener(javax.swing.event.ListSelectionListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 3 with UiNotifyConnector

use of com.intellij.util.ui.update.UiNotifyConnector in project intellij-community by JetBrains.

the class XXXXX method initComponent.

private void initComponent() {
    myPanel.setLayout(new BorderLayout());
    myPanel.add(myHeaderPanel, BorderLayout.NORTH);
    myGutterComponent.setOpaque(true);
    myScrollPane.setViewportView(myEditorComponent);
    //myScrollPane.setBorder(null);
    myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    myScrollPane.setRowHeaderView(myGutterComponent);
    myEditorComponent.setTransferHandler(new MyTransferHandler());
    myEditorComponent.setAutoscrolls(true);
    if (mayShowToolbar()) {
        JLayeredPane layeredPane = new JBLayeredPane() {

            @Override
            public void doLayout() {
                final Component[] components = getComponents();
                final Rectangle r = getBounds();
                for (Component c : components) {
                    if (c instanceof JScrollPane) {
                        c.setBounds(0, 0, r.width, r.height);
                    } else {
                        final Dimension d = c.getPreferredSize();
                        final MyScrollBar scrollBar = getVerticalScrollBar();
                        c.setBounds(r.width - d.width - scrollBar.getWidth() - 30, 20, d.width, d.height);
                    }
                }
            }

            @Override
            public Dimension getPreferredSize() {
                return myScrollPane.getPreferredSize();
            }
        };
        layeredPane.add(myScrollPane, JLayeredPane.DEFAULT_LAYER);
        myPanel.add(layeredPane);
        new ContextMenuImpl(layeredPane, myScrollPane, this);
    } else {
        myPanel.add(myScrollPane);
    }
    myEditorComponent.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() >= KeyEvent.VK_A && e.getKeyCode() <= KeyEvent.VK_Z) {
                myCharKeyPressed = true;
            }
            KeyboardInternationalizationNotificationManager.showNotification();
        }

        @Override
        public void keyTyped(@NotNull KeyEvent event) {
            myNeedToSelectPreviousChar = false;
            if (event.isConsumed()) {
                return;
            }
            if (processKeyTyped(event)) {
                event.consume();
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            myCharKeyPressed = false;
        }
    });
    MyMouseAdapter mouseAdapter = new MyMouseAdapter();
    myEditorComponent.addMouseListener(mouseAdapter);
    myGutterComponent.addMouseListener(mouseAdapter);
    MyMouseMotionListener mouseMotionListener = new MyMouseMotionListener();
    myEditorComponent.addMouseMotionListener(mouseMotionListener);
    myGutterComponent.addMouseMotionListener(mouseMotionListener);
    myEditorComponent.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(@NotNull FocusEvent e) {
            myCaretCursor.activate();
            for (Caret caret : myCaretModel.getAllCarets()) {
                int caretLine = caret.getLogicalPosition().line;
                repaintLines(caretLine, caretLine);
            }
            fireFocusGained();
        }

        @Override
        public void focusLost(@NotNull FocusEvent e) {
            clearCaretThread();
            for (Caret caret : myCaretModel.getAllCarets()) {
                int caretLine = caret.getLogicalPosition().line;
                repaintLines(caretLine, caretLine);
            }
            fireFocusLost();
        }
    });
    UiNotifyConnector connector = new UiNotifyConnector(myEditorComponent, new Activatable.Adapter() {

        @Override
        public void showNotify() {
            myGutterComponent.updateSize();
        }
    });
    Disposer.register(getDisposable(), connector);
    try {
        final DropTarget dropTarget = myEditorComponent.getDropTarget();
        if (dropTarget != null) {
            // might be null in headless environment
            dropTarget.addDropTargetListener(new DropTargetAdapter() {

                @Override
                public void drop(@NotNull DropTargetDropEvent e) {
                }

                @Override
                public void dragOver(@NotNull DropTargetDragEvent e) {
                    Point location = e.getLocation();
                    getCaretModel().moveToLogicalPosition(getLogicalPositionForScreenPos(location.x, location.y, true));
                    getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
                }
            });
        }
    } catch (TooManyListenersException e) {
        LOG.error(e);
    }
    myPanel.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(@NotNull ComponentEvent e) {
            myMarkupModel.recalcEditorDimensions();
            myMarkupModel.repaint(-1, -1);
        }
    });
}
Also used : UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) EditorFragmentComponent(com.intellij.codeInsight.hint.EditorFragmentComponent) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) Activatable(com.intellij.util.ui.update.Activatable) DropTargetAdapter(java.awt.dnd.DropTargetAdapter) JBLayeredPane(com.intellij.ui.components.JBLayeredPane) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Example 4 with UiNotifyConnector

use of com.intellij.util.ui.update.UiNotifyConnector in project intellij-community by JetBrains.

the class IdeGlassPaneUtil method installPainter.

public static void installPainter(final JComponent target, final Painter painter, final Disposable parent) {
    final UiNotifyConnector connector = new UiNotifyConnector(target, new Activatable() {

        IdeGlassPane myPane;

        public void showNotify() {
            IdeGlassPane pane = find(target);
            if (myPane != null && myPane != pane) {
                myPane.removePainter(painter);
            }
            myPane = pane;
            myPane.addPainter(target, painter, parent);
        }

        public void hideNotify() {
            if (myPane != null) {
                myPane.removePainter(painter);
            }
        }
    });
    Disposer.register(parent, connector);
}
Also used : Activatable(com.intellij.util.ui.update.Activatable) UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector)

Example 5 with UiNotifyConnector

use of com.intellij.util.ui.update.UiNotifyConnector in project intellij-community by JetBrains.

the class YYYYYYY method initComponent.

private void initComponent() {
    myPanel.setLayout(new BorderLayout());
    myPanel.add(myHeaderPanel, BorderLayout.NORTH);
    myGutterComponent.setOpaque(true);
    myScrollPane.setViewportView(myEditorComponent);
    //myScrollPane.setBorder(null);
    myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    myScrollPane.setRowHeaderView(myGutterComponent);
    myEditorComponent.setTransferHandler(new MyTransferHandler());
    myEditorComponent.setAutoscrolls(true);
    if (mayShowToolbar()) {
        JLayeredPane layeredPane = new JBLayeredPane() {

            @Override
            public void doLayout() {
                final Component[] components = getComponents();
                final Rectangle r = getBounds();
                for (Component c : components) {
                    if (c instanceof JScrollPane) {
                        c.setBounds(0, 0, r.width, r.height);
                    } else {
                        final Dimension d = c.getPreferredSize();
                        final MyScrollBar scrollBar = getVerticalScrollBar();
                        c.setBounds(r.width - d.width - scrollBar.getWidth() - 30, 20, d.width, d.height);
                    }
                }
            }

            @Override
            public Dimension getPreferredSize() {
                return myScrollPane.getPreferredSize();
            }
        };
        layeredPane.add(myScrollPane, JLayeredPane.DEFAULT_LAYER);
        myPanel.add(layeredPane);
        new ContextMenuImpl(layeredPane, myScrollPane, this);
    } else {
        myPanel.add(myScrollPane);
    }
    myEditorComponent.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(@NotNull KeyEvent e) {
            if (e.getKeyCode() >= KeyEvent.VK_A && e.getKeyCode() <= KeyEvent.VK_Z) {
                myCharKeyPressed = true;
            }
            KeyboardInternationalizationNotificationManager.showNotification();
        }

        @Override
        public void keyTyped(@NotNull KeyEvent event) {
            myNeedToSelectPreviousChar = false;
            if (event.isConsumed()) {
                return;
            }
            if (processKeyTyped(event)) {
                event.consume();
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            myCharKeyPressed = false;
        }
    });
    MyMouseAdapter mouseAdapter = new MyMouseAdapter();
    myEditorComponent.addMouseListener(mouseAdapter);
    myGutterComponent.addMouseListener(mouseAdapter);
    MyMouseMotionListener mouseMotionListener = new MyMouseMotionListener();
    myEditorComponent.addMouseMotionListener(mouseMotionListener);
    myGutterComponent.addMouseMotionListener(mouseMotionListener);
    myEditorComponent.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(@NotNull FocusEvent e) {
            myCaretCursor.activate();
            for (Caret caret : myCaretModel.getAllCarets()) {
                int caretLine = caret.getLogicalPosition().line;
                repaintLines(caretLine, caretLine);
            }
            fireFocusGained();
        }

        @Override
        public void focusLost(@NotNull FocusEvent e) {
            clearCaretThread();
            for (Caret caret : myCaretModel.getAllCarets()) {
                int caretLine = caret.getLogicalPosition().line;
                repaintLines(caretLine, caretLine);
            }
            fireFocusLost();
        }
    });
    UiNotifyConnector connector = new UiNotifyConnector(myEditorComponent, new Activatable.Adapter() {

        @Override
        public void showNotify() {
            myGutterComponent.updateSize();
        }
    });
    Disposer.register(getDisposable(), connector);
    try {
        final DropTarget dropTarget = myEditorComponent.getDropTarget();
        if (dropTarget != null) {
            // might be null in headless environment
            dropTarget.addDropTargetListener(new DropTargetAdapter() {

                @Override
                public void drop(@NotNull DropTargetDropEvent e) {
                }

                @Override
                public void dragOver(@NotNull DropTargetDragEvent e) {
                    Point location = e.getLocation();
                    getCaretModel().moveToLogicalPosition(getLogicalPositionForScreenPos(location.x, location.y, true));
                    getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
                }
            });
        }
    } catch (TooManyListenersException e) {
        LOG.error(e);
    }
    myPanel.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(@NotNull ComponentEvent e) {
            myMarkupModel.recalcEditorDimensions();
            myMarkupModel.repaint(-1, -1);
        }
    });
}
Also used : UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) EditorFragmentComponent(com.intellij.codeInsight.hint.EditorFragmentComponent) Override(java.lang.Override) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) Activatable(com.intellij.util.ui.update.Activatable) DropTargetAdapter(java.awt.dnd.DropTargetAdapter) JBLayeredPane(com.intellij.ui.components.JBLayeredPane) DropTarget(java.awt.dnd.DropTarget) DropTargetDropEvent(java.awt.dnd.DropTargetDropEvent)

Aggregations

UiNotifyConnector (com.intellij.util.ui.update.UiNotifyConnector)13 Activatable (com.intellij.util.ui.update.Activatable)11 EditorFragmentComponent (com.intellij.codeInsight.hint.EditorFragmentComponent)3 Disposable (com.intellij.openapi.Disposable)3 JBLayeredPane (com.intellij.ui.components.JBLayeredPane)3 DropTarget (java.awt.dnd.DropTarget)3 DropTargetAdapter (java.awt.dnd.DropTargetAdapter)3 DropTargetDragEvent (java.awt.dnd.DropTargetDragEvent)3 DropTargetDropEvent (java.awt.dnd.DropTargetDropEvent)3 MergingUpdateQueue (com.intellij.util.ui.update.MergingUpdateQueue)2 UiActivity (com.intellij.ide.UiActivity)1 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)1 PresentationData (com.intellij.ide.projectView.PresentationData)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 PresentableNodeDescriptor (com.intellij.ide.util.treeView.PresentableNodeDescriptor)1 ApplicationActivationListener (com.intellij.openapi.application.ApplicationActivationListener)1 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 IdeFrame (com.intellij.openapi.wm.IdeFrame)1