IDEA-22546 Tab rows are "jumping" in multiline rows mode

This commit is contained in:
Konstantin Bulenkov
2014-10-13 15:34:36 +02:00
parent e167f2fdad
commit 5a45da27e7
7 changed files with 51 additions and 32 deletions
@@ -24,7 +24,6 @@ import com.intellij.ui.ColorUtil;
import com.intellij.ui.Gray;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.tabs.TabInfo;
import com.intellij.ui.tabs.TabsUtil;
import com.intellij.ui.tabs.UiDecorator;
import com.intellij.ui.tabs.impl.JBTabsImpl;
import com.intellij.ui.tabs.impl.TabLabel;
@@ -75,7 +74,7 @@ public class
int _y = effectiveBounds.y + insets.top + 3;
int _width = effectiveBounds.width - insets.left - insets.right;
int _height = effectiveBounds.height - insets.top - insets.bottom - 3;
_height -= TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT;
_height -= getActiveTabUnderlineHeight();
if (dark) {
g2d.setPaint(UIUtil.getGradientPaint(_x, _y, ColorUtil.shift(UIUtil.getListBackground(), 1.3), _x, _y + effectiveBounds.height, UIUtil.getPanelBackground()));
g2d.fillRect(_x, _y, _width, _height);
@@ -122,7 +121,7 @@ public class
Rectangle rectangle;
int y = r2.y + insets.top;
int height = maxLength - insets.top - insets.bottom;
height -= TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT;
height -= getActiveTabUnderlineHeight();
rectangle = new Rectangle(maxOffset, y, r2.width - maxOffset - insets.left - insets.right, height);
@@ -194,7 +193,7 @@ public class
shape.insets = shape.path.transformInsets(getLayoutInsets());
shape.labelPath = shape.path.createTransform(r);
shape.labelBottomY = shape.labelPath.getMaxY() - shape.labelPath.deltaY(TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT - 1);
shape.labelBottomY = shape.labelPath.getMaxY() - shape.labelPath.deltaY(getActiveTabUnderlineHeight() - 1);
shape.labelTopY = shape.labelPath.getY() + shape.labelPath.deltaY(1);
shape.labelLeftX = shape.labelPath.getX();
shape.labelRightX = shape.labelPath.getMaxX() - shape.labelPath.deltaX(1);
@@ -210,8 +209,8 @@ public class
int lastX = shape.path.getWidth() - shape.path.deltaX(shape.insets.right);
shape.path.lineTo(lastX, shape.labelBottomY);
shape.path.lineTo(lastX, shape.labelBottomY + shape.labelPath.deltaY(TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT - 1));
shape.path.lineTo(leftX, shape.labelBottomY + shape.labelPath.deltaY(TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT - 1));
shape.path.lineTo(lastX, shape.labelBottomY + shape.labelPath.deltaY(getActiveTabUnderlineHeight() - 1));
shape.path.lineTo(leftX, shape.labelBottomY + shape.labelPath.deltaY(getActiveTabUnderlineHeight() - 1));
shape.path.closePath();
shape.fillPath = shape.path.copy();
@@ -298,7 +297,7 @@ public class
@Override
public Dimension getPreferredSize() {
Dimension result = super.getPreferredSize();
result.height += TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT;
result.height += myTabs.getActiveTabUnderlineHeight();
return result;
}
}
@@ -26,7 +26,6 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.tabs.JBTabsPosition;
import com.intellij.ui.tabs.TabInfo;
import com.intellij.ui.tabs.TabsUtil;
import com.intellij.ui.tabs.impl.singleRow.ScrollableSingleRowLayout;
import com.intellij.ui.tabs.impl.singleRow.SingleRowLayout;
import com.intellij.ui.tabs.impl.table.TableLayout;
@@ -98,9 +97,11 @@ public class JBEditorTabs extends JBTabsImpl {
@Override
public boolean hasUnderline() {
return true;
return isSingleRow();
}
protected void doPaintInactive(Graphics2D g2d,
boolean leftGhostExists,
TabLabel label,
@@ -116,14 +117,14 @@ public class JBEditorTabs extends JBTabsImpl {
if ((!isSingleRow() /* for multiline */) || (isSingleRow() && isHorizontalTabs())) {
if (isSingleRow() && getPosition() == JBTabsPosition.bottom) {
_y += TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT;
_y += getActiveTabUnderlineHeight();
} else {
if (isSingleRow()) {
_height -= TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT;
_height -= getActiveTabUnderlineHeight();
} else {
TabInfo info = label.getInfo();
if (((TableLayout)getEffectiveLayout()).isLastRow(info)) {
_height -= TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT;
_height -= getActiveTabUnderlineHeight();
}
}
}
@@ -131,7 +132,19 @@ public class JBEditorTabs extends JBTabsImpl {
final boolean vertical = getTabsPosition() == JBTabsPosition.left || getTabsPosition() == JBTabsPosition.right;
final Color tabColor = label.getInfo().getTabColor();
final Composite oldComposite = g2d.getComposite();
//if (label != getSelectedLabel()) {
// g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.9f));
//}
getPainter().doPaintInactive(g2d, effectiveBounds, _x, _y, _width, _height, tabColor, row, column, vertical);
//g2d.setComposite(oldComposite);
}
@Override
public int getActiveTabUnderlineHeight() {
return hasUnderline() ? super.getActiveTabUnderlineHeight() : 1;
}
JBEditorTabsPainter getPainter() {
@@ -186,9 +199,9 @@ public class JBEditorTabs extends JBTabsImpl {
int y = r2.y + insets.top;
int height = maxLength - insets.top - insets.bottom;
if (getTabsPosition() == JBTabsPosition.bottom) {
y = r2.height - height - insets.top + TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT;
y = r2.height - height - insets.top + getActiveTabUnderlineHeight();
} else {
height -= TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT;
height -= getActiveTabUnderlineHeight();
}
rectangle = new Rectangle(maxOffset, y, r2.width - maxOffset - insets.left - insets.right, height);
@@ -229,7 +242,7 @@ public class JBEditorTabs extends JBTabsImpl {
shape.insets = shape.path.transformInsets(getLayoutInsets());
shape.labelPath = shape.path.createTransform(getSelectedLabel().getBounds());
shape.labelBottomY = shape.labelPath.getMaxY() - shape.labelPath.deltaY(TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT - 1);
shape.labelBottomY = shape.labelPath.getMaxY() - shape.labelPath.deltaY(getActiveTabUnderlineHeight() - 1);
shape.labelTopY =
shape.labelPath.getY() + (getPosition() == JBTabsPosition.top || getPosition() == JBTabsPosition.bottom ? shape.labelPath.deltaY(1) : 0) ;
shape.labelLeftX = shape.labelPath.getX() + (getPosition() == JBTabsPosition.top || getPosition() == JBTabsPosition.bottom ? 0 : shape.labelPath.deltaX(
@@ -247,8 +260,8 @@ public class JBEditorTabs extends JBTabsImpl {
int lastX = shape.path.getWidth() - shape.path.deltaX(shape.insets.right);
shape.path.lineTo(lastX, shape.labelBottomY);
shape.path.lineTo(lastX, shape.labelBottomY + shape.labelPath.deltaY(TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT - 1));
shape.path.lineTo(leftX, shape.labelBottomY + shape.labelPath.deltaY(TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT - 1));
shape.path.lineTo(lastX, shape.labelBottomY + shape.labelPath.deltaY(getActiveTabUnderlineHeight() - 1));
shape.path.lineTo(leftX, shape.labelBottomY + shape.labelPath.deltaY(getActiveTabUnderlineHeight() - 1));
shape.path.closePath();
shape.fillPath = shape.path.copy();
@@ -345,6 +345,10 @@ public class JBTabsImpl extends JComponent
return this;
}
public int getActiveTabUnderlineHeight() {
return TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT;
}
public boolean isEditorTabs() {
return false;
}
@@ -53,7 +53,7 @@ public class TabLabel extends JPanel {
private boolean myCentered;
private final Wrapper myLabelPlaceholder = new Wrapper(false);
private final JBTabsImpl myTabs;
protected final JBTabsImpl myTabs;
private BufferedImage myInactiveStateImage;
private Rectangle myLastPaintedInactiveImageBounds;
@@ -241,7 +241,12 @@ public class TabLabel extends JPanel {
}
});
final Composite oldComposite = ((Graphics2D)g).getComposite();
if (myTabs instanceof JBEditorTabs && !myTabs.isSingleRow() && myTabs.getSelectedInfo() != myInfo) {
((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
}
super.paint(g);
((Graphics2D)g).setComposite(oldComposite);
doTranslate(new PairConsumer<Integer, Integer>() {
@Override
@@ -253,7 +258,7 @@ public class TabLabel extends JPanel {
protected int getNonSelectedOffset() {
if (myTabs.isEditorTabs() && (myTabs.isSingleRow() || ((TableLayout)myTabs.getEffectiveLayout()).isLastRow(getInfo()))) {
return -TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT / 2 + 1;
return -myTabs.getActiveTabUnderlineHeight() / 2 + 1;
}
return 1;
}
@@ -275,7 +280,7 @@ public class TabLabel extends JPanel {
switch (pos) {
case top:
case bottom:
if (myTabs.hasUnderline()) size.height += TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT - 1;
if (myTabs.hasUnderline()) size.height += myTabs.getActiveTabUnderlineHeight() - 1;
break;
case left:
case right:
@@ -18,7 +18,6 @@ package com.intellij.ui.tabs.impl.singleRow;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.tabs.JBTabsPosition;
import com.intellij.ui.tabs.TabInfo;
import com.intellij.ui.tabs.TabsUtil;
import com.intellij.ui.tabs.impl.*;
import org.jetbrains.annotations.Nullable;
@@ -50,8 +49,8 @@ public class SingleRowLayout extends TabLayout {
protected int getIconY(Rectangle iconRec) {
final int shift;
switch (myTabs.getTabsPosition()) {
case bottom: shift = TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT; break;
case top: shift = -(TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT / 2); break;
case bottom: shift = myTabs.getActiveTabUnderlineHeight(); break;
case top: shift = -(myTabs.getActiveTabUnderlineHeight() / 2); break;
default: shift = 0;
}
return super.getIconY(iconRec) + shift;
@@ -16,7 +16,6 @@
package com.intellij.ui.tabs.impl.table;
import com.intellij.ui.tabs.TabInfo;
import com.intellij.ui.tabs.TabsUtil;
import com.intellij.ui.tabs.impl.JBTabsImpl;
import com.intellij.ui.tabs.impl.LayoutPassInfo;
import com.intellij.ui.tabs.impl.TabLabel;
@@ -103,10 +102,10 @@ public class TableLayout extends TabLayout {
toMove.add(data.table.get(i));
}
for (TableRow eachMove : toMove) {
data.table.remove(eachMove);
data.table.add(0, eachMove);
}
//for (TableRow eachMove : toMove) {
// data.table.remove(eachMove);
// data.table.add(0, eachMove);
//}
return data;
@@ -131,7 +130,7 @@ public class TableLayout extends TabLayout {
int eachY = insets.top;
int eachX;
int row = 0;
final int tabUnderlineFix = myTabs.isEditorTabs() ? TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT : 0;
final int tabUnderlineFix = myTabs.isEditorTabs() ? myTabs.getActiveTabUnderlineHeight() : 0;
for (TableRow eachRow : data.table) {
eachX = insets.left;
@@ -65,11 +65,11 @@ public class JBTabsPaneImpl implements TabbedPane, SwingConstants {
maxOffset++;
g2d.setPaint(UIUtil.getPanelBackground());
if (getFirstTabOffset() > 0) {
g2d.fillRect(clip.x, clip.y, clip.x + getFirstTabOffset() - 1, clip.y + maxLength - TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT);
g2d.fillRect(clip.x, clip.y, clip.x + getFirstTabOffset() - 1, clip.y + maxLength - getActiveTabUnderlineHeight());
}
g2d.fillRect(clip.x + maxOffset, clip.y, clip.width - maxOffset, clip.y + maxLength - TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT);
g2d.fillRect(clip.x + maxOffset, clip.y, clip.width - maxOffset, clip.y + maxLength - getActiveTabUnderlineHeight());
g2d.setPaint(new JBColor(Gray._181, UIUtil.getPanelBackground()));
g2d.drawLine(clip.x + maxOffset, clip.y + maxLength - TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT, clip.x + clip.width, clip.y + maxLength - TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT);
g2d.drawLine(clip.x + maxOffset, clip.y + maxLength - getActiveTabUnderlineHeight(), clip.x + clip.width, clip.y + maxLength - getActiveTabUnderlineHeight());
g2d.setPaint(UIUtil.getPanelBackground());
g2d.drawLine(clip.x, clip.y + maxLength, clip.width, clip.y + maxLength);
}