Browse Source

Merge pull request #597 in BA/design from ~VITO/design:master to master

* commit '51c7715dc123f523f4ba1822d96ff1262018960c':
  pmd
  REPORT-1220 修复表单界面的图表和控件悬浮面板点击其他位置不消失的问题
master
superman 8 years ago
parent
commit
965da42791
  1. 183
      designer_form/src/com/fr/design/mainframe/FormParaWidgetPane.java

183
designer_form/src/com/fr/design/mainframe/FormParaWidgetPane.java

@ -18,7 +18,6 @@ import com.fr.form.ui.*;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.stable.ArrayUtils;
import com.fr.stable.OperatingSystem;
import javax.swing.*;
import java.awt.*;
@ -27,7 +26,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class FormParaWidgetPane extends JPanel{
public class FormParaWidgetPane extends JPanel {
private static FormParaWidgetPane THIS;
private List<WidgetOption> predifinedwidgeList = new ArrayList<WidgetOption>();
@ -46,19 +45,19 @@ public class FormParaWidgetPane extends JPanel{
//预定义控件最多显示20行
private int preWidgetShowMaxRow = 20;
//显示8个图表组件
private static final int commonChartNum = 8;
private static final int COMMON_CHAR_NUM = 8;
//显示10个普通控件
private int commonWidgetNum = 10;
private JSeparator jSeparatorPara;
private JSeparator jSeparatorChart;
private JSeparator jSeparatorLayout;
private UILabel paraLabel ;
private UILabel paraLabel;
private FormDesigner designer;
public static final FormParaWidgetPane getInstance(FormDesigner designer) {
if(THIS == null) {
if (THIS == null) {
THIS = new FormParaWidgetPane();
}
THIS.designer = designer;
@ -71,13 +70,13 @@ public class FormParaWidgetPane extends JPanel{
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
if (FormParaWidgetPane.this.getParent() != null) {
JPanel fother = (JPanel)FormParaWidgetPane.this.getParent();
JPanel fother = (JPanel) FormParaWidgetPane.this.getParent();
int delta_wdith = 0;
for (int i = 0; i < fother.getComponentCount() - 1; i ++) {
for (int i = 0; i < fother.getComponentCount() - 1; i++) {
delta_wdith += fother.getComponent(i).getWidth();
}
if(delta_wdith == 0){
if (delta_wdith == 0) {
return;
}
@ -97,16 +96,16 @@ public class FormParaWidgetPane extends JPanel{
JPanel paraPane = new JPanel(new FlowLayout());
ToolBarButton paraButton = new paraButton(FormWidgetOption.PARAMETERCONTAINER);
paraPane.add(paraButton);
add(createNormalCombinationPane(paraPane,Inter.getLocText("FR-Designer_Parameter")));
add(createNormalCombinationPane(paraPane, Inter.getLocText("FR-Designer_Parameter")));
jSeparatorPara = createJSeparator();
add(jSeparatorPara);
JPanel layoutPane = new JPanel(new FlowLayout());
for(WidgetOption option : loadLayoutOptions()){
for (WidgetOption option : loadLayoutOptions()) {
layoutPane.add(new ToolBarButton(option));
}
layoutPane.add(new ToolBarButton(FormWidgetOption.ELEMENTCASE));
add(createNormalCombinationPane(layoutPane,Inter.getLocText("FR-Designer_Layout_Block_Blank")));
add(createNormalCombinationPane(layoutPane, Inter.getLocText("FR-Designer_Layout_Block_Blank")));
jSeparatorLayout = createJSeparator();
add(jSeparatorLayout);
@ -114,8 +113,8 @@ public class FormParaWidgetPane extends JPanel{
int totalChartNums = loadChartOptions().length;
if (totalChartNums > 0) {
JPanel chartTypePane = new JPanel(new FlowLayout());
for (int i = 0;i < commonChartNum ;i++) {
chartTypePane.add( new ToolBarButton(loadChartOptions()[i]));
for (int i = 0; i < COMMON_CHAR_NUM; i++) {
chartTypePane.add(new ToolBarButton(loadChartOptions()[i]));
}
add(createChartCombinationPane(chartTypePane, Inter.getLocText("FR-Designer-Form-ToolBar_Chart")));
jSeparatorChart = createJSeparator();
@ -123,13 +122,13 @@ public class FormParaWidgetPane extends JPanel{
}
JPanel widgetPane = new JPanel(new FlowLayout());
for (int i = 0;i < commonWidgetNum;i++) {
for (int i = 0; i < commonWidgetNum; i++) {
widgetPane.add(new ToolBarButton(loadWidgetOptions()[i]));
}
widgetPane.add(createJSeparator(20));
loadPredefinedWidget();
int num = Math.min(predifinedwidgeList.size(),preWidgetShowMaxNum);
for (int i = 0 ;i < num ;i++) {
int num = Math.min(predifinedwidgeList.size(), preWidgetShowMaxNum);
for (int i = 0; i < num; i++) {
widgetPane.add(new ToolBarButton(predifinedwidgeList.get(i)));
}
add(createWidgetCombinationPane(widgetPane, Inter.getLocText("FR-Designer-Form-ToolBar_Widget")));
@ -138,9 +137,9 @@ public class FormParaWidgetPane extends JPanel{
private void loadPredefinedWidget() {
predifinedwidgeList.clear();
if(designer != null) {
if (designer != null) {
WidgetOption[] designerPre = designer.getDesignerMode().getPredefinedWidgetOptions();
for(int i = 0; i < designerPre.length; i++) {
for (int i = 0; i < designerPre.length; i++) {
predifinedwidgeList.add(designerPre[i]);
}
}
@ -156,7 +155,7 @@ public class FormParaWidgetPane extends JPanel{
// ...
continue;
}
if (!XCreatorUtils.createXCreator(widget).canEnterIntoParaPane()){
if (!XCreatorUtils.createXCreator(widget).canEnterIntoParaPane()) {
//预定义控件工具栏这儿不显示工具栏中没有的预定义控件
continue;
}
@ -177,61 +176,61 @@ public class FormParaWidgetPane extends JPanel{
}
private JPanel createNormalCombinationPane(JComponent jComponent,String typeName){
JPanel reportPane = new JPanel(new BorderLayout(17,5));
reportPane.add(jComponent,BorderLayout.CENTER);
private JPanel createNormalCombinationPane(JComponent jComponent, String typeName) {
JPanel reportPane = new JPanel(new BorderLayout(17, 5));
reportPane.add(jComponent, BorderLayout.CENTER);
JPanel labelPane = new JPanel(new BorderLayout());
UILabel label = new UILabel(typeName,UILabel.CENTER);
if(ComparatorUtils.equals(Inter.getLocText("FR-Designer_Parameter"),typeName )){
UILabel label = new UILabel(typeName, UILabel.CENTER);
if (ComparatorUtils.equals(Inter.getLocText("FR-Designer_Parameter"), typeName)) {
paraLabel = label;
}
labelPane.add(label,BorderLayout.CENTER);
reportPane.add(labelPane,BorderLayout.SOUTH);
reportPane.setPreferredSize(new Dimension((int)reportPane.getPreferredSize().getWidth(),(int)reportPane.getPreferredSize().getHeight()));
labelPane.add(label, BorderLayout.CENTER);
reportPane.add(labelPane, BorderLayout.SOUTH);
reportPane.setPreferredSize(new Dimension((int) reportPane.getPreferredSize().getWidth(), (int) reportPane.getPreferredSize().getHeight()));
return reportPane;
}
private JPanel createChartCombinationPane(JComponent jComponent,String typeName){
JPanel chartPane = new JPanel(new BorderLayout(17,5));
private JPanel createChartCombinationPane(JComponent jComponent, String typeName) {
JPanel chartPane = new JPanel(new BorderLayout(17, 5));
chartPane.add(jComponent, BorderLayout.CENTER);
JPanel labelPane = new JPanel(new BorderLayout());
labelPane.add(new UILabel(typeName,UILabel.CENTER),BorderLayout.CENTER);
labelPane.add(new UILabel(typeName, UILabel.CENTER), BorderLayout.CENTER);
UIButton chartPopUpButton = createPopUpButton();
chartPopUpButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(chartTypeWindow == null) {
if (chartTypeWindow == null) {
JPanel componentsPara = new JPanel(new FlowLayout(FlowLayout.LEFT));
WidgetOption[] chartOptions = loadChartOptions();
for (WidgetOption chartOption : chartOptions) {
componentsPara.add( new ToolBarButton(chartOption));
componentsPara.add(new ToolBarButton(chartOption));
}
int x = commonChartNum * (widgetButtonWidth + smallGAP);
int y = (int)Math.ceil(chartOptions.length/((double)commonChartNum)) * (widgetButtonHeight + smallGAP);
componentsPara.setPreferredSize(new Dimension(x,y));
int x = COMMON_CHAR_NUM * (widgetButtonWidth + smallGAP);
int y = (int) Math.ceil(chartOptions.length / ((double) COMMON_CHAR_NUM)) * (widgetButtonHeight + smallGAP);
componentsPara.setPreferredSize(new Dimension(x, y));
chartTypeWindow = new PopUpWindow(componentsPara, Inter.getLocText("FR-Designer-Form-ToolBar_Chart"));
chartTypeWindow.setLocation((int)jSeparatorLayout.getLocationOnScreen().getX() + 1, (int)jSeparatorLayout.getLocationOnScreen().getY());
chartTypeWindow.setLocation((int) jSeparatorLayout.getLocationOnScreen().getX() + 1, (int) jSeparatorLayout.getLocationOnScreen().getY());
chartTypeWindow.setSize(chartTypeWindow.getPreferredSize());
}
chartTypeWindow.setVisible(true);
}
});
labelPane.add(chartPopUpButton,BorderLayout.EAST);
chartPane.add(labelPane,BorderLayout.SOUTH);
labelPane.add(chartPopUpButton, BorderLayout.EAST);
chartPane.add(labelPane, BorderLayout.SOUTH);
return chartPane;
}
private JPanel createWidgetCombinationPane(JComponent jComponent,String typeName){
JPanel widgetPane = new JPanel(new BorderLayout(17,5));
widgetPane.add(jComponent,BorderLayout.CENTER);
private JPanel createWidgetCombinationPane(JComponent jComponent, String typeName) {
JPanel widgetPane = new JPanel(new BorderLayout(17, 5));
widgetPane.add(jComponent, BorderLayout.CENTER);
JPanel labelPane = new JPanel(new BorderLayout());
labelPane.add(new UILabel(typeName,UILabel.CENTER),BorderLayout.CENTER);
labelPane.add(new UILabel(typeName, UILabel.CENTER), BorderLayout.CENTER);
UIButton chartPopUpButton = createPopUpButton();
chartPopUpButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
JPanel widgetPane = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));
JPanel widgetPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
loadPredefinedWidget();
int rowNum = calculateWidgetWindowRowNum();
JPanel westPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
@ -239,27 +238,27 @@ public class FormParaWidgetPane extends JPanel{
westPanel.add(new ToolBarButton(o));
}
int x = commonWidgetNum * (widgetButtonWidth + smallGAP);
westPanel.setPreferredSize(new Dimension(x,(int)(rowNum * westPanel.getPreferredSize().getHeight())));
westPanel.setPreferredSize(new Dimension(x, (int) (rowNum * westPanel.getPreferredSize().getHeight())));
JPanel eastPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
for (WidgetOption no : predifinedwidgeList) {
eastPane.add(new ToolBarButton(no));
}
int maxWidth = preWidgetShowMaxNum * (widgetButtonWidth + smallGAP);
int width = predifinedwidgeList.size() >= preWidgetShowMaxNum ? maxWidth:(int)eastPane.getPreferredSize().getWidth();
eastPane.setPreferredSize(new Dimension(width,(int)(rowNum*eastPane.getPreferredSize().getHeight())));
int width = predifinedwidgeList.size() >= preWidgetShowMaxNum ? maxWidth : (int) eastPane.getPreferredSize().getWidth();
eastPane.setPreferredSize(new Dimension(width, (int) (rowNum * eastPane.getPreferredSize().getHeight())));
UIScrollPane eastScrollPane = new UIScrollPane(eastPane);
eastScrollPane.setBorder(null);
int maxHeight = preWidgetShowMaxRow * (widgetButtonHeight + smallGAP);
int height = predifinedwidgeList.size() >= preWidgetShowMaxNum * preWidgetShowMaxRow ? maxHeight : (int)eastPane.getPreferredSize().getHeight();
width = predifinedwidgeList.size() >= preWidgetShowMaxNum * preWidgetShowMaxRow ? (int)eastPane.getPreferredSize().getWidth() + smallGAP + jsparatorWidth : (int)eastPane.getPreferredSize().getWidth();
eastScrollPane.setPreferredSize(new Dimension(width,height));
int height = predifinedwidgeList.size() >= preWidgetShowMaxNum * preWidgetShowMaxRow ? maxHeight : (int) eastPane.getPreferredSize().getHeight();
width = predifinedwidgeList.size() >= preWidgetShowMaxNum * preWidgetShowMaxRow ? (int) eastPane.getPreferredSize().getWidth() + smallGAP + jsparatorWidth : (int) eastPane.getPreferredSize().getWidth();
eastScrollPane.setPreferredSize(new Dimension(width, height));
widgetPane.add(westPanel);
widgetPane.add(createJSeparator(height));
widgetPane.add(eastScrollPane);
widgetTypeWindow = new PopUpWindow( widgetPane, Inter.getLocText("FR-Designer-Form-ToolBar_Widget"));
widgetTypeWindow = new PopUpWindow(widgetPane, Inter.getLocText("FR-Designer-Form-ToolBar_Widget"));
widgetTypeWindow.setSize(widgetTypeWindow.getPreferredSize());
if (jSeparatorChart != null) {
widgetTypeWindow.setLocation((int) jSeparatorChart.getLocationOnScreen().getX() + 1, (int) jSeparatorChart.getLocationOnScreen().getY());
@ -268,59 +267,60 @@ public class FormParaWidgetPane extends JPanel{
}
});
labelPane.add(chartPopUpButton,BorderLayout.EAST);
widgetPane.add(labelPane,BorderLayout.SOUTH);
labelPane.add(chartPopUpButton, BorderLayout.EAST);
widgetPane.add(labelPane, BorderLayout.SOUTH);
return widgetPane;
}
private int calculateWidgetWindowRowNum(){
private int calculateWidgetWindowRowNum() {
//向上取整
int rowNum = (int)Math.ceil((double)predifinedwidgeList.size()/(double)preWidgetShowMaxNum);
rowNum = Math.max(rowNum,2);
rowNum = Math.min(rowNum,preWidgetShowMaxRow);
int rowNum = (int) Math.ceil((double) predifinedwidgeList.size() / (double) preWidgetShowMaxNum);
rowNum = Math.max(rowNum, 2);
rowNum = Math.min(rowNum, preWidgetShowMaxRow);
return rowNum;
}
private JSeparator createJSeparator(){
JSeparator jSeparator = new JSeparator(SwingConstants.VERTICAL );
jSeparator.setPreferredSize(new Dimension(jsparatorWidth,jsparatorHeight));
private JSeparator createJSeparator() {
JSeparator jSeparator = new JSeparator(SwingConstants.VERTICAL);
jSeparator.setPreferredSize(new Dimension(jsparatorWidth, jsparatorHeight));
return jSeparator;
}
private JSeparator createJSeparator(double height){
JSeparator jSeparator = new JSeparator(SwingConstants.VERTICAL );
jSeparator.setPreferredSize(new Dimension(jsparatorWidth,(int)height));
private JSeparator createJSeparator(double height) {
JSeparator jSeparator = new JSeparator(SwingConstants.VERTICAL);
jSeparator.setPreferredSize(new Dimension(jsparatorWidth, (int) height));
return jSeparator;
}
private UIButton createPopUpButton(){
private UIButton createPopUpButton() {
UIButton popUpButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/buttonicon/arrowdown.png"));
popUpButton.set4ToolbarButton();
return popUpButton;
}
private UIButton createPopDownButton(){
private UIButton createPopDownButton() {
UIButton popUpButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/buttonicon/arrowup.png"));
popUpButton.set4ToolbarButton();
return popUpButton;
}
private class paraButton extends ToolBarButton{
public paraButton(WidgetOption no){
private class paraButton extends ToolBarButton {
public paraButton(WidgetOption no) {
super(no);
this.setDisabledIcon(BaseUtils.readIcon("/com/fr/web/images/form/resources/layout_parameter2.png"));
if(designer != null){
if (designer != null) {
this.setEnabled(designer.getParaComponent() == null);
}
}
public void mouseDragged(MouseEvent e) {
if (designer.getParaComponent() != null){
if (designer.getParaComponent() != null) {
return;
}
designer.addParaComponent();
JPanel pane =FormWidgetDetailPane.getInstance(designer);
JPanel pane = FormWidgetDetailPane.getInstance(designer);
EastRegionContainerPane.getInstance().replaceDownPane(pane);
this.setEnabled(false);
@ -334,7 +334,7 @@ public class FormParaWidgetPane extends JPanel{
public void setEnabled(boolean b) {
super.setEnabled(b);
paraLabel.setForeground(b ? Color.BLACK : new Color(198,198,198));
paraLabel.setForeground(b ? Color.BLACK : new Color(198, 198, 198));
}
}
@ -348,6 +348,7 @@ public class FormParaWidgetPane extends JPanel{
/**
* 响应界面改变事件
*
* @param evt 事件
*/
public void fireCreatorModified(DesignerEvent evt) {
@ -356,14 +357,13 @@ public class FormParaWidgetPane extends JPanel{
}
private class PopUpWindow extends JWindow {
private JPanel northPane;
private String typeName;
private int LineWidth = 5;
private int BarWidth = 10;
public PopUpWindow(JPanel northPane,String typeName){
public PopUpWindow(JPanel northPane, String typeName) {
super();
this.northPane = northPane;
this.typeName = typeName;
@ -376,21 +376,18 @@ public class FormParaWidgetPane extends JPanel{
public void eventDispatched(AWTEvent event) {
if (event instanceof MouseEvent) {
MouseEvent mv = (MouseEvent) event;
Point point = mv.getLocationOnScreen();
double endX = PopUpWindow.this.getX() + northPane.getWidth() + LineWidth;
double startX = endX - BarWidth;
double startY = PopUpWindow.this.getY() + northPane.getY();
double endY = startY + northPane.getHeight();
boolean dragBar = startX < point.getX() && endX > point.getX() && endY > point.getY();
if (!dragBar && mv.getClickCount() > 0 && mv.getID() != MouseEvent.MOUSE_RELEASED) {
if(!ComparatorUtils.equals(mv.getSource(), PopUpWindow.this)) {
if (!OperatingSystem.isMacOS()) {
if (mv.getClickCount() > 0) {
Point point = new Point((int) (mv.getLocationOnScreen().getX()), (int) mv.getLocationOnScreen().getY());
// 直接contains在mac下,点击内部也会消失
Dimension d = PopUpWindow.this.getSize();
Point p = PopUpWindow.this.getLocation();
Rectangle rect = new Rectangle(p, d);
if (!rect.contains(point)) {
PopUpWindow.this.setVisible(false);
}
}
}
}
}
};
@ -398,9 +395,9 @@ public class FormParaWidgetPane extends JPanel{
JPanel rootPane = new EditorChoosePane();
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(17, 0));
contentPane.add(northPane,BorderLayout.CENTER);
contentPane.add(northPane, BorderLayout.CENTER);
JPanel labelPane = new JPanel(new BorderLayout());
labelPane.add(new UILabel(typeName,UILabel.CENTER),BorderLayout.CENTER);
labelPane.add(new UILabel(typeName, UILabel.CENTER), BorderLayout.CENTER);
JButton popUpButton = createPopDownButton();
popUpButton.addMouseListener(new MouseAdapter() {
@Override
@ -409,8 +406,8 @@ public class FormParaWidgetPane extends JPanel{
}
});
labelPane.add(popUpButton, BorderLayout.EAST);
contentPane.add(labelPane,BorderLayout.SOUTH);
rootPane.add(contentPane,BorderLayout.CENTER);
contentPane.add(labelPane, BorderLayout.SOUTH);
rootPane.add(contentPane, BorderLayout.CENTER);
return rootPane;
}
@ -421,31 +418,31 @@ public class FormParaWidgetPane extends JPanel{
private class EditorChoosePane extends JPanel {
public EditorChoosePane() {
super();
((FlowLayout)this.getLayout()).setVgap(1);
((FlowLayout) this.getLayout()).setVgap(1);
}
@Override
public void paintComponent(Graphics g) {
Rectangle r = this.getBounds();
g.setColor(UIConstants.NORMAL_BACKGROUND);
g.fillRoundRect(r.x, r.y, r.width, r.height,0,0);
g.fillRoundRect(r.x, r.y, r.width, r.height, 0, 0);
g.setColor(UIConstants.LINE_COLOR);
g.drawLine(r.x, r.y, r.x, r.y+r.height);
g.drawLine(r.x, r.y+r.height-1, r.x+r.width-1, r.y+r.height-1);
g.drawLine(r.x+r.width-1, r.y, r.x+r.width-1, r.y+r.height-1);
g.drawLine(r.x, r.y, r.x, r.y + r.height);
g.drawLine(r.x, r.y + r.height - 1, r.x + r.width - 1, r.y + r.height - 1);
g.drawLine(r.x + r.width - 1, r.y, r.x + r.width - 1, r.y + r.height - 1);
}
}
private WidgetOption[] loadWidgetOptions() {
if (widgetOptions == null) {
widgetOptions = (WidgetOption[])ArrayUtils.addAll(WidgetOption.getFormWidgetIntance(), ExtraDesignClassManager.getInstance().getFormWidgetOptions());
widgetOptions = (WidgetOption[]) ArrayUtils.addAll(WidgetOption.getFormWidgetIntance(), ExtraDesignClassManager.getInstance().getFormWidgetOptions());
}
return widgetOptions;
}
private WidgetOption[] loadLayoutOptions() {
if (layoutOptions == null) {
layoutOptions = (WidgetOption[])ArrayUtils.addAll(FormWidgetOption.getFormLayoutInstance(), ExtraDesignClassManager.getInstance().getFormWidgetContainerOptions());
layoutOptions = (WidgetOption[]) ArrayUtils.addAll(FormWidgetOption.getFormLayoutInstance(), ExtraDesignClassManager.getInstance().getFormWidgetContainerOptions());
}
return layoutOptions;
}

Loading…
Cancel
Save