Search in sources :

Example 1 with JBTabsPosition

use of com.intellij.ui.tabs.JBTabsPosition in project intellij-community by JetBrains.

the class JBEditorTabsPainter method paintSelectionAndBorder.

public void paintSelectionAndBorder(Graphics2D g2d, Rectangle rect, JBTabsImpl.ShapeInfo selectedShape, Insets insets, Color tabColor) {
    Insets i = selectedShape.path.transformInsets(insets);
    int _x = rect.x;
    int _y = rect.y;
    int _height = rect.height;
    final JBTabsPosition position = myTabs.getPosition();
    final boolean horizontalTabs = myTabs.isHorizontalTabs();
    if (myTabs.hasUnderlineSelection()) /*&& myTabs.getTabCount() > 1*/
    {
        fillSelectionAndBorder(g2d, selectedShape, tabColor, _x, _y, _height);
        //todo[kb] move to editor scheme
        Color underlineColor = Registry.getColor("ide.new.editor.tabs.selection.color", Gray._0);
        g2d.setColor(hasFocus(myTabs) ? underlineColor : ColorUtil.withAlpha(underlineColor, 0.5));
        int thickness = 3;
        if (position == JBTabsPosition.bottom) {
            g2d.fillRect(rect.x, rect.y - 1, rect.width, thickness);
        } else if (position == JBTabsPosition.top) {
            g2d.fillRect(rect.x, rect.y + rect.height - thickness + 1, rect.width, thickness);
            g2d.setColor(UIUtil.CONTRAST_BORDER_COLOR);
            g2d.drawLine(Math.max(0, rect.x - 1), rect.y, rect.x + rect.width, rect.y);
        } else if (position == JBTabsPosition.left) {
            g2d.fillRect(rect.x + rect.width - thickness + 1, rect.y, thickness, rect.height);
        } else if (position == JBTabsPosition.right) {
            g2d.fillRect(rect.x, rect.y, thickness, rect.height);
        }
        return;
    }
    if (!horizontalTabs) {
        g2d.setColor(Gray._0.withAlpha(45));
        g2d.draw(selectedShape.labelPath.transformLine(i.left, selectedShape.labelPath.getMaxY() - selectedShape.labelPath.deltaY(4), selectedShape.path.getMaxX(), selectedShape.labelPath.getMaxY() - selectedShape.labelPath.deltaY(4)));
        g2d.setColor(Gray._0.withAlpha(15));
        g2d.draw(selectedShape.labelPath.transformLine(i.left, selectedShape.labelPath.getMaxY() - selectedShape.labelPath.deltaY(5), selectedShape.path.getMaxX(), selectedShape.labelPath.getMaxY() - selectedShape.labelPath.deltaY(5)));
    }
    fillSelectionAndBorder(g2d, selectedShape, tabColor, _x, _y, _height);
    if (!horizontalTabs) {
        // side shadow
        g2d.setColor(Gray._0.withAlpha(30));
        g2d.draw(selectedShape.labelPath.transformLine(selectedShape.labelPath.getMaxX() + selectedShape.labelPath.deltaX(1), selectedShape.labelPath.getY() + selectedShape.labelPath.deltaY(1), selectedShape.labelPath.getMaxX() + selectedShape.labelPath.deltaX(1), selectedShape.labelPath.getMaxY() - selectedShape.labelPath.deltaY(4)));
        g2d.draw(selectedShape.labelPath.transformLine(selectedShape.labelPath.getX() - selectedShape.labelPath.deltaX(1), selectedShape.labelPath.getY() + selectedShape.labelPath.deltaY(1), selectedShape.labelPath.getX() - selectedShape.labelPath.deltaX(1), selectedShape.labelPath.getMaxY() - selectedShape.labelPath.deltaY(4)));
    }
    g2d.setColor(Gray._0.withAlpha(15));
    g2d.draw(selectedShape.labelPath.transformLine(i.left, selectedShape.labelPath.getMaxY(), selectedShape.path.getMaxX(), selectedShape.labelPath.getMaxY()));
}
Also used : JBTabsPosition(com.intellij.ui.tabs.JBTabsPosition)

Example 2 with JBTabsPosition

use of com.intellij.ui.tabs.JBTabsPosition in project intellij-community by JetBrains.

the class JBTabsDemo method main.

public static void main(String[] args) {
    System.out.println("JBTabs.main");
    IconLoader.activate();
    final JFrame frame = new JFrame();
    frame.getContentPane().setLayout(new BorderLayout(0, 0));
    final int[] count = new int[1];
    final JBTabsImpl tabs = new JBTabsImpl(null, ActionManager.getInstance(), null, Disposer.newDisposable());
    tabs.setTestMode(true);
    //final JPanel flow = new JPanel(new FlowLayout(FlowLayout.CENTER));
    //frame.getContentPane().add(flow);
    //flow.add(tabs.getComponent());
    frame.getContentPane().add(tabs.getComponent(), BorderLayout.CENTER);
    JPanel south = new JPanel(new FlowLayout());
    south.setOpaque(true);
    south.setBackground(Color.white);
    final JComboBox pos = new JComboBox(new Object[] { JBTabsPosition.top, JBTabsPosition.left, JBTabsPosition.right, JBTabsPosition.bottom });
    pos.setSelectedIndex(0);
    south.add(pos);
    pos.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final JBTabsPosition p = (JBTabsPosition) pos.getSelectedItem();
            if (p != null) {
                tabs.getPresentation().setTabsPosition(p);
            }
        }
    });
    final JCheckBox bb = new JCheckBox("Buffered", true);
    bb.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setUseBufferedPaint(bb.isSelected());
        }
    });
    south.add(bb);
    final JCheckBox f = new JCheckBox("Focused");
    f.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setFocused(f.isSelected());
        }
    });
    south.add(f);
    final JCheckBox v = new JCheckBox("Vertical");
    v.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setSideComponentVertical(v.isSelected());
        }
    });
    south.add(v);
    final JCheckBox row = new JCheckBox("Single row", true);
    row.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setSingleRow(row.isSelected());
        }
    });
    south.add(row);
    final JCheckBox ghosts = new JCheckBox("Ghosts always visible", false);
    ghosts.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setGhostsAlwaysVisible(ghosts.isSelected());
        }
    });
    south.add(ghosts);
    final JCheckBox stealth = new JCheckBox("Stealth tab", tabs.isStealthTabMode());
    stealth.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setStealthTabMode(stealth.isSelected());
        }
    });
    south.add(stealth);
    final JCheckBox hide = new JCheckBox("Hide tabs", tabs.isHideTabs());
    hide.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setHideTabs(hide.isSelected());
        }
    });
    south.add(hide);
    frame.getContentPane().add(south, BorderLayout.SOUTH);
    tabs.addListener(new TabsListener.Adapter() {

        public void selectionChanged(final TabInfo oldSelection, final TabInfo newSelection) {
            System.out.println("TabsWithActions.selectionChanged old=" + oldSelection + " new=" + newSelection);
        }
    });
    final JTree someTree = new Tree() {

        public void addNotify() {
            //To change body of overridden methods use File | Settings | File Templates.
            super.addNotify();
            System.out.println("JBTabs.addNotify");
        }

        public void removeNotify() {
            System.out.println("JBTabs.removeNotify");
            //To change body of overridden methods use File | Settings | File Templates.
            super.removeNotify();
        }
    };
    //someTree.setBorder(new LineBorder(Color.cyan));
    tabs.addTab(new TabInfo(someTree)).setText("Tree1").setActions(new DefaultActionGroup(), null).setIcon(AllIcons.Debugger.Frame);
    final JTree component = new Tree();
    final TabInfo toAnimate1 = new TabInfo(component);
    //toAnimate1.setIcon(IconLoader.getIcon("/debugger/console.png"));
    final JCheckBox attract1 = new JCheckBox("Attract 1");
    attract1.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            if (attract1.isSelected()) {
                toAnimate1.fireAlert();
            } else {
                toAnimate1.stopAlerting();
            }
        }
    });
    south.add(attract1);
    final JCheckBox hide1 = new JCheckBox("Hide 1", toAnimate1.isHidden());
    hide1.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            toAnimate1.setHidden(!toAnimate1.isHidden());
        }
    });
    south.add(hide1);
    final JCheckBox block = new JCheckBox("Block", false);
    block.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            tabs.setPaintBlocked(!block.isSelected(), true);
        }
    });
    south.add(block);
    final JCheckBox fill = new JCheckBox("Tab fill in", true);
    fill.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            tabs.getPresentation().setActiveTabFillIn(fill.isSelected() ? Color.white : null);
        }
    });
    south.add(fill);
    final JButton refire = new JButton("Re-fire attraction");
    refire.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            toAnimate1.fireAlert();
        }
    });
    south.add(refire);
    final JEditorPane text = new JEditorPane();
    text.setEditorKit(new HTMLEditorKit());
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 50; i++) {
        buffer.append("1234567890abcdefghijklmnopqrstv1234567890abcdefghijklmnopqrstv1234567890abcdefghijklmnopqrstv<br>");
    }
    text.setText(buffer.toString());
    final JLabel tb = new JLabel("Side comp");
    tb.setBorder(new LineBorder(Color.red));
    tabs.addTab(new TabInfo(ScrollPaneFactory.createScrollPane(text)).setSideComponent(tb)).setText("Text text text");
    tabs.addTab(toAnimate1).append("Tree2", new SimpleTextAttributes(SimpleTextAttributes.STYLE_WAVED, Color.black, Color.red));
    tabs.addTab(new TabInfo(new JTable())).setText("Table 1").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 2").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 3").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 4").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 5").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 6").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 7").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 8").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 9").setActions(new DefaultActionGroup(), null);
    //tabs.getComponent().setBorder(new EmptyBorder(5, 5, 5, 5));
    tabs.setTabSidePaintBorder(5);
    tabs.setPaintBorder(1, 1, 1, 1);
    tabs.getPresentation().setActiveTabFillIn(Color.white);
    tabs.setGhostsAlwaysVisible(true);
    //tabs.setBorder(new LineBorder(Color.blue, 5));
    tabs.setBorder(new EmptyBorder(30, 30, 30, 30));
    tabs.setUiDecorator(new UiDecorator() {

        public UiDecoration getDecoration() {
            return new UiDecoration(null, new Insets(0, -1, 0, -1));
        }
    });
    tabs.setStealthTabMode(true);
    frame.setBounds(1400, 200, 1000, 800);
    frame.show();
}
Also used : JBTabsPosition(com.intellij.ui.tabs.JBTabsPosition) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) LineBorder(javax.swing.border.LineBorder) TabsListener(com.intellij.ui.tabs.TabsListener) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) Tree(com.intellij.ui.treeStructure.Tree) TabInfo(com.intellij.ui.tabs.TabInfo) EmptyBorder(javax.swing.border.EmptyBorder) UiDecorator(com.intellij.ui.tabs.UiDecorator) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener)

Example 3 with JBTabsPosition

use of com.intellij.ui.tabs.JBTabsPosition in project intellij-community by JetBrains.

the class TabLabel method getPreferredSize.

@Override
public Dimension getPreferredSize() {
    final Dimension size = super.getPreferredSize();
    size.height = TabsUtil.getTabsHeight();
    if (myActionPanel != null && !myActionPanel.isVisible()) {
        final Dimension actionPanelSize = myActionPanel.getPreferredSize();
        size.width += actionPanelSize.width;
    }
    final JBTabsPosition pos = myTabs.getTabsPosition();
    switch(pos) {
        case top:
        case bottom:
            if (myTabs.hasUnderline())
                size.height += myTabs.getActiveTabUnderlineHeight() - 1;
            break;
        case left:
        case right:
            size.width += getSelectedOffset();
            break;
    }
    return size;
}
Also used : JBTabsPosition(com.intellij.ui.tabs.JBTabsPosition)

Example 4 with JBTabsPosition

use of com.intellij.ui.tabs.JBTabsPosition in project intellij-community by JetBrains.

the class DragHelper method processDragFinish.

@Override
protected void processDragFinish(MouseEvent event, boolean willDragOutStart) {
    super.processDragFinish(event, willDragOutStart);
    endDrag(willDragOutStart);
    final JBTabsPosition position = myTabs.getTabsPosition();
    if (!willDragOutStart && myTabs.isAlphabeticalMode() && position != JBTabsPosition.top && position != JBTabsPosition.bottom) {
        Point p = new Point(event.getPoint());
        p = SwingUtilities.convertPoint(event.getComponent(), p, myTabs);
        if (myTabs.getVisibleRect().contains(p) && myPressedOnScreenPoint.distance(new RelativePoint(event).getScreenPoint()) > 15) {
            final int answer = Messages.showOkCancelDialog(myTabs, IdeBundle.message("alphabetical.mode.is.on.warning"), IdeBundle.message("title.warning"), Messages.getQuestionIcon());
            if (answer == Messages.OK) {
                JBEditorTabs.setAlphabeticalMode(false);
                myTabs.relayout(true, false);
                myTabs.revalidate();
            }
        }
    }
}
Also used : JBTabsPosition(com.intellij.ui.tabs.JBTabsPosition) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 5 with JBTabsPosition

use of com.intellij.ui.tabs.JBTabsPosition in project intellij-community by JetBrains.

the class TabLabel method doTranslate.

public void doTranslate(PairConsumer<Integer, Integer> consumer) {
    final JBTabsPosition pos = myTabs.getTabsPosition();
    int dX = 0;
    int dXs = 0;
    int dY = 0;
    int dYs = 0;
    int selected = getSelectedOffset();
    int plain = getNonSelectedOffset();
    switch(pos) {
        case bottom:
            dY = -plain;
            dYs = -selected;
            break;
        case left:
            dX = plain;
            dXs = selected;
            break;
        case right:
            dX = -plain;
            dXs = -selected;
            break;
        case top:
            dY = plain;
            dYs = selected;
            break;
    }
    if (!myTabs.isDropTarget(myInfo)) {
        if (myTabs.getSelectedInfo() != myInfo) {
            consumer.consume(dX, dY);
        } else {
            consumer.consume(dXs, dYs);
        }
    }
}
Also used : JBTabsPosition(com.intellij.ui.tabs.JBTabsPosition)

Aggregations

JBTabsPosition (com.intellij.ui.tabs.JBTabsPosition)5 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 TabInfo (com.intellij.ui.tabs.TabInfo)1 TabsListener (com.intellij.ui.tabs.TabsListener)1 UiDecorator (com.intellij.ui.tabs.UiDecorator)1 Tree (com.intellij.ui.treeStructure.Tree)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 EmptyBorder (javax.swing.border.EmptyBorder)1 LineBorder (javax.swing.border.LineBorder)1 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)1