Search in sources :

Example 1 with JBLayeredPane

use of com.intellij.ui.components.JBLayeredPane 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 2 with JBLayeredPane

use of com.intellij.ui.components.JBLayeredPane 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)

Example 3 with JBLayeredPane

use of com.intellij.ui.components.JBLayeredPane in project android by JetBrains.

the class BaseLineChartSegment method setCenterContent.

@Override
protected void setCenterContent(@NotNull JPanel panel) {
    JBLayeredPane layeredPane = new JBLayeredPane();
    layeredPane.add(mLineChart);
    layeredPane.add(mGrid);
    layeredPane.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            JLayeredPane host = (JLayeredPane) e.getComponent();
            if (host != null) {
                Dimension dim = host.getSize();
                for (Component c : host.getComponents()) {
                    c.setBounds(0, 0, dim.width, dim.height);
                }
            }
        }
    });
    panel.add(layeredPane, BorderLayout.CENTER);
}
Also used : JBLayeredPane(com.intellij.ui.components.JBLayeredPane)

Example 4 with JBLayeredPane

use of com.intellij.ui.components.JBLayeredPane 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 5 with JBLayeredPane

use of com.intellij.ui.components.JBLayeredPane in project android by JetBrains.

the class AxisLineChartVisualTest method createMockTimeline.

private JLayeredPane createMockTimeline() {
    JBLayeredPane timelinePane = new JBLayeredPane();
    timelinePane.add(mMemoryAxis1);
    timelinePane.add(mMemoryAxis2);
    timelinePane.add(mTimeAxis);
    timelinePane.add(mLineChart);
    timelinePane.add(mSelection);
    timelinePane.add(mGrid);
    timelinePane.add(mScrollbar);
    // TODO move to ProfilerOverviewVisualTest.
    JBPanel labelPanel = new JBPanel();
    labelPanel.setLayout(new FlowLayout());
    labelPanel.add(mLegendComponent);
    timelinePane.add(labelPanel);
    timelinePane.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            JLayeredPane host = (JLayeredPane) e.getComponent();
            if (host != null) {
                Dimension dim = host.getSize();
                for (Component c : host.getComponents()) {
                    if (c instanceof AxisComponent) {
                        AxisComponent axis = (AxisComponent) c;
                        switch(axis.getOrientation()) {
                            case LEFT:
                                axis.setBounds(0, 0, AXIS_SIZE, dim.height);
                                break;
                            case BOTTOM:
                                axis.setBounds(0, dim.height - AXIS_SIZE, dim.width, AXIS_SIZE);
                                break;
                            case RIGHT:
                                axis.setBounds(dim.width - AXIS_SIZE, 0, AXIS_SIZE, dim.height);
                                break;
                            case TOP:
                                axis.setBounds(0, 0, dim.width, AXIS_SIZE);
                                break;
                        }
                    } else if (c instanceof RangeScrollbar) {
                        int sbHeight = c.getPreferredSize().height;
                        c.setBounds(0, dim.height - sbHeight, dim.width, sbHeight);
                    } else {
                        c.setBounds(AXIS_SIZE, AXIS_SIZE, dim.width - AXIS_SIZE * 2, dim.height - AXIS_SIZE * 2);
                    }
                }
            }
        }
    });
    return timelinePane;
}
Also used : JBLayeredPane(com.intellij.ui.components.JBLayeredPane) ComponentEvent(java.awt.event.ComponentEvent) JBPanel(com.intellij.ui.components.JBPanel) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

JBLayeredPane (com.intellij.ui.components.JBLayeredPane)9 EditorFragmentComponent (com.intellij.codeInsight.hint.EditorFragmentComponent)3 Activatable (com.intellij.util.ui.update.Activatable)3 UiNotifyConnector (com.intellij.util.ui.update.UiNotifyConnector)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 ComponentAdapter (java.awt.event.ComponentAdapter)3 ComponentEvent (java.awt.event.ComponentEvent)3 AnimatedComponent (com.android.tools.adtui.AnimatedComponent)1 LegendComponent (com.android.tools.adtui.LegendComponent)1 JBPanel (com.intellij.ui.components.JBPanel)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 Override (java.lang.Override)1