Browse Source

REPORT-38954&&REPORT-38927&&REPORT-38924&&REPORT-38896 TopXCreator中添加XCreator的变量,绘制的时候禁用其双缓冲然后直接调用其paint方法

feature/big-screen
Yuan.Wang 4 years ago
parent
commit
a946a7e3d9
  1. 1
      designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java
  2. 35
      designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java
  3. 35
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  4. 15
      designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java
  5. 17
      designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java
  6. 5
      designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java
  7. 6
      designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java
  8. 5
      designer-form/src/main/java/com/fr/design/designer/creator/XWParameterLayout.java
  9. 5
      designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java
  10. 6
      designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java
  11. 1
      designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java
  12. 19
      designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java
  13. 39
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java
  14. 38
      designer-form/src/main/java/com/fr/design/mainframe/TopXCreator.java
  15. 38
      designer-form/src/main/java/com/fr/design/mainframe/TopXCreators.java
  16. 49
      designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreator.java

1
designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java

@ -310,7 +310,6 @@ public class SelectionModel {
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED);
setSelectedCreator(isInPara ? designer.getParaComponent() : designer.getRootComponent()); setSelectedCreator(isInPara ? designer.getParaComponent() : designer.getRootComponent());
designer.getTopXCreators().refresh();
// 触发事件 // 触发事件

35
designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java

@ -17,8 +17,6 @@ import com.fr.design.mainframe.CoverReportPane;
import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.EditingMouseListener;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.HelpDialogManager; import com.fr.design.mainframe.HelpDialogManager;
import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator;
import com.fr.design.mainframe.widget.topxcreator.TopXCreator;
import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor;
import com.fr.design.module.DesignModuleFactory; import com.fr.design.module.DesignModuleFactory;
import com.fr.form.ui.BaseChartEditor; import com.fr.form.ui.BaseChartEditor;
@ -231,6 +229,9 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
*/ */
public void paint(Graphics g) { public void paint(Graphics g) {
designerEditor.paintEditor(g, this.getSize()); designerEditor.paintEditor(g, this.getSize());
if (coverPanel != null) {
coverPanel.setSize(this.getSize());
}
super.paint(g); super.paint(g);
if (isEditing) { if (isEditing) {
g.setColor(INNER_BORDER_COLOR); g.setColor(INNER_BORDER_COLOR);
@ -361,34 +362,4 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
return false; return false;
} }
@Override
public BasicTopXCreator getTopXCreator() {
return new TopXChart(this);
}
private class TopXChart extends TopXCreator {
private final DesignerEditor designerEditor;
public TopXChart(XCreator creator) {
super(creator);
designerEditor = creator.getDesignerEditor();
Rectangle bounds = getBounds();
designerEditor.getEditorTarget().setBounds(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2);
}
/**
* 更新designerEditor的大小
*/
protected void resetSize(Rectangle bounds) {
super.resetSize(bounds);
designerEditor.getEditorTarget().setBounds(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2);
}
@Override
public void paint(Graphics g) {
designerEditor.paintEditor(g, this.getSize());
super.paint(g);
}
}
} }

35
designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java

@ -19,22 +19,16 @@ import com.fr.design.mainframe.CoverReportPane;
import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.EditingMouseListener;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.NoSupportAuthorityEdit; import com.fr.design.mainframe.NoSupportAuthorityEdit;
import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator;
import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.design.utils.gui.LayoutUtils; import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WTitleLayout; import com.fr.form.ui.container.WTitleLayout;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import com.fr.stable.CoreGraphHelper;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.third.javax.annotation.Nullable;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.border.Border; import javax.swing.border.Border;
import java.awt.BorderLayout; import java.awt.BorderLayout;
@ -44,7 +38,6 @@ import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -812,32 +805,4 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
return false; return false;
} }
/**
* 获得该组件的顶层显示组件
*/
@Nullable
public BasicTopXCreator getTopXCreator() {
return new BasicTopXCreator(this) {
@Override
protected void addComponent() {
Icon icon = new ImageIcon(getImage());
JLabel jLabel = new JLabel(icon, JLabel.CENTER);
jLabel.setSize(getSize());
this.add(jLabel);
}
};
}
/**
* 获得组件的图像
*/
public BufferedImage getImage() {
BufferedImage image = CoreGraphHelper.createBufferedImage(getWidth(), getHeight());
Graphics g = image.createGraphics();
this.paint(g);
return image;
}
} }

15
designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java

@ -343,4 +343,19 @@ public class XCreatorUtils {
} }
return xCreator != null; return xCreator != null;
} }
/**
* 获取组件的最顶层XMainBorderLayout,没有则返回null
* */
@com.fr.third.javax.annotation.Nullable
public static XWCardMainBorderLayout getTopXMainBorderLayout(Container creator) {
XWCardMainBorderLayout result = null;
while (creator != null) {
if (creator instanceof XWCardMainBorderLayout) {
result = (XWCardMainBorderLayout) creator;
}
creator = creator.getParent();
}
return result;
}
} }

17
designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java

@ -13,8 +13,6 @@ import com.fr.design.mainframe.widget.editors.ElementCaseToolBarEditor;
import com.fr.design.mainframe.widget.editors.PaddingMarginEditor; import com.fr.design.mainframe.widget.editors.PaddingMarginEditor;
import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor;
import com.fr.design.mainframe.widget.propertypane.BrowserFitPropertyEditor; import com.fr.design.mainframe.widget.propertypane.BrowserFitPropertyEditor;
import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator;
import com.fr.design.mainframe.widget.topxcreator.TopXCreator;
import com.fr.form.FormElementCaseContainerProvider; import com.fr.form.FormElementCaseContainerProvider;
import com.fr.form.FormElementCaseProvider; import com.fr.form.FormElementCaseProvider;
import com.fr.form.FormProvider; import com.fr.form.FormProvider;
@ -374,19 +372,4 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
return true; return true;
} }
@Override
public BasicTopXCreator getTopXCreator() {
return new TopXElementCase(this);
}
private class TopXElementCase extends TopXCreator {
private UILabel imageLabel;
public TopXElementCase(XCreator creator) {
super(creator);
imageLabel = initImageBackground();
add(imageLabel);
}
}
} }

5
designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java

@ -7,7 +7,6 @@ import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.fun.WidgetPropertyUIProvider;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor;
import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator;
import com.fr.form.ui.container.WAbsoluteBodyLayout; import com.fr.form.ui.container.WAbsoluteBodyLayout;
import com.fr.stable.core.PropertyChangeAdapter; import com.fr.stable.core.PropertyChangeAdapter;
@ -132,8 +131,4 @@ public class XWAbsoluteBodyLayout extends XWAbsoluteLayout {
return false; return false;
} }
@Override
public BasicTopXCreator getTopXCreator() {
return null;
}
} }

6
designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java

@ -25,8 +25,6 @@ import com.fr.design.mainframe.FormArea;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.WidgetHelpDialog; import com.fr.design.mainframe.WidgetHelpDialog;
import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator;
import com.fr.design.mainframe.widget.topxcreator.TopXCreator;
import com.fr.form.ui.Connector; import com.fr.form.ui.Connector;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
@ -610,8 +608,4 @@ public class XWAbsoluteLayout extends XLayoutContainer {
} }
} }
@Override
public BasicTopXCreator getTopXCreator() {
return new TopXCreator(this);
}
} }

5
designer-form/src/main/java/com/fr/design/designer/creator/XWParameterLayout.java

@ -15,7 +15,6 @@ import com.fr.design.mainframe.widget.editors.BooleanEditor;
import com.fr.design.mainframe.widget.editors.WidgetDisplayPosition; import com.fr.design.mainframe.widget.editors.WidgetDisplayPosition;
import com.fr.design.mainframe.widget.renderer.BackgroundRenderer; import com.fr.design.mainframe.widget.renderer.BackgroundRenderer;
import com.fr.design.mainframe.widget.renderer.WidgetDisplayPositionRender; import com.fr.design.mainframe.widget.renderer.WidgetDisplayPositionRender;
import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator;
import com.fr.form.ui.container.WBorderLayout; import com.fr.form.ui.container.WBorderLayout;
import com.fr.form.ui.container.WFitLayout; import com.fr.form.ui.container.WFitLayout;
import com.fr.form.ui.container.WParameterLayout; import com.fr.form.ui.container.WParameterLayout;
@ -252,10 +251,6 @@ public class XWParameterLayout extends XWAbsoluteLayout {
return false; return false;
} }
@Override
public BasicTopXCreator getTopXCreator() {
return null;
}
} }

5
designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java

@ -7,7 +7,6 @@ import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.FRTitleLayoutAdapter; import com.fr.design.designer.beans.adapters.layout.FRTitleLayoutAdapter;
import com.fr.design.form.layout.FRTitleLayout; import com.fr.design.form.layout.FRTitleLayout;
import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.fun.WidgetPropertyUIProvider;
import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator;
import com.fr.form.ui.Label; import com.fr.form.ui.Label;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.form.ui.WidgetTitle; import com.fr.form.ui.WidgetTitle;
@ -191,8 +190,4 @@ public class XWTitleLayout extends DedicateLayoutContainer {
return creator.getWidgetPropertyUIProviders(); return creator.getWidgetPropertyUIProviders();
} }
@Override
public BasicTopXCreator getTopXCreator() {
return getEditingChildCreator().getTopXCreator();
}
} }

6
designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java

@ -23,8 +23,6 @@ import com.fr.design.mainframe.EditingMouseListener;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.WidgetHelpDialog; import com.fr.design.mainframe.WidgetHelpDialog;
import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator;
import com.fr.design.mainframe.widget.topxcreator.TopXCreator;
import com.fr.form.event.Listener; import com.fr.form.event.Listener;
import com.fr.form.ui.CardSwitchButton; import com.fr.form.ui.CardSwitchButton;
import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.LayoutBorderStyle;
@ -515,8 +513,4 @@ public class XWCardMainBorderLayout extends XWBorderLayout {
return true; return true;
} }
@Override
public BasicTopXCreator getTopXCreator() {
return new TopXCreator(this);
}
} }

1
designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java

@ -90,7 +90,6 @@ public class ComponentTree extends JTree {
public void setSelectionPath(TreePath path) { public void setSelectionPath(TreePath path) {
// 不管点击哪一项,都要先退出编辑状态(图表、报表块、绝对布局、tab块) // 不管点击哪一项,都要先退出编辑状态(图表、报表块、绝对布局、tab块)
designer.stopEditing(path); designer.stopEditing(path);
designer.getTopXCreators().refresh();
super.setSelectionPath(path); super.setSelectionPath(path);
} }

19
designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java

@ -316,7 +316,6 @@ public class EditingMouseListener extends MouseInputAdapter {
XCreator component = designer.getComponentAt(e); XCreator component = designer.getComponentAt(e);
setCoverPaneNotDisplay(component, e, false); setCoverPaneNotDisplay(component, e, false);
designer.getTopXCreators().displayCoverPane(e);
if (processTopLayoutMouseMove(component, e)) { if (processTopLayoutMouseMove(component, e)) {
return; return;
@ -406,16 +405,7 @@ public class EditingMouseListener extends MouseInputAdapter {
} }
private void setCoverPaneNotDisplay(XCreator component, MouseEvent e, boolean isLinkedHelpDialog) { private void setCoverPaneNotDisplay(XCreator component, MouseEvent e, boolean isLinkedHelpDialog) {
if (xElementCase != null) {
int x = getParentPositionX(xElementCase, 0) - designer.getArea().getHorizontalValue();
int y = getParentPositionY(xElementCase, 0) - designer.getArea().getVerticalValue();
Rectangle rect = new Rectangle(x, y, xElementCase.getWidth(), xElementCase.getHeight());
if (rect.contains(e.getPoint())) {
return;
}
xElementCase.displayCoverPane(false);
}
if (xChartEditor != null) { if (xChartEditor != null) {
xChartEditor.displayCoverPane(false); xChartEditor.displayCoverPane(false);
} }
@ -426,6 +416,15 @@ public class EditingMouseListener extends MouseInputAdapter {
if (xTopLayoutContainer != null) { if (xTopLayoutContainer != null) {
xTopLayoutContainer.setMouseEnter(false); xTopLayoutContainer.setMouseEnter(false);
} }
//不知道为什么要对XElementCase进行判断,但是直接return会有bug,所以把他放在最后
if (xElementCase != null) {
int x = getParentPositionX(xElementCase, 0) - designer.getArea().getHorizontalValue();
int y = getParentPositionY(xElementCase, 0) - designer.getArea().getVerticalValue();
Rectangle rect = new Rectangle(x, y, xElementCase.getWidth(), xElementCase.getHeight());
if (!rect.contains(e.getPoint())) {
xElementCase.displayCoverPane(false);
}
}
designer.repaint(); designer.repaint();
} }

39
designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java

@ -35,9 +35,8 @@ import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWAbsoluteBodyLayout; import com.fr.design.designer.creator.XWAbsoluteBodyLayout;
import com.fr.design.designer.creator.XWAbsoluteLayout; import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.design.designer.creator.XWBorderLayout; import com.fr.design.designer.creator.XWBorderLayout;
import com.fr.design.designer.creator.XWFitLayout;
import com.fr.design.designer.creator.XWParameterLayout; import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.XWTitleLayout; import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.designer.properties.FormWidgetAuthorityEditPane; import com.fr.design.designer.properties.FormWidgetAuthorityEditPane;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
@ -46,7 +45,6 @@ import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.form.util.XCreatorConstants; import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.fun.RightSelectionHandlerProvider; import com.fr.design.fun.RightSelectionHandlerProvider;
import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus;
import com.fr.design.mainframe.widget.topxcreator.TopXCreators;
import com.fr.design.menu.MenuDef; import com.fr.design.menu.MenuDef;
import com.fr.design.menu.ShortCut; import com.fr.design.menu.ShortCut;
import com.fr.design.menu.ToolBarDef; import com.fr.design.menu.ToolBarDef;
@ -65,7 +63,6 @@ import com.fr.form.ui.Widget;
import com.fr.form.ui.WidgetValue; import com.fr.form.ui.WidgetValue;
import com.fr.form.ui.container.WBorderLayout; import com.fr.form.ui.container.WBorderLayout;
import com.fr.form.ui.container.WFitLayout; import com.fr.form.ui.container.WFitLayout;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
@ -837,47 +834,35 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/** /**
* 从已选择的组件中找x,y所在的组件 * 从已选择的组件中找x,y所在的组件
*/ */
private XCreator xCreatorAt(int x, int y,XCreator root) { private XCreator xCreatorAt(int x, int y, XCreator root) {
XCreator[] xCreators = selectionModel.getSelection().getSelectedCreators(); XCreator[] xCreators = selectionModel.getSelection().getSelectedCreators();
for (XCreator creator : xCreators) { for (XCreator creator : xCreators) {
boolean shouldContinue = creator == null boolean shouldContinue = creator == null
|| !creator.isVisible() || !creator.isVisible()
|| !XCreatorUtils.containComponent(root, creator) || !XCreatorUtils.containComponent(root, creator);
|| creator instanceof XWAbsoluteBodyLayout
|| creator instanceof XWFitLayout
|| creator instanceof XWParameterLayout;
if (shouldContinue) { if (shouldContinue) {
continue; continue;
} }
//如果组件为XWCardMainBorderLayout的子组件,直接从XWCardMainBorderLayout中去找
XWCardMainBorderLayout borderLayout = XCreatorUtils.getTopXMainBorderLayout(creator);
if (borderLayout != null) {
return xCreatorAt(x, y, borderLayout, null);
}
if (creator instanceof XLayoutContainer) {
return xCreatorAt(x, y, creator, null);
}
x -= creator.getX(); x -= creator.getX();
y -= creator.getY(); y -= creator.getY();
Rectangle rect = ComponentUtils.computeVisibleRect(creator); Rectangle rect = ComponentUtils.computeVisibleRect(creator);
rect.y += nestTabCount(creator) * WCardMainBorderLayout.TAB_HEIGHT;
// 判断是否处于交叉区域 // 判断是否处于交叉区域
if (!isIntersectArea(x, y, rect)) { if (!isIntersectArea(x, y, rect)) {
continue; continue;
} }
if (creator instanceof XWTitleLayout) { return creator;
return creator.getEditingChildCreator();
}
return xCreatorAt(x, y, creator, null);
} }
return null; return null;
} }
/**
* 计算嵌套的tab层数
*/
private int nestTabCount(Container xCreator) {
if (xCreator == null) {
return 0;
}
if (xCreator instanceof XWTabFitLayout) {
return 1 + nestTabCount(xCreator.getParent());
}
return nestTabCount(xCreator.getParent());
}
/** /**
* 刷新顶层组件 * 刷新顶层组件
* */ * */

38
designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/BasicTopXCreator.java → designer-form/src/main/java/com/fr/design/mainframe/TopXCreator.java

@ -1,23 +1,28 @@
package com.fr.design.mainframe.widget.topxcreator; package com.fr.design.mainframe;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.stable.CoreGraphHelper;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
/** /**
* @Author: Yuan.Wang * @Author: Yuan.Wang
* @Date: 2020/8/31 * @Date: 2020/8/31
*/ */
public class BasicTopXCreator extends JComponent { public class TopXCreator extends JComponent {
private FormDesigner designer; private final FormDesigner designer;
private XCreator creator; private final XCreator creator;
public BasicTopXCreator(XCreator creator) { public TopXCreator(XCreator creator) {
this.designer = WidgetPropertyPane.getInstance().getEditingFormDesigner(); this.designer = WidgetPropertyPane.getInstance().getEditingFormDesigner();
this.creator = creator; this.creator = creator;
init(); init();
@ -28,30 +33,16 @@ public class BasicTopXCreator extends JComponent {
setBackground(null); setBackground(null);
setLayout(null); setLayout(null);
setBounds(calculateBounds()); setBounds(calculateBounds());
addComponent();
} }
//子类可能会重写该方法
protected void resetSize(Rectangle bounds) {
//do nothing
}
protected void addComponent() {
}
/** /**
* 重新设置组件大小 * 重新设置组件大小
* */ * */
public void resizeTopXCreator() { public void resizeTopXCreator() {
Rectangle bounds=calculateBounds(); setBounds(calculateBounds());
setBounds(bounds);
resetSize(bounds);
} }
public void displayCoverPane(MouseEvent e, boolean visible) {}
/** /**
* 计算显示大小 * 计算显示大小
* */ * */
@ -63,8 +54,15 @@ public class BasicTopXCreator extends JComponent {
return bounds; return bounds;
} }
@Override @Override
public void paint(Graphics g) { public void paint(Graphics g) {
super.paint(g); super.paint(g);
ArrayList<JComponent> dbcomponents = new ArrayList<JComponent>();
// 禁止双缓冲
ComponentUtils.disableBuffer(creator, dbcomponents);
creator.paint(g);
// 恢复双缓冲
ComponentUtils.resetBuffer(dbcomponents);
} }
} }

38
designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreators.java → designer-form/src/main/java/com/fr/design/mainframe/TopXCreators.java

@ -1,11 +1,10 @@
package com.fr.design.mainframe.widget.topxcreator; package com.fr.design.mainframe;
import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
import java.awt.event.MouseEvent;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -31,7 +30,7 @@ public class TopXCreators extends JComponent {
setBackground(null); setBackground(null);
setOpaque(false); setOpaque(false);
designer.addDesignerEditListener(e -> { designer.addDesignerEditListener(e -> {
if (e.getCreatorEventID() == DesignerEvent.CREATOR_EDITED) { if (e.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
refresh(); refresh();
} }
}); });
@ -52,28 +51,6 @@ public class TopXCreators extends JComponent {
super.paint(g); super.paint(g);
} }
@Override
public void setVisible(boolean aFlag) {
super.setVisible(aFlag);
for (int i = 0, count = getComponentCount(); i < count; i++) {
if (getComponent(i) instanceof TopXCreator) {
TopXCreator xCreator = (TopXCreator) getComponent(i);
xCreator.displayCoverPane(aFlag);
}
}
repaint();
}
/**
* 依据MouseEvent坐标来设置是否显示蒙层
*/
public void displayCoverPane(MouseEvent e) {
for (int i = 0, count = getComponentCount(); i < count; i++) {
BasicTopXCreator xCreator = (BasicTopXCreator) getComponent(i);
xCreator.displayCoverPane(e, isVisible());
}
}
/** /**
* 加入被选择的组件 * 加入被选择的组件
*/ */
@ -81,19 +58,18 @@ public class TopXCreators extends JComponent {
SelectionModel selectionModel = designer.getSelectionModel(); SelectionModel selectionModel = designer.getSelectionModel();
XCreator[] xCreators = selectionModel.getSelection().getSelectedCreators(); XCreator[] xCreators = selectionModel.getSelection().getSelectedCreators();
for (XCreator creator : xCreators) { for (XCreator creator : xCreators) {
BasicTopXCreator topXCreator = creator.getTopXCreator(); XWCardMainBorderLayout topXMainBorderLayout = XCreatorUtils.getTopXMainBorderLayout(creator);
if (topXCreator != null) { TopXCreator topXCreator = topXMainBorderLayout == null ? new TopXCreator(creator) : new TopXCreator(topXMainBorderLayout);
add(topXCreator); add(topXCreator);
} }
} }
}
/** /**
* 更新顶层组件的位置和大小 * 更新顶层组件的位置和大小
*/ */
private void resizeTopXCreators() { private void resizeTopXCreators() {
for (int i = 0, count = getComponentCount(); i < count; i++) { for (int i = 0, count = getComponentCount(); i < count; i++) {
BasicTopXCreator topXCreator = (BasicTopXCreator) getComponent(i); TopXCreator topXCreator = (TopXCreator) getComponent(i);
topXCreator.resizeTopXCreator(); topXCreator.resizeTopXCreator();
} }
repaint(); repaint();

49
designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreator.java

@ -1,49 +0,0 @@
package com.fr.design.mainframe.widget.topxcreator;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.mainframe.CoverReportPane;
import java.awt.*;
import java.awt.event.MouseEvent;
/**
* @Author: Yuan.Wang
* @Date: 2020/8/26
*/
public class TopXCreator extends BasicTopXCreator {
private final CoverReportPane coverPanel;
public TopXCreator(XCreator creator) {
super(creator);
coverPanel = new CoverReportPane();
init();
}
private void init() {
coverPanel.setSize(getSize());
coverPanel.setVisible(false);
add(coverPanel);
}
protected void resetSize(Rectangle bounds) {
coverPanel.setSize(getSize());
}
/**
* 设置是否显示蒙层
* */
public void displayCoverPane(boolean visible) {
coverPanel.setVisible(visible);
}
/**
* 依据鼠标事件和visible设置是否显示蒙层
* */
public void displayCoverPane(MouseEvent event, boolean visible) {
boolean isVisible = visible && getBounds().contains(event.getX(), event.getY());
coverPanel.setVisible(isVisible);
}
}
Loading…
Cancel
Save