Browse Source

REPORT-3163 合作开发9.0设计器=>初步合并外框架代码

master
plough 7 years ago
parent
commit
4659e8e312
  1. 299
      designer_base/src/com/fr/design/gui/icontainer/UIEastResizableContainer.java
  2. 247
      designer_base/src/com/fr/design/mainframe/EastRegionContainerPane.java

299
designer_base/src/com/fr/design/gui/icontainer/UIEastResizableContainer.java

@ -0,0 +1,299 @@
package com.fr.design.gui.icontainer;
import com.fr.base.BaseUtils;
import com.fr.design.constants.UIConstants;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.Constants;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
/**
* Created by plough on 2017/7/7.
*/
public class UIEastResizableContainer extends JPanel {
private static final long serialVersionUID = 1854340560790476907L;
private int containerWidth = 240;
private int preferredWidth = 240;
private int topToolPaneHeight = 20;
private int leftPaneWidth = 40;
private JComponent leftPane;
private JComponent rightPane;
// private HorizotalToolPane horizontToolPane;
private TopToolPane topToolPane;
private static final int ARROW_MARGIN = 15;
private static final int ARROW_RANGE = 35;
private boolean isRightPaneVisible = true;
public UIEastResizableContainer() {
this(new JPanel(), new JPanel());
}
/**
* 设置面板宽度
*
* @param width
*/
public void setContainerWidth(int width) {
this.containerWidth = width;
this.preferredWidth = width;
}
public void setRightPaneVisible(boolean isVisible){
this.isRightPaneVisible = isVisible;
}
private void setPreferredWidth(int width) {
this.preferredWidth = width;
}
public UIEastResizableContainer(JComponent leftPane, JComponent rightPane) {
setBackground(UIConstants.NORMAL_BACKGROUND);
this.leftPane = leftPane;
this.rightPane = rightPane;
this.topToolPane = new TopToolPane();
setLayout(containerLayout);
add(topToolPane);
add(leftPane);
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);
}
/**
* 将面板设置成最佳的宽度
*/
public void setWindow2PreferWidth() {
if (containerWidth == leftPaneWidth) {
containerWidth = preferredWidth;
refreshContainer();
}
}
/**
* 得到容器的宽度
*
* @return
*/
public int getContainerWidth() {
return this.containerWidth;
}
/**
* 设置关闭设计器前最后一次面板的宽度
*
* @param containerWidth
*/
public void setLastContainerWidth(int containerWidth) {
this.containerWidth = containerWidth;
}
private LayoutManager containerLayout = new LayoutManager() {
@Override
public void removeLayoutComponent(Component comp) {
// TODO Auto-generated method stub
}
@Override
public Dimension preferredLayoutSize(Container parent) {
return parent.getPreferredSize();
}
@Override
public Dimension minimumLayoutSize(Container parent) {
return null;
}
@Override
public void layoutContainer(Container parent) {
if (topToolPane == null || rightPane == null) {
return;
}
topToolPane.setBounds(0, 0, containerWidth, topToolPaneHeight);//0,0,10,462
leftPane.setBounds(0, topToolPaneHeight, leftPaneWidth, getHeight() - topToolPaneHeight);
// parameterPane.setBounds(20, 0, 230, getParameterPaneHeight());//10,0,230,462
rightPane.setBounds(leftPaneWidth, topToolPaneHeight, containerWidth-leftPaneWidth, getHeight() - topToolPaneHeight);//20,0,230,0
}
@Override
public void addLayoutComponent(String name, Component comp) {
}
};
@Override
/**
* 得到最佳大小
*/
public Dimension getPreferredSize() {
return new Dimension(containerWidth, 400);
}
/**
* 替换左子面板
*
* @param pane 面板
*/
public void replaceLeftPane(JComponent pane) {
remove(pane);
remove(this.leftPane);
add(this.leftPane = pane);
refreshContainer();
}
/**
* 替换右子面板
*
* @param pane 面板
*/
public void replaceRightPane(JComponent pane) {
remove(pane);
remove(this.rightPane);
add(this.rightPane = pane);
refreshContainer();
}
/**
* 得到左子面板
*
* @return
*/
public JComponent getLeftPane() {
return this.leftPane;
}
/**
* 得到右子面板
*
* @return
*/
public JComponent getRightPane() {
return this.rightPane;
}
private void refreshContainer() {
validate();
repaint();
revalidate();
}
private class TopToolPane extends JPanel {
private int model = UIConstants.MODEL_NORMAL;
public TopToolPane() {
super();
addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseMoved(MouseEvent e) {
if (e.getX() <= ARROW_RANGE) {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
model = UIConstants.MODEL_PRESS;
} else {
setCursor(Cursor.getDefaultCursor());
model = UIConstants.MODEL_NORMAL;
}
repaint();
}
@Override
public void mouseDragged(MouseEvent e) {
}
});
addMouseListener(new MouseAdapter() {
@Override
public void mouseExited(MouseEvent e) {
setCursor(Cursor.getDefaultCursor());
model = UIConstants.MODEL_NORMAL;
repaint();
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getX() <= ARROW_RANGE) {
if (containerWidth == leftPaneWidth) {
containerWidth = preferredWidth;
} else {
setPreferredWidth(containerWidth);
containerWidth = leftPaneWidth;
}
refreshContainer();
if (BaseUtils.isAuthorityEditing()) {
DesignerContext.getDesignerFrame().doResize();
}
}
}
});
}
@Override
public void paint(Graphics g) {
Image button;
g.drawImage(UIConstants.DRAG_BAR, 0, 0, containerWidth, topToolPaneHeight, null);
if (containerWidth == leftPaneWidth) {
if (model == UIConstants.MODEL_NORMAL) {
button = UIConstants.DRAG_LEFT_NORMAL;
} else {
button = UIConstants.DRAG_LEFT_PRESS;
}
} else {
if (model == UIConstants.MODEL_NORMAL) {
button = UIConstants.DRAG_RIGHT_NORMAL;
} else {
button = UIConstants.DRAG_RIGHT_PRESS;
}
}
// g.drawImage(button, 2, ARROW_MARGIN_VERTICAL, 5, toolPaneHeight, null);
g.drawImage(button, 20, 7, 5, 5, null);
}
}
}

247
designer_base/src/com/fr/design/mainframe/EastRegionContainerPane.java

@ -1,11 +1,28 @@
package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.design.DesignerEnvManager;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icontainer.UIEastResizableContainer;
import com.fr.design.gui.icontainer.UIResizableContainer;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.Constants;
public class EastRegionContainerPane extends UIResizableContainer {
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
public class EastRegionContainerPane extends UIEastResizableContainer {
private static EastRegionContainerPane THIS;
private List<PropertyItem> propertyItemList;
private CardLayout propertyCard;
private JPanel leftPane;
private JPanel rightPane;
private static final int CONTAINER_WIDTH = 260;
private static final int BUTTON_WIDTH = 40;
/**
* 得到实例
@ -15,24 +32,240 @@ public class EastRegionContainerPane extends UIResizableContainer {
public static final EastRegionContainerPane getInstance() {
if (THIS == null) {
THIS = new EastRegionContainerPane();
THIS.setLastToolPaneY(DesignerEnvManager.getEnvManager().getLastEastRegionToolPaneY());
// THIS.setLastToolPaneY(DesignerEnvManager.getEnvManager().getLastEastRegionToolPaneY());
THIS.setLastContainerWidth(DesignerEnvManager.getEnvManager().getLastEastRegionContainerWidth());
}
return THIS;
}
public EastRegionContainerPane() {
super(Constants.LEFT);
setVerticalDragEnabled(false);
super();
// setVerticalDragEnabled(false);
initPropertyItemList();
initRightPane();
initLeftPane();
// super(leftPane, rightPane);
setContainerWidth(260);
}
private void initPropertyItemList() {
propertyItemList = new ArrayList<>();
// 单元格元素
PropertyItem cellElement = new PropertyItem("cellElement", "/com/fr/design/images/buttonicon/add.png");
// 单元格属性
PropertyItem cellAttr = new PropertyItem("cellAttr", "com/fr/design/images/toolbarbtn/close.png");
// 悬浮元素
PropertyItem floatElement = new PropertyItem("floatElement", "com/fr/design/images/toolbarbtn/close.png");
// 控件设置
PropertyItem widgetSettings = new PropertyItem("widgetSettings", "com/fr/design/images/toolbarbtn/close.png");
// 条件属性
PropertyItem conditionAttr = new PropertyItem("conditionAttr", "com/fr/design/images/toolbarbtn/close.png");
// 超级链接
PropertyItem hyperlink = new PropertyItem("hyperlink", "com/fr/design/images/toolbarbtn/close.png");
// 组件库
PropertyItem widgetLib = new PropertyItem("widgetLib", "com/fr/design/images/toolbarbtn/close.png");
propertyItemList.add(cellElement);
propertyItemList.add(cellAttr);
propertyItemList.add(floatElement);
propertyItemList.add(widgetSettings);
propertyItemList.add(conditionAttr);
propertyItemList.add(hyperlink);
propertyItemList.add(widgetLib);
}
// 右侧属性面板
private void initRightPane() {
rightPane = new JPanel();
propertyCard = new CardLayout();
rightPane.setBackground(Color.green);
rightPane.setLayout(propertyCard);
for (PropertyItem item : propertyItemList) {
rightPane.add(item.getName(), item.getPropertyPanel());
}
replaceRightPane(rightPane);
}
// 左侧按钮面板
private void initLeftPane() {
leftPane = new JPanel();
for (PropertyItem item : propertyItemList) {
leftPane.add(item.getButton());
}
// leftPane.setLayout(new BoxLayout(leftPane, BoxLayout.Y_AXIS));
leftPane.setBackground(Color.yellow);
replaceLeftPane(leftPane);
}
public EastRegionContainerPane(JPanel leftPane, JPanel rightPane) {
super(leftPane, rightPane);
// setVerticalDragEnabled(false);
// setContainerWidth(260);
}
public void replaceUpPane(JComponent pane) {
propertyItemList.get(0).replaceContentPane(pane);
}
public void replaceDownPane(JComponent pane) {
propertyItemList.get(1).replaceContentPane(pane);
}
public JComponent getUpPane() {
return propertyItemList.get(0).getContentPane();
}
public JComponent getDownPane() {
return propertyItemList.get(1).getContentPane();
}
public void addParameterPane(JComponent paraPane) {
propertyItemList.get(2).replaceContentPane(paraPane);
}
public void setParameterHeight(int height) {
// stub
}
public static void main(String[] args){
JFrame jf = new JFrame("test");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel cc = new JPanel();
cc.setBackground(Color.white);
// JPanel leftPane = new JPanel();
// leftPane.setBackground(Color.yellow);
// JPanel rightPane = new JPanel();
// rightPane.setBackground(Color.green);
//
// JButton b1, b2;
// b1 = new JButton("b1");
// b2 = new JButton("b2");
// b1.setPreferredSize(new Dimension(40, 40));
// b2.setPreferredSize(new Dimension(40, 40));
// leftPane.add(b1);
// leftPane.add(b2);
// leftPane.setLayout(new BoxLayout(leftPane, BoxLayout.Y_AXIS));
JPanel content = (JPanel)jf.getContentPane();
// content.setLayout(null);
content.add(cc, BorderLayout.CENTER);
content.add(new EastRegionContainerPane(), BorderLayout.EAST);
GUICoreUtils.centerWindow(jf);
jf.setSize(400, 400);
jf.setVisible(true);
}
public void removeParameterPane() {
}
/**
* 刷新下面板
* 刷新面板
*/
public void refreshRightPane() {
if (this.getRightPane() instanceof DockingView) {
((DockingView) this.getRightPane()).refreshDockingView();
}
}
public void refreshDownPane() {
if (this.getDownPane() instanceof DockingView) {
((DockingView) this.getDownPane()).refreshDockingView();
JComponent pane = propertyItemList.get(1).getContentPane();
if (pane instanceof DockingView) {
((DockingView) pane).refreshDockingView();
}
}
public int getToolPaneY() {
return 0;
}
class PropertyItem {
// private UIButton button;
private JButton button;
private String name;
private JPanel propertyPanel;
private JComponent contentPane;
private int x, y; // 弹出框的坐标
private int height; // 弹出框的高度
private boolean isPoppedOut; // 是否弹出
public PropertyItem(String name, String btnUrl) {
this.name = name;
initButton(btnUrl);
initPropertyPanel();
}
// 选项不可用
public void setEnabled(boolean enabled) {
button.setEnabled(enabled);
}
private void initPropertyPanel() {
propertyPanel = new JPanel();
propertyPanel.setBackground(Color.pink);
// propertyPanel.setPreferredSize(getPreferredSize());
// JPanel titlePanel = new JPanel();
// titlePanel.setPreferredSize(new Dimension(propertyPanel.getPreferredSize().width, 20));
// titlePanel
JButton testBtn = new JButton(name);
testBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setEnabled(!button.isEnabled());
}
});
contentPane = new JPanel();
contentPane.add(testBtn);
propertyPanel.setLayout(new BorderLayout());
propertyPanel.add(contentPane, BorderLayout.CENTER);
}
public void replaceContentPane(JComponent pane) {
// remove(pane);
propertyPanel.remove(this.contentPane);
propertyPanel.add(this.contentPane = pane);
refreshContainer();
}
public JComponent getContentPane() {
return contentPane;
}
private void refreshContainer() {
propertyPanel.validate();
propertyPanel.repaint();
propertyPanel.revalidate();
}
private void initButton(String btnUrl) {
button = new JButton(BaseUtils.readIcon(btnUrl));
// button = new UIButton("btnd\nssdg");
// button.set4LargeToolbarButton();
button.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_WIDTH));
button.setContentAreaFilled(false);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
propertyCard.show(rightPane, name);
}
});
}
public JButton getButton() {
return button;
}
public String getName() {
return name;
}
public JPanel getPropertyPanel() {
return propertyPanel;
}
}
}
Loading…
Cancel
Save