Search in sources :

Example 1 with ComponentEvent

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

the class ActionToolbarImpl method showAutoPopup.

private void showAutoPopup() {
    if (isPopupShowing())
        return;
    final ActionGroup group;
    if (myOrientation == SwingConstants.HORIZONTAL) {
        group = myActionGroup;
    } else {
        final DefaultActionGroup outside = new DefaultActionGroup();
        for (int i = myFirstOutsideIndex; i < myVisibleActions.size(); i++) {
            outside.add(myVisibleActions.get(i));
        }
        group = outside;
    }
    PopupToolbar popupToolbar = new PopupToolbar(myPlace, group, true, myDataManager, myActionManager, myUpdater.getKeymapManager(), this) {

        @Override
        protected void onOtherActionPerformed() {
            hidePopup();
        }

        @Override
        protected DataContext getDataContext() {
            return ActionToolbarImpl.this.getDataContext();
        }
    };
    popupToolbar.setLayoutPolicy(NOWRAP_LAYOUT_POLICY);
    popupToolbar.updateActionsImmediately();
    Point location;
    if (myOrientation == SwingConstants.HORIZONTAL) {
        location = getLocationOnScreen();
    } else {
        location = getLocationOnScreen();
        location.y = location.y + getHeight() - popupToolbar.getPreferredSize().height;
    }
    final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(popupToolbar, null);
    builder.setResizable(false).setMovable(// fit the screen automatically
    true).setRequestFocus(false).setTitle(null).setCancelOnClickOutside(true).setCancelOnOtherWindowOpen(true).setCancelCallback(() -> {
        final boolean toClose = myActionManager.isActionPopupStackEmpty();
        if (toClose) {
            myUpdater.updateActions(false, true);
        }
        return toClose;
    }).setCancelOnMouseOutCallback(new MouseChecker() {

        @Override
        public boolean check(final MouseEvent event) {
            return myAutoPopupRec != null && myActionManager.isActionPopupStackEmpty() && !new RelativeRectangle(ActionToolbarImpl.this, myAutoPopupRec).contains(new RelativePoint(event));
        }
    });
    builder.addListener(new JBPopupAdapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            processClosed();
        }
    });
    myPopup = builder.createPopup();
    final AnActionListener.Adapter listener = new AnActionListener.Adapter() {

        @Override
        public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
            final JBPopup popup = myPopup;
            if (popup != null && !popup.isDisposed() && popup.isVisible()) {
                popup.cancel();
            }
        }
    };
    ActionManager.getInstance().addAnActionListener(listener);
    Disposer.register(myPopup, popupToolbar);
    Disposer.register(popupToolbar, new Disposable() {

        @Override
        public void dispose() {
            ActionManager.getInstance().removeAnActionListener(listener);
        }
    });
    myPopup.showInScreenCoordinates(this, location);
    final Window window = SwingUtilities.getWindowAncestor(this);
    if (window != null) {
        final ComponentAdapter componentAdapter = new ComponentAdapter() {

            @Override
            public void componentResized(final ComponentEvent e) {
                hidePopup();
            }

            @Override
            public void componentMoved(final ComponentEvent e) {
                hidePopup();
            }

            @Override
            public void componentShown(final ComponentEvent e) {
                hidePopup();
            }

            @Override
            public void componentHidden(final ComponentEvent e) {
                hidePopup();
            }
        };
        window.addComponentListener(componentAdapter);
        Disposer.register(popupToolbar, new Disposable() {

            @Override
            public void dispose() {
                window.removeComponentListener(componentAdapter);
            }
        });
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) ComponentAdapter(java.awt.event.ComponentAdapter) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 2 with ComponentEvent

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

the class AdjustComponentWhenShown method install.

public void install(final Component component) {
    final ComponentListener listener = new ComponentListener() {

        @Override
        public void componentResized(ComponentEvent e) {
            impl();
        }

        private void impl() {
            if (canExecute()) {
                if (init()) {
                    component.removeComponentListener(this);
                    myIsAdjusted = true;
                }
            }
        }

        @Override
        public void componentMoved(ComponentEvent e) {
        }

        @Override
        public void componentShown(ComponentEvent e) {
            impl();
        }

        @Override
        public void componentHidden(ComponentEvent e) {
        }
    };
    component.addComponentListener(listener);
}
Also used : ComponentListener(java.awt.event.ComponentListener) ComponentEvent(java.awt.event.ComponentEvent)

Example 3 with ComponentEvent

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

the class MultilineTreeCellRenderer method installRenderer.

public static JScrollPane installRenderer(final JTree tree, final MultilineTreeCellRenderer renderer) {
    final TreeCellRenderer defaultRenderer = tree.getCellRenderer();
    JScrollPane scrollpane = new JBScrollPane(tree) {

        private int myAddRemoveCounter = 0;

        private boolean myShouldResetCaches = false;

        public void setSize(Dimension d) {
            boolean isChanged = getWidth() != d.width || myShouldResetCaches;
            super.setSize(d);
            if (isChanged)
                resetCaches();
        }

        public void reshape(int x, int y, int w, int h) {
            boolean isChanged = w != getWidth() || myShouldResetCaches;
            super.reshape(x, y, w, h);
            if (isChanged)
                resetCaches();
        }

        private void resetCaches() {
            resetHeightCache(tree, defaultRenderer, renderer);
            myShouldResetCaches = false;
        }

        public void addNotify() {
            //To change body of overriden methods use Options | File Templates.
            super.addNotify();
            if (myAddRemoveCounter == 0)
                myShouldResetCaches = true;
            myAddRemoveCounter++;
        }

        public void removeNotify() {
            //To change body of overriden methods use Options | File Templates.
            super.removeNotify();
            myAddRemoveCounter--;
        }
    };
    scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    tree.setCellRenderer(renderer);
    scrollpane.addComponentListener(new ComponentAdapter() {

        public void componentResized(ComponentEvent e) {
            resetHeightCache(tree, defaultRenderer, renderer);
        }

        public void componentShown(ComponentEvent e) {
            // componentResized not called when adding to opened tool window.
            // Seems to be BUG#4765299, however I failed to create same code to reproduce it.
            // To reproduce it with IDEA: 1. remove this method, 2. Start any Ant task, 3. Keep message window open 4. start Ant task again.
            resetHeightCache(tree, defaultRenderer, renderer);
        }
    });
    return scrollpane;
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) ComponentEvent(java.awt.event.ComponentEvent) JBScrollPane(com.intellij.ui.components.JBScrollPane) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 4 with ComponentEvent

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

the class ConsoleGutterComponent method updateSize.

public void updateSize(int start, int end) {
    int oldAnnotationsWidth = maxContentWidth;
    computeMaxAnnotationWidth(start, end);
    if (oldAnnotationsWidth != maxContentWidth || myLastPreferredHeight != editor.getPreferredHeight()) {
        processComponentEvent(new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED));
    }
    repaint();
}
Also used : ComponentEvent(java.awt.event.ComponentEvent) HintHint(com.intellij.ui.HintHint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 5 with ComponentEvent

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

the class EditConfigurationsDialog method addRunConfiguration.

public void addRunConfiguration(@NotNull final ConfigurationFactory factory) {
    final RunConfigurable configurable = (RunConfigurable) getConfigurable();
    final SingleConfigurationConfigurable<RunConfiguration> configuration = configurable.createNewConfiguration(factory);
    if (!isVisible()) {
        getContentPanel().addComponentListener(new ComponentAdapter() {

            @Override
            public void componentShown(ComponentEvent e) {
                if (configuration != null) {
                    configurable.updateRightPanel(configuration);
                    getContentPanel().removeComponentListener(this);
                }
            }
        });
    }
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

ComponentEvent (java.awt.event.ComponentEvent)120 ComponentAdapter (java.awt.event.ComponentAdapter)97 Dimension (java.awt.Dimension)22 Component (java.awt.Component)18 ActionEvent (java.awt.event.ActionEvent)18 JPanel (javax.swing.JPanel)18 JScrollPane (javax.swing.JScrollPane)16 ComponentListener (java.awt.event.ComponentListener)15 MouseEvent (java.awt.event.MouseEvent)15 JButton (javax.swing.JButton)15 JLabel (javax.swing.JLabel)15 BorderLayout (java.awt.BorderLayout)12 Point (java.awt.Point)12 WindowAdapter (java.awt.event.WindowAdapter)12 WindowEvent (java.awt.event.WindowEvent)12 MouseAdapter (java.awt.event.MouseAdapter)11 ActionListener (java.awt.event.ActionListener)10 JTable (javax.swing.JTable)9 AbstractAction (javax.swing.AbstractAction)8 BoxLayout (javax.swing.BoxLayout)8