Search in sources :

Example 6 with UiNotifyConnector

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

the class Alarm method setActivationComponent.

@NotNull
public Alarm setActivationComponent(@NotNull final JComponent component) {
    myActivationComponent = component;
    //noinspection ResultOfObjectAllocationIgnored
    new UiNotifyConnector(component, new Activatable() {

        @Override
        public void showNotify() {
            flushPending();
        }

        @Override
        public void hideNotify() {
        }
    });
    return this;
}
Also used : Activatable(com.intellij.util.ui.update.Activatable) UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with UiNotifyConnector

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

the class EditorImpl 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();
                        int rightInsets = getVerticalScrollBar().getWidth() + (isMirrored() ? myGutterComponent.getWidth() : 0);
                        c.setBounds(r.width - d.width - rightInsets - 20, 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;
        }
    });
    myEditorComponent.addMouseListener(myMouseListener);
    myGutterComponent.addMouseListener(myMouseListener);
    myEditorComponent.addMouseMotionListener(myMouseMotionListener);
    myGutterComponent.addMouseMotionListener(myMouseMotionListener);
    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.updateSizeOnShowNotify();
        }
    });
    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().moveToVisualPosition(getTargetPosition(location.x, location.y, true));
                    getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
                    requestFocus();
                }
            });
        }
    } catch (TooManyListenersException e) {
        LOG.error(e);
    }
    // update area available for soft wrapping on component shown/hidden
    myPanel.addHierarchyListener(e -> mySoftWrapModel.getApplianceManager().updateAvailableArea());
    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 8 with UiNotifyConnector

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

the class DockablePopupManager method createToolWindow.

public void createToolWindow(final PsiElement element, PsiElement originalElement) {
    assert myToolWindow == null;
    final T component = createComponent();
    final ToolWindowManagerEx toolWindowManagerEx = ToolWindowManagerEx.getInstanceEx(myProject);
    final ToolWindow toolWindow = toolWindowManagerEx.getToolWindow(getToolwindowId());
    myToolWindow = toolWindow == null ? toolWindowManagerEx.registerToolWindow(getToolwindowId(), true, ToolWindowAnchor.RIGHT, myProject) : toolWindow;
    myToolWindow.setIcon(AllIcons.Toolwindows.Documentation);
    myToolWindow.setAvailable(true, null);
    myToolWindow.setToHideOnEmptyContent(false);
    setToolwindowDefaultState();
    ((ToolWindowEx) myToolWindow).setTitleActions(createRestorePopupAction());
    final ContentManager contentManager = myToolWindow.getContentManager();
    final ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
    final Content content = contentFactory.createContent(component, getTitle(element), false);
    contentManager.addContent(content);
    contentManager.addContentManagerListener(new ContentManagerAdapter() {

        @Override
        public void contentRemoved(ContentManagerEvent event) {
            restorePopupBehavior();
        }
    });
    new UiNotifyConnector(component, new Activatable() {

        @Override
        public void showNotify() {
            restartAutoUpdate(myAutoUpdateDocumentation);
        }

        @Override
        public void hideNotify() {
            restartAutoUpdate(false);
        }
    });
    myToolWindow.show(null);
    PropertiesComponent.getInstance().setValue(getShowInToolWindowProperty(), Boolean.TRUE.toString());
    restartAutoUpdate(PropertiesComponent.getInstance().getBoolean(getAutoUpdateEnabledProperty(), true));
    doUpdateComponent(element, originalElement, component);
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) ToolWindowEx(com.intellij.openapi.wm.ex.ToolWindowEx) Activatable(com.intellij.util.ui.update.Activatable) UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx)

Example 9 with UiNotifyConnector

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

the class AbstractProjectViewPSIPane method createComponent.

@Override
public JComponent createComponent() {
    if (myComponent != null)
        return myComponent;
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(null);
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    myTree = createTree(treeModel);
    enableDnD();
    myComponent = ScrollPaneFactory.createScrollPane(myTree);
    if (Registry.is("error.stripe.enabled")) {
        ErrorStripePainter painter = new ErrorStripePainter(true);
        Disposer.register(this, new TreeUpdater<ErrorStripePainter>(painter, myComponent, myTree) {

            @Override
            protected void update(ErrorStripePainter painter, int index, Object object) {
                if (object instanceof DefaultMutableTreeNode) {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) object;
                    object = node.getUserObject();
                }
                if (object instanceof PsiDirectoryNode && !myTree.isCollapsed(index)) {
                    object = null;
                }
                super.update(painter, index, object);
            }

            @Override
            protected ErrorStripe getErrorStripe(Object object) {
                if (object instanceof PresentableNodeDescriptor) {
                    PresentableNodeDescriptor node = (PresentableNodeDescriptor) object;
                    PresentationData presentation = node.getPresentation();
                    TextAttributesKey key = presentation.getTextAttributesKey();
                    if (key != null) {
                        TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
                        if (attributes != null && EffectType.WAVE_UNDERSCORE == attributes.getEffectType()) {
                            return ErrorStripe.create(attributes.getEffectColor(), 1);
                        }
                    }
                }
                return null;
            }
        });
    }
    myTreeStructure = createStructure();
    BaseProjectTreeBuilder treeBuilder = createBuilder(treeModel);
    installComparator(treeBuilder);
    setTreeBuilder(treeBuilder);
    initTree();
    Disposer.register(getTreeBuilder(), new UiNotifyConnector(myTree, new Activatable() {

        private boolean showing;

        @Override
        public void showNotify() {
            if (!showing) {
                showing = true;
                restoreExpandedPaths();
            }
        }

        @Override
        public void hideNotify() {
            if (showing) {
                showing = false;
                saveExpandedPaths();
            }
        }
    }));
    return myComponent;
}
Also used : ErrorStripe(com.intellij.ui.stripe.ErrorStripe) PresentableNodeDescriptor(com.intellij.ide.util.treeView.PresentableNodeDescriptor) PresentationData(com.intellij.ide.projectView.PresentationData) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Activatable(com.intellij.util.ui.update.Activatable) ErrorStripePainter(com.intellij.ui.stripe.ErrorStripePainter) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) BaseProjectTreeBuilder(com.intellij.ide.projectView.BaseProjectTreeBuilder)

Example 10 with UiNotifyConnector

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

the class MouseDragHelper method start.

public void start() {
    if (myGlassPane != null)
        return;
    new UiNotifyConnector(myDragComponent, new Activatable() {

        @Override
        public void showNotify() {
            attach();
        }

        @Override
        public void hideNotify() {
            detach(true);
        }
    });
    Disposer.register(myParentDisposable, new Disposable() {

        @Override
        public void dispose() {
            stop();
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) Activatable(com.intellij.util.ui.update.Activatable) UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector)

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