From dbd1b3af3645cdcf87c50ab5312e57c998422d19 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Wed, 20 Apr 2016 13:34:12 +0300 Subject: [PATCH] IDEA-153631 merge: expand middle panel on double click on divider --- .../diff/tools/util/ThreeDiffSplitter.java | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/ThreeDiffSplitter.java b/platform/diff-impl/src/com/intellij/diff/tools/util/ThreeDiffSplitter.java index 82231b8566d6..6fd7bd7f7a7b 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/ThreeDiffSplitter.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/ThreeDiffSplitter.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.awt.event.MouseEvent; +import java.util.Arrays; import java.util.List; public class ThreeDiffSplitter extends JPanel { @@ -75,6 +76,17 @@ public class ThreeDiffSplitter extends JPanel { myProportion1 = myProportion2 = 1f / 3; } + private void expandMiddlePanel() { + myProportion1 = myProportion2 = 0f; + } + + private boolean areDefaultProportions() { + int width = getWidth(); + int[] widths1 = calcComponentsWidths(width, myProportion1, myProportion2); + int[] widths2 = calcComponentsWidths(width, 1f / 3, 1f / 3); + return Arrays.equals(widths1, widths2); + } + private void setProportion(float proportion, @NotNull Side side) { proportion = Math.min(1f, Math.max(0f, proportion)); float otherProportion = side.select(myProportion2, myProportion1); @@ -89,16 +101,8 @@ public class ThreeDiffSplitter extends JPanel { int width = getWidth(); int height = getHeight(); - int dividersTotalWidth = DIVIDER_WIDTH * 2; - int contentsTotalWidth = Math.max(width - dividersTotalWidth, 0); - JComponent[] components = new JComponent[]{myContents.get(0), myDivider1, myContents.get(1), myDivider2, myContents.get(2)}; - int[] contentWidths = new int[5]; - contentWidths[1] = DIVIDER_WIDTH; // divider1 - contentWidths[3] = DIVIDER_WIDTH; // divider2 - contentWidths[0] = (int)(contentsTotalWidth * myProportion1); // content1 - contentWidths[4] = (int)(contentsTotalWidth * myProportion2); // content3 - contentWidths[2] = Math.max(contentsTotalWidth - contentWidths[0] - contentWidths[4], 0); // content2 + int[] contentWidths = calcComponentsWidths(width, myProportion1, myProportion2); int x = 0; for (int i = 0; i < 5; i++) { @@ -109,6 +113,20 @@ public class ThreeDiffSplitter extends JPanel { } } + @NotNull + private static int[] calcComponentsWidths(int width, float proportion1, float proportion2) { + int dividersTotalWidth = DIVIDER_WIDTH * 2; + int contentsTotalWidth = Math.max(width - dividersTotalWidth, 0); + + int[] contentWidths = new int[5]; + contentWidths[1] = DIVIDER_WIDTH; // divider1 + contentWidths[3] = DIVIDER_WIDTH; // divider2 + contentWidths[0] = (int)(contentsTotalWidth * proportion1); // content1 + contentWidths[4] = (int)(contentsTotalWidth * proportion2); // content3 + contentWidths[2] = Math.max(contentsTotalWidth - contentWidths[0] - contentWidths[4], 0); // content2 + return contentWidths; + } + @Override public Dimension getMinimumSize() { int width = DIVIDER_WIDTH * 2; @@ -176,7 +194,12 @@ public class ThreeDiffSplitter extends JPanel { protected void processMouseEvent(MouseEvent e) { super.processMouseEvent(e); if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() == 2) { - resetProportions(); + if (areDefaultProportions()) { + expandMiddlePanel(); + } + else { + resetProportions(); + } revalidate(); repaint();