From 2f9337f43ce3c877187855744d2205a5e8c89f75 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Fri, 4 Sep 2009 18:04:30 +0400 Subject: [PATCH] buffered painting of tabs - take 1 --- .../src/com/intellij/ui/tabs/impl/JBTabsImpl.java | 55 ++++++++++++++++++---- .../src/com/intellij/ui/tabs/impl/JBTabsTest.java | 8 ++++ .../src/com/intellij/ui/tabs/impl/TabLabel.java | 16 ++++++- .../src/com/intellij/util/ui/Animator.java | 4 +- .../src/misc/registry.properties | 1 + 5 files changed, 72 insertions(+), 12 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java index 5630d21140..0c16141df8 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java @@ -7,6 +7,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ShadowAction; import com.intellij.openapi.ui.TestableUi; import com.intellij.openapi.util.*; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.*; import com.intellij.openapi.wm.impl.content.GraphicsConfig; import com.intellij.ui.CaptionPanel; @@ -130,6 +131,7 @@ public class JBTabsImpl extends JComponent private boolean myTabDraggingEnabled; private DragHelper myDragHelper; private boolean myNavigationActionsEnabled = true; + private boolean myUseBufferedPaint = true; public JBTabsImpl(@NotNull Project project) { this(project, project); @@ -1608,13 +1610,39 @@ public class JBTabsImpl extends JComponent for (int eachColumn = myLastLayoutPass.getColumnCount(eachRow) - 1; eachColumn >= 0; eachColumn--) { final TabInfo each = myLastLayoutPass.getTabAt(eachRow, eachColumn); if (getSelectedInfo() == each) continue; - paintTab(g2d, each, leftGhostExists); + paintNonSelected(g2d, each, leftGhostExists); } } } - private void paintTab(final Graphics2D g2d, final TabInfo each, final boolean leftGhostExists) { - int tabIndex = myVisibleInfos.indexOf(each); + private void paintNonSelected(final Graphics2D g2d, final TabInfo each, final boolean leftGhostExists) { + final TabLabel label = myInfo2Label.get(each); + if (label.getBounds().width == 0) return; + + if (isToBufferPainting()) { + Rectangle bounds = label.getBounds(); + BufferedImage img = label.getInactiveStateImage(); + if (img == null) { + img = new BufferedImage(label.getWidth() + 2, label.getHeight() + 1, BufferedImage.TYPE_INT_ARGB); + Graphics2D imgG2d = img.createGraphics(); + imgG2d.addRenderingHints(g2d.getRenderingHints()); + doPaintInactictive(imgG2d, leftGhostExists, label, false); + imgG2d.dispose(); + } + + g2d.drawImage(img, bounds.x, bounds.y, bounds.width + 2, bounds.height + 1, null); + label.setInactiveStateImage(img); + } else { + doPaintInactictive(g2d, leftGhostExists, label, true); + } + } + + private boolean isToBufferPainting() { + return Registry.is("ide.tabbedPane.bufferedPaint") && myUseBufferedPaint; + } + + private void doPaintInactictive(Graphics2D g2d, boolean leftGhostExists, TabLabel label, boolean useXY) { + int tabIndex = myVisibleInfos.indexOf(label.getInfo()); final int arc = getArcSize(); Color topBlickColor = getTopBlickColor(); @@ -1622,7 +1650,7 @@ public class JBTabsImpl extends JComponent Color boundsColor = getBoundsColor(); Color backgroundColor = getBackground(); - final Color tabColor = each.getTabColor(); + final Color tabColor = label.getInfo().getTabColor(); if (tabColor != null) { backgroundColor = tabColor; boundsColor = tabColor.darker(); @@ -1634,10 +1662,6 @@ public class JBTabsImpl extends JComponent final int selectionTabVShift = getSelectionTabVShift(); - final TabLabel eachLabel = myInfo2Label.get(each); - if (eachLabel.getBounds().width == 0) return; - - final TabInfo prev = myLastLayoutPass.getPreviousFor(myVisibleInfos.get(tabIndex)); final TabInfo next = myLastLayoutPass.getNextFor(myVisibleInfos.get(tabIndex)); @@ -1654,7 +1678,8 @@ public class JBTabsImpl extends JComponent boolean leftFromSelection = selected != null && tabIndex == myVisibleInfos.indexOf(selected) - 1; - final ShapeTransform shape = getEffectiveLayout().createShapeTransform(eachLabel.getBounds()); + Rectangle originalBounds = useXY ? label.getBounds() : new Rectangle(label.getSize()); + final ShapeTransform shape = getEffectiveLayout().createShapeTransform(originalBounds); int leftX = firstShowing ? shape.getX() : shape.getX() - shape.deltaX(arc + 1); int topY = shape.getY() + shape.deltaY(selectionTabVShift); @@ -1670,7 +1695,7 @@ public class JBTabsImpl extends JComponent if (!isSingleRow()) { final TablePassInfo info = myTableLayout.myLastTableLayout; - if (!info.isInSelectionRow(each)) { + if (!info.isInSelectionRow(label.getInfo())) { shape.lineTo(rigthX, bottomY + shape.deltaY(getArcSize())); shape.lineTo(leftX, bottomY + shape.deltaY(getArcSize())); shape.lineTo(leftX, bottomY); @@ -2650,4 +2675,14 @@ public class JBTabsImpl extends JComponent selected.putInfo(info); } } + + public boolean isUseBufferedPaint() { + return myUseBufferedPaint; + } + + public void setUseBufferedPaint(boolean useBufferedPaint) { + myUseBufferedPaint = useBufferedPaint; + revalidate(); + repaint(); + } } diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsTest.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsTest.java index acf6fa4d6f..38b9ebcd76 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsTest.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsTest.java @@ -58,6 +58,14 @@ public class JBTabsTest { } }); + 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) { diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java index 14c9fe7450..f638f01946 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java @@ -35,6 +35,7 @@ public class TabLabel extends JPanel { private final JBTabsImpl myTabs; private BufferedImage myImage; + private BufferedImage myInactiveStateImage; public TabLabel(JBTabsImpl tabs, final TabInfo info) { myTabs = tabs; @@ -212,8 +213,9 @@ public class TabLabel extends JPanel { if (myLabel.getRootPane() == null) return; if (myLabel.getSize() != null && myLabel.getSize().equals(myLabel.getPreferredSize())) return; - myLabel.getParent().invalidate(); + myInactiveStateImage = null; + myLabel.getParent().invalidate(); myTabs.revalidateAndRepaint(false); } @@ -394,4 +396,16 @@ public class TabLabel extends JPanel { public void setTabEnabled(boolean enabled) { myLabel.setEnabled(enabled); } + + + public BufferedImage getInactiveStateImage() { + return myInactiveStateImage; + } + + public void setInactiveStateImage(BufferedImage img) { + if (myImage != null && img != myImage) { + myImage.flush(); + } + myInactiveStateImage = img; + } } diff --git a/platform/platform-api/src/com/intellij/util/ui/Animator.java b/platform/platform-api/src/com/intellij/util/ui/Animator.java index ce539e9836..998290ff7d 100644 --- a/platform/platform-api/src/com/intellij/util/ui/Animator.java +++ b/platform/platform-api/src/com/intellij/util/ui/Animator.java @@ -18,6 +18,7 @@ package com.intellij.util.ui; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.Application; import javax.swing.*; @@ -62,7 +63,8 @@ public abstract class Animator implements Disposable { myForward = forward; myCurrentFrame = forward ? 0 : totalFrames; - myTimer = ApplicationManager.getApplication().isUnitTestMode() ? + Application app = ApplicationManager.getApplication(); + myTimer = (app != null && app.isUnitTestMode()) ? new Timer(myName, myCycleLength / myTotalFrames) { { dispose(); diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 2d3e3e6c5b..871f138496 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -26,6 +26,7 @@ ide.tree.showBusyIndicator=true ide.tree.waitForReadyTimout=250 ide.tree.clearOnHideTime=120000 ide.tree.autoscrollToVCenter=true +ide.tabbedPane.bufferedPaint=true debugger.valueTooltipAutoShow=true debugger.valueTooltipAutoShow.description=Auto show tooltip on mouse over -- 2.11.4.GIT