|
|
@ -3,27 +3,26 @@ package com.fr.design.gui.icontainer; |
|
|
|
|
|
|
|
|
|
|
|
import com.fine.theme.icon.LazyIcon; |
|
|
|
import com.fine.theme.icon.LazyIcon; |
|
|
|
import com.fine.theme.utils.FineUIScale; |
|
|
|
import com.fine.theme.utils.FineUIScale; |
|
|
|
|
|
|
|
import com.fine.theme.utils.FineUIUtils; |
|
|
|
import com.fr.design.base.mode.DesignModeContext; |
|
|
|
import com.fr.design.base.mode.DesignModeContext; |
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
|
|
|
import com.fr.design.layout.VerticalFlowLayout; |
|
|
|
import com.fr.design.layout.VerticalFlowLayout; |
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
import javax.swing.BorderFactory; |
|
|
|
import javax.swing.UIManager; |
|
|
|
import javax.swing.Icon; |
|
|
|
import javax.swing.JComponent; |
|
|
|
import javax.swing.JComponent; |
|
|
|
import javax.swing.JFrame; |
|
|
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.Icon; |
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
|
|
|
import javax.swing.UIManager; |
|
|
|
import javax.swing.border.Border; |
|
|
|
import javax.swing.border.Border; |
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
|
|
|
import java.awt.Component; |
|
|
|
import java.awt.Component; |
|
|
|
import java.awt.Container; |
|
|
|
import java.awt.Container; |
|
|
|
import java.awt.Cursor; |
|
|
|
import java.awt.Cursor; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Graphics; |
|
|
|
import java.awt.Graphics; |
|
|
|
import java.awt.LayoutManager; |
|
|
|
import java.awt.LayoutManager; |
|
|
|
|
|
|
|
import java.awt.Point; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseMotionListener; |
|
|
|
import java.awt.event.MouseMotionListener; |
|
|
@ -34,32 +33,87 @@ import java.awt.event.MouseMotionListener; |
|
|
|
public class UIEastResizableContainer extends JPanel { |
|
|
|
public class UIEastResizableContainer extends JPanel { |
|
|
|
private static final long serialVersionUID = 1854340560790476907L; |
|
|
|
private static final long serialVersionUID = 1854340560790476907L; |
|
|
|
|
|
|
|
|
|
|
|
public static final int MAX_CONTAINER_WIDTH = FineUIScale.scale(340); |
|
|
|
public static final int MAX_CONTAINER_WIDTH = FineUIUtils.getScaledI18nDimension( |
|
|
|
public static final int MIN_CONTAINER_WIDTH = FineUIScale.scale(286); |
|
|
|
"com.fr.design.mainframe.EastRegionContainerPane.maximum").width; |
|
|
|
|
|
|
|
public static final int MIN_CONTAINER_WIDTH = FineUIUtils.getScaledI18nDimension( |
|
|
|
|
|
|
|
"com.fr.design.mainframe.EastRegionContainerPane.minimum").width; |
|
|
|
|
|
|
|
public static final int STD_CONTAINER_WIDTH = FineUIUtils.getScaledI18nDimension( |
|
|
|
|
|
|
|
"com.fr.design.mainframe.EastRegionContainerPane.standard").width; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int containerWidth = STD_CONTAINER_WIDTH; |
|
|
|
|
|
|
|
private int preferredWidth = STD_CONTAINER_WIDTH; |
|
|
|
|
|
|
|
protected final int leftPaneWidth = FineUIScale.scale(42); |
|
|
|
|
|
|
|
protected final int topToolPaneHeight = FineUIScale.scale(40); |
|
|
|
|
|
|
|
|
|
|
|
private int containerWidth = FineUIScale.scale(240); |
|
|
|
private static final int ARROW_RANGE = FineUIScale.scale(35); |
|
|
|
private int preferredWidth = FineUIScale.scale(240); |
|
|
|
|
|
|
|
private int topToolPaneHeight = FineUIScale.scale(40); |
|
|
|
|
|
|
|
private int leftPaneWidth = FineUIScale.scale(42); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JComponent leftPane; |
|
|
|
private JComponent leftPane; |
|
|
|
private JComponent rightPane; |
|
|
|
private JComponent rightPane; |
|
|
|
|
|
|
|
|
|
|
|
private TopToolPane topToolPane; |
|
|
|
private TopToolPane topToolPane; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int DRAG_GAP_SIZE = 10; |
|
|
|
private static final int ARROW_MARGIN = FineUIScale.scale(15); |
|
|
|
private Point dragPoint; |
|
|
|
private static final int ARROW_RANGE = FineUIScale.scale(35); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UIEastResizableContainer() { |
|
|
|
public UIEastResizableContainer() { |
|
|
|
this(new JPanel(), new JPanel()); |
|
|
|
this(new JPanel(), new JPanel()); |
|
|
|
|
|
|
|
initMouseListener(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initMouseListener() { |
|
|
|
|
|
|
|
MouseAdapter mouseAdapter = new MouseAdapter() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void mouseMoved(MouseEvent e) { |
|
|
|
|
|
|
|
updateCursor(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
|
|
|
|
if (isEnableDrag(e)) { |
|
|
|
|
|
|
|
dragPoint = e.getPoint(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void mouseDragged(MouseEvent e) { |
|
|
|
|
|
|
|
resizePanel(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addMouseListener(mouseAdapter); |
|
|
|
|
|
|
|
addMouseMotionListener(mouseAdapter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateCursor(MouseEvent e) { |
|
|
|
|
|
|
|
if (isEnableDrag(e)) { |
|
|
|
|
|
|
|
setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected boolean isEnableDrag(MouseEvent e) { |
|
|
|
|
|
|
|
return e.getX() <= DRAG_GAP_SIZE && isRightPaneVisible(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void resizePanel(MouseEvent e) { |
|
|
|
|
|
|
|
if (!isRightPaneVisible()) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int dx = e.getX() - dragPoint.x; |
|
|
|
|
|
|
|
Dimension size = getSize(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int newWidth = size.width - dx; |
|
|
|
|
|
|
|
// 限制container大小为指定范围
|
|
|
|
|
|
|
|
containerWidth = Math.max(MIN_CONTAINER_WIDTH, Math.min(newWidth, MAX_CONTAINER_WIDTH)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SwingUtilities.invokeLater(this::revalidate); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 设置面板宽度 |
|
|
|
* 设置面板宽度 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param width |
|
|
|
* @param width 宽度 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setContainerWidth(int width) { |
|
|
|
public void setContainerWidth(int width) { |
|
|
|
this.containerWidth = width; |
|
|
|
this.containerWidth = width; |
|
|
@ -70,8 +124,6 @@ public class UIEastResizableContainer extends JPanel { |
|
|
|
return containerWidth > leftPaneWidth; |
|
|
|
return containerWidth > leftPaneWidth; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setPreferredWidth(int width) { |
|
|
|
private void setPreferredWidth(int width) { |
|
|
|
this.preferredWidth = width; |
|
|
|
this.preferredWidth = width; |
|
|
|
} |
|
|
|
} |
|
|
@ -81,7 +133,7 @@ public class UIEastResizableContainer extends JPanel { |
|
|
|
this.rightPane = rightPane; |
|
|
|
this.rightPane = rightPane; |
|
|
|
this.topToolPane = new TopToolPane(); |
|
|
|
this.topToolPane = new TopToolPane(); |
|
|
|
topToolPane.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 1, 0)); |
|
|
|
topToolPane.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 1, 0)); |
|
|
|
topToolPane.setBorder(BorderFactory.createMatteBorder(0 ,1, 0, 1, UIManager.getColor("East.border"))); |
|
|
|
topToolPane.setBorder(BorderFactory.createMatteBorder(0, 1, 0, 1, UIManager.getColor("East.border"))); |
|
|
|
|
|
|
|
|
|
|
|
setLayout(containerLayout); |
|
|
|
setLayout(containerLayout); |
|
|
|
add(topToolPane); |
|
|
|
add(topToolPane); |
|
|
@ -89,38 +141,6 @@ public class UIEastResizableContainer extends JPanel { |
|
|
|
add(rightPane); |
|
|
|
add(rightPane); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String... args) { |
|
|
|
|
|
|
|
JFrame jf = new JFrame("test"); |
|
|
|
|
|
|
|
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
|
|
|
|
JPanel content = (JPanel) jf.getContentPane(); |
|
|
|
|
|
|
|
content.setLayout(new BorderLayout()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JPanel leftPane = new JPanel(); |
|
|
|
|
|
|
|
// leftPane.setBackground(Color.yellow);
|
|
|
|
|
|
|
|
JPanel rightPane = new JPanel(); |
|
|
|
|
|
|
|
// rightPane.setBackground(Color.green);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UIButton b1, b2; |
|
|
|
|
|
|
|
b1 = new UIButton("b1"); |
|
|
|
|
|
|
|
b2 = new UIButton("b2"); |
|
|
|
|
|
|
|
b1.setPreferredSize(new Dimension(40, 40)); |
|
|
|
|
|
|
|
b2.setPreferredSize(new Dimension(40, 40)); |
|
|
|
|
|
|
|
leftPane.add(b1); |
|
|
|
|
|
|
|
leftPane.add(b2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UIEastResizableContainer bb = new UIEastResizableContainer(leftPane, rightPane); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JPanel cc = new JPanel(); |
|
|
|
|
|
|
|
// cc.setBackground(Color.WHITE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content.add(bb, BorderLayout.EAST); |
|
|
|
|
|
|
|
content.add(cc, BorderLayout.CENTER); |
|
|
|
|
|
|
|
GUICoreUtils.centerWindow(jf); |
|
|
|
|
|
|
|
jf.setSize(500, 500); |
|
|
|
|
|
|
|
jf.setVisible(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 将面板设置成最佳的宽度 |
|
|
|
* 将面板设置成最佳的宽度 |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -156,7 +176,6 @@ public class UIEastResizableContainer extends JPanel { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void removeLayoutComponent(Component comp) { |
|
|
|
public void removeLayoutComponent(Component comp) { |
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -182,7 +201,7 @@ public class UIEastResizableContainer extends JPanel { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void addLayoutComponent(String name, Component comp) { |
|
|
|
public void addLayoutComponent(String name, Component comp) { |
|
|
|
// do nothing
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|