diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTabbedPaneUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTabbedPaneUI.java index 55c7d996f4ac..f3f4a02523f2 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTabbedPaneUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaTabbedPaneUI.java @@ -15,6 +15,7 @@ */ package com.intellij.ide.ui.laf.darcula.ui; +import com.intellij.ui.JBColor; import com.intellij.util.ui.JBInsets; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.JBValue; @@ -58,7 +59,7 @@ public class DarculaTabbedPaneUI extends BasicTabbedPaneUI { Object rStyle = UIManager.get("TabbedPane.tabFillStyle"); tabStyle = rStyle != null ? TabStyle.valueOf(rStyle.toString()) : TabStyle.underline; - contentBorderInsets = JBUI.insetsTop(1); + contentBorderInsets = tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT ? JBUI.insetsTop(1) : JBUI.emptyInsets(); } @Override @@ -66,12 +67,16 @@ public class DarculaTabbedPaneUI extends BasicTabbedPaneUI { super.installListeners(); borderTypePropertyListener = evt -> { - contentBorderInsets = evt.getNewValue() == Boolean.TRUE ? JBUI.insets(1) : JBUI.insetsTop(1); + boolean fullBorder = tabPane.getClientProperty("JTabbedPane.hasFullBorder") == Boolean.TRUE; + contentBorderInsets = (tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT) ? + fullBorder ? JBUI.insets(1) : JBUI.insetsTop(1) : + fullBorder ? JBUI.insets(0, 1, 1, 1) : JBUI.emptyInsets(); tabPane.revalidate(); tabPane.repaint(); }; tabPane.addPropertyChangeListener("JTabbedPane.hasFullBorder", borderTypePropertyListener); + tabPane.addPropertyChangeListener("tabLayoutPolicy", borderTypePropertyListener); paneMouseListener = new MouseAdapter() { public void mouseEntered(MouseEvent e) { @@ -119,6 +124,21 @@ public class DarculaTabbedPaneUI extends BasicTabbedPaneUI { return i; } + @Override + protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex) { + if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) { + Rectangle bounds = g.getClipBounds(); + g.setColor(JBColor.namedColor("TabbedPane.contentAreaColor", 0xbfbfbf)); + + if (tabPlacement == LEFT || tabPlacement == RIGHT) { + g.fillRect(bounds.x + bounds.width - OFFSET.get(), bounds.y, OFFSET.get(), bounds.y + bounds.height); + } else { + g.fillRect(bounds.x, bounds.y + bounds.height - OFFSET.get(), bounds.x + bounds.width, OFFSET.get()); + } + } + super.paintTabArea(g, tabPlacement, selectedIndex); + } + @Override protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { switch (tabStyle) { @@ -137,6 +157,15 @@ public class DarculaTabbedPaneUI extends BasicTabbedPaneUI { } break; } + + if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) { + if (tabPlacement == LEFT || tabPlacement == RIGHT) { + w -= OFFSET.get(); + } else { + h -= OFFSET.get(); + } + } + g.fillRect(x, y, w, h); } @@ -145,19 +174,21 @@ public class DarculaTabbedPaneUI extends BasicTabbedPaneUI { if (isSelected && tabStyle == TabStyle.underline) { g.setColor(tabPane.isEnabled() ? ENABLED_SELECTED_COLOR : DISABLED_SELECTED_COLOR); + int offset = tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT ? OFFSET.get() : SELECTION_HEIGHT.get(); + switch(tabPlacement) { case LEFT: - g.fillRect(x + w - OFFSET.get(), y, SELECTION_HEIGHT.get(), h); + g.fillRect(x + w - offset, y, SELECTION_HEIGHT.get(), h); break; case RIGHT: - g.fillRect(x - OFFSET.get(), y, SELECTION_HEIGHT.get(), h); + g.fillRect(x - offset, y, SELECTION_HEIGHT.get(), h); break; case BOTTOM: - g.fillRect(x, y - OFFSET.get(), w, SELECTION_HEIGHT.get()); + g.fillRect(x, y - offset, w, SELECTION_HEIGHT.get()); break; case TOP: default: - g.fillRect(x, y + h - OFFSET.get(), w, SELECTION_HEIGHT.get()); + g.fillRect(x, y + h - offset, w, SELECTION_HEIGHT.get()); } } } @@ -210,7 +241,9 @@ public class DarculaTabbedPaneUI extends BasicTabbedPaneUI { } Insets tabInsets = getTabInsets(tabPlacement, tabIndex); height += tabInsets.top + tabInsets.bottom; - return Math.max(height, TAB_HEIGHT.get() - OFFSET.get()); + + int minHeight = TAB_HEIGHT.get() - (tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT ? OFFSET.get() : 0); + return Math.max(height, minHeight); } @Override diff --git a/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java b/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java index b350e39f8cbb..44b6044626d1 100644 --- a/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java +++ b/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java @@ -43,6 +43,8 @@ public class ComponentPanelTestAction extends DumbAwareAction { private final Alarm myAlarm = new Alarm(getDisposable()); private ProgressTimerRequest progressTimerRequest; + private JTabbedPane pane; + private ComponentPanelTest(Project project) { super(project); init(); @@ -52,7 +54,7 @@ public class ComponentPanelTestAction extends DumbAwareAction { @Nullable @Override protected JComponent createCenterPanel() { - JTabbedPane pane = new JBTabbedPane(SwingConstants.TOP); + pane = new JBTabbedPane(SwingConstants.TOP); pane.addTab("Component", createComponentPanel()); pane.addTab("Component Grid", createComponentGridPanel()); pane.addTab("Progress Grid", createProgressGridPanel()); @@ -64,6 +66,7 @@ public class ComponentPanelTestAction extends DumbAwareAction { } //pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); + //pane.putClientProperty("JTabbedPane.hasFullBorder", Boolean.TRUE); pane.addChangeListener(e -> { if (pane.getSelectedIndex() == 2) { @@ -104,12 +107,16 @@ public class ComponentPanelTestAction extends DumbAwareAction { } }); - panel.add(UI.PanelFactory.panel(new JCheckBox("This is a checkbox 1")). - withComment("My long long long long long long long long long long comment"). + JCheckBox cb1 = new JCheckBox("Scroll tab layout"); + cb1.addActionListener(e -> pane.setTabLayoutPolicy(cb1.isSelected() ? JTabbedPane.SCROLL_TAB_LAYOUT : JTabbedPane.WRAP_TAB_LAYOUT)); + panel.add(UI.PanelFactory.panel(cb1). + withComment("Set tabbed pane tabs layout property to SCROLL_TAB_LAYOUT"). createPanel()); - panel.add(UI.PanelFactory.panel(new JCheckBox("This is a checkbox 2")). - withTooltip("Help tooltip description").createPanel()); + JCheckBox cb2 = new JCheckBox("Full border"); + cb2.addActionListener(e -> pane.putClientProperty("JTabbedPane.hasFullBorder", Boolean.valueOf(cb2.isSelected()))); + panel.add(UI.PanelFactory.panel(cb2). + withTooltip("Enable full border around the tabbed pane").createPanel()); panel.add(UI.PanelFactory.panel(new JButton("Abracadabra")). withComment("Abradabra comment").resizeX(false).createPanel());