diff --git a/designer_base/src/com/fr/design/data/BasicTableDataTreePane.java b/designer_base/src/com/fr/design/data/BasicTableDataTreePane.java index 32049380d..a6fd601a8 100644 --- a/designer_base/src/com/fr/design/data/BasicTableDataTreePane.java +++ b/designer_base/src/com/fr/design/data/BasicTableDataTreePane.java @@ -3,6 +3,7 @@ package com.fr.design.data; import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.base.TableData; +import com.fr.data.TableDataSource; import com.fr.data.impl.storeproc.StoreProcedure; import com.fr.design.DesignModelAdapter; import com.fr.design.actions.UpdateAction; @@ -423,4 +424,7 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp this.setSmallIcon(BaseUtils.readIcon(IconPathConstants.TD_CONNECTION_ICON_PATH)); } } + public void addTableData(TableDataSource tableDataSource){ + + } } diff --git a/designer_base/src/com/fr/design/data/datapane/TableDataTreePane.java b/designer_base/src/com/fr/design/data/datapane/TableDataTreePane.java index 162957ebf..911b0d9c9 100644 --- a/designer_base/src/com/fr/design/data/datapane/TableDataTreePane.java +++ b/designer_base/src/com/fr/design/data/datapane/TableDataTreePane.java @@ -39,6 +39,7 @@ import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; public class TableDataTreePane extends BasicTableDataTreePane { @@ -138,6 +139,7 @@ public class TableDataTreePane extends BasicTableDataTreePane { populate(new TableDataSourceOP(tc)); this.checkButtonEnabled(); } + protected void initbuttonGroup() { Icon[] iconArray = {BaseUtils.readIcon("/com/fr/design/images/data/datasource.png"), BaseUtils.readIcon("/com/fr/design/images/data/dock/serverdatabase.png")}; final Integer[] modeArray = {TEMPLATE_TABLE_DATA, SERVER_TABLE_DATA}; @@ -267,4 +269,22 @@ public class TableDataTreePane extends BasicTableDataTreePane { public TableDataTree getDataTree() { return dataTree; } + + public void addTableData(TableDataSource tableDataSource) { + DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER); + TableDataSource tds = tc.getBook(); + Iterator tdIterator = tableDataSource.getTableDataNameIterator(); + while (tdIterator.hasNext()) { + String tdName = (String) tdIterator.next(); + TableData td = tableDataSource.getTableData(tdName); + if (tds.getTableData(tdName) != null) { + tds.putTableData(tdName + "-fr-el", td); + } else { + tds.putTableData(tdName, td); + } + } + tc.fireTargetModified(); + tc.parameterChanged(); + dataTree.refresh(); + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/icon/IconPathConstants.java b/designer_base/src/com/fr/design/icon/IconPathConstants.java index c254e04d6..4a86bcf6f 100644 --- a/designer_base/src/com/fr/design/icon/IconPathConstants.java +++ b/designer_base/src/com/fr/design/icon/IconPathConstants.java @@ -1 +1 @@ -package com.fr.design.icon; /** * Created by IntelliJ IDEA. * Author : Richer * Version: 6.5.6 * Date: 12-12-18 * Time: 上午9:42 * 用于保存所有图标路径的类 */ public class IconPathConstants { private IconPathConstants() { } public static final String ADD_POPMENU_ICON_PATH = "/com/fr/design/images/control/addPopup.png"; public static final String DS_ICON_PATH = "/com/fr/design/images/data/datasource.png"; public static final String CLASS_TD_ICON_PATH = "/com/fr/design/images/data/source/classTableData.png"; public static final String EMB_TD_ICON_PATH = "/com/fr/design/images/data/dataTable.png"; public static final String DS_RELATION_TD_ICON_PATH = "/com/fr/design/images/data/multi.png"; public static final String FILE_TD_ICON_PATH = "/com/fr/design/images/data/file.png"; public static final String DS_TREE_TD_ICON_PATH = "/com/fr/design/images/data/tree.png"; public static final String DS_QUERY_ICON_PATH = "/com/fr/design/images/data/database.png"; public static final String PREVIEW_ICON_PATH = "/com/fr/design/images/m_file/preview.png"; public static final String TD_EDIT_ICON_PATH = "/com/fr/design/images/control/edit.png"; public static final String TD_REMOVE_ICON_PATH = "/com/fr/base/images/cell/control/remove.png"; public static final String TD_CONNECTION_ICON_PATH = "/com/fr/design/images/m_web/connection.png"; public static final String SP_SHOW_ICON_PATH = "/com/fr/design/images/data/store_procedure.png"; public static final String STD_SHOW_ICON_PATH = "/com/fr/design/images/data/dock/serverdatabase.png"; public static final String XMLA_ICON_PATH = "/com/fr/design/images/data/cube.png"; public static final String FORBID_ICON_PATH ="/com/fr/web/images/form/forbid.png"; } \ No newline at end of file +package com.fr.design.icon; /** * Created by IntelliJ IDEA. * Author : Richer * Version: 6.5.6 * Date: 12-12-18 * Time: 上午9:42 * 用于保存所有图标路径的类 */ public class IconPathConstants { private IconPathConstants() { } public static final String ADD_POPMENU_ICON_PATH = "/com/fr/design/images/control/addPopup.png"; public static final String DS_ICON_PATH = "/com/fr/design/images/data/datasource.png"; public static final String CLASS_TD_ICON_PATH = "/com/fr/design/images/data/source/classTableData.png"; public static final String EMB_TD_ICON_PATH = "/com/fr/design/images/data/dataTable.png"; public static final String DS_RELATION_TD_ICON_PATH = "/com/fr/design/images/data/multi.png"; public static final String FILE_TD_ICON_PATH = "/com/fr/design/images/data/file.png"; public static final String DS_TREE_TD_ICON_PATH = "/com/fr/design/images/data/tree.png"; public static final String DS_QUERY_ICON_PATH = "/com/fr/design/images/data/database.png"; public static final String PREVIEW_ICON_PATH = "/com/fr/design/images/m_file/preview.png"; public static final String TD_EDIT_ICON_PATH = "/com/fr/design/images/control/edit.png"; public static final String TD_EL_SHARE_HELP_ICON_PATH = "/com/fr/design/images/control/help_open.png"; public static final String TD_EL_SHARE_CLOSE_ICON_PATH = "/com/fr/design/images/control/help_close.png"; public static final String TD_REMOVE_ICON_PATH = "/com/fr/base/images/cell/control/remove.png"; public static final String TD_CONNECTION_ICON_PATH = "/com/fr/design/images/m_web/connection.png"; public static final String SP_SHOW_ICON_PATH = "/com/fr/design/images/data/store_procedure.png"; public static final String STD_SHOW_ICON_PATH = "/com/fr/design/images/data/dock/serverdatabase.png"; public static final String XMLA_ICON_PATH = "/com/fr/design/images/data/cube.png"; public static final String FORBID_ICON_PATH ="/com/fr/web/images/form/forbid.png"; } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/images/control/help_close.png b/designer_base/src/com/fr/design/images/control/help_close.png new file mode 100644 index 000000000..036865c18 Binary files /dev/null and b/designer_base/src/com/fr/design/images/control/help_close.png differ diff --git a/designer_base/src/com/fr/design/images/control/help_open.png b/designer_base/src/com/fr/design/images/control/help_open.png new file mode 100644 index 000000000..b988d678f Binary files /dev/null and b/designer_base/src/com/fr/design/images/control/help_open.png differ diff --git a/designer_form/src/com/fr/design/designer/creator/XCreator.java b/designer_form/src/com/fr/design/designer/creator/XCreator.java index 552402398..d030104a2 100644 --- a/designer_form/src/com/fr/design/designer/creator/XCreator.java +++ b/designer_form/src/com/fr/design/designer/creator/XCreator.java @@ -12,6 +12,10 @@ import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.*; import com.fr.design.utils.gui.LayoutUtils; +import com.fr.form.share.ShareLoader; +import com.fr.form.ui.AbstractFormSharableEditor; +import com.fr.form.ui.ElCaseBindInfo; +import com.fr.form.ui.FormSharableEditor; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WTitleLayout; import com.fr.stable.StableUtils; @@ -590,4 +594,21 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo * @param msg 帮助信息 */ public void setSharedMsg(String msg){} + + /** + * 根据widget设置Xcreator共享信息 + * @param widget + */ + public void setShareMsgByWidget(Widget widget){ + if (widget != null && (widget instanceof FormSharableEditor)) { + String shareId = ((AbstractFormSharableEditor) widget).getShareId(); + ElCaseBindInfo info = ShareLoader.getLoader().getElCaseBindInfoById(shareId); + if (info != null) { + + setSharedMsg(info.getGuideInfo()); + + } + } + + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/creator/XCreatorUtils.java b/designer_form/src/com/fr/design/designer/creator/XCreatorUtils.java index e0fc68355..36158f821 100644 --- a/designer_form/src/com/fr/design/designer/creator/XCreatorUtils.java +++ b/designer_form/src/com/fr/design/designer/creator/XCreatorUtils.java @@ -157,6 +157,7 @@ public class XCreatorUtils { FRContext.getLogger().error("Error to create xcreator!"); creator = new NullCreator(widget, d); } + creator.setShareMsgByWidget(widget);//设置共享信息 return creator; } diff --git a/designer_form/src/com/fr/design/designer/creator/XElementCase.java b/designer_form/src/com/fr/design/designer/creator/XElementCase.java index 252ec35c7..0e0d35637 100644 --- a/designer_form/src/com/fr/design/designer/creator/XElementCase.java +++ b/designer_form/src/com/fr/design/designer/creator/XElementCase.java @@ -35,7 +35,7 @@ import java.beans.PropertyDescriptor; public class XElementCase extends XBorderStyleWidgetCreator implements FormElementCaseContainerProvider{ private UILabel imageLable; - private JPanel coverPanel; + private CoverReportPane coverPanel; private FormDesigner designer; //缩略图 private BufferedImage thumbnailImage; @@ -181,11 +181,10 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme * @param display 是否 */ public void displayCoverPane(boolean display){ - coverPanel.setVisible(display); - coverPanel.setPreferredSize(editor.getPreferredSize()); - coverPanel.setBounds(editor.getBounds()); - editor.repaint(); - } + coverPanel.setVisible(display); + coverPanel.setBounds(1, 1, (int) editor.getBounds().getWidth(), (int) editor.getBounds().getHeight()); + editor.repaint(); + } public JComponent getCoverPane(){ return coverPanel; @@ -263,7 +262,11 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme */ public void respondClick(EditingMouseListener editingMouseListener,MouseEvent e){ super.respondClick(editingMouseListener, e); - switchTab(e,editingMouseListener); + if (this.isHelpBtnOnFocus()) { + coverPanel.setMsgDisplay(e); + }else { + switchTab(e,editingMouseListener); + } } @@ -280,4 +283,9 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme public WidgetPropertyUIProvider[] getWidgetPropertyUIProviders() { return new WidgetPropertyUIProvider[]{ new ElementCasePropertyUI(this)}; } + + @Override + public void setSharedMsg(String msg) { + coverPanel.setHelpMsg(msg); + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/CoverReportPane.java b/designer_form/src/com/fr/design/mainframe/CoverReportPane.java index 183cf24ee..42dc62040 100644 --- a/designer_form/src/com/fr/design/mainframe/CoverReportPane.java +++ b/designer_form/src/com/fr/design/mainframe/CoverReportPane.java @@ -1,12 +1,19 @@ package com.fr.design.mainframe; -import com.fr.base.BaseUtils; +import com.fr.design.constants.UIConstants; +import com.fr.design.designer.beans.events.DesignerEditListener; +import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.icon.IconPathConstants; +import com.fr.form.share.ShareConstants; +import com.fr.general.FRScreen; +import com.fr.general.IOUtils; import com.fr.general.Inter; +import com.fr.stable.StringUtils; import javax.swing.*; import java.awt.*; +import java.awt.event.MouseEvent; /** * Created with IntelliJ IDEA. @@ -14,59 +21,122 @@ import java.awt.*; * Date: 14-7-24 * Time: 上午9:09 */ -public class CoverReportPane extends JPanel{ +public class CoverReportPane extends JPanel { private UIButton editButton; + private Icon controlMode = IOUtils.readIcon(IconPathConstants.TD_EL_SHARE_CLOSE_ICON_PATH); + private JComponent controlButton = new JComponent() { + protected void paintComponent(Graphics g) { + g.setColor(UIConstants.NORMAL_BACKGROUND); + g.fillArc(0, 0, ShareConstants.SHARE_EL_CONTROL_BUTTON_HW, ShareConstants.SHARE_EL_CONTROL_BUTTON_HW, + 0, 360); + controlMode.paintIcon(this, g, 0, 0); + } + }; + + + private String helpMsg;//帮助信息(后续帮助信息可能会变成标配,就直接放这边了) + + private ElementCaseHelpDialog helpDialog = null; private AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 60 / 100.0F); - public CoverReportPane(){ - setLayout(coverLayout); + public CoverReportPane() { + this(StringUtils.EMPTY); + } + + public CoverReportPane(String helpMsg) { + this.helpMsg = helpMsg; + setLayout(getCoverLayout()); setBackground(null); setOpaque(false); - editButton = new UIButton(Inter.getLocText("Edit"), BaseUtils.readIcon(IconPathConstants.TD_EDIT_ICON_PATH)){ + editButton = new UIButton(Inter.getLocText("Edit"), IOUtils.readIcon(IconPathConstants.TD_EDIT_ICON_PATH)) { @Override public Dimension getPreferredSize() { - return new Dimension(60,24); + return new Dimension(60, 24); } }; editButton.setBorderPainted(false); editButton.setExtraPainted(false); - editButton.setBackground(new Color(176,196,222)); + editButton.setBackground(new Color(176, 196, 222)); add(editButton); + add(controlButton); + WidgetPropertyPane.getInstance().getEditingFormDesigner().addDesignerEditListener(new DesignerEditListener() { + @Override + public void fireCreatorModified(DesignerEvent evt) { + if (evt.getCreatorEventID() == (DesignerEvent.CREATOR_DELETED) + || evt.getCreatorEventID() == (DesignerEvent.CREATOR_RESIZED)) { + destroyHelpDialog(); + } + } + }); + } + public String getHelpMsg() { + return helpMsg; } - private LayoutManager coverLayout = new LayoutManager() { + public void setHelpMsg(String helpMsg) { + this.helpMsg = helpMsg; + } - @Override - public void removeLayoutComponent(Component comp) { + public void setMsgDisplay(MouseEvent e) { + if (helpDialog == null) { + controlMode = IOUtils.readIcon(IconPathConstants.TD_EL_SHARE_CLOSE_ICON_PATH); + controlButton.repaint(); + helpDialog = new ElementCaseHelpDialog(DesignerContext.getDesignerFrame(), helpMsg); + double screenValue = FRScreen.getByDimension(Toolkit.getDefaultToolkit().getScreenSize()).getValue(); + int offsetX = 0; + if (screenValue < FormArea.DEFAULT_SLIDER) { + offsetX = (int) ((1 - screenValue / FormArea.DEFAULT_SLIDER) + * WidgetPropertyPane.getInstance().getEditingFormDesigner().getRootComponent().getWidth() / 2); + } + int rX = WestRegionContainerPane.getInstance().getWidth() + e.getX() + offsetX - 227;//弹出框宽度190加上图标的宽度27加上10的偏移 + int rY = 165 + e.getY();//165是设计器最上面几个面板的高度 + helpDialog.setLocationRelativeTo(DesignerContext.getDesignerFrame(), rX, rY); + helpDialog.showWindow(); + } else { + controlMode = IOUtils.readIcon(IconPathConstants.TD_EL_SHARE_HELP_ICON_PATH); + controlButton.repaint(); + helpDialog.dispose(); + helpDialog = null; } + } - @Override - public Dimension preferredLayoutSize(Container parent) { - return parent.getPreferredSize(); - } + protected LayoutManager getCoverLayout() { + return new LayoutManager() { - @Override - public Dimension minimumLayoutSize(Container parent) { - return null; - } + @Override + public void removeLayoutComponent(Component comp) { + } - @Override - public void layoutContainer(Container parent) { - int width = parent.getParent().getWidth(); - int height = parent.getParent().getHeight(); - int preferWidth = editButton.getPreferredSize().width; - int preferHeight = editButton.getPreferredSize().height; - editButton.setBounds((width - preferWidth)/2, (height - preferHeight)/2, preferWidth, preferHeight); - } + @Override + public Dimension preferredLayoutSize(Container parent) { + return parent.getPreferredSize(); + } + + @Override + public Dimension minimumLayoutSize(Container parent) { + return null; + } + + @Override + public void layoutContainer(Container parent) { + int width = parent.getParent().getWidth(); + int height = parent.getParent().getHeight(); + int preferWidth = editButton.getPreferredSize().width; + int preferHeight = editButton.getPreferredSize().height; + editButton.setBounds((width - preferWidth) / 2, (height - preferHeight) / 2, preferWidth, preferHeight); + controlButton.setBounds((width - 28), 0, 27, 27); + } + + @Override + public void addLayoutComponent(String name, Component comp) { + } + }; + } - @Override - public void addLayoutComponent(String name, Component comp) { - } - }; public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; @@ -77,4 +147,14 @@ public class CoverReportPane extends JPanel{ g2d.setComposite(oldComposite); super.paint(g); } + + public void destroyHelpDialog() { + if (helpDialog != null) { + controlMode = IOUtils.readIcon(IconPathConstants.TD_EL_SHARE_HELP_ICON_PATH); + controlButton.repaint(); + helpDialog.dispose(); + helpDialog = null; + } + } + } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java b/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java index fc25bd124..0aa77281d 100644 --- a/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java +++ b/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java @@ -1,14 +1,5 @@ package com.fr.design.mainframe; -import java.awt.Color; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.Rectangle; -import java.awt.event.MouseEvent; - -import javax.swing.*; -import javax.swing.event.MouseInputAdapter; - import com.fr.base.BaseUtils; import com.fr.design.beans.location.MoveUtils; import com.fr.design.designer.beans.AdapterBus; @@ -29,6 +20,11 @@ import com.fr.design.utils.gui.LayoutUtils; import com.fr.general.Inter; import com.fr.stable.Constants; +import javax.swing.*; +import javax.swing.event.MouseInputAdapter; +import java.awt.*; +import java.awt.event.MouseEvent; + /** * 普通模式下的鼠标点击、位置处理器 */ @@ -291,18 +287,28 @@ public class EditingMouseListener extends MouseInputAdapter { if (component.isReport()) { xElementCase = (XElementCase)component; - UIButton button = (UIButton)xElementCase.getCoverPane().getComponent(0); + UIButton button = (UIButton)xElementCase.getCoverPane().getComponent(0); + JComponent button1= (JComponent) xElementCase.getCoverPane().getComponent(1); if(designer.getCursor().getType() ==Cursor.HAND_CURSOR) { designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } // component.getParent() 是报表块所在的XWTitleLayout int minX = button.getX() + getParentPositionX(component, 0) - designer.getArea().getHorizontalValue(); + int minX1 = button1.getX() + getParentPositionX(component, 0) - designer.getArea().getHorizontalValue(); int minY = button.getY() + getParentPositionY(component, 0) - designer.getArea().getVerticalValue(); - if(e.getX() + GAP > minX && e.getX() - GAP < minX + button.getWidth()){ - if( e.getY() + GAP > minY && e.getY() - GAP < minY + button.getHeight()){ - designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } - } - xElementCase.displayCoverPane(true); + int minY1 = button1.getY() + getParentPositionY(component, 0) - designer.getArea().getVerticalValue(); + if (e.getX() + GAP - xElementCase.getInsets().left > minX && e.getX() - GAP - xElementCase.getInsets().left < minX + button.getWidth()) { + if (e.getY() + GAP - xElementCase.getInsets().top > minY && e.getY() - GAP - xElementCase.getInsets().top < minY + button.getHeight()) { + designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } + } + xElementCase.setHelpBtnOnFocus(false); + if (e.getX() + GAP - xElementCase.getInsets().left > minX1 && e.getX() - GAP - xElementCase.getInsets().left < minX1 + button1.getWidth()) { + if (e.getY() + GAP - xElementCase.getInsets().top > minY1 && e.getY() - GAP - xElementCase.getInsets().top < minY1 + button1.getHeight()) { + designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + xElementCase.setHelpBtnOnFocus(true); + } + } + xElementCase.displayCoverPane(true); xElementCase.setDirections(Direction.TOP_BOTTOM_LEFT_RIGHT); designer.repaint(); diff --git a/designer_form/src/com/fr/design/mainframe/ElementCaseHelpDialog.java b/designer_form/src/com/fr/design/mainframe/ElementCaseHelpDialog.java new file mode 100644 index 000000000..60b699107 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/ElementCaseHelpDialog.java @@ -0,0 +1,73 @@ +package com.fr.design.mainframe; + +import com.fr.design.dialog.UIDialog; +import com.fr.design.gui.icontainer.UIScrollPane; +import com.fr.design.gui.itextarea.UITextArea; + +import javax.swing.*; +import java.awt.*; + +/** + * @author zack + * @date 2016-10-14 + * @since 8.0 + */ +public class ElementCaseHelpDialog extends UIDialog { + + private static final int OUTER_WIDTH = 190; + private static final int OUTER_HEIGHT = 120; + + + private String helpMsg; + private UIScrollPane helpArea; + + + public ElementCaseHelpDialog(Frame parent, String helpMsg) { + super(parent); + this.helpMsg = helpMsg; + setUndecorated(true); + initHelpArea(); + JPanel panel = (JPanel) getContentPane(); + initComponents(panel); + setSize(new Dimension(OUTER_WIDTH, OUTER_HEIGHT)); + } + + private void initHelpArea() { + UITextArea textArea = new UITextArea(helpMsg); + textArea.setEditable(false); + textArea.setBorder(null); + helpArea = new UIScrollPane(textArea); + helpArea.setBounds(0, 0, 190, 120); + helpArea.setBorder(null); + } + + private void initComponents(JPanel contentPane) { + contentPane.setLayout(new BorderLayout()); + add(helpArea, BorderLayout.CENTER); + } + + /** + * 打开帮助框 + */ + public void showWindow() { + setVisible(true); + this.setResizable(false); + } + + /** + * 略 + */ + @Override + public void checkValid() throws Exception { + + } + + public void setLocationRelativeTo(JFrame c, int x, int y) { + int dx = 0, dy = 0; + Point compLocation = c.getLocationOnScreen();//获取设计器Jframe坐标作为相对位置原点 + setLocation(dx + x, dy + y); + dx = compLocation.x; + dy = compLocation.y + c.getRootPane().getY();//加上底层容器的y坐标(其实就是设计器最上方图标栏的高度) + setLocation(dx + x, dy + y); + } +} \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java b/designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java index 1172a4b64..91c39f988 100644 --- a/designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java +++ b/designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java @@ -1,20 +1,8 @@ package com.fr.design.mainframe; -import java.awt.Color; -import java.awt.Component; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.dnd.DropTarget; -import java.awt.dnd.DropTargetDragEvent; -import java.awt.dnd.DropTargetDropEvent; -import java.awt.dnd.DropTargetEvent; -import java.util.ArrayList; - -import javax.swing.BorderFactory; -import javax.swing.JWindow; - import com.fr.base.BaseUtils; +import com.fr.design.DesignModelAdapter; +import com.fr.design.data.datapane.TableDataTreePane; import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.Painter; @@ -25,177 +13,192 @@ import com.fr.design.form.util.XCreatorConstants; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.icon.IconPathConstants; import com.fr.design.utils.ComponentUtils; +import com.fr.form.share.ShareLoader; +import com.fr.form.ui.SharableElementCaseEditor; import com.fr.form.ui.Widget; import com.fr.general.Inter; import com.fr.stable.Constants; +import javax.swing.*; +import java.awt.*; +import java.awt.dnd.DropTarget; +import java.awt.dnd.DropTargetDragEvent; +import java.awt.dnd.DropTargetDropEvent; +import java.awt.dnd.DropTargetEvent; + /** * 添加模式下鼠标事件处理器。 */ public class FormCreatorDropTarget extends DropTarget { - private FormDesigner designer; - /** - * 当前鼠标的设计组件 - */ - private Component current; - /** - * 当前添加模式对应的model - */ - private AddingModel addingModel; + private FormDesigner designer; + /** + * 当前鼠标的设计组件 + */ + private Component current; + /** + * 当前添加模式对应的model + */ + private AddingModel addingModel; private final static int GAP = 30; private JWindow promptWindow = new JWindow(); private UIButton promptButton = new UIButton("", BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); - public FormCreatorDropTarget(FormDesigner designer) { - this.designer = designer; - this.addingModel = designer.getAddingModel(); + public FormCreatorDropTarget(FormDesigner designer) { + this.designer = designer; + this.addingModel = designer.getAddingModel(); this.promptWindow.add(promptButton); - } + } + + private void adding(int x, int y) { + // 当前鼠标所在的组件 + XCreator hoveredComponent = designer.getComponentAt(x, y); - private void adding(int x, int y) { - // 当前鼠标所在的组件 - XCreator hoveredComponent = designer.getComponentAt(x, y); + // 获取该组件所在的焦点容器 + XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); - // 获取该组件所在的焦点容器 - XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); - - //cardTagLayout里用到 - container.stopAddingState(designer); + //cardTagLayout里用到 + container.stopAddingState(designer); - boolean success = false; + boolean success = false; - if (container != null) { - // 如果是容器,则调用其acceptComponent接受组件 - AddingModel model = designer.getAddingModel(); + if (container != null) { + // 如果是容器,则调用其acceptComponent接受组件 + AddingModel model = designer.getAddingModel(); - boolean chartEnter2Para =!addingModel.getXCreator().canEnterIntoParaPane() && container.acceptType(XWParameterLayout.class); + boolean chartEnter2Para = !addingModel.getXCreator().canEnterIntoParaPane() && container.acceptType(XWParameterLayout.class); boolean formSubmit2Adapt = !addingModel.getXCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class); - if (model != null && !chartEnter2Para && !formSubmit2Adapt) { - success = model.add2Container(designer, container, x, y); - } + if (model != null && !chartEnter2Para && !formSubmit2Adapt) { + success = model.add2Container(designer, container, x, y); + } cancelPromptWidgetForbidEnter(); - } + } - if (success) { - // 如果添加成功,则触发相应事件 + if (success) { + // 如果添加成功,则触发相应事件 XCreator xCreator = container.acceptType(XWParameterLayout.class) ? designer.getParaComponent() : designer.getRootComponent(); - //SetSelection时要确保选中的是最顶层的布局 - //tab布局添加的时候是初始化了XWCardLayout,实际上最顶层的布局是XWCardMainBorderLayout - XCreator addingXCreator = addingModel.getXCreator(); - Widget widget = (addingXCreator.getTopLayout() != null) ? (addingXCreator.getTopLayout().toData()) : addingXCreator.toData(); - designer.getSelectionModel().setSelectedCreators( - FormSelectionUtils.rebuildSelection(xCreator, new Widget[]{widget})); - designer.getEditListenerTable().fireCreatorModified(addingModel.getXCreator(), DesignerEvent.CREATOR_ADDED); - } else { - Toolkit.getDefaultToolkit().beep(); - } - - // 取消提示 - designer.setPainter(null); - // 切换添加状态到普通状态 - designer.stopAddingState(); - } - - private void entering(int x, int y) { - // 将要添加的组件图标移动到鼠标下的位置 - addingModel.moveTo(x, y); - designer.repaint(); - } - - private void exiting() { + //SetSelection时要确保选中的是最顶层的布局 + //tab布局添加的时候是初始化了XWCardLayout,实际上最顶层的布局是XWCardMainBorderLayout + XCreator addingXCreator = addingModel.getXCreator(); + if (addingXCreator.isShared()) { + SharableElementCaseEditor sharableEditor = ShareLoader.getLoader().getSharedElCaseEditorById(addingXCreator.getShareId()); + if (sharableEditor != null) { + TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()).addTableData(sharableEditor.getTableDataSource()); + } + } + Widget widget = (addingXCreator.getTopLayout() != null) ? (addingXCreator.getTopLayout().toData()) : addingXCreator.toData(); + designer.getSelectionModel().setSelectedCreators( + FormSelectionUtils.rebuildSelection(xCreator, new Widget[]{widget})); + designer.getEditListenerTable().fireCreatorModified(addingModel.getXCreator(), DesignerEvent.CREATOR_ADDED); + } else { + Toolkit.getDefaultToolkit().beep(); + } + + // 取消提示 + designer.setPainter(null); + // 切换添加状态到普通状态 + designer.stopAddingState(); + } + + private void entering(int x, int y) { + // 将要添加的组件图标移动到鼠标下的位置 + addingModel.moveTo(x, y); + designer.repaint(); + } + + private void exiting() { cancelPromptWidgetForbidEnter(); - // 隐藏组件图标 - addingModel.reset(); - designer.setPainter(null); - designer.repaint(); - } - - private void hovering(int x, int y) { - // 当前位置移植鼠标e所在的位置 - addingModel.moveTo(x, y); - // 获取e所在的焦点组件 - XCreator hotspot = designer.getComponentAt(x, y); - // 获取焦点组件所在的焦点容器 - XLayoutContainer container = XCreatorUtils.getHotspotContainer(hotspot); + // 隐藏组件图标 + addingModel.reset(); + designer.setPainter(null); + designer.repaint(); + } + + private void hovering(int x, int y) { + // 当前位置移植鼠标e所在的位置 + addingModel.moveTo(x, y); + // 获取e所在的焦点组件 + XCreator hotspot = designer.getComponentAt(x, y); + // 获取焦点组件所在的焦点容器 + XLayoutContainer container = XCreatorUtils.getHotspotContainer(hotspot); //提示组件是否可以拖入 promptUser(x, y, container); - if (container != null) { - HoverPainter painter = null; - - if (container != current || designer.getPainter() == null) { - // 如果焦点容器不是当前容器 - if (current != null) { - // 取消前一个焦点容器的提示渲染器 - designer.setPainter(null); - } - //获取painter的时候要考虑布局之间嵌套的问题 - XLayoutContainer xLayoutContainer = container.getTopLayout(); - if (xLayoutContainer != null && xLayoutContainer.getParent() != null - && ((XLayoutContainer)xLayoutContainer.getParent()).acceptType(XWAbsoluteLayout.class)){ - if(!xLayoutContainer.isEditable()){ - xLayoutContainer = (XLayoutContainer)xLayoutContainer.getParent(); - } - } - painter = AdapterBus.getContainerPainter(designer, - xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class) ? xLayoutContainer : container); - - // 为界面设计器设置提示渲染提示器 - designer.setPainter(painter); - - // 将当前容器更新为新的容器 - current = container; - } else { - // 获取当前设计界面的提示渲染器 - Painter p = designer.getPainter(); - if (p instanceof HoverPainter) { - painter = (HoverPainter) p; - } - } - - if (painter != null) { - // 为提示渲染器设置焦点位置、区域等渲染参数 - Rectangle rect = ComponentUtils.getRelativeBounds(container); - rect.x -= designer.getArea().getHorizontalValue(); - rect.y -= designer.getArea().getVerticalValue(); - painter.setRenderingBounds(rect); - painter.setHotspot(new Point(x, y)); - painter.setCreator(addingModel.getXCreator()); - } - } else { - // 如果鼠标不在任何组件上,则取消提示器 - designer.setPainter(null); - current = null; - } - designer.repaint(); - } - - private void promptUser(int x, int y, XLayoutContainer container){ - if (!addingModel.getXCreator().canEnterIntoParaPane() && container.acceptType(XWParameterLayout.class)){ + if (container != null) { + HoverPainter painter = null; + + if (container != current || designer.getPainter() == null) { + // 如果焦点容器不是当前容器 + if (current != null) { + // 取消前一个焦点容器的提示渲染器 + designer.setPainter(null); + } + //获取painter的时候要考虑布局之间嵌套的问题 + XLayoutContainer xLayoutContainer = container.getTopLayout(); + if (xLayoutContainer != null && xLayoutContainer.getParent() != null + && ((XLayoutContainer) xLayoutContainer.getParent()).acceptType(XWAbsoluteLayout.class)) { + if (!xLayoutContainer.isEditable()) { + xLayoutContainer = (XLayoutContainer) xLayoutContainer.getParent(); + } + } + painter = AdapterBus.getContainerPainter(designer, + xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class) ? xLayoutContainer : container); + + // 为界面设计器设置提示渲染提示器 + designer.setPainter(painter); + + // 将当前容器更新为新的容器 + current = container; + } else { + // 获取当前设计界面的提示渲染器 + Painter p = designer.getPainter(); + if (p instanceof HoverPainter) { + painter = (HoverPainter) p; + } + } + + if (painter != null) { + // 为提示渲染器设置焦点位置、区域等渲染参数 + Rectangle rect = ComponentUtils.getRelativeBounds(container); + rect.x -= designer.getArea().getHorizontalValue(); + rect.y -= designer.getArea().getVerticalValue(); + painter.setRenderingBounds(rect); + painter.setHotspot(new Point(x, y)); + painter.setCreator(addingModel.getXCreator()); + } + } else { + // 如果鼠标不在任何组件上,则取消提示器 + designer.setPainter(null); + current = null; + } + designer.repaint(); + } + + private void promptUser(int x, int y, XLayoutContainer container) { + if (!addingModel.getXCreator().canEnterIntoParaPane() && container.acceptType(XWParameterLayout.class)) { promptButton.setText(Inter.getLocText("FR-Designer_Forbid_Drag_into_Para_Pane")); - promptWidgetForbidEnter(x ,y ,container); - } else if (!addingModel.getXCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)){ + promptWidgetForbidEnter(x, y, container); + } else if (!addingModel.getXCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)) { promptButton.setText(Inter.getLocText("FR-Designer_Forbid_Drag_into_Adapt_Pane")); - promptWidgetForbidEnter(x ,y , container); + promptWidgetForbidEnter(x, y, container); } else { cancelPromptWidgetForbidEnter(); } } - private void promptWidgetForbidEnter(int x,int y, XLayoutContainer container){ + private void promptWidgetForbidEnter(int x, int y, XLayoutContainer container) { container.setBorder(BorderFactory.createLineBorder(Color.RED, Constants.LINE_MEDIUM)); - int screen_X = (int)designer.getArea().getLocationOnScreen().getX(); - int screen_Y = (int)designer.getArea().getLocationOnScreen().getY(); + int screen_X = (int) designer.getArea().getLocationOnScreen().getX(); + int screen_Y = (int) designer.getArea().getLocationOnScreen().getY(); this.promptWindow.setSize(promptWindow.getPreferredSize()); this.promptWindow.setPreferredSize(promptWindow.getPreferredSize()); - promptWindow.setLocation( screen_X + x + GAP ,screen_Y + y + GAP); + promptWindow.setLocation(screen_X + x + GAP, screen_Y + y + GAP); promptWindow.setVisible(true); } - private void cancelPromptWidgetForbidEnter(){ - if (designer.getParaComponent() != null){ + private void cancelPromptWidgetForbidEnter() { + if (designer.getParaComponent() != null) { designer.getParaComponent().setBorder(BorderFactory.createLineBorder(XCreatorConstants.LAYOUT_SEP_COLOR, Constants.LINE_THIN)); } designer.getRootComponent().setBorder(BorderFactory.createLineBorder(XCreatorConstants.LAYOUT_SEP_COLOR, Constants.LINE_THIN)); @@ -204,45 +207,50 @@ public class FormCreatorDropTarget extends DropTarget { /** * 拖拽进入 - * @param dtde 事件 + * + * @param dtde 事件 */ - public void dragEnter(DropTargetDragEvent dtde) { - Point loc = dtde.getLocation(); - this.entering(loc.x, loc.y); - } + public void dragEnter(DropTargetDragEvent dtde) { + Point loc = dtde.getLocation(); + this.entering(loc.x, loc.y); + } /** * 拖拽移动经过 - * @param dtde 事件 + * + * @param dtde 事件 */ - public void dragOver(DropTargetDragEvent dtde) { - Point loc = dtde.getLocation(); - hovering(loc.x, loc.y); - } + public void dragOver(DropTargetDragEvent dtde) { + Point loc = dtde.getLocation(); + hovering(loc.x, loc.y); + } /** * 拖拽事件 - * @param dtde 事件 + * + * @param dtde 事件 */ - public void dropActionChanged(DropTargetDragEvent dtde) { - } + public void dropActionChanged(DropTargetDragEvent dtde) { + } /** * 拖拽离开 - * @param dte 事件 + * + * @param dte 事件 */ - public void dragExit(DropTargetEvent dte) { - this.exiting(); - } + public void dragExit(DropTargetEvent dte) { + this.exiting(); + } /** * 拖拽释放 - * @param dtde 事件 + * + * @param dtde 事件 */ - public void drop(DropTargetDropEvent dtde) { - Point loc = dtde.getLocation(); - this.adding(loc.x, loc.y); + public void drop(DropTargetDropEvent dtde) { + Point loc = dtde.getLocation(); + this.adding(loc.x, loc.y); //针对在表单中拖入一个控件直接ctrl+s无反应 designer.requestFocus(); - } + } } \ No newline at end of file