mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-153631 merge: expand middle panel on double click on divider
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user