mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Support BOTTOM side
This commit is contained in:
@@ -24,6 +24,16 @@ import java.awt.*;
|
||||
* @author Alexander Lobas
|
||||
*/
|
||||
public class LightFillLayout implements LayoutManager2 {
|
||||
private final boolean myVertical;
|
||||
|
||||
public LightFillLayout() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public LightFillLayout(boolean vertical) {
|
||||
myVertical = vertical;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayoutComponent(Component comp, Object constraints) {
|
||||
}
|
||||
@@ -57,7 +67,7 @@ public class LightFillLayout implements LayoutManager2 {
|
||||
|
||||
@Override
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
return layoutSize(parent, new Function<Component, Dimension>() {
|
||||
return layoutSize(parent, myVertical, new Function<Component, Dimension>() {
|
||||
@Override
|
||||
public Dimension fun(Component component) {
|
||||
return component.getPreferredSize();
|
||||
@@ -67,7 +77,7 @@ public class LightFillLayout implements LayoutManager2 {
|
||||
|
||||
@Override
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
return layoutSize(parent, new Function<Component, Dimension>() {
|
||||
return layoutSize(parent, myVertical, new Function<Component, Dimension>() {
|
||||
@Override
|
||||
public Dimension fun(Component component) {
|
||||
return component.getMinimumSize();
|
||||
@@ -75,23 +85,37 @@ public class LightFillLayout implements LayoutManager2 {
|
||||
});
|
||||
}
|
||||
|
||||
private static Dimension layoutSize(Container parent, Function<Component, Dimension> getSize) {
|
||||
private static Dimension layoutSize(Container parent, boolean vertical, Function<Component, Dimension> getSize) {
|
||||
int[] extraSize = new int[2];
|
||||
JComponent jParent = (JComponent)parent;
|
||||
getSize(jParent, LightToolWindow.LEFT_MIN_KEY, vertical, extraSize);
|
||||
getSize(jParent, LightToolWindow.RIGHT_MIN_KEY, vertical, extraSize);
|
||||
|
||||
Component toolbar = parent.getComponent(0);
|
||||
Dimension toolbarSize = toolbar.isVisible() ? getSize.fun(toolbar) : new Dimension();
|
||||
Dimension contentSize = getSize.fun(parent.getComponent(1));
|
||||
int extraWidth = 0;
|
||||
JComponent jParent = (JComponent)parent;
|
||||
if (jParent.getClientProperty(LightToolWindow.LEFT_MIN_KEY) != null) {
|
||||
extraWidth += LightToolWindow.MINIMIZE_WIDTH;
|
||||
|
||||
return new Dimension(Math.max(toolbarSize.width, contentSize.width + extraSize[0]),
|
||||
toolbarSize.height + contentSize.height + extraSize[1]);
|
||||
}
|
||||
|
||||
private static void getSize(JComponent jParent, String key, boolean vertical, int[] size) {
|
||||
if (jParent.getClientProperty(key) != null) {
|
||||
size[vertical ? 1 : 0] += LightToolWindow.MINIMIZE_WIDTH;
|
||||
}
|
||||
if (jParent.getClientProperty(LightToolWindow.RIGHT_MIN_KEY) != null) {
|
||||
extraWidth += LightToolWindow.MINIMIZE_WIDTH;
|
||||
}
|
||||
return new Dimension(Math.max(toolbarSize.width, contentSize.width + extraWidth), toolbarSize.height + contentSize.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void layoutContainer(Container parent) {
|
||||
if (myVertical) {
|
||||
layoutVContainer(parent);
|
||||
}
|
||||
else {
|
||||
layoutHContainer(parent);
|
||||
}
|
||||
}
|
||||
|
||||
private static void layoutHContainer(Container parent) {
|
||||
int leftWidth = 0;
|
||||
int rightWidth = 0;
|
||||
JComponent jParent = (JComponent)parent;
|
||||
@@ -119,4 +143,24 @@ public class LightFillLayout implements LayoutManager2 {
|
||||
right.setBounds(width + leftWidth, 0, rightWidth, height);
|
||||
}
|
||||
}
|
||||
|
||||
private static void layoutVContainer(Container parent) {
|
||||
int bottomHeight = 0;
|
||||
JComponent jParent = (JComponent)parent;
|
||||
JComponent bottom = (JComponent)jParent.getClientProperty(LightToolWindow.RIGHT_MIN_KEY);
|
||||
if (bottom != null) {
|
||||
bottomHeight = LightToolWindow.MINIMIZE_WIDTH;
|
||||
}
|
||||
|
||||
int width = parent.getWidth();
|
||||
int height = parent.getHeight() - bottomHeight;
|
||||
Component toolbar = parent.getComponent(0);
|
||||
Dimension toolbarSize = toolbar.isVisible() ? toolbar.getPreferredSize() : new Dimension();
|
||||
toolbar.setBounds(0, 0, width, toolbarSize.height);
|
||||
parent.getComponent(1).setBounds(0, toolbarSize.height, width, height - toolbarSize.height);
|
||||
|
||||
if (bottom != null) {
|
||||
bottom.setBounds(0, height, width, bottomHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* @author Alexander Lobas
|
||||
@@ -185,7 +184,12 @@ public class LightToolWindow extends JPanel {
|
||||
@Override
|
||||
public void doLayout() {
|
||||
Dimension size = myMinimizeButton.getPreferredSize();
|
||||
myMinimizeButton.setBounds(0, 0, getWidth(), size.height);
|
||||
if (myAnchor == ToolWindowAnchor.BOTTOM) {
|
||||
myMinimizeButton.setBounds(0, 1, size.width, MINIMIZE_WIDTH);
|
||||
}
|
||||
else {
|
||||
myMinimizeButton.setBounds(0, 0, getWidth(), size.height);
|
||||
}
|
||||
}
|
||||
};
|
||||
myMinimizeComponent.add(myMinimizeButton);
|
||||
@@ -196,7 +200,20 @@ public class LightToolWindow extends JPanel {
|
||||
}
|
||||
|
||||
private void configureBorder() {
|
||||
int borderStyle = isLeft() ? SideBorder.RIGHT : SideBorder.LEFT;
|
||||
int borderStyle;
|
||||
if (myAnchor == ToolWindowAnchor.LEFT) {
|
||||
borderStyle = SideBorder.RIGHT;
|
||||
}
|
||||
else if (myAnchor == ToolWindowAnchor.RIGHT) {
|
||||
borderStyle = SideBorder.LEFT;
|
||||
}
|
||||
else if (myAnchor == ToolWindowAnchor.BOTTOM) {
|
||||
borderStyle = SideBorder.TOP;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
setBorder(IdeBorderFactory.createBorder(borderStyle));
|
||||
myMinimizeComponent.setBorder(IdeBorderFactory.createBorder(borderStyle));
|
||||
}
|
||||
@@ -381,14 +398,18 @@ public class LightToolWindow extends JPanel {
|
||||
public HideAction() {
|
||||
Presentation presentation = getTemplatePresentation();
|
||||
presentation.setText(UIBundle.message("tool.window.hide.action.name"));
|
||||
if (isLeft()) {
|
||||
if (myAnchor == ToolWindowAnchor.LEFT) {
|
||||
presentation.setIcon(AllIcons.General.HideLeftPart);
|
||||
presentation.setHoveredIcon(AllIcons.General.HideLeftPartHover);
|
||||
}
|
||||
else {
|
||||
else if (myAnchor == ToolWindowAnchor.RIGHT) {
|
||||
presentation.setIcon(AllIcons.General.HideRightPart);
|
||||
presentation.setHoveredIcon(AllIcons.General.HideRightPartHover);
|
||||
}
|
||||
else if (myAnchor == ToolWindowAnchor.BOTTOM) {
|
||||
presentation.setIcon(AllIcons.General.HideDownPart);
|
||||
presentation.setHoveredIcon(AllIcons.General.HideDownPartHover);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -523,10 +544,7 @@ public class LightToolWindow extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private class HeaderPanel extends JPanel {
|
||||
private BufferedImage myActiveImage;
|
||||
private BufferedImage myImage;
|
||||
|
||||
private static class HeaderPanel extends JPanel {
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension size = super.getPreferredSize();
|
||||
@@ -538,44 +556,5 @@ public class LightToolWindow extends JPanel {
|
||||
Dimension size = super.getMinimumSize();
|
||||
return new Dimension(size.width, TabsUtil.getTabsHeight());
|
||||
}
|
||||
|
||||
protected void _paintComponent(Graphics g) { // XXX: visual artifacts on linux
|
||||
Rectangle r = getBounds();
|
||||
|
||||
Image image;
|
||||
if (isActive()) {
|
||||
if (myActiveImage == null || myActiveImage.getHeight() != r.height) {
|
||||
myActiveImage = drawToBuffer(true, r.height);
|
||||
}
|
||||
image = myActiveImage;
|
||||
}
|
||||
else {
|
||||
if (myImage == null || myImage.getHeight() != r.height) {
|
||||
myImage = drawToBuffer(false, r.height);
|
||||
}
|
||||
image = myImage;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
Rectangle clipBounds = g2d.getClip().getBounds();
|
||||
for (int x = clipBounds.x; x < clipBounds.x + clipBounds.width; x += 150) {
|
||||
g2d.drawImage(image, x, 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isActive() {
|
||||
return LightToolWindow.this.isActive();
|
||||
}
|
||||
}
|
||||
|
||||
private static BufferedImage drawToBuffer(boolean active, int height) {
|
||||
final int width = 150;
|
||||
|
||||
BufferedImage image = UIUtil.createImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = image.createGraphics();
|
||||
UIUtil.drawHeader(g, 0, width, height, active, true, false, false);
|
||||
g.dispose();
|
||||
|
||||
return image;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.intellij.designer;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -186,7 +185,7 @@ public abstract class LightToolWindowManager implements ProjectComponent {
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public final ActionGroup createGearActions() {
|
||||
public AnAction createGearActions() {
|
||||
DefaultActionGroup group = new DefaultActionGroup("In Editor Mode", true);
|
||||
|
||||
if (myLeftEditorModeAction == null) {
|
||||
@@ -298,7 +297,7 @@ public abstract class LightToolWindowManager implements ProjectComponent {
|
||||
return value.equals("ToolWindow") ? null : ToolWindowAnchor.fromText(value);
|
||||
}
|
||||
|
||||
final void setEditorMode(@Nullable ToolWindowAnchor newState) {
|
||||
protected final void setEditorMode(@Nullable ToolWindowAnchor newState) {
|
||||
ToolWindowAnchor oldState = getEditorMode();
|
||||
myPropertiesComponent.setValue(myEditorModeKey, newState == null ? "ToolWindow" : newState.toString());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user