diff --git a/.gitignore b/.gitignore index ec8c85a73..5cc51f5ed 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ designer_base/bin designer_chart/bin designer_form/bin *.iml +designer_base/src/com/fr/design/locale/.idea + + diff --git a/designer/designer.iml b/designer/designer.iml index 661dcd939..eca9d8fcd 100644 --- a/designer/designer.iml +++ b/designer/designer.iml @@ -1,13 +1,14 @@ - - + + - + - + + \ No newline at end of file diff --git a/designer/src/com/fr/aspectj/designer/TemplateProcessTracker.aj b/designer/src/com/fr/aspectj/designer/TemplateProcessTracker.aj new file mode 100644 index 000000000..032cd2342 --- /dev/null +++ b/designer/src/com/fr/aspectj/designer/TemplateProcessTracker.aj @@ -0,0 +1,73 @@ +package com.fr.aspectj.designer; + +/** + * 记录模板过程 + * Created by plough on 2017/3/3. + */ + +import com.fr.design.mainframe.templateinfo.TemplateInfoCollector; +import com.fr.grid.Grid; +import org.aspectj.lang.reflect.SourceLocation; + +import java.awt.event.ActionEvent; +import java.awt.event.MouseEvent; +import java.util.Date; + +public aspect TemplateProcessTracker { + //声明一个pointcut,匹配你需要的方法 + pointcut onMouseClicked(MouseEvent e) : + execution(* mouseClicked(MouseEvent)) && args(e); + pointcut onMousePressed(MouseEvent e) : + execution(* mousePressed(MouseEvent)) && args(e); + pointcut onMouseReleased(MouseEvent e) : + execution(* mouseReleased(MouseEvent)) && args(e); + pointcut onActionPerformed(ActionEvent e) : + execution(* actionPerformed(ActionEvent)) && args(e); + pointcut onSetValueAt(Object v, int r, int c) : + execution(* setValueAt(java.lang.Object, int, int)) && args(v, r, c); + pointcut onSetValue4EditingElement(Grid g, Object v) : + call(* setValue4EditingElement(java.lang.Object)) && target(g) && args(v); + + //before表示之前的意思 + //这整个表示在MouseAdapter的public void mouseXXX(MouseEvent)方法调用之前,你想要执行的代码 + before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) { + SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置 + +// String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; + TemplateInfoCollector.appendProcess(log); + } + //同上 + before(ActionEvent e) : onActionPerformed(e) { + SourceLocation sl = thisJoinPoint.getSourceLocation(); + // !within(LogHandlerBar) 没用, 手动过滤 + if (e.getSource().toString().contains("javax.swing.Timer")) { + return; + } + + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; + TemplateInfoCollector.appendProcess(log); + + } + //同上 + before(Object v, int r, int c) : onSetValueAt(v, r, c) { + SourceLocation sl = thisJoinPoint.getSourceLocation(); + + //String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c); + String log = ""; + TemplateInfoCollector.appendProcess(log); + + } + //同上 + before(Grid g, Object v) : onSetValue4EditingElement(g, v) { + SourceLocation sl = thisJoinPoint.getSourceLocation(); + +// String v = "test"; + //String log = String.format("%s:\n%s\nset value: %s at %s\n\n", new Date(), sl, v, g.getEditingCellElement()); + String log = ""; + TemplateInfoCollector.appendProcess(log); + } + + +} diff --git a/designer/src/com/fr/design/cell/editor/RichTextToolBar.java b/designer/src/com/fr/design/cell/editor/RichTextToolBar.java index 8d7708c9c..1bf8a2f56 100644 --- a/designer/src/com/fr/design/cell/editor/RichTextToolBar.java +++ b/designer/src/com/fr/design/cell/editor/RichTextToolBar.java @@ -134,7 +134,7 @@ public class RichTextToolBar extends BasicPane{ } private void bindListener(){ - FRFont defaultFont = RichTextPane.DEFAUL_FONT; + FRFont defaultFont = (this.textPane != null) ? FRFont.getInstance(this.textPane.getFont()) : RichTextPane.DEFAUL_FONT; fontNameComboBox.addItemListener(fontNameItemListener); fontNameComboBox.setSelectedItem(defaultFont.getFontName()); fontSizeComboBox.addItemListener(fontSizeItemListener); diff --git a/designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java b/designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java index d464d8f48..a760e0043 100644 --- a/designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java +++ b/designer/src/com/fr/design/mainframe/AuthorityEditToolBarPane.java @@ -1 +1,251 @@ -package com.fr.design.mainframe; import com.fr.design.constants.LayoutConstants; import com.fr.design.constants.UIConstants; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.roleAuthority.ReportAndFSManagePane; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.design.webattr.ToolBarButton; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import com.fr.stable.StringUtils; import javax.swing.*; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.List; /** * 用于在权限编辑状态对工具栏的元素进行权限编辑的面板 * Author : daisy * Date: 13-9-18 * Time: 下午2:15 */ public class AuthorityEditToolBarPane extends AuthorityPropertyPane { private static final int TITLE_HEIGHT = 19; private AuthorityEditPane authorityEditPane = null; private AuthorityToolBarPane authorityToolBarPane; private String[] selectedPathArray; public AuthorityEditToolBarPane(List buttonlists) { super(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); this.setLayout(new BorderLayout()); this.setBorder(null); UILabel authorityTitle = new UILabel(Inter.getLocText(new String[]{"DashBoard-Potence", "Edit"})) { @Override public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, TITLE_HEIGHT); } }; authorityTitle.setHorizontalAlignment(SwingConstants.CENTER); authorityTitle.setVerticalAlignment(SwingConstants.CENTER); JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); northPane.add(authorityTitle, BorderLayout.CENTER); northPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LINE_COLOR)); this.add(northPane, BorderLayout.NORTH); authorityEditPane = new AuthorityEditPane(buttonlists); this.add(authorityEditPane, BorderLayout.CENTER); } public void setAuthorityToolBarPane(AuthorityToolBarPane authorityToolBarPane) { this.authorityToolBarPane = authorityToolBarPane; } public void populate() { authorityToolBarPane.populateAuthority(); signelSelection(); authorityEditPane.populateDetials(); } private void signelSelection() { JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (jTemplate.isJWorkBook()) { //清参数面板 jTemplate.removeParameterPaneSelection(); //清报表主体 jTemplate.removeTemplateSelection(); } } private class AuthorityEditPane extends JPanel { private static final int TOP_GAP = 11; private static final int LEFT_GAP = 8; private static final int ALIGNMENT_GAP = -3; private UILabel type = null; private UILabel name = null; private JPanel checkPane = null; private List buttonlists; private UICheckBox buttonVisible = new UICheckBox(Inter.getLocText("Widget-Visible")); private ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { String selectedRole = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); initSelectedselectedPathArray(); if (ComparatorUtils.equals(selectedRole, Inter.getLocText("Role"))) { return; } if (selectedRole == null) { return; } if (selectedPathArray == null) { return; } for (int t = 0; t _buttonlists = AuthorityEditPane.this.buttonlists; for (int j = 0; j < _buttonlists.size(); j++) { if (_buttonlists.get(j).isSelected()) { //由引擎实现保存进模板报表 authorityToolBarPane.setAuthorityWebAttr(_buttonlists.get(j).getWidget(), checkbox.isSelected(), selectedPathArray[t]); } } } } }; private void initSelectedselectedPathArray () { TreePath[] selectionPaths = ReportAndFSManagePane.getInstance().getRoleTree().getCheckBoxTreeSelectionModel().getSelectionPaths(); if (selectionPaths.length == 1){ if(((ExpandMutableTreeNode)(selectionPaths[0].getLastPathComponent())).getChildCount() > 0){ ExpandMutableTreeNode node = (ExpandMutableTreeNode) ((ExpandMutableTreeNode)(selectionPaths[0].getLastPathComponent())).getLastChild(); selectedPathArray = new String[node.getChildCount()]; for (int i = 0 ; i < node.getChildCount(); i++) { ExpandMutableTreeNode n = (ExpandMutableTreeNode) node.getChildAt(i); String nodeName = n.getUserObject().toString(); selectedPathArray[i] = nodeName; } } else { selectedPathArray = pathToString(selectionPaths); } } else { selectedPathArray = pathToString(selectionPaths); } } protected String[] pathToString(TreePath[] path) { String roles = StringUtils.EMPTY; if(path == null || path.length == 0){ return null; } for(TreePath tempPath:path){ String temp = tempPath.toString(); boolean isTrue = temp.length() > 0 && temp.charAt(0) == '[' && temp.endsWith("]"); if (isTrue) { temp = temp.substring(1, temp.length() - 1); String[] selectedRoles = temp.split(","); String role = selectedRoles[2].trim(); if(roles.isEmpty()){ roles = role; }else{ roles = roles + "," + role; } } } String[] selectedRole = roles.split(","); return selectedRole; } public AuthorityEditPane(List buttonlists) { setLayout(new BorderLayout()); type = new UILabel(); name = new UILabel(); checkPane = new JPanel(); checkPane.setLayout(new BorderLayout()); this.add(layoutText(), BorderLayout.WEST); this.add(layoutPane(), BorderLayout.CENTER); this.setBorder(BorderFactory.createEmptyBorder(TOP_GAP, LEFT_GAP, 0, 0)); this.buttonlists = buttonlists; buttonVisible.addItemListener(itemListener); } private JPanel layoutText() { double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("Type") + ":", SwingConstants.RIGHT)}, new Component[]{new UILabel(Inter.getLocText("WF-Name") + ":", SwingConstants.RIGHT)}, new Component[]{new UILabel(Inter.getLocText("DashBoard-Potence") + ":", SwingConstants.RIGHT)}, }; double[] rowSize = {p, p, p}; double[] columnSize = {p}; int[][] rowCount = {{1}, {1}, {1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel layoutPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{type}, new Component[]{name}, new Component[]{checkPane}, }; double[] rowSize = {p, p, p}; double[] columnSize = {f}; int[][] rowCount = {{1}, {1}, {1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } /** * 更新权限编辑面板的具体内容:类型、名称、权限面板 */ public void populateDetials() { populateName(); populateType(); populateCheckPane(); checkVisibleCheckBoxes(); } private void checkVisibleCheckBoxes() { buttonVisible.removeItemListener(itemListener); String selected = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); if (selected == null) { buttonVisible.setSelected(true); } for (int i = 0; i < buttonlists.size(); i++) { if (buttonlists.get(i).isSelected()) { buttonVisible.setSelected(!buttonlists.get(i).isDoneAuthorityEdited(selected)); break; } } buttonVisible.addItemListener(itemListener); } public void populateType() { if (name.getText() == "") { type.setText(""); } else { type.setText(Inter.getLocText(new String[]{"ReportServerP-Toolbar", "Form-Button"})); } } public void populateName() { String names = ""; for (int i = 0; i < buttonlists.size(); i++) { if (buttonlists.get(i).isSelected()) { names += "," + buttonlists.get(i).getNameOption().optionName(); } } if (names != "") { names = names.substring(1); } name.setText(names); } public void populateCheckPane() { checkPane.removeAll(); if (name.getText() == "") { return; } double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("Form-Button"), SwingConstants.LEFT), buttonVisible}, }; double[] rowSize = {p, p}; double[] columnSize = {p, p, f}; int[][] rowCount = {{1, 1, 1}, {1, 1, 1}}; JPanel check = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); checkPane.add(check, BorderLayout.CENTER); checkPane.setBorder(BorderFactory.createEmptyBorder(ALIGNMENT_GAP, 0, 0, 0)); } } } \ No newline at end of file +package com.fr.design.mainframe; + +import com.fr.design.constants.LayoutConstants; +import com.fr.design.constants.UIConstants; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.roleAuthority.ReportAndFSManagePane; +import com.fr.design.roleAuthority.RolesAlreadyEditedPane; +import com.fr.design.webattr.ToolBarButton; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; + +import javax.swing.*; +import javax.swing.tree.TreePath; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.List; + +/** + * 用于在权限编辑状态对工具栏的元素进行权限编辑的面板 + * Author : daisy + * Date: 13-9-18 + * Time: 下午2:15 + */ +public class AuthorityEditToolBarPane extends AuthorityPropertyPane { + + private static final int TITLE_HEIGHT = 19; + private AuthorityEditPane authorityEditPane = null; + private AuthorityToolBarPane authorityToolBarPane; + private String[] selectedPathArray; + + public AuthorityEditToolBarPane(List buttonlists) { + super(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + this.setLayout(new BorderLayout()); + this.setBorder(null); + UILabel authorityTitle = new UILabel(Inter.getLocText(new String[]{"FR-Designer_Permissions", + "FR-Designer_Edit"})) { + @Override + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, TITLE_HEIGHT); + } + }; + authorityTitle.setHorizontalAlignment(SwingConstants.CENTER); + authorityTitle.setVerticalAlignment(SwingConstants.CENTER); + JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + northPane.add(authorityTitle, BorderLayout.CENTER); + northPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.LINE_COLOR)); + this.add(northPane, BorderLayout.NORTH); + authorityEditPane = new AuthorityEditPane(buttonlists); + this.add(authorityEditPane, BorderLayout.CENTER); + } + + public void setAuthorityToolBarPane(AuthorityToolBarPane authorityToolBarPane) { + this.authorityToolBarPane = authorityToolBarPane; + } + + + public void populate() { + authorityToolBarPane.populateAuthority(); + signelSelection(); + authorityEditPane.populateDetials(); + } + + + private void signelSelection() { + JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (jTemplate.isJWorkBook()) { + //清参数面板 + jTemplate.removeParameterPaneSelection(); + //清报表主体 + jTemplate.removeTemplateSelection(); + } + } + + + private class AuthorityEditPane extends JPanel { + private static final int TOP_GAP = 11; + private static final int LEFT_GAP = 8; + private static final int ALIGNMENT_GAP = -3; + private UILabel type = null; + private UILabel name = null; + private JPanel checkPane = null; + private List buttonlists; + private UICheckBox buttonVisible = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); + private ItemListener itemListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + String selectedRole = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + initSelectedPathArray(); + if (ComparatorUtils.equals(selectedRole, Inter.getLocText("FR-Designer_Role")) || selectedRole == + null || selectedPathArray == null) { + return; + } + for (int t = 0; t < selectedPathArray.length; t++) { + for (int i = 0; i < buttonlists.size(); i++) { + if (buttonlists.get(i).isSelected()) { + buttonlists.get(i).changeAuthorityState(selectedPathArray[t], buttonVisible.isSelected()); + authorityToolBarPane.repaint(); + } + } + HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().fireTargetModified(); + RolesAlreadyEditedPane.getInstance().refreshDockingView(); + UICheckBox checkbox = (UICheckBox) e.getSource(); + List btns = AuthorityEditPane.this.buttonlists; + for (int j = 0; j < btns.size(); j++) { + if (btns.get(j).isSelected()) { + //由引擎实现保存进模板报表 + authorityToolBarPane.setAuthorityWebAttr(btns.get(j).getWidget(), checkbox.isSelected(), selectedPathArray[t]); + } + } + } + } + }; + + /** + * @see ElementCasePaneAuthorityEditPane initSelectedPathArray() + */ + private void initSelectedPathArray() { + TreePath[] selectionPaths = ReportAndFSManagePane.getInstance().getRoleTree().getCheckBoxTreeSelectionModel().getSelectionPaths(); + if (selectionPaths.length == 1) { + if (((ExpandMutableTreeNode) (selectionPaths[0].getLastPathComponent())).getChildCount() > 0) { + ExpandMutableTreeNode node = (ExpandMutableTreeNode) ((ExpandMutableTreeNode) (selectionPaths[0].getLastPathComponent())).getLastChild(); + selectedPathArray = new String[node.getChildCount()]; + for (int i = 0; i < node.getChildCount(); i++) { + ExpandMutableTreeNode n = (ExpandMutableTreeNode) node.getChildAt(i); + String nodeName = n.getUserObject().toString(); + selectedPathArray[i] = nodeName; + } + } else { + selectedPathArray = ElementCasePaneAuthorityEditPane.pathToString(selectionPaths); + } + } else { + selectedPathArray = ElementCasePaneAuthorityEditPane.pathToString(selectionPaths); + } + + } + + public AuthorityEditPane(List buttonlists) { + setLayout(new BorderLayout()); + type = new UILabel(); + name = new UILabel(); + checkPane = new JPanel(); + checkPane.setLayout(new BorderLayout()); + this.add(layoutText(), BorderLayout.WEST); + this.add(layoutPane(), BorderLayout.CENTER); + this.setBorder(BorderFactory.createEmptyBorder(TOP_GAP, LEFT_GAP, 0, 0)); + this.buttonlists = buttonlists; + buttonVisible.addItemListener(itemListener); + } + + private JPanel layoutText() { + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Type") + ":", SwingConstants.RIGHT)}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_WF_Name") + ":", SwingConstants.RIGHT)}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Permissions") + ":", SwingConstants + .RIGHT)}, + }; + double[] rowSize = {p, p, p}; + double[] columnSize = {p}; + int[][] rowCount = {{1}, {1}, {1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + + private JPanel layoutPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{type}, + new Component[]{name}, + new Component[]{checkPane}, + }; + double[] rowSize = {p, p, p}; + double[] columnSize = {f}; + int[][] rowCount = {{1}, {1}, {1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + /** + * 更新权限编辑面板的具体内容:类型、名称、权限面板 + */ + public void populateDetials() { + populateName(); + populateType(); + populateCheckPane(); + checkVisibleCheckBoxes(); + } + + private void checkVisibleCheckBoxes() { + buttonVisible.removeItemListener(itemListener); + String selected = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (selected == null) { + buttonVisible.setSelected(true); + } + for (int i = 0; i < buttonlists.size(); i++) { + if (buttonlists.get(i).isSelected()) { + buttonVisible.setSelected(!buttonlists.get(i).isDoneAuthorityEdited(selected)); + break; + } + } + buttonVisible.addItemListener(itemListener); + } + + + public void populateType() { + if (name.getText() == "") { + type.setText(""); + } else { + type.setText(Inter.getLocText(new String[]{"ReportServerP-Toolbar", "FR-Designer_Form_Button"})); + } + } + + public void populateName() { + String names = ""; + for (int i = 0; i < buttonlists.size(); i++) { + if (buttonlists.get(i).isSelected()) { + names += "," + buttonlists.get(i).getNameOption().optionName(); + } + } + if (names != "") { + names = names.substring(1); + } + name.setText(names); + } + + public void populateCheckPane() { + checkPane.removeAll(); + if (name.getText() == "") { + return; + } + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Form_Button"), SwingConstants.LEFT), + buttonVisible}, + }; + double[] rowSize = {p, p}; + double[] columnSize = {p, p, f}; + int[][] rowCount = {{1, 1, 1}, {1, 1, 1}}; + JPanel check = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + checkPane.add(check, BorderLayout.CENTER); + checkPane.setBorder(BorderFactory.createEmptyBorder(ALIGNMENT_GAP, 0, 0, 0)); + } + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/CellElementPropertyPane.java b/designer/src/com/fr/design/mainframe/CellElementPropertyPane.java index fa602c8bd..69a68f451 100644 --- a/designer/src/com/fr/design/mainframe/CellElementPropertyPane.java +++ b/designer/src/com/fr/design/mainframe/CellElementPropertyPane.java @@ -102,12 +102,25 @@ public class CellElementPropertyPane extends DockingView { return element; } + public void removeAll() { + this.remove(titlePane); + this.remove(cellElementEditPane); + } + + public void reInit(ElementCasePane ePane) { + if (titlePane.getParent() == null) { // 如果处于隐藏状态,则让其显示 + this.add(titlePane, BorderLayout.NORTH); + this.add(cellElementEditPane, BorderLayout.CENTER); + } + cellElementEditPane.populate(ePane); + } + public void populate(ElementCasePane ePane) { TemplateElementCase elementCase = ePane.getEditingElementCase(); if (elementCase == null) { return; } - cellElementEditPane.populate(ePane); + ePane.getSelection().populatePropertyPane(ePane); } @Override diff --git a/designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java b/designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java index 3f9a717dd..fe6c616ed 100644 --- a/designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java +++ b/designer/src/com/fr/design/mainframe/ElementCasePaneAuthorityEditPane.java @@ -1 +1,829 @@ -package com.fr.design.mainframe; import com.fr.design.constants.LayoutConstants; import com.fr.design.editor.ValueEditorPane; import com.fr.design.editor.ValueEditorPaneFactory; import com.fr.design.event.UIObserverListener; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.toolbar.AuthorityEditToolBarComponent; import com.fr.design.roleAuthority.ReportAndFSManagePane; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.form.ui.Widget; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.FloatSelection; import com.fr.grid.selection.Selection; import com.fr.js.NameJavaScriptGroup; import com.fr.report.cell.AbstractCellElement; import com.fr.report.cell.DefaultTemplateCellElement; import com.fr.report.cell.FloatElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.elementcase.TemplateElementCase; import com.fr.report.worksheet.WorkSheet; import com.fr.stable.ColumnRow; import com.fr.stable.StringUtils; import javax.swing.*; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; /** * Author : daisy * Date: 13-9-4 * Time: 下午4:01 */ public class ElementCasePaneAuthorityEditPane extends AuthorityEditPane { private static final int WIDGET_VISIBLE = 0; private static final int WIDGET_USABLE = 1; private static final int CELL = 2; private static final int HYPER_LINK = 3; private static final int FLOAT_SELECTION = 3; private static final int NEW_VALUE = 4; //新值下面的编辑器的宽度 private static final int NEW_PANE_WIDTH = 120; private UICheckBox floatElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); private UICheckBox cellElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); private UICheckBox widgetVisible = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); private UICheckBox widgetAvailable = new UICheckBox(Inter.getLocText("FR-Designer_Enabled")); private UICheckBox gridColumnRowVisible = new UICheckBox(Inter.getLocText("FR-Designer_Hide")); private UICheckBox newValue = new UICheckBox(Inter.getLocText("FR-Designer_New_Value")); private ValueEditorPane valueEditor = ValueEditorPaneFactory.createBasicValueEditorPane(NEW_PANE_WIDTH); private UICheckBox[] hyperlinkCheckBoxes = null; private ElementCasePane elementCasePane = null; private int selectionType = CellSelection.NORMAL; private CellSelection cellSelection; private FloatSelection floatSelection; private boolean isAllHasWidget; private boolean isAllHasHyperlink; private String[] selectedPathArray; private UIObserverListener observerListener = new UIObserverListener() { @Override public void doChange() { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(NEW_VALUE)) { elementCasePane.fireTargetModified(); } } }; private ItemListener newValuelistener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(NEW_VALUE)) { valueEditor.setEnabled(newValue.isSelected()); doAfterAuthority(); } } }; private ItemListener columnRowAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null) { return; } boolean isDone = false; if (selectionType == CellSelection.CHOOSE_COLUMN) { isDone = setAuthorityColumn(); } else { isDone = setAuthorityRow(); } if (isDone) { doAfterAuthority(); } } }; private ItemListener floatElementAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || floatSelection == null) { return; } if (setLFloatAuthorityStyle()) { doAfterAuthority(); } } }; private ItemListener cellRolesAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(CELL)) { doAfterAuthority(); } } }; private ItemListener widgetVisibleRoleAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(WIDGET_VISIBLE)) { doAfterAuthority(); } } }; private ItemListener widgetUsableAuthorityListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (elementCasePane == null || cellSelection == null) { return; } if (setAuthorityStyle(WIDGET_USABLE)) { doAfterAuthority(); } } }; public ElementCasePaneAuthorityEditPane(ElementCasePane elementCasePane) { super(elementCasePane); this.elementCasePane = elementCasePane; initCheckBoxesState(); initListener(); } private void doAfterAuthority() { elementCasePane.repaint(); elementCasePane.fireTargetModified(); RolesAlreadyEditedPane.getInstance().refreshDockingView(); RolesAlreadyEditedPane.getInstance().setReportAndFSSelectedRoles(); RolesAlreadyEditedPane.getInstance().repaint(); checkCheckBoxes(); } private boolean setAuthorityColumn() { initSelectedselectedPathArray(); String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { return false; } if (selectedRoles == null) { return false; } if (selectedPathArray == null) { return false; } final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); boolean isVisible = !gridColumnRowVisible.isSelected(); for (int t = 0; t= 0; j--) { for (int i = cellRectangle.width - 1; i >= 0; i--) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; TemplateCellElement editCellElement = elementCase.getTemplateCellElement(column, row); if (editCellElement == null) { editCellElement = new DefaultTemplateCellElement(column, row); elementCase.addCellElement(editCellElement); } else { // 对于合并的格子,我们不多次计算的权限. if (editCellElement.getColumn() != column || editCellElement.getRow() != row) { continue; } } if (type == CELL) { editCellElement.changeAuthorityState(selectedPathArray[t], cellElementVisibleCheckBoxes.isSelected()); } else if (type == NEW_VALUE) { editCellElement.changeNewValueAuthorityState(selectedPathArray[t], newValue.isSelected(), valueEditor.update()); } else if (type == WIDGET_VISIBLE) { Widget widget = editCellElement.getWidget(); widget.changeVisibleAuthorityState(selectedPathArray[t], widgetVisible.isSelected()); } else { Widget widget = editCellElement.getWidget(); widget.changeUsableAuthorityState(selectedPathArray[t], widgetAvailable.isSelected()); } } } } } return true; } private void initSelectedselectedPathArray () { TreePath[] selectionPaths = ReportAndFSManagePane.getInstance().getRoleTree().getCheckBoxTreeSelectionModel().getSelectionPaths(); if (selectionPaths.length == 1){ if(((ExpandMutableTreeNode)(selectionPaths[0].getLastPathComponent())).getChildCount() > 0){ ExpandMutableTreeNode node = (ExpandMutableTreeNode) ((ExpandMutableTreeNode)(selectionPaths[0].getLastPathComponent())).getLastChild(); System.out.printf(node.getUserObject().toString()); selectedPathArray = new String[node.getChildCount()]; for (int i = 0; i < node.getChildCount(); i++) { ExpandMutableTreeNode n = (ExpandMutableTreeNode) node.getChildAt(i); String nodeName = n.getUserObject().toString(); selectedPathArray[i] = nodeName; } } else { selectedPathArray = pathToString(selectionPaths); } } else { selectedPathArray = pathToString(selectionPaths); } } protected String[] pathToString(TreePath[] path) { String roles = StringUtils.EMPTY; if(path == null || path.length == 0){ return null; } for(TreePath tempPath:path){ String temp = tempPath.toString(); boolean isTrue = temp.length() > 0 && temp.charAt(0) == '[' && temp.endsWith("]"); if (isTrue) { temp = temp.substring(1, temp.length() - 1); String[] selectedRoles = temp.split(","); String role = selectedRoles[2].trim(); if(roles.isEmpty()){ roles = role; }else{ roles = roles + "," + role; } } } String[] selectedRole = roles.split(","); return selectedRole; } /** * 选中的单元格的乐见状态以第一个单元格为齐 */ public void initCheckBoxesState() { final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); if (cellSelection == null) { cellElementVisibleCheckBoxes.setSelected(true); } else { Rectangle cellRectangle = cellSelection.getCellRectangle(0); DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(cellRectangle.x, cellRectangle.y); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(cellRectangle.x, cellRectangle.y); } boolean firstCellDoneaAuthority = cellElement.isDoneAuthority( ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName()); cellElementVisibleCheckBoxes.setSelected(!firstCellDoneaAuthority); } widgetAvailable.setEnabled(cellElementVisibleCheckBoxes.isSelected()); widgetVisible.setEnabled(cellElementVisibleCheckBoxes.isSelected()); } private void initListener() { cellElementVisibleCheckBoxes.addItemListener(cellRolesAuthorityListener); widgetVisible.addItemListener(widgetVisibleRoleAuthorityListener); widgetAvailable.addItemListener(widgetUsableAuthorityListener); floatElementVisibleCheckBoxes.addItemListener(floatElementAuthorityListener); gridColumnRowVisible.addItemListener(columnRowAuthorityListener); newValue.addItemListener(newValuelistener); valueEditor.registerChangeListener(observerListener); } private void removeListener() { cellElementVisibleCheckBoxes.removeItemListener(cellRolesAuthorityListener); widgetVisible.removeItemListener(widgetVisibleRoleAuthorityListener); widgetAvailable.removeItemListener(widgetUsableAuthorityListener); floatElementVisibleCheckBoxes.removeItemListener(floatElementAuthorityListener); gridColumnRowVisible.removeItemListener(columnRowAuthorityListener); newValue.removeItemListener(newValuelistener); valueEditor.registerChangeListener(null); } private void addHyperlinkListener() { cellElementVisibleCheckBoxes.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (hyperlinkCheckBoxes != null) { for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { hyperlinkCheckBoxes[i].setEnabled(cellElementVisibleCheckBoxes.isSelected()); if (!cellElementVisibleCheckBoxes.isSelected()) { hyperlinkCheckBoxes[i].setSelected(false); } } } } }); for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { hyperlinkCheckBoxes[i].addItemListener(cellRolesAuthorityListener); } } /** * 更新适合的类型 */ public void populateType() { if (selectionType == CellSelection.NORMAL) { type.setText(Inter.getLocText("FR-Designer_Cell")); } else if (selectionType == CellSelection.CHOOSE_ROW) { type.setText(Inter.getLocText("FR-Designer_Row")); } else if (selectionType == CellSelection.CHOOSE_COLUMN) { type.setText(Inter.getLocText("FR-Designer_Column")); } else { type.setText(Inter.getLocText("M_Insert-Float")); } } /** * 名字 */ public void populateName() { if (selectionType == CellSelection.NORMAL) { name.setText(getCellSelectionName()); } else if (selectionType == CellSelection.CHOOSE_ROW || selectionType == CellSelection.CHOOSE_COLUMN) { name.setText(getCellColumnRowName()); } else { name.setText(getFloatSelectionName()); } } private String getCellSelectionName() { String nameText = ""; int count = cellSelection.getCellRectangleCount(); for (int rect = 0; rect < count; rect++) { nameText += ","; Rectangle cellRectangle = cellSelection.getCellRectangle(rect); ColumnRow beginCR = ColumnRow.valueOf(cellRectangle.x, cellRectangle.y); nameText += beginCR.toString(); if (cellRectangle.width * cellRectangle.height != 1) { ColumnRow endCR = ColumnRow.valueOf(cellRectangle.width + cellRectangle.x - 1, cellRectangle.height + cellRectangle.y - 1); nameText += ":" + endCR.toString(); } } return nameText.substring(1); } private String getCellColumnRowName() { int count = cellSelection.getCellRectangleCount(); String nameText = ""; ColumnRow cr = ColumnRow.valueOf(cellSelection.getColumn(), cellSelection.getRow()); if (cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN && count == 1) { if (cellSelection.getColumnSpan() == 1) { nameText = cr.toString().substring(0, 1); } else { ColumnRow endCr = ColumnRow.valueOf(cellSelection.getColumn() + cellSelection.getColumnSpan() - 1, cellSelection.getRow() + cellSelection.getRowSpan() - 1); nameText = cr.toString().substring(0, 1) + "-" + endCr.toString().substring(0, 1); } } else if (cellSelection.getSelectedType() == CellSelection.CHOOSE_ROW && count == 1) { if (cellSelection.getRowSpan() == 1) { nameText = cr.toString().substring(1); } else { ColumnRow endCr = ColumnRow.valueOf(cellSelection.getColumn() + cellSelection.getColumnSpan() - 1, cellSelection.getRow() + cellSelection.getRowSpan() - 1); nameText = cr.toString().substring(1) + "-" + endCr.toString().substring(1); } } return nameText; } private String getFloatSelectionName() { return floatSelection.getSelectedFloatName(); } private void mutilRect(CellSelection cellSelection) { isAllHasWidget = true; isAllHasHyperlink = true; int count = cellSelection.getCellRectangleCount(); final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); for (int rect = 0; rect < count; rect++) { Rectangle cellRectangle = cellSelection.getCellRectangle(rect); for (int j = 0; j < cellRectangle.height; j++) { for (int i = 0; i < cellRectangle.width; i++) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(column, row); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); } if (cellElement.getCellWidgetAttr() == null) { isAllHasWidget = false; } if (cellElement.getNameHyperlinkGroup() == null) { isAllHasHyperlink = false; } } } } } /** * 更新适合的pane * * @return 返回Pane */ public JPanel populateCheckPane() { checkPane.removeAll(); if (selectionType == CellSelection.NORMAL) { populateCellSelectionCheckPane(checkPane); } else if (selectionType == CellSelection.CHOOSE_COLUMN || selectionType == CellSelection.CHOOSE_ROW) { populateColumnRowCheckPane(checkPane); } else if (selectionType == FLOAT_SELECTION) { populateFloatSelectionCheckPane(checkPane); } checkPane.setBorder(BorderFactory.createEmptyBorder(ALIGNMENT_GAP, 0, 0, 0)); return checkPane; } private void populateColumnRowCheckPane(JPanel checkPane) { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{gridColumnRowVisible} }; double[] rowSize = {p}; double[] columnSize = {f}; int[][] rowCount = {{1}}; checkPane.add( TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM) , BorderLayout.WEST); } private void populateFloatSelectionCheckPane(JPanel checkPane) { checkPane.add(populateFloatElementCheckPane(), BorderLayout.WEST); } private void populateCellSelectionCheckPane(JPanel checkPane) { if (elementCasePane.isSelectedOneCell()) { //只选中了一个单元格 final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(cellSelection.getColumn(), cellSelection.getRow()); if (cellElement == null) { cellElement = new DefaultTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); } //单元格带控件 if (cellElement.getCellWidgetAttr() != null) { checkPane.add(populateWidgetCheckPane(), BorderLayout.WEST); } else { checkPane.add(populatCellCheckPane(), BorderLayout.WEST); } } else { //批量选中单元格 mutilRect(cellSelection); if (!isAllHasWidget && !isAllHasHyperlink) { checkPane.add(populateMutilCellCheckPane(), BorderLayout.WEST); } else if (isAllHasWidget) { checkPane.add(populateMutilWidgetCheckPane(), BorderLayout.WEST); } } } /** * 对单元格区域进行操作时的权限编辑页面 ,对应的角色的populate */ public void populateDetials() { //做模式标记,此时鼠标焦点是在报表主体,为下一次退出权限编辑时做准备 HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().setAuthorityMode(false); TemplateElementCase templateElementCase = elementCasePane.getEditingElementCase(); if (templateElementCase instanceof WorkSheet) { ((WorkSheet) templateElementCase).setPaintSelection(true); } signelSelection(); Selection selection = elementCasePane.getSelection(); if (selection instanceof CellSelection) { selectionType = CellSelection.NORMAL; this.cellSelection = ((CellSelection) selection).clone(); this.floatSelection = null; judgeChooseCR(); } else if (selection instanceof FloatSelection) { selectionType = FLOAT_SELECTION; cellSelection = null; floatSelection = new FloatSelection(((FloatSelection) selection).getSelectedFloatName()); } populateType(); populateName(); populateCheckPane(); checkCheckBoxes(); } //判断是否选择的行列 private void judgeChooseCR() { if (cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN && cellSelection.getCellRectangleCount() == 1) { selectionType = CellSelection.CHOOSE_COLUMN; } if (cellSelection.getSelectedType() == CellSelection.CHOOSE_ROW && cellSelection.getCellRectangleCount() == 1) { selectionType = CellSelection.CHOOSE_ROW; } } //实现单选 private void signelSelection() { JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (jTemplate.isJWorkBook()) { //清工具栏 JComponent component = DesignerContext.getDesignerFrame().getToolbarComponent(); if (component instanceof AuthorityEditToolBarComponent) { ((AuthorityEditToolBarComponent) component).removeSelection(); } //清参数面板 jTemplate.removeParameterPaneSelection(); } } private JPanel populateFloatElementCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("M_Insert-Float"), SwingConstants.LEFT), floatElementVisibleCheckBoxes} }; double[] rowSize = {p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateWidgetCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}, new Component[]{null, newValue}, new Component[]{null, valueEditor}, new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget"), SwingConstants.LEFT), widgetVisible}, new Component[]{null, widgetAvailable} }; double[] rowSize = {p, p, p, p, p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateMutilWidgetCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}, new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget"), SwingConstants.LEFT), widgetVisible}, new Component[]{null, widgetAvailable} }; double[] rowSize = {p, p, p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateMutilCellCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{cellElementVisibleCheckBoxes}, }; double[] rowSize = {p}; double[] columnSize = {f}; int[][] rowCount = {{1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populatCellCheckPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[][]{ new Component[]{cellElementVisibleCheckBoxes}, new Component[]{newValue}, new Component[]{valueEditor} }; double[] rowSize = {p, p, p}; double[] columnSize = {f}; int[][] rowCount = {{1}, {1}, {1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } public TemplateCellElement getFirstCell() { final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); Rectangle cellRectangle = cellSelection.getCellRectangle(0); // 从最后循环起以保证最后一个修改标准单元格(originalStyle)。 TemplateCellElement firstCell = null; for (int j = cellRectangle.height - 1; j >= 0; j--) { for (int i = cellRectangle.width - 1; i >= 0; i--) { int column = i + cellRectangle.x; int row = j + cellRectangle.y; TemplateCellElement editCellElement = elementCase.getTemplateCellElement(column, row); if (editCellElement != null) { // 对于合并的格子,我们不多次计算的权限. if (editCellElement.getColumn() != column || editCellElement.getRow() != row) { continue; } firstCell = editCellElement; } } } return firstCell; } private void checkCheckBoxes() { String selected = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); removeListener(); if (selectionType == CellSelection.NORMAL) { checkCellSelectionCkeckboxes(selected); } else if (selectionType == CellSelection.CHOOSE_COLUMN || selectionType == CellSelection.CHOOSE_ROW) { checkColumnRowCheckBoxes(selected); } else if (selectionType == FLOAT_SELECTION) { checkFloatSelectionCkeckboxes(selected); } initListener(); } private void checkCellSelectionCkeckboxes(String selected) { TemplateCellElement firstCell = getFirstCell(); if (firstCell == null) { resetCellElementCheckBoxes(); return; } cellElementVisibleCheckBoxes.setSelected(!firstCell.isDoneAuthority(selected)); newValue.setEnabled(!firstCell.isDoneAuthority(selected)); if (!firstCell.isDoneAuthority(selected)) { newValue.setSelected(firstCell.isDoneNewValueAuthority(selected)); if (newValue.isSelected()) { valueEditor.setEnabled(true); valueEditor.populate(firstCell.getCellPrivilegeControl().getNewValueMap().get(selected)); } else { valueEditor.setEnabled(false); } } else { newValue.setSelected(false); valueEditor.setEnabled(false); } populateWidgetButton(firstCell.getWidget(), selected, firstCell); } private void populateWidgetButton(Widget widget, String selected, TemplateCellElement firstCell){ if(widget == null){ return; } if(widget.isVisible()){ widgetVisible.setSelected(!widget.isDoneVisibleAuthority(selected)); widgetVisible.setEnabled(!firstCell.isDoneAuthority(selected)); }else{ widgetVisible.setSelected(widget.isVisibleAuthority(selected)); } if(widget.isEnabled()){ widgetAvailable.setSelected(!widget.isDoneUsableAuthority(selected)); widgetAvailable.setEnabled(!widget.isDoneVisibleAuthority(selected)); }else{ widgetAvailable.setSelected(widget.isUsableAuthority(selected)); } } private void resetCellElementCheckBoxes() { cellElementVisibleCheckBoxes.setSelected(true); widgetVisible.setSelected(true); widgetVisible.setEnabled(true); widgetAvailable.setSelected(true); widgetAvailable.setEnabled(true); newValue.setSelected(false); valueEditor.setEnabled(false); } private void checkColumnRowCheckBoxes(String selected) { if (cellSelection == null) { gridColumnRowVisible.setSelected(false); return; } TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); boolean isInside = selectionType == CellSelection.CHOOSE_COLUMN ? elementCase.getColumnPrivilegeControl(cellSelection.getColumn()).checkInvisible(selected) : elementCase.getRowPrivilegeControl(cellSelection.getRow()).checkInvisible(selected); gridColumnRowVisible.setSelected(isInside); } private void checkFloatSelectionCkeckboxes(String selected) { String name = floatSelection.getSelectedFloatName(); TemplateElementCase ec = elementCasePane.getEditingElementCase(); FloatElement fe = ec.getFloatElement(name); floatElementVisibleCheckBoxes.setSelected(!fe.isDoneAuthority(selected)); } private JPanel populateHyperlinkCheckPane(AbstractCellElement cellElement) { NameJavaScriptGroup linkGroup = cellElement.getNameHyperlinkGroup(); //超链接的个数+单元格可见的操作 hyperlinkCheckBoxes = new UICheckBox[linkGroup.size()]; double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[hyperlinkCheckBoxes.length + 1][]; if (linkGroup.size() == 1) { components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}; components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; } else { components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(linkGroup.getNameHyperlink(0).getName() + Inter.getLocText("FR-Designer_Visible"))}; for (int i = 1; i < hyperlinkCheckBoxes.length; i++) { components[i + 1] = new Component[]{null, hyperlinkCheckBoxes[i] = new UICheckBox(linkGroup.getNameHyperlink(i).getName() + Inter.getLocText("FR-Designer_Visible"))}; } } for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { hyperlinkCheckBoxes[i].setEnabled(cellElementVisibleCheckBoxes.isSelected()); } addHyperlinkListener(); double[] rowSize = new double[hyperlinkCheckBoxes.length + 1]; int[][] rowCount = new int[hyperlinkCheckBoxes.length + 1][]; for (int i = 0; i < hyperlinkCheckBoxes.length + 1; i++) { rowSize[i] = p; rowCount[i] = new int[]{1, 1}; } double[] columnSize = {p, f}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } private JPanel populateMutilHyperlinkCheckPane() { //超链接的个数+单元格可见的操作 hyperlinkCheckBoxes = new UICheckBox[1]; double f = TableLayout.FILL; double p = TableLayout.PREFERRED; Component[][] components = new Component[2][]; components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}; components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; hyperlinkCheckBoxes[0].setEnabled(cellElementVisibleCheckBoxes.isSelected()); addHyperlinkListener(); double[] rowSize = {p, p}; double[] columnSize = {p, f}; int[][] rowCount = {{1, 1}, {1, 1}}; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); } } \ No newline at end of file +package com.fr.design.mainframe; + +import com.fr.design.constants.LayoutConstants; +import com.fr.design.editor.ValueEditorPane; +import com.fr.design.editor.ValueEditorPaneFactory; +import com.fr.design.event.UIObserverListener; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.toolbar.AuthorityEditToolBarComponent; +import com.fr.design.roleAuthority.ReportAndFSManagePane; +import com.fr.design.roleAuthority.RolesAlreadyEditedPane; +import com.fr.form.ui.Widget; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.FloatSelection; +import com.fr.grid.selection.Selection; +import com.fr.js.NameJavaScriptGroup; +import com.fr.report.cell.AbstractCellElement; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.FloatElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.report.worksheet.WorkSheet; +import com.fr.stable.ColumnRow; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import javax.swing.tree.TreePath; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; + +/** + * Author : daisy + * Date: 13-9-4 + * Time: 下午4:01 + */ +public class ElementCasePaneAuthorityEditPane extends AuthorityEditPane { + private static final int WIDGET_VISIBLE = 0; + private static final int WIDGET_USABLE = 1; + private static final int CELL = 2; + private static final int HYPER_LINK = 3; + private static final int FLOAT_SELECTION = 3; + private static final int NEW_VALUE = 4; + //新值下面的编辑器的宽度 + private static final int NEW_PANE_WIDTH = 120; + + + private UICheckBox floatElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); + private UICheckBox cellElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); + private UICheckBox widgetVisible = new UICheckBox(Inter.getLocText("FR-Designer_Visible")); + private UICheckBox widgetAvailable = new UICheckBox(Inter.getLocText("FR-Designer_Enabled")); + private UICheckBox gridColumnRowVisible = new UICheckBox(Inter.getLocText("FR-Designer_Hide")); + private UICheckBox newValue = new UICheckBox(Inter.getLocText("FR-Designer_New_Value")); + private ValueEditorPane valueEditor = ValueEditorPaneFactory.createBasicValueEditorPane(NEW_PANE_WIDTH); + private UICheckBox[] hyperlinkCheckBoxes = null; + private ElementCasePane elementCasePane = null; + private int selectionType = CellSelection.NORMAL; + private CellSelection cellSelection; + private FloatSelection floatSelection; + private boolean isAllHasWidget; + private boolean isAllHasHyperlink; + private String[] selectedPathArray; + private UIObserverListener observerListener = new UIObserverListener() { + @Override + public void doChange() { + if (elementCasePane == null || cellSelection == null) { + return; + } + if (setAuthorityStyle(NEW_VALUE)) { + elementCasePane.fireTargetModified(); + } + + } + }; + private ItemListener newValuelistener = new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null || cellSelection == null) { + return; + } + if (setAuthorityStyle(NEW_VALUE)) { + valueEditor.setEnabled(newValue.isSelected()); + doAfterAuthority(); + } + } + }; + private ItemListener columnRowAuthorityListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null) { + return; + } + boolean isDone = false; + if (selectionType == CellSelection.CHOOSE_COLUMN) { + isDone = setAuthorityColumn(); + } else { + isDone = setAuthorityRow(); + } + if (isDone) { + doAfterAuthority(); + } + } + }; + private ItemListener floatElementAuthorityListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null || floatSelection == null) { + return; + } + if (setLFloatAuthorityStyle()) { + doAfterAuthority(); + } + } + }; + private ItemListener cellRolesAuthorityListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null || cellSelection == null) { + return; + } + if (setAuthorityStyle(CELL)) { + doAfterAuthority(); + } + } + }; + private ItemListener widgetVisibleRoleAuthorityListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null || cellSelection == null) { + return; + } + if (setAuthorityStyle(WIDGET_VISIBLE)) { + doAfterAuthority(); + } + } + }; + private ItemListener widgetUsableAuthorityListener = new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (elementCasePane == null || cellSelection == null) { + return; + } + + if (setAuthorityStyle(WIDGET_USABLE)) { + doAfterAuthority(); + } + } + }; + + public ElementCasePaneAuthorityEditPane(ElementCasePane elementCasePane) { + super(elementCasePane); + this.elementCasePane = elementCasePane; + initCheckBoxesState(); + initListener(); + } + + private void doAfterAuthority() { + elementCasePane.repaint(); + elementCasePane.fireTargetModified(); + RolesAlreadyEditedPane.getInstance().refreshDockingView(); + RolesAlreadyEditedPane.getInstance().setReportAndFSSelectedRoles(); + RolesAlreadyEditedPane.getInstance().repaint(); + checkCheckBoxes(); + } + + private boolean setAuthorityColumn() { + initSelectedPathArray(); + String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { + return false; + } + if (selectedRoles == null) { + return false; + } + if (selectedPathArray == null) { + return false; + } + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + boolean isVisible = !gridColumnRowVisible.isSelected(); + for (int t = 0; t < selectedPathArray.length; t++) { + if (!isVisible) { + for (int col = cellSelection.getColumn(); col < cellSelection.getColumn() + cellSelection.getColumnSpan(); col++) { + elementCase.addColumnPrivilegeControl(col, selectedPathArray[t]); + } + } else { + for (int col = cellSelection.getColumn(); col < cellSelection.getColumn() + cellSelection.getColumnSpan(); col++) { + elementCase.removeColumnPrivilegeControl(col, selectedPathArray[t]); + } + } + } + + return true; + } + + private boolean setAuthorityRow() { + initSelectedPathArray(); + String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { + return false; + } + if (selectedRoles == null) { + return false; + } + if (selectedPathArray == null) { + return false; + } + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + boolean isVisible = !gridColumnRowVisible.isSelected(); + for (int t = 0; t < selectedPathArray.length; t++) { + if (!isVisible) { + for (int row = cellSelection.getRow(); row < cellSelection.getRow() + cellSelection.getRowSpan(); row++) { + elementCase.addRowPrivilegeControl(row, selectedPathArray[t]); + } + } else { + for (int row = cellSelection.getRow(); row < cellSelection.getRow() + cellSelection.getRowSpan(); row++) { + elementCase.removeRowPrivilegeControl(row, selectedPathArray[t]); + } + } + } + + + return true; + } + + private boolean setLFloatAuthorityStyle() { + initSelectedPathArray(); + String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role"))) { + return false; + } + if (selectedRoles == null) { + return false; + } + if (selectedPathArray == null) { + return false; + } + String name = floatSelection.getSelectedFloatName(); + TemplateElementCase ec = elementCasePane.getEditingElementCase(); + FloatElement fe = ec.getFloatElement(name); + for (int t = 0; t < selectedPathArray.length; t++) { + fe.changeAuthorityState(selectedPathArray[t], floatElementVisibleCheckBoxes.isSelected()); + } + + return true; + } + + private boolean setAuthorityStyle(int type) { + initSelectedPathArray(); + String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + if (ComparatorUtils.equals(selectedRoles, Inter.getLocText("FR-Designer_Role")) || + selectedRoles == null || selectedPathArray == null) { + return false; + } + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + int cellRectangleCount = cellSelection.getCellRectangleCount(); + for (int t = 0; t < selectedPathArray.length; t++) { + + for (int rec = 0; rec < cellRectangleCount; rec++) { + Rectangle cellRectangle = cellSelection.getCellRectangle(rec); + // 从最后循环起以保证最后一个修改标准单元格(originalStyle)。 + for (int j = cellRectangle.height - 1; j >= 0; j--) { + for (int i = cellRectangle.width - 1; i >= 0; i--) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement editCellElement = elementCase.getTemplateCellElement(column, row); + if (editCellElement == null) { + editCellElement = new DefaultTemplateCellElement(column, row); + elementCase.addCellElement(editCellElement); + } else { + // 对于合并的格子,我们不多次计算的权限. + if (editCellElement.getColumn() != column + || editCellElement.getRow() != row) { + continue; + } + } + if (type == CELL) { + editCellElement.changeAuthorityState(selectedPathArray[t], cellElementVisibleCheckBoxes.isSelected()); + } else if (type == NEW_VALUE) { + editCellElement.changeNewValueAuthorityState(selectedPathArray[t], newValue.isSelected(), valueEditor.update()); + } else if (type == WIDGET_VISIBLE) { + Widget widget = editCellElement.getWidget(); + widget.changeVisibleAuthorityState(selectedPathArray[t], widgetVisible.isSelected()); + } else { + Widget widget = editCellElement.getWidget(); + widget.changeUsableAuthorityState(selectedPathArray[t], widgetAvailable.isSelected()); + } + + } + } + } + } + return true; + } + + /** + * @see AuthorityEditToolBarPane initSelectedPathArray + */ + private void initSelectedPathArray() { + TreePath[] selectionPaths = ReportAndFSManagePane.getInstance().getRoleTree().getCheckBoxTreeSelectionModel().getSelectionPaths(); + if (selectionPaths.length == 1) { + if (((ExpandMutableTreeNode) (selectionPaths[0].getLastPathComponent())).getChildCount() > 0) { + ExpandMutableTreeNode node = (ExpandMutableTreeNode) ((ExpandMutableTreeNode) (selectionPaths[0].getLastPathComponent())).getLastChild(); + selectedPathArray = new String[node.getChildCount()]; + for (int i = 0; i < node.getChildCount(); i++) { + ExpandMutableTreeNode n = (ExpandMutableTreeNode) node.getChildAt(i); + String nodeName = n.getUserObject().toString(); + selectedPathArray[i] = nodeName; + } + } else { + selectedPathArray = pathToString(selectionPaths); + } + } else { + selectedPathArray = pathToString(selectionPaths); + } + + } + + public static String[] pathToString(TreePath[] path) { + java.util.List roles = new ArrayList(); + if (path != null && path.length > 0) { + for (TreePath tempPath : path) { + String temp = tempPath.toString(); + boolean isTrue = temp.length() > 0 && temp.charAt(0) == '[' && temp.endsWith("]"); + if (isTrue) { + temp = temp.substring(1, temp.length() - 1); + String[] selectedRoles = temp.split("," + StringUtils.BLANK); + String role = selectedRoles[2].trim(); + roles.add(role); + } + + } + } + return roles.toArray(new String[0]); + } + + /** + * 选中的单元格的乐见状态以第一个单元格为齐 + */ + public void initCheckBoxesState() { + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + if (cellSelection == null) { + cellElementVisibleCheckBoxes.setSelected(true); + } else { + Rectangle cellRectangle = cellSelection.getCellRectangle(0); + DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(cellRectangle.x, cellRectangle.y); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(cellRectangle.x, cellRectangle.y); + } + boolean firstCellDoneaAuthority = cellElement.isDoneAuthority( + ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName()); + cellElementVisibleCheckBoxes.setSelected(!firstCellDoneaAuthority); + } + widgetAvailable.setEnabled(cellElementVisibleCheckBoxes.isSelected()); + widgetVisible.setEnabled(cellElementVisibleCheckBoxes.isSelected()); + } + + private void initListener() { + cellElementVisibleCheckBoxes.addItemListener(cellRolesAuthorityListener); + widgetVisible.addItemListener(widgetVisibleRoleAuthorityListener); + widgetAvailable.addItemListener(widgetUsableAuthorityListener); + floatElementVisibleCheckBoxes.addItemListener(floatElementAuthorityListener); + gridColumnRowVisible.addItemListener(columnRowAuthorityListener); + newValue.addItemListener(newValuelistener); + valueEditor.registerChangeListener(observerListener); + } + + private void removeListener() { + cellElementVisibleCheckBoxes.removeItemListener(cellRolesAuthorityListener); + widgetVisible.removeItemListener(widgetVisibleRoleAuthorityListener); + widgetAvailable.removeItemListener(widgetUsableAuthorityListener); + floatElementVisibleCheckBoxes.removeItemListener(floatElementAuthorityListener); + gridColumnRowVisible.removeItemListener(columnRowAuthorityListener); + newValue.removeItemListener(newValuelistener); + valueEditor.registerChangeListener(null); + } + + private void addHyperlinkListener() { + cellElementVisibleCheckBoxes.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if (hyperlinkCheckBoxes != null) { + for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { + hyperlinkCheckBoxes[i].setEnabled(cellElementVisibleCheckBoxes.isSelected()); + if (!cellElementVisibleCheckBoxes.isSelected()) { + hyperlinkCheckBoxes[i].setSelected(false); + } + } + } + } + }); + for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { + hyperlinkCheckBoxes[i].addItemListener(cellRolesAuthorityListener); + } + } + + /** + * 更新适合的类型 + */ + public void populateType() { + if (selectionType == CellSelection.NORMAL) { + type.setText(Inter.getLocText("FR-Designer_Cell")); + } else if (selectionType == CellSelection.CHOOSE_ROW) { + type.setText(Inter.getLocText("FR-Designer_Row")); + } else if (selectionType == CellSelection.CHOOSE_COLUMN) { + type.setText(Inter.getLocText("FR-Designer_Column")); + } else { + type.setText(Inter.getLocText("M_Insert-Float")); + } + } + + /** + * 名字 + */ + public void populateName() { + if (selectionType == CellSelection.NORMAL) { + name.setText(getCellSelectionName()); + } else if (selectionType == CellSelection.CHOOSE_ROW || selectionType == CellSelection.CHOOSE_COLUMN) { + name.setText(getCellColumnRowName()); + } else { + name.setText(getFloatSelectionName()); + } + } + + private String getCellSelectionName() { + String nameText = ""; + int count = cellSelection.getCellRectangleCount(); + for (int rect = 0; rect < count; rect++) { + nameText += ","; + Rectangle cellRectangle = cellSelection.getCellRectangle(rect); + ColumnRow beginCR = ColumnRow.valueOf(cellRectangle.x, cellRectangle.y); + nameText += beginCR.toString(); + if (cellRectangle.width * cellRectangle.height != 1) { + ColumnRow endCR = ColumnRow.valueOf(cellRectangle.width + cellRectangle.x - 1, cellRectangle.height + cellRectangle.y - 1); + nameText += ":" + endCR.toString(); + } + } + return nameText.substring(1); + } + + private String getCellColumnRowName() { + int count = cellSelection.getCellRectangleCount(); + String nameText = ""; + ColumnRow cr = ColumnRow.valueOf(cellSelection.getColumn(), cellSelection.getRow()); + if (cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN && count == 1) { + if (cellSelection.getColumnSpan() == 1) { + nameText = cr.toString().substring(0, 1); + } else { + ColumnRow endCr = ColumnRow.valueOf(cellSelection.getColumn() + cellSelection.getColumnSpan() - 1, + cellSelection.getRow() + cellSelection.getRowSpan() - 1); + nameText = cr.toString().substring(0, 1) + "-" + endCr.toString().substring(0, 1); + } + } else if (cellSelection.getSelectedType() == CellSelection.CHOOSE_ROW && count == 1) { + if (cellSelection.getRowSpan() == 1) { + nameText = cr.toString().substring(1); + } else { + ColumnRow endCr = ColumnRow.valueOf(cellSelection.getColumn() + cellSelection.getColumnSpan() - 1, + cellSelection.getRow() + cellSelection.getRowSpan() - 1); + nameText = cr.toString().substring(1) + "-" + endCr.toString().substring(1); + } + } + return nameText; + } + + private String getFloatSelectionName() { + return floatSelection.getSelectedFloatName(); + } + + private void mutilRect(CellSelection cellSelection) { + isAllHasWidget = true; + isAllHasHyperlink = true; + int count = cellSelection.getCellRectangleCount(); + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + for (int rect = 0; rect < count; rect++) { + Rectangle cellRectangle = cellSelection.getCellRectangle(rect); + for (int j = 0; j < cellRectangle.height; j++) { + for (int i = 0; i < cellRectangle.width; i++) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(column, row); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); + } + if (cellElement.getCellWidgetAttr() == null) { + isAllHasWidget = false; + } + if (cellElement.getNameHyperlinkGroup() == null) { + isAllHasHyperlink = false; + } + } + } + } + } + + /** + * 更新适合的pane + * + * @return 返回Pane + */ + public JPanel populateCheckPane() { + checkPane.removeAll(); + if (selectionType == CellSelection.NORMAL) { + populateCellSelectionCheckPane(checkPane); + } else if (selectionType == CellSelection.CHOOSE_COLUMN || selectionType == CellSelection.CHOOSE_ROW) { + populateColumnRowCheckPane(checkPane); + } else if (selectionType == FLOAT_SELECTION) { + populateFloatSelectionCheckPane(checkPane); + } + checkPane.setBorder(BorderFactory.createEmptyBorder(ALIGNMENT_GAP, 0, 0, 0)); + return checkPane; + } + + private void populateColumnRowCheckPane(JPanel checkPane) { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{gridColumnRowVisible} + }; + double[] rowSize = {p}; + double[] columnSize = {f}; + int[][] rowCount = {{1}}; + checkPane.add( + TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM) + , BorderLayout.WEST); + } + + private void populateFloatSelectionCheckPane(JPanel checkPane) { + checkPane.add(populateFloatElementCheckPane(), BorderLayout.WEST); + } + + private void populateCellSelectionCheckPane(JPanel checkPane) { + if (elementCasePane.isSelectedOneCell()) { + //只选中了一个单元格 + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + DefaultTemplateCellElement cellElement = (DefaultTemplateCellElement) elementCase.getCellElement(cellSelection.getColumn(), cellSelection.getRow()); + if (cellElement == null) { + cellElement = new DefaultTemplateCellElement(cellSelection.getColumn(), cellSelection.getRow()); + } + //单元格带控件 + if (cellElement.getCellWidgetAttr() != null) { + checkPane.add(populateWidgetCheckPane(), BorderLayout.WEST); + } else { + checkPane.add(populatCellCheckPane(), BorderLayout.WEST); + } + } else { + //批量选中单元格 + mutilRect(cellSelection); + if (!isAllHasWidget && !isAllHasHyperlink) { + checkPane.add(populateMutilCellCheckPane(), BorderLayout.WEST); + } else if (isAllHasWidget) { + checkPane.add(populateMutilWidgetCheckPane(), BorderLayout.WEST); + } + } + } + + /** + * 对单元格区域进行操作时的权限编辑页面 ,对应的角色的populate + */ + public void populateDetials() { + //做模式标记,此时鼠标焦点是在报表主体,为下一次退出权限编辑时做准备 + HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().setAuthorityMode(false); + TemplateElementCase templateElementCase = elementCasePane.getEditingElementCase(); + if (templateElementCase instanceof WorkSheet) { + ((WorkSheet) templateElementCase).setPaintSelection(true); + } + signelSelection(); + Selection selection = elementCasePane.getSelection(); + if (selection instanceof CellSelection) { + selectionType = CellSelection.NORMAL; + this.cellSelection = ((CellSelection) selection).clone(); + this.floatSelection = null; + judgeChooseCR(); + } else if (selection instanceof FloatSelection) { + selectionType = FLOAT_SELECTION; + cellSelection = null; + floatSelection = new FloatSelection(((FloatSelection) selection).getSelectedFloatName()); + } + populateType(); + populateName(); + populateCheckPane(); + checkCheckBoxes(); + } + + //判断是否选择的行列 + private void judgeChooseCR() { + if (cellSelection.getSelectedType() == CellSelection.CHOOSE_COLUMN && cellSelection.getCellRectangleCount() == 1) { + selectionType = CellSelection.CHOOSE_COLUMN; + } + if (cellSelection.getSelectedType() == CellSelection.CHOOSE_ROW && cellSelection.getCellRectangleCount() == 1) { + selectionType = CellSelection.CHOOSE_ROW; + } + } + + //实现单选 + private void signelSelection() { + JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (jTemplate.isJWorkBook()) { + //清工具栏 + JComponent component = DesignerContext.getDesignerFrame().getToolbarComponent(); + if (component instanceof AuthorityEditToolBarComponent) { + ((AuthorityEditToolBarComponent) component).removeSelection(); + } + //清参数面板 + jTemplate.removeParameterPaneSelection(); + } + } + + private JPanel populateFloatElementCheckPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("M_Insert-Float"), SwingConstants.LEFT), floatElementVisibleCheckBoxes} + }; + double[] rowSize = {p}; + double[] columnSize = {p, f}; + int[][] rowCount = {{1, 1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + private JPanel populateWidgetCheckPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}, + new Component[]{null, newValue}, + new Component[]{null, valueEditor}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget"), SwingConstants.LEFT), widgetVisible}, + new Component[]{null, widgetAvailable} + }; + double[] rowSize = {p, p, p, p, p}; + double[] columnSize = {p, f}; + int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + private JPanel populateMutilWidgetCheckPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget"), SwingConstants.LEFT), widgetVisible}, + new Component[]{null, widgetAvailable} + }; + double[] rowSize = {p, p, p}; + double[] columnSize = {p, f}; + int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + private JPanel populateMutilCellCheckPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{cellElementVisibleCheckBoxes}, + }; + double[] rowSize = {p}; + double[] columnSize = {f}; + int[][] rowCount = {{1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + private JPanel populatCellCheckPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[][]{ + new Component[]{cellElementVisibleCheckBoxes}, + new Component[]{newValue}, + new Component[]{valueEditor} + }; + double[] rowSize = {p, p, p}; + double[] columnSize = {f}; + int[][] rowCount = {{1}, {1}, {1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } + + public TemplateCellElement getFirstCell() { + final TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + Rectangle cellRectangle = cellSelection.getCellRectangle(0); + // 从最后循环起以保证最后一个修改标准单元格(originalStyle)。 + TemplateCellElement firstCell = null; + for (int j = cellRectangle.height - 1; j >= 0; j--) { + for (int i = cellRectangle.width - 1; i >= 0; i--) { + int column = i + cellRectangle.x; + int row = j + cellRectangle.y; + TemplateCellElement editCellElement = elementCase.getTemplateCellElement(column, row); + if (editCellElement != null) { + // 对于合并的格子,我们不多次计算的权限. + if (editCellElement.getColumn() != column || editCellElement.getRow() != row) { + continue; + } + firstCell = editCellElement; + } + } + } + return firstCell; + } + + private void checkCheckBoxes() { + String selected = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + removeListener(); + if (selectionType == CellSelection.NORMAL) { + checkCellSelectionCkeckboxes(selected); + } else if (selectionType == CellSelection.CHOOSE_COLUMN || selectionType == CellSelection.CHOOSE_ROW) { + checkColumnRowCheckBoxes(selected); + } else if (selectionType == FLOAT_SELECTION) { + checkFloatSelectionCkeckboxes(selected); + } + initListener(); + } + + private void checkCellSelectionCkeckboxes(String selected) { + TemplateCellElement firstCell = getFirstCell(); + if (firstCell == null) { + resetCellElementCheckBoxes(); + return; + } + cellElementVisibleCheckBoxes.setSelected(!firstCell.isDoneAuthority(selected)); + newValue.setEnabled(!firstCell.isDoneAuthority(selected)); + if (!firstCell.isDoneAuthority(selected)) { + newValue.setSelected(firstCell.isDoneNewValueAuthority(selected)); + if (newValue.isSelected()) { + valueEditor.setEnabled(true); + valueEditor.populate(firstCell.getCellPrivilegeControl().getNewValueMap().get(selected)); + } else { + valueEditor.setEnabled(false); + } + } else { + newValue.setSelected(false); + valueEditor.setEnabled(false); + } + populateWidgetButton(firstCell.getWidget(), selected, firstCell); + } + + private void populateWidgetButton(Widget widget, String selected, TemplateCellElement firstCell) { + if (widget != null) { + if (widget.isVisible()) { + widgetVisible.setSelected(!widget.isDoneVisibleAuthority(selected)); + widgetVisible.setEnabled(!firstCell.isDoneAuthority(selected)); + } else { + widgetVisible.setSelected(widget.isVisibleAuthority(selected)); + } + if (widget.isEnabled()) { + widgetAvailable.setSelected(!widget.isDoneUsableAuthority(selected)); + widgetAvailable.setEnabled(!widget.isDoneVisibleAuthority(selected)); + } else { + widgetAvailable.setSelected(widget.isUsableAuthority(selected)); + } + } + } + + private void resetCellElementCheckBoxes() { + cellElementVisibleCheckBoxes.setSelected(true); + widgetVisible.setSelected(true); + widgetVisible.setEnabled(true); + widgetAvailable.setSelected(true); + widgetAvailable.setEnabled(true); + newValue.setSelected(false); + valueEditor.setEnabled(false); + } + + private void checkColumnRowCheckBoxes(String selected) { + if (cellSelection == null) { + gridColumnRowVisible.setSelected(false); + return; + } + TemplateElementCase elementCase = elementCasePane.getEditingElementCase(); + boolean isInside = selectionType == CellSelection.CHOOSE_COLUMN ? + elementCase.getColumnPrivilegeControl(cellSelection.getColumn()).checkInvisible(selected) : + elementCase.getRowPrivilegeControl(cellSelection.getRow()).checkInvisible(selected); + + gridColumnRowVisible.setSelected(isInside); + } + + private void checkFloatSelectionCkeckboxes(String selected) { + String name = floatSelection.getSelectedFloatName(); + TemplateElementCase ec = elementCasePane.getEditingElementCase(); + FloatElement fe = ec.getFloatElement(name); + floatElementVisibleCheckBoxes.setSelected(!fe.isDoneAuthority(selected)); + } + + private JPanel populateHyperlinkCheckPane(AbstractCellElement cellElement) { + NameJavaScriptGroup linkGroup = cellElement.getNameHyperlinkGroup(); + //超链接的个数+单元格可见的操作 + hyperlinkCheckBoxes = new UICheckBox[linkGroup.size()]; + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[hyperlinkCheckBoxes.length + 1][]; + if (linkGroup.size() == 1) { + components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}; + components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; + + } else { + components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; + components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(linkGroup.getNameHyperlink(0).getName() + Inter.getLocText("FR-Designer_Visible"))}; + for (int i = 1; i < hyperlinkCheckBoxes.length; i++) { + components[i + 1] = new Component[]{null, hyperlinkCheckBoxes[i] = new UICheckBox(linkGroup.getNameHyperlink(i).getName() + Inter.getLocText("FR-Designer_Visible"))}; + } + } + for (int i = 0; i < hyperlinkCheckBoxes.length; i++) { + hyperlinkCheckBoxes[i].setEnabled(cellElementVisibleCheckBoxes.isSelected()); + } + addHyperlinkListener(); + double[] rowSize = new double[hyperlinkCheckBoxes.length + 1]; + int[][] rowCount = new int[hyperlinkCheckBoxes.length + 1][]; + for (int i = 0; i < hyperlinkCheckBoxes.length + 1; i++) { + rowSize[i] = p; + rowCount[i] = new int[]{1, 1}; + } + double[] columnSize = {p, f}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + + } + + private JPanel populateMutilHyperlinkCheckPane() { + //超链接的个数+单元格可见的操作 + hyperlinkCheckBoxes = new UICheckBox[1]; + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + Component[][] components = new Component[2][]; + components[0] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Cell"), SwingConstants.LEFT), cellElementVisibleCheckBoxes}; + components[1] = new Component[]{new UILabel(Inter.getLocText("FR-Designer_Hyperlink"), SwingConstants.LEFT), hyperlinkCheckBoxes[0] = new UICheckBox(Inter.getLocText("FR-Designer_Visible"))}; + hyperlinkCheckBoxes[0].setEnabled(cellElementVisibleCheckBoxes.isSelected()); + addHyperlinkListener(); + double[] rowSize = {p, p}; + double[] columnSize = {p, f}; + int[][] rowCount = {{1, 1}, {1, 1}}; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); + } +} \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/InformationCollector.java b/designer/src/com/fr/design/mainframe/InformationCollector.java index a4b3fc6ab..f50cc5dad 100644 --- a/designer/src/com/fr/design/mainframe/InformationCollector.java +++ b/designer/src/com/fr/design/mainframe/InformationCollector.java @@ -10,6 +10,7 @@ import com.fr.data.core.db.dml.Delete; import com.fr.data.core.db.dml.Select; import com.fr.data.core.db.dml.Table; import com.fr.design.DesignerEnvManager; +import com.fr.design.mainframe.templateinfo.TemplateInfoCollector; import com.fr.general.*; import com.fr.general.http.HttpClient; import com.fr.json.JSONArray; @@ -315,6 +316,7 @@ public class InformationCollector implements XMLReadable, XMLWriter { } sendFunctionsInfo(); sendUserInfo(); + TemplateInfoCollector.getInstance().sendTemplateInfo(); } }); sendThread.start(); diff --git a/designer/src/com/fr/design/mainframe/JPolyWorkBook.java b/designer/src/com/fr/design/mainframe/JPolyWorkBook.java index bfdb39664..aa5a727e8 100644 --- a/designer/src/com/fr/design/mainframe/JPolyWorkBook.java +++ b/designer/src/com/fr/design/mainframe/JPolyWorkBook.java @@ -24,7 +24,6 @@ public class JPolyWorkBook extends JWorkBook { super(new WorkBook(new PolyWorkSheet()), DEFAULT_NAME); populateReportParameterAttr(); } - /** * 创建sheet名称tab面板 diff --git a/designer/src/com/fr/design/mainframe/JWorkBook.java b/designer/src/com/fr/design/mainframe/JWorkBook.java index f3722c4ac..fd4cd7b0d 100644 --- a/designer/src/com/fr/design/mainframe/JWorkBook.java +++ b/designer/src/com/fr/design/mainframe/JWorkBook.java @@ -3,6 +3,7 @@ package com.fr.design.mainframe; import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.base.Parameter; +import com.fr.base.parameter.ParameterUI; import com.fr.design.DesignModelAdapter; import com.fr.design.ExtraDesignClassManager; import com.fr.design.actions.AllowAuthorityEditAction; @@ -26,6 +27,8 @@ import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icontainer.UIModeControlContainer; import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.mainframe.cell.QuickEditorRegion; +import com.fr.design.mainframe.templateinfo.JWorkBookProcessInfo; +import com.fr.design.mainframe.templateinfo.TemplateProcessInfo; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import com.fr.design.menu.*; import com.fr.design.module.DesignModuleFactory; @@ -54,7 +57,10 @@ import com.fr.main.impl.WorkBook; import com.fr.main.parameter.ReportParameterAttr; import com.fr.poly.PolyDesigner; import com.fr.privilege.finegrain.WorkSheetPrivilegeControl; +import com.fr.report.cellcase.CellCase; import com.fr.report.elementcase.TemplateElementCase; +import com.fr.report.poly.PolyWorkSheet; +import com.fr.report.report.Report; import com.fr.report.worksheet.WorkSheet; import com.fr.stable.ArrayUtils; import com.fr.stable.StableUtils; @@ -66,10 +72,7 @@ import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * JWorkBook used to edit WorkBook. @@ -129,6 +132,13 @@ public class JWorkBook extends JTemplate { return centerPane; } + public TemplateProcessInfo getProcessInfo() { + if (processInfo == null) { + processInfo = new JWorkBookProcessInfo(template); + } + return processInfo; + } + /** * 判断sheet权限 * @@ -463,7 +473,7 @@ public class JWorkBook extends JTemplate { */ public ShortCut[] shortCuts4Authority() { return new ShortCut[]{ - new NameSeparator(Inter.getLocText(new String[]{"DashBoard-Potence", "Edit"})), + new NameSeparator(Inter.getLocText("FR-Designer_Permissions_Edition")), BaseUtils.isAuthorityEditing() ? new ExitAuthorityEditAction(this) : new AllowAuthorityEditAction(this), }; diff --git a/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java b/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java index f6e3d3e7c..90d84059b 100644 --- a/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java +++ b/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java @@ -5,7 +5,6 @@ package com.fr.design.mainframe.bbs; import com.fr.base.FRContext; import com.fr.design.DesignerEnvManager; -import com.fr.design.dialog.UIDialog; import com.fr.design.extra.*; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.imenu.UIMenuItem; @@ -103,17 +102,13 @@ public class UserInfoLabel extends UILabel { if (StableUtils.getMajorJavaVersion() == 8) { PluginWebBridge.getHelper().setUILabel(UserInfoLabel.this); } - QQLoginWebBridge.getHelper().setUILabelInPlugin(UserInfoLabel.this); + LoginWebBridge.getHelper().setUILabelInPlugin(UserInfoLabel.this); UserLoginContext.addLoginContextListener(new LoginContextListener() { @Override public void showLoginContext() { - LoginPane managerPane = new LoginPane(); - UIDialog qqdlg = new LoginDialog(DesignerContext.getDesignerFrame(), managerPane); - LoginWebBridge.getHelper().setDialogHandle(qqdlg); + WebViewDlgHelper.createLoginDialog(); LoginWebBridge.getHelper().setUILabel(UserInfoLabel.this); - QQLoginWebBridge.getHelper().setLoginlabel(); - qqdlg.setVisible(true); clearLoginInformation(); updateInfoPane(); } diff --git a/designer/src/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java b/designer/src/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java index ffeaae0d9..0e45a1e97 100644 --- a/designer/src/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java +++ b/designer/src/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java @@ -3,7 +3,9 @@ package com.fr.design.mainframe.cell.settingpane; import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.util.Locale; +import com.fr.base.FRContext; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.ilable.UILabel; @@ -76,23 +78,23 @@ public class CellOtherSetPane extends AbstractCellAttrPane { double p = TableLayout.PREFERRED; double[] rowSize1 = {p, p, p, p, p, p, p}; double[] columnSize1 = {p, f}; - UILabel autoAdjustLabel = new UILabel(Inter.getLocText("Auto_Adjust_Size") + ":", SwingConstants.RIGHT); + UILabel autoAdjustLabel = new UILabel(Inter.getLocText("FR-Designer_Auto_Adjust_Size") + ":", SwingConstants.RIGHT); autoAdjustLabel.setVerticalAlignment(UILabel.TOP); Component[][] components1 = new Component[][]{ new Component[]{autoAdjustLabel, autoshrik}, - new Component[]{new UILabel(Inter.getLocText("Preview") + ":", SwingConstants.RIGHT), previewCellContent}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Preview") + ":", SwingConstants.RIGHT), previewCellContent}, new Component[]{new UILabel(Inter.getLocText("CellWrite-Print_Export") + ":", SwingConstants.RIGHT), printAndExportContent}, new Component[]{null, printAndExportBackground}, - new Component[]{new UILabel(Inter.getLocText("Show_Content") + ":", SwingConstants.RIGHT), showContent}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Show_Content") + ":", SwingConstants.RIGHT), showContent}, new Component[]{null, fileNamePane}, - new Component[]{new UILabel(Inter.getLocText("CellWrite-ToolTip") + ":", SwingConstants.RIGHT), tooltipTextField}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_CellWrite_ToolTip") + ":", SwingConstants.RIGHT), tooltipTextField}, }; JPanel northContentPane = TableLayoutHelper.createTableLayoutPane(components1, rowSize1, columnSize1); double[] rowSize2 = {p, p, p, p, p, p}; double[] columnSize2 = {p, f}; Component[][] components2 = new Component[][]{ new Component[]{new JSeparator(JSeparator.HORIZONTAL), null}, - new Component[]{new UILabel(Inter.getLocText("Pagination")), null}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Pagination")), null}, new Component[]{pageBeforeRowCheckBox, pageAfterRowCheckBox}, new Component[]{pageBeforeColumnCheckBox, pageAfterColumnCheckBox}, new Component[]{canBreakOnPaginateCheckBox, null}, @@ -121,22 +123,28 @@ public class CellOtherSetPane extends AbstractCellAttrPane { private JPanel createNormal() { String[] AjustRowTypes = new String[]{ - Inter.getLocText("No"), Inter.getLocText("Utils-Row_Height"), Inter.getLocText("Utils-Column_Width"), Inter.getLocText("Default")}; + Inter.getLocText("FR-Designer_No"), Inter.getLocText("Utils-Row_Height"), Inter.getLocText("Utils-Column_Width"), Inter.getLocText("FR-Designer_DEFAULT")}; autoshrik = new UIButtonGroup(AjustRowTypes); - autoshrik.setTwoLine(); - autoshrik.setLayout(new GridLayout(2, 2, 1, 1)); + if (FRContext.getLocale().equals(Locale.US)) { + // 英文显示不全,故每行一个按钮 + autoshrik.setFourLine(); + autoshrik.setLayout(new GridLayout(4, 1, 1, 1)); + } else { + autoshrik.setTwoLine(); + autoshrik.setLayout(new GridLayout(2, 2, 1, 1)); + } previewCellContent = new UICheckBox(Inter.getLocText("CellWrite-Preview_Cell_Content")); printAndExportContent = new UICheckBox(Inter.getLocText("CellWrite-Print_Content")); printAndExportBackground = new UICheckBox(Inter.getLocText("CellWrite-Print_Background")); - showContent = new UIComboBox(new String[]{Inter.getLocText("Default"), Inter.getLocText("CellWrite-Show_As_Image"), Inter.getLocText("CellWrite-Show_As_HTML"), - Inter.getLocText("ShowAsDownload")}); + showContent = new UIComboBox(new String[]{Inter.getLocText("FR-Designer_DEFAULT"), Inter.getLocText("CellWrite-Show_As_Image"), Inter.getLocText("CellWrite-Show_As_HTML"), + Inter.getLocText("FR-Designer_Show_As_Download")}); final CardLayout fileNameLayout = new CardLayout(); final JPanel fileNamePane = new JPanel(fileNameLayout); JPanel fileNameCCPane = new JPanel(new BorderLayout(4, 0)); - fileNameCCPane.add(new UILabel(Inter.getLocText("FileNameForDownload")), BorderLayout.WEST); + fileNameCCPane.add(new UILabel(Inter.getLocText("FR-Designer_File_Name_For_Download")), BorderLayout.WEST); fileNameTextField = new UITextField(); tooltipTextField = new UITextField(); @@ -186,13 +194,13 @@ public class CellOtherSetPane extends AbstractCellAttrPane { } private void initAllNames() { - autoshrik.setGlobalName(Inter.getLocText("Auto_Adjust_Size")); - previewCellContent.setGlobalName(Inter.getLocText("Preview")); + autoshrik.setGlobalName(Inter.getLocText("FR-Designer_Auto_Adjust_Size")); + previewCellContent.setGlobalName(Inter.getLocText("FR-Designer_Preview")); printAndExportContent.setGlobalName(Inter.getLocText("CellWrite-Preview_Cell_Content")); printAndExportBackground.setGlobalName(Inter.getLocText("CellWrite-Print_Background")); - showContent.setGlobalName(Inter.getLocText("Show_Content")); - fileNameTextField.setGlobalName(Inter.getLocText("Show_Content")); - tooltipTextField.setGlobalName(Inter.getLocText("CellWrite-ToolTip")); + showContent.setGlobalName(Inter.getLocText("FR-Designer_Show_Content")); + fileNameTextField.setGlobalName(Inter.getLocText("FR-Designer_Show_Content")); + tooltipTextField.setGlobalName(Inter.getLocText("FR-Designer_CellWrite_ToolTip")); pageBeforeRowCheckBox.setGlobalName(Inter.getLocText("CellWrite-Page_Before_Row")); pageAfterRowCheckBox.setGlobalName(Inter.getLocText("CellWrite-Page_After_Row")); pageBeforeColumnCheckBox.setGlobalName(Inter.getLocText("CellWrite-Page_Before_Column")); @@ -224,10 +232,10 @@ public class CellOtherSetPane extends AbstractCellAttrPane { } else if (cellGUIAttr.isShowAsHTML()) { showContent.setSelectedItem(Inter.getLocText("CellWrite-Show_As_HTML")); } else if (cellGUIAttr.isShowAsDownload()) { - showContent.setSelectedItem(Inter.getLocText("ShowAsDownload")); + showContent.setSelectedItem(Inter.getLocText("FR-Designer_Show_As_Download")); fileNameTextField.setText(cellGUIAttr.getFileName()); } else { - showContent.setSelectedItem(Inter.getLocText("Default")); + showContent.setSelectedItem(Inter.getLocText("FR-Designer_DEFAULT")); } tooltipTextField.setText(cellGUIAttr.getTooltipText()); CellPageAttr cellPageAttr = cellElement.getCellPageAttr(); // 分页 @@ -272,11 +280,11 @@ public class CellOtherSetPane extends AbstractCellAttrPane { cellGUIAttr = new CellGUIAttr(); } - if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("Auto_Adjust_Size"))) { + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("FR-Designer_Auto_Adjust_Size"))) { cellGUIAttr.setAdjustMode(autoshrik.getSelectedIndex()); } - if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("Preview"))) { + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("FR-Designer_Preview"))) { cellGUIAttr.setPreviewContent(previewCellContent.isSelected()); } @@ -288,7 +296,7 @@ public class CellOtherSetPane extends AbstractCellAttrPane { cellGUIAttr.setPrintBackground(printAndExportBackground.isSelected()); } - if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("Show_Content"))) { + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("FR-Designer_Show_Content"))) { cellGUIAttr.setShowAsDefault(showContent.getSelectedIndex() == 0); cellGUIAttr.setShowAsImage(showContent.getSelectedIndex() == 1); cellGUIAttr.setShowAsHTML(showContent.getSelectedIndex() == 2); @@ -300,7 +308,7 @@ public class CellOtherSetPane extends AbstractCellAttrPane { } } - if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("CellWrite-ToolTip"))) { + if (ComparatorUtils.equals(getGlobalName(), Inter.getLocText("FR-Designer_CellWrite_ToolTip"))) { if (tooltipTextField.getText() == null || tooltipTextField.getText().trim().length() <= 0) { cellGUIAttr.setTooltipText(fieldName); } else { diff --git a/designer/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java b/designer/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java new file mode 100644 index 000000000..bf5d835d2 --- /dev/null +++ b/designer/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java @@ -0,0 +1,74 @@ +package com.fr.design.mainframe.templateinfo; + +import com.fr.base.parameter.ParameterUI; +import com.fr.main.impl.WorkBook; +import com.fr.report.cellcase.CellCase; +import com.fr.report.poly.PolyWorkSheet; +import com.fr.report.worksheet.WorkSheet; + +import java.util.Iterator; + +/** + * Created by plough on 2017/3/17. + */ +public class JWorkBookProcessInfo extends TemplateProcessInfo { + + public JWorkBookProcessInfo(WorkBook wb) { + super(wb); + } + + // 获取模板类型 + public int getReportType() { + return template.isElementCaseBook() ? 0 : 1; + } + + // 获取模板格子数 + public int getCellCount() { + int cellCount = 0; + if (template.isElementCaseBook()) { // 如果是普通报表 + for (int i = 0; i < template.getReportCount(); i++) { + WorkSheet r = (WorkSheet) template.getReport(i); + CellCase cc = r.getBlock().getCellCase(); + for (int j = 0; j < cc.getRowCount(); j++) { + Iterator iter = cc.getRow(j); + while (iter.hasNext()) { + cellCount ++; + iter.next(); + } + } + } + } + return cellCount; + } + // 获取模板悬浮元素个数 + public int getFloatCount() { + int chartCount = 0; + if (template.isElementCaseBook()) { // 如果是普通报表 + for (int i = 0; i < template.getReportCount(); i++) { + WorkSheet r = (WorkSheet) template.getReport(i); + Iterator fiter = r.getBlock().floatIterator(); + while (fiter.hasNext()) { + chartCount ++; + fiter.next(); + } + } + } + return chartCount; + } + // 获取模板聚合块个数 + public int getBlockCount() { + int blockCount = 0; + if (!template.isElementCaseBook()) { // 如果是聚合报表 + for (int i = 0; i < template.getReportCount(); i++) { + PolyWorkSheet r = (PolyWorkSheet) template.getReport(i); + blockCount += r.getBlockCount(); + } + } + return blockCount; + } + // 获取模板控件数 + public int getWidgetCount() { + ParameterUI pui = template.getReportParameterAttr().getParameterUI(); + return pui == null ? 0 : (pui.getAllWidgets().length - 1); + } +} diff --git a/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java b/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java index 46bc378ae..af5906c33 100644 --- a/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java +++ b/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java @@ -10,7 +10,7 @@ import javax.swing.event.ChangeListener; import com.fr.base.FRContext; import com.fr.design.dialog.BasicPane; -import com.fr.design.extra.WebDialog; +import com.fr.design.extra.WebViewDlgHelper; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.ActionLabel; import com.fr.design.gui.ilable.UILabel; @@ -553,7 +553,7 @@ public class RepeatAndFreezeSettingPane extends BasicPane { public void actionPerformed(ActionEvent e) { try { //Desktop.getDesktop().browse(new URI(url)); - WebDialog.createPluginDialog(); + WebViewDlgHelper.createPluginDialog(); RepeatAndFreezeSettingPane.this.getTopLevelAncestor().setVisible(false); } catch (Exception exp) { diff --git a/designer/src/com/fr/design/report/mobile/MobileUseHtmlGroupPane.java b/designer/src/com/fr/design/report/mobile/MobileUseHtmlGroupPane.java index 0e0ec087d..ee3c51fec 100644 --- a/designer/src/com/fr/design/report/mobile/MobileUseHtmlGroupPane.java +++ b/designer/src/com/fr/design/report/mobile/MobileUseHtmlGroupPane.java @@ -7,6 +7,10 @@ import com.fr.report.mobile.ElementCaseMobileAttr; * Created by kunsnat on 2016/8/3. */ public class MobileUseHtmlGroupPane extends MobileUseHtmlGroupBeanPane { + public MobileUseHtmlGroupPane(String annotation) { + super(annotation); + } + @Override public void populateBean(ElementCaseMobileAttr mobileAttr) { if(mobileAttr != null) { diff --git a/designer/src/com/fr/design/report/mobile/ReportMobileAttrPane.java b/designer/src/com/fr/design/report/mobile/ReportMobileAttrPane.java index 8f8f74437..e91d1d3b8 100644 --- a/designer/src/com/fr/design/report/mobile/ReportMobileAttrPane.java +++ b/designer/src/com/fr/design/report/mobile/ReportMobileAttrPane.java @@ -34,7 +34,7 @@ public class ReportMobileAttrPane extends BasicBeanPane{ appFitBrowserPane.setAppFitPreviewPane(appFitPreviewPane); jPanel.add(appFitBrowserPane); - jPanel.add(htmlGroupPane = new MobileUseHtmlGroupPane()); + jPanel.add(htmlGroupPane = new MobileUseHtmlGroupPane(Inter.getLocText("FR-Designer_Mobile_Report_Analysis_Annotation"))); jPanel.add(mobileToolBarPane = new MobileToolBarPane()); diff --git a/designer/src/com/fr/design/webattr/EditToolBar.java b/designer/src/com/fr/design/webattr/EditToolBar.java index 58f455870..938fd4509 100644 --- a/designer/src/com/fr/design/webattr/EditToolBar.java +++ b/designer/src/com/fr/design/webattr/EditToolBar.java @@ -7,6 +7,7 @@ import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.fun.ExportToolBarProvider; +import com.fr.design.fun.ExtraButtonToolBarProvider; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; @@ -199,7 +200,7 @@ public class EditToolBar extends BasicPane { toolBarButton.setWidget(widget); if (widget instanceof Button) { String iconname = ((Button) widget).getIconName(); - if (!StringUtils.isBlank(iconname)) { + if (StringUtils.isNotBlank(iconname)) { Image iimage = WidgetManager.getProviderInstance().getIconManager().getIconImage(iconname); toolBarButton.setIcon(new ImageIcon(iimage)); } @@ -326,17 +327,18 @@ public class EditToolBar extends BasicPane { private IconDefinePane iconPane; private UIButton button; private JavaScriptActionPane javaScriptPane; - private ExportToolBarProvider[] exportToolBarProviders; + private ExportToolBarProvider[] exportToolBarProviders; - private ChangeListener changeListener = new ChangeListener() { - public void stateChanged(ChangeEvent e) { + private ActionListener actionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { if (isVerify.isSelected()) { failSubmit.setVisible(true); } else { failSubmit.setVisible(false); + failSubmit.setSelected(false); } } - }; public ButtonPane() { @@ -386,6 +388,11 @@ public class EditToolBar extends BasicPane { centerPane.add(getCpane(), "appendcount"); centerPane.add(getSubmitPane(), "submit"); + Set extraButtonSet = ExtraDesignClassManager.getInstance().getArray(ExtraButtonToolBarProvider.XML_TAG); + for (ExtraButtonToolBarProvider provider : extraButtonSet) { + provider.updateCenterPane(centerPane); + } + this.add(centerPane, BorderLayout.CENTER); } @@ -475,11 +482,10 @@ public class EditToolBar extends BasicPane { submitPane.add(isVerify); submitPane.add(failSubmit); submitPane.add(isCurSheet); - isVerify.addChangeListener(changeListener); + isVerify.addActionListener(actionListener); return submitPane; } - @Override protected String title4PopupWindow() { return "Button"; @@ -528,13 +534,18 @@ public class EditToolBar extends BasicPane { } else if (widget instanceof CustomToolBarButton) { populateCustomToolBarButton(); } - } - + + Set extraButtonSet = ExtraDesignClassManager.getInstance().getArray(ExtraButtonToolBarProvider.XML_TAG); + for (ExtraButtonToolBarProvider provider : extraButtonSet) { + provider.populate(widget, card, centerPane); + } + } + private void populateAppendColumnRow(){ card.show(centerPane, "appendcount"); count.setValue(((AppendColumnRow) widget).getCount()); } - + private void populateExport(){ card.show(centerPane, "export"); Export export = (Export) widget; @@ -550,7 +561,7 @@ public class EditToolBar extends BasicPane { } } } - + private void populateCustomToolBarButton(){ card.show(centerPane, "custom"); CustomToolBarButton customToolBarButton = (CustomToolBarButton) widget; @@ -558,21 +569,24 @@ public class EditToolBar extends BasicPane { this.javaScriptPane.populateBean(customToolBarButton.getJSImpl()); } } - + private void populateSubmit(){ card.show(centerPane, "submit"); Submit submit = ((Submit) widget); this.isVerify.setSelected(submit.isVerify()); + if (!submit.isVerify()) { + this.failSubmit.setVisible(false); + } this.failSubmit.setSelected(submit.isFailVerifySubmit()); this.isCurSheet.setSelected(submit.isOnlySubmitSelect()); } - + private void populatePDFPrint(){ card.show(centerPane, "pdfprint"); PDFPrint pdfPrint = (PDFPrint) widget; this.isPopup.setSelected(pdfPrint.isPopup()); } - + private void populatePrint(){ card.show(centerPane, "print"); Print print = (Print) widget; @@ -581,7 +595,7 @@ public class EditToolBar extends BasicPane { this.flashPrint.setSelected(print.isFlashPrint()); this.serverPrint.setSelected(print.isServerPrint()); } - + private void populateDefault(){ Button button = (Button) widget; this.icon.setSelected(button.isShowIcon()); @@ -592,7 +606,7 @@ public class EditToolBar extends BasicPane { /** * 更新 - * + * * @return 对应组件 */ public Widget update() { @@ -613,23 +627,29 @@ public class EditToolBar extends BasicPane { if (widget instanceof Button) { updateDefault(); } + + Set extraButtonSet = ExtraDesignClassManager.getInstance().getArray(ExtraButtonToolBarProvider.XML_TAG); + for (ExtraButtonToolBarProvider provider : extraButtonSet) { + provider.update(widget); + } + return widget; } - + private void updateDefault(){ ((Button) widget).setShowIcon(this.icon.isSelected()); ((Button) widget).setShowText(this.text.isSelected()); ((Button) widget).setText(this.nameField.getText()); ((Button) widget).setIconName(this.iconPane.update()); } - + private void updateSubmit(){ Submit submit = ((Submit) widget); submit.setVerify(this.isVerify.isSelected()); submit.setFailVerifySubmit(this.failSubmit.isSelected()); submit.setOnlySubmitSelect(this.isCurSheet.isSelected()); } - + private void updatePrint(){ Print print = (Print) widget; print.setAppletPrint(this.appletPrint.isSelected()); @@ -637,7 +657,7 @@ public class EditToolBar extends BasicPane { print.setPDFPrint(this.pdfPrint.isSelected()); print.setServerPrint(this.serverPrint.isSelected()); } - + private void updateExport(){ Export export = (Export) widget; export.setPdfAvailable(this.pdf.isSelected()); diff --git a/designer/src/com/fr/design/webattr/ReportWebWidgetConstants.java b/designer/src/com/fr/design/webattr/ReportWebWidgetConstants.java index e2fa6ae4d..653599524 100644 --- a/designer/src/com/fr/design/webattr/ReportWebWidgetConstants.java +++ b/designer/src/com/fr/design/webattr/ReportWebWidgetConstants.java @@ -78,13 +78,13 @@ public class ReportWebWidgetConstants { public static final WidgetOption EDIT = WidgetOptionFactory.createByWidgetClass("Edit", Edit.class); // 导出成Excel 分页导出 - public static final WidgetOption EXCELP = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"Excel", "Export-Excel-Page"}, new String[]{"(", ")"}), + public static final WidgetOption EXCELP = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"Excel", "FR-Designer_Export_Excel_Page"}, new String[]{"(", ")"}), BaseUtils.readIcon("/com/fr/web/images/excel.png"), ExcelP.class); // 导出成Excel 原样导出 - public static final WidgetOption EXCELO = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"Excel", "Export-Excel-Simple"}, new String[]{"(", ")"}), + public static final WidgetOption EXCELO = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"Excel", "FR-Designer_Export_Excel_Simple"}, new String[]{"(", ")"}), BaseUtils.readIcon("/com/fr/web/images/excel.png"), ExcelO.class); // 导出成Excel 分页分Sheet导出 - public static final WidgetOption EXCELS = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"Excel", "Export-Excel-PageToSheet"}, new String[]{"(", ")"}), + public static final WidgetOption EXCELS = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"Excel", "FR-Designer_Export_Excel_PageToSheet"}, new String[]{"(", ")"}), BaseUtils.readIcon("/com/fr/web/images/excel.png"), ExcelS.class); // 导出成Word diff --git a/designer/src/com/fr/design/widget/CellWidgetCardPane.java b/designer/src/com/fr/design/widget/CellWidgetCardPane.java index 5d4cf74a5..d286cc190 100644 --- a/designer/src/com/fr/design/widget/CellWidgetCardPane.java +++ b/designer/src/com/fr/design/widget/CellWidgetCardPane.java @@ -20,24 +20,28 @@ import java.awt.*; * carl :单独弄出来 */ public class CellWidgetCardPane extends BasicPane { - // 当前的编辑器属性定义面板 + //当前的编辑器属性定义面板 private DataModify currentEditorDefinePane; - + //属性配置切换面板 private JTabbedPane tabbedPane; - private BasicWidgetPropertySettingPane widgetPropertyPane; - private JPanel attriPane; - private JPanel cardPane; - private CardLayout card; - private JPanel presPane; - private JPanel cardPaneForPresent; - private CardLayout cardForPresent; + //通用属性容器 + private JPanel attriTabPane; + private JPanel attriCardPane; + private CardLayout attriCardLayout; - private JPanel cardPaneForTreeSetting; + //数字字典属性容器 + private JPanel dictTabPane; + private JPanel dictCardPane; + private CardLayout dictCardLayout; - private JPanel formPane; - private WidgetEventPane eventTabPane; + //构建树属性容器 + private JPanel treeTabPane; + + //事件属性容器 + private JPanel eventTabPane; + private WidgetEventPane eventPane; public CellWidgetCardPane(ElementCasePane pane) { this.initComponents(pane); @@ -47,26 +51,31 @@ public class CellWidgetCardPane extends BasicPane { this.setLayout(FRGUIPaneFactory.createBorderLayout()); tabbedPane = new UITabbedPane(); this.add(tabbedPane, BorderLayout.CENTER); - attriPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - formPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - eventTabPane = new WidgetEventPane(pane); - formPane.add(eventTabPane, BorderLayout.CENTER); - tabbedPane.add(Inter.getLocText("FR-Designer_Attribute"), attriPane); - tabbedPane.add(Inter.getLocText("FR-Designer_Form_Editing_Listeners"), formPane); + attriTabPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + eventTabPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + eventPane = new WidgetEventPane(pane); + eventTabPane.add(eventPane, BorderLayout.CENTER); + tabbedPane.add(Inter.getLocText("FR-Designer_Attribute"), attriTabPane); + tabbedPane.add(Inter.getLocText("FR-Designer_Form_Editing_Listeners"), eventTabPane); - presPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - cardPaneForPresent = FRGUIPaneFactory.createCardLayout_S_Pane(); - presPane.add(cardPaneForPresent, BorderLayout.CENTER); - cardForPresent = new CardLayout(); - cardPaneForPresent.setLayout(cardForPresent); + dictTabPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + dictCardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); + dictTabPane.add(dictCardPane, BorderLayout.CENTER); + dictCardLayout = new CardLayout(); + dictCardPane.setLayout(dictCardLayout); - cardPaneForTreeSetting = FRGUIPaneFactory.createBorderLayout_L_Pane(); + treeTabPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); widgetPropertyPane = new BasicWidgetPropertySettingPane(); - attriPane.add(widgetPropertyPane, BorderLayout.NORTH); - cardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); - attriPane.add(cardPane, BorderLayout.CENTER); - card = (CardLayout) cardPane.getLayout(); + JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + northPane.setBorder(BorderFactory.createEmptyBorder(5, 8, 0, 8)); + JPanel basic = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_Form_Basic_Properties")); + northPane.add(basic); + basic.add(widgetPropertyPane); + attriTabPane.add(northPane, BorderLayout.NORTH); + attriCardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); + attriTabPane.add(attriCardPane, BorderLayout.CENTER); + attriCardLayout = (CardLayout) attriCardPane.getLayout(); this.setPreferredSize(new Dimension(600, 450)); } @@ -84,49 +93,44 @@ public class CellWidgetCardPane extends BasicPane { this.tabbedPane.setEnabled(true); } - attriPane.remove(widgetPropertyPane); - widgetPropertyPane = new BasicWidgetPropertySettingPane(); - JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - northPane.setBorder(BorderFactory.createEmptyBorder(5, 8, 0, 8)); - JPanel basic = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_Form_Basic_Properties")); - northPane.add(basic); - basic.add(widgetPropertyPane); - attriPane.add(northPane, BorderLayout.NORTH); - WidgetDefinePaneFactory.RN rn = WidgetDefinePaneFactory.createWidgetDefinePane(cellWidget, new Operator() { @Override public void did(DataCreatorUI ui, String cardName) { if (ui == null) { - addPresPane(false); - addTreeSettingPane(false); + removeDictAttriPane(); + removeTreeAttriPane(); } if (ui instanceof DictionaryPane) { + removeDictAttriPane(); + removeTreeAttriPane(); showDictPane(ui, cardName); } else if (ui instanceof TreeSettingPane) { + removeDictAttriPane(); + removeTreeAttriPane(); showTreePane(ui); } } }); DataModify definePane = rn.getDefinePane(); - cardPane.add(definePane.toSwingComponent(), rn.getCardName()); - card.show(cardPane, rn.getCardName()); + attriCardPane.add(definePane.toSwingComponent(), rn.getCardName()); + attriCardLayout.show(attriCardPane, rn.getCardName()); currentEditorDefinePane = definePane; - eventTabPane.populate(cellWidget); + eventPane.populate(cellWidget); widgetPropertyPane.populate(cellWidget); tabbedPane.setSelectedIndex(0); } private void showDictPane(DataCreatorUI ui, String cardName) { - cardPaneForPresent.removeAll(); - cardPaneForPresent.add(ui.toSwingComponent(), cardName); - cardForPresent.show(cardPaneForPresent, cardName); - addPresPane(true); + dictCardPane.removeAll(); + dictCardPane.add(ui.toSwingComponent(), cardName); + dictCardLayout.show(dictCardPane, cardName); + addDictAttriPane(); } private void showTreePane(DataCreatorUI ui) { - cardPaneForTreeSetting.removeAll(); - cardPaneForTreeSetting.add(ui.toSwingComponent()); - addTreeSettingPane(true); + treeTabPane.removeAll(); + treeTabPane.add(ui.toSwingComponent()); + addTreeAttriPane(); } public Widget update() { @@ -139,7 +143,7 @@ public class CellWidgetCardPane extends BasicPane { } widgetPropertyPane.update(widget); - Listener[] listener = eventTabPane == null ? new Listener[0] : eventTabPane.updateListeners(); + Listener[] listener = eventPane == null ? new Listener[0] : eventPane.updateListeners(); widget.clearListeners(); for (Listener l : listener) { widget.addListener(l); @@ -155,25 +159,26 @@ public class CellWidgetCardPane extends BasicPane { */ public void checkValid() throws Exception { currentEditorDefinePane.checkValid(); - eventTabPane.checkValid(); + eventPane.checkValid(); } - //:jackie 如果选择的项有形态,则将形态面板加入tab面板 - private void addPresPane(boolean add) { - if (add) { - tabbedPane.add(this.presPane, 1); - tabbedPane.setTitleAt(1, Inter.getLocText("FR-Designer_DS_Dictionary")); - } else { - tabbedPane.remove(presPane); - } + + private void addDictAttriPane() { + tabbedPane.add(this.dictTabPane, 1); + tabbedPane.setTitleAt(1, Inter.getLocText("FR-Designer_DS_Dictionary")); } - private void addTreeSettingPane(boolean add) { - if (add) { - tabbedPane.add(this.cardPaneForTreeSetting, 1); - tabbedPane.setTitleAt(1, Inter.getLocText("FR-Designer_Create_Tree")); - } else { - tabbedPane.remove(this.cardPaneForTreeSetting); - } + private void addTreeAttriPane() { + tabbedPane.add(this.treeTabPane, 1); + tabbedPane.setTitleAt(1, Inter.getLocText("FR-Designer_Create_Tree")); + } + + private void removeDictAttriPane() { + tabbedPane.remove(this.dictTabPane); } -} \ No newline at end of file + + private void removeTreeAttriPane() { + tabbedPane.remove(this.treeTabPane); + } + +} diff --git a/designer/src/com/fr/design/widget/ui/FieldEditorDefinePane.java b/designer/src/com/fr/design/widget/ui/FieldEditorDefinePane.java index 34c355f51..bb3565c82 100644 --- a/designer/src/com/fr/design/widget/ui/FieldEditorDefinePane.java +++ b/designer/src/com/fr/design/widget/ui/FieldEditorDefinePane.java @@ -20,7 +20,7 @@ import com.fr.form.ui.FieldEditor; import com.fr.general.Inter; public abstract class FieldEditorDefinePane extends AbstractDataModify { - private static final int ALLOW_BLANK_CHECK_BOX_WIDTH = GraphHelper.getLocTextWidth("FR-Designer_Allow_Blank") + 30; + private static final int ALLOW_BLANK_CHECK_BOX_WIDTH = GraphHelper.getLocTextWidth("FR-Designer_Allow_Null") + 30; private static final int ALLOW_BLANK_CHECK_BOX_HEIGHT = 30; private UICheckBox allowBlankCheckBox; // richer:错误信息,是所有控件共有的属性,所以放到这里来 @@ -39,7 +39,7 @@ public abstract class FieldEditorDefinePane extends Abstr initRegErrorMsgTextField(); //JPanel firstPanel = FRGUIPaneFactory.createBorderLayout_M_Pane(); - allowBlankCheckBox = new UICheckBox(Inter.getLocText("FR-Designer_Allow_Blank")); + allowBlankCheckBox = new UICheckBox(Inter.getLocText("FR-Designer_Allow_Null")); allowBlankCheckBox.setPreferredSize(new Dimension(ALLOW_BLANK_CHECK_BOX_WIDTH, ALLOW_BLANK_CHECK_BOX_HEIGHT)); allowBlankCheckBox.addItemListener(new ItemListener() { diff --git a/designer/src/com/fr/design/widget/ui/TextFieldEditorDefinePane.java b/designer/src/com/fr/design/widget/ui/TextFieldEditorDefinePane.java index 1c11aad2e..c9128627c 100644 --- a/designer/src/com/fr/design/widget/ui/TextFieldEditorDefinePane.java +++ b/designer/src/com/fr/design/widget/ui/TextFieldEditorDefinePane.java @@ -61,11 +61,7 @@ public class TextFieldEditorDefinePane extends FieldEditorDefinePane regPane.getRegComboBox().addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { RegExp regExp = (RegExp) regPane.getRegComboBox().getSelectedItem(); - if (!StringUtils.isNotEmpty(regExp.toRegText())) { - getRegErrorMsgTextField().setEnabled(false); - } else { - getRegErrorMsgTextField().setEnabled(true); - } + getRegErrorMsgTextField().setEnabled(regExp.errorMessageEditable()); } }); diff --git a/designer/src/com/fr/grid/Grid.java b/designer/src/com/fr/grid/Grid.java index a259cf63b..178cd085e 100644 --- a/designer/src/com/fr/grid/Grid.java +++ b/designer/src/com/fr/grid/Grid.java @@ -10,6 +10,7 @@ import com.fr.design.constants.UIConstants; import com.fr.design.fun.GridUIProcessor; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.mainframe.templateinfo.TemplateInfoCollector; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; import com.fr.grid.event.CellEditorEvent; @@ -35,6 +36,7 @@ import javax.swing.plaf.ComponentUI; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.geom.Point2D; +import java.util.Date; import java.util.Hashtable; import java.util.Iterator; @@ -1065,6 +1067,13 @@ public class Grid extends BaseGridComponent { } + /** + * @return editingCellElement 的字符串表示 + */ + public String getEditingCellElement() { + return editingCellElement.toString(); + } + /** * 将新值赋给editingCellElement * diff --git a/designer/src/com/fr/grid/selection/CellSelection.java b/designer/src/com/fr/grid/selection/CellSelection.java index c08f87088..458d9fd29 100644 --- a/designer/src/com/fr/grid/selection/CellSelection.java +++ b/designer/src/com/fr/grid/selection/CellSelection.java @@ -18,6 +18,7 @@ import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.imenu.UIMenu; import com.fr.design.gui.imenu.UIPopupMenu; +import com.fr.design.mainframe.CellElementPropertyPane; import com.fr.design.mainframe.ElementCasePane; import com.fr.design.mainframe.ElementCasePane.Clear; import com.fr.design.mainframe.JTemplate; @@ -684,4 +685,9 @@ public class CellSelection extends Selection { editor.populate(tc); return editor; } + + @Override + public void populatePropertyPane(ElementCasePane ePane) { + CellElementPropertyPane.getInstance().reInit(ePane); + } } \ No newline at end of file diff --git a/designer/src/com/fr/grid/selection/FloatSelection.java b/designer/src/com/fr/grid/selection/FloatSelection.java index 0c1b1fcb0..5f0be878c 100644 --- a/designer/src/com/fr/grid/selection/FloatSelection.java +++ b/designer/src/com/fr/grid/selection/FloatSelection.java @@ -20,6 +20,7 @@ import com.fr.design.cell.clipboard.CellElementsClip; import com.fr.design.cell.clipboard.ElementsTransferable; import com.fr.design.cell.clipboard.FloatElementsClip; import com.fr.design.designer.TargetComponent; +import com.fr.design.mainframe.CellElementPropertyPane; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import com.fr.design.mainframe.ElementCasePane; @@ -230,4 +231,9 @@ public class FloatSelection extends Selection { editor.populate(tc); return editor; } + + @Override + public void populatePropertyPane(ElementCasePane ePane) { + CellElementPropertyPane.getInstance().removeAll(); + } } \ No newline at end of file diff --git a/designer/src/com/fr/grid/selection/Selection.java b/designer/src/com/fr/grid/selection/Selection.java index e7466b365..c12dda83b 100644 --- a/designer/src/com/fr/grid/selection/Selection.java +++ b/designer/src/com/fr/grid/selection/Selection.java @@ -87,6 +87,8 @@ public abstract class Selection implements FCloneable, Serializable , Selectable // //////////////////////////Just4CellSelection/////////////////////////////// public abstract boolean containsColumnRow(ColumnRow cr); + + public abstract void populatePropertyPane(ElementCasePane ePane); @Override diff --git a/designer/src/com/fr/poly/hanlder/BottomCornerMouseHanlder.java b/designer/src/com/fr/poly/hanlder/BottomCornerMouseHanlder.java index 729562740..3f063e21d 100644 --- a/designer/src/com/fr/poly/hanlder/BottomCornerMouseHanlder.java +++ b/designer/src/com/fr/poly/hanlder/BottomCornerMouseHanlder.java @@ -161,7 +161,7 @@ public class BottomCornerMouseHanlder extends MouseInputAdapter { * @param isIntersects 是否重叠 */ @Override - public void setWidgetsIntersects(boolean isIntersects) { + public void setWidgetsIntersected(boolean isIntersects) { } /** @@ -170,7 +170,7 @@ public class BottomCornerMouseHanlder extends MouseInputAdapter { * @return 重叠 */ @Override - public boolean getWidgetsIntersects() { + public boolean isWidgetsIntersected() { return false; } diff --git a/designer/src/com/fr/start/ReportSplashPane.java b/designer/src/com/fr/start/ReportSplashPane.java index ab45bc453..5f2f3acd2 100644 --- a/designer/src/com/fr/start/ReportSplashPane.java +++ b/designer/src/com/fr/start/ReportSplashPane.java @@ -4,6 +4,7 @@ package com.fr.start; import com.fr.base.BaseUtils; +import com.fr.base.FRContext; import com.fr.base.GraphHelper; import com.fr.design.mainframe.bbs.BBSConstants; import com.fr.general.GeneralContext; @@ -18,6 +19,7 @@ import java.awt.*; import java.awt.font.FontRenderContext; import java.awt.font.LineMetrics; import java.awt.image.BufferedImage; +import java.util.Locale; import java.util.Random; import java.util.TimerTask; @@ -117,9 +119,22 @@ public class ReportSplashPane extends SplashPane{ GraphHelper.drawString(splashG2d, showText, MODULE_INFO_X, y); //每次随机感谢一位论坛用户 - splashG2d.setPaint(THANK_COLOR); - String content = Inter.getLocText("FR-Designer_Thanks-To") + GUEST; - GraphHelper.drawString(splashG2d, content, THANK_INFO_X, y); + if (shouldShowThanks()) { + splashG2d.setPaint(THANK_COLOR); + String content = Inter.getLocText("FR-Designer_Thanks-To") + GUEST; + GraphHelper.drawString(splashG2d, content, THANK_INFO_X, y); + } + } + + // 是否显示鸣谢文字 + private boolean shouldShowThanks() { + Locale[] hideLocales = {Locale.US, Locale.KOREA, Locale.JAPAN}; + for (Locale loc : hideLocales) { + if (FRContext.getLocale().equals(loc)) { + return false; + } + } + return true; } private static String getRandomUser(){ diff --git a/designer_base/build.dev.gradle b/designer_base/build.dev.gradle index b02f751e7..9b2b65770 100644 --- a/designer_base/build.dev.gradle +++ b/designer_base/build.dev.gradle @@ -1,8 +1,25 @@ - -apply plugin: 'java' tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } + +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} //指定构建的jdk版本 sourceCompatibility=1.7 //指定生成jar包版本 diff --git a/designer_base/build.dev.gradle.bak b/designer_base/build.dev.gradle.bak new file mode 100644 index 000000000..b02f751e7 --- /dev/null +++ b/designer_base/build.dev.gradle.bak @@ -0,0 +1,70 @@ + +apply plugin: 'java' +tasks.withType(JavaCompile){ + options.encoding = 'UTF-8' +} +//指定构建的jdk版本 +sourceCompatibility=1.7 +//指定生成jar包版本 +version='8.0' +//生成jar包重命名 +jar{ + baseName='fr-designer-core' +} + + +def srcDir="." + +//指定源码路径 +sourceSets{ + main{ + java{ + srcDirs=["${srcDir}/src"] + } + } +} +//获取什么分支名 +FileTree files =fileTree(dir:'./',include:'build.*.gradle') +def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('\\')) +buildDir=buildDir.substring(0,buildDir.lastIndexOf ('\\')) +def branchName=buildDir.substring(buildDir.lastIndexOf ('\\')+1) + +//声明外部依赖 +dependencies{ + +compile fileTree(dir:"../../../finereport-lib-stable/${branchName}",include:'**/*.jar') +compile fileTree(dir:'../../../',include:"finereport-*-stable/${branchName}/**/build/libs/*.jar") + + testCompile 'junit:junit:4.12' +} +//复制非.java文件到classes文件夹下参与打包 +task copyFile(type:Copy,dependsOn:compileJava){ + copy{ + from ("${srcDir}/src"){ + exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' + } + into 'build/classes/main' + } + +} + + +//压缩项目中的js文件 +task compressJS{ + ant.taskdef(name:'yuicompress',classname:'com.yahoo.platform.yui.compressor.YUICompressTask'){ + classpath { + fileset(dir:'../../../finereport-lib4build-stable',includes:'**/*.jar') + } + } + ant.yuicompress(linebreak:"500",warn:"false", munge:"yes",preserveallsemicolons:"false",charset:"utf-8",encoding:"utf-8",outputfolder:'build/classes/main'){ + fileset (dir:"${srcDir}/src"){ + include (name:'**/*.js') + include (name:'**/*.css') + } + + } +} +jar.dependsOn compressJS + + + diff --git a/designer_base/build.master.gradle b/designer_base/build.master.gradle index b02f751e7..5220ecebf 100644 --- a/designer_base/build.master.gradle +++ b/designer_base/build.master.gradle @@ -1,8 +1,26 @@ -apply plugin: 'java' tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} + //指定构建的jdk版本 sourceCompatibility=1.7 //指定生成jar包版本 diff --git a/designer_base/build.master.gradle.bak b/designer_base/build.master.gradle.bak new file mode 100644 index 000000000..86cb6ca3e --- /dev/null +++ b/designer_base/build.master.gradle.bak @@ -0,0 +1,89 @@ + +apply plugin: 'java' +tasks.withType(JavaCompile){ + options.encoding = 'UTF-8' +} +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} + +//指定构建的jdk版本 +sourceCompatibility=1.7 +//指定生成jar包版本 +version='8.0' +//生成jar包重命名 +jar{ + baseName='fr-designer-core' +} + + +def srcDir="." + +//指定源码路径 +sourceSets{ + main{ + java{ + srcDirs=["${srcDir}/src"] + } + } +} +//获取什么分支名 +FileTree files =fileTree(dir:'./',include:'build.*.gradle') +def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('\\')) +buildDir=buildDir.substring(0,buildDir.lastIndexOf ('\\')) +def branchName=buildDir.substring(buildDir.lastIndexOf ('\\')+1) + +//声明外部依赖 +dependencies{ + +compile fileTree(dir:"../../../finereport-lib-stable/${branchName}",include:'**/*.jar') +compile fileTree(dir:'../../../',include:"finereport-*-stable/${branchName}/**/build/libs/*.jar") + + testCompile 'junit:junit:4.12' +} +//复制非.java文件到classes文件夹下参与打包 +task copyFile(type:Copy,dependsOn:compileJava){ + copy{ + from ("${srcDir}/src"){ + exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' + } + into 'build/classes/main' + } + +} + + +//压缩项目中的js文件 +task compressJS{ + ant.taskdef(name:'yuicompress',classname:'com.yahoo.platform.yui.compressor.YUICompressTask'){ + classpath { + fileset(dir:'../../../finereport-lib4build-stable',includes:'**/*.jar') + } + } + ant.yuicompress(linebreak:"500",warn:"false", munge:"yes",preserveallsemicolons:"false",charset:"utf-8",encoding:"utf-8",outputfolder:'build/classes/main'){ + fileset (dir:"${srcDir}/src"){ + include (name:'**/*.js') + include (name:'**/*.css') + } + + } +} +jar.dependsOn compressJS + + + diff --git a/designer_base/build.release.gradle b/designer_base/build.release.gradle index 4ed4ba12b..6aa5467c2 100644 --- a/designer_base/build.release.gradle +++ b/designer_base/build.release.gradle @@ -1,8 +1,29 @@ -apply plugin: 'java' tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } + +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' + +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} + + //指定构建的jdk版本 sourceCompatibility=1.8 //指定生成jar包版本 diff --git a/designer_base/src/com/fr/aspectj/designerbase/TemplateProcessTracker.aj b/designer_base/src/com/fr/aspectj/designerbase/TemplateProcessTracker.aj new file mode 100644 index 000000000..61a0be500 --- /dev/null +++ b/designer_base/src/com/fr/aspectj/designerbase/TemplateProcessTracker.aj @@ -0,0 +1,60 @@ +package com.fr.aspectj.designerbase; + +/** + * 记录模板过程 + * Created by plough on 2017/3/3. + */ + +import com.fr.design.mainframe.templateinfo.TemplateInfoCollector; +import org.aspectj.lang.reflect.SourceLocation; + +import java.awt.event.ActionEvent; +import java.awt.event.MouseEvent; +import java.util.Date; + +public aspect TemplateProcessTracker { + //声明一个pointcut,匹配你需要的方法 + pointcut onMouseClicked(MouseEvent e) : + execution(* mouseClicked(MouseEvent)) && args(e); + pointcut onMousePressed(MouseEvent e) : + execution(* mousePressed(MouseEvent)) && args(e); + pointcut onMouseReleased(MouseEvent e) : + execution(* mouseReleased(MouseEvent)) && args(e); + pointcut onActionPerformed(ActionEvent e) : + execution(* actionPerformed(ActionEvent)) && args(e); + pointcut onSetValueAt(Object v, int r, int c) : + execution(* setValueAt(java.lang.Object, int, int)) && args(v, r, c); + + //before表示之前的意思 + //这整个表示在MouseAdapter的public void mouseXXX(MouseEvent)方法调用之前,你想要执行的代码 + before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) { + SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置 + + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; + TemplateInfoCollector.appendProcess(log); + } + //同上 + before(ActionEvent e) : onActionPerformed(e) { + SourceLocation sl = thisJoinPoint.getSourceLocation(); + // !within(LogHandlerBar) 没用, 手动过滤 + if (e.getSource().toString().contains("javax.swing.Timer")) { + return; + } + + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; + TemplateInfoCollector.appendProcess(log); + + } + //同上 + before(Object v, int r, int c) : onSetValueAt(v, r, c) { + SourceLocation sl = thisJoinPoint.getSourceLocation(); + + //String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c); + String log = ""; + TemplateInfoCollector.appendProcess(log); + } + + +} diff --git a/designer_base/src/com/fr/design/actions/edit/CopyAction.java b/designer_base/src/com/fr/design/actions/edit/CopyAction.java index 6f7ec1c4d..d0579a579 100644 --- a/designer_base/src/com/fr/design/actions/edit/CopyAction.java +++ b/designer_base/src/com/fr/design/actions/edit/CopyAction.java @@ -1,37 +1,35 @@ -/* - * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. - */ -package com.fr.design.actions.edit; - -import java.awt.event.KeyEvent; - -import javax.swing.KeyStroke; - -import com.fr.base.BaseUtils; -import com.fr.design.actions.TemplateComponentAction; -import com.fr.design.designer.TargetComponent; -import com.fr.general.Inter; - -/** - * Copy. - */ -public class CopyAction extends TemplateComponentAction { - public CopyAction(TargetComponent t) { - super(t); - - this.setName(Inter.getLocText("M_Edit-Copy")); - this.setMnemonic('C'); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); - this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK)); - } - - @Override - public boolean executeActionReturnUndoRecordNeeded() { - TargetComponent tc = getEditingComponent(); - if (tc != null) { - tc.copy(); - } - - return false; - } +/* + * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.actions.edit; + +import com.fr.base.BaseUtils; +import com.fr.design.actions.TemplateComponentAction; +import com.fr.design.designer.TargetComponent; +import com.fr.general.Inter; + +import javax.swing.*; +import java.awt.event.KeyEvent; + +/** + * Copy. + */ +public class CopyAction extends TemplateComponentAction { + public CopyAction(TargetComponent t) { + super(t); + + this.setName(Inter.getLocText("M_Edit-Copy")); + this.setMnemonic('C'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); + this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK)); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + TargetComponent tc = getEditingComponent(); + if (tc != null) { + tc.copy(); + } + return false; + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/actions/file/LocalePane.java b/designer_base/src/com/fr/design/actions/file/LocalePane.java index 3356fa70a..4dd25c504 100644 --- a/designer_base/src/com/fr/design/actions/file/LocalePane.java +++ b/designer_base/src/com/fr/design/actions/file/LocalePane.java @@ -27,6 +27,8 @@ import com.fr.design.dialog.BasicPane; import com.fr.file.filetree.FileNode; import com.fr.general.*; import com.fr.stable.ArrayUtils; +import com.fr.stable.StringUtils; +import com.fr.stable.bridge.StableFactory; import com.fr.stable.project.ProjectConstants; /** @@ -51,8 +53,8 @@ public class LocalePane extends BasicPane { add(tabbedPane, BorderLayout.CENTER); predefineTableModel = new DefaultTableModel() { - public boolean isCellEditable(int col, int row) { - return false; + public boolean isCellEditable(int row, int column) { + return column == 0; } }; @@ -109,23 +111,39 @@ public class LocalePane extends BasicPane { } private void initPredefinedProperties() { - Map map = Inter.getPredefinedPackageMap(); - LocalePackage chinese = map.get(Locale.SIMPLIFIED_CHINESE); + + Map supportLocaleMap = Inter.getSupportLocaleMap(); + + String[] localeFiles = StableFactory.getLocaleFiles(); + + List sortKeys = new ArrayList(); - Set bundles = chinese.getKindsOfResourceBundle(); - for (ResourceBundle bundle : bundles) { - sortKeys.addAll(bundle.keySet()); + for (String path : localeFiles) { + ResourceBundle chineseBundle = loadResourceBundle(path, Locale.SIMPLIFIED_CHINESE); + sortKeys.addAll(chineseBundle.keySet()); } Collections.sort(sortKeys); + Map> localeResourceBundleMap = new HashMap>(); + for (Map.Entry entry : supportLocaleMap.entrySet()) { + Locale locale = entry.getKey(); + List list = new ArrayList<>(); + for (String path : localeFiles) { + ResourceBundle chineseBundle = loadResourceBundle(path, locale); + list.add(chineseBundle); + } + localeResourceBundleMap.put(locale, list); + } + Map> data = new HashMap>(); - for (Map.Entry entry : map.entrySet()) { + for (Map.Entry> entry : localeResourceBundleMap.entrySet()) { Vector column = new Vector(); + List rbs = entry.getValue(); for (String key : sortKeys) { - column.add(entry.getValue().getLocText(key)); + column.add(readText(rbs, key)); } data.put(entry.getKey(), column); } @@ -140,6 +158,19 @@ public class LocalePane extends BasicPane { } } + private String readText(List rbs, String key) { + for (ResourceBundle rb : rbs) { + if (rb.containsKey(key)) { + return rb.getString(key); + } + } + return null; + } + + private ResourceBundle loadResourceBundle(String dir, Locale locale) { + return ResourceBundle.getBundle(dir, locale, Inter.class.getClassLoader()); + } + private void initCustomProperties() throws Exception { Env env = FRContext.getCurrentEnv(); if (env == null) { @@ -176,22 +207,9 @@ public class LocalePane extends BasicPane { } } - private Properties loadLocaleProperties(String name) { - Properties properties = new Properties(); - InputStream inputStream = IOUtils.readResource("/com/fr/general/locale/" + name); - try { - properties.load(inputStream); - } catch (IOException e) { - FRLogger.getLogger().error(e.getMessage()); - } - return properties; - } - /** * 保存当前编辑的国际化 * - * - * @date 2014-9-30-下午3:10:30 */ public void save() { Env env = FRContext.getCurrentEnv(); diff --git a/designer_base/src/com/fr/design/actions/help/AboutPane.java b/designer_base/src/com/fr/design/actions/help/AboutPane.java index 7f00b5d7c..9c8953597 100644 --- a/designer_base/src/com/fr/design/actions/help/AboutPane.java +++ b/designer_base/src/com/fr/design/actions/help/AboutPane.java @@ -68,10 +68,7 @@ public class AboutPane extends JPanel { Inter.getLocText("FR-Designer-Basic_Activation_Key_Copy_OK") })); - // 英文去掉服务电话和 QQ - if (FRContext.getLocale() == Locale.ENGLISH || FRContext.getLocale() == Locale.US || FRContext.getLocale() == Locale.UK){ - // do nothing - } else { + if (shouldShowPhoneAndQQ()){ if(ComparatorUtils.equals(ProductConstants.APP_NAME,FINEREPORT)){ boxCenterAlignmentPane = new BoxCenterAligmentPane(Inter.getLocText("FR-Designer_Service_Phone") + ProductConstants.COMPARE_TELEPHONE); contentPane.add(boxCenterAlignmentPane); @@ -80,13 +77,29 @@ public class AboutPane extends JPanel { contentPane.add(boxCenterAlignmentPane); } - BoxCenterAligmentPane actionLabel = getURLActionLabel(SiteCenter.getInstance().acquireUrlByKind("website", ProductConstants.WEBSITE_URL)); - BoxCenterAligmentPane emailLabel = getEmailActionLabel(SiteCenter.getInstance().acquireUrlByKind("register.email", ProductConstants.SUPPORT_EMAIL)); + BoxCenterAligmentPane actionLabel = getURLActionLabel(SiteCenter.getInstance().acquireUrlByKind("website." + FRContext.getLocale(), ProductConstants.WEBSITE_URL)); + BoxCenterAligmentPane emailLabel = getEmailActionLabel(SiteCenter.getInstance().acquireUrlByKind("support.email", ProductConstants.SUPPORT_EMAIL)); contentPane.add(actionLabel); contentPane.add(emailLabel); - - addThankPane(contentPane); + if (shouldShowThanks()) { + addThankPane(contentPane); + } + } + + // 是否显示服务电话和 qq + private boolean shouldShowPhoneAndQQ() { + return !FRContext.getLocale().equals(Locale.US); + } + // 是否显示鸣谢面板 + private boolean shouldShowThanks() { + Locale[] hideLocales = {Locale.US, Locale.KOREA, Locale.JAPAN}; + for (Locale loc : hideLocales) { + if (FRContext.getLocale().equals(loc)) { + return false; + } + } + return true; } //添加鸣谢面板 @@ -111,7 +124,7 @@ public class AboutPane extends JPanel { private String getCopyRight(){ return append(Inter.getLocText("FR-Designer_About_CopyRight"), COPYRIGHT_LABEL, - ProductConstants.HISTORY, StringUtils.BLANK, ProductConstants.COMPANY_NAME); + ProductConstants.HISTORY, StringUtils.BLANK, SiteCenter.getInstance().acquireUrlByKind("company.name", ProductConstants.COMPANY_NAME)); } private String getBuildTitle() { diff --git a/designer_base/src/com/fr/design/actions/help/TutorialAction.java b/designer_base/src/com/fr/design/actions/help/TutorialAction.java index b23835945..8ae2b2962 100644 --- a/designer_base/src/com/fr/design/actions/help/TutorialAction.java +++ b/designer_base/src/com/fr/design/actions/help/TutorialAction.java @@ -59,18 +59,20 @@ public class TutorialAction extends UpdateAction { * @param evt 事件 */ public void actionPerformed(ActionEvent evt) { - Locale locale = FRContext.getLocale(); - if (ComparatorUtils.equals(locale, Locale.CHINA) || ComparatorUtils.equals(locale, Locale.TAIWAN)){ - HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("help")); + String helpURL = SiteCenter.getInstance().acquireUrlByKind("help." + FRContext.getLocale()); + + if (helpURL != null) { + HttpClient client = new HttpClient(helpURL); if(client.getResponseCode() != -1) { try { - Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("help"))); + Desktop.getDesktop().browse(new URI(helpURL)); return; } catch (Exception e) { //出了异常的话, 依然打开本地教程 } } } + if (OperatingSystem.isMacOS()) { nativeExcuteMacInstallHomePrograms("helptutorial.app"); } diff --git a/designer_base/src/com/fr/design/actions/server/ConnectionListAction.java b/designer_base/src/com/fr/design/actions/server/ConnectionListAction.java index e24826b50..68e605757 100644 --- a/designer_base/src/com/fr/design/actions/server/ConnectionListAction.java +++ b/designer_base/src/com/fr/design/actions/server/ConnectionListAction.java @@ -1,171 +1,176 @@ -package com.fr.design.actions.server; - -import com.fr.base.BaseUtils; -import com.fr.base.Env; -import com.fr.base.FRContext; -import com.fr.base.ModifiedTable; -import com.fr.data.impl.Connection; -import com.fr.dav.LocalEnv; -import com.fr.design.actions.UpdateAction; -import com.fr.design.data.datapane.connect.ConnectionManagerPane; -import com.fr.design.dialog.BasicDialog; -import com.fr.design.dialog.DialogActionAdapter; -import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.DesignerFrame; -import com.fr.design.menu.MenuKeySet; -import com.fr.file.DatasourceManager; -import com.fr.file.DatasourceManagerProvider; -import com.fr.general.Inter; - -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.util.HashMap; - -/** - * DatasourceList Action - */ -public class ConnectionListAction extends UpdateAction { - private static final int BYTENUM = 1444; - - public ConnectionListAction() { - this.setMenuKeySet(DEFINE_DATA_CONNECTION); - this.setName(getMenuKeySet().getMenuKeySetName()); - this.setMnemonic(getMenuKeySet().getMnemonic()); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_web/connection.png")); - } - - public static final MenuKeySet DEFINE_DATA_CONNECTION = new MenuKeySet() { - @Override - public char getMnemonic() { - return 'D'; - } - - @Override - public String getMenuName() { - return Inter.getLocText("Server-Define_Data_Connection"); - } - - @Override - public KeyStroke getKeyStroke() { - return null; - } - }; - - /** - * 执行动作 - * - * @param evt 事件 - */ - public void actionPerformed(ActionEvent evt) { - DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); - final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); - final DatasourceManager backupManager = datasourceManager.getBackUpManager(); - final ConnectionManagerPane databaseManagerPane = new ConnectionManagerPane() { - public void complete() { - populate(datasourceManager); - } - - protected void renameConnection(String oldName, String newName) { - datasourceManager.getConnectionLocalModifyTable().rename(oldName, newName); - } - }; - final BasicDialog databaseListDialog = databaseManagerPane.showLargeWindow(designerFrame, null); - databaseListDialog.addDialogActionListener(new DialogActionAdapter() { - public void doOk() { - if (!databaseManagerPane.isNamePermitted()) { - databaseListDialog.setDoOKSucceed(false); - return; - } - if (!doWithDatasourceManager(datasourceManager, backupManager, databaseManagerPane, databaseListDialog)) { - //如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面 - return; - } - // marks:保存数据 - writeFile(datasourceManager); - } - - public void doCancel() { - datasourceManager.synchronizedWithServer(); - } - }); - databaseListDialog.setVisible(true); - } - - - private void writeFile(DatasourceManagerProvider datasourceManager) { - Env currentEnv = FRContext.getCurrentEnv(); - try { - boolean isSuccess = currentEnv.writeResource(datasourceManager); - if (!isSuccess) { - throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); - } - } catch (Exception e) { - throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); - } - DesignerContext.getDesignerBean("databasename").refreshBeanElement(); - } - - /** - * 是否正常更新完datasourceManager - * - * @param datasourceManager - * @param databaseManagerPane - * @return - */ - private boolean doWithDatasourceManager(DatasourceManagerProvider datasourceManager, DatasourceManager backupManager, - ConnectionManagerPane databaseManagerPane, BasicDialog databaseListDialog) { - databaseManagerPane.update(datasourceManager); - HashMap modifyDetails = datasourceManager.getConnectionModifyDetails(); - modifyDetails.clear(); - Env currentEnv = FRContext.getCurrentEnv(); - ModifiedTable localModifiedTable = datasourceManager.checkConnectionModifyTable(backupManager, currentEnv.getUserID()); - boolean isFailed = false; - if (currentEnv.isSupportLocalFileOperate() && !((LocalEnv) currentEnv).isNoRemoteUser()) { - //如果是本地,并且有远程用户时则更新自己的修改表 - datasourceManager.updateSelfConnectionTotalModifiedTable(localModifiedTable, ModifiedTable.LOCAL_MODIFIER); - } else { - if (!currentEnv.isSupportLocalFileOperate()) { - //如果是远程,则去取服务器的最新的修改表,检查有没有冲突 - ModifiedTable currentServerModifyTable = currentEnv.getDataSourceModifiedTables(DatasourceManager.CONNECTION); - if (localModifiedTable.checkModifiedTableConflictWithServer(currentServerModifyTable, currentEnv.getUserID())) { - //有冲突,进行提示 - String title = Inter.getLocText(new String[]{"Select", "Single", "Setting"}); - int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), localModifiedTable.getWaringMessage(), title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); - if (returnVal == JOptionPane.YES_OPTION) { - //点击是,进行相应刷新去冲突 - datasourceManager.synchronizedWithServer(backupManager, DatasourceManager.CONNECTION); - //要是有重命名冲突的,则对详细的修改表先进行修改 - datasourceManager.doWithConnectionConflict(localModifiedTable); - localModifiedTable.removeConfilct(); - modifyDetails.clear(); - //更新面板 - databaseManagerPane.populate(datasourceManager); - } else { - //更新失败,继续停留页面 - isFailed = true; - } - - } - } - } - //存在请重命名则不能更新 - int index = datasourceManager.isConnectionMapContainsRename(); - if (index != -1) { - isFailed = true; - databaseManagerPane.setSelectedIndex(index); - } - databaseListDialog.setDoOKSucceed(!isFailed); - //如果修改成功,则去远程端增量修改修改表 - if (!isFailed && !currentEnv.isSupportLocalFileOperate()) { - currentEnv.writeDataSourceModifiedTables(localModifiedTable, DatasourceManager.CONNECTION); - localModifiedTable.clear(); - modifyDetails.clear(); - } - return !isFailed; - } - - - public void update() { - this.setEnabled(true); - } +package com.fr.design.actions.server; + +import com.fr.base.BaseUtils; +import com.fr.base.Env; +import com.fr.base.FRContext; +import com.fr.base.ModifiedTable; +import com.fr.data.impl.Connection; +import com.fr.dav.LocalEnv; +import com.fr.design.actions.UpdateAction; +import com.fr.design.data.datapane.connect.ConnectionManagerPane; +import com.fr.design.data.datapane.connect.ConnectionShowPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrame; +import com.fr.design.menu.MenuKeySet; +import com.fr.file.DatasourceManager; +import com.fr.file.DatasourceManagerProvider; +import com.fr.general.Inter; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.util.HashMap; + +/** + * DatasourceList Action + */ +public class ConnectionListAction extends UpdateAction { + + public ConnectionListAction() { + this.setMenuKeySet(DEFINE_DATA_CONNECTION); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_web/connection.png")); + } + + public static final MenuKeySet DEFINE_DATA_CONNECTION = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'D'; + } + + @Override + public String getMenuName() { + return Inter.getLocText("Server-Define_Data_Connection"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + /** + * 执行动作 + * + * @param evt 事件 + */ + public void actionPerformed(ActionEvent evt) { + DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); + final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); + final DatasourceManager backupManager = datasourceManager.getBackUpManager(); + final ConnectionManagerPane databaseManagerPane = new ConnectionManagerPane() { + public void complete() { + populate(datasourceManager); + } + + protected void renameConnection(String oldName, String newName) { + datasourceManager.getConnectionLocalModifyTable().rename(oldName, newName); + } + }; + final BasicDialog databaseListDialog = databaseManagerPane.showLargeWindow(designerFrame, null); + databaseListDialog.addDialogActionListener(new DialogActionAdapter() { + public void doOk() { + if (!databaseManagerPane.isNamePermitted()) { + databaseListDialog.setDoOKSucceed(false); + return; + } + if (!doWithDatasourceManager(datasourceManager, backupManager, databaseManagerPane, databaseListDialog)) { + //如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面 + return; + } + // marks:保存数据 + writeFile(datasourceManager); + } + + public void doCancel() { + datasourceManager.synchronizedWithServer(); + } + }); + databaseListDialog.setVisible(true); + } + + + /** + * @param datasourceManager + */ + public static void writeFile(DatasourceManagerProvider datasourceManager) { + Env currentEnv = FRContext.getCurrentEnv(); + try { + boolean isSuccess = currentEnv.writeResource(datasourceManager); + if (!isSuccess) { + throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); + } + } catch (Exception e) { + throw new RuntimeException(Inter.getLocText("FR-Designer_Already_exist")); + } + DesignerContext.getDesignerBean("databasename").refreshBeanElement(); + } + + /** + * 更新datasourceManager + * + * @param datasourceManager datasource管理对象 + * @param backupManager datasource管理对象备份 + * @param connectionShowPane datasource面板 + * @param databaseListDialog datasource管理对话框 + * @return boolean 是否更新成功 + */ + public static boolean doWithDatasourceManager(DatasourceManagerProvider datasourceManager, DatasourceManager + backupManager, ConnectionShowPane connectionShowPane, BasicDialog databaseListDialog) { + connectionShowPane.update(datasourceManager); + HashMap modifyDetails = datasourceManager.getConnectionModifyDetails(); + modifyDetails.clear(); + Env currentEnv = FRContext.getCurrentEnv(); + ModifiedTable localModifiedTable = datasourceManager.checkConnectionModifyTable(backupManager, currentEnv.getUserID()); + boolean isFailed = false; + if (currentEnv.isSupportLocalFileOperate() && !((LocalEnv) currentEnv).isNoRemoteUser()) { + //如果是本地,并且有远程用户时则更新自己的修改表 + datasourceManager.updateSelfConnectionTotalModifiedTable(localModifiedTable, ModifiedTable.LOCAL_MODIFIER); + } else { + if (!currentEnv.isSupportLocalFileOperate()) { + //如果是远程,则去取服务器的最新的修改表,检查有没有冲突 + ModifiedTable currentServerModifyTable = currentEnv.getDataSourceModifiedTables(DatasourceManager.CONNECTION); + if (localModifiedTable.checkModifiedTableConflictWithServer(currentServerModifyTable, currentEnv.getUserID())) { + //有冲突,进行提示 + String title = Inter.getLocText(new String[]{"Select", "Single", "Setting"}); + int returnVal = JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), localModifiedTable.getWaringMessage(), title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + if (returnVal == JOptionPane.YES_OPTION) { + //点击是,进行相应刷新去冲突 + datasourceManager.synchronizedWithServer(backupManager, DatasourceManager.CONNECTION); + //要是有重命名冲突的,则对详细的修改表先进行修改 + datasourceManager.doWithConnectionConflict(localModifiedTable); + localModifiedTable.removeConfilct(); + modifyDetails.clear(); + //更新面板 + connectionShowPane.populate(datasourceManager); + } else { + //更新失败,继续停留页面 + isFailed = true; + } + + } + } + } + //存在请重命名则不能更新 + int index = datasourceManager.isConnectionMapContainsRename(); + if (index != -1) { + isFailed = true; + connectionShowPane.setSelectedIndex(index); + } + databaseListDialog.setDoOKSucceed(!isFailed); + //如果修改成功,则去远程端增量修改修改表 + if (!isFailed && !currentEnv.isSupportLocalFileOperate()) { + currentEnv.writeDataSourceModifiedTables(localModifiedTable, DatasourceManager.CONNECTION); + localModifiedTable.clear(); + modifyDetails.clear(); + } + return !isFailed; + } + + + public void update() { + this.setEnabled(true); + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java index 08dc91b07..bd77bfa0c 100644 --- a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java +++ b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java @@ -2,7 +2,7 @@ package com.fr.design.actions.server; import com.fr.base.BaseUtils; import com.fr.design.actions.UpdateAction; -import com.fr.design.extra.WebDialog; +import com.fr.design.extra.WebViewDlgHelper; import com.fr.design.menu.MenuKeySet; import com.fr.general.Inter; @@ -25,7 +25,7 @@ public class PluginManagerAction extends UpdateAction { @Override public void actionPerformed(ActionEvent e) { - WebDialog.createPluginDialog(); + WebViewDlgHelper.createPluginDialog(); } public static final MenuKeySet PLUGIN_MANAGER = new MenuKeySet() { diff --git a/designer_base/src/com/fr/design/beans/location/MoveUtils.java b/designer_base/src/com/fr/design/beans/location/MoveUtils.java index f796768a6..d3dc94a08 100644 --- a/designer_base/src/com/fr/design/beans/location/MoveUtils.java +++ b/designer_base/src/com/fr/design/beans/location/MoveUtils.java @@ -16,10 +16,9 @@ import java.util.ArrayList; public class MoveUtils { public static final int SORPTION_UNIT = 5; + private static final int EQUIDISTANTLINE_UNIT = 4; - public static WidgetForbidWindow widgetForbidWindow = new WidgetForbidWindow(); - - public static ArrayList equidistantLines = new ArrayList<>(); + private static ArrayList equidistantLines = new ArrayList<>(); private MoveUtils() { @@ -77,13 +76,13 @@ public class MoveUtils { * 设置designer内部组件是否重叠的标志位 * @param isIntersects 是否重叠 */ - void setWidgetsIntersects(boolean isIntersects); + void setWidgetsIntersected(boolean isIntersects); /** * 获取designer内部组件是否重叠的标志位 * @return 重叠 */ - boolean getWidgetsIntersects(); + boolean isWidgetsIntersected(); /** * 获取designer相对屏幕的位置 @@ -258,8 +257,7 @@ public class MoveUtils { equidistantLineInfo.setReference(bounds.y); equidistantLineInfo.setDirection(SwingConstants.BOTTOM); } - } - else if ((leftMiddleY > bounds.getY()) && (leftMiddleY < (bounds.getY() + bounds.getHeight()))){ + } else if ((leftMiddleY > bounds.getY()) && (leftMiddleY < (bounds.getY() + bounds.getHeight()))) { //当前操作rec在bounds的右侧 if (left > (bounds.getX() + bounds.getWidth())){ equidistantLineInfo.setDistance(left - (bounds.x + bounds.width)); @@ -278,13 +276,6 @@ public class MoveUtils { } } - public static void displayForbidWindow(int x, int y) { - widgetForbidWindow.showWindow(x, y); - } - - public static void hideForbidWindow() { - widgetForbidWindow.hideWindow(); - } /** * 吸附 @@ -317,25 +308,16 @@ public class MoveUtils { RectangleIterator iterator = designer.createRectangleIterator(); java.util.List cacheRecs = new ArrayList(); - //是否存在控件重叠 - boolean isWidgetsIntersects = false; - while (iterator.hasNext()) { - Rectangle bounds = iterator.nextRectangle(); - cacheRecs.add(bounds); - boolean isIntersects = operatingRectangle.intersects(bounds); - findX(px, bounds, left, right, width); - findY(py, bounds, top, bottom, height); - - if(!isParameterLayout){ - if(isIntersects) { - isWidgetsIntersects = true; - } - else{ - findEquidistantLine(bounds, left, top, height, width); - } - } - } - showForbiddenWindow(designer, x, y, isWidgetsIntersects); + while (iterator.hasNext()) { + Rectangle bounds = iterator.nextRectangle(); + cacheRecs.add(bounds); + findX(px, bounds, left, right, width); + findY(py, bounds, top, bottom, height); + + if (!isParameterLayout) { + findEquidistantLine(bounds, left, top, height, width); + } + } createXAbsorptionline(px, designer, width, cacheRecs); createYAbsorptionline(py, designer, height, cacheRecs); @@ -352,18 +334,6 @@ public class MoveUtils { return sorptionPoint; } - public static void showForbiddenWindow(RectangleDesigner designer, int x, int y, boolean isIntersects){ - if (isIntersects){ - if(designer.getDesignerLocationOnScreen() != null) { - displayForbidWindow(x + designer.getDesignerLocationOnScreen().x, y + designer.getDesignerLocationOnScreen().y); - } - designer.setWidgetsIntersects(true); - } - else{ - designer.setWidgetsIntersects(false); - hideForbidWindow(); - } - } private static void createXAbsorptionline(PlacePointing px, RectangleDesigner designer, int width, java.util.List cacheRecs) { Absorptionline line = null; @@ -479,10 +449,10 @@ public class MoveUtils { } private static void processEquidistantLinesList(PlacePointing pEquidistantX, PlacePointing pEquidistantY, Rectangle operatingRectangle){ - EquidistantLine[] equidistantLines1 = new EquidistantLine[4]; + EquidistantLine[] equidistantLines1 = new EquidistantLine[EQUIDISTANTLINE_UNIT]; //先按方向处理,只保留四个方向上距离最近 for(int count = 0; count < equidistantLines.size(); count++){ - for (int direction = 0; direction < 4; direction++){ + for (int direction = 0; direction < EQUIDISTANTLINE_UNIT; direction++){ if(equidistantLines.get(count).getDirection() == (direction + 1)){//direction 1,2,3,4 分别对应top,left,bottom,right if(equidistantLines1[direction] != null && equidistantLines1[direction].getDistance() > equidistantLines.get(count).getDistance() diff --git a/designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java b/designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java deleted file mode 100644 index acf934e25..000000000 --- a/designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.fr.design.beans.location; - -import com.fr.base.BaseUtils; -import com.fr.design.gui.ibutton.UIButton; -import com.fr.design.icon.IconPathConstants; -import com.fr.general.Inter; - -import javax.swing.*; - -/** - * Created by zhouping on 2016/7/24. - */ -public class WidgetForbidWindow extends JWindow { - - private static final int WIDTH = 150; - private static final int HEIGHT = 20; - - private UIButton promptButton = new UIButton(Inter.getLocText("FR-Designer_Forbid_Widgets_Intersects"), BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); - - /** - * 构造函数 - */ - public WidgetForbidWindow() { - this.add(promptButton); - - this.setSize(WIDTH, HEIGHT); - } - - /** - * 在指定位置显示窗口, 默认将window的中心点放到指定位置上 - * - * @param x x坐标 - * @param y y坐标 - * - */ - public void showWindow(int x, int y){ - this.setLocation(x - WIDTH / 2, y - HEIGHT / 2); - this.setVisible(true); - } - - /** - * 隐藏当前窗口 - * - */ - public void hideWindow(){ - this.setVisible(false); - } -} diff --git a/designer_base/src/com/fr/design/data/DesignTableDataManager.java b/designer_base/src/com/fr/design/data/DesignTableDataManager.java index e0569424d..621e303b1 100644 --- a/designer_base/src/com/fr/design/data/DesignTableDataManager.java +++ b/designer_base/src/com/fr/design/data/DesignTableDataManager.java @@ -36,7 +36,6 @@ import java.io.ByteArrayOutputStream; import java.text.Collator; import java.util.*; import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; /** * 设计器管理操作数据集的类: @@ -59,7 +58,7 @@ public abstract class DesignTableDataManager { private static java.util.Map dsNameChangedMap = new HashMap(); // private static List dsListeners = new ArrayList(); - private static Map> dsListenersMap = new HashMap>(); + private static Map> dsListenersMap = new HashMap>(); public static String NO_PARAMETER = "no_paramater_pane"; @@ -79,7 +78,7 @@ public abstract class DesignTableDataManager { * 响应数据集改变. */ private static void fireDsChanged() { - for(Entry> listenerEntry : dsListenersMap.entrySet()) { + for (Entry> listenerEntry : dsListenersMap.entrySet()) { List dsListeners = listenerEntry.getValue(); for (int i = 0; i < dsListeners.size(); i++) { //增强for循环用的iterator实现的, 如果中间哪个listener修改或删除了(如ChartEditPane.dsChangeListener), @@ -91,8 +90,8 @@ public abstract class DesignTableDataManager { } } - public static void closeTemplate(JTemplate template) { - if(template != null) { + public static void closeTemplate(JTemplate template) { + if (template != null) { dsListenersMap.remove(template.getFullPathName()); } } @@ -151,7 +150,7 @@ public abstract class DesignTableDataManager { public static void addDsChangeListener(ChangeListener l) { JTemplate template = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); String key = StringUtils.EMPTY; - if(template != null) { + if (template != null) { key = template.getFullPathName(); } List dsListeners = dsListenersMap.get(key); @@ -180,7 +179,7 @@ public abstract class DesignTableDataManager { * august:返回当前正在编辑的具有报表数据源的模板(基本报表、聚合报表) 包括 : 图表模板 * * @return TableDataSource - * attention:与这个方法有关系的静态组件(不随着切换模板tab而变化的),应该重新执行该方法,再刷新组件 + * attention:与这个方法有关系的静态组件(不随着切换模板tab而变化的),应该重新执行该方法,再刷新组件 */ public static TableDataSource getEditingTableDataSource() { return DesignModelAdapter.getCurrentModelAdapter() == null ? null : DesignModelAdapter.getCurrentModelAdapter().getBook(); @@ -319,7 +318,6 @@ public abstract class DesignTableDataManager { } - private static void addStoreProcedureData(java.util.Map resMap) { DatasourceManagerProvider mgr = DatasourceManager.getProviderInstance(); String[] namearray = new String[0]; @@ -381,42 +379,34 @@ public abstract class DesignTableDataManager { private static EmbeddedTableData previewTableData(TableData tabledata, int rowCount, boolean isMustInputParameters, boolean needLoadingBar) throws Exception { final AutoProgressBar loadingBar = PreviewTablePane.getInstance().getProgressBar(); Env currentEnv = FRContext.getCurrentEnv(); - EmbeddedTableData embeddedTableData = null; ParameterProvider[] parameters = currentEnv.getTableDataParameters(tabledata); - boolean isNullParameter = parameters == null || parameters.length == 0; - ParameterProvider[] tableDataParameter = tabledata.getParameters(Calculator.createCalculator()); - boolean isOriginalNUllParameter = tableDataParameter == null || tableDataParameter.length == 0; - if (isNullParameter && !isOriginalNUllParameter) { - parameters = tableDataParameter; - } - boolean hasValue = true; - for (ParameterProvider parameter : parameters) { - if (parameter.getValue() == null || ComparatorUtils.equals(StringUtils.EMPTY, parameter.getValue())) { - hasValue = false; - break; - } + if (ArrayUtils.isEmpty(parameters)) { + parameters = tabledata.getParameters(Calculator.createCalculator()); } - final Map parameterMap = new HashMap(); - if (!hasValue || isMustInputParameters) { - if (parameters != null && parameters.length > 0) { - final ParameterInputPane pPane = new ParameterInputPane(parameters); - pPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { - - public void doOk() { - parameterMap.putAll(pPane.update()); - } - }).setVisible(true); - } + final Map parameterMap = new HashMap<>(); + if (needInputParams(isMustInputParameters, parameters)) { + final ParameterInputPane pPane = new ParameterInputPane(parameters); + pPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + @Override + public void doOk() { + parameterMap.putAll(pPane.update()); + } + }).setVisible(true); } else { - for (int i = 0; i < parameters.length; i++) { - parameterMap.put(parameters[i].getName(), parameters[i].getValue()); + for (ParameterProvider parameter : parameters) { + parameterMap.put(parameter.getName(), parameter.getValue()); } } if (loadingBar != null && needLoadingBar) { loadingBar.start(); } try { - embeddedTableData = currentEnv.previewTableData(tabledata, parameterMap, rowCount); + for (ParameterProvider parameter : currentEnv.getTableDataParameters(tabledata)) { + if (parameterMap.containsKey(parameter.getName())) { + parameter.setValue(parameterMap.get(parameter.getName())); + } + } + return currentEnv.previewTableData(tabledata, parameterMap, rowCount); } catch (TableDataException e) { throw new TableDataException(e.getMessage(), e); } finally { @@ -426,7 +416,18 @@ public abstract class DesignTableDataManager { } }, 100); } - return embeddedTableData; + } + + private static boolean needInputParams(boolean mustInputParameters, ParameterProvider[] parameters) { + if (mustInputParameters && ArrayUtils.isNotEmpty(parameters)) { + return true; + } + for (ParameterProvider parameter : parameters) { + if (parameter.getValue() == null || StringUtils.EMPTY.equals(parameter.getValue())) { + return true; + } + } + return false; } /** @@ -495,6 +496,4 @@ public abstract class DesignTableDataManager { public static void setThreadLocal(String value) { threadLocal.set(value); } - - } \ No newline at end of file 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 5a893803c..c8f5ba317 100644 --- a/designer_base/src/com/fr/design/data/datapane/TableDataTreePane.java +++ b/designer_base/src/com/fr/design/data/datapane/TableDataTreePane.java @@ -84,7 +84,7 @@ public class TableDataTreePane extends BasicTableDataTreePane { GeneralContext.addPluginReadListener(new PluginReadListener() { @Override - public void success() { + public void success(Status status) { addMenuDef.clearShortCuts(); createAddMenuDef(); } diff --git a/designer_base/src/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java b/designer_base/src/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java index cc75b7ca2..c80970bd9 100644 --- a/designer_base/src/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java +++ b/designer_base/src/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java @@ -1,128 +1,140 @@ -package com.fr.design.data.datapane.connect; - -import com.fr.base.Env; -import com.fr.base.FRContext; -import com.fr.data.impl.AbstractDatabaseConnection; -import com.fr.data.impl.Connection; -import com.fr.data.impl.NameDatabaseConnection; -import com.fr.design.DesignerEnvManager; -import com.fr.design.dialog.BasicDialog; -import com.fr.design.dialog.DialogActionAdapter; -import com.fr.file.DatasourceManager; -import com.fr.file.DatasourceManagerProvider; -import com.fr.general.ComparatorUtils; -import com.fr.stable.StringUtils; - -import javax.swing.*; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.ArrayList; -import java.util.List; - -/** - * 选择数据连接的下拉框 - * - * @editor zhou - * @since 2012-3-28下午3:02:30 - */ -public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { - /** - * - */ - private static final long serialVersionUID = 1L; - private Class cls; // 所取的Connection都是cls及其子类 - private java.util.List nameList = new ArrayList(); - - public ConnectionComboBoxPanel(Class cls) { - super(); - - this.cls = cls; - - // alex:添加item change监听,当改变时改变DesignerEnvManager中的最近选中的数据连接 - this.itemComboBox.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent e) { - String selected = ConnectionComboBoxPanel.this.getSelectedItem(); - if (StringUtils.isNotBlank(selected)) { - DesignerEnvManager.getEnvManager().setRecentSelectedConnection(selected); - } - } - }); - refreshItems(); - } - - /* - * 刷新ComboBox.items - */ - protected java.util.Iterator items() { - nameList = new ArrayList(); - - DatasourceManagerProvider mgr = DatasourceManager.getProviderInstance(); - java.util.Iterator nameIt = mgr.getConnectionNameIterator(); - while (nameIt.hasNext()) { - String conName = nameIt.next(); - Connection connection = mgr.getConnection(conName); - filterConnection(connection, conName, nameList); - } - - return nameList.iterator(); - } - - protected void filterConnection(Connection connection, String conName, List nameList) { - connection.addConnection(nameList, conName, new Class[]{AbstractDatabaseConnection.class}); - } - - - public int getConnectionSize() { - return nameList.size(); - } - - public String getConnection(int i) { - return nameList.get(i); - } - - /* - * 弹出对话框编辑Items - */ - protected void editItems() { - final ConnectionListPane connectionListPane = new ConnectionListPane(); - final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); - connectionListPane.populate(datasourceManager); - BasicDialog connectionListDialog = connectionListPane.showLargeWindow( - SwingUtilities.getWindowAncestor(ConnectionComboBoxPanel.this), new DialogActionAdapter() { - public void doOk() { - connectionListPane.update(datasourceManager); - // marks:保存数据 - Env currentEnv = FRContext.getCurrentEnv(); - try { - currentEnv.writeResource(datasourceManager); - } catch (Exception ex) { - FRContext.getLogger().error(ex.getMessage(), ex); - } - } - }); - connectionListDialog.setVisible(true); - refreshItems(); - } - - public void populate(com.fr.data.impl.Connection connection) { - editButton.setEnabled(FRContext.getCurrentEnv().isRoot()); - if (connection instanceof NameDatabaseConnection) { - this.setSelectedItem(((NameDatabaseConnection) connection).getName()); - } else { - String s = DesignerEnvManager.getEnvManager().getRecentSelectedConnection(); - if (StringUtils.isNotBlank(s)) { - for (int i = 0; i < this.getConnectionSize(); i++) { - String t = this.getConnection(i); - if (ComparatorUtils.equals(s, t)) { - this.setSelectedItem(s); - break; - } - } - } - // alex:如果这个ComboBox还是没有选中,那么选中第一个 - if (StringUtils.isBlank(this.getSelectedItem()) && this.getConnectionSize() > 0) { - this.setSelectedItem(this.getConnection(0)); - } - } - } +package com.fr.design.data.datapane.connect; + +import com.fr.base.FRContext; +import com.fr.data.impl.AbstractDatabaseConnection; +import com.fr.data.impl.Connection; +import com.fr.data.impl.NameDatabaseConnection; +import com.fr.design.DesignerEnvManager; +import com.fr.design.actions.server.ConnectionListAction; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.file.DatasourceManager; +import com.fr.file.DatasourceManagerProvider; +import com.fr.general.ComparatorUtils; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * 选择数据连接的下拉框 + * + * @editor zhou + * @since 2012-3-28下午3:02:30 + */ +public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel { + /** + * + */ + private static final long serialVersionUID = 1L; + private Class cls; // 所取的Connection都是cls及其子类 + private List nameList = new ArrayList(); + + public ConnectionComboBoxPanel(Class cls) { + super(); + + this.cls = cls; + + // alex:添加item change监听,当改变时改变DesignerEnvManager中的最近选中的数据连接 + this.itemComboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + String selected = ConnectionComboBoxPanel.this.getSelectedItem(); + if (StringUtils.isNotBlank(selected)) { + DesignerEnvManager.getEnvManager().setRecentSelectedConnection(selected); + } + } + }); + refreshItems(); + } + + /* + * 刷新ComboBox.items + */ + protected Iterator items() { + nameList = new ArrayList(); + + DatasourceManagerProvider mgr = DatasourceManager.getProviderInstance(); + Iterator nameIt = mgr.getConnectionNameIterator(); + while (nameIt.hasNext()) { + String conName = nameIt.next(); + Connection connection = mgr.getConnection(conName); + filterConnection(connection, conName, nameList); + } + + return nameList.iterator(); + } + + protected void filterConnection(Connection connection, String conName, List nameList) { + connection.addConnection(nameList, conName, new Class[]{AbstractDatabaseConnection.class}); + } + + public int getConnectionSize() { + return nameList.size(); + } + + public String getConnection(int i) { + return nameList.get(i); + } + + /* + * 弹出对话框编辑Items + */ + protected void editItems() { + final ConnectionListPane connectionListPane = new ConnectionListPane(); + final DatasourceManagerProvider datasourceManager = DatasourceManager.getProviderInstance(); + final DatasourceManager backupManager = datasourceManager.getBackUpManager(); + connectionListPane.populate(datasourceManager); + final BasicDialog connectionListDialog = connectionListPane.showLargeWindow( + SwingUtilities.getWindowAncestor(ConnectionComboBoxPanel.this), null); + connectionListDialog.addDialogActionListener(new DialogActionAdapter() { + public void doOk() { + if (!connectionListPane.isNamePermitted()) { + connectionListDialog.setDoOKSucceed(false); + return; + } + if (!ConnectionListAction.doWithDatasourceManager(datasourceManager, backupManager, connectionListPane, + connectionListDialog)) { + //如果更新失败,则不关闭对话框,也不写xml文件,并且将对话框定位在请重命名的那个对象页面 + return; + } + // marks:保存数据 + ConnectionListAction.writeFile(datasourceManager); + } + + public void doCancel() { + datasourceManager.synchronizedWithServer(); + } + }); + connectionListDialog.setVisible(true); + refreshItems(); + } + + /** + * @param connection 数据库链接 + */ + public void populate(Connection connection) { + editButton.setEnabled(FRContext.getCurrentEnv().isRoot()); + if (connection instanceof NameDatabaseConnection) { + this.setSelectedItem(((NameDatabaseConnection) connection).getName()); + } else { + String s = DesignerEnvManager.getEnvManager().getRecentSelectedConnection(); + if (StringUtils.isNotBlank(s)) { + for (int i = 0; i < this.getConnectionSize(); i++) { + String t = this.getConnection(i); + if (ComparatorUtils.equals(s, t)) { + this.setSelectedItem(s); + break; + } + } + } + // alex:如果这个ComboBox还是没有选中,那么选中第一个 + if (StringUtils.isBlank(this.getSelectedItem()) && this.getConnectionSize() > 0) { + this.setSelectedItem(this.getConnection(0)); + } + } + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/data/datapane/connect/ConnectionListPane.java b/designer_base/src/com/fr/design/data/datapane/connect/ConnectionListPane.java index 8d0f2aa39..1cdf1cb1a 100644 --- a/designer_base/src/com/fr/design/data/datapane/connect/ConnectionListPane.java +++ b/designer_base/src/com/fr/design/data/datapane/connect/ConnectionListPane.java @@ -1,163 +1,163 @@ -package com.fr.design.data.datapane.connect; - -import com.fr.data.impl.Connection; -import com.fr.data.impl.JDBCDatabaseConnection; -import com.fr.data.impl.JNDIDatabaseConnection; -import com.fr.design.ExtraDesignClassManager; -import com.fr.design.fun.ConnectionProvider; -import com.fr.design.gui.controlpane.JListControlPane; -import com.fr.design.gui.controlpane.NameObjectCreator; -import com.fr.design.gui.controlpane.NameableCreator; -import com.fr.file.DatasourceManagerProvider; -import com.fr.general.ComparatorUtils; -import com.fr.general.Inter; -import com.fr.general.NameObject; -import com.fr.stable.ArrayUtils; -import com.fr.stable.Nameable; -import com.fr.stable.StringUtils; -import com.fr.stable.core.PropertyChangeAdapter; - -import javax.swing.*; -import java.util.*; - -/** - * Connection List Pane. - */ -public class ConnectionListPane extends JListControlPane { - public static final String TITLE_NAME = Inter.getLocText("Server-Define_Data_Connection"); - private boolean isNamePermitted = true; - private HashMap renameMap = new HashMap(); - - public ConnectionListPane() { - renameMap.clear(); - this.addEditingListner(new PropertyChangeAdapter() { - public void propertyChange() { - isNamePermitted = true; - String[] allListNames = nameableList.getAllNames(); - allListNames[nameableList.getSelectedIndex()] = StringUtils.EMPTY; - String tempName = getEditingName(); - if (StringUtils.isEmpty(tempName)) { - String[] warning = new String[]{"NOT_NULL_Des", "Please_Rename"}; - String[] sign = new String[]{",", "!"}; - nameableList.stopEditing(); - JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), Inter.getLocText(warning, sign)); - setWarnigText(editingIndex); - isNamePermitted = false; - return; - } - if (!ComparatorUtils.equals(tempName, selectedName) - && isNameRepeted(new List[]{Arrays.asList(allListNames)}, tempName)) { - isNamePermitted = false; - nameableList.stopEditing(); - String message = Inter.getLocText(new String[]{"Utils-has_been_existed", "DashBoard-ConnectionList", "Please_Rename"}, new String[]{"", tempName + ",", "!"}); - JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), message); - setWarnigText(editingIndex); - } - if (isNamePermitted && !ComparatorUtils.equals(tempName, selectedName)) { - rename(selectedName, tempName); - } - - } - }); - } - - - protected void rename(String oldName, String newName) { - if (renameMap.containsKey(selectedName)) { - renameMap.remove(selectedName); - } - renameMap.put(selectedName, newName); - } - - /** - * 名字是否允许 - * - * @return 是/否 - */ - public boolean isNamePermitted() { - return isNamePermitted; - } - - /** - * 检查按钮可用状态 Check button enabled. - */ - public void checkButtonEnabled() { - super.checkButtonEnabled(); - isNamePermitted = !isContainsRename(); - } - - - public HashMap getRenameMap() { - return renameMap; - } - - /** - * 创建菜单项 - * - * @return 菜单项 - */ - public NameableCreator[] createNameableCreators() { - NameableCreator[] creators = new NameableCreator[]{new NameObjectCreator( - "JDBC", - "/com/fr/design/images/data/source/jdbcTableData.png", - JDBCDatabaseConnection.class, - DatabaseConnectionPane.JDBC.class - ), new NameObjectCreator( - "JNDI", - "/com/fr/design/images/data/source/jdbcTableData.png", - JNDIDatabaseConnection.class, - DatabaseConnectionPane.JNDI.class - )}; - Set pluginCreators = ExtraDesignClassManager.getInstance().getArray(ConnectionProvider.XML_TAG); - for (ConnectionProvider provider : pluginCreators) { - NameObjectCreator creator = new NameObjectCreator( - provider.nameForConnection(), - provider.iconPathForConnection(), - provider.classForConnection(), - provider.appearanceForConnection() - ); - creators = ArrayUtils.add(creators, creator); - } - - return creators; - } - - @Override - protected String title4PopupWindow() { - return TITLE_NAME; - } - - /** - * Populate. - * - * @param datasourceManager the new datasourceManager. - */ - public void populate(DatasourceManagerProvider datasourceManager) { - Iterator nameIt = datasourceManager.getConnectionNameIterator(); - - List nameObjectList = new ArrayList(); - while (nameIt.hasNext()) { - String name = nameIt.next(); - nameObjectList.add(new NameObject(name, datasourceManager.getConnection(name))); - } - this.populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); - - } - - /** - * Update. - */ - public void update(DatasourceManagerProvider datasourceManager) { - // Nameable[]居然不能强转成NameObject[],一定要这么写... - Nameable[] res = this.update(); - NameObject[] res_array = new NameObject[res.length]; - java.util.Arrays.asList(res).toArray(res_array); - - datasourceManager.clearAllConnection(); - - for (int i = 0; i < res_array.length; i++) { - NameObject nameObject = res_array[i]; - datasourceManager.putConnection(nameObject.getName(), (Connection) nameObject.getObject()); - } - } +package com.fr.design.data.datapane.connect; + +import com.fr.data.impl.Connection; +import com.fr.data.impl.JDBCDatabaseConnection; +import com.fr.data.impl.JNDIDatabaseConnection; +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.fun.ConnectionProvider; +import com.fr.design.gui.controlpane.JListControlPane; +import com.fr.design.gui.controlpane.NameObjectCreator; +import com.fr.design.gui.controlpane.NameableCreator; +import com.fr.file.DatasourceManagerProvider; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.general.NameObject; +import com.fr.stable.ArrayUtils; +import com.fr.stable.Nameable; +import com.fr.stable.StringUtils; +import com.fr.stable.core.PropertyChangeAdapter; + +import javax.swing.*; +import java.util.*; + +/** + * Connection List Pane. + */ +public class ConnectionListPane extends JListControlPane implements ConnectionShowPane { + public static final String TITLE_NAME = Inter.getLocText("Server-Define_Data_Connection"); + private boolean isNamePermitted = true; + private HashMap renameMap = new HashMap(); + + public ConnectionListPane() { + renameMap.clear(); + this.addEditingListner(new PropertyChangeAdapter() { + public void propertyChange() { + isNamePermitted = true; + String[] allListNames = nameableList.getAllNames(); + allListNames[nameableList.getSelectedIndex()] = StringUtils.EMPTY; + String tempName = getEditingName(); + if (StringUtils.isEmpty(tempName)) { + String[] warning = new String[]{"NOT_NULL_Des", "Please_Rename"}; + String[] sign = new String[]{",", "!"}; + nameableList.stopEditing(); + JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), Inter.getLocText(warning, sign)); + setWarnigText(editingIndex); + isNamePermitted = false; + return; + } + if (!ComparatorUtils.equals(tempName, selectedName) + && isNameRepeted(new List[]{Arrays.asList(allListNames)}, tempName)) { + isNamePermitted = false; + nameableList.stopEditing(); + String message = Inter.getLocText(new String[]{"Utils-has_been_existed", "DashBoard-ConnectionList", "Please_Rename"}, new String[]{"", tempName + ",", "!"}); + JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(ConnectionListPane.this), message); + setWarnigText(editingIndex); + } + if (isNamePermitted && !ComparatorUtils.equals(tempName, selectedName)) { + rename(selectedName, tempName); + } + + } + }); + } + + + protected void rename(String oldName, String newName) { + if (renameMap.containsKey(selectedName)) { + renameMap.remove(selectedName); + } + renameMap.put(selectedName, newName); + } + + /** + * 名字是否允许 + * + * @return 是/否 + */ + public boolean isNamePermitted() { + return isNamePermitted; + } + + /** + * 检查按钮可用状态 Check button enabled. + */ + public void checkButtonEnabled() { + super.checkButtonEnabled(); + isNamePermitted = !isContainsRename(); + } + + + public HashMap getRenameMap() { + return renameMap; + } + + /** + * 创建菜单项 + * + * @return 菜单项 + */ + public NameableCreator[] createNameableCreators() { + NameableCreator[] creators = new NameableCreator[]{new NameObjectCreator( + "JDBC", + "/com/fr/design/images/data/source/jdbcTableData.png", + JDBCDatabaseConnection.class, + DatabaseConnectionPane.JDBC.class + ), new NameObjectCreator( + "JNDI", + "/com/fr/design/images/data/source/jdbcTableData.png", + JNDIDatabaseConnection.class, + DatabaseConnectionPane.JNDI.class + )}; + Set pluginCreators = ExtraDesignClassManager.getInstance().getArray(ConnectionProvider.XML_TAG); + for (ConnectionProvider provider : pluginCreators) { + NameObjectCreator creator = new NameObjectCreator( + provider.nameForConnection(), + provider.iconPathForConnection(), + provider.classForConnection(), + provider.appearanceForConnection() + ); + creators = ArrayUtils.add(creators, creator); + } + + return creators; + } + + @Override + protected String title4PopupWindow() { + return TITLE_NAME; + } + + /** + * Populate. + * + * @param datasourceManager the new datasourceManager. + */ + public void populate(DatasourceManagerProvider datasourceManager) { + Iterator nameIt = datasourceManager.getConnectionNameIterator(); + + List nameObjectList = new ArrayList(); + while (nameIt.hasNext()) { + String name = nameIt.next(); + nameObjectList.add(new NameObject(name, datasourceManager.getConnection(name))); + } + this.populate(nameObjectList.toArray(new NameObject[nameObjectList.size()])); + + } + + /** + * Update. + */ + public void update(DatasourceManagerProvider datasourceManager) { + // Nameable[]居然不能强转成NameObject[],一定要这么写... + Nameable[] res = this.update(); + NameObject[] res_array = new NameObject[res.length]; + java.util.Arrays.asList(res).toArray(res_array); + + datasourceManager.clearAllConnection(); + + for (int i = 0; i < res_array.length; i++) { + NameObject nameObject = res_array[i]; + datasourceManager.putConnection(nameObject.getName(), (Connection) nameObject.getObject()); + } + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/data/datapane/connect/ConnectionManagerPane.java b/designer_base/src/com/fr/design/data/datapane/connect/ConnectionManagerPane.java index ace69ff69..70d4933fa 100644 --- a/designer_base/src/com/fr/design/data/datapane/connect/ConnectionManagerPane.java +++ b/designer_base/src/com/fr/design/data/datapane/connect/ConnectionManagerPane.java @@ -1,78 +1,79 @@ -package com.fr.design.data.datapane.connect; - -import com.fr.base.FRContext; -import com.fr.design.gui.frpane.LoadingBasicPane; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itextfield.UITextField; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.file.DatasourceManagerProvider; -import com.fr.general.Inter; -import com.fr.stable.project.ProjectConstants; - -import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.util.HashMap; - -public class ConnectionManagerPane extends LoadingBasicPane { - private UITextField connectionTextField; - private ConnectionListPane connectionListPane; - - protected void initComponents(JPanel container) { - container.setLayout(FRGUIPaneFactory.createBorderLayout()); - - JPanel connectionPathPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); - container.add(connectionPathPane, BorderLayout.NORTH); - - connectionPathPane.setBorder(BorderFactory.createEmptyBorder(6, 2, 2, 2)); - - connectionPathPane.add(new UILabel(Inter.getLocText("FR-Designer_Save_Path") + ":"), BorderLayout.WEST); - this.connectionTextField = new UITextField(); - connectionPathPane.add(connectionTextField, BorderLayout.CENTER); - this.connectionTextField.setEditable(false); - connectionListPane = new ConnectionListPane(){ - protected void rename(String oldName,String newName) { - super.rename(oldName,newName); - renameConnection(oldName,newName); - } - }; - container.add(connectionListPane, BorderLayout.CENTER); - } - - @Override - protected String title4PopupWindow() { - return Inter.getLocText("Server-Define_Data_Connection"); - } - - public HashMap getRenameMap() { - return connectionListPane.getRenameMap(); - } - - public void populate(DatasourceManagerProvider datasourceManager) { - this.connectionTextField.setText(FRContext.getCurrentEnv().getPath() + File.separator + ProjectConstants.RESOURCES_NAME - + File.separator + datasourceManager.fileName()); - this.connectionListPane.populate(datasourceManager); - } - - public void update(DatasourceManagerProvider datasourceManager) { - this.connectionListPane.update(datasourceManager); - } - - /** - * 设置选中项 - * - * @param index 选中项的序列号 - */ - public void setSelectedIndex(int index) { - this.connectionListPane.setSelectedIndex(index); - } - - /** - * 名字是否允许 - * @return 允许返回true - */ - public boolean isNamePermitted() { - return connectionListPane.isNamePermitted(); - } - +package com.fr.design.data.datapane.connect; + +import com.fr.base.FRContext; +import com.fr.design.gui.frpane.LoadingBasicPane; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.file.DatasourceManagerProvider; +import com.fr.general.Inter; +import com.fr.stable.project.ProjectConstants; + +import javax.swing.*; +import java.awt.*; +import java.io.File; +import java.util.HashMap; + +public class ConnectionManagerPane extends LoadingBasicPane implements ConnectionShowPane { + private UITextField connectionTextField; + private ConnectionListPane connectionListPane; + + protected void initComponents(JPanel container) { + container.setLayout(FRGUIPaneFactory.createBorderLayout()); + + JPanel connectionPathPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + container.add(connectionPathPane, BorderLayout.NORTH); + + connectionPathPane.setBorder(BorderFactory.createEmptyBorder(6, 2, 2, 2)); + + connectionPathPane.add(new UILabel(Inter.getLocText("FR-Designer_Save_Path") + ":"), BorderLayout.WEST); + this.connectionTextField = new UITextField(); + connectionPathPane.add(connectionTextField, BorderLayout.CENTER); + this.connectionTextField.setEditable(false); + connectionListPane = new ConnectionListPane() { + protected void rename(String oldName, String newName) { + super.rename(oldName, newName); + renameConnection(oldName, newName); + } + }; + container.add(connectionListPane, BorderLayout.CENTER); + } + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("Server-Define_Data_Connection"); + } + + public HashMap getRenameMap() { + return connectionListPane.getRenameMap(); + } + + public void populate(DatasourceManagerProvider datasourceManager) { + this.connectionTextField.setText(FRContext.getCurrentEnv().getPath() + File.separator + ProjectConstants.RESOURCES_NAME + + File.separator + datasourceManager.fileName()); + this.connectionListPane.populate(datasourceManager); + } + + public void update(DatasourceManagerProvider datasourceManager) { + this.connectionListPane.update(datasourceManager); + } + + /** + * 设置选中项 + * + * @param index 选中项的序列号 + */ + public void setSelectedIndex(int index) { + this.connectionListPane.setSelectedIndex(index); + } + + /** + * 名字是否允许 + * + * @return 允许返回true + */ + public boolean isNamePermitted() { + return connectionListPane.isNamePermitted(); + } + } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/data/datapane/connect/ConnectionShowPane.java b/designer_base/src/com/fr/design/data/datapane/connect/ConnectionShowPane.java new file mode 100644 index 000000000..ce857ddc6 --- /dev/null +++ b/designer_base/src/com/fr/design/data/datapane/connect/ConnectionShowPane.java @@ -0,0 +1,15 @@ +package com.fr.design.data.datapane.connect; + +import com.fr.file.DatasourceManagerProvider; + +/** + * Created by yaoh.wu on 2017/4/22. + * 数据链接显示面板 + */ +public interface ConnectionShowPane { + void update(DatasourceManagerProvider datasourceManager); + + void populate(DatasourceManagerProvider datasourceManager); + + void setSelectedIndex(int index); +} diff --git a/designer_base/src/com/fr/design/dialog/BasicDialog.java b/designer_base/src/com/fr/design/dialog/BasicDialog.java index 703b19205..bc9ec749d 100644 --- a/designer_base/src/com/fr/design/dialog/BasicDialog.java +++ b/designer_base/src/com/fr/design/dialog/BasicDialog.java @@ -13,6 +13,7 @@ public abstract class BasicDialog extends UIDialog { public static final Dimension CHART = new Dimension(760, 560); public static final Dimension MAP_SIZE = new Dimension(760, 450); public static final Dimension UPDATE_ONLINE_SIZE = new Dimension(600,300); + public static final Dimension TOOLBAR_SIZE = new Dimension(660, 327); public BasicDialog(Frame parent) { super(parent); diff --git a/designer_base/src/com/fr/design/dialog/BasicPane.java b/designer_base/src/com/fr/design/dialog/BasicPane.java index eb1b41305..05c6a84f2 100644 --- a/designer_base/src/com/fr/design/dialog/BasicPane.java +++ b/designer_base/src/com/fr/design/dialog/BasicPane.java @@ -251,6 +251,30 @@ public abstract class BasicPane extends JPanel { return dg; } + /** + * 显示窗口 + * + * @param window 窗口 + * @param l 对话框监听器 + * @return 对话框 + */ + public BasicDialog showToolBarWindow(Window window, DialogActionListener l) { + BasicDialog dg; + if (window instanceof Frame) { + dg = new DIALOG((Frame) window); + } else { + dg = new DIALOG((Dialog) window); + } + + if (l != null) { + dg.addDialogActionListener(l); + } + dg.setBasicDialogSize(BasicDialog.TOOLBAR_SIZE); + GUICoreUtils.centerWindow(dg); + dg.setResizable(false); + return dg; + } + protected abstract String title4PopupWindow(); public String getTitle() { diff --git a/designer_base/src/com/fr/design/dialog/mobile/MobileUseHtmlGroupBeanPane.java b/designer_base/src/com/fr/design/dialog/mobile/MobileUseHtmlGroupBeanPane.java index 5ddf61e56..06666ee57 100644 --- a/designer_base/src/com/fr/design/dialog/mobile/MobileUseHtmlGroupBeanPane.java +++ b/designer_base/src/com/fr/design/dialog/mobile/MobileUseHtmlGroupBeanPane.java @@ -23,11 +23,11 @@ public abstract class MobileUseHtmlGroupBeanPane extends BasicBeanPane { private List radioButtons = new ArrayList(); - public MobileUseHtmlGroupBeanPane() { - initComponents(); + public MobileUseHtmlGroupBeanPane(String annotation) { + initComponents(annotation); } - private void initComponents() { + private void initComponents(String annotation) { this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setBorder(UITitledBorder.createBorderWithTitle(this.title4PopupWindow())); @@ -43,7 +43,7 @@ public abstract class MobileUseHtmlGroupBeanPane extends BasicBeanPane { Component[][] components = new Component[][]{ new Component[]{new UILabel(Inter.getLocText("FR-mobile_analysis_style")), useApp, useHTML5}, - new Component[]{new UILabel(Inter.getLocText("FR-mobile_analysis_annotation")), null, null} + new Component[]{new UILabel(annotation), null, null} }; JPanel usePane = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); usePane.setBorder(BorderFactory.createEmptyBorder(10, 13, 10, 10)); diff --git a/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java b/designer_base/src/com/fr/design/extra/LoginDialog.java similarity index 59% rename from designer/src/com/fr/design/mainframe/bbs/LoginDialog.java rename to designer_base/src/com/fr/design/extra/LoginDialog.java index e3013e487..32d4dca03 100644 --- a/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java +++ b/designer_base/src/com/fr/design/extra/LoginDialog.java @@ -1,32 +1,29 @@ -package com.fr.design.mainframe.bbs; +package com.fr.design.extra; -import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.UIDialog; import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.general.Inter; -import com.fr.general.SiteCenter; -import com.fr.general.http.HttpClient; -import com.fr.stable.StringUtils; +import com.fr.stable.StableUtils; import javax.swing.*; import java.awt.*; /** - * Created by zhaohehe on 16/7/26. + * Created by vito on 2017/5/5. */ public class LoginDialog extends UIDialog { private static final Dimension DEFAULT_SHOP = new Dimension(401, 201); - - public LoginDialog(Frame frame, BasicPane pane) { + + public LoginDialog(Frame frame, Component pane) { super(frame); - setUndecorated(true); + if (StableUtils.getMajorJavaVersion() == 8) { + setUndecorated(true); + } JPanel panel = (JPanel) getContentPane(); panel.setLayout(new BorderLayout()); add(pane, BorderLayout.CENTER); setSize(DEFAULT_SHOP); GUICoreUtils.centerWindow(this); setResizable(false); - setTitle(Inter.getLocText("FR-Designer-Plugin_Manager")); } @Override diff --git a/designer_base/src/com/fr/design/extra/LoginPane.java b/designer_base/src/com/fr/design/extra/LoginPane.java deleted file mode 100644 index 41a2ce8ce..000000000 --- a/designer_base/src/com/fr/design/extra/LoginPane.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.fr.design.extra; - -import com.fr.base.FRContext; -import com.fr.design.DesignerEnvManager; -import com.fr.design.RestartHelper; -import com.fr.design.dialog.BasicPane; -import com.fr.design.gui.frpane.UITabbedPane; -import com.fr.general.ComparatorUtils; -import com.fr.general.IOUtils; -import com.fr.general.Inter; -import com.fr.general.SiteCenter; -import com.fr.general.http.HttpClient; -import com.fr.plugin.PluginVerifyException; -import com.fr.stable.StableUtils; - -import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.concurrent.ExecutionException; - -/** - * Created by zhaohehe on 16/7/27. - */ -public class LoginPane extends BasicPane { - private static final String LATEST = "latest"; - - public LoginPane() { - setLayout(new BorderLayout()); - if (StableUtils.getMajorJavaVersion() == 8) { - String installHome; - if (StableUtils.isDebug()) { - URL url = ClassLoader.getSystemResource(""); - installHome = url.getPath(); - addPane(installHome); - } else { - installHome = StableUtils.getInstallHome(); - File file = new File(StableUtils.pathJoin(installHome, "scripts")); - if (!file.exists()) { - int rv = JOptionPane.showConfirmDialog( - this, - Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.INFORMATION_MESSAGE - ); - if (rv == JOptionPane.OK_OPTION) { - downloadShopScripts(); - } - } else { - addPane(installHome); - updateShopScripts(); - } - } - } else { - initTraditionalStore(); - } - } - - private void addPane(String installHome) { - LoginWebPane webPane = new LoginWebPane(new File(installHome).getAbsolutePath(),LoginPane.this); - add(webPane, BorderLayout.CENTER); - } - - @Override - protected String title4PopupWindow() { - return Inter.getLocText("FR-Designer-Plugin_Manager"); - } - - private void downloadShopScripts() { - new SwingWorker() { - @Override - protected Boolean doInBackground() throws Exception { - String id = "shop_scripts"; - String username = DesignerEnvManager.getEnvManager().getBBSName(); - String password = DesignerEnvManager.getEnvManager().getBBSPassword(); - try { - PluginHelper.downloadPluginFile(id, username, password, new Process() { - @Override - public void process(Double integer) { - } - }); - } catch (PluginVerifyException e) { - JOptionPane.showMessageDialog(LoginPane.this, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - return false; - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - return false; - } - return true; - } - - @Override - protected void done() { - try { - if (get()) { - IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome()); - int rv = JOptionPane.showOptionDialog( - LoginPane.this, - Inter.getLocText("FR-Designer-Plugin_Shop_Installed"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.YES_NO_OPTION, - JOptionPane.INFORMATION_MESSAGE, - null, - new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")}, - null - ); - if (rv == JOptionPane.OK_OPTION) { - RestartHelper.restart(); - } - } - } catch (InterruptedException | ExecutionException e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } - }.execute(); - } - - private void updateShopScripts() { - new SwingWorker() { - @Override - protected Void doInBackground() throws Exception { - HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("store.version") + "&version=" + PluginStoreConstants.VERSION); - if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { - if (!ComparatorUtils.equals(httpClient.getResponseText(), LATEST)) { - int rv = JOptionPane.showConfirmDialog( - LoginPane.this, - Inter.getLocText("FR-Designer-Plugin_Shop_Need_Update"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.INFORMATION_MESSAGE - ); - if (rv == JOptionPane.OK_OPTION) { - downloadShopScripts(); - } - } - } - return null; - } - }.execute(); - } - - private void initTraditionalStore() { - UITabbedPane tabbedPane = new UITabbedPane(); - add(tabbedPane, BorderLayout.CENTER); - PluginInstalledPane installedPane = new PluginInstalledPane(); - tabbedPane.addTab(installedPane.tabTitle(), installedPane); - tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_Update"), new PluginUpdatePane(tabbedPane)); - tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_All_Plugins"), new PluginFromStorePane(tabbedPane)); - } -} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/LoginWebBridge.java b/designer_base/src/com/fr/design/extra/LoginWebBridge.java index 41ed99beb..6592e1601 100644 --- a/designer_base/src/com/fr/design/extra/LoginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/LoginWebBridge.java @@ -6,7 +6,6 @@ import com.fr.design.dialog.UIDialog; import com.fr.design.extra.ucenter.Client; import com.fr.design.extra.ucenter.XMLHelper; import com.fr.design.gui.ilable.UILabel; -import com.fr.design.mainframe.DesignerContext; import com.fr.general.SiteCenter; import com.fr.general.http.HttpClient; import com.fr.json.JSONObject; @@ -14,10 +13,10 @@ import com.fr.stable.EncodeConstants; import com.fr.stable.StringUtils; import javafx.scene.web.WebEngine; -import java.io.UnsupportedEncodingException; -import java.net.URI; import javax.swing.*; import java.awt.*; +import java.io.UnsupportedEncodingException; +import java.net.URI; import java.net.URLEncoder; import java.util.HashMap; import java.util.LinkedList; @@ -47,50 +46,48 @@ public class LoginWebBridge { //用户名,密码为空 private static final String LOGIN_INFO_EMPTY = "-5"; private static final int TIME_OUT = 10000; + private static final String LOGIN_SUCCESS = "ok"; + private static final String LOGIN_FAILED = "failed"; - private static com.fr.design.extra.LoginWebBridge helper; + private static LoginWebBridge helper; + private UILabel pluginuiLabel; private UIDialog uiDialog; + private UIDialog qqDialog; private UILabel uiLabel; private String userName; - public int getMessageCount() { - return messageCount; - } - - /** - * 测试论坛网络连接 - * @return - */ - private boolean testConnection() { - HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test")); - return client.isServerAlive(); + public LoginWebBridge() { + String username = DesignerEnvManager.getEnvManager().getBBSName(); + setUserName(username, uiLabel); } - public static com.fr.design.extra.LoginWebBridge getHelper() { + public static LoginWebBridge getHelper() { if (helper != null) { return helper; } - synchronized (com.fr.design.extra.LoginWebBridge.class) { + synchronized (LoginWebBridge.class) { if (helper == null) { - helper = new com.fr.design.extra.LoginWebBridge(); + helper = new LoginWebBridge(); } return helper; } } - public static com.fr.design.extra.LoginWebBridge getHelper(WebEngine webEngine) { - getHelper(); - helper.setEngine(webEngine); - return helper; + public int getMessageCount() { + return messageCount; } - private WebEngine webEngine; + public void setUILabelInPlugin(UILabel uiLabel) { + this.pluginuiLabel = uiLabel; + } - public void setEngine(WebEngine webEngine) { - this.webEngine = webEngine; + public void setQqDialog(UIDialog qqDialog) { + closeQQWindow(); + this.qqDialog = qqDialog; } public void setDialogHandle(UIDialog uiDialog) { + closeWindow(); this.uiDialog = uiDialog; } @@ -98,50 +95,56 @@ public class LoginWebBridge { this.uiLabel = uiLabel; } - public LoginWebBridge() { - String username = DesignerEnvManager.getEnvManager().getBBSName(); - setUserName(username, uiLabel); - } - /** * 设置显示的用户名 + * * @param userName 登录用户名 - * @param label label显示 + * @param label label显示 */ public void setUserName(String userName, UILabel label) { if (uiLabel == null) { this.uiLabel = label; } - if(StringUtils.isEmpty(userName)){ + if (StringUtils.isEmpty(userName)) { return; } - if(!StringUtils.isEmpty(this.userName)){ + if (StringUtils.isNotEmpty(this.userName)) { updateMessageCount(); } this.userName = userName; } + /** + * 测试论坛网络连接 + * + * @return + */ + private boolean testConnection() { + HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test")); + return client.isServerAlive(); + } + /** * 定时取后台论坛消息 */ - public void updateMessageCount(){ + public void updateMessageCount() { //启动获取消息更新的线程 //登陆状态, 根据存起来的用户名密码, 每1分钟发起一次请求, 更新消息条数. Thread updateMessageThread = new Thread(new Runnable() { @Override public void run() { sleep(CHECK_MESSAGE_TIME); - while(StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())){ + while (StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())) { HashMap para = new HashMap<>(); int uid = DesignerEnvManager.getEnvManager().getBbsUid(); para.put("uid", String.valueOf(uid)); HttpClient getMessage = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.message"), para); getMessage.asGet(); - if(getMessage.isServerAlive()){ + if (getMessage.isServerAlive()) { try { String res = getMessage.getResponseText(); if (res.equals(FAILED_MESSAGE_STATUS)) { - }else { + } else { JSONObject jo = new JSONObject(res); if (jo.getString("status").equals(SUCCESS_MESSAGE_STATUS)) { setMessageCount(Integer.parseInt(jo.getString("message"))); @@ -160,6 +163,7 @@ public class LoginWebBridge { /** * 设置获取的消息长度,并设置显示 + * * @param count */ public void setMessageCount(int count) { @@ -177,7 +181,7 @@ public class LoginWebBridge { uiLabel.setText(sb.toString()); } - private String encode(String str){ + private String encode(String str) { try { return URLEncoder.encode(str, EncodeConstants.ENCODING_UTF_8); } catch (UnsupportedEncodingException e) { @@ -185,7 +189,7 @@ public class LoginWebBridge { } } - private void sleep(long millis){ + private void sleep(long millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { @@ -199,7 +203,7 @@ public class LoginWebBridge { public void registerHref() { try { Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.register"))); - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } } @@ -210,13 +214,14 @@ public class LoginWebBridge { public void forgetHref() { try { Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.reset"))); - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } } /** * 设计器端的用户登录 + * * @param username 用户名 * @param password 密码 * @return 登录信息标志 @@ -227,9 +232,10 @@ public class LoginWebBridge { /** * 插件管理的用户登录部分 + * * @param username 用户名 * @param password 密码 - * @param uiLabel 设计器端的label + * @param uiLabel 设计器端的label * @return 登录信息标志 */ public String pluginManageLogin(String username, String password, UILabel uiLabel) { @@ -238,9 +244,10 @@ public class LoginWebBridge { /** * 登录操作 + * * @param username 用户名 * @param password 密码 - * @param uiLabel 两边的label显示 + * @param uiLabel 两边的label显示 * @return 登录信息标志 */ public String login(String username, String password, UILabel uiLabel) { @@ -271,8 +278,8 @@ public class LoginWebBridge { /** * 更新后台的用户信息 + * * @param username 用户名 - * @param password 密码 */ public void updateUserInfo(String username) { this.userName = username; @@ -280,6 +287,7 @@ public class LoginWebBridge { /** * 关闭窗口并且重新赋值 + * * @param username */ public void loginSuccess(String username, UILabel uiLabel) { @@ -294,13 +302,7 @@ public class LoginWebBridge { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - //弹出qq登录的窗口 - QQLoginPane managerPane = new QQLoginPane(); - UIDialog qqlog = new QQLoginDialog(DesignerContext.getDesignerFrame(),managerPane); - QQLoginWebBridge.getHelper().setDialogHandle(uiDialog); - QQLoginWebBridge.getHelper().setQQDialogHandle(qqlog); - QQLoginWebBridge.getHelper().setUILabel(uiLabel); - qqlog.setVisible(true); + WebViewDlgHelper.createQQLoginDialog(); } }); } @@ -326,12 +328,55 @@ public class LoginWebBridge { } else { return UNKNOWN_ERROR;//未知错误,-3 } - }else { + } else { return NET_FAILED; } - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } return UNKNOWN_ERROR; } + + /** + * 关闭QQ授权窗口 + */ + public void closeQQWindow() { + if (qqDialog != null) { + qqDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + qqDialog.setVisible(false); + } + } + + /** + * 获取用户信息 + * + * @param userInfo + */ + public void getLoginInfo(String userInfo) { + org.json.JSONObject jo = new org.json.JSONObject(userInfo); + String status = jo.get("status").toString(); + if (status.equals(LOGIN_SUCCESS)) { + String username = jo.get("username").toString(); + int uid = Integer.parseInt(jo.get("uid") == null ? "" : jo.get("uid").toString()); + closeWindow(); + closeQQWindow(); + pluginuiLabel.setText(username); + DesignerEnvManager.getEnvManager().setBBSName(username); + DesignerEnvManager.getEnvManager().setBbsUid(uid); + DesignerEnvManager.getEnvManager().setInShowBBsName(username); + } else if (status.equals(LOGIN_FAILED)) { + //账号没有QQ授权 + closeQQWindow(); + try { + Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("QQ_binding"))); + } catch (Exception exp) { + } + } + } + + public void openUrlAtLocalWebBrowser(WebEngine eng, String url) { + if (url.indexOf("qqLogin.html") > 0) { + return; + } + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/LoginWebPane.java b/designer_base/src/com/fr/design/extra/LoginWebPane.java index b49db6ace..ee0a3275a 100644 --- a/designer_base/src/com/fr/design/extra/LoginWebPane.java +++ b/designer_base/src/com/fr/design/extra/LoginWebPane.java @@ -17,11 +17,7 @@ import javax.swing.*; */ public class LoginWebPane extends JFXPanel { - private WebEngine webEngine; - private LoginPane loginPane; - - public LoginWebPane(final String installHome,LoginPane loginPane) { - this.loginPane = loginPane; + public LoginWebPane(final String installHome) { Platform.setImplicitExit(false); Platform.runLater(new Runnable() { @Override @@ -30,7 +26,7 @@ public class LoginWebPane extends JFXPanel { Scene scene = new Scene(root); LoginWebPane.this.setScene(scene); WebView webView = new WebView(); - webEngine = webView.getEngine(); + WebEngine webEngine = webView.getEngine(); webEngine.load("file:///" + installHome + "/scripts/qqLogin/web/login.html"); webEngine.setOnAlert(new EventHandler>() { @Override @@ -39,17 +35,13 @@ public class LoginWebPane extends JFXPanel { } }); JSObject obj = (JSObject) webEngine.executeScript("window"); - obj.setMember("LoginHelper", LoginWebBridge.getHelper(webEngine)); + obj.setMember("LoginHelper", LoginWebBridge.getHelper()); webView.setContextMenuEnabled(false);//屏蔽右键 root.setCenter(webView); } }); } - public void setEngine(WebEngine webEngine) { - this.webEngine = webEngine; - } - private void showAlert(final String message) { SwingUtilities.invokeLater(new Runnable() { @Override diff --git a/designer_base/src/com/fr/design/extra/PluginHelper.java b/designer_base/src/com/fr/design/extra/PluginHelper.java index 119858206..5180af88f 100644 --- a/designer_base/src/com/fr/design/extra/PluginHelper.java +++ b/designer_base/src/com/fr/design/extra/PluginHelper.java @@ -7,6 +7,7 @@ import com.fr.design.extra.plugindependence.DownLoadDependenceUI; import com.fr.general.*; import com.fr.general.http.HttpClient; import com.fr.plugin.Plugin; +import com.fr.plugin.PluginConfigManager; import com.fr.stable.plugin.PluginConstants; import com.fr.plugin.PluginLoader; import com.fr.plugin.PluginManagerHelper; @@ -225,6 +226,8 @@ public class PluginHelper { } // 删除放解压文件的临时文件夹 StableUtils.deleteFile(new File(TEMP_PATH)); + PluginConfigManager.getProviderInstance().pushNewPlugin(plugin); + PluginConfigManager.getProviderInstance().syncPluginConfig(); new SwingWorker() { @Override @@ -256,7 +259,7 @@ public class PluginHelper { if (PluginLoader.getLoader().isInstalled(plugin)) { throw new com.fr.plugin.PluginVerifyException(Inter.getLocText("FR-Designer-Plugin_Has_Been_Installed")); } - if (plugin.isJarExpired()) { + if (plugin.checkIfJarExpired()) { String jarExpiredInfo = Inter.getLocText(new String[]{"FR-Designer-Plugin_Jar_Expired", ",", "FR-Designer-Plugin_Install_Failed", ",", "FR-Designer-Plugin_Please_Update_Jar", plugin.getRequiredJarTime()}); FRLogger.getLogger().error(jarExpiredInfo); throw new com.fr.plugin.PluginVerifyException(jarExpiredInfo); @@ -319,6 +322,8 @@ public class PluginHelper { if (plugin == null || env == null) { return ArrayUtils.EMPTY_STRING_ARRAY; } + //卸载前监听 + plugin.preUninstall(); PluginLoader.getLoader().deletePlugin(plugin); return env.deleteFileFromPluginAndLibFolder(plugin); } diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 12c3e85c4..f1759f016 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -136,6 +136,7 @@ public class PluginWebBridge { } public void setDialogHandle(UIDialog uiDialog) { + closeWindow(); this.uiDialog = uiDialog; } @@ -367,6 +368,7 @@ public class PluginWebBridge { /** * 获取系统登录的用户名 + * * @param callback */ public void getLoginInfo(final JSObject callback) { @@ -381,7 +383,7 @@ public class PluginWebBridge { try { String loginUrl = SiteCenter.getInstance().acquireUrlByKind("bbs.default"); Desktop.getDesktop().browse(new URI(loginUrl)); - }catch (Exception exp) { + } catch (Exception exp) { FRContext.getLogger().info(exp.getMessage()); } } @@ -493,13 +495,14 @@ public class PluginWebBridge { /*-------------------------------登录部分的处理----------------------------------*/ + /** * 注册页面 */ public void registerHref() { try { Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.register"))); - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } } @@ -510,7 +513,7 @@ public class PluginWebBridge { public void forgetHref() { try { Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.reset"))); - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } } @@ -521,6 +524,7 @@ public class PluginWebBridge { /** * 登录操作的回调 + * * @param username * @param password * @return diff --git a/designer_base/src/com/fr/design/extra/QQLoginDialog.java b/designer_base/src/com/fr/design/extra/QQLoginDialog.java index 1a6416174..71224c3a8 100644 --- a/designer_base/src/com/fr/design/extra/QQLoginDialog.java +++ b/designer_base/src/com/fr/design/extra/QQLoginDialog.java @@ -1,6 +1,5 @@ package com.fr.design.extra; -import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.UIDialog; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.Inter; @@ -14,7 +13,7 @@ import java.awt.*; public class QQLoginDialog extends UIDialog { private static final Dimension DEFAULT_SHOP = new Dimension(700, 500); - public QQLoginDialog(Frame frame, BasicPane pane) { + public QQLoginDialog(Frame frame, Component pane) { super(frame); setUndecorated(true); JPanel panel = (JPanel) getContentPane(); @@ -24,7 +23,6 @@ public class QQLoginDialog extends UIDialog { GUICoreUtils.centerWindow(this); setResizable(false); setTitle(Inter.getLocText("FR-Designer-Plugin_Manager")); - } @Override diff --git a/designer_base/src/com/fr/design/extra/QQLoginPane.java b/designer_base/src/com/fr/design/extra/QQLoginPane.java deleted file mode 100644 index 2bbdd7e53..000000000 --- a/designer_base/src/com/fr/design/extra/QQLoginPane.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.fr.design.extra; - -import com.fr.base.FRContext; -import com.fr.design.DesignerEnvManager; -import com.fr.design.RestartHelper; -import com.fr.design.dialog.BasicPane; -import com.fr.general.ComparatorUtils; -import com.fr.general.IOUtils; -import com.fr.general.Inter; -import com.fr.general.SiteCenter; -import com.fr.general.http.HttpClient; -import com.fr.plugin.PluginVerifyException; -import com.fr.stable.StableUtils; - -import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.concurrent.ExecutionException; - -/** - * Created by zhaohehe on 16/7/28. - */ -public class QQLoginPane extends BasicPane { - private static final String LATEST = "latest"; - - public QQLoginPane() { - setLayout(new BorderLayout()); - if (StableUtils.getMajorJavaVersion() == 8) { - String installHome; - if (StableUtils.isDebug()) { - URL url = ClassLoader.getSystemResource(""); - installHome = url.getPath(); - addPane(installHome); - } else { - installHome = StableUtils.getInstallHome(); - File file = new File(StableUtils.pathJoin(installHome, "scripts")); - if (!file.exists()) { - int rv = JOptionPane.showConfirmDialog( - this, - Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.INFORMATION_MESSAGE - ); - if (rv == JOptionPane.OK_OPTION) { - downloadShopScripts(); - } - } else { - addPane(installHome); - updateShopScripts(); - } - } - } else { - } - } - - private void addPane(String installHome) { - QQLoginWebPane webPane = new QQLoginWebPane(new File(installHome).getAbsolutePath()); - add(webPane, BorderLayout.CENTER); - } - - - @Override - protected String title4PopupWindow() { - return Inter.getLocText("FR-Designer-Plugin_Manager"); - } - - - private void downloadShopScripts() { - new SwingWorker() { - @Override - protected Boolean doInBackground() throws Exception { - String id = "shop_scripts"; - String username = DesignerEnvManager.getEnvManager().getBBSName(); - String password = DesignerEnvManager.getEnvManager().getBBSPassword(); - try { - PluginHelper.downloadPluginFile(id, username, password, new Process() { - @Override - public void process(Double integer) { - } - }); - } catch (PluginVerifyException e) { - JOptionPane.showMessageDialog(QQLoginPane.this, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - return false; - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - return false; - } - return true; - } - - @Override - protected void done() { - - try { - if (get()) { - IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome()); - int rv = JOptionPane.showOptionDialog( - QQLoginPane.this, - Inter.getLocText("FR-Designer-Plugin_Shop_Installed"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.YES_NO_OPTION, - JOptionPane.INFORMATION_MESSAGE, - null, - new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")}, - null - ); - if (rv == JOptionPane.OK_OPTION) { - RestartHelper.restart(); - } - } - } catch (InterruptedException | ExecutionException e) { - FRContext.getLogger().error(e.getMessage(), e); - } - - } - }.execute(); - } - - private void updateShopScripts() { - new SwingWorker() { - @Override - protected Void doInBackground() throws Exception { - HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("store.version") + "&version=" + PluginStoreConstants.VERSION); - if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { - if (!ComparatorUtils.equals(httpClient.getResponseText(), LATEST)) { - int rv = JOptionPane.showConfirmDialog( - QQLoginPane.this, - Inter.getLocText("FR-Designer-Plugin_Shop_Need_Update"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.INFORMATION_MESSAGE - ); - if (rv == JOptionPane.OK_OPTION) { - downloadShopScripts(); - } - } - } - return null; - } - }.execute(); - } -} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java b/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java deleted file mode 100644 index d0bcc27e1..000000000 --- a/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.fr.design.extra; - -import com.fr.design.DesignerEnvManager; -import com.fr.design.dialog.UIDialog; -import com.fr.design.gui.ilable.UILabel; -import com.fr.general.FRLogger; -import com.fr.general.SiteCenter; -import javafx.scene.web.WebEngine; -import org.json.JSONObject; -import netscape.javascript.JSObject; - -import javax.swing.*; -import java.awt.*; -import java.io.IOException; -import java.net.URI; - -/** - * Created by lp on 2016/8/10. - */ -public class QQLoginWebBridge { - - private static com.fr.design.extra.QQLoginWebBridge helper; - private WebEngine webEngine; - private static String LOGINSUCCESS = "ok"; - private static String LOGINFAILED = "failed"; - private UIDialog uiDialog; - private UILabel uiLabel; - private UILabel pluginuiLabel; - private UIDialog qqDialog; - private String username; - - - private QQLoginWebBridge() { - } - - public static com.fr.design.extra.QQLoginWebBridge getHelper() { - if (helper != null) { - return helper; - } - synchronized (com.fr.design.extra.QQLoginWebBridge.class) { - if (helper == null) { - helper = new com.fr.design.extra.QQLoginWebBridge(); - } - return helper; - } - } - - public void setEngine(WebEngine webEngine) { - this.webEngine = webEngine; - } - - public void setDialogHandle(UIDialog uiDialog) { - this.uiDialog = uiDialog; - } - - public void setQQDialogHandle(UIDialog uiDialog) { - this.qqDialog = uiDialog; - } - - public void setUILabel(UILabel uiLabel) { - this.uiLabel = uiLabel; - } - - public void setUILabelInPlugin(UILabel uiLabel) { - this.pluginuiLabel = uiLabel; - } - - public void setLoginlabel() { - username = DesignerEnvManager.getEnvManager().getBBSName(); - } - - private static JSObject window; - - public static com.fr.design.extra.QQLoginWebBridge getHelper(WebEngine webEngine) { - getHelper(); - helper.setEngine(webEngine); - return helper; - } - - /** - * 关闭QQ授权窗口 - */ - public void closeQQWindow() { - if (qqDialog != null) { - qqDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - qqDialog.setVisible(false); - } - } - - /** - * 关闭父窗口 - */ - public void closeParentWindow() { - if (uiDialog != null) { - uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - uiDialog.setVisible(false); - } - } - - /** - * 获取用户信息 - * @param userInfo - */ - public void getLoginInfo(String userInfo) { - JSONObject jo = new JSONObject(userInfo); - String status = jo.get("status").toString(); - if (status.equals(LOGINSUCCESS)) { - String username = jo.get("username").toString(); - int uid = Integer.parseInt(jo.get("uid") == null ? "" : jo.get("uid").toString()); - closeQQWindow(); - closeParentWindow(); - pluginuiLabel.setText(username); - DesignerEnvManager.getEnvManager().setBBSName(username); - DesignerEnvManager.getEnvManager().setBbsUid(uid); - DesignerEnvManager.getEnvManager().setInShowBBsName(username); - }else if (status.equals(LOGINFAILED)){ - //账号没有QQ授权 - closeQQWindow(); - try { - Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("QQ_binding"))); - }catch (Exception exp) { - } - } - } - - public void openUrlAtLocalWebBrowser(WebEngine eng, String url) { - if (url.indexOf("qqLogin.html") > 0) { - return; - } - } -} diff --git a/designer_base/src/com/fr/design/extra/QQLoginWebPane.java b/designer_base/src/com/fr/design/extra/QQLoginWebPane.java index 5861bb9ed..f3c96d219 100644 --- a/designer_base/src/com/fr/design/extra/QQLoginWebPane.java +++ b/designer_base/src/com/fr/design/extra/QQLoginWebPane.java @@ -40,6 +40,7 @@ import java.awt.*; public class QQLoginWebPane extends JFXPanel { private WebEngine webEngine; + private String url; private static JSObject window; @@ -50,7 +51,9 @@ public class QQLoginWebPane extends JFXPanel { private static int DEFAULT_CONFIRM_HEIGHT = 160; private static int DEFAULT_OFFEST = 20; - class Delta { double x, y; } + class Delta { + double x, y; + } public QQLoginWebPane(final String installHome) { Platform.setImplicitExit(false); @@ -62,7 +65,8 @@ public class QQLoginWebPane extends JFXPanel { QQLoginWebPane.this.setScene(scene); final WebView webView = new WebView(); webEngine = webView.getEngine(); - webEngine.load("file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html"); + url = "file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html"; + webEngine.load(url); final Stage primaryStage = new Stage(); @@ -76,51 +80,56 @@ public class QQLoginWebPane extends JFXPanel { primaryStage.setX(0); primaryStage.setY(Screen.getPrimary().getBounds().getHeight() + DEFAULT_PRIMARYSTAGE_HEIGHT); primaryStage.show(); - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } - - webView.getEngine().setConfirmHandler(new Callback() { - @Override public Boolean call(String msg) { - Boolean confirmed = confirm(primaryStage, msg, installHome, webView); - return confirmed; - } - }); - - webEngine.locationProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, final String oldValue, String newValue) { - disableLink(webEngine); - // webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转 - if (ComparatorUtils.equals(newValue, "file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html") || ComparatorUtils.equals(newValue, SiteCenter.getInstance().acquireUrlByKind("bbs.mobile"))) { - return; - } - QQLoginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue); - } - }); - webEngine.setOnAlert(new EventHandler>() { + webEngine.setConfirmHandler(new Callback() { @Override - public void handle(WebEvent event) { - showAlert(event.getData()); + public Boolean call(String msg) { + Boolean confirmed = confirm(primaryStage, msg, webView); + return confirmed; } }); - webEngine.getLoadWorker().stateProperty().addListener( - new ChangeListener() { - public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) { - if (newState == Worker.State.SUCCEEDED) { - window = (JSObject) webEngine.executeScript("window"); - window.setMember("QQLoginHelper", QQLoginWebBridge.getHelper(webEngine)); - } - } - } - ); - + configWebEngine(); webView.setContextMenuEnabled(false);//屏蔽右键 root.setCenter(webView); } }); } + private void configWebEngine() { + + webEngine.locationProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, final String oldValue, String newValue) { + disableLink(webEngine); + // webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转 + if (ComparatorUtils.equals(newValue, url) || ComparatorUtils.equals(newValue, SiteCenter.getInstance().acquireUrlByKind("bbs.mobile"))) { + return; + } + LoginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue); + } + }); + + webEngine.setOnAlert(new EventHandler>() { + @Override + public void handle(WebEvent event) { + showAlert(event.getData()); + } + }); + + webEngine.getLoadWorker().stateProperty().addListener( + new ChangeListener() { + public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) { + if (newState == Worker.State.SUCCEEDED) { + window = (JSObject) webEngine.executeScript("window"); + window.setMember("QQLoginHelper", LoginWebBridge.getHelper()); + } + } + } + ); + } + private void showAlert(final String message) { SwingUtilities.invokeLater(new Runnable() { @Override @@ -138,7 +147,7 @@ public class QQLoginWebPane extends JFXPanel { @Override public void run() { eng.executeScript("location.reload()"); - QQLoginWebBridge.getHelper().closeQQWindow(); + LoginWebBridge.getHelper().closeQQWindow(); } }); } catch (Exception e) { @@ -146,12 +155,12 @@ public class QQLoginWebPane extends JFXPanel { } } - private Boolean confirm(final Stage parent, String msg, final String installHome,final WebView webView) { + private Boolean confirm(final Stage parent, String msg, final WebView webView) { final BooleanProperty confirmationResult = new SimpleBooleanProperty(); // initialize the confirmation dialog final Stage dialog = new Stage(StageStyle.UTILITY); - dialog.setX(Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2 - DEFAULT_CONFIRM_WIDTH / 2 + DEFAULT_OFFEST); - dialog.setY(Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2 + DEFAULT_OFFEST); + dialog.setX(Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - DEFAULT_CONFIRM_WIDTH / 2 + DEFAULT_OFFEST); + dialog.setY(Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 + DEFAULT_OFFEST); dialog.setHeight(DEFAULT_CONFIRM_HEIGHT); dialog.setWidth(DEFAULT_CONFIRM_WIDTH); dialog.setIconified(false); @@ -162,7 +171,8 @@ public class QQLoginWebPane extends JFXPanel { HBoxBuilder.create().styleClass("modal-dialog").children( LabelBuilder.create().text(msg).build(), ButtonBuilder.create().text(Inter.getLocText("FR-Designer-BBSLogin_Switch-Account")).defaultButton(true).onAction(new EventHandler() { - @Override public void handle(ActionEvent actionEvent) { + @Override + public void handle(ActionEvent actionEvent) { // take action and close the dialog. confirmationResult.set(true); webView.getEngine().reload(); @@ -170,7 +180,8 @@ public class QQLoginWebPane extends JFXPanel { } }).build(), ButtonBuilder.create().text(Inter.getLocText("FR-Engine_Cancel")).cancelButton(true).onAction(new EventHandler() { - @Override public void handle(ActionEvent actionEvent) { + @Override + public void handle(ActionEvent actionEvent) { // abort action and close the dialog. confirmationResult.set(false); dialog.close(); @@ -180,35 +191,39 @@ public class QQLoginWebPane extends JFXPanel { , Color.TRANSPARENT ) ); + configDrag(dialog); + // style and show the dialog. + dialog.getScene().getStylesheets().add(getClass().getResource("modal-dialog.css").toExternalForm()); + dialog.setOnCloseRequest(new EventHandler() { + @Override + public void handle(WindowEvent event) { + event.consume(); + dialog.close(); + } + }); + dialog.showAndWait(); + return confirmationResult.get(); + } + + private void configDrag(final Stage dialog) { // allow the dialog to be dragged around. final Node root = dialog.getScene().getRoot(); final Delta dragDelta = new Delta(); root.setOnMousePressed(new EventHandler() { - @Override public void handle(MouseEvent mouseEvent) { + @Override + public void handle(MouseEvent mouseEvent) { // record a delta distance for the drag and drop operation. dragDelta.x = dialog.getX() - mouseEvent.getScreenX(); dragDelta.y = dialog.getY() - mouseEvent.getScreenY(); } }); root.setOnMouseDragged(new EventHandler() { - @Override public void handle(MouseEvent mouseEvent) { + @Override + public void handle(MouseEvent mouseEvent) { dialog.setX(mouseEvent.getScreenX() + dragDelta.x); dialog.setY(mouseEvent.getScreenY() + dragDelta.y); } }); - // style and show the dialog. - dialog.getScene().getStylesheets().add(getClass().getResource("modal-dialog.css").toExternalForm()); - - dialog.setOnCloseRequest(new EventHandler(){ - @Override - public void handle(WindowEvent event){ - event.consume(); - dialog.close(); - } - }); - - dialog.showAndWait(); - return confirmationResult.get(); } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/ReuseWebBridge.java b/designer_base/src/com/fr/design/extra/ReuseWebBridge.java deleted file mode 100644 index 413f86275..000000000 --- a/designer_base/src/com/fr/design/extra/ReuseWebBridge.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.fr.design.extra; - -import javafx.scene.web.WebEngine; - -/** - * Created by vito on 2016/9/28. - */ -public class ReuseWebBridge { - public static ReuseWebBridge helper; - private WebEngine webEngine; - - public static ReuseWebBridge getHelper() { - if (helper != null) { - return helper; - } - synchronized (ReuseWebBridge.class) { - if (helper == null) { - helper = new ReuseWebBridge(); - } - return helper; - } - } - - public static ReuseWebBridge getHelper(WebEngine webEngine) { - getHelper(); - helper.setEngine(webEngine); - return helper; - } - - private ReuseWebBridge() { - } - - public void setEngine(WebEngine webEngine) { - this.webEngine = webEngine; - } -} diff --git a/designer_base/src/com/fr/design/extra/ReuseWebPane.java b/designer_base/src/com/fr/design/extra/ReuseWebPane.java deleted file mode 100644 index b48957e0f..000000000 --- a/designer_base/src/com/fr/design/extra/ReuseWebPane.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.fr.design.extra; - -import javafx.application.Platform; -import javafx.embed.swing.JFXPanel; -import javafx.event.EventHandler; -import javafx.scene.Scene; -import javafx.scene.layout.BorderPane; -import javafx.scene.web.WebEngine; -import javafx.scene.web.WebEvent; -import javafx.scene.web.WebView; -import netscape.javascript.JSObject; - -import javax.swing.*; - -/** - * Created by vito on 2016/9/28. - */ -public class ReuseWebPane extends JFXPanel { - private WebEngine webEngine; - - public ReuseWebPane(final String mainJs) { - Platform.setImplicitExit(false); - Platform.runLater(new Runnable() { - @Override - public void run() { - BorderPane root = new BorderPane(); - Scene scene = new Scene(root); - ReuseWebPane.this.setScene(scene); - WebView webView = new WebView(); - webEngine = webView.getEngine(); - webEngine.load("file:///" + mainJs); - webEngine.setOnAlert(new EventHandler>() { - @Override - public void handle(WebEvent event) { - showAlert(event.getData()); - } - }); - JSObject obj = (JSObject) webEngine.executeScript("window"); - obj.setMember("ReuseHelper", ReuseWebBridge.getHelper(webEngine)); - webView.setContextMenuEnabled(false);//屏蔽右键 - root.setCenter(webView); - } - }); - } - - private void showAlert(final String message) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - JOptionPane.showMessageDialog(ReuseWebPane.this, message); - } - }); - } -} diff --git a/designer_base/src/com/fr/design/extra/WebDialog.java b/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java similarity index 75% rename from designer_base/src/com/fr/design/extra/WebDialog.java rename to designer_base/src/com/fr/design/extra/WebViewDlgHelper.java index ed7d73563..481498fc8 100644 --- a/designer_base/src/com/fr/design/extra/WebDialog.java +++ b/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java @@ -24,14 +24,14 @@ import java.util.concurrent.ExecutionException; /** * Created by vito on 2016/9/28. */ -public class WebDialog { +public class WebViewDlgHelper { private static final String LATEST = "latest"; private static final String SHOP_SCRIPTS = "shop_scripts"; private static final int VERSION_8 = 8; + // 调试时,使用installHome = ClassLoader.getSystemResource("").getPath()代替下面 private static String installHome = StableUtils.getInstallHome(); public static void createPluginDialog() { - UIDialog dlg; if (StableUtils.getMajorJavaVersion() >= VERSION_8) { String relativePath = "/scripts/store/web/index.html"; String mainJsPath = StableUtils.pathJoin(new File(installHome).getAbsolutePath(), relativePath); @@ -49,10 +49,7 @@ public class WebDialog { } } else { updateShopScripts(SHOP_SCRIPTS); - BasicPane managerPane = new ShopManagerPane(new PluginWebPane(mainJsPath)); - dlg = new ShopDialog(DesignerContext.getDesignerFrame(), managerPane); - PluginWebBridge.getHelper().setDialogHandle(dlg); - dlg.setVisible(true); + showPluginDlg(mainJsPath); } } else { BasicPane traditionalStorePane = new BasicPane() { @@ -63,21 +60,62 @@ public class WebDialog { }; traditionalStorePane.setLayout(new BorderLayout()); traditionalStorePane.add(initTraditionalStore(), BorderLayout.CENTER); - dlg = new ShopDialog(DesignerContext.getDesignerFrame(), traditionalStorePane); + UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(), traditionalStorePane); dlg.setVisible(true); } } /** * 以关键词打开设计器商店 - *

- * // * @param keyword 关键词 + * + * @param keyword 关键词 */ - public void createPluginDialog(String keyword) { + public static void createPluginDialog(String keyword) { PluginWebBridge.getHelper().openWithSearch(keyword); createPluginDialog(); } + public static void createLoginDialog() { + if (StableUtils.getMajorJavaVersion() == VERSION_8) { + File file = new File(StableUtils.pathJoin(installHome, "scripts")); + if (!file.exists()) { + int rv = JOptionPane.showConfirmDialog( + null, + Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"), + Inter.getLocText("FR-Designer-Plugin_Warning"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.INFORMATION_MESSAGE + ); + if (rv == JOptionPane.OK_OPTION) { + downloadShopScripts(SHOP_SCRIPTS); + } + } else { + showLoginDlg(); + updateShopScripts(SHOP_SCRIPTS); + } + } + } + + public static void createQQLoginDialog() { + QQLoginWebPane webPane = new QQLoginWebPane(new File(installHome).getAbsolutePath()); + UIDialog qqlog = new QQLoginDialog(DesignerContext.getDesignerFrame(), webPane); + LoginWebBridge.getHelper().setQqDialog(qqlog); + qqlog.setVisible(true); + } + + private static void showPluginDlg(String mainJsPath) { + BasicPane managerPane = new ShopManagerPane(new PluginWebPane(mainJsPath)); + UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(), managerPane); + PluginWebBridge.getHelper().setDialogHandle(dlg); + dlg.setVisible(true); + } + + private static void showLoginDlg() { + LoginWebPane webPane = new LoginWebPane(new File(installHome).getAbsolutePath()); + UIDialog qqdlg = new LoginDialog(DesignerContext.getDesignerFrame(), webPane); + LoginWebBridge.getHelper().setDialogHandle(qqdlg); + qqdlg.setVisible(true); + } private static Component initTraditionalStore() { UITabbedPane tabbedPane = new UITabbedPane(); diff --git a/designer_base/src/com/fr/design/formula/FormulaPane.java b/designer_base/src/com/fr/design/formula/FormulaPane.java index d7e3f21be..9ef2e4b2b 100644 --- a/designer_base/src/com/fr/design/formula/FormulaPane.java +++ b/designer_base/src/com/fr/design/formula/FormulaPane.java @@ -22,6 +22,7 @@ import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.Inter; import com.fr.parser.FRLexer; import com.fr.parser.FRParser; +import com.fr.stable.EncodeConstants; import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; import com.fr.stable.script.Expression; @@ -32,16 +33,20 @@ import javax.swing.event.ListSelectionListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.*; + import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.Locale; +import java.util.Set; + /** * 公式编辑面板 + * * @editor zhou * @since 2012-3-29下午1:50:53 */ -public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ +public class FormulaPane extends BasicPane implements KeyListener, UIFormula { protected VariableTreeAndDescriptionArea variableTreeAndDescriptionArea; protected RSyntaxTextArea formulaTextArea; @@ -61,38 +66,26 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ initComponents(); } - protected void initComponents() { - this.setLayout(new BorderLayout(4, 4)); - - // text - JPanel textPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - this.add(textPane, BorderLayout.CENTER); - - JPanel checkBoxandbuttonPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); - - UILabel formulaLabel = new UILabel(Inter.getLocText("FormulaD-Input_formula_in_the_text_area_below") + ":" - + " "); - formulaLabel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); - formulaTextArea = new RSyntaxTextArea(); - configFormulaArea(); + private void initFormulaTextAreaKeyListener() { formulaTextArea.addKeyListener(this); - formulaTextArea.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { formulaTextArea.setForeground(Color.black); String text = formulaTextArea.getText(); // 判断在中文输入状态是否还包含提示符 要删掉 - String tip = "\n\n\n" + Inter.getLocText("Tips:You_Can_Input_B1_To_Input_The_Data_Of_The_First_Row_Second_Column"); - if(text.contains(tip)) { + //Tips:You_Can_Input_B1_To_Input_The_Data_Of_The_First_Row_Second_Column + String tip = "\n\n\n" + Inter.getLocText("FR-Designer_FormulaPane_Tips"); + if (text.contains(tip)) { text = text.substring(0, text.indexOf(tip)); insertPosition = 0; formulaTextArea.setText(text); } } }); + } + private void initFormulaTextAreaMouseListener() { formulaTextArea.addMouseListener(new MouseAdapter() { - @Override public void mousePressed(MouseEvent e) { insertPosition = formulaTextArea.getCaretPosition(); @@ -115,24 +108,17 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ } } }); - UIScrollPane formulaTextAreaScrollPane = new UIScrollPane(formulaTextArea); - formulaTextAreaScrollPane.setBorder(null); - textPane.add(formulaLabel, BorderLayout.NORTH); - textPane.add(formulaTextAreaScrollPane, BorderLayout.CENTER); - textPane.add(checkBoxandbuttonPane, BorderLayout.SOUTH); - - // tipsPane - JPanel tipsPane = new JPanel(new BorderLayout(4, 4)); - this.add(tipsPane, BorderLayout.EAST); + } - JPanel searchPane = new JPanel(new BorderLayout(4, 4)); - searchPane.add(keyWordTextField, BorderLayout.CENTER); - UIButton searchButton = new UIButton(Inter.getLocText("Search")); - searchPane.add(searchButton, BorderLayout.EAST); - tipsPane.add(searchPane, BorderLayout.NORTH); + private void initFormulaTextArea() { + formulaTextArea = new RSyntaxTextArea(); + configFormulaArea(); + initFormulaTextAreaKeyListener(); + initFormulaTextAreaMouseListener(); + } + private void initKeyWordTextFieldKeyListener() { keyWordTextField.addKeyListener(new KeyListener() { - @Override public void keyTyped(KeyEvent e) { } @@ -146,21 +132,59 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ if (e.getKeyCode() == KeyEvent.VK_ENTER) { String toFind = keyWordTextField.getText(); search(toFind, false); - fixFunctionNameList(); e.consume(); } } }); + } + private void initTipsPane() { + // tipsPane + JPanel tipsPane = new JPanel(new BorderLayout(4, 4)); + this.add(tipsPane, BorderLayout.EAST); + + JPanel searchPane = new JPanel(new BorderLayout(4, 4)); + searchPane.add(keyWordTextField, BorderLayout.CENTER); + UIButton searchButton = new UIButton(Inter.getLocText("FR-Designer_FormulaPane_Search")); + searchPane.add(searchButton, BorderLayout.EAST); + tipsPane.add(searchPane, BorderLayout.NORTH); + initKeyWordTextFieldKeyListener(); tipsList = new JList(listModel); tipsList.addMouseListener(new DoubleClick()); UIScrollPane tipsScrollPane = new UIScrollPane(tipsList); tipsScrollPane.setPreferredSize(new Dimension(170, 75)); tipsScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); - tipsPane.add(tipsScrollPane, BorderLayout.CENTER); + searchButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String toFind = keyWordTextField.getText(); + search(toFind, false); + formulaTextArea.requestFocusInWindow(); + fixFunctionNameList(); + } + }); + } + protected void initComponents() { + this.setLayout(new BorderLayout(4, 4)); + // text + JPanel textPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + this.add(textPane, BorderLayout.CENTER); + JPanel checkBoxandbuttonPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + UILabel formulaLabel = new UILabel(Inter.getLocText("FormulaD-Input_formula_in_the_text_area_below") + ":" + + " "); + formulaLabel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); + initFormulaTextArea(); + + UIScrollPane formulaTextAreaScrollPane = new UIScrollPane(formulaTextArea); + formulaTextAreaScrollPane.setBorder(null); + textPane.add(formulaLabel, BorderLayout.NORTH); + textPane.add(formulaTextAreaScrollPane, BorderLayout.CENTER); + textPane.add(checkBoxandbuttonPane, BorderLayout.SOUTH); + + initTipsPane(); UIButton checkValidButton = new UIButton(Inter.getLocText("FormulaD-Check_Valid")); checkValidButton.addActionListener(checkValidActionListener); @@ -169,20 +193,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ checkBoxPane.setPreferredSize(new Dimension(450, 30)); checkBoxandbuttonPane.add(checkBoxPane, BorderLayout.WEST); checkBoxandbuttonPane.add(checkValidButton, BorderLayout.EAST); - extendCheckBoxPane(checkBoxPane); - - searchButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - String toFind = keyWordTextField.getText(); - search(toFind, false); - formulaTextArea.requestFocusInWindow(); - - fixFunctionNameList(); - } - }); variableTreeAndDescriptionArea = new VariableTreeAndDescriptionArea(); this.add(variableTreeAndDescriptionArea, BorderLayout.SOUTH); } @@ -254,10 +265,18 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ } } + //hugh:为啥会是10呢?搞不懂~~~ + private static final int KEY_10 = 10; + //上下左右 + private static final int KEY_37 = 37; + private static final int KEY_38 = 38; + private static final int KEY_39 = 39; + private static final int KEY_40 = 40; + @Override public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); - if (key == 38 || key == 40 || key == 37 || key == 39 || key == 10) //如果是删除符号 ,为了可读性 没有和其他按键的程序相融合 + if (key == KEY_38 || key == KEY_40 || key == KEY_37 || key == KEY_39 || key == KEY_10) //如果是删除符号 ,为了可读性 没有和其他按键的程序相融合 { listModel.removeAllElements(); currentPosition = formulaTextArea.getCaretPosition(); @@ -440,10 +459,10 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ formulaTextArea.requestFocus(); insertPosition = formulaTextArea.getCaretPosition(); } - + @Override protected String title4PopupWindow() { - return Inter.getLocText("FormulaD-Formula_Definition"); + return Inter.getLocText("FormulaD-Formula_Definition"); } /** @@ -461,7 +480,8 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ String content = formula.getContent(); if (content.trim().equals("=")) { this.formulaTextArea.setForeground(Color.gray); - this.formulaTextArea.setText("\n\n\n" + Inter.getLocText("Tips:You_Can_Input_B1_To_Input_The_Data_Of_The_First_Row_Second_Column")); + //Tips:You_Can_Input_B1_To_Input_The_Data_Of_The_First_Row_Second_Column + this.formulaTextArea.setText("\n\n\n" + Inter.getLocText("FR-Designer_FormulaPane_Tips")); this.formulaTextArea.setCaretPosition(0); ifHasBeenWriten = 0; this.listModel.removeAllElements(); @@ -549,71 +569,66 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ this.initComponents(); } - private void initComponents() { - this.setLayout(new BorderLayout(4, 4)); - - // Function - JPanel functionPane = new JPanel(new BorderLayout(4, 4)); - this.add(functionPane, BorderLayout.WEST); - - + private void initFunctionTypeList(JPanel functionPane) { functionTypeList = new QuickList(functionTypeListModel); UIScrollPane functionTypeScrollPane = new UIScrollPane(functionTypeList); functionTypeScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); functionTypeScrollPane.setPreferredSize(new Dimension(140, 200)); functionPane.add(this.createNamePane(Inter.getLocText("FormulaD-Function_category") + ":", functionTypeScrollPane), BorderLayout.WEST); - functionTypeList.setCellRenderer(new DefaultListCellRenderer() { - - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof FunctionGroup) { - this.setText(((FunctionGroup) value).getGroupName()); - } - return this; - } - }); - - functionTypeListModel.addElement(FunctionConstants.COMMON); - for (int i = 0; i < FunctionConstants.EMBFUNCTIONS.length; i++) { - functionTypeListModel.addElement(FunctionConstants.EMBFUNCTIONS[i]); - } - functionTypeListModel.addElement(FunctionConstants.ALL); - functionTypeListModel.addElement(FunctionConstants.CUSTOM); - functionTypeListModel.addElement(FunctionConstants.PLUGIN); + initTypeListCellRenderer(); + initGroupTypeModel(); + initTypeListSelectionListener(); + } + + private void initTypeListCellRenderer() { + functionTypeList.setCellRenderer( + new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (value instanceof FunctionGroup) { + this.setText(((FunctionGroup) value).getGroupName()); + } + return this; + } + }); + } + private void initTypeListSelectionListener() { functionTypeList.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent evt) { Object selectedValue = ((JList) evt.getSource()).getSelectedValue(); if (!(selectedValue instanceof FunctionGroup)) { return; } - NameAndDescription[] nads = ((FunctionGroup) selectedValue).getDescriptions(); functionNameModel = (DefaultListModel) functionNameList.getModel(); - functionNameModel.clear(); - for (NameAndDescription nad : nads) { functionNameModel.addElement(nad); } - if (functionNameModel.size() > 0) { functionNameList.setSelectedIndex(0); functionNameList.ensureIndexIsVisible(0); } } }); + } - functionNameList = new JList(new DefaultListModel()); - UIScrollPane functionNameScrollPane = new UIScrollPane(functionNameList); - functionNameScrollPane.setPreferredSize(new Dimension(140, 200)); - functionPane.add( - this.createNamePane(Inter.getLocText("FormulaD-Function_name") + ":", functionNameScrollPane), - BorderLayout.CENTER); - functionNameScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); + private void initGroupTypeModel() { + functionTypeListModel.addElement(FunctionConstants.COMMON); + for (int i = 0; i < FunctionConstants.EMBFUNCTIONS.length; i++) { + functionTypeListModel.addElement(FunctionConstants.EMBFUNCTIONS[i]); + } + functionTypeListModel.addElement(FunctionConstants.ALL); + functionTypeListModel.addElement(FunctionConstants.CUSTOM); + functionTypeListModel.addElement(FunctionConstants.PLUGIN); + + //hugh: 从函数分组插件中添加分组 + FunctionConstants.addFunctionGroupFromPlugins(functionTypeListModel); + } + private void initFunctionNameListCellRenderer() { functionNameList.setCellRenderer(new DefaultListCellRenderer() { @Override @@ -625,7 +640,9 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ return this; } }); + } + private void initFunctionNameListSelectionListener() { functionNameList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { @@ -640,11 +657,11 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ descriptionTextArea.moveCaretPosition(0); } }); + } + private void initFunctionNameListMouseListener() { functionNameList.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent evt) { - if (evt.getClickCount() >= 2) { Object selectedValue = functionNameList.getSelectedValue(); if (!(selectedValue instanceof NameAndDescription)) { @@ -654,7 +671,6 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ applyText(insert); } - if (SwingUtilities.isRightMouseButton(evt)) { JPopupMenu popupMenu = new JPopupMenu(); LookDetailAction lookDetailAction = new LookDetailAction(); @@ -665,24 +681,28 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ } } }); + } - // vairable. - variablesTree = new JTree(); - UIScrollPane variablesTreePane = new UIScrollPane(variablesTree); - variablesTreePane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); - this.add(this.createNamePane( - Inter.getLocText("Variables") + ":", variablesTreePane), BorderLayout.CENTER); - variablesTree.setRootVisible(false); - variablesTree.setShowsRootHandles(true); - variablesTree.addMouseListener(applyTextMouseListener); - variablesTree.setCellRenderer(applyTreeCellRenderer); + private void initFunctionNameList(JPanel functionPane) { + functionNameList = new JList(new DefaultListModel()); + UIScrollPane functionNameScrollPane = new UIScrollPane(functionNameList); + functionNameScrollPane.setPreferredSize(new Dimension(140, 200)); + functionPane.add( + this.createNamePane(Inter.getLocText("FormulaD-Function_name") + ":", functionNameScrollPane), + BorderLayout.CENTER); + functionNameScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); + initFunctionNameListCellRenderer(); + initFunctionNameListSelectionListener(); + initFunctionNameListMouseListener(); + } + private void initDescriptionTextArea() { // Description descriptionTextArea = new UITextArea(16, 27); UIScrollPane desScrollPane = new UIScrollPane(descriptionTextArea); desScrollPane.setBorder(null); - this.add(this.createNamePane(Inter.getLocText("Formula_Description") + ":", desScrollPane), BorderLayout.EAST); + this.add(this.createNamePane(Inter.getLocText("FR-Designer_FormulaPane_Formula_Description") + ":", desScrollPane), BorderLayout.EAST); descriptionTextArea.setBackground(new Color(255, 255, 225)); descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); @@ -696,19 +716,41 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ } }); - variablesTree.addTreeSelectionListener(new TreeSelectionListener() { + } + + private StringBuilder getText(TextUserObject selectedValue, String path) throws IOException { + Reader desReader; + StringBuilder desBuf = new StringBuilder(); + InputStream desInputStream = BaseUtils.readResource(path + ((TextUserObject) selectedValue).displayText + ".txt"); + if (desInputStream == null) { + String description = ""; + desReader = new StringReader(description); + } else { + desReader = new InputStreamReader(desInputStream, EncodeConstants.ENCODING_UTF_8); + } + BufferedReader reader = new BufferedReader(desReader); + String lineText; + while ((lineText = reader.readLine()) != null) { + if (desBuf.length() > 0) { + desBuf.append('\n'); + } + desBuf.append(lineText); + } + reader.close(); + desReader.close(); + return desBuf; + } + private void initVariablesTreeSelectionListener() { + variablesTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { Object selectedValue = ((DefaultMutableTreeNode) variablesTree.getLastSelectedPathComponent()).getUserObject(); if (selectedValue == null) { return; } - StringBuilder desBuf = new StringBuilder(); try { - Reader desReader; String path; - Locale locale = FRContext.getLocale(); if (locale.equals(Locale.CHINA)) { path = "/com/fr/design/insert/formula/variable/cn/"; @@ -716,43 +758,42 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ path = "/com/fr/design/insert/formula/variable/en/"; } if (selectedValue instanceof TextUserObject) { - - InputStream desInputStream = BaseUtils.readResource(path - + ((TextUserObject) selectedValue).displayText - + ".txt"); - if (desInputStream == null) { - String description = ""; - - desReader = new StringReader(description); - } else { - desReader = new InputStreamReader( - desInputStream); - } - - BufferedReader reader = new BufferedReader( - desReader); - String lineText; - while ((lineText = reader.readLine()) != null) { - if (desBuf.length() > 0) { - desBuf.append('\n'); - } - - desBuf.append(lineText); - } - - reader.close(); - desReader.close(); + desBuf = getText((TextUserObject) selectedValue, path); } } catch (IOException exp) { FRContext.getLogger().error(exp.getMessage(), exp); } - descriptionTextArea.setText(desBuf.toString()); - descriptionTextArea.moveCaretPosition(0); } }); + } + private void initVariablesTree() { + // vairable. + variablesTree = new JTree(); + UIScrollPane variablesTreePane = new UIScrollPane(variablesTree); + variablesTreePane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC)); + this.add(this.createNamePane( + Inter.getLocText("FR-Designer_FormulaPane_Variables") + ":", variablesTreePane), BorderLayout.CENTER); + variablesTree.setRootVisible(false); + variablesTree.setShowsRootHandles(true); + variablesTree.addMouseListener(applyTextMouseListener); + variablesTree.setCellRenderer(applyTreeCellRenderer); + + initDescriptionTextArea(); + + initVariablesTreeSelectionListener(); + } + + private void initComponents() { + this.setLayout(new BorderLayout(4, 4)); + // Function + JPanel functionPane = new JPanel(new BorderLayout(4, 4)); + this.add(functionPane, BorderLayout.WEST); + initFunctionTypeList(functionPane); + initFunctionNameList(functionPane); + initVariablesTree(); // 选择: functionTypeList.setSelectedIndex(0); } @@ -763,7 +804,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ private class LookDetailAction extends UpdateAction { public LookDetailAction() { - this.setName(Inter.getLocText("Function_Detail")); + this.setName(Inter.getLocText("FR-Designer_FormulaPane_Function_Detail")); this.setMnemonic('L'); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_file/preview.png")); } @@ -776,10 +817,10 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ private void showPopupPane() { BasicPane basicPane = new BasicPane() { - @Override - protected String title4PopupWindow() { - return Inter.getLocText("Function_Detail"); - } + @Override + protected String title4PopupWindow() { + return Inter.getLocText("FR-Designer_FormulaPane_Function_Detail"); + } }; basicPane.setLayout(FRGUIPaneFactory.createBorderLayout()); UITextArea desArea = new UITextArea(); @@ -869,52 +910,28 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ rootNode.add(bindCellNode); } - { - MutableTreeNode tableTreeNode = new TextFolderUserObject( - Inter.getLocText("FormulaD-Data_Fields"), - BaseUtils.readIcon("/com/fr/design/images/dialog/table.png"), - variableResolver.resolveColumnNames()).createMutableTreeNode(); + rootNode.add(new TextFolderUserObject(Inter.getLocText("FormulaD-Data_Fields"), + BaseUtils.readIcon("/com/fr/design/images/dialog/table.png"), + variableResolver.resolveColumnNames()).createMutableTreeNode()); - rootNode.add(tableTreeNode); - } + // Set cutReport Variable + rootNode.add(new TextFolderUserObject(Inter.getLocText("FR-Designer_FormulaPane_Variables"), + BaseUtils.readIcon("/com/fr/design/images/dialog/variable.png"), + variableResolver.resolveCurReportVariables()).createMutableTreeNode()); - { - // Set cutReport Variable - rootNode.add(new TextFolderUserObject( - Inter.getLocText("Variables"), - BaseUtils.readIcon("/com/fr/design/images/dialog/variable.png"), - variableResolver.resolveCurReportVariables()).createMutableTreeNode()); - } - - - { - rootNode.add(new TextFolderUserObject( - Inter.getLocText(new String[]{"Datasource-Datasource", "Parameter"}), - BaseUtils.readIcon("/com/fr/design/images/dialog/parameter.gif"), - variableResolver.resolveTableDataParameterVariables()).createMutableTreeNode()); - } + rootNode.add(new TextFolderUserObject(Inter.getLocText(new String[]{"Datasource-Datasource", "Parameter"}), + BaseUtils.readIcon("/com/fr/design/images/dialog/parameter.gif"), + variableResolver.resolveTableDataParameterVariables()).createMutableTreeNode()); + rootNode.add(new TextFolderUserObject(Inter.getLocText("ParameterD-Report_Parameter"), + BaseUtils.readIcon("/com/fr/design/images/m_report/p.gif"), + variableResolver.resolveReportParameterVariables()).createMutableTreeNode()); - { - MutableTreeNode reportParameterTreeNode = new TextFolderUserObject( - Inter.getLocText("ParameterD-Report_Parameter"), - BaseUtils.readIcon("/com/fr/design/images/m_report/p.gif"), - variableResolver.resolveReportParameterVariables()).createMutableTreeNode(); - - rootNode.add(reportParameterTreeNode); - } - - { - MutableTreeNode globalParameterTreeNode = new TextFolderUserObject( - Inter.getLocText("M_Server-Global_Parameters"), - BaseUtils.readIcon("/com/fr/design/images/dialog/parameter.gif"), - variableResolver.resolveGlobalParameterVariables()).createMutableTreeNode(); - rootNode.add(globalParameterTreeNode); - } - + rootNode.add(new TextFolderUserObject(Inter.getLocText("M_Server-Global_Parameters"), + BaseUtils.readIcon("/com/fr/design/images/dialog/parameter.gif"), + variableResolver.resolveGlobalParameterVariables()).createMutableTreeNode()); variableModel.reload(); - // Expand for (int row = 0; row < this.variablesTree.getRowCount(); row++) { this.variablesTree.expandRow(row); @@ -993,6 +1010,6 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula{ buffer.append("|"); buffer.append("\n"); } - System.out.println(buffer.toString()); + FRContext.getLogger().debug(buffer.toString()); } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/formula/FunctionConstants.java b/designer_base/src/com/fr/design/formula/FunctionConstants.java index cfb983dd7..8a0675897 100644 --- a/designer_base/src/com/fr/design/formula/FunctionConstants.java +++ b/designer_base/src/com/fr/design/formula/FunctionConstants.java @@ -11,6 +11,8 @@ import com.fr.stable.EncodeConstants; import com.fr.stable.OperatingSystem; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; +import com.fr.stable.fun.FunctionDefContainer; +import com.fr.stable.fun.mark.Mutable; import com.fr.stable.script.Function; import com.fr.stable.script.FunctionDef; @@ -23,8 +25,49 @@ import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import javax.swing.DefaultListModel; + public abstract class FunctionConstants { + + /** + * 将函数分组插件中的函数添加到对应的列表中 + * @param listModel + */ + public static void addFunctionGroupFromPlugins(DefaultListModel listModel){ + //hugh:自定义函数分组 + Set containers = ExtraClassManager.getInstance().getArray(FunctionDefContainer.MARK_STRING); + if(!containers.isEmpty()){ + for(Mutable container : containers){ + listModel.addElement(createFunctionGroup((FunctionDefContainer)container)); + } + } + } + + /** + * 创建一个新的分组 + * @param container + * @return + */ + private static FunctionGroup createFunctionGroup(final FunctionDefContainer container){ + return new FunctionGroup() { + @Override + public String getGroupName() { + return container.getGroupName(); + } + @Override + public NameAndDescription[] getDescriptions() { + FunctionDef[] fs = container.getFunctionDefs(); + int count = fs.length; + FunctionDefNAD[] nads = new FunctionDefNAD[count]; + for (int i = 0; i < count; i ++) { + nads[i] = new FunctionDefNAD(fs[i]); + } + return nads; + } + }; + } + public static FunctionGroup PLUGIN = new FunctionGroup() { @Override public String getGroupName() { @@ -96,7 +139,13 @@ public abstract class FunctionConstants { } Collections.addAll(all, PLUGIN.getDescriptions()); Collections.addAll(all, CUSTOM.getDescriptions()); - + //hugh:自定义函数分组 + Set containers = ExtraClassManager.getInstance().getArray(FunctionDefContainer.MARK_STRING); + if(!containers.isEmpty()){ + for(Mutable container : containers){ + Collections.addAll(all,createFunctionGroup(((FunctionDefContainer)container)).getDescriptions()); + } + } java.util.Collections.sort(all, NameAndDescriptionComparator); return all.toArray(new NameAndDescription[all.size()]); diff --git a/designer_base/src/com/fr/design/formula/FunctionDefNAD.java b/designer_base/src/com/fr/design/formula/FunctionDefNAD.java index c7c2177b5..715660169 100644 --- a/designer_base/src/com/fr/design/formula/FunctionDefNAD.java +++ b/designer_base/src/com/fr/design/formula/FunctionDefNAD.java @@ -6,7 +6,7 @@ import com.fr.stable.StringUtils; public class FunctionDefNAD extends AbstractNameAndDescription { private FunctionDef def; - FunctionDefNAD(FunctionDef def) { + public FunctionDefNAD(FunctionDef def) { this.def = def; } diff --git a/designer_base/src/com/fr/design/formula/FunctionManagerPane.java b/designer_base/src/com/fr/design/formula/FunctionManagerPane.java index 3fffe594e..001bd5626 100644 --- a/designer_base/src/com/fr/design/formula/FunctionManagerPane.java +++ b/designer_base/src/com/fr/design/formula/FunctionManagerPane.java @@ -20,6 +20,7 @@ import com.fr.file.FunctionManagerProvider; import com.fr.general.Inter; import com.fr.general.NameObject; import com.fr.stable.Nameable; +import com.fr.stable.ProductConstants; import com.fr.stable.project.ProjectConstants; import com.fr.stable.script.FunctionDef; @@ -159,10 +160,11 @@ public class FunctionManagerPane extends BasicPane { descriptionArea.setWrapStyleWord(true); descriptionArea.setLineWrap(true); northPane.add(descriptionArea); - descriptionArea.setText(Inter.getLocText(new String[]{"Function-The_class_must_inherit","Fuction-The_compiled_class_should_be_copied_to", - "Function-J2EE_server", "Directory", "Function-Source_Code", "Example"}, - new String[]{" \"com.fr.script.AbstractFunction\".", "\n", " \"" + File.separator + "WEB-INF" + File.separator + "classes\"", - ",", ".\n", ":" + FRContext.getCurrentEnv().getPath() + File.separator + "classes"})); + + String path1 = getEscapePath(File.separator + ProjectConstants.WEBINF_NAME + File.separator + ProjectConstants.CLASSES_NAME); + String path2 = getEscapePath(FRContext.getCurrentEnv().getPath() + File.separator + ProjectConstants.CLASSES_NAME); + descriptionArea.setText(Inter.getLocText("FR-Designer_Function_Description_Area_Text", path1, path2)); + JPanel descriptionPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); //Description Pane this.add(descriptionPane, BorderLayout.SOUTH); descriptionPane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); @@ -170,6 +172,10 @@ public class FunctionManagerPane extends BasicPane { this.descriptionTextArea = new UITextArea(6, 24); descriptionPane.add(new JScrollPane(this.descriptionTextArea), BorderLayout.CENTER); } + + private String getEscapePath(String path) { + return path.replace("\\", "\\\\"); + } private ActionListener createEditorButtonActionListener() { return new ActionListener() { diff --git a/designer_base/src/com/fr/design/formula/VariableResolverAdapter.java b/designer_base/src/com/fr/design/formula/VariableResolverAdapter.java index eb80600ac..623b1cbf4 100644 --- a/designer_base/src/com/fr/design/formula/VariableResolverAdapter.java +++ b/designer_base/src/com/fr/design/formula/VariableResolverAdapter.java @@ -4,12 +4,16 @@ import com.fr.base.ConfigManager; import com.fr.base.Parameter; import com.fr.design.DesignModelAdapter; import com.fr.base.ConfigManagerProvider; +import com.fr.plugin.ExtraClassManager; import com.fr.script.ScriptConstants; +import com.fr.stable.ArrayUtils; import com.fr.stable.Constants; +import com.fr.stable.fun.BuiltInParametersProvider; import com.fr.stable.script.CalculatorProvider; import java.util.ArrayList; import java.util.List; +import java.util.Set; public abstract class VariableResolverAdapter implements VariableResolver { private static final int TABLE_DATA_PARA = 0; @@ -21,7 +25,7 @@ public abstract class VariableResolverAdapter implements VariableResolver { * @return 内置参数 */ public String[] resolveCurReportVariables() { - return new String[] { ScriptConstants.SUMMARY_TAG + "page_number", + String [] variables = new String[] { ScriptConstants.SUMMARY_TAG + "page_number", ScriptConstants.SUMMARY_TAG + "totalPage_number", // 下面是权限相关的参数 ScriptConstants.DETAIL_TAG + Constants.P.PRIVILEGE_USERNAME, ScriptConstants.DETAIL_TAG + Constants.P.PRIVILEGE_AUTHORITY, @@ -32,6 +36,13 @@ public abstract class VariableResolverAdapter implements VariableResolver { CalculatorProvider.REPORT_NAME, CalculatorProvider.FORMLET_NAME, CalculatorProvider.SERVLET_URL, CalculatorProvider.SERVER_SCHEMA, CalculatorProvider.SERVER_NAME, CalculatorProvider.SERVER_PORT, CalculatorProvider.SERVER_URL, CalculatorProvider.CONTEXT_PATH, CalculatorProvider.SESSION_ID }; + Set set = ExtraClassManager.getInstance().getArray(BuiltInParametersProvider.XML_TAG); + for (BuiltInParametersProvider provider : set) { + return (String[]) ArrayUtils.addAll(variables, new String []{ + ScriptConstants.DETAIL_TAG + provider.getParametersName() + }); + } + return variables; } private Parameter[] getCurrentModeParameters(int type) { diff --git a/designer_base/src/com/fr/design/fun/ConnectionProvider.java b/designer_base/src/com/fr/design/fun/ConnectionProvider.java index c6bd2fca2..766f7d414 100644 --- a/designer_base/src/com/fr/design/fun/ConnectionProvider.java +++ b/designer_base/src/com/fr/design/fun/ConnectionProvider.java @@ -12,7 +12,8 @@ public interface ConnectionProvider extends Mutable { public static final String XML_TAG = "ConnectionProvider"; - int CURRENT_LEVEL = 1; + // 2016-12-14 1 -> 2 , 增加connection.feature方法导致不兼容. + int CURRENT_LEVEL = 2; /** * 数据连接弹出菜单的名字 diff --git a/designer_base/src/com/fr/design/fun/ExtraButtonToolBarProvider.java b/designer_base/src/com/fr/design/fun/ExtraButtonToolBarProvider.java new file mode 100644 index 000000000..09bff1f1a --- /dev/null +++ b/designer_base/src/com/fr/design/fun/ExtraButtonToolBarProvider.java @@ -0,0 +1,41 @@ +package com.fr.design.fun; + +import com.fr.form.ui.Widget; +import com.fr.stable.fun.mark.Mutable; + +import javax.swing.*; +import java.awt.*; + +/** + * 报表工具栏设计器端拓展,用于配置按钮额外属性 + * Created by harry on 2016-12-23. + */ +public interface ExtraButtonToolBarProvider extends Mutable { + + String XML_TAG = "ExtraButtonToolBarProvider"; + + int CURRENT_LEVEL = 1; + + /** + * 用于添加属性面板 + * + * @param centerPane 面板 + */ + void updateCenterPane(JPanel centerPane); + + /** + * 更新界面 + * + * @param widget 控件 + * @param card 卡片布局 + * @param centerPane 面板 + */ + void populate(Widget widget, CardLayout card, JPanel centerPane); + + /** + * 保存界面设置 + * + * @param widget 控件 + */ + void update(Widget widget); +} diff --git a/designer_base/src/com/fr/design/fun/HyperlinkProvider.java b/designer_base/src/com/fr/design/fun/HyperlinkProvider.java index e6eccc882..9f0a53cfa 100644 --- a/designer_base/src/com/fr/design/fun/HyperlinkProvider.java +++ b/designer_base/src/com/fr/design/fun/HyperlinkProvider.java @@ -10,7 +10,7 @@ import com.fr.stable.fun.mark.Mutable; public interface HyperlinkProvider extends Mutable { String XML_TAG = "HyperlinkProvider"; - int CURRENT_LEVEL = 1; + int CURRENT_LEVEL = 2; /** diff --git a/designer_base/src/com/fr/design/fun/impl/AbstractExtraButtonToolBarProvider.java b/designer_base/src/com/fr/design/fun/impl/AbstractExtraButtonToolBarProvider.java new file mode 100644 index 000000000..064d72d1c --- /dev/null +++ b/designer_base/src/com/fr/design/fun/impl/AbstractExtraButtonToolBarProvider.java @@ -0,0 +1,19 @@ +package com.fr.design.fun.impl; + +import com.fr.design.fun.ExtraButtonToolBarProvider; +import com.fr.stable.fun.impl.AbstractProvider; +import com.fr.stable.fun.mark.API; + +/** + * Created by harry on 2016-12-23. + */ +@API(level = ExtraButtonToolBarProvider.CURRENT_LEVEL) +public abstract class AbstractExtraButtonToolBarProvider extends AbstractProvider implements ExtraButtonToolBarProvider { + public int currentAPILevel() { + return ExtraButtonToolBarProvider.CURRENT_LEVEL; + } + + public String mark4Provider() { + return getClass().getName(); + } +} diff --git a/designer_base/src/com/fr/design/gui/controlpane/JListControlPane.java b/designer_base/src/com/fr/design/gui/controlpane/JListControlPane.java index dd91b7824..52802921a 100644 --- a/designer_base/src/com/fr/design/gui/controlpane/JListControlPane.java +++ b/designer_base/src/com/fr/design/gui/controlpane/JListControlPane.java @@ -109,6 +109,10 @@ public abstract class JListControlPane extends JControlPane { } + protected void doBeforePopulate(ListModelElement el, Object obj) { + + } + @Override protected ShortCut4JControlPane addItemShortCut() { ShortCut addItemShortCut; @@ -832,6 +836,7 @@ public abstract class JListControlPane extends JControlPane { cardPane.add(updatePanes[i], String.valueOf(i)); } card.show(cardPane, String.valueOf(i)); + doBeforePopulate(el, ob2Populate); updatePanes[i].populateBean(ob2Populate); doWhenPopulate(updatePanes[i]); break; diff --git a/designer_base/src/com/fr/design/gui/frpane/HyperlinkGroupPane.java b/designer_base/src/com/fr/design/gui/frpane/HyperlinkGroupPane.java index 112fa54dc..99fc5948e 100644 --- a/designer_base/src/com/fr/design/gui/frpane/HyperlinkGroupPane.java +++ b/designer_base/src/com/fr/design/gui/frpane/HyperlinkGroupPane.java @@ -13,6 +13,7 @@ import com.fr.js.JavaScript; import com.fr.js.NameJavaScript; import com.fr.js.NameJavaScriptGroup; import com.fr.plugin.PluginManager; +import com.fr.stable.ListMap; import com.fr.stable.Nameable; import java.util.ArrayList; @@ -34,7 +35,7 @@ public class HyperlinkGroupPane extends JListControlPane { * @return 返回Nameable按钮数组. */ public NameableCreator[] createNameableCreators() { - Map nameCreators = new TreeMap(); + Map nameCreators = new ListMap<>(); NameableCreator[] creators = DesignModuleFactory.getHyperlinkGroupType().getHyperlinkCreators(); for (NameableCreator creator : creators) { nameCreators.put(creator.menuName(), creator); diff --git a/designer_base/src/com/fr/design/gui/ibutton/UIButtonGroup.java b/designer_base/src/com/fr/design/gui/ibutton/UIButtonGroup.java index 8a266a2a1..636f72858 100644 --- a/designer_base/src/com/fr/design/gui/ibutton/UIButtonGroup.java +++ b/designer_base/src/com/fr/design/gui/ibutton/UIButtonGroup.java @@ -28,6 +28,7 @@ import com.fr.design.utils.gui.GUICoreUtils; public class UIButtonGroup extends JPanel implements GlobalNameObserver { private boolean isTwoLine = false; + private boolean isFourLine = false; private static final long serialVersionUID = 1L; protected List labelButtonList; protected int selectedIndex = -1; @@ -176,6 +177,10 @@ public class UIButtonGroup extends JPanel implements GlobalNameObserver { this.isTwoLine = true; } + public void setFourLine() { + this.isFourLine = true; + } + /** * paintComponent * @@ -201,32 +206,40 @@ public class UIButtonGroup extends JPanel implements GlobalNameObserver { } Graphics2D g2d = (Graphics2D) g; g2d.setColor(UIConstants.LINE_COLOR); - if (!isTwoLine) { + if (isTwoLine) { int width = 0; - for (int i = 0; i < labelButtonList.size() - 1; i++) { + int upCount = (labelButtonList.size() - 1) / 2 + 1; + for (int i = 0; i < upCount - 1; i++) { width += labelButtonList.get(i).getWidth() + 1; - int height = labelButtonList.get(i).getHeight(); + int height = labelButtonList.get(i).getHeight() * 2 + 1; g.drawLine(width, 0, width, height); } - width += labelButtonList.get(labelButtonList.size() - 1).getWidth() + 1; - + width += labelButtonList.get(upCount).getWidth() + 1; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.drawRoundRect(0, 0, width, getHeight() - 1, UIConstants.ARC, UIConstants.ARC); + g2d.drawLine(0, getHeight() / 2, width, getHeight() / 2); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + } else if (isFourLine) { + // 4 * 1 + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, UIConstants.ARC, UIConstants.ARC); + for (int i = 1; i <= 3; i++) { + g2d.drawLine(0, getHeight() / 4 * i, getWidth() - 1, getHeight() / 4 * i); + } g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } else { int width = 0; - int upCount = (labelButtonList.size() - 1) / 2 + 1; - for (int i = 0; i < upCount - 1; i++) { + for (int i = 0; i < labelButtonList.size() - 1; i++) { width += labelButtonList.get(i).getWidth() + 1; - int height = labelButtonList.get(i).getHeight() * 2 + 1; + int height = labelButtonList.get(i).getHeight(); g.drawLine(width, 0, width, height); } - width += labelButtonList.get(upCount).getWidth() + 1; + width += labelButtonList.get(labelButtonList.size() - 1).getWidth() + 1; + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.drawRoundRect(0, 0, width, getHeight() - 1, UIConstants.ARC, UIConstants.ARC); - g2d.drawLine(0, getHeight() / 2, width, getHeight() / 2); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } diff --git a/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java b/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java index d6d149674..350b99ead 100644 --- a/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java +++ b/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java @@ -160,6 +160,14 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser uiObserverListener = listener; } + public void removeChangeListener(){ + uiObserverListener = null; + } + + public UIObserverListener getUiObserverListener(){ + return uiObserverListener; + } + /** * @return */ diff --git a/designer_base/src/com/fr/design/gui/itable/AbstractPropertyTable.java b/designer_base/src/com/fr/design/gui/itable/AbstractPropertyTable.java index 02a6f547b..36e9cc17d 100644 --- a/designer_base/src/com/fr/design/gui/itable/AbstractPropertyTable.java +++ b/designer_base/src/com/fr/design/gui/itable/AbstractPropertyTable.java @@ -26,32 +26,39 @@ import com.fr.general.Inter; */ public abstract class AbstractPropertyTable extends JTable { - // 属性分组 + // // 所有数据组, 把数据分组,一个可折叠的项里面的所有行 为一组 protected ArrayList groups; - protected TableModel default_table_model; // 属性表被选中的行加一个浅蓝色的背景 public static final Color PROPERTY_SELECTION_BACKGROUND = new Color(153, 204, 255); // 属性表的行高 public static final int PROPERTY_TABLE_ROW_HEIGHT = 22; + private static final int PROPERTY_ICON_WIDTH = 10; public AbstractPropertyTable() { - this.setRowHeight(PROPERTY_TABLE_ROW_HEIGHT); + this.setTableProperties(); + this.initPopup(); + this.setModel(new DefaultTableModel()); + } + + private void setTableProperties() { JTableHeader header = getTableHeader(); header.setReorderingAllowed(false); header.setPreferredSize(new Dimension(0, PROPERTY_TABLE_ROW_HEIGHT)); header.setDefaultRenderer(new HeaderRenderer()); + this.setRowHeight(PROPERTY_TABLE_ROW_HEIGHT); this.setGridColor(new Color(212, 208, 200)); this.setSelectionBackground(PROPERTY_SELECTION_BACKGROUND); this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); this.setColumnSelectionAllowed(false); this.setRowSelectionAllowed(true); this.setFillsViewportHeight(true); - this.initPopup(); - default_table_model = new DefaultTableModel(); - this.setModel(default_table_model); this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); } + /** + * 在这个函数里面初始化表格数据再repaint + * @param source + */ public abstract void initPropertyGroups(Object source); public void fireValueChanged(Object old_value, boolean success, Object newValue) { @@ -64,12 +71,15 @@ public abstract class AbstractPropertyTable extends JTable { @Override public TableCellRenderer getCellRenderer(int row, int column) { + //如果数据组不为空 if (groups != null) { Point pIndex = getGroupIndex(row); if (pIndex == null){ return super.getCellRenderer(row, column); } + //拿出当前行所在的那个属性组 PropertyGroup group = groups.get(pIndex.x); + //如果是标题行 if (pIndex.y == 0) { if (column == 0) { return group.getFirstRenderer(); @@ -77,11 +87,13 @@ public abstract class AbstractPropertyTable extends JTable { return group.getSecondRenderer(); } } else { + //如果是非标题行第一列,采用默认渲染器 if (column == 0) { return super.getCellRenderer(row, column); } else { TableCellRenderer renderer = group.getModel().getRenderer(pIndex.y - 1); if (renderer instanceof Component) { + //如果这个渲染器是继承自Component,根据当前行列是否可编辑决定该控件是否可用 ((Component) renderer).setEnabled(isCellEditable(row, column)); } return renderer; @@ -115,6 +127,12 @@ public abstract class AbstractPropertyTable extends JTable { } } + /** + * 看懂了。。写个注释先 + * 获取当前row行的Point(x, y), x代表当前row行是属于groups中的第x个组,y代表当前row行所在的第x组里面的第y行 + * @param row + * @return + */ private Point getGroupIndex(int row) { int count = 0; for (int i = 0; i < groups.size(); i++) { @@ -135,6 +153,10 @@ public abstract class AbstractPropertyTable extends JTable { this.addMouseListener(new MouseAdapter() { + /** + * 如果点到标题行就要触发折叠事件 + * @param e + */ @Override public void mouseClicked(MouseEvent e) { if (!e.isPopupTrigger() && groups != null) { @@ -148,13 +170,18 @@ public abstract class AbstractPropertyTable extends JTable { } } + /** + * 这个mousePressed和上面的mouseClicked唯一不同的地方是单双击和e.getX() < 10 的判断 + * 这个意思应该就是说点到图标(加号减号),立即触发折叠效果,否则点其他处要双击才能触发 + * @param e + */ @Override public void mousePressed(MouseEvent e) { if (!e.isPopupTrigger() && groups != null) { int row = AbstractPropertyTable.super.rowAtPoint(e.getPoint()); if (row != -1) { Point pIndex = getGroupIndex(row); - if (pIndex.y == 0 && e.getClickCount() == 1 && e.getX() < 10) { + if (pIndex.y == 0 && e.getClickCount() == 1 && e.getX() < PROPERTY_ICON_WIDTH) { toggleCollapse(pIndex.x); } } @@ -163,16 +190,27 @@ public abstract class AbstractPropertyTable extends JTable { }); } + /** + * 切换属性组折叠属性true/false + * @param groupIndex + */ private void toggleCollapse(int groupIndex) { PropertyGroup group = groups.get(groupIndex); group.setCollapsed(!group.isCollapsed()); + //这里获取表格的父控件是为了当表格被折叠了后,装表格的父控件也要相应的重新布局一下 + //比如折叠之后表格行数应该比原来的少,占用父容器空间应该小点,不重新布局父容器,表格大小不会改变 Container parent = AbstractPropertyTable.this.getParent(); if (parent != null) { - parent.doLayout(); +// parent.doLayout(); // 这里还是用revalidate吧。。daLayout有时候会失效不知道为什么 + parent.revalidate(); } repaint(); } + /** + * BeanTableModel类,提供表格数据 + * 它的所有数据来源均来自PropertyGroup中的AbstractPropertyGroupModel中的descriptor + */ public class BeanTableModel extends AbstractTableModel { @Override diff --git a/designer_base/src/com/fr/design/gui/itable/PropertyGroup.java b/designer_base/src/com/fr/design/gui/itable/PropertyGroup.java index f66288e39..c863c882d 100644 --- a/designer_base/src/com/fr/design/gui/itable/PropertyGroup.java +++ b/designer_base/src/com/fr/design/gui/itable/PropertyGroup.java @@ -4,11 +4,14 @@ import javax.swing.table.TableCellRenderer; import com.fr.design.beans.GroupModel; +/** + * PropertyGroup类描述了属性表中一个属性分组 + */ public class PropertyGroup { - private GroupModel model; - private String name; - private boolean collapsed; + private GroupModel model; // 描述这个属性组中的数据model + private String name; // 这组属性的标题名称 + private boolean collapsed; // 这组属性是否折叠 private GroupRenderer renderer1; private GroupRenderer renderer2; @@ -55,4 +58,5 @@ public class PropertyGroup { public TableCellRenderer getSecondRenderer() { return renderer2; } + } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/gui/style/BorderPane.java b/designer_base/src/com/fr/design/gui/style/BorderPane.java index 60989aedd..cb37f1c1a 100644 --- a/designer_base/src/com/fr/design/gui/style/BorderPane.java +++ b/designer_base/src/com/fr/design/gui/style/BorderPane.java @@ -51,34 +51,16 @@ public class BorderPane extends AbstractBasicStylePane { } protected void initComponents() { - topToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/top.png")); - leftToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/left.png")); - bottomToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/bottom.png")); - rightToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/right.png")); - horizontalToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/horizontal.png")); - verticalToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/vertical.png")); - this.currentLineCombo = new LineComboBox(CoreConstants.UNDERLINE_STYLE_ARRAY); - this.currentLineColorPane = new NewColorSelectBox(100); - + initButtonsWithIcon(); this.setLayout(new BorderLayout(0, 6)); - - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - - double[] columnSize1 = {p, f}; - double[] rowSize1 = {p, p}; - - + double p = TableLayout.PREFERRED, f = TableLayout.FILL; + double[] columnSize1 = {p, f}, rowSize1 = {p, p}; Component[][] components1 = new Component[][]{ - new Component[]{new UILabel(Inter.getLocText("Style") + ":"), currentLineCombo}, - new Component[]{new UILabel(Inter.getLocText("Color") + ":"), currentLineColorPane}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Style") + ":"), currentLineCombo}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Color") + ":"), currentLineColorPane}, }; - JPanel northPane = TableLayoutHelper.createTableLayoutPane(components1, rowSize1, columnSize1); - - - double[] columnSize2 = {p, f}; - double[] rowSize2 = {p, p}; + double[] columnSize2 = {p, f}, rowSize2 = {p, p}; JPanel externalPane = new JPanel(new GridLayout(0, 4)); externalPane.add(topToggleButton); externalPane.add(leftToggleButton); @@ -87,23 +69,15 @@ public class BorderPane extends AbstractBasicStylePane { JPanel insidePane = new JPanel(new GridLayout(0, 2)); insidePane.add(horizontalToggleButton); insidePane.add(verticalToggleButton); - - Component[][] components2 = new Component[][]{ new Component[]{outerToggleButton = new UIToggleButton(BaseUtils.readIcon("com/fr/design/images/m_format/out.png")), innerToggleButton = new UIToggleButton(BaseUtils.readIcon("com/fr/design/images/m_format/in.png"))}, new Component[]{externalPane, insidePane,} }; JPanel centerPane = TableLayoutHelper.createTableLayoutPane(components2, rowSize2, columnSize2); - this.setLayout(new BorderLayout(0, 6)); this.add(northPane, BorderLayout.NORTH); this.add(centerPane, BorderLayout.CENTER); - - - this.currentLineColorPane.setSelectObject(Color.BLACK); - outerToggleButton.addChangeListener(new ChangeListener() { - @Override public void stateChanged(ChangeEvent e) { boolean value = outerToggleButton.isSelected(); @@ -113,9 +87,7 @@ public class BorderPane extends AbstractBasicStylePane { rightToggleButton.setSelected(value); } }); - innerToggleButton.addChangeListener(new ChangeListener() { - @Override public void stateChanged(ChangeEvent e) { boolean value = innerToggleButton.isSelected(); @@ -123,12 +95,22 @@ public class BorderPane extends AbstractBasicStylePane { verticalToggleButton.setSelected(value); } }); + } + private void initButtonsWithIcon(){ + topToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/top.png")); + leftToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/left.png")); + bottomToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/bottom.png")); + rightToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/right.png")); + horizontalToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/horizontal.png")); + verticalToggleButton = new UIToggleButton(BaseUtils.readIcon("/com/fr/base/images/dialog/border/vertical.png")); + this.currentLineCombo = new LineComboBox(CoreConstants.UNDERLINE_STYLE_ARRAY); + this.currentLineColorPane = new NewColorSelectBox(100); } @Override public String title4PopupWindow() { - return Inter.getLocText("Border"); + return Inter.getLocText("FR-Designer_Border"); } public void populate(Style style) { diff --git a/designer_base/src/com/fr/design/images/control/tab/end.png b/designer_base/src/com/fr/design/images/control/tab/end.png new file mode 100644 index 000000000..da848239f Binary files /dev/null and b/designer_base/src/com/fr/design/images/control/tab/end.png differ diff --git a/designer_base/src/com/fr/design/images/control/tab/end_not.png b/designer_base/src/com/fr/design/images/control/tab/end_not.png new file mode 100644 index 000000000..1f08bdf35 Binary files /dev/null and b/designer_base/src/com/fr/design/images/control/tab/end_not.png differ diff --git a/designer_base/src/com/fr/design/images/control/tab/first.png b/designer_base/src/com/fr/design/images/control/tab/first.png new file mode 100644 index 000000000..5bdb04402 Binary files /dev/null and b/designer_base/src/com/fr/design/images/control/tab/first.png differ diff --git a/designer_base/src/com/fr/design/images/control/tab/first_not.png b/designer_base/src/com/fr/design/images/control/tab/first_not.png new file mode 100644 index 000000000..50d048a19 Binary files /dev/null and b/designer_base/src/com/fr/design/images/control/tab/first_not.png differ diff --git a/designer_base/src/com/fr/design/images/control/tab/next.png b/designer_base/src/com/fr/design/images/control/tab/next.png new file mode 100644 index 000000000..495a51805 Binary files /dev/null and b/designer_base/src/com/fr/design/images/control/tab/next.png differ diff --git a/designer_base/src/com/fr/design/images/control/tab/next_not.png b/designer_base/src/com/fr/design/images/control/tab/next_not.png new file mode 100644 index 000000000..f002a0b9e Binary files /dev/null and b/designer_base/src/com/fr/design/images/control/tab/next_not.png differ diff --git a/designer_base/src/com/fr/design/images/control/tab/prev.png b/designer_base/src/com/fr/design/images/control/tab/prev.png new file mode 100644 index 000000000..5923d5794 Binary files /dev/null and b/designer_base/src/com/fr/design/images/control/tab/prev.png differ diff --git a/designer_base/src/com/fr/design/images/control/tab/prev_not.png b/designer_base/src/com/fr/design/images/control/tab/prev_not.png new file mode 100644 index 000000000..2530395fd Binary files /dev/null and b/designer_base/src/com/fr/design/images/control/tab/prev_not.png differ diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/$$$.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/$$$.txt index ea95070da..48d884dc4 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/$$$.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/$$$.txt @@ -1 +1 @@ -ǰֵ \ No newline at end of file +当前值 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/$$page_number.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/$$page_number.txt index 322c867f4..0e45e0871 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/$$page_number.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/$$page_number.txt @@ -1 +1 @@ -ǰҳ +当前的页数。 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/$$totalPage_number.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/$$totalPage_number.txt index a6a8244be..11c6fb59b 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/$$totalPage_number.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/$$totalPage_number.txt @@ -1 +1 @@ -ҳ \ No newline at end of file +总页数。 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_authority.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_authority.txt index eadf192eb..abafe8eff 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_authority.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_authority.txt @@ -1 +1 @@ -ʹȨʱɫIJ \ No newline at end of file +使用权限时保存角色的参数 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_username.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_username.txt index 586198ed0..9dadd3883 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_username.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_username.txt @@ -1 +1 @@ -ʹȨʱûIJ \ No newline at end of file +使用权限时保存用户名的参数 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_userposition.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_userposition.txt index 07b3122ab..73cb5a6d2 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_userposition.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/$fr_userposition.txt @@ -1,3 +1 @@ -ʹȨʱ,$fr_userpositionDzŽɫ -ʽ磺{"departments":"","jobTitle":"۾"} -ŽɫԲźְɵ顣 \ No newline at end of file +使用权限时,$fr_userposition就是部门角色,格式如:{"jobTitle":"销售经理","departments":"销售"},部门角色是以部门和职务组成的数组。 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/NOFILTER.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/NOFILTER.txt index ccda7162b..13caca6bc 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/NOFILTER.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/NOFILTER.txt @@ -1 +1 @@ -NOFILTERһֵȽ϶ΪtrueIJ +NOFILTER是一个与任意值比较都为true的参数。 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/NULL.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/NULL.txt index 90e31a9b2..40ea67ca4 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/NULL.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/NULL.txt @@ -1 +1 @@ -ֵIJ \ No newline at end of file +空值的参数。 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/contextPath.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/contextPath.txt index 0257c7e84..2faf5629e 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/contextPath.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/contextPath.txt @@ -1,3 +1 @@ -contextPathָ·ķĿ¼. -ʣhttp://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt -contextPath/WebReport \ No newline at end of file +contextPath是指绝对路径的服务器别名,即虚拟目录.假如访问:http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,contextPath是/WebReport \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/curReport.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/curReport.txt index cc01b6726..4a0b82a92 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/curReport.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/curReport.txt @@ -1 +1 @@ -ǰ \ No newline at end of file +当前报表。 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/formletName.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/formletName.txt index 95c5feec3..c9921354a 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/formletName.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/formletName.txt @@ -1,3 +1 @@ - -ʣhttp://localhost:8080/WebReport/ReportServer?formlet=Form1.frm -formNameForm1.frm \ No newline at end of file +表单名字假如访问:http://localhost:8080/WebReport/ReportServer?formlet=Form1.frm,formName就是Form1.frm \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/fr_submitinfo.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/fr_submitinfo.txt index 4a1e38b99..41212da23 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/fr_submitinfo.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/fr_submitinfo.txt @@ -1 +1 @@ -ύ¼ķϢ fr_submitinfo.success¼ɹ fr_submitinfo.failinfo򵥼¼Ϣ \ No newline at end of file +提交入库事件的返回信息。fr_submitinfo.success记录成功与否fr_submitinfo.failinfo简单记录出错信息 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/reportName.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/reportName.txt index 982b43b72..d2bb66ad3 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/reportName.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/reportName.txt @@ -1,3 +1 @@ - -ʣhttp://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt -reportNameWorkBook1.cpt \ No newline at end of file +报表名字假如访问:http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,reportName就是WorkBook1.cpt \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/serverName.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/serverName.txt index 89eb2f98d..d6fca7188 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/serverName.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/serverName.txt @@ -1,3 +1 @@ -serverNameַָ. -ʣhttp://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt -serverNameָǣlocalhostʻӵIP \ No newline at end of file +serverName,是指服务器地址或名称.假如访问:http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,serverName指的是:localhost,即访问机子的IP \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/serverPort.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/serverPort.txt index 8a0dd40cf..24552e730 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/serverPort.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/serverPort.txt @@ -1 +1 @@ -serverPortָǷʵĶ˿ \ No newline at end of file +serverPort指的是访问的端口 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/serverSchema.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/serverSchema.txt index 02cecc67e..15bcc7e9f 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/serverSchema.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/serverSchema.txt @@ -1,3 +1 @@ -serverSchemaָЭ. -ʣhttp://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt -serverSchemaָǣhttp \ No newline at end of file +serverSchema,是指协议名称.假如访问:http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,serverSchema指的是:http \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/serverURL.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/serverURL.txt index 5fd3852e9..02c7db49f 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/serverURL.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/serverURL.txt @@ -1,3 +1 @@ -serverURLָʷURL -ʣhttp://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt -serverURLhttp://localhost:8080 +serverURL是指访问服务的URL假如访问:http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,serverURL就是http://localhost:8080 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/servletURL.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/servletURL.txt index 73a1c0fff..2a1e5dfd4 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/servletURL.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/servletURL.txt @@ -1,2 +1 @@ -ʣhttp://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt -servletURLָǣ/WebReport/ReportServer \ No newline at end of file +假如访问:http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,servletURL指的是:/WebReport/ReportServer \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/cn/sessionID.txt b/designer_base/src/com/fr/design/insert/formula/variable/cn/sessionID.txt index a27a6b408..eb0b42cf6 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/cn/sessionID.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/cn/sessionID.txt @@ -1,4 +1 @@ -SessionIDǷûỰıʶ -ڴỰʱΪÿһỰһıʶ -ỰʶԳͷءSessionIDڱλỰIDļ¼ -SessionID WEBҳͳơ \ No newline at end of file +SessionID属性是返回用户会话的标识。在创建会话时,服务器会为每一个会话生成一个单独的标识,会话标识以长整形数据类型返回。SessionID等于本次会话ID的记录,SessionID 多数情况是用于WEB页面的统计。 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/$$$.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/$$$.txt index 4148f61d3..7f4e9bf6a 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/$$$.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/$$$.txt @@ -1 +1 @@ -The current value \ No newline at end of file +The current value \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_authority.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_authority.txt index c7c8074a0..4cd04a675 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_authority.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_authority.txt @@ -1 +1 @@ -Parameter of user authority \ No newline at end of file +Parameter of user authority \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_username.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_username.txt index 8b8e172de..4acc4b6a8 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_username.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_username.txt @@ -1 +1 @@ -Parameter of username \ No newline at end of file +Parameter of username \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_userposition.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_userposition.txt index 1071578ed..065c00081 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_userposition.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/$fr_userposition.txt @@ -1 +1 @@ -department role of user \ No newline at end of file +department role of user \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/NOFILTER.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/NOFILTER.txt index 8902cd963..e2fdaa0c6 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/NOFILTER.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/NOFILTER.txt @@ -1 +1 @@ -The result is aways true when NOFILTER is compared with any other values. +The result is aways true when NOFILTER is compared with any other values. \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/contextPath.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/contextPath.txt index 8b37a4d9e..7c6256035 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/contextPath.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/contextPath.txt @@ -1 +1 @@ -absolute path of the server http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt contextPath is /WebReport \ No newline at end of file +absolute path of the serverhttp://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,contextPath is /WebReport \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/formletName.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/formletName.txt index 320a270d6..48e90583c 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/formletName.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/formletName.txt @@ -1,3 +1 @@ -form name -http://localhost:8080/WebReport/ReportServer?formlet=Form1.frm -formName is Form1.frm \ No newline at end of file +form namehttp://localhost:8080/WebReport/ReportServer?formlet=Form1.frm,formName is Form1.frm \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/fr_submitinfo.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/fr_submitinfo.txt index a4dc1dc07..ce8c81728 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/fr_submitinfo.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/fr_submitinfo.txt @@ -1 +1 @@ -callback status of form submit contains fr_submitinfo.success and fr_submitinfo.failinfo \ No newline at end of file +callback status of form submitcontains fr_submitinfo.success and fr_submitinfo.failinfo \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/reportName.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/reportName.txt index bd15a4025..88afaad37 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/reportName.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/reportName.txt @@ -1,3 +1 @@ -report name -http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt -reportName is WorkBook1.cpt \ No newline at end of file +report namehttp://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,reportName is WorkBook1.cpt \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/serverName.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/serverName.txt index 666c13b64..265bd4ad0 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/serverName.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/serverName.txt @@ -1,3 +1 @@ -address or name of the server -http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt -serverName means localhost \ No newline at end of file +address or name of the serverhttp://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,serverName means localhost \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/serverSchema.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/serverSchema.txt index 2b06eaa23..85072e652 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/serverSchema.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/serverSchema.txt @@ -1,3 +1 @@ -serverSchema -http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt -serverSchema is http \ No newline at end of file +serverSchemahttp://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,serverSchema is http \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/serverURL.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/serverURL.txt index 347114b08..f14f92583 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/serverURL.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/serverURL.txt @@ -1,3 +1 @@ -URL of the server -http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt -serverURL is http://localhost:8080 +URL of the serverhttp://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,serverURL is http://localhost:8080 \ No newline at end of file diff --git a/designer_base/src/com/fr/design/insert/formula/variable/en/servletURL.txt b/designer_base/src/com/fr/design/insert/formula/variable/en/servletURL.txt index b5ed4ec75..b9149deff 100644 --- a/designer_base/src/com/fr/design/insert/formula/variable/en/servletURL.txt +++ b/designer_base/src/com/fr/design/insert/formula/variable/en/servletURL.txt @@ -1,2 +1 @@ -http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt -servletURL is /WebReport/ReportServer \ No newline at end of file +http://localhost:8080/WebReport/ReportServer?reportlet=WorkBook1.cpt,servletURL is /WebReport/ReportServer \ No newline at end of file diff --git a/designer_base/src/com/fr/design/mainframe/BaseJForm.java b/designer_base/src/com/fr/design/mainframe/BaseJForm.java index c0fd09f17..559387b20 100644 --- a/designer_base/src/com/fr/design/mainframe/BaseJForm.java +++ b/designer_base/src/com/fr/design/mainframe/BaseJForm.java @@ -1 +1,66 @@ -package com.fr.design.mainframe; import javax.swing.JComponent; import com.fr.form.FormElementCaseContainerProvider; /** * Author : Shockway * Date: 13-7-15 * Time: 上午10:28 */ public interface BaseJForm extends JTemplateProvider{ public static final String XML_TAG = "JForm"; public static final int FORM_TAB = 0; public static final int ELEMENTCASE_TAB = 1; public static final int ELEMENTCASE_CHANGE_TAB = 2; /** * 刷新所有控件 */ public void refreshAllNameWidgets(); /** * 刷新参数 */ public void populateParameter(); /** * 刷新选中的控件 */ public void refreshSelectedWidget(); /** * 获取当前的Target */ public Object getTarget(); /** * 执行撤销 * * @param o 之前保存的状态 */ public void applyUndoState4Form(BaseUndoState o); /** * 获取当前编辑的组件 */ public JComponent getEditingPane(); /** * 只在Form和ElementCase之间切换 * @param index 切换位置 */ public void tabChanged(int index); /** * 在Form和ElementCase, 以及ElementCase和ElementCase之间切换 * @param index 切换位置 * @param ecContainer ElementCase所在container */ public void tabChanged(int index, FormElementCaseContainerProvider ecContainer); } \ No newline at end of file +package com.fr.design.mainframe; + +import javax.swing.JComponent; + +import com.fr.form.FormElementCaseContainerProvider; + + +/** + * Author : Shockway + * Date: 13-7-15 + * Time: 上午10:28 + */ +public interface BaseJForm extends JTemplateProvider { + + String XML_TAG = "JForm"; + int FORM_TAB = 0; + int ELEMENTCASE_TAB = 1; + int ELEMENTCASE_CHANGE_TAB = 2; + + /** + * 刷新所有控件 + */ + void refreshAllNameWidgets(); + + /** + * 刷新参数 + */ + void populateParameter(); + + /** + * 刷新选中的控件 + */ + void refreshSelectedWidget(); + + /** + * 获取当前的Target + */ + Object getTarget(); + + /** + * 执行撤销 + * + * @param o 之前保存的状态 + */ + void applyUndoState4Form(BaseUndoState o); + + /** + * 获取当前编辑的组件 + */ + JComponent getEditingPane(); + + /** + * 只在Form和ElementCase之间切换 + * + * @param index 切换位置 + */ + void tabChanged(int index); + + /** + * 在Form和ElementCase, 以及ElementCase和ElementCase之间切换 + * + * @param index 切换位置 + * @param ecContainer ElementCase所在container + */ + void tabChanged(int index, FormElementCaseContainerProvider ecContainer); +} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/mainframe/DesignerFrame.java b/designer_base/src/com/fr/design/mainframe/DesignerFrame.java index f1c144d7c..f67608aca 100644 --- a/designer_base/src/com/fr/design/mainframe/DesignerFrame.java +++ b/designer_base/src/com/fr/design/mainframe/DesignerFrame.java @@ -169,7 +169,6 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta /** * 初始menuPane的方法 方便OEM时修改该组件 - * @param ad */ protected void initMenuPane(){ menuPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); @@ -189,7 +188,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta final JPanel northEastPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); GeneralContext.addPluginReadListener(new PluginReadListener() { @Override - public void success() { + public void success(Status status) { TitlePlaceProcessor processor = ExtraDesignClassManager.getInstance().getSingle(TitlePlaceProcessor.MARK_STRING); if (processor == null) { processor = new DefaultTitlePlace(); diff --git a/designer_base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java b/designer_base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java index 9355a3348..352fc1564 100644 --- a/designer_base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java +++ b/designer_base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java @@ -29,6 +29,7 @@ import com.fr.file.filetree.FileNode; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; import com.fr.general.Inter; +import com.fr.plugin.proxy.PluginProxyCompatibleUtils; import com.fr.stable.CoreConstants; import com.fr.stable.StableUtils; import com.fr.stable.project.ProjectConstants; @@ -131,6 +132,7 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt } toolbarDef.addShortCut(delFileAction); Set extraShortCuts = ExtraDesignClassManager.getInstance().getArray(ShortCut.TEMPLATE_TREE); + extraShortCuts = PluginProxyCompatibleUtils.toOriObjectHashSet(extraShortCuts); for (ShortCut shortCut : extraShortCuts){ toolbarDef.addShortCut(shortCut); } diff --git a/designer_base/src/com/fr/design/mainframe/JTemplate.java b/designer_base/src/com/fr/design/mainframe/JTemplate.java index 58060d91a..a275d3d5d 100644 --- a/designer_base/src/com/fr/design/mainframe/JTemplate.java +++ b/designer_base/src/com/fr/design/mainframe/JTemplate.java @@ -27,6 +27,8 @@ import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.templateinfo.TemplateInfoCollector; +import com.fr.design.mainframe.templateinfo.TemplateProcessInfo; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import com.fr.design.menu.MenuDef; import com.fr.design.menu.NameSeparator; @@ -72,16 +74,27 @@ public abstract class JTemplate> ex private UndoManager authorityUndoManager; protected U undoState; protected U authorityUndoState = null; + protected T template; // 当前模板 + protected TemplateProcessInfo processInfo; // 模板过程的相关信息 private static short currentIndex = 0;// 此变量用于多次新建模板时,让名字不重复 private DesignModelAdapter designModel; private PreviewProvider previewType; + private long openTime = 0L; // 打开模板的时间点(包括新建模板) + private TemplateInfoCollector tic = TemplateInfoCollector.getInstance(); + private StringBuilder process = new StringBuilder(""); // 制作模板的过程 public JTemplate(T t, String defaultFileName) { - this(t, new MemFILE(newTemplateNameByIndex(defaultFileName))); + this(t, new MemFILE(newTemplateNameByIndex(defaultFileName)), true); + openTime = System.currentTimeMillis(); } public JTemplate(T t, FILE file) { + this(t, file, false); + } + + public JTemplate(T t, FILE file, boolean isNewFile) { super(t); + this.template = t; this.previewType = parserPreviewProvider(t.getPreviewType()); this.editingFILE = file; this.setLayout(FRGUIPaneFactory.createBorderLayout()); @@ -89,6 +102,39 @@ public abstract class JTemplate> ex this.add(createCenterPane(), BorderLayout.CENTER); this.undoState = createUndoState(); designModel = createDesignModel(); + // 如果不是新建模板,并且在收集列表中 + if (!isNewFile && tic.inList(t)) { + openTime = System.currentTimeMillis(); + process.append(tic.loadProcess(t)); + } + } + + // 为收集模版信息作准备 + private void initForCollect() { + template.initTemplateID(); // 为新模板设置 templateID 属性 + if (openTime == 0) { + openTime = System.currentTimeMillis(); + } + } + private void collectInfo() { // 执行收集操作 + if (openTime == 0) { // 旧模板,不收集数据 + return; + } + long saveTime = System.currentTimeMillis(); // 保存模板的时间点 + tic.collectInfo(template, this, openTime, saveTime); + openTime = saveTime; // 更新 openTime,准备下一次计算 + } + + public abstract TemplateProcessInfo getProcessInfo(); + + // 追加过程记录 + public void appendProcess(String s) { + process.append(s); + } + + // 获取过程记录 + public String getProcess() { + return process.toString(); } public U getUndoState() { @@ -326,7 +372,7 @@ public abstract class JTemplate> ex } protected boolean accept(Object o){ - return true; + return true; } private void fireSuperTargetModified() { @@ -439,17 +485,18 @@ public abstract class JTemplate> ex JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_No-Privilege") + "!", Inter.getLocText("FR-Designer_Message"), JOptionPane.WARNING_MESSAGE); return false; } + collectInfo(); return this.saveFile(); } - + private boolean isCancelOperation(int operation){ - return operation == FILEChooserPane.CANCEL_OPTION || - operation == FILEChooserPane.JOPTIONPANE_CANCEL_OPTION; + return operation == FILEChooserPane.CANCEL_OPTION || + operation == FILEChooserPane.JOPTIONPANE_CANCEL_OPTION; } - + private boolean isOkOperation(int operation){ - return operation == FILEChooserPane.JOPTIONPANE_OK_OPTION || - operation == FILEChooserPane.OK_OPTION; + return operation == FILEChooserPane.JOPTIONPANE_OK_OPTION || + operation == FILEChooserPane.OK_OPTION; } private boolean saveAsTemplate(boolean isShowLoc) { @@ -466,8 +513,8 @@ public abstract class JTemplate> ex if (isCancelOperation(chooseResult)) { fileChooser = null; return false; - } - + } + if (isOkOperation(chooseResult)) { if (!FRContext.getCurrentEnv().hasFileFolderAllow(fileChooser.getSelectedFILE().getPath()) ) { JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_No-Privilege") + "!", Inter.getLocText("FR-Designer_Message"), JOptionPane.WARNING_MESSAGE); @@ -477,38 +524,41 @@ public abstract class JTemplate> ex mkNewFile(editingFILE); fileChooser = null; } - + return saveNewFile(editingFILE, oldName); } - + protected boolean saveNewFile(FILE editingFILE, String oldName){ - this.editingFILE = editingFILE; + // 在保存之前,初始化 templateID + initForCollect(); // 如果保存新模板(新建模板直接保存,或者另存为),则添加 templateID + this.editingFILE = editingFILE; boolean result = this.saveFile(); if (result) { DesignerFrameFileDealerPane.getInstance().refresh(); + collectInfo(); } //更换最近打开 DesignerEnvManager.getEnvManager().replaceRecentOpenedFilePath(oldName, this.getFullPathName()); return result; } - + protected void mkNewFile(FILE file){ try { - file.mkfile(); + file.mkfile(); } catch (Exception e) { FRContext.getLogger().error(e.getMessage(), e); } } - + /** - * 将模板另存为可以分享出去的混淆后内置数据集模板 - * - * @return 是否另存成功 - * - */ + * 将模板另存为可以分享出去的混淆后内置数据集模板 + * + * @return 是否另存成功 + * + */ public boolean saveShareFile(){ - return true; + return true; } public Widget getSelectElementCase(){ return new NoneWidget(); @@ -713,7 +763,7 @@ public abstract class JTemplate> ex public void revert() { } - + private int getVersionCompare(String versionString){ if (StringUtils.isBlank(versionString)) { return 0; @@ -723,7 +773,7 @@ public abstract class JTemplate> ex return ComparatorUtils.compare(versionString.substring(0, len), ProductConstants.DESIGNER_VERSION.substring(0, len)); } - + private int getVersionCompareHBB(String versionString){ if (StringUtils.isBlank(versionString)) { return 0; @@ -731,17 +781,17 @@ public abstract class JTemplate> ex return ComparatorUtils.compare(versionString, "HBB"); } - + private boolean isHigherThanCurrent(String versionString) { return getVersionCompare(versionString) > 0; } - + private boolean isLowerThanCurrent(String versionString) { - return getVersionCompare(versionString) < 0; + return getVersionCompare(versionString) < 0; } - + private boolean isLowerThanHBB(String versionString) { - return getVersionCompareHBB(versionString) < 0; + return getVersionCompareHBB(versionString) < 0; } /** @@ -751,7 +801,7 @@ public abstract class JTemplate> ex public boolean isNewDesigner() { String xmlDesignerVersion = getTarget().getXMLDesignerVersion(); if (isLowerThanHBB(xmlDesignerVersion)) { - String info = Inter.getLocText("FR-Designer_open-new-form-tip"); + String info = Inter.getLocText("FR-Designer_open-new-form-tip"); String moreInfo = Inter.getLocText("FR-Designer_Server-version-tip-moreInfo"); new InformationWarnPane(info, moreInfo, Inter.getLocText("FR-Designer_Tooltips")).show(); return true; @@ -805,13 +855,13 @@ public abstract class JTemplate> ex * @return 是则返回true */ public abstract boolean isJWorkBook(); - + /** * 返回当前支持的超链界面pane * @return 超链连接界面 */ public HyperlinkGroupPane getHyperLinkPane() { - return new HyperlinkGroupPane(); + return new HyperlinkGroupPane(); } /** @@ -866,29 +916,29 @@ public abstract class JTemplate> ex public void requestGridFocus() { } - + /** - * 创建内置sql提交的pane - * - * @return 内置sql提交的pane - * - * - * @date 2014-10-14-下午7:39:27 - */ + * 创建内置sql提交的pane + * + * @return 内置sql提交的pane + * + * + * @date 2014-10-14-下午7:39:27 + */ public DBManipulationPane createDBManipulationPane(){ - return new DBManipulationPane(); + return new DBManipulationPane(); } - + /** * 创建控件事件里内置sql提交的pane - * + * * @return 内置sql提交的pane - * + * * * @date 2014-10-14-下午7:39:27 */ public DBManipulationPane createDBManipulationPaneInWidget(){ - return new DBManipulationInWidgetEventPane(); + return new DBManipulationInWidgetEventPane(); } /** @@ -916,15 +966,15 @@ public abstract class JTemplate> ex public void styleChange(){ } - + /** - * 创建分享模板的按钮, 目前只有jworkbook实现了 - * - * @return 分享模板按钮 - * - */ + * 创建分享模板的按钮, 目前只有jworkbook实现了 + * + * @return 分享模板按钮 + * + */ public UIButton[] createShareButton(){ - return new UIButton[0]; + return new UIButton[0]; } /** @@ -979,4 +1029,4 @@ public abstract class JTemplate> ex return uiButtons; } -} \ No newline at end of file +} diff --git a/designer_base/src/com/fr/design/mainframe/WestRegionContainerPane.java b/designer_base/src/com/fr/design/mainframe/WestRegionContainerPane.java index 917e4cbfc..7fa8012fe 100644 --- a/designer_base/src/com/fr/design/mainframe/WestRegionContainerPane.java +++ b/designer_base/src/com/fr/design/mainframe/WestRegionContainerPane.java @@ -29,7 +29,7 @@ public class WestRegionContainerPane extends UIResizableContainer { super(DesignerFrameFileDealerPane.getInstance(), Constants.RIGHT); GeneralContext.addPluginReadListener(new PluginReadListener() { @Override - public void success() { + public void success(Status status) { setDownPane(TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter())); } }); diff --git a/designer_base/src/com/fr/design/mainframe/backgroundpane/PatternBackgroundQuickPane.java b/designer_base/src/com/fr/design/mainframe/backgroundpane/PatternBackgroundQuickPane.java index 4e31405d1..16b294955 100644 --- a/designer_base/src/com/fr/design/mainframe/backgroundpane/PatternBackgroundQuickPane.java +++ b/designer_base/src/com/fr/design/mainframe/backgroundpane/PatternBackgroundQuickPane.java @@ -26,17 +26,16 @@ import java.awt.geom.Rectangle2D; public class PatternBackgroundQuickPane extends BackgroundQuickPane { private int patternIndex = 0; // pattern setIndex. + private final static int DEFAULT_DIM_HEIGHT = 190; private ColorSelectBox foregroundColorPane; private ColorSelectBox backgroundColorPane; private PatternButton[] patternButtonArray; public PatternBackgroundQuickPane() { this.setLayout(new BorderLayout(0, 4)); - JPanel contentPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); this.add(contentPane, BorderLayout.NORTH); contentPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); - JPanel typePane2 = new JPanel(); contentPane.add(typePane2); typePane2.setLayout(new GridLayout(0, 8, 1, 1)); @@ -48,15 +47,11 @@ public class PatternBackgroundQuickPane extends BackgroundQuickPane { patternButtonGroup.add(patternButtonArray[i]); typePane2.add(patternButtonArray[i]); } - JPanel colorPane = new JPanel(new GridLayout(0, 2)); foregroundColorPane = new ColorSelectBox(70); backgroundColorPane = new ColorSelectBox(70); - foregroundColorPane.setSelectObject(Color.lightGray); - backgroundColorPane.setSelectObject(Color.black); - - colorPane.add(this.createLabelColorPane(Inter.getLocText("Foreground") + ":", foregroundColorPane)); - colorPane.add(this.createLabelColorPane(Inter.getLocText("Background") + ":", backgroundColorPane)); + colorPane.add(this.createLabelColorPane(Inter.getLocText("FR-Designer_Foreground") + ":", foregroundColorPane)); + colorPane.add(this.createLabelColorPane(Inter.getLocText("FR-Designer_Background") + ":", backgroundColorPane)); this.add(colorPane, BorderLayout.CENTER); foregroundColorPane.addSelectChangeListener(colorChangeListener); backgroundColorPane.addSelectChangeListener(colorChangeListener); @@ -65,7 +60,7 @@ public class PatternBackgroundQuickPane extends BackgroundQuickPane { @Override public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); - dim.height = 190; + dim.height = DEFAULT_DIM_HEIGHT; return dim; } @@ -206,6 +201,6 @@ public class PatternBackgroundQuickPane extends BackgroundQuickPane { @Override public String title4PopupWindow() { - return Inter.getLocText("Background-Pattern"); + return Inter.getLocText("FR-Designer_Background-Pattern"); } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java new file mode 100644 index 000000000..17d785a43 --- /dev/null +++ b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java @@ -0,0 +1,526 @@ +package com.fr.design.mainframe.templateinfo; + +import com.fr.base.FRContext; +import com.fr.base.io.IOFile; +import com.fr.design.DesignerEnvManager; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; +import com.fr.env.RemoteEnv; +import com.fr.general.*; +import com.fr.general.http.HttpClient; +import com.fr.stable.*; +import com.fr.stable.xml.*; +import com.fr.third.javax.xml.stream.XMLStreamException; +import com.fr.json.JSONObject; + +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.HashMap; + +/** + * 做模板的过程和耗时收集,辅助类 + * Created by plough on 2017/2/21. + */ +public class TemplateInfoCollector implements Serializable, XMLReadable, XMLWriter { + private static final String FILE_NAME = "tpl.info"; + private static final String OBJECT_FILE_NAME = "tplInfo.ser"; + private static TemplateInfoCollector instance; + private Map> templateInfoList; + private String designerOpenDate; //设计器最近一次打开日期 + private static final int VALID_CELL_COUNT = 5; // 有效报表模板的格子数 + private static final int VALID_WIDGET_COUNT = 5; // 有效报表模板的控件数 + private static final int COMPLETE_DAY_COUNT = 15; // 判断模板是否完成的天数 + private static final int ONE_THOUSAND = 1000; + static final long serialVersionUID = 2007L; + private static final String XML_DESIGNER_OPEN_DATE = "DesignerOpenDate"; + private static final String XML_TEMPLATE_INFO_LIST = "TemplateInfoList"; + private static final String XML_TEMPLATE_INFO = "TemplateInfo"; + private static final String XML_PROCESS_MAP = "processMap"; + private static final String XML_CONSUMING_MAP = "consumingMap"; + private static final String ATTR_DAY_COUNT = "day_count"; + private static final String ATTR_TEMPLATE_ID = "templateID"; + private static final String ATTR_PROCESS = "process"; + private static final String ATTR_FLOAT_COUNT = "float_count"; + private static final String ATTR_WIDGET_COUNT = "widget_count"; + private static final String ATTR_CELL_COUNT = "cell_count"; + private static final String ATTR_BLOCK_COUNT = "block_count"; + private static final String ATTR_REPORT_TYPE = "report_type"; + private static final String ATTR_ACTIVITYKEY = "activitykey"; + private static final String ATTR_JAR_TIME = "jar_time"; + private static final String ATTR_CREATE_TIME = "create_time"; + private static final String ATTR_UUID = "uuid"; + private static final String ATTR_TIME_CONSUME = "time_consume"; + private static final String ATTR_VERSION = "version"; + private static final String ATTR_USERNAME = "username"; + private static final String JSON_CONSUMING_MAP = "jsonConsumingMap"; + private static final String JSON_PROCESS_MAP = "jsonProcessMap"; + + + @SuppressWarnings("unchecked") + private TemplateInfoCollector() { + templateInfoList = new HashMap<>(); + setDesignerOpenDate(); + } + + /** + * 把设计器最近打开日期设定为当前日期 + */ + private void setDesignerOpenDate() { + designerOpenDate = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); + } + + /** + * 判断今天是否第一次打开设计器 + */ + private boolean designerOpenFirstTime() { + String today = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); + return !ComparatorUtils.equals(today, designerOpenDate); + } + + /** + * 获取缓存文件存放路径 + */ + private static File getInfoFile() { + return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME)); + } + + private static File getObjectInfoFile() { + return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), OBJECT_FILE_NAME)); + } + + public static TemplateInfoCollector getInstance() { + if (instance == null) { + instance = new TemplateInfoCollector(); + readXMLFile(instance, getInfoFile()); + // 兼容过渡。如果没有新文件,则从老文件读取数据。以后都是读写新的 xml 文件 + if (!getInfoFile().exists() && getObjectInfoFile().exists()) { + try { + ObjectInputStream is = new ObjectInputStream(new FileInputStream(getObjectInfoFile())); + instance = (TemplateInfoCollector) is.readObject(); + } catch (Exception ex) { + // 什么也不做,instance 使用新值 + } + } + } + return instance; + } + + private static void readXMLFile(XMLReadable xmlReadable, File xmlFile){ + if (xmlFile == null || !xmlFile.exists()) { + return; + } + String charset = EncodeConstants.ENCODING_UTF_8; + try { + String fileContent = getFileContent(xmlFile); + InputStream xmlInputStream = new ByteArrayInputStream(fileContent.getBytes(charset)); + InputStreamReader inputStreamReader = new InputStreamReader(xmlInputStream, charset); + XMLableReader xmlReader = XMLableReader.createXMLableReader(inputStreamReader); + + if (xmlReader != null) { + xmlReader.readXMLObject(xmlReadable); + } + xmlInputStream.close(); + } catch (FileNotFoundException e) { + FRContext.getLogger().error(e.getMessage()); + } catch (IOException e) { + FRContext.getLogger().error(e.getMessage()); + } catch (XMLStreamException e) { + FRContext.getLogger().error(e.getMessage()); + } + + } + + private static String getFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException{ + InputStream is = new FileInputStream(xmlFile); + return IOUtils.inputStream2String(is); + } + + private boolean shouldCollectInfo() { + if (FRContext.getCurrentEnv() instanceof RemoteEnv) { // 远程设计不收集数据 + return false; + } + return DesignerEnvManager.getEnvManager().isJoinProductImprove() && FRContext.isChineseEnv(); + } + + public void appendProcess(String log) { + if (!shouldCollectInfo()) { + return; + } + // 获取当前编辑的模板 + JTemplate jt = DesignerContext.getDesignerFrame().getSelectedJTemplate(); + // 追加过程记录 + jt.appendProcess(log); + } + + /** + * 加载已经存储的模板过程 + */ + @SuppressWarnings("unchecked") + public String loadProcess(T t) { + HashMap processMap = (HashMap) templateInfoList.get(t.getTemplateID()).get(XML_PROCESS_MAP); + return (String)processMap.get(ATTR_PROCESS); + } + + /** + * 根据模板ID是否在收集列表中,判断是否需要收集当前模板的信息 + */ + public boolean inList(T t) { + return templateInfoList.containsKey(t.getTemplateID()); + } + + /** + * 将包含所有信息的对象保存到文件 + */ + private void saveInfo() { + try { + FileOutputStream out = new FileOutputStream(getInfoFile()); + XMLTools.writeOutputStreamXML(this, out); + } catch (Exception ex) { + FRLogger.getLogger().error(ex.getMessage()); + } + } + + /** + * 更新 day_count:打开设计器却未编辑模板的连续日子 + */ + private void addDayCount() { + if (designerOpenFirstTime()) { + for (String key : templateInfoList.keySet()) { + HashMap templateInfo = templateInfoList.get(key); + int dayCount = (int)templateInfo.get(ATTR_DAY_COUNT) + 1; + templateInfo.put(ATTR_DAY_COUNT, dayCount); + } + setDesignerOpenDate(); + } + } + + /** + * 收集模板信息。如果之前没有记录,则新增;如果已有记录,则更新。 + * 同时将最新数据保存到文件中。 + */ + @SuppressWarnings("unchecked") + public void collectInfo(T t, JTemplate jt, long openTime, long saveTime) { + if (!shouldCollectInfo()) { + return; + } + + HashMap templateInfo; + + long timeConsume = ((saveTime - openTime) / ONE_THOUSAND); // 制作模板耗时(单位:s) + String templateID = t.getTemplateID(); + + if (inList(t)) { // 已有记录 + templateInfo = templateInfoList.get(t.getTemplateID()); + // 更新 conusmingMap + HashMap consumingMap = (HashMap) templateInfo.get(XML_CONSUMING_MAP); + timeConsume += (long)consumingMap.get(ATTR_TIME_CONSUME); // 加上之前的累计编辑时间 + consumingMap.put(ATTR_TIME_CONSUME, timeConsume); + } + else { // 新增 + templateInfo = new HashMap<>(); + templateInfo.put(XML_CONSUMING_MAP, getNewConsumingMap(templateID, openTime, timeConsume)); + } + + // 直接覆盖 processMap + templateInfo.put(XML_PROCESS_MAP, getProcessMap(templateID, jt)); + + // 保存模板时,让 day_count 归零 + templateInfo.put(ATTR_DAY_COUNT, 0); + + templateInfoList.put(templateID, templateInfo); + + saveInfo(); // 每次更新之后,都同步到暂存文件中 + } + + private HashMap getNewConsumingMap(String templateID, long openTime, long timeConsume) { + HashMap consumingMap = new HashMap<>(); + + String username = DesignerEnvManager.getEnvManager().getBBSName(); + String uuid = DesignerEnvManager.getEnvManager().getUUID(); + String activitykey = DesignerEnvManager.getEnvManager().getActivationKey(); + String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime()); + String jarTime = GeneralUtils.readBuildNO(); + String version = ProductConstants.VERSION; + consumingMap.put(ATTR_USERNAME, username); + consumingMap.put(ATTR_UUID, uuid); + consumingMap.put(ATTR_ACTIVITYKEY, activitykey); + consumingMap.put(ATTR_TEMPLATE_ID, templateID); + consumingMap.put(ATTR_CREATE_TIME, createTime); + consumingMap.put(ATTR_TIME_CONSUME, timeConsume); + consumingMap.put(ATTR_JAR_TIME, jarTime); + consumingMap.put(ATTR_VERSION, version); + + return consumingMap; + } + + private HashMap getProcessMap(String templateID, JTemplate jt) { + HashMap processMap = new HashMap<>(); + + processMap.put(ATTR_TEMPLATE_ID, templateID); + processMap.put(ATTR_PROCESS, jt.getProcess()); + + TemplateProcessInfo info = jt.getProcessInfo(); + processMap.put(ATTR_REPORT_TYPE, info.getReportType()); + processMap.put(ATTR_CELL_COUNT, info.getCellCount()); + processMap.put(ATTR_FLOAT_COUNT, info.getFloatCount()); + processMap.put(ATTR_BLOCK_COUNT, info.getBlockCount()); + processMap.put(ATTR_WIDGET_COUNT, info.getWidgetCount()); + + return processMap; + } + + /** + * 发送本地模板信息到服务器 + */ + public void sendTemplateInfo() { + addDayCount(); + String consumingUrl = SiteCenter.getInstance().acquireUrlByKind("tempinfo.consuming") + "/single"; + String processUrl = SiteCenter.getInstance().acquireUrlByKind("tempinfo.process") + "/single"; + ArrayList> completeTemplatesInfo = getCompleteTemplatesInfo(); + for (HashMap templateInfo : completeTemplatesInfo) { + String jsonConsumingMap = templateInfo.get(JSON_CONSUMING_MAP); + String jsonProcessMap = templateInfo.get(JSON_PROCESS_MAP); + if (sendSingleTemplateInfo(consumingUrl, jsonConsumingMap) && sendSingleTemplateInfo(processUrl, jsonProcessMap)) { + // 清空记录 + removeFromTemplateInfoList(templateInfo.get(ATTR_TEMPLATE_ID)); + } + } + saveInfo(); + } + + private boolean sendSingleTemplateInfo(String url, String content) { + HashMap para = new HashMap<>(); + String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); + para.put("token", CodeUtils.md5Encode(date, "", "MD5")); + para.put("content", content); + HttpClient httpClient = new HttpClient(url, para, true); + httpClient.setTimeout(5000); + httpClient.asGet(); + + if (!httpClient.isServerAlive()) { + return false; + } + + String res = httpClient.getResponseText(); + boolean success; + try { + success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); + } catch (Exception ex) { + success = false; + } + return success; + } + + /** + * 返回已完成的模板信息 + */ + @SuppressWarnings("unchecked") + private ArrayList> getCompleteTemplatesInfo() { + ArrayList> completeTemplatesInfo = new ArrayList<>(); + ArrayList testTemplateKeys = new ArrayList<>(); // 保存测试模板的key + for (String key : templateInfoList.keySet()) { + HashMap templateInfo = templateInfoList.get(key); + if ((int)templateInfo.get(ATTR_DAY_COUNT) <= COMPLETE_DAY_COUNT) { // 未完成模板 + continue; + } + if (isTestTemplate(templateInfo)) { + testTemplateKeys.add(key); + continue; + } + HashMap consumingMap = (HashMap) templateInfo.get(XML_CONSUMING_MAP); + HashMap processMap = (HashMap) templateInfo.get(XML_PROCESS_MAP); + String jsonConsumingMap = new JSONObject(consumingMap).toString(); + String jsonProcessMap = new JSONObject(processMap).toString(); + HashMap jsonTemplateInfo = new HashMap<>(); + jsonTemplateInfo.put(JSON_CONSUMING_MAP, jsonConsumingMap); + jsonTemplateInfo.put(JSON_PROCESS_MAP, jsonProcessMap); + jsonTemplateInfo.put(ATTR_TEMPLATE_ID, key); + completeTemplatesInfo.add(jsonTemplateInfo); + } + // 删除测试模板 + for (String key : testTemplateKeys) { + removeFromTemplateInfoList(key); + } + return completeTemplatesInfo; + } + + private void removeFromTemplateInfoList(String key) { + templateInfoList.remove(key); + } + + @SuppressWarnings("unchecked") + private boolean isTestTemplate(HashMap templateInfo) { + HashMap processMap = (HashMap) templateInfo.get(XML_PROCESS_MAP); + int reportType = (int)processMap.get(ATTR_REPORT_TYPE); + int cellCount = (int)processMap.get(ATTR_CELL_COUNT); + int floatCount = (int)processMap.get(ATTR_FLOAT_COUNT); + int blockCount = (int)processMap.get(ATTR_BLOCK_COUNT); + int widgetCount = (int)processMap.get(ATTR_WIDGET_COUNT); + boolean isTestTemplate = false; + if (reportType == 0) { // 普通报表 + isTestTemplate = cellCount <= VALID_CELL_COUNT && floatCount <= 1 && widgetCount <= VALID_WIDGET_COUNT; + } else if (reportType == 1) { // 聚合报表 + isTestTemplate = blockCount <= 1 && widgetCount <= VALID_WIDGET_COUNT; + } else { // 表单(reportType == 2) + isTestTemplate = widgetCount <= 1; + } + return isTestTemplate; + } + + @SuppressWarnings("unchecked") + @Override + public void readXML(XMLableReader reader) { + if (reader.isChildNode()) { + try { + String name = reader.getTagName(); + if (XML_DESIGNER_OPEN_DATE.equals(name)) { + this.designerOpenDate = reader.getElementValue(); + } else if(XML_TEMPLATE_INFO_LIST.equals(name)){ + readTemplateInfoList(reader); + } + } catch (Exception ex) { + // 什么也不做,使用默认值 + } + } + } + + private void readTemplateInfoList(XMLableReader reader) { + reader.readXMLObject(new XMLReadable() { + public void readXML(XMLableReader reader) { + if (XML_TEMPLATE_INFO.equals(reader.getTagName())) { + TemplateInfo templateInfo = new TemplateInfo(); + reader.readXMLObject(templateInfo); + templateInfoList.put(templateInfo.getTemplateID(), templateInfo.getTemplateInfo()); + } + } + }); + } + + @Override + public void writeXML(XMLPrintWriter writer) { + writer.startTAG("TplInfo"); + + writer.startTAG(XML_DESIGNER_OPEN_DATE); + writer.textNode(designerOpenDate); + writer.end(); + + writeTemplateInfoList(writer); + + writer.end(); + } + + private void writeTemplateInfoList(XMLPrintWriter writer){ + //启停 + writer.startTAG(XML_TEMPLATE_INFO_LIST); + for (String templateID : templateInfoList.keySet()) { + new TemplateInfo(templateInfoList.get(templateID)).writeXML(writer); + } + writer.end(); + } + + private class TemplateInfo implements XMLReadable, XMLWriter { + + private int dayCount; + private String templateID; + private HashMap processMap = new HashMap<>(); + private HashMap consumingMap = new HashMap<>(); + + @SuppressWarnings("unchecked") + public TemplateInfo(HashMap templateInfo) { + this.dayCount = (int)templateInfo.get(ATTR_DAY_COUNT); + this.processMap = (HashMap) templateInfo.get(XML_PROCESS_MAP); + this.consumingMap = (HashMap) templateInfo.get(XML_CONSUMING_MAP); + this.templateID = (String) processMap.get(ATTR_TEMPLATE_ID); + } + + public TemplateInfo() {} + + public String getTemplateID() { + return templateID; + } + + public HashMap getTemplateInfo() { + HashMap templateInfo = new HashMap<>(); + templateInfo.put(XML_PROCESS_MAP, processMap); + templateInfo.put(XML_CONSUMING_MAP, consumingMap); + templateInfo.put(ATTR_DAY_COUNT, dayCount); + return templateInfo; + } + + public void writeXML(XMLPrintWriter writer) { + writer.startTAG(XML_TEMPLATE_INFO); + if (StringUtils.isNotEmpty(templateID)) { + writer.attr(ATTR_TEMPLATE_ID, this.templateID); + } + if (dayCount >= 0) { + writer.attr(ATTR_DAY_COUNT, this.dayCount); + } + writeProcessMap(writer); + writeConsumingMap(writer); + + writer.end(); + } + + private void writeProcessMap(XMLPrintWriter writer) { + writer.startTAG(XML_PROCESS_MAP); + writer.attr(ATTR_PROCESS, (String)processMap.get(ATTR_PROCESS)); + writer.attr(ATTR_FLOAT_COUNT, (int)processMap.get(ATTR_FLOAT_COUNT)); + writer.attr(ATTR_WIDGET_COUNT, (int)processMap.get(ATTR_WIDGET_COUNT)); + writer.attr(ATTR_CELL_COUNT, (int)processMap.get(ATTR_CELL_COUNT)); + writer.attr(ATTR_BLOCK_COUNT, (int)processMap.get(ATTR_BLOCK_COUNT)); + writer.attr(ATTR_REPORT_TYPE, (int)processMap.get(ATTR_REPORT_TYPE)); + writer.end(); + } + + private void writeConsumingMap(XMLPrintWriter writer) { + writer.startTAG(XML_CONSUMING_MAP); + writer.attr(ATTR_ACTIVITYKEY, (String)consumingMap.get(ATTR_ACTIVITYKEY)); + writer.attr(ATTR_JAR_TIME, (String)consumingMap.get(ATTR_JAR_TIME)); + writer.attr(ATTR_CREATE_TIME, (String)consumingMap.get(ATTR_CREATE_TIME)); + writer.attr(ATTR_UUID, (String)consumingMap.get(ATTR_UUID)); + writer.attr(ATTR_TIME_CONSUME, (long)consumingMap.get(ATTR_TIME_CONSUME)); + writer.attr(ATTR_VERSION, (String)consumingMap.get(ATTR_VERSION)); + writer.attr(ATTR_USERNAME, (String)consumingMap.get(ATTR_USERNAME)); + writer.end(); + } + + public void readXML(XMLableReader reader) { + if (!reader.isChildNode()) { + dayCount = reader.getAttrAsInt(ATTR_DAY_COUNT, 0); + templateID = reader.getAttrAsString(ATTR_TEMPLATE_ID, StringUtils.EMPTY); + } else { + try { + String name = reader.getTagName(); + if (XML_PROCESS_MAP.equals(name)) { + processMap.put(ATTR_PROCESS, reader.getAttrAsString(ATTR_PROCESS, StringUtils.EMPTY)); + processMap.put(ATTR_FLOAT_COUNT, reader.getAttrAsInt(ATTR_FLOAT_COUNT, 0)); + processMap.put(ATTR_WIDGET_COUNT, reader.getAttrAsInt(ATTR_WIDGET_COUNT, 0)); + processMap.put(ATTR_CELL_COUNT, reader.getAttrAsInt(ATTR_CELL_COUNT, 0)); + processMap.put(ATTR_BLOCK_COUNT, reader.getAttrAsInt(ATTR_BLOCK_COUNT, 0)); + processMap.put(ATTR_REPORT_TYPE, reader.getAttrAsInt(ATTR_REPORT_TYPE, 0)); + processMap.put(ATTR_TEMPLATE_ID, templateID); + } else if(XML_CONSUMING_MAP.equals(name)){ + consumingMap.put(ATTR_ACTIVITYKEY, reader.getAttrAsString(ATTR_ACTIVITYKEY, StringUtils.EMPTY)); + consumingMap.put(ATTR_JAR_TIME, reader.getAttrAsString(ATTR_JAR_TIME, StringUtils.EMPTY)); + consumingMap.put(ATTR_CREATE_TIME, reader.getAttrAsString(ATTR_CREATE_TIME, StringUtils.EMPTY)); + consumingMap.put(ATTR_TEMPLATE_ID, templateID); + consumingMap.put(ATTR_UUID, reader.getAttrAsString(ATTR_UUID, StringUtils.EMPTY)); + consumingMap.put(ATTR_TIME_CONSUME, reader.getAttrAsLong(ATTR_TIME_CONSUME, 0)); + consumingMap.put(ATTR_VERSION, reader.getAttrAsString(ATTR_VERSION, "8.0")); + consumingMap.put(ATTR_USERNAME, reader.getAttrAsString(ATTR_USERNAME, StringUtils.EMPTY)); + } + } catch (Exception ex) { + // 什么也不做,使用默认值 + } + } + } + + } + + + public static void main(String[] args) { + TemplateInfoCollector tic = TemplateInfoCollector.getInstance(); + tic.sendTemplateInfo(); + } +} diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateProcessInfo.java b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateProcessInfo.java new file mode 100644 index 000000000..d92ca7028 --- /dev/null +++ b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateProcessInfo.java @@ -0,0 +1,26 @@ +package com.fr.design.mainframe.templateinfo; + +import com.fr.base.io.IOFile; + +/** + * Created by plough on 2017/3/17. + */ +public abstract class TemplateProcessInfo { + + protected T template; + + public TemplateProcessInfo(T template) { + this.template = template; + } + + // 获取模板类型。0 代表普通报表,1 代表聚合报表,2 代表表单 + public abstract int getReportType(); + // 获取模板格子数 + public abstract int getCellCount(); + // 获取模板悬浮元素个数 + public abstract int getFloatCount(); + // 获取模板聚合块个数 + public abstract int getBlockCount(); + // 获取模板控件数 + public abstract int getWidgetCount(); +} diff --git a/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDockPlus.java b/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDockPlus.java index 6c85ce214..ada075aeb 100644 --- a/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDockPlus.java +++ b/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDockPlus.java @@ -12,52 +12,52 @@ public interface ToolBarMenuDockPlus { * * @return 工具 */ - public ToolBarDef[] toolbars4Target(); + ToolBarDef[] toolbars4Target(); /** * 文件菜单的子菜单 * * @return 子菜单 */ - public ShortCut[] shortcut4FileMenu(); + ShortCut[] shortcut4FileMenu(); /** * 目标的菜单 * * @return 菜单 */ - public MenuDef[] menus4Target(); + MenuDef[] menus4Target(); /** * 表单的工具栏 * * @return 表单工具栏 */ - public JPanel[] toolbarPanes4Form(); + JPanel[] toolbarPanes4Form(); /** * 表单的工具按钮 * * @return 工具按钮 */ - public JComponent[] toolBarButton4Form(); + JComponent[] toolBarButton4Form(); /** * 权限细粒度状态下的工具面板 * * @return 工具面板 */ - public JComponent toolBar4Authority(); + JComponent toolBar4Authority(); - public int getMenuState(); + int getMenuState(); - public int getToolBarHeight(); + int getToolBarHeight(); /** * 导出菜单的子菜单 ,目前用于图表设计器 * * @return 子菜单 */ - public ShortCut[] shortcut4ExportMenu(); - + ShortCut[] shortcut4ExportMenu(); + } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java b/designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java index 2e2743048..3ba3d610d 100644 --- a/designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java +++ b/designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java @@ -1 +1,72 @@ -package com.fr.design.parameter; import com.fr.base.Parameter; import com.fr.base.parameter.ParameterUI; import com.fr.design.mainframe.AuthorityEditPane; import javax.swing.*; import java.awt.*; /** * 参数设计界面接口 */ public interface ParameterDesignerProvider { public void addListener(ParaDefinitePane paraDefinitePane); public Component createWrapper(); public void setDesignHeight(int height); public Dimension getDesignSize(); public Dimension getPreferredSize(); public void populate(ParameterUI p); public void refreshAllNameWidgets(); public void refresh4TableData(String oldName, String newName); public void refreshParameter(ParaDefinitePane paraDefinitePane); public boolean isWithQueryButton(); public java.util.List getAllXCreatorNameList(); public boolean isWithoutParaXCreator(Parameter[] ps); public boolean isBlank(); public ParameterUI getParaTarget(); public boolean addingParameter2Editor(Parameter parameter, int index); public boolean addingParameter2EditorWithQueryButton(Parameter parameter, int index); public void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex); public JPanel[] toolbarPanes4Form(); public JComponent[] toolBarButton4Form(); public void initBeforeUpEdit(); public void populateParameterPropertyPane(ParaDefinitePane p); public void initWidgetToolbarPane(); public AuthorityEditPane getAuthorityEditPane(); public JPanel getEastUpPane(); public JPanel getEastDownPane(); public boolean isSupportAuthority(); public void removeSelection(); public ParameterBridge getParaComponent(); } \ No newline at end of file +package com.fr.design.parameter; + +import com.fr.base.Parameter; +import com.fr.base.parameter.ParameterUI; +import com.fr.design.mainframe.AuthorityEditPane; + +import javax.swing.*; +import java.awt.*; + + +/** + * 参数设计界面接口 + */ +public interface ParameterDesignerProvider { + + void addListener(ParaDefinitePane paraDefinitePane); + + Component createWrapper(); + + void setDesignHeight(int height); + + Dimension getDesignSize(); + + Dimension getPreferredSize(); + + void populate(ParameterUI p); + + void refreshAllNameWidgets(); + + void refresh4TableData(String oldName, String newName); + + void refreshParameter(ParaDefinitePane paraDefinitePane); + + boolean isWithQueryButton(); + + java.util.List getAllXCreatorNameList(); + + boolean isWithoutParaXCreator(Parameter[] ps); + + boolean isBlank(); + + ParameterUI getParaTarget(); + + boolean addingParameter2Editor(Parameter parameter, int index); + + boolean addingParameter2EditorWithQueryButton(Parameter parameter, int index); + + void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex); + + JPanel[] toolbarPanes4Form(); + + JComponent[] toolBarButton4Form(); + + void initBeforeUpEdit(); + + void populateParameterPropertyPane(ParaDefinitePane p); + + void initWidgetToolbarPane(); + + AuthorityEditPane getAuthorityEditPane(); + + JPanel getEastUpPane(); + + JPanel getEastDownPane(); + + boolean isSupportAuthority(); + + void removeSelection(); + + ParameterBridge getParaComponent(); + +} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/present/dict/TableDataDictPane.java b/designer_base/src/com/fr/design/present/dict/TableDataDictPane.java index 149118894..4e454ee9b 100644 --- a/designer_base/src/com/fr/design/present/dict/TableDataDictPane.java +++ b/designer_base/src/com/fr/design/present/dict/TableDataDictPane.java @@ -77,7 +77,7 @@ public class TableDataDictPane extends FurtherBasicBeanPane } }); keyColumnPane = ValueEditorPaneFactory.createValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor()}); - FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); + FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("FR-Designer_Parameter-Formula")); formulaEditor.setEnabled(true); valueDictPane = ValueEditorPaneFactory.createValueEditorPane(new Editor[]{new ColumnNameEditor(), new ColumnIndexEditor(), formulaEditor}); } @@ -95,9 +95,9 @@ public class TableDataDictPane extends FurtherBasicBeanPane Component[][] components = new Component[][]{ - new Component[]{new UILabel(" " + Inter.getLocText("DS-TableData") + ":", UILabel.RIGHT), firstLine}, - new Component[]{new UILabel(Inter.getLocText("Actual_Value") + ":", UILabel.RIGHT), keyColumnPane}, - new Component[]{new UILabel(Inter.getLocText("Display_Value") + ":", UILabel.RIGHT), valueDictPane} + new Component[]{new UILabel(" " + Inter.getLocText("FR-Designer_DS_TableData") + ":", UILabel.RIGHT), firstLine}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Actual_Value") + ":", UILabel.RIGHT), keyColumnPane}, + new Component[]{new UILabel(Inter.getLocText("FR-Designer_Display_Value") + ":", UILabel.RIGHT), valueDictPane} }; JPanel panel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); @@ -158,7 +158,7 @@ public class TableDataDictPane extends FurtherBasicBeanPane columnIndexEditor1.addItemListener(itemListener); keyColumnPane.setEditors(new Editor[]{columnNameEditor1, columnIndexEditor1}, columnNames[0]); - FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("Parameter-Formula")); + FormulaEditor formulaEditor = new FormulaEditor(Inter.getLocText("FR-Designer_Parameter-Formula")); formulaEditor.setEnabled(true); formulaEditor.addChangeListener(new ChangeListener() { diff --git a/designer_base/src/com/fr/design/roleAuthority/RoleTree.java b/designer_base/src/com/fr/design/roleAuthority/RoleTree.java index 3ee627987..1af8c1caa 100644 --- a/designer_base/src/com/fr/design/roleAuthority/RoleTree.java +++ b/designer_base/src/com/fr/design/roleAuthority/RoleTree.java @@ -1 +1 @@ -package com.fr.design.roleAuthority; import com.fr.general.NameObject; import com.fr.design.constants.UIConstants; import com.fr.design.beans.BasicBeanPane; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.gui.itree.refreshabletree.UserObjectRefreshJTree; import com.fr.design.mainframe.AuthorityPropertyPane; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.EastRegionContainerPane; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import javax.swing.*; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.*; import java.awt.*; import java.util.Enumeration; /** * Author : daisy * Date: 13-8-30 * Time: 下午3:32 */ public class RoleTree extends UserObjectRefreshJTree { private static final long serialVersionUID = 2L; private String roleName = null; public RoleTree() { super(); this.setCellRenderer(roleTreeRenderer); this.setEnabled(true); this.setEditable(true); this.setRowHeight(20); this.setDigIn(true); this.removeMouseListener(treeMouseListener); this.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { doWithValueChanged(e); } }); } public boolean isCheckBoxVisible(TreePath path) { return true; } /** * 更新UI */ public void updateUI() { super.updateUI(); setUI(new UIRoleTreeUI()); } protected void doWithValueChanged(TreeSelectionEvent e) { if (e.getNewLeadSelectionPath() != null) { if (e.getNewLeadSelectionPath().getLastPathComponent().toString() != Inter.getLocText("Role")) { roleName = e.getNewLeadSelectionPath().getLastPathComponent().toString(); setTabRoleName(roleName); refreshRoleTree(roleName); refreshElementAndAuthorityPane(); HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().judgeSheetAuthority(roleName); } } } protected void setTabRoleName(String roleName) { } /** * 刷新角色树 * * @param selectedRole 角色 */ public void refreshRoleTree(String selectedRole) { if (EastRegionContainerPane.getInstance().getUpPane() instanceof AuthorityPropertyPane) { AuthorityPropertyPane authorityPropertyPane = (AuthorityPropertyPane) EastRegionContainerPane.getInstance().getUpPane(); authorityPropertyPane.populate(); EastRegionContainerPane.getInstance().replaceUpPane(authorityPropertyPane); } } public void setSelectedRole(String selectedRole, TreePath parent) { ExpandMutableTreeNode node = (ExpandMutableTreeNode) parent.getLastPathComponent(); if (node.children() != null && node.getChildCount() >= 0) { for (Enumeration e = node.children(); e.hasMoreElements(); ) { ExpandMutableTreeNode n = (ExpandMutableTreeNode) e.nextElement(); Object userObj = n.getUserObject(); String chilld = null; if (userObj instanceof String) { chilld = (String) userObj; } else if (userObj instanceof NameObject) { NameObject nameObject = (NameObject) userObj; chilld = nameObject.getName(); } if (ComparatorUtils.equals(chilld, selectedRole)) { this.setSelectionPath(parent.pathByAddingChild(n)); return; } else { setSelectedRole(selectedRole, parent.pathByAddingChild(n)); } } } } private void refreshElementAndAuthorityPane() { JComponent authorityToolBar = DesignerContext.getDesignerFrame().getToolbarComponent(); if (authorityToolBar instanceof BasicBeanPane) { //说明是工具栏的 ((BasicBeanPane) authorityToolBar).populateAuthority(); } HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().repaint(); } public String getSelectedRoleName() { return roleName; } public void setSelectedRoleName(String name) { roleName = name; } private DefaultTreeCellRenderer roleTreeRenderer = new DefaultTreeCellRenderer() { private static final long serialVersionUID = 2L; public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); ExpandMutableTreeNode treeNode = (ExpandMutableTreeNode) value; Object userObj = treeNode.getUserObject(); if (userObj instanceof String) { // p:这个是column field. this.setIcon(null); this.setText((String) userObj); } else if (userObj instanceof NameObject) { NameObject nameObject = (NameObject) userObj; this.setText(nameObject.getName()); this.setIcon(null); } // 这里新建一个Label作为render是因为JTree在动态刷新的时候,节点上render画布的的宽度不会变,会使得一部分比较长的数据显示为"..." this.setBackgroundNonSelectionColor(UIConstants.NORMAL_BACKGROUND); this.setForeground(UIConstants.FONT_COLOR); this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE); return this; } }; /* * p:获得选中的NameObject = name + role. */ public NameObject getSelectedNameObject() { TreePath selectedTreePath = this.getSelectionPath(); if (selectedTreePath == null) { return null; } ExpandMutableTreeNode selectedTreeNode = (ExpandMutableTreeNode) selectedTreePath.getLastPathComponent(); Object selectedUserObject = selectedTreeNode.getUserObject(); return new NameObject(selectedUserObject.toString(), ""); } /** * p:添加一个NameObject节点 * @param no 需要添加的节点 */ public void addNameObject(NameObject no) { if (no == null) { return; } DefaultTreeModel treeModel = (DefaultTreeModel) this.getModel(); // 新建一个放着NameObject的newChildTreeNode,加到Root下面 ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); ExpandMutableTreeNode newChildTreeNode = new ExpandMutableTreeNode(no); root.add(newChildTreeNode); newChildTreeNode.add(new ExpandMutableTreeNode()); treeModel.reload(root); } /** * 刷新树节点 */ public void refreshTreeNode() { DefaultTreeModel treeModel = (DefaultTreeModel) this.getModel(); ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); if (interceptRefresh(root)) { return; } ExpandMutableTreeNode[] new_nodes = loadChildTreeNodes(root); java.util.List childTreeNodeList = new java.util.ArrayList(); for (int i = 0, len = root.getChildCount(); i < len; i++) { if (root.getChildAt(i) instanceof ExpandMutableTreeNode) { childTreeNodeList.add((ExpandMutableTreeNode) root.getChildAt(i)); } else { childTreeNodeList.add((DefaultMutableTreeNode) root.getChildAt(i)); } } root.removeAllChildren(); for (int ci = 0; ci < new_nodes.length; ci++) { Object cUserObject = new_nodes[ci].getUserObject(); for (int ni = 0, nlen = childTreeNodeList.size(); ni < nlen; ni++) { ExpandMutableTreeNode cTreeNode = (ExpandMutableTreeNode) childTreeNodeList.get(ni); if (ComparatorUtils.equals(cTreeNode.getUserObject(), cUserObject)) { new_nodes[ci].setExpanded(cTreeNode.isExpanded()); if (cTreeNode.getFirstChild() instanceof ExpandMutableTreeNode && cTreeNode.isExpanded()) { checkChildNodes(cTreeNode, new_nodes[ci]); } break; } } root.add(new_nodes[ci]); } } protected void checkChildNodes(ExpandMutableTreeNode oldNode, ExpandMutableTreeNode newNode) { for (int i = 0; i < oldNode.getChildCount(); i++) { ExpandMutableTreeNode oldChild = (ExpandMutableTreeNode) oldNode.getChildAt(i); for (int j = 0; j < newNode.getChildCount(); j++) { ExpandMutableTreeNode newChild = (ExpandMutableTreeNode) newNode.getChildAt(j); ExpandMutableTreeNode[] nodes = RoleTree.this.loadChildTreeNodes(newChild); for (int k = 0; k < nodes.length; k++) { newChild.add(nodes[k]); } if (newChild.getChildCount() > 1 && ((ExpandMutableTreeNode) newChild.getFirstChild()).getUserObject() == PENDING) { newChild.remove(0); } if (ComparatorUtils.equals(oldChild.getUserObject(), newChild.getUserObject())) { newChild.setExpanded(oldChild.isExpanded()); } } } } public NameObject getRealSelectedNameObject() { TreePath selectedTreePath = this.getSelectionPath(); if (selectedTreePath == null) { return null; } ExpandMutableTreeNode selectedTreeNode = (ExpandMutableTreeNode) selectedTreePath.getLastPathComponent(); Object selectedUserObject = selectedTreeNode.getUserObject(); if (selectedUserObject instanceof NameObject) { return (NameObject) selectedUserObject; } selectedTreeNode = (ExpandMutableTreeNode) selectedTreeNode.getParent(); selectedUserObject = selectedTreeNode.getUserObject(); if (selectedUserObject instanceof NameObject) { return (NameObject) selectedUserObject; } return null; } } \ No newline at end of file +package com.fr.design.roleAuthority; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.itree.checkboxtree.CheckBoxTree; import com.fr.design.gui.itree.checkboxtree.CheckBoxTreeSelectionModel; import com.fr.general.NameObject; import com.fr.design.constants.UIConstants; import com.fr.design.beans.BasicBeanPane; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.gui.itree.refreshabletree.UserObjectRefreshJTree; import com.fr.design.mainframe.AuthorityPropertyPane; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.EastRegionContainerPane; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import javax.swing.SwingUtilities; import javax.swing.JTree; import javax.swing.JComponent; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import java.awt.Component; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; /** * Author : daisy * Time: 下午3:32 * Date: 13-8-30 */ public class RoleTree extends UserObjectRefreshJTree { private static final long serialVersionUID = 2L; private String roleName = null; public RoleTree() { super(); this.setCellRenderer(roleTreeRenderer); this.setEnabled(true); this.setEditable(true); this.setRowHeight(20); this.setDigIn(true); Handler handler = createHandlerForRoleTree(); this.replaceMouseListener(this, handler, 0); this.replaceKeyListener(this, handler, 0); this.addTreeSelectionListener(handler); // this.removeMouseListener(treeMouseListener); // this.addTreeSelectionListener(new TreeSelectionListener() { // public void valueChanged(TreeSelectionEvent e) { // doWithValueChanged(e); // } // }); } public boolean isCheckBoxVisible(TreePath path) { return true; } /** * Creates the mouse listener and key listener used by RoleTree. * * @return the Handler. */ protected Handler createHandlerForRoleTree() { return new Handler(this); } protected static class Handler implements MouseListener, KeyListener, TreeSelectionListener { protected RoleTree _tree; int _hotspot = new UICheckBox().getPreferredSize().width; private int _toggleCount = -1; public Handler(RoleTree tree) { _tree = tree; } protected TreePath getTreePathForMouseEvent(MouseEvent e) { if (!SwingUtilities.isLeftMouseButton(e)) { return null; } if (!_tree.isCheckBoxEnabled()) { return null; } TreePath path = _tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return null; } // if (clicksInCheckBox(e, path)) { return path; // } else { // return null; // } } // protected boolean clicksInCheckBox(MouseEvent e, TreePath path) { // if (!_tree.isCheckBoxVisible(path)) { // return false; // } else { // Rectangle bounds = _tree.getPathBounds(path); // if (_tree.getComponentOrientation().isLeftToRight()) { // return e.getX() < bounds.x + _hotspot; // } else { // return e.getX() > bounds.x + bounds.width - _hotspot; // } // } // } private TreePath preventToggleEvent(MouseEvent e) { TreePath pathForMouseEvent = getTreePathForMouseEvent(e); if (pathForMouseEvent != null) { int toggleCount = _tree.getToggleClickCount(); if (toggleCount != -1) { _toggleCount = toggleCount; _tree.setToggleClickCount(-1); } } return pathForMouseEvent; } public void mouseClicked(MouseEvent e) { preventToggleEvent(e); } public void mousePressed(MouseEvent e) { TreePath path = preventToggleEvent(e); if (path != null) { toggleSelection(path); e.consume(); } } public void mouseReleased(MouseEvent e) { TreePath path = preventToggleEvent(e); if (path != null) { e.consume(); } if (_toggleCount != -1) { _tree.setToggleClickCount(_toggleCount); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void keyPressed(KeyEvent e) { if (e.isConsumed()) { return; } if (!_tree.isCheckBoxEnabled()) { return; } if (e.getModifiers() == 0 && e.getKeyChar() == KeyEvent.VK_SPACE) { toggleSelections(); } } public void keyTyped(KeyEvent e) { } public void keyReleased(KeyEvent e) { } public void valueChanged(TreeSelectionEvent e) { _tree.treeDidChange(); _tree.doWithValueChanged(e); } private void toggleSelection(TreePath path) { if (!_tree.isEnabled() || !_tree.isCheckBoxEnabled(path)) { return; } CheckBoxTreeSelectionModel selectionModel = _tree.getCheckBoxTreeSelectionModel(); boolean selected = selectionModel.isPathSelected(path, selectionModel.isDigIn()); selectionModel.removeTreeSelectionListener(this); try { if (!selectionModel.isSingleEventMode()) { selectionModel.setBatchMode(true); } if (selected) selectionModel.removeSelectionPath(path); else selectionModel.addSelectionPath(path); } finally { if (!selectionModel.isSingleEventMode()) { selectionModel.setBatchMode(false); } selectionModel.addTreeSelectionListener(this); _tree.treeDidChange(); _tree.doWithValueChanged(path); } } protected void toggleSelections() { TreePath[] treePaths = _tree.getSelectionPaths(); if (treePaths == null) { return; } for (int i = 0, length = treePaths.length; i < length; i++) { TreePath tmpTreePath = treePaths[i]; toggleSelection(tmpTreePath); } // for (TreePath treePath : treePaths) { // toggleSelection(treePath); // } } } /** * 更新UI */ public void updateUI() { super.updateUI(); setUI(new UIRoleTreeUI()); } /** * @param e 选中事件 */ protected void doWithValueChanged(TreeSelectionEvent e) { if (e.getNewLeadSelectionPath() != null) { if (!e.getNewLeadSelectionPath().getLastPathComponent().toString().equals(Inter.getLocText("FR-Designer_Role"))) { roleName = e.getNewLeadSelectionPath().getLastPathComponent().toString(); setTabRoleName(roleName); refreshRoleTree(roleName); refreshElementAndAuthorityPane(); HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().judgeSheetAuthority(roleName); } } } /** * @param treepath 所选的节点路径 */ protected void doWithValueChanged(TreePath treepath) { if (treepath != null && !treepath.getLastPathComponent().toString().equals(Inter.getLocText("FR-Designer_Role"))) { roleName = treepath.getLastPathComponent().toString(); setTabRoleName(roleName); refreshRoleTree(roleName); refreshElementAndAuthorityPane(); HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().judgeSheetAuthority(roleName); } } protected void setTabRoleName(String roleName) { } /** * 刷新角色树 * * @param selectedRole 角色 */ public void refreshRoleTree(String selectedRole) { if (EastRegionContainerPane.getInstance().getUpPane() instanceof AuthorityPropertyPane) { AuthorityPropertyPane authorityPropertyPane = (AuthorityPropertyPane) EastRegionContainerPane.getInstance().getUpPane(); authorityPropertyPane.populate(); EastRegionContainerPane.getInstance().replaceUpPane(authorityPropertyPane); } } public void setSelectedRole(String selectedRole, TreePath parent) { ExpandMutableTreeNode node = (ExpandMutableTreeNode) parent.getLastPathComponent(); if (node.children() != null && node.getChildCount() >= 0) { for (Enumeration e = node.children(); e.hasMoreElements(); ) { ExpandMutableTreeNode n = (ExpandMutableTreeNode) e.nextElement(); Object userObj = n.getUserObject(); String chilld = null; if (userObj instanceof String) { chilld = (String) userObj; } else if (userObj instanceof NameObject) { NameObject nameObject = (NameObject) userObj; chilld = nameObject.getName(); } if (ComparatorUtils.equals(chilld, selectedRole)) { this.setSelectionPath(parent.pathByAddingChild(n)); return; } else { setSelectedRole(selectedRole, parent.pathByAddingChild(n)); } } } } private void refreshElementAndAuthorityPane() { JComponent authorityToolBar = DesignerContext.getDesignerFrame().getToolbarComponent(); if (authorityToolBar instanceof BasicBeanPane) { //说明是工具栏的 ((BasicBeanPane) authorityToolBar).populateAuthority(); } HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().repaint(); } public String getSelectedRoleName() { return roleName; } public void setSelectedRoleName(String name) { roleName = name; } private DefaultTreeCellRenderer roleTreeRenderer = new DefaultTreeCellRenderer() { private static final long serialVersionUID = 2L; public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); ExpandMutableTreeNode treeNode = (ExpandMutableTreeNode) value; Object userObj = treeNode.getUserObject(); if (userObj instanceof String) { // p:这个是column field. this.setIcon(null); this.setText((String) userObj); } else if (userObj instanceof NameObject) { NameObject nameObject = (NameObject) userObj; this.setText(nameObject.getName()); this.setIcon(null); } // 这里新建一个Label作为render是因为JTree在动态刷新的时候,节点上render画布的的宽度不会变,会使得一部分比较长的数据显示为"..." this.setBackgroundNonSelectionColor(UIConstants.NORMAL_BACKGROUND); this.setForeground(UIConstants.FONT_COLOR); this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE); return this; } }; /** * 去除不需要的鼠标监听器 * * @param component 组件 * @param l 所需的鼠标监听器 * @param index 插入的索引 */ private void replaceMouseListener(Component component, MouseListener l, int index) { component.removeMouseListener(treeMouseListener); MouseListener[] listeners = component.getMouseListeners(); for (int i = 0, length = listeners.length; i < length; i++) { component.removeMouseListener(listeners[i]); } // for (MouseListener listener : listeners) { // component.removeMouseListener(listener); // } for (int i = 0; i < listeners.length; i++) { MouseListener listener = listeners[i]; if (index == i) { component.addMouseListener(l); } if (listener instanceof CheckBoxTree.Handler) { continue; } component.addMouseListener(listener); } // index is too large, add to the end. if (index > listeners.length - 1) { component.addMouseListener(l); } } /** * 去除一些不需要的键盘监听器 * * @param component 组件 * @param l 所需的键盘监听器 * @param index 插入的索引 */ private void replaceKeyListener(Component component, KeyListener l, int index) { KeyListener[] listeners = component.getKeyListeners(); for (int i = 0, length = listeners.length; i < length; i++) { component.removeKeyListener(listeners[i]); } // for (MouseListener listener : listeners) { // component.removeMouseListener(listener); // } for (int i = 0; i < listeners.length; i++) { KeyListener listener = listeners[i]; if (index == i) { component.addKeyListener(l); } if (listener instanceof CheckBoxTree.Handler) { continue; } component.addKeyListener(listener); } // index is too large, add to the end. if (index > listeners.length - 1) { component.addKeyListener(l); } } /* * p:获得选中的NameObject = name + role. */ public NameObject getSelectedNameObject() { TreePath selectedTreePath = this.getSelectionPath(); if (selectedTreePath == null) { return null; } ExpandMutableTreeNode selectedTreeNode = (ExpandMutableTreeNode) selectedTreePath.getLastPathComponent(); Object selectedUserObject = selectedTreeNode.getUserObject(); return new NameObject(selectedUserObject.toString(), ""); } /** * p:添加一个NameObject节点 * * @param no 需要添加的节点 */ public void addNameObject(NameObject no) { if (no == null) { return; } DefaultTreeModel treeModel = (DefaultTreeModel) this.getModel(); // 新建一个放着NameObject的newChildTreeNode,加到Root下面 ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); ExpandMutableTreeNode newChildTreeNode = new ExpandMutableTreeNode(no); root.add(newChildTreeNode); newChildTreeNode.add(new ExpandMutableTreeNode()); treeModel.reload(root); } /** * 刷新树节点 */ public void refreshTreeNode() { DefaultTreeModel treeModel = (DefaultTreeModel) this.getModel(); ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); if (interceptRefresh(root)) { return; } ExpandMutableTreeNode[] new_nodes = loadChildTreeNodes(root); List childTreeNodeList = new ArrayList(); for (int i = 0, len = root.getChildCount(); i < len; i++) { if (root.getChildAt(i) instanceof ExpandMutableTreeNode) { childTreeNodeList.add((ExpandMutableTreeNode) root.getChildAt(i)); } else { childTreeNodeList.add((DefaultMutableTreeNode) root.getChildAt(i)); } } root.removeAllChildren(); for (int ci = 0; ci < new_nodes.length; ci++) { Object cUserObject = new_nodes[ci].getUserObject(); for (int ni = 0, nlen = childTreeNodeList.size(); ni < nlen; ni++) { ExpandMutableTreeNode cTreeNode = (ExpandMutableTreeNode) childTreeNodeList.get(ni); if (ComparatorUtils.equals(cTreeNode.getUserObject(), cUserObject)) { new_nodes[ci].setExpanded(cTreeNode.isExpanded()); if (cTreeNode.getFirstChild() instanceof ExpandMutableTreeNode && cTreeNode.isExpanded()) { checkChildNodes(cTreeNode, new_nodes[ci]); } break; } } root.add(new_nodes[ci]); } } protected void checkChildNodes(ExpandMutableTreeNode oldNode, ExpandMutableTreeNode newNode) { for (int i = 0; i < oldNode.getChildCount(); i++) { ExpandMutableTreeNode oldChild = (ExpandMutableTreeNode) oldNode.getChildAt(i); for (int j = 0; j < newNode.getChildCount(); j++) { ExpandMutableTreeNode newChild = (ExpandMutableTreeNode) newNode.getChildAt(j); ExpandMutableTreeNode[] nodes = RoleTree.this.loadChildTreeNodes(newChild); for (int k = 0; k < nodes.length; k++) { newChild.add(nodes[k]); } if (newChild.getChildCount() > 1 && ((ExpandMutableTreeNode) newChild.getFirstChild()).getUserObject() == PENDING) { newChild.remove(0); } if (ComparatorUtils.equals(oldChild.getUserObject(), newChild.getUserObject())) { newChild.setExpanded(oldChild.isExpanded()); } } } } public NameObject getRealSelectedNameObject() { TreePath selectedTreePath = this.getSelectionPath(); if (selectedTreePath == null) { return null; } ExpandMutableTreeNode selectedTreeNode = (ExpandMutableTreeNode) selectedTreePath.getLastPathComponent(); Object selectedUserObject = selectedTreeNode.getUserObject(); if (selectedUserObject instanceof NameObject) { return (NameObject) selectedUserObject; } selectedTreeNode = (ExpandMutableTreeNode) selectedTreeNode.getParent(); selectedUserObject = selectedTreeNode.getUserObject(); if (selectedUserObject instanceof NameObject) { return (NameObject) selectedUserObject; } return null; } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/style/background/gradient/GradientBackgroundPane.java b/designer_base/src/com/fr/design/style/background/gradient/GradientBackgroundPane.java index 9ab11eb14..ee0cd3385 100644 --- a/designer_base/src/com/fr/design/style/background/gradient/GradientBackgroundPane.java +++ b/designer_base/src/com/fr/design/style/background/gradient/GradientBackgroundPane.java @@ -43,7 +43,7 @@ public class GradientBackgroundPane extends BackgroundDetailPane { JPanel blankJp = new JPanel(); gradientBar = new GradientBar(4, 254); blankJp.add(gradientBar); - UILabel jl = new UILabel(Inter.getLocText("Drag_to_select_gradient")); + UILabel jl = new UILabel(Inter.getLocText("FR-Designer_Drag_To_Select_Gradient")); jl.setHorizontalAlignment(SwingConstants.CENTER); gradientPanel.add(jl, BorderLayout.NORTH); gradientPanel.add(blankJp, BorderLayout.SOUTH); @@ -53,14 +53,14 @@ public class GradientBackgroundPane extends BackgroundDetailPane { JPanel innercenterPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); centerPane.add(new UILabel(" ")); centerPane.add(innercenterPane); - innercenterPane.add(new UILabel(Inter.getLocText("Gradient-Direction") + ":")); + innercenterPane.add(new UILabel(Inter.getLocText("FR-Designer_Gradient_Direction") + ":")); - left2right = new UIRadioButton(Inter.getLocText("PageSetup-Landscape")); + left2right = new UIRadioButton(Inter.getLocText("FR-Designer_PageSetup_Horizontal")); innercenterPane.add(left2right); left2right.setSelected(true); left2right.addActionListener(reviewListener); - top2bottom = new UIRadioButton(Inter.getLocText("PageSetup-Portrait")); + top2bottom = new UIRadioButton(Inter.getLocText("FR-Designer_PageSetup_Vertical")); innercenterPane.add(top2bottom); top2bottom.addActionListener(reviewListener); diff --git a/designer_base/src/com/fr/design/style/color/ColorPicker.java b/designer_base/src/com/fr/design/style/color/ColorPicker.java index 8807e1f40..e91968675 100644 --- a/designer_base/src/com/fr/design/style/color/ColorPicker.java +++ b/designer_base/src/com/fr/design/style/color/ColorPicker.java @@ -7,11 +7,14 @@ package com.fr.design.style.color; import com.fr.base.BaseUtils; import com.fr.general.FRLogger; +import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; -import javax.swing.*; /** * 取色框 diff --git a/designer_base/src/com/fr/design/style/color/ColorSelectBox.java b/designer_base/src/com/fr/design/style/color/ColorSelectBox.java index f926775ee..2dd5d51c3 100644 --- a/designer_base/src/com/fr/design/style/color/ColorSelectBox.java +++ b/designer_base/src/com/fr/design/style/color/ColorSelectBox.java @@ -63,6 +63,7 @@ public class ColorSelectBox extends AbstractSelectBox implements UIObserv fireDisplayComponent(ColorBackground.getInstance(color)); } }); + colorPane.setColor(color); return colorPane; } diff --git a/designer_base/src/com/fr/design/style/color/ColorSelectConfigManager.java b/designer_base/src/com/fr/design/style/color/ColorSelectConfigManager.java index 4d20c1207..e135b17c6 100644 --- a/designer_base/src/com/fr/design/style/color/ColorSelectConfigManager.java +++ b/designer_base/src/com/fr/design/style/color/ColorSelectConfigManager.java @@ -1,56 +1,195 @@ package com.fr.design.style.color; +import com.fr.file.XMLFileManager; + + +import com.fr.base.FRContext; +import com.fr.cluster.rpc.RPC; +import com.fr.file.BaseClusterHelper; +import com.fr.general.ComparatorUtils; +import com.fr.general.GeneralContext; +import com.fr.stable.EnvChangedListener; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLTools; +import com.fr.stable.xml.XMLableReader; +import com.fr.general.FRLogger; + import java.awt.Color; import java.util.ArrayList; import java.util.List; +import java.io.InputStream; /** * 最近使用颜色 - * @author focus * + * @author focus */ -public class ColorSelectConfigManager{ - - // 最近使用的颜色个数 - private int colorNums = 20; - // 最近使用颜色 - private List colors; - - private static ColorSelectConfigManager colorSelectConfigManager = null; - - public Color[] getColors() { - if(colors == null){ - colors = new ArrayList(); - } - return colors.toArray(new Color[colors.size()]); - } - - public int getColorNum() { - return colorNums; - } - public void setColorNum(int colorNums) { - this.colorNums = colorNums; - } - - public synchronized static ColorSelectConfigManager getInstance() { - if (colorSelectConfigManager == null) { - colorSelectConfigManager = new ColorSelectConfigManager(); - } - return colorSelectConfigManager; - } - - /** - * 添加颜色到最近使用队列中 - * - * @param color 颜色 - * - */ - public void addToColorQueue(Color color){ - // 过滤重复的最近使用颜色 - // 因为有个后进先出的问题,最近使用的颜色需要放到最前面所以没用set - if(colors.contains(color)){ - colors.remove(color); - } - colors.add(color); - } -} \ No newline at end of file +public class ColorSelectConfigManager extends XMLFileManager implements ColorSelectConfigManagerProvider { + + // 最近使用的颜色个数 + private int colorNums = 20; + + private static ColorSelectConfigManagerProvider configManager = null; + private static ColorSelectConfigManager colorSelectConfigManager = null; + private boolean init = true; + // 最近使用颜色 + private List colors = new ArrayList(); + private static final String RECENT_COLOR_TAG = "RecentColors"; + private static final String COLOR_TAG = "Color"; + + static { + GeneralContext.addEnvChangedListener(new EnvChangedListener() { + public void envChanged() { + ColorSelectConfigManager.envChanged(); + } + }); + } + + private static void envChanged() { + configManager = null; + } + + public Color[] getColors() { + + //初次打开软件时从xml文件中获取历史颜色信息 + if (init) { + ColorSelectConfigManagerProvider manager = ColorSelectConfigManager.getProviderInstance(); + this.colors = manager.getColorsFromFile(); + init = false; + } + if (colors == null) { + colors = new ArrayList(); + } + return colors.toArray(new Color[colors.size()]); + } + + public int getColorNum() { + return colorNums; + } + + public void setColorNum(int colorNums) { + this.colorNums = colorNums; + } + + public synchronized static ColorSelectConfigManager getInstance() { + if (colorSelectConfigManager == null) { + colorSelectConfigManager = new ColorSelectConfigManager(); + } + return colorSelectConfigManager; + } + + /** + * 添加颜色到最近使用队列中 + * + * @param color 颜色 + */ + public void addToColorQueue(Color color) { + if(color == null){ + return; + } + // 过滤重复的最近使用颜色 + // 因为有个后进先出的问题,最近使用的颜色需要放到最前面所以没用set + if (colors.contains(color)) { + colors.remove(color); + } + colors.add(color); + + /*@author yaohwu*/ + //将历史颜色信息保存到xml文件中去 + ColorSelectConfigManagerProvider manager = ColorSelectConfigManager.getProviderInstance(); + if (colors != null && !colors.isEmpty()) { + manager.setColorsToFile(colors); + } + try { + FRContext.getCurrentEnv().writeResource(manager); + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + } + + + /** + * 读取配置文件流 + * + * @param input 流 + * @throws Exception 异常 + */ + @Override + public void readFromInputStream(InputStream input) throws Exception { + ColorSelectConfigManager manager = new ColorSelectConfigManager(); + XMLTools.readInputStreamXML(manager, input); + configManager = manager; + FRContext.getCurrentEnv().writeResource(configManager); + } + + + /** + * 获取配置管理接口 + * + * @return 配置管理接口ConfigManagerProvider + */ + public synchronized static ColorSelectConfigManagerProvider getProviderInstance() { + if (configManager == null) { + if (isClusterMember()) { + return configManager; + } + configManager.readXMLFile(); + } + return configManager; + } + + private synchronized static boolean isClusterMember() { + switch (BaseClusterHelper.getClusterState()) { + case LEADER: + configManager = new ColorSelectConfigManager(); + RPC.registerSkeleton(configManager); + return false; + case MEMBER: + String ip = BaseClusterHelper.getMainServiceIP(); + configManager = (ColorSelectConfigManagerProvider) RPC.getProxy(ColorSelectConfigManager.class, ip); + return true; + default: + configManager = new ColorSelectConfigManager(); + break; + } + return false; + } + + public boolean writeResource() throws Exception { + return FRContext.getCurrentEnv().writeResource(ColorSelectConfigManager.getProviderInstance()); + } + + public String fileName() { + return "recentcolors.xml"; + } + + public void readXML(XMLableReader reader) { + String name = reader.getTagName(); + if (reader.isChildNode()) { + if (ComparatorUtils.equals(COLOR_TAG, name)) { + Color color = null; + colors.add(reader.getAttrAsColor("colors", color)); + } + } + } + + public void writeXML(XMLPrintWriter writer) { + writer.startTAG(RECENT_COLOR_TAG); + if (this.colors != null && !this.colors.isEmpty()) { + for (int i = 0; i < this.colors.size(); i++) { + writer.startTAG(COLOR_TAG); + writer.attr("colors", colors.get(i).getRGB()); + writer.end(); + } + } + writer.end(); + } + + public List getColorsFromFile() { + return this.colors; + } + + public void setColorsToFile(List colors) { + this.colors = colors; + } +} diff --git a/designer_base/src/com/fr/design/style/color/ColorSelectConfigManagerProvider.java b/designer_base/src/com/fr/design/style/color/ColorSelectConfigManagerProvider.java new file mode 100644 index 000000000..f9b2ec988 --- /dev/null +++ b/designer_base/src/com/fr/design/style/color/ColorSelectConfigManagerProvider.java @@ -0,0 +1,17 @@ +package com.fr.design.style.color; + +import com.fr.stable.file.RemoteXMLFileManagerProvider; + +import java.awt.Color; +import java.util.List; + + +/** + * Created by yaohwu on 2017/2/8. + */ +public interface ColorSelectConfigManagerProvider extends RemoteXMLFileManagerProvider { + + List getColorsFromFile(); + + void setColorsToFile(List colors); +} diff --git a/designer_base/src/com/fr/design/style/color/ColorSelectDetailPane.java b/designer_base/src/com/fr/design/style/color/ColorSelectDetailPane.java index 5c6c505a3..a84b772ca 100644 --- a/designer_base/src/com/fr/design/style/color/ColorSelectDetailPane.java +++ b/designer_base/src/com/fr/design/style/color/ColorSelectDetailPane.java @@ -1,112 +1,104 @@ package com.fr.design.style.color; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; +import com.fr.design.dialog.BasicPane; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Inter; -import javax.swing.JColorChooser; -import javax.swing.JPanel; +import javax.swing.*; import javax.swing.colorchooser.AbstractColorChooserPanel; import javax.swing.colorchooser.ColorSelectionModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; - -import com.fr.design.dialog.BasicPane; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.general.Inter; +import java.awt.*; /** * 颜色选择器更多颜色面板 - * @author focus * + * @author focus */ -public class ColorSelectDetailPane extends BasicPane{ - private static final int SELECT_PANEL_HEIGHT = 245; - // Selected color - private Color color; - - // 颜色选择器面板 - JColorChooser selectedPanel; - - // 最近使用颜色面板 - JPanel recentUsePanel; - - // 预览 - JPanel previewPanel; - - public JColorChooser getSelectedPanel() { - return selectedPanel; - } - - public void setSelectedPanel(JColorChooser selectedPanel) { - this.selectedPanel = selectedPanel; - } - - public Color getColor() { - return color; - } - - public void setColor(Color color) { - this.color = color; - } - - public ColorSelectDetailPane() { - super(); - } - - public ColorSelectDetailPane(Color color){ - if(color == null){ - color = Color.white; - } - this.color = color; - initComponents(); - } - - @Override - protected String title4PopupWindow() { - return null; - } - - protected void initComponents() { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - - // 颜色选择器面板 - selectedPanel = new JColorChooser(this.color); - selectedPanel.setPreferredSize(new Dimension(selectedPanel.getWidth(),SELECT_PANEL_HEIGHT)); - AbstractColorChooserPanel[] choosers = selectedPanel.getChooserPanels(); - for(int i=0;i colorChangeListenerList = new ArrayList(); - - ColorSelectDetailPane pane; - + + + /* default */ ColorSelectDetailPane pane; + /** * Constructor. */ public ColorSelectPane() { - super(true); - initialCompents(true); + super(true); + initialCompents(true); } public ColorSelectPane(boolean isSupportTransparent) { super(isSupportTransparent); initialCompents(isSupportTransparent); } - + private void initialCompents(boolean isSupportTransparent) { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); - if (isSupportTransparent) { - UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency")); - this.add(transpanrentButton, BorderLayout.NORTH); - transpanrentButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - doTransparent(); - } - }); - } - - // center - JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); - this.add(centerPane, BorderLayout.CENTER); - - centerPane.add(getRow1Pane()); - - JPanel menuColorPane1 = getMenuColorPane(); - centerPane.add(menuColorPane1); + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); + if (isSupportTransparent) { + UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency")); + this.add(transpanrentButton, BorderLayout.NORTH); + transpanrentButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + doTransparent(); + } + }); + } + + // center + JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); + this.add(centerPane, BorderLayout.CENTER); + + centerPane.add(getRow1Pane()); + + JPanel menuColorPane1 = getMenuColorPane(); + centerPane.add(menuColorPane1); Color[] colorArray = this.getColorArray(); - for (int i = 0; i < colorArray.length; i++) { - Color color = colorArray[i] == null ? UsedColorPane.DEFAULT_COLOR : colorArray[i]; - menuColorPane1.add(new ColorCell(color, this)); - } - - centerPane.add(Box.createVerticalStrut(1)); - - UIButton customButton = new UIButton(Inter.getLocText("FR-Designer-Basic_More_Color")); - - customButton.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - customButtonPressed(); - } - }); - customButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); - JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane(); - centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 8, 8)); - centerPane1.add(customButton, BorderLayout.NORTH); - centerPane.add(centerPane1); - } - - protected JPanel getMenuColorPane() { - JPanel menuColorPane = new JPanel(); - menuColorPane.setLayout(new GridLayout(5, 8, 1, 1)); - menuColorPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); - - return menuColorPane; - } - - // 第一行,1个取色按钮 + 7个最近使用的颜色 - protected JPanel getRow1Pane() { - JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout()); - row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0)); - row1Pane.setPreferredSize(new Dimension(135, 24)); // 宽度为 16 * 8 + 7 - - // 最近使用 - UsedColorPane usedColorPane = new UsedColorPane(1, 8, 1, ColorSelectConfigManager.getInstance().getColors(), this, true, true); - usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8)); - row1Pane.add(usedColorPane.getPane()); - return row1Pane; - } - - protected Color[] getColorArray(){ + for (int i = 0; i < colorArray.length; i++) { + Color color = colorArray[i] == null ? UsedColorPane.DEFAULT_COLOR : colorArray[i]; + menuColorPane1.add(new ColorCell(color, this)); + } + + centerPane.add(Box.createVerticalStrut(1)); + + UIButton customButton = new UIButton(Inter.getLocText("FR-Designer-Basic_More_Color")); + + customButton.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + customButtonPressed(); + } + }); + customButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); + JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane(); + centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 8, 8)); + centerPane1.add(customButton, BorderLayout.NORTH); + centerPane.add(centerPane1); + } + + protected JPanel getMenuColorPane() { + JPanel menuColorPane = new JPanel(); + menuColorPane.setLayout(new GridLayout(5, 8, 1, 1)); + menuColorPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); + + return menuColorPane; + } + + // 第一行,1个取色按钮 + 1个留空的单元格 + 6个最近使用的颜色 + protected JPanel getRow1Pane() { + JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout()); + row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0)); + row1Pane.setPreferredSize(new Dimension(135, 24)); // 宽度为 16 * 8 + 7 + + // 最近使用 + UsedColorPane usedColorPane = new UsedColorPane(1, 8, 1, this, true, true); + usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8)); + row1Pane.add(usedColorPane.getPane()); + return row1Pane; + } + + protected Color[] getColorArray() { return ColorFactory.MenuColors; } @@ -125,15 +123,16 @@ public class ColorSelectPane extends TransparentPane implements ColorSelectable /** * Add change listener. * 增加监听 - * @param 监听 + * + * @param changeListener */ public void addChangeListener(ChangeListener changeListener) { this.colorChangeListenerList.add(changeListener); } - + @Override protected String title4PopupWindow() { - return "Color"; + return "Color"; } /** @@ -166,38 +165,36 @@ public class ColorSelectPane extends TransparentPane implements ColorSelectable /** * 选中颜色 - * @param 颜色单元格 - * */ - @Override - public void colorSetted(ColorCell colorCell) { - colorCell.repaint(); - } - - /** - * 初始化中央面板 - * @param centerPane 中央面板 - * - */ - @Override - public void initCenterPaneChildren(JPanel centerPane) { - GUICoreUtils.initCenterPaneChildren(centerPane, this); - } - - /** - * 透明 - */ - @Override - public void doTransparent() { - this.setColor(null); - } - - /** - * 更多颜色 - */ - @Override - public void customButtonPressed() { - pane = new ColorSelectDetailPane(Color.WHITE); - ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this); - } + @Override + public void colorSetted(ColorCell colorCell) { + colorCell.repaint(); + } + + /** + * 初始化中央面板 + * + * @param centerPane 中央面板 + */ + @Override + public void initCenterPaneChildren(JPanel centerPane) { + GUICoreUtils.initCenterPaneChildren(centerPane, this); + } + + /** + * 透明 + */ + @Override + public void doTransparent() { + this.setColor(null); + } + + /** + * 更多颜色 + */ + @Override + public void customButtonPressed() { + pane = new ColorSelectDetailPane(Color.WHITE); + ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this); + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/style/color/NewColorSelectPane.java b/designer_base/src/com/fr/design/style/color/NewColorSelectPane.java index b9903a81f..cb4398fd9 100644 --- a/designer_base/src/com/fr/design/style/color/NewColorSelectPane.java +++ b/designer_base/src/com/fr/design/style/color/NewColorSelectPane.java @@ -1,215 +1,205 @@ package com.fr.design.style.color; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; - -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.JPanel; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -import com.fr.design.constants.UIConstants; import com.fr.design.border.UIRoundedBorder; +import com.fr.design.constants.UIConstants; +import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.dialog.BasicPane; import com.fr.general.Inter; +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; + /** - * * @author zhou * @since 2012-5-29上午10:39:35 */ public class NewColorSelectPane extends BasicPane implements ColorSelectable { - private static final long serialVersionUID = -8634152305687249392L; - - private Color color = null; // color - // color setting action. - private ArrayList colorChangeListenerList = new ArrayList(); - - // 颜色选择器 - private ColorSelectDetailPane pane; - // 是否支持透明 - private boolean isSupportTransparent; - - private final static int TRANSPANENT_WINDOW_HEIGHT = 165; - private final static int WINDWO_HEIGHT = 150; - - // 最近使用颜色 - UsedColorPane usedColorPane; - - /** - * Constructor. - */ - public NewColorSelectPane() { - this(false); - } - - /** - * Constructor. - */ - public NewColorSelectPane(boolean isSupportTransparent) { - this.isSupportTransparent = isSupportTransparent; - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); - if (isSupportTransparent) { - UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency")); - this.add(transpanrentButton, BorderLayout.NORTH); - transpanrentButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - doTransparent(); - } - }); - } - - // center - JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); - this.add(centerPane, BorderLayout.CENTER); - - // 第一行 - JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout()); - row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0)); - row1Pane.setPreferredSize(new Dimension(135, 16)); // 宽度为 16 * 8 + 7 - centerPane.add(row1Pane); - // 最近使用 - usedColorPane = new UsedColorPane(1, 8, 1, ColorSelectConfigManager.getInstance().getColors(), this, true, false); - usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8)); - row1Pane.add(usedColorPane.getPane()); - - JPanel menuColorPane1 = new JPanel(); - centerPane.add(menuColorPane1); - - menuColorPane1.setLayout(new GridLayout(5, 8, 1, 1)); - menuColorPane1.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); - for (int i = 0; i < ColorFactory.MenuColors.length; i++) { - menuColorPane1.add(new ColorCell(ColorFactory.MenuColors[i], this)); - } - - centerPane.add(Box.createVerticalStrut(1)); - - // mod by anchore 16/11/16 - UIButton customButton = new UIButton(Inter.getLocText("FR-Designer-Basic_More_Color")); - //UIButton customButton = new UIButton(Inter.getLocText(new String[]{"More", "Color"}) + "..."); - - customButton.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - customButtonPressed(); - } - }); - customButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); - JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane(); - centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 8)); - centerPane1.add(customButton, BorderLayout.NORTH); - centerPane.add(centerPane1); - } - - - - /** - * 添加监听 - * @param 监听列表 - * Add change listener. - */ - public void addChangeListener(ChangeListener changeListener) { - this.colorChangeListenerList.add(changeListener); - } - - @Override - protected String title4PopupWindow() { - return "Color"; - } - - /** - * 获取颜色 - * @return 颜色 - * Return the color. - */ - public Color getColor() { - return color; - } - - /** - * 获取颜色 - * - * @return 颜色 - */ - public Color getNotNoneColor() { - if (color == null) { - setColor(Color.WHITE); - return Color.WHITE; - } - return color; - } - - /** - * Set the color. - * - * @param color - * the new color. - */ - @Override - public void setColor(Color color) { - this.color = color; - - // fire color change. - if (!colorChangeListenerList.isEmpty()) { - ChangeEvent evt = new ChangeEvent(this); - - for (int i = 0; i < colorChangeListenerList.size(); i++) { - this.colorChangeListenerList.get(i).stateChanged(evt); - } - } - ColorSelectConfigManager.getInstance().addToColorQueue(color); - this.repaint(); - } - - /** - * 设置颜色 - * @param 颜色位置 - */ - @Override - public void colorSetted(ColorCell colorCell) { - colorCell.repaint(); - } - - protected void doTransparent() { - setColor(null); - } - protected void customButtonPressed() { - pane = new ColorSelectDetailPane(Color.WHITE); - ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this); - } - - @Override - public Dimension getPreferredSize() { - if(isSupportTransparent){ - return new Dimension(super.getPreferredSize().width, TRANSPANENT_WINDOW_HEIGHT); - } - return new Dimension(super.getPreferredSize().width, WINDWO_HEIGHT); - } - - /** - * 更新最近使用颜色 - * - */ - public void updateUsedColor(){ - usedColorPane.updateUsedColor(); - } - + private static final long serialVersionUID = -8634152305687249392L; + + private Color color = null; // color + // color setting action. + private ArrayList colorChangeListenerList = new ArrayList(); + + // 颜色选择器 + private ColorSelectDetailPane pane; + // 是否支持透明 + private boolean isSupportTransparent; + + private final static int TRANSPANENT_WINDOW_HEIGHT = 165; + private final static int WINDWO_HEIGHT = 150; + + // 最近使用颜色 + private UsedColorPane usedColorPane; + + /** + * Constructor. + */ + public NewColorSelectPane() { + this(false); + } + + /** + * Constructor. + */ + public NewColorSelectPane(boolean isSupportTransparent) { + this.isSupportTransparent = isSupportTransparent; + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); + if (isSupportTransparent) { + UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency")); + this.add(transpanrentButton, BorderLayout.NORTH); + transpanrentButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + doTransparent(); + } + }); + } + + // center + JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); + this.add(centerPane, BorderLayout.CENTER); + + // 第一行 + JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout()); + row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0)); + row1Pane.setPreferredSize(new Dimension(135, 16)); // 宽度为 16 * 8 + 7 + centerPane.add(row1Pane); + // 最近使用 + usedColorPane = new UsedColorPane(1, 8, 1, this, true, false); + usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8)); + row1Pane.add(usedColorPane.getPane()); + + JPanel menuColorPane1 = new JPanel(); + centerPane.add(menuColorPane1); + + menuColorPane1.setLayout(new GridLayout(5, 8, 1, 1)); + menuColorPane1.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); + for (int i = 0; i < ColorFactory.MenuColors.length; i++) { + menuColorPane1.add(new ColorCell(ColorFactory.MenuColors[i], this)); + } + + centerPane.add(Box.createVerticalStrut(1)); + + // mod by anchore 16/11/16 + UIButton customButton = new UIButton(Inter.getLocText("FR-Designer-Basic_More_Color")); + + customButton.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + customButtonPressed(); + } + }); + customButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); + JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane(); + centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 8)); + centerPane1.add(customButton, BorderLayout.NORTH); + centerPane.add(centerPane1); + } + + + /** + * 添加监听 + * + * @param 监听列表 Add change listener. + */ + public void addChangeListener(ChangeListener changeListener) { + this.colorChangeListenerList.add(changeListener); + } + + @Override + protected String title4PopupWindow() { + return "Color"; + } + + /** + * 获取颜色 + * + * @return 颜色 + * Return the color. + */ + public Color getColor() { + return color; + } + + /** + * 获取颜色 + * + * @return 颜色 + */ + public Color getNotNoneColor() { + if (color == null) { + setColor(Color.WHITE); + return Color.WHITE; + } + return color; + } + + /** + * Set the color. + * + * @param color the new color. + */ + @Override + public void setColor(Color color) { + this.color = color; + + // fire color change. + if (!colorChangeListenerList.isEmpty()) { + ChangeEvent evt = new ChangeEvent(this); + + for (int i = 0; i < colorChangeListenerList.size(); i++) { + this.colorChangeListenerList.get(i).stateChanged(evt); + } + } + ColorSelectConfigManager.getInstance().addToColorQueue(color); + this.repaint(); + } + + /** + * 设置颜色 + * + * @param 颜色位置 + */ + @Override + public void colorSetted(ColorCell colorCell) { + colorCell.repaint(); + } + + protected void doTransparent() { + setColor(null); + } + + protected void customButtonPressed() { + pane = new ColorSelectDetailPane(Color.WHITE); + ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this); + } + + @Override + public Dimension getPreferredSize() { + if (isSupportTransparent) { + return new Dimension(super.getPreferredSize().width, TRANSPANENT_WINDOW_HEIGHT); + } + return new Dimension(super.getPreferredSize().width, WINDWO_HEIGHT); + } + + /** + * 更新最近使用颜色 + */ + public void updateUsedColor() { + usedColorPane.updateUsedColor(); + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/style/color/RecentUseColorPane.java b/designer_base/src/com/fr/design/style/color/RecentUseColorPane.java index 914436d0f..c85ff6be8 100644 --- a/designer_base/src/com/fr/design/style/color/RecentUseColorPane.java +++ b/designer_base/src/com/fr/design/style/color/RecentUseColorPane.java @@ -1,55 +1,48 @@ package com.fr.design.style.color; -import java.awt.BorderLayout; -import java.awt.Color; - -import javax.swing.JColorChooser; -import javax.swing.JPanel; - import com.fr.design.dialog.BasicPane; import com.fr.design.layout.FRGUIPaneFactory; -public class RecentUseColorPane extends BasicPane implements ColorSelectable{ - - JColorChooser chooser; - - @Override - protected String title4PopupWindow() { - return null; - } - - public RecentUseColorPane() { - } - - public RecentUseColorPane(JColorChooser chooser) { - this.chooser = chooser; - - // center - JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); - this.add(centerPane, BorderLayout.CENTER); - // 最近使用 - UsedColorPane pane = new UsedColorPane(2, 10, ColorSelectConfigManager.getInstance().getColors(),this); - centerPane.add(pane.getPane()); - } - - /** - * 选中颜色 - * - * @param 颜色 - */ - @Override - public void colorSetted(ColorCell color) { - - } - - @Override - public Color getColor() { - return null; - } - - @Override - public void setColor(Color color) { - chooser.getSelectionModel().setSelectedColor(color); - } - +import javax.swing.*; +import java.awt.*; + +public class RecentUseColorPane extends BasicPane implements ColorSelectable { + + private JColorChooser chooser; + + @Override + protected String title4PopupWindow() { + return null; + } + + + public RecentUseColorPane(JColorChooser chooser) { + this.chooser = chooser; + + // center + JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); + this.add(centerPane, BorderLayout.CENTER); + // 最近使用 + UsedColorPane pane = new UsedColorPane(2, 10, this); + centerPane.add(pane.getPane()); + } + + /** + * 选中颜色 + */ + @Override + public void colorSetted(ColorCell color) { + + } + + @Override + public Color getColor() { + return null; + } + + @Override + public void setColor(Color color) { + chooser.getSelectionModel().setSelectedColor(color); + } + } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/style/color/UsedColorPane.java b/designer_base/src/com/fr/design/style/color/UsedColorPane.java index c8dfdcaec..5594254c3 100644 --- a/designer_base/src/com/fr/design/style/color/UsedColorPane.java +++ b/designer_base/src/com/fr/design/style/color/UsedColorPane.java @@ -1,119 +1,112 @@ package com.fr.design.style.color; -import java.awt.Color; -import java.awt.GridLayout; - -import javax.swing.BorderFactory; -import javax.swing.JPanel; - import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ibutton.SpecialUIButton; -public class UsedColorPane extends BasicPane{ - - public static final Color DEFAULT_COLOR = new Color(222,222,222); - - // 最近使用面板列数 - private int columns; - // 最近使用面板行数 - private int rows; - // 留白的单元格数量 - private int reserveCells; - // 是否需要取色器按钮 - private boolean needPickColorButton; - // 是否在取色时实时设定颜色 - private boolean setColorRealTime; - // 最近使用颜色 - private Object[] colors; - // 最近使用面板 - private JPanel pane; - - private ColorSelectable selectable; - - public JPanel getPane() { - return pane; - } - - public void setPane(JPanel pane) { - this.pane = pane; - } - - public UsedColorPane(){ - - } - - /** - * 构造函数 - * - * @param rows 行 - * @param columns 列 - * @param reserveCells 留白的单元格个数 - * @param colors 最近使用的颜色 - * @param needPickColorButton 是否需要加上取色器按钮 - * @param setColorRealTime 取色器是否实时设定颜色 - */ - public UsedColorPane(int rows,int columns,int reserveCells, Object[] colors, ColorSelectable selectable, boolean needPickColorButton, boolean setColorRealTime){ - this.columns = columns; - this.rows = rows; - this.reserveCells = reserveCells; - this.colors = colors; - this.selectable = selectable; - this.needPickColorButton = needPickColorButton; - this.setColorRealTime = setColorRealTime; - initialComponents(); - } - - public UsedColorPane(int rows,int columns, Object[] colors,ColorSelectable selectable){ - this(rows, columns, 0, colors, selectable, false, false); - } - - private void initialComponents(){ - int total = columns * rows; - JPanel panel = new JPanel(); - panel.setLayout(new GridLayout(rows,columns, 1, 1)); - panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8)); - Color[] colors = ColorSelectConfigManager.getInstance().getColors(); - int size = colors.length; - - int i = 0; - if (needPickColorButton) { - // 取色按钮 - SpecialUIButton pickColorButton = PickColorButtonFactory.getPickColorButton(selectable, PickColorButtonFactory.IconType.ICON16, setColorRealTime); - panel.add(pickColorButton); - i++; - this.reserveCells += 1; - } - while (i < this.reserveCells) { - ColorCell cc = new ColorCell(DEFAULT_COLOR, selectable); - cc.setVisible(false); - panel.add(cc); - i++; - } - while (i < total) { - Color color = i < size ? colors[size-1-i]: DEFAULT_COLOR; - panel.add(new ColorCell(color == null ? DEFAULT_COLOR : color, selectable)); - i++; - } - this.pane = panel; - } - - /** - * 更新最近使用颜色 - * - */ - public void updateUsedColor(){ - int total = columns * rows; - Color[] colors = ColorSelectConfigManager.getInstance().getColors(); - int size = colors.length; - for(int i=this.reserveCells; i dbcomponents) { - for (JComponent jcomponent : dbcomponents) { - jcomponent.setDoubleBuffered(true); - } - } - - /** - * 禁止双缓冲状态,并将初始状态为启动双缓冲的组件保存到dbcomponents中 - */ - public static void disableBuffer(Component comp, ArrayList dbcomponents) { - if ((comp instanceof JComponent) && comp.isDoubleBuffered()) { - JComponent jcomponent = (JComponent) comp; - - dbcomponents.add(jcomponent); - jcomponent.setDoubleBuffered(false); - } - - if (comp instanceof Container) { - Container container = (Container) comp; - int count = container.getComponentCount(); - - if (count > 0) { - for (int i = 0; i < count; i++) { - Component component = container.getComponent(i); - - disableBuffer(component, dbcomponents); - } - } - } - } - - public static int indexOfComponent(Container container, Component target) { - int count = container.getComponentCount(); - - for (int i = 0; i < count; i++) { - Component child = container.getComponent(i); - - if (child == target) { - return i; - } - } - - return -1; - } - - /** - * 计算组件root相对于其顶层容器的可见区域 - */ - public static Rectangle computeVisibleRectRel2Root(Component root) { - Container container = findAncestorScrollPane(root); - - if (container == null) { - return getRelativeBounds(root); - } else { - // 如果是JScrollPane的子组件,需要计算其viewport与改组件的交叉的可见区域 - return getBoundsRel2Parent(root, container); - } - } - - /** - * 计算组件root相对于其顶层容器的可见区域 - */ - public static Rectangle computeVisibleRect(JComponent root) { - Rectangle root_bounds = ComponentUtils.getRelativeBounds(root); - Rectangle rect = computeVisibleRectRel2Root(root); - rect.x -= root_bounds.x; - rect.y -= root_bounds.y; - - return rect; - } - - private static Rectangle getBoundsRel2Parent(Component child, Container parent) { - Rectangle cRect = getRelativeBounds(child); - Rectangle pRect = getRelativeBounds(parent); - Rectangle bounds = new Rectangle(); - Rectangle2D.intersect(cRect, pRect, bounds); - - return bounds; - } - - public static Container findAncestorScrollPane(Component p) { - if ((p == null) || !(p instanceof Container)) { - return null; - } - - Container c = p.getParent(); - - return findAncestorScrollPane(c); - } - - public static boolean isRootComponent(Component root) { - Container parent = root.getParent(); - return parent == null; - } - - public static boolean isChildOf(Component component, Class parent) { - Container container = component.getParent(); - if (container != null) { - if (ComparatorUtils.equals(container.getClass(), parent)) { - return true; - } else { - return isChildOf(container, parent); - } - } - return false; - } +package com.fr.design.utils; + +import com.fr.general.ComparatorUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; + +/** + * 工具类,提供常用的工具方法 + */ +public class ComponentUtils { + + private ComponentUtils() { + } + + public static boolean isComponentVisible(Component comp) { + if (!comp.isVisible() && !isRootComponent(comp)) { + return false; + } + Component parent = comp.getParent(); + + return parent == null || isComponentVisible(parent); + + } + + /** + * 获取component所在的容器的绝对位置 + */ + public static Rectangle getRelativeBounds(Component component) { + Rectangle bounds = new Rectangle(0, 0, component.getWidth(), component.getHeight()); + Container parent = component.getParent(); + + while (parent != null) { + bounds.x += component.getX(); + bounds.y += component.getY(); + component = parent; + parent = component.getParent(); + } + + return bounds; + } + + /** + * 恢复双缓冲状态,dbcomponents保存着初始状态为启动双缓冲的组件 + */ + public static void resetBuffer(ArrayList dbcomponents) { + for (JComponent jcomponent : dbcomponents) { + jcomponent.setDoubleBuffered(true); + } + } + + /** + * 禁止双缓冲状态,并将初始状态为启动双缓冲的组件保存到dbcomponents中 + */ + public static void disableBuffer(Component comp, ArrayList dbcomponents) { + if ((comp instanceof JComponent) && comp.isDoubleBuffered()) { + JComponent jcomponent = (JComponent) comp; + + dbcomponents.add(jcomponent); + jcomponent.setDoubleBuffered(false); + } + + if (comp instanceof Container) { + Container container = (Container) comp; + int count = container.getComponentCount(); + + if (count > 0) { + for (int i = 0; i < count; i++) { + Component component = container.getComponent(i); + + disableBuffer(component, dbcomponents); + } + } + } + } + + public static int indexOfComponent(Container container, Component target) { + int count = container.getComponentCount(); + + for (int i = 0; i < count; i++) { + Component child = container.getComponent(i); + + if (child.equals(target)) { + return i; + } + } + + return -1; + } + + /** + * 计算组件root相对于其顶层容器的可见区域 + */ + public static Rectangle computeVisibleRectRel2Root(Component root) { + Container container = findAncestorScrollPane(root); + + if (container == null) { + return getRelativeBounds(root); + } else { + // 如果是JScrollPane的子组件,需要计算其viewport与改组件的交叉的可见区域 + return getBoundsRel2Parent(root, container); + } + } + + /** + * 计算组件root相对于其顶层容器的可见区域 + */ + public static Rectangle computeVisibleRect(JComponent root) { + Rectangle rootBounds = ComponentUtils.getRelativeBounds(root); + Rectangle rect = computeVisibleRectRel2Root(root); + rect.x -= rootBounds.x; + rect.y -= rootBounds.y; + + return rect; + } + + private static Rectangle getBoundsRel2Parent(Component child, Container parent) { + Rectangle cRect = getRelativeBounds(child); + Rectangle pRect = getRelativeBounds(parent); + Rectangle bounds = new Rectangle(); + Rectangle2D.intersect(cRect, pRect, bounds); + + return bounds; + } + + public static Container findAncestorScrollPane(Component p) { + if ((p == null) || !(p instanceof Container)) { + return null; + } + + Container c = p.getParent(); + + return findAncestorScrollPane(c); + } + + public static boolean isRootComponent(Component root) { + Container parent = root.getParent(); + return parent == null; + } + + public static boolean isChildOf(Component component, Class parent) { + Container container = component.getParent(); + if (container != null) { + if (ComparatorUtils.equals(container.getClass(), parent)) { + return true; + } else { + return isChildOf(container, parent); + } + } + return false; + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/env/RemoteEnv.java b/designer_base/src/com/fr/env/RemoteEnv.java index a0bdc0e13..ac5732e73 100644 --- a/designer_base/src/com/fr/env/RemoteEnv.java +++ b/designer_base/src/com/fr/env/RemoteEnv.java @@ -55,7 +55,7 @@ import java.util.Timer; import java.util.logging.Level; import java.util.regex.Pattern; -public class RemoteEnv implements Env { +public class RemoteEnv extends AbstractEnv { private static final int TIME_OUT = 30 * 1000; private static final int PLAIN_SOCKET_PORT = 80; private static final int SSL_PORT = 443; @@ -1483,6 +1483,8 @@ public class RemoteEnv implements Env { * @throws Exception 异常 */ public boolean writeSvgFile(SvgProvider svgFile) throws Exception { + testServerConnection(); + HashMap para = new HashMap(); para.put("op", "fr_remote_design"); para.put("cmd", "design_save_svg"); @@ -1534,6 +1536,8 @@ public class RemoteEnv implements Env { */ @Override public boolean writeResource(XMLFileManagerProvider mgr) throws Exception { + testServerConnection(); + HashMap para = new HashMap(); para.put("op", "fr_remote_design"); para.put("cmd", "design_save_resource"); diff --git a/designer_base/src/com/fr/start/BaseDesigner.java b/designer_base/src/com/fr/start/BaseDesigner.java index 016ad604d..301a9191f 100644 --- a/designer_base/src/com/fr/start/BaseDesigner.java +++ b/designer_base/src/com/fr/start/BaseDesigner.java @@ -7,7 +7,7 @@ import com.fr.base.FRContext; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; import com.fr.design.RestartHelper; -import com.fr.design.extra.WebDialog; +import com.fr.design.extra.WebViewDlgHelper; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.MutilTempalteTabPane; import com.fr.design.file.TemplateTreePane; @@ -124,10 +124,10 @@ public abstract class BaseDesigner extends ToolBarMenuDock { public void actionPerformed(ActionEvent e) { String[] plugins = PluginCollector.getCollector().getErrorPlugins(); if (ArrayUtils.isNotEmpty(plugins)) { - String text = StableUtils.join(plugins, ",") + Inter.getLocText("FR-Designer_Plugin_Should_Update"); + String text = StableUtils.join(plugins, ",") + ": " + Inter.getLocText("FR-Designer_Plugin_Should_Update_Please_Contact_Developer"); int r = JOptionPane.showConfirmDialog(null, text, Inter.getLocText("FR-Designer_Plugin_Should_Update_Title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (r == JOptionPane.OK_OPTION) { - WebDialog.createPluginDialog(); + WebViewDlgHelper.createPluginDialog(); } } timer.stop(); diff --git a/designer_chart/build.dev.gradle b/designer_chart/build.dev.gradle index ba6df992b..db1478361 100644 --- a/designer_chart/build.dev.gradle +++ b/designer_chart/build.dev.gradle @@ -1,8 +1,26 @@ -apply plugin: 'java' tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } + +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} //指定构建的jdk版本 sourceCompatibility=1.7 //指定生成jar包的版本 diff --git a/designer_chart/build.dev.gradle.bak b/designer_chart/build.dev.gradle.bak new file mode 100644 index 000000000..7566bcc82 --- /dev/null +++ b/designer_chart/build.dev.gradle.bak @@ -0,0 +1,85 @@ + +apply plugin: 'java' +tasks.withType(JavaCompile){ + options.encoding = 'UTF-8' +} + +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} +//指定构建的jdk版本 +sourceCompatibility=1.7 +//指定生成jar包的版本 +version='8.0' + +def srcDir="." + +//对生成的jar包进行重命名 + +jar{ + baseName='fr-designer-chart' +} + +sourceSets{ + main{ + java{ + srcDirs=["${srcDir}/src"] + } + } +} +FileTree files =fileTree(dir:'./',include:'build.*.gradle') +def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('\\')) +buildDir=buildDir.substring(0,buildDir.lastIndexOf ('\\')) +def branchName=buildDir.substring(buildDir.lastIndexOf ('\\')+1) + +//指定外部依赖 +dependencies{ +compile fileTree(dir:"../../../finereport-lib-stable/${branchName}",include:'**/*.jar') +compile fileTree(dir:'../../../',include:"finereport-*-stable/${branchName}/**/build/libs/*.jar") + + testCompile 'junit:junit:4.12' +} +//将非.java 文件复制到classes文件夹下参与打包 +task copyFile(type:Copy,dependsOn:compileJava){ + copy{ + from ("${srcDir}/src"){ + exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' + + } + into 'build/classes/main' + } + +} + +//压缩项目中的js文件 +task compressJS{ + ant.taskdef(name:'yuicompress',classname:'com.yahoo.platform.yui.compressor.YUICompressTask'){ + classpath { + fileset(dir:'../../../finereport-lib4build-stable',includes:'**/*.jar') + } + } + ant.yuicompress(linebreak:"500",warn:"false", munge:"yes",preserveallsemicolons:"false",charset:"utf-8",encoding:"utf-8",outputfolder:'build/classes/main'){ + fileset (dir:"${srcDir}/src"){ + include (name:'**/*.js') + include (name:'**/*.css') + } + + } +} +jar.dependsOn compressJS + diff --git a/designer_chart/build.master.gradle b/designer_chart/build.master.gradle index ba6df992b..6730fd1ee 100644 --- a/designer_chart/build.master.gradle +++ b/designer_chart/build.master.gradle @@ -1,8 +1,26 @@ -apply plugin: 'java' tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} + //指定构建的jdk版本 sourceCompatibility=1.7 //指定生成jar包的版本 diff --git a/designer_chart/build.master.gradle.bak b/designer_chart/build.master.gradle.bak new file mode 100644 index 000000000..c0f28d1f8 --- /dev/null +++ b/designer_chart/build.master.gradle.bak @@ -0,0 +1,85 @@ + +apply plugin: 'java' +tasks.withType(JavaCompile){ + options.encoding = 'UTF-8' +} +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} + +//指定构建的jdk版本 +sourceCompatibility=1.7 +//指定生成jar包的版本 +version='8.0' + +def srcDir="." + +//对生成的jar包进行重命名 + +jar{ + baseName='fr-designer-chart' +} + +sourceSets{ + main{ + java{ + srcDirs=["${srcDir}/src"] + } + } +} +FileTree files =fileTree(dir:'./',include:'build.*.gradle') +def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('\\')) +buildDir=buildDir.substring(0,buildDir.lastIndexOf ('\\')) +def branchName=buildDir.substring(buildDir.lastIndexOf ('\\')+1) + +//指定外部依赖 +dependencies{ +compile fileTree(dir:"../../../finereport-lib-stable/${branchName}",include:'**/*.jar') +compile fileTree(dir:'../../../',include:"finereport-*-stable/${branchName}/**/build/libs/*.jar") + + testCompile 'junit:junit:4.12' +} +//将非.java 文件复制到classes文件夹下参与打包 +task copyFile(type:Copy,dependsOn:compileJava){ + copy{ + from ("${srcDir}/src"){ + exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' + + } + into 'build/classes/main' + } + +} + +//压缩项目中的js文件 +task compressJS{ + ant.taskdef(name:'yuicompress',classname:'com.yahoo.platform.yui.compressor.YUICompressTask'){ + classpath { + fileset(dir:'../../../finereport-lib4build-stable',includes:'**/*.jar') + } + } + ant.yuicompress(linebreak:"500",warn:"false", munge:"yes",preserveallsemicolons:"false",charset:"utf-8",encoding:"utf-8",outputfolder:'build/classes/main'){ + fileset (dir:"${srcDir}/src"){ + include (name:'**/*.js') + include (name:'**/*.css') + } + + } +} +jar.dependsOn compressJS + diff --git a/designer_chart/build.release.gradle b/designer_chart/build.release.gradle index e97176e24..b897c71de 100644 --- a/designer_chart/build.release.gradle +++ b/designer_chart/build.release.gradle @@ -1,8 +1,26 @@ -apply plugin: 'java' tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} + //指定构建的jdk版本 sourceCompatibility=1.8 //指定生成jar包的版本 diff --git a/designer_chart/src/com/fr/aspectj/designerchart/TemplateProcessTracker.aj b/designer_chart/src/com/fr/aspectj/designerchart/TemplateProcessTracker.aj new file mode 100644 index 000000000..51e86fd15 --- /dev/null +++ b/designer_chart/src/com/fr/aspectj/designerchart/TemplateProcessTracker.aj @@ -0,0 +1,59 @@ +package com.fr.aspectj.designerchart; + +/** + * Created by plough on 2017/3/3. + */ +import com.fr.chart.chartattr.Chart; +import com.fr.design.mainframe.templateinfo.TemplateInfoCollector; +import org.aspectj.lang.reflect.SourceLocation; + +import javax.swing.event.ListSelectionEvent; +import java.awt.event.ActionEvent; +import java.awt.event.MouseEvent; +import java.util.Date; + +public aspect TemplateProcessTracker { + //声明一个pointcut,匹配你需要的方法 + pointcut onMouseClicked(MouseEvent e) : + execution(* mouseClicked(MouseEvent)) && args(e); + pointcut onMousePressed(MouseEvent e) : + execution(* mousePressed(MouseEvent)) && args(e); + pointcut onMouseReleased(MouseEvent e) : + execution(* mouseReleased(MouseEvent)) && args(e); + pointcut onActionPerformed(ActionEvent e) : + execution(* actionPerformed(ActionEvent)) && args(e); + pointcut onChartUpdate(Chart c) : + execution(* update(Chart)) && args(c); + + //before表示之前的意思 + //这整个表示在MouseAdapter的public void mouseXXX(MouseEvent)方法调用之前,你想要执行的代码 + before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) { + SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置 + + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; + TemplateInfoCollector.appendProcess(log); + } + //同上 + before(ActionEvent e) : onActionPerformed(e) { + SourceLocation sl = thisJoinPoint.getSourceLocation(); + // !within(LogHandlerBar) 没用, 手动过滤 + if (e.getSource().toString().contains("javax.swing.Timer")) { + return; + } + + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; + TemplateInfoCollector.appendProcess(log); + + } + //同上 + before(Chart c) : onChartUpdate(c) { + SourceLocation sl = thisJoinPoint.getSourceLocation(); + //String log = String.format("%s:\n%s\n插入新图表:%s\n\n", new Date(), sl, c.getChartName()); + String log = ""; + TemplateInfoCollector.appendProcess(log); + + } + +} diff --git a/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java b/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java index c091c54b9..c67a6aea5 100644 --- a/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java +++ b/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java @@ -75,7 +75,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh static { GeneralContext.addPluginReadListener(new PluginReadListener() { @Override - public void success() { + public void success(Status status) { //重新注册designModuleFactory DesignModuleFactory.registerExtraWidgetOptions(initWidgetOption()); } diff --git a/designer_chart/src/com/fr/design/chart/axis/MinMaxValuePane.java b/designer_chart/src/com/fr/design/chart/axis/MinMaxValuePane.java index d717d31a8..8a157f084 100644 --- a/designer_chart/src/com/fr/design/chart/axis/MinMaxValuePane.java +++ b/designer_chart/src/com/fr/design/chart/axis/MinMaxValuePane.java @@ -31,44 +31,55 @@ public class MinMaxValuePane extends JPanel { protected UITextField secUnitField; public MinMaxValuePane() { - minCheckBox = new UICheckBox(Inter.getLocText(new String[]{"Custom", "Min_Value"})); - minValueField = new UITextField(6); - maxCheckBox = new UICheckBox(Inter.getLocText(new String[]{"Custom", "Max_Value"})); - maxValueField = new UITextField(6); - isCustomMainUnitBox = new UICheckBox(Inter.getLocText("FR-Chart_MainGraduationUnit")); - mainUnitField = new UITextField(6); - isCustomSecUnitBox = new UICheckBox(Inter.getLocText("FR-Chart_SecondGraduationUnit")); - secUnitField = new UITextField(6); + minCheckBox = new UICheckBox(Inter.getLocText(new String[]{"Custom", "Min_Value"})); + minValueField = new UITextField(6); + maxCheckBox = new UICheckBox(Inter.getLocText(new String[]{"Custom", "Max_Value"})); + maxValueField = new UITextField(6); + isCustomMainUnitBox = new UICheckBox(Inter.getLocText("FR-Chart_MainGraduationUnit")); + mainUnitField = new UITextField(6); + isCustomSecUnitBox = new UICheckBox(Inter.getLocText("FR-Chart_SecondGraduationUnit")); + secUnitField = new UITextField(6); + double p = TableLayout.PREFERRED; double f = TableLayout.FILL; - double[] columnSize = { p, f }; - double[] rowSize = { p, p, p, p}; + double[] columnSize = {p, f}; - Component[][] components = getPanelComponents(); - JPanel panel = TableLayoutHelper.createTableLayoutPane(components ,rowSize,columnSize); + Component[][] components = getPanelComponents(); + JPanel panel = TableLayoutHelper.createTableLayoutPane(components, getRowSize(p), columnSize); this.setLayout(new BorderLayout()); - this.add(panel,BorderLayout.CENTER); + this.add(panel, BorderLayout.CENTER); + addComponentListener(components); + } - for(int i = 0; i < components.length; i++) { - ((UICheckBox)components[i][0]).addActionListener(new ActionListener() { + protected double[] getRowSize(double p) { + return new double[]{p, p, p, p}; + } - @Override - public void actionPerformed(ActionEvent e) { - checkBoxUse(); - } - }); - ChartSwingUtils.addListener((UICheckBox)components[i][0], (UITextField)components[i][1]); + protected void addComponentListener(Component[][] components) { + for (int i = 0; i < components.length; i++) { + addListener((UICheckBox) components[i][0]); + ChartSwingUtils.addListener((UICheckBox) components[i][0], (UITextField) components[i][1]); } } - protected Component[][] getPanelComponents() { - return new Component[][]{ - new Component[]{minCheckBox, minValueField}, - new Component[]{maxCheckBox, maxValueField}, - new Component[]{isCustomMainUnitBox, mainUnitField}, - new Component[]{isCustomSecUnitBox, secUnitField}, - }; - } + protected void addListener(UICheckBox checkBox) { + checkBox.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + checkBoxUse(); + } + }); + } + + protected Component[][] getPanelComponents() { + return new Component[][]{ + new Component[]{minCheckBox, minValueField}, + new Component[]{maxCheckBox, maxValueField}, + new Component[]{isCustomMainUnitBox, mainUnitField}, + new Component[]{isCustomSecUnitBox, secUnitField}, + }; + } private void checkBoxUse() { minValueField.setEnabled(minCheckBox.isSelected()); @@ -101,7 +112,7 @@ public class MinMaxValuePane extends JPanel { if(axis.getMinValue() != null) { minValueField.setText(axis.getMinValue().toString()); } - } + } // 最大值 if (axis.isCustomMaxValue()) { @@ -109,7 +120,7 @@ public class MinMaxValuePane extends JPanel { if(axis.getMaxValue() != null) { maxValueField.setText(axis.getMaxValue().toString()); } - } + } // 主次刻度单位 if (axis.isCustomMainUnit()) { @@ -117,7 +128,7 @@ public class MinMaxValuePane extends JPanel { if(axis.getMainUnit() != null) { mainUnitField.setText(axis.getMainUnit().toString()); } - } + } if(axis.isCustomSecUnit()) { isCustomSecUnitBox.setSelected(true); diff --git a/designer_chart/src/com/fr/design/chart/report/GisMapTableDataContentPane.java b/designer_chart/src/com/fr/design/chart/report/GisMapTableDataContentPane.java index 4e0443c9f..5a2f3a4b9 100644 --- a/designer_chart/src/com/fr/design/chart/report/GisMapTableDataContentPane.java +++ b/designer_chart/src/com/fr/design/chart/report/GisMapTableDataContentPane.java @@ -245,7 +245,7 @@ public class GisMapTableDataContentPane extends FurtherBasicBeanPane{ while(names.hasNext()) { Object name = names.next(); String layName = editingAttr.getLayerTo(Utils.objectToString(name)); - if(ArrayUtils.contains(ChartConstants.NONE_KEYS, layName)) {// kunsnat: 考虑切换设计器语言. + if(ArrayUtils.contains(ChartConstants.getNoneKeys(), layName)) {// kunsnat: 考虑切换设计器语言. layName = StringUtils.EMPTY; } list.add(new Object[]{name, layName}); @@ -230,7 +230,7 @@ public class MapCubeLayerPane extends BasicBeanPane{ while(names.hasNext()) { Object name = names.next(); String layName = editingAttr.getLayerTo(Utils.objectToString(name)); - if(ArrayUtils.contains(ChartConstants.NONE_KEYS, layName)) {// kunsnat: 考虑切换设计器语言. + if(ArrayUtils.contains(ChartConstants.getNoneKeys(), layName)) {// kunsnat: 考虑切换设计器语言. layName = StringUtils.EMPTY; } list.add(new Object[]{name, layName}); diff --git a/designer_chart/src/com/fr/design/chart/series/SeriesCondition/impl/ChartHyperPoplinkPane.java b/designer_chart/src/com/fr/design/chart/series/SeriesCondition/impl/ChartHyperPoplinkPane.java index 94836c7a3..1a68ad5e5 100644 --- a/designer_chart/src/com/fr/design/chart/series/SeriesCondition/impl/ChartHyperPoplinkPane.java +++ b/designer_chart/src/com/fr/design/chart/series/SeriesCondition/impl/ChartHyperPoplinkPane.java @@ -45,7 +45,7 @@ public class ChartHyperPoplinkPane extends BasicBeanPane { ChartCollection cc = createChartCollection(); chartComponent = new ChartComponent(); - chartComponent.setPreferredSize(new Dimension(220, 170));// 在单元格弹出时 需要调整保证属性表的大小. + chartComponent.setPreferredSize(new Dimension(200, 170));// 在单元格弹出时 需要调整保证属性表的大小. chartComponent.setSupportEdit(false); chartComponent.populate(cc); diff --git a/designer_chart/src/com/fr/design/chart/series/SeriesCondition/impl/FormHyperlinkPane.java b/designer_chart/src/com/fr/design/chart/series/SeriesCondition/impl/FormHyperlinkPane.java index 52607e72e..01754ce2a 100644 --- a/designer_chart/src/com/fr/design/chart/series/SeriesCondition/impl/FormHyperlinkPane.java +++ b/designer_chart/src/com/fr/design/chart/series/SeriesCondition/impl/FormHyperlinkPane.java @@ -95,6 +95,8 @@ public class FormHyperlinkPane extends BasicBeanPane { parameterList.toArray(parameters); formHyperlink.setParameters(parameters); + } else { + formHyperlink.setParameters(null); } } diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java index 91b6bba3c..3710dcd52 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java @@ -79,7 +79,7 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen eastPane.setLayout(new BorderLayout()); - eastPane.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 15)); + eastPane.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 5)); JPanel button = new JPanel(); button.setPreferredSize(new Dimension(45, 20)); button.setLayout(new GridLayout(1, 2, 5, 0)); @@ -425,6 +425,8 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen private void deleteAButton() { //先重构属性,在重构面板,否则面板在重构过程中,会重新将属性中的切换图表加到indexList中,导致面板无法删除 + //记录改变前的plotID + String lastPlotID = editingCollection == null ? StringUtils.EMPTY : editingCollection.getSelectedChart().getPlot().getPlotID(); if (editingCollection != null) { int count = editingCollection.getChartCount(); for (int i = 0; i < count; i++) { @@ -447,6 +449,11 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen checkoutChange(); relayoutPane(); + + //重构面板 + if (parent != null ){ + parent.reLayoutEditPane(lastPlotID, editingCollection); + } } private void relayoutPane() { diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java index a3a028ef8..0b5cfe6c9 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java @@ -33,7 +33,7 @@ import java.util.List; * @version 创建时间:2012-12-26 上午10:56:51 */ public class ChartTypePane extends AbstractChartAttrPane{ - private ComboBoxPane chartTypePane; + private ComboBoxPane chartTypeComBox; private ChartTypeButtonPane buttonPane; private ChartEditPane editPane; private ChartCollection editingCollection; @@ -72,13 +72,13 @@ public class ChartTypePane extends AbstractChartAttrPane{ if (editingCollection != null) { relayoutChartTypePane(editingCollection); }else { - chartTypePane = new ComboBoxPane(); + chartTypeComBox = new ComboBoxPane(); } BasicScrollPane scrollPane = new BasicScrollPane() { @Override protected JPanel createContentPane() { - return chartTypePane; + return chartTypeComBox; } @Override @@ -99,7 +99,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ }; content.add(scrollPane, BorderLayout.CENTER); - buttonPane.setEditingChartPane(chartTypePane); + buttonPane.setEditingChartPane(chartTypeComBox); return content; } @@ -206,6 +206,8 @@ public class ChartTypePane extends AbstractChartAttrPane{ } //第一步就是重构cardNames cardNames = ChartTypeInterfaceManager.getInstance().getTitle4PopupWindow(chartID); + //下拉框重构开始。为了防止重构是触发update + ((FlexibleComboBox)jcb).setItemEvenType(ItemEventType.REACTOR); //重构下拉框选项 reactorComboBox(); //重新选择选中的下拉项 @@ -213,6 +215,8 @@ public class ChartTypePane extends AbstractChartAttrPane{ String plotID = chart.getPlot().getPlotID(); Object item = ChartTypeInterfaceManager.getInstance().getTitle4PopupWindow(chartID, plotID); jcb.setSelectedItem(item); + //下拉框重构结束 + ((FlexibleComboBox)jcb).setItemEvenType(ItemEventType.DEFAULT); //重新选中 checkPlotPane(); } @@ -223,13 +227,10 @@ public class ChartTypePane extends AbstractChartAttrPane{ } private void reactorComboBox() { - FlexibleComboBox fcb = (FlexibleComboBox)jcb; - fcb.setItemEvenType(ItemEventType.REACTOR); - fcb.removeAllItems(); + jcb.removeAllItems(); for (int i = 0; i < this.cardNames.length; i++) { - fcb.addItem(cardNames[i]); + jcb.addItem(cardNames[i]); } - fcb.setItemEvenType(ItemEventType.DEFAULT); } @Override @@ -285,7 +286,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ public void relayoutChartTypePane(ChartCollection collection){ if (needRelayout(collection)) { - chartTypePane.relayout(collection); + chartTypeComBox.relayout(collection); //设置面板切换状态 updatePaneState(collection); } @@ -313,7 +314,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ initContentPane(); buttonPane.populateBean(collection); - chartTypePane.populateBean(chart); + chartTypeComBox.populateBean(chart); this.initAllListeners(); } @@ -325,7 +326,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ editingCollection = collection; buttonPane.update(collection);// 内部操作时 已经做过处理. Chart chart = collection.getSelectedChart(); - chartTypePane.updateBean(chart); + chartTypeComBox.updateBean(chart); } /** @@ -333,7 +334,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ * @return 类型界面 */ public FurtherBasicBeanPane[] getPaneList(){ - return chartTypePane.getCards().toArray(new FurtherBasicBeanPane[0]); + return chartTypeComBox.getCards().toArray(new FurtherBasicBeanPane[0]); } /** @@ -341,7 +342,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ * @return 当前选中的图表的index */ public int getSelectedIndex(){ - return chartTypePane.getSelectedIndex(); + return chartTypeComBox.getSelectedIndex(); } /** @@ -349,7 +350,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ * @return 选中的图标的序号 */ public int getSelectedChartIndex(){ - return chartTypePane.getSelectedIndex(); + return chartTypeComBox.getSelectedIndex(); } /** diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/UIEditLabel.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/UIEditLabel.java index ceca4f9dc..c7c3c51c7 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/UIEditLabel.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/UIEditLabel.java @@ -161,35 +161,47 @@ public class UIEditLabel extends JPanel implements UIObserver{ return text; } + protected boolean appendOriginalLabel() { + return true; + } + private void stopEditing(){ isEditingStopped = true; this.removeAll(); - String text =this.showLabel.getText(); - text = StringUtils.cutStringEndWith(text,":"); - text = !ComparatorUtils.equals(text, this.originalLabel) ? - StringUtils.perfectEnd(text, "(" + this.originalLabel + ")"): this.originalLabel; - showLabel.setText(StringUtils.perfectEnd(text,":")); + if(appendOriginalLabel()) { + String text = this.showLabel.getText(); + text = StringUtils.cutStringEndWith(text, ":"); + text = !ComparatorUtils.equals(text, this.originalLabel) ? + StringUtils.perfectEnd(text, "(" + this.originalLabel + ")") : this.originalLabel; + showLabel.setText(StringUtils.perfectEnd(text, ":")); + } this.add(showLabel, BorderLayout.CENTER); this.revalidate(); this.repaint(); } public String getText(){ - String text =this.showLabel.getText(); - text = StringUtils.cutStringEndWith(text,":"); - return StringUtils.cutStringEndWith(text,"("+this.originalLabel+")"); + if(appendOriginalLabel()) { + String text = this.showLabel.getText(); + text = StringUtils.cutStringEndWith(text, ":"); + return StringUtils.cutStringEndWith(text, "(" + this.originalLabel + ")"); + } else { + return this.showLabel.getText(); + } } public void setText(String text){ - if(text == null || StringUtils.isEmpty(text)){ - this.showLabel.setText(this.originalLabel); - return; - } - if(!ComparatorUtils.equals(text,originalLabel)){ - text = StringUtils.cutStringEndWith(text, ":"); - text = StringUtils.perfectEnd(text,"("+originalLabel+")"); + if(appendOriginalLabel()) { + if (text == null || StringUtils.isEmpty(text)) { + this.showLabel.setText(this.originalLabel); + return; + } + if (!ComparatorUtils.equals(text, originalLabel)) { + text = StringUtils.cutStringEndWith(text, ":"); + text = StringUtils.perfectEnd(text, "(" + originalLabel + ")"); + } + text = StringUtils.perfectEnd(text, ":"); } - text = StringUtils.perfectEnd(text,":"); this.showLabel.setText(text); } diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/data/TableDataPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/data/TableDataPane.java index a6bea6b0c..721e7432a 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/data/TableDataPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/data/TableDataPane.java @@ -25,6 +25,10 @@ public class TableDataPane extends FurtherBasicBeanPane{ private ChartDataPane parent; + protected AbstractTableDataContentPane getDataContentPane() { + return dataContentPane; + } + public TableDataPane(ChartDataPane parent) { this.parent = parent; initDataPane(); @@ -103,34 +107,41 @@ public class TableDataPane extends FurtherBasicBeanPane{ * @param collection 图表属性的集合 */ public void refreshContentPane(ChartCollection collection) { + refreshContentPane(getContentPane(collection.getSelectedChart().getPlot())); + } + + protected void refreshContentPane(AbstractTableDataContentPane contentPane) { if(dataContentPane != null) { remove(dataContentPane); } - dataContentPane = getContentPane(collection.getSelectedChart().getPlot()); + dataContentPane = contentPane; if(dataContentPane != null) { add(dataContentPane, BorderLayout.CENTER); } } - /** - * 更新界面属性 + * 更新界面属性 */ public void populateBean(ChartCollection collection) { if(collection == null) { return; } TableDataDefinition data = (TableDataDefinition)collection.getSelectedChart().getFilterDefinition(); + populateDSName(data); + if(dataContentPane != null) { + dataContentPane.populateBean(collection); + } + } + protected void populateDSName(TableDataDefinition dataDefinition){ + TableData tableData = null; - if(data != null) { - tableData = data.getTableData(); + if(dataDefinition != null) { + tableData = dataDefinition.getTableData(); } onSelectTableData(); checkBoxUse(); tableDataPane.populateBean(tableData); - if(dataContentPane != null) { - dataContentPane.populateBean(collection); - } } /** @@ -141,6 +152,10 @@ public class TableDataPane extends FurtherBasicBeanPane{ dataContentPane.updateBean(collection); } TopDefinition dataDefinition = (TopDefinition)collection.getSelectedChart().getFilterDefinition(); + updateDSName(dataDefinition); + } + + protected void updateDSName(TopDefinition dataDefinition) { if(dataDefinition instanceof TableDataDefinition) { TableDataWrapper tableDataWrapper = tableDataPane.getTableDataWrapper(); if (dataDefinition != null && tableDataWrapper != null){ diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/data/report/AbstractReportDataContentPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/data/report/AbstractReportDataContentPane.java index 4ff643522..768ecb7e8 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/data/report/AbstractReportDataContentPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/data/report/AbstractReportDataContentPane.java @@ -3,6 +3,8 @@ package com.fr.design.mainframe.chart.gui.data.report; import com.fr.base.Formula; import com.fr.base.Utils; import com.fr.chart.chartattr.ChartCollection; +import com.fr.chart.chartdata.NormalReportDataDefinition; +import com.fr.chart.chartdata.SeriesDefinition; import com.fr.design.beans.BasicBeanPane; import com.fr.design.constants.UIConstants; import com.fr.design.event.UIObserverListener; @@ -16,6 +18,7 @@ import com.fr.stable.StableUtils; import javax.swing.*; import javax.swing.event.ChangeEvent; import java.awt.*; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -95,6 +98,20 @@ public abstract class AbstractReportDataContentPane extends BasicBeanPane{ axisLineStylePane = new ChartAxisLineStylePane(); zeroPane = aliagnZero4Second(); - axisReversed = new UICheckBox(Inter.getLocText("AxisReversed")); + axisReversed = new UICheckBox(Inter.getLocText("FR-Designer_AxisReversed")); unitCombox = new UIComboBox(ChartConstants.UNIT_I18N_VALUES); formatPane = new FormatPane(); axisLabelPane = new ChartAxisLabelPane(); @@ -151,7 +151,7 @@ public class ChartValuePane extends ChartAxisUsePane{ double p = TableLayout.PREFERRED; double f = TableLayout.FILL; double[] columnSize = { LayoutConstants.CHART_ATTR_TOMARGIN,p,f}; - double[] rowSize = { p, p,}; + double[] rowSize = { p, p}; Component[][] component = new Component[][]{ new Component[]{null,initMinMaxValue(),null}, new Component[]{null, addLogarithmicPane2ValuePane(), addLogText()}, @@ -171,12 +171,12 @@ public class ChartValuePane extends ChartAxisUsePane{ // 返回对数相关界面. 百分比 没有此界面. protected JPanel addLogarithmicPane2ValuePane() { JPanel labelLogPane = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); - labelLogPane.add(logBox = new UICheckBox(Inter.getLocText("Logarithmic")+":")); - labelLogPane.add(new UILabel(Inter.getLocText("Chart_Log_Base"))); - + labelLogPane.add(logBox = new UICheckBox(Inter.getLocText("FR-Designer_Logarithmic")+":")); + labelLogPane.add(new UILabel(Inter.getLocText("FR-Designer_Chart_Log_Base"))); + logBaseField = new UITextField(4); logBaseField.setText("10"); - logBaseField.setPreferredSize(new Dimension(20, 20)); + logBaseField.setPreferredSize(new Dimension(55, 20)); logBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -185,7 +185,7 @@ public class ChartValuePane extends ChartAxisUsePane{ }); ChartSwingUtils.addListener(logBox, logBaseField); - + return labelLogPane; } @@ -221,7 +221,7 @@ public class ChartValuePane extends ChartAxisUsePane{ * @return 返回标题. */ public String title4PopupWindow() { - return Inter.getLocText("Chart_F_Radar_Axis"); + return Inter.getLocText("FR-Designer_Chart_F_Radar_Axis"); } @Override diff --git a/designer_form/build.dev.gradle b/designer_form/build.dev.gradle index 20dc49a33..4b71fed5f 100644 --- a/designer_form/build.dev.gradle +++ b/designer_form/build.dev.gradle @@ -1,10 +1,27 @@ -apply plugin: 'java' tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} //指定构建的jdk版本 -sourceCompatibility=1.8 +sourceCompatibility=1.7 //指定生成的jar包版本 version='8.0' diff --git a/designer_form/build.dev.gradle.bak b/designer_form/build.dev.gradle.bak index 2b727caac..ae16b033e 100644 --- a/designer_form/build.dev.gradle.bak +++ b/designer_form/build.dev.gradle.bak @@ -4,7 +4,7 @@ tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } //指定构建的jdk版本 -sourceCompatibility=1.8 +sourceCompatibility=1.7 //指定生成的jar包版本 version='8.0' @@ -20,7 +20,7 @@ sourceSets{ main{ java{ srcDirs=["${srcDir}/src", -"${srcDir}/../designer/src"] + "${srcDir}/../designer/src"] } } } diff --git a/designer_form/build.master.gradle b/designer_form/build.master.gradle index 324f408bf..45d1d86f1 100644 --- a/designer_form/build.master.gradle +++ b/designer_form/build.master.gradle @@ -1,8 +1,27 @@ -apply plugin: 'java' tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } + +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} + //指定构建的jdk版本 sourceCompatibility=1.7 //指定生成的jar包版本 diff --git a/designer_form/build.master.gradle.bak b/designer_form/build.master.gradle.bak index b6fdde506..348ba4875 100644 --- a/designer_form/build.master.gradle.bak +++ b/designer_form/build.master.gradle.bak @@ -3,6 +3,26 @@ apply plugin: 'java' tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } + +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} + //指定构建的jdk版本 sourceCompatibility=1.7 //指定生成的jar包版本 @@ -47,7 +67,7 @@ def dataContent ={def dir -> } } } -FileTree f1=fileTree(dir:'../../../'include:"finereport-*-stable/${branchName}/build/libs/*.jar") +FileTree f1=fileTree(dir:'../../../',include:"finereport-*-stable/${branchName}/build/libs/*.jar") f1.each{File file-> println "----------${file.path}" } diff --git a/designer_form/build.release.gradle b/designer_form/build.release.gradle index 90abcb81e..793f6a0b1 100644 --- a/designer_form/build.release.gradle +++ b/designer_form/build.release.gradle @@ -1,10 +1,27 @@ -apply plugin: 'java' tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } +buildscript { + repositories { + maven { + url "http://www.eveoh.nl/files/maven2" + } + } + + dependencies { + classpath "nl.eveoh:gradle-aspectj:1.2" + } +} + +ext.aspectjVersion = '1.7.4' +apply plugin: 'aspectj' + +repositories { + mavenCentral() +} //指定构建的jdk版本 -sourceCompatibility=1.8 +sourceCompatibility=1.7 //指定生成的jar包版本 version='8.0' diff --git a/designer_form/src/com/fr/aspectj/designerform/TemplateProcessTracker.aj b/designer_form/src/com/fr/aspectj/designerform/TemplateProcessTracker.aj new file mode 100644 index 000000000..0aabeb362 --- /dev/null +++ b/designer_form/src/com/fr/aspectj/designerform/TemplateProcessTracker.aj @@ -0,0 +1,59 @@ +package com.fr.aspectj.designerform; + +/** + * Created by plough on 2017/3/3. + */ +import com.fr.design.mainframe.templateinfo.TemplateInfoCollector; +import org.aspectj.lang.reflect.SourceLocation; + +import java.awt.event.ActionEvent; +import java.awt.event.MouseEvent; +import java.util.Date; + +public aspect TemplateProcessTracker { + //声明一个pointcut,匹配你需要的方法 + pointcut onMouseClicked(MouseEvent e) : + execution(* mouseClicked(MouseEvent)) && args(e); + pointcut onMousePressed(MouseEvent e) : + execution(* mousePressed(MouseEvent)) && args(e); + pointcut onMouseReleased(MouseEvent e) : + execution(* mouseReleased(MouseEvent)) && args(e); + pointcut onActionPerformed(ActionEvent e) : + execution(* actionPerformed(ActionEvent)) && args(e); + pointcut onSetValueAt(Object v, int r, int c) : + execution(* setValueAt(java.lang.Object, int, int)) && args(v, r, c); + + //before表示之前的意思 + //这整个表示在MouseAdapter的public void mouseXXX(MouseEvent)方法调用之前,你想要执行的代码 + before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) { + SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置 + + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; + TemplateInfoCollector.appendProcess(log); + } + //同上 + before(ActionEvent e) : onActionPerformed(e) { + SourceLocation sl = thisJoinPoint.getSourceLocation(); + // !within(LogHandlerBar) 没用, 手动过滤 + if (e.getSource().toString().contains("javax.swing.Timer")) { + return; + } + + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; + TemplateInfoCollector.appendProcess(log); + + } + //同上 + before(Object v, int r, int c) : onSetValueAt(v, r, c) { + SourceLocation sl = thisJoinPoint.getSourceLocation(); + + //String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c); + String log = ""; + TemplateInfoCollector.appendProcess(log); + + } + + +} diff --git a/designer_form/src/com/fr/design/designer/beans/ConnectorCreator.java b/designer_form/src/com/fr/design/designer/beans/ConnectorCreator.java index 2bfc0bf3f..ca9934416 100644 --- a/designer_form/src/com/fr/design/designer/beans/ConnectorCreator.java +++ b/designer_form/src/com/fr/design/designer/beans/ConnectorCreator.java @@ -8,13 +8,12 @@ import java.util.PriorityQueue; import com.fr.form.ui.container.WLayout; import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; - public class ConnectorCreator { public static final int UNIT = 10; public static final int SIDE = 2; public static final int CORNER_LOSS = 20; - public static final int vector[][] = { { UNIT, 0 }, { -UNIT, 0 }, { 0, UNIT }, { 0, -UNIT } }; + public static final int VECTOR[][] = { { UNIT, 0 }, { -UNIT, 0 }, { 0, UNIT }, { 0, -UNIT } }; private long timeOut = 200; private boolean beyond; @@ -179,8 +178,8 @@ public class ConnectorCreator { } void pushInto() { - for (int i = 0; i < vector.length; i++) { - Point temp = new Point(p.x + vector[i][0], p.y + vector[i][1]); + for (int i = 0; i < VECTOR.length; i++) { + Point temp = new Point(p.x + VECTOR[i][0], p.y + VECTOR[i][1]); if (parent != null && parent.x == temp.x && parent.y == temp.y) { continue; } @@ -192,8 +191,8 @@ public class ConnectorCreator { } boolean reCheck() { - for (int i = 0; i < vector.length; i++) { - Point temp = new Point(p.x + SIDE * vector[i][0], p.y + SIDE * vector[i][1]); + for (int i = 0; i < VECTOR.length; i++) { + Point temp = new Point(p.x + SIDE * VECTOR[i][0], p.y + SIDE * VECTOR[i][1]); AssessedPoint ap = new AssessedPoint(temp, this, loss(temp)); if (check(temp)) { open.add(ap); diff --git a/designer_form/src/com/fr/design/designer/beans/LayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/LayoutAdapter.java index fffc1c587..c087d78fe 100644 --- a/designer_form/src/com/fr/design/designer/beans/LayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/LayoutAdapter.java @@ -1,85 +1,94 @@ -package com.fr.design.designer.beans; - -import com.fr.design.beans.GroupModel; -import com.fr.design.designer.creator.XCreator; - -/** - * 该接口是LayoutManager的BeanInfo类。标准Java平台没有提供布局管理器的BeanInfo类, - * 对于界面设计工具来说还需一些特殊的行为。 - * @since 6.5.3 - */ -public interface LayoutAdapter { - - /** - * 在添加组件状态时,当鼠标移动到某个容器上方时,如果该容器有布局管理器,则会调用该布局 - * 管理适配器的accept来决定当前位置是否可以放置,并提供特殊的标识,比如红色区域标识。比 - * 如在BorderLayout中,如果某个方位已经放置了组件,则此时应该返回false标识该区域不可以 - * 放置。 - *@param creator 组件 - *@param x 添加的位置x,该位置是相对于container的 - *@param y 添加的位置y,该位置是相对于container的 - *@return 是否可以放置 - */ - boolean accept(XCreator creator, int x, int y); - - /** - * 有的控件在拖拽调整大小后需要根据自身内容重新计算下当前的尺寸是否合适,如果不合适,就需要重新fix一下 - * @param creator 组件 - */ - void fix(XCreator creator); - - /** - * 组件的ComponentAdapter在添加组件时,如果发现布局管理器不为空,会继而调用该布局管理器的 - * addComp方法来完成组件的具体添加。在该方法内,布局管理器可以提供额外的功能。 - * @param creator 被添加的新组件 - * @param x 添加的位置x,该位置是相对于container的 - * @param y 添加的位置y,该位置是相对于container的 - * @return 是否添加成功,成功返回true,否则false - */ - boolean addBean(XCreator creator, int x, int y); - - /** - * 返回该布局管理适配器的Painter,为容器提供放置位置的标识。 - */ - HoverPainter getPainter(); - - /** - * 显示parent的字组件child,解决CardLayout中显示某个非显示组件的特殊情况 - * @param child 组件 - */ - void showComponent(XCreator child); - - void addNextComponent(XCreator dragged); - - /** - * 组件叠放顺序前插入 - * @param target 目标组件 - * @param added 插入组件 - */ - void addBefore(XCreator target, XCreator added); - - /** - * 组件叠放顺序后插入 - * @param target 目标组件 - * @param added 放置组件 - */ - void addAfter(XCreator target, XCreator added); - - /** - * 能否放置更多组件 - * @return 能则返回true - */ - boolean canAcceptMoreComponent(); - - ConstraintsGroupModel getLayoutConstraints(XCreator creator); - - GroupModel getLayoutProperties(); - - /** - * 删除组件 - * @param creator 组件 - * @param initWidth 组件之前宽度 - * @param initHeight 组件之前高度 - */ - void removeBean(XCreator creator, int initWidth, int initHeight); +package com.fr.design.designer.beans; + +import com.fr.design.beans.GroupModel; +import com.fr.design.designer.creator.XCreator; + +/** + * 该接口是LayoutManager的BeanInfo类。标准Java平台没有提供布局管理器的BeanInfo类, + * 对于界面设计工具来说还需一些特殊的行为。 + * + * @since 6.5.3 + */ +public interface LayoutAdapter { + + /** + * 在添加组件状态时,当鼠标移动到某个容器上方时,如果该容器有布局管理器,则会调用该布局 + * 管理适配器的accept来决定当前位置是否可以放置,并提供特殊的标识,比如红色区域标识。比 + * 如在BorderLayout中,如果某个方位已经放置了组件,则此时应该返回false标识该区域不可以 + * 放置。 + * + * @param creator 组件 + * @param x 添加的位置x,该位置是相对于container的 + * @param y 添加的位置y,该位置是相对于container的 + * @return 是否可以放置 + */ + boolean accept(XCreator creator, int x, int y); + + /** + * 有的控件在拖拽调整大小后需要根据自身内容重新计算下当前的尺寸是否合适,如果不合适,就需要重新fix一下 + * + * @param creator 组件 + */ + void fix(XCreator creator); + + /** + * 组件的ComponentAdapter在添加组件时,如果发现布局管理器不为空,会继而调用该布局管理器的 + * addComp方法来完成组件的具体添加。在该方法内,布局管理器可以提供额外的功能。 + * + * @param creator 被添加的新组件 + * @param x 添加的位置x,该位置是相对于container的 + * @param y 添加的位置y,该位置是相对于container的 + * @return 是否添加成功,成功返回true,否则false + */ + boolean addBean(XCreator creator, int x, int y); + + /** + * 返回该布局管理适配器的Painter,为容器提供放置位置的标识。 + */ + HoverPainter getPainter(); + + /** + * 显示parent的字组件child,解决CardLayout中显示某个非显示组件的特殊情况 + * + * @param child 组件 + */ + void showComponent(XCreator child); + + void addNextComponent(XCreator dragged); + + /** + * 组件叠放顺序前插入 + * + * @param target 目标组件 + * @param added 插入组件 + */ + void addBefore(XCreator target, XCreator added); + + /** + * 组件叠放顺序后插入 + * + * @param target 目标组件 + * @param added 放置组件 + */ + void addAfter(XCreator target, XCreator added); + + /** + * 能否放置更多组件 + * + * @return 能则返回true + */ + boolean canAcceptMoreComponent(); + + ConstraintsGroupModel getLayoutConstraints(XCreator creator); + + GroupModel getLayoutProperties(); + + /** + * 删除组件 + * + * @param creator 组件 + * @param initWidth 组件之前宽度 + * @param initHeight 组件之前高度 + */ + void removeBean(XCreator creator, int initWidth, int initHeight); } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java b/designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java index e32ece18e..23686f651 100644 --- a/designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java +++ b/designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java @@ -1,31 +1,30 @@ -package com.fr.design.designer.beans.actions; - -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; - -import javax.swing.KeyStroke; - -import com.fr.base.BaseUtils; -import com.fr.general.Inter; -import com.fr.design.mainframe.FormDesigner; - -public class CopyAction extends FormEditAction { - - public CopyAction(FormDesigner t) { - super(t); - this.setName(Inter.getLocText("M_Edit-Copy")); - this.setMnemonic('C'); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); - this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); - } - - @Override - public boolean executeActionReturnUndoRecordNeeded() { - FormDesigner tc = getEditingComponent(); - if (tc != null) { - tc.copy(); - } - return false; - } - +package com.fr.design.designer.beans.actions; + +import com.fr.base.BaseUtils; +import com.fr.design.mainframe.FormDesigner; +import com.fr.general.Inter; + +import javax.swing.*; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; + +public class CopyAction extends FormEditAction { + + public CopyAction(FormDesigner t) { + super(t); + this.setName(Inter.getLocText("M_Edit-Copy")); + this.setMnemonic('C'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); + this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); + } + + @Override + public boolean executeActionReturnUndoRecordNeeded() { + FormDesigner tc = getEditingComponent(); + if (tc != null) { + tc.copy(); + } + return false; + } + } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java index d5232d26a..493dd02aa 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java @@ -1,174 +1,189 @@ -package com.fr.design.designer.beans.adapters.layout; - -import java.awt.LayoutManager; - -import com.fr.general.ComparatorUtils; -import com.fr.design.beans.GroupModel; -import com.fr.design.designer.beans.ConstraintsGroupModel; -import com.fr.design.designer.beans.HoverPainter; -import com.fr.design.designer.beans.LayoutAdapter; -import com.fr.design.designer.beans.painters.NullPainter; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWidgetCreator; -import com.fr.design.utils.ComponentUtils; -import com.fr.design.utils.gui.LayoutUtils; - -public abstract class AbstractLayoutAdapter implements LayoutAdapter { - - protected XLayoutContainer container; - protected LayoutManager layout; - - public AbstractLayoutAdapter(XLayoutContainer container) { - this.container = container; - this.layout = container.getLayout(); - } - - /** - * 是否使用控件备份大小 - * @param xCreator 控件 - * @return 所在容器相同,且支持备份的话返回true - */ - public boolean whetherUseBackupSize(XCreator xCreator) { - Class clazz = container.getClass(); - Class bkClazz = null; - if(xCreator.getBackupParent() != null) { - bkClazz = xCreator.getBackupParent().getClass(); - } - return ComparatorUtils.equals(bkClazz, clazz) - && supportBackupSize(); - } - - /** - * 是否支持用备份大小 - * @return 否 - */ - public boolean supportBackupSize() { - return false; - } - - /** - * 有的控件在拖拽调整大小后需要根据自身内容重新计算下当前的尺寸是否合适,如果不合适,就需要重新fix一下 - * @param creator 组件 - */ - public void fix(XCreator creator) { - } - - /** - * 显示parent的字组件child,解决CardLayout中显示某个非显示组件的特殊情况 - * @param child 组件 - */ - @Override - public void showComponent(XCreator child) { - child.setVisible(true); - } - - /** - * 组件的ComponentAdapter在添加组件时,如果发现布局管理器不为空,会继而调用该布局管理器的 - * addComp方法来完成组件的具体添加。在该方法内,布局管理器可以提供额外的功能。 - * @param creator 被添加的新组件 - * @param x 添加的位置x,该位置是相对于container的 - * @param y 添加的位置y,该位置是相对于container的 - * @return 是否添加成功,成功返回true,否则false - */ - @Override - public boolean addBean(XCreator creator, int x, int y) { - if (!accept(creator, x, y)) { - return false; - } - addComp(creator, x, y); - ((XWidgetCreator) creator).recalculateChildrenSize(); - return true; - } - - /** - * 删除组件 - * @param creator 组件 - * @param initWidth 组件之前宽度 - * @param initHeight 组件之前高度 - */ - public void removeBean(XCreator creator, int creatorWidth, int creatorHeight) { - delete(creator, creatorWidth, creatorHeight); - } - - protected void delete(XCreator creator, int creatorWidth, int creatorHeight) { - } - - protected abstract void addComp(XCreator creator, int x, int y); - - /** - * 增加下一个组件 - * @param dragged 组件 - */ - @Override - public void addNextComponent(XCreator dragged) { - container.add(dragged); - LayoutUtils.layoutRootContainer(container); - } - - /** - * 目标控件位置插入组件 - * @param target 目标 - * @param added 增加组件 - */ - @Override - public void addBefore(XCreator target, XCreator added) { - int index = ComponentUtils.indexOfComponent(container, target); - - if (index == -1) { - container.add(added, 0); - } else { - container.add(added, index); - } - - LayoutUtils.layoutRootContainer(container); - } - - /** - * 插在目标组件后面 - * @param target 目标 - * @param added 增加组件 - */ - @Override - public void addAfter(XCreator target, XCreator added) { - int index = ComponentUtils.indexOfComponent(container, target); - - if (index == -1) { - container.add(added); - } else { - index++; - - if (index >= container.getComponentCount()) { - container.add(added); - } else { - container.add(added, index); - } - } - - LayoutUtils.layoutRootContainer(container); - } - - @Override - public HoverPainter getPainter() { - return new NullPainter(container); - } - - /** - * 是否能接收更多的组件 - * @return 能则返回true - */ - @Override - public boolean canAcceptMoreComponent() { - return true; - } - - @Override - public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { - return null; - } - - @Override - public GroupModel getLayoutProperties() { - return null; - } +package com.fr.design.designer.beans.adapters.layout; + +import com.fr.design.beans.GroupModel; +import com.fr.design.designer.beans.ConstraintsGroupModel; +import com.fr.design.designer.beans.HoverPainter; +import com.fr.design.designer.beans.LayoutAdapter; +import com.fr.design.designer.beans.painters.NullPainter; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWidgetCreator; +import com.fr.design.utils.ComponentUtils; +import com.fr.design.utils.gui.LayoutUtils; +import com.fr.general.ComparatorUtils; + +import java.awt.*; + +public abstract class AbstractLayoutAdapter implements LayoutAdapter { + + protected XLayoutContainer container; + protected LayoutManager layout; + + public AbstractLayoutAdapter(XLayoutContainer container) { + this.container = container; + this.layout = container.getLayout(); + } + + /** + * 是否使用控件备份大小 + * + * @param xCreator 控件 + * @return 所在容器相同,且支持备份的话返回true + */ + public boolean whetherUseBackupSize(XCreator xCreator) { + Class clazz = container.getClass(); + Class bkClazz = null; + if (xCreator.getBackupParent() != null) { + bkClazz = xCreator.getBackupParent().getClass(); + } + return ComparatorUtils.equals(bkClazz, clazz) + && supportBackupSize(); + } + + /** + * 是否支持用备份大小 + * + * @return 否 + */ + public boolean supportBackupSize() { + return false; + } + + /** + * 有的控件在拖拽调整大小后需要根据自身内容重新计算下当前的尺寸是否合适,如果不合适,就需要重新fix一下 + * + * @param creator 组件 + */ + public void fix(XCreator creator) { + } + + /** + * 显示parent的字组件child,解决CardLayout中显示某个非显示组件的特殊情况 + * + * @param child 组件 + */ + @Override + public void showComponent(XCreator child) { + child.setVisible(true); + } + + /** + * 组件的ComponentAdapter在添加组件时,如果发现布局管理器不为空,会继而调用该布局管理器的 + * addComp方法来完成组件的具体添加。在该方法内,布局管理器可以提供额外的功能。 + * + * @param creator 被添加的新组件 + * @param x 添加的位置x,该位置是相对于container的 + * @param y 添加的位置y,该位置是相对于container的 + * @return 是否添加成功,成功返回true,否则false + */ + @Override + public boolean addBean(XCreator creator, int x, int y) { + if (!accept(creator, x, y)) { + return false; + } + addComp(creator, x, y); + ((XWidgetCreator) creator).recalculateChildrenSize(); + return true; + } + + /** + * 删除组件 + * + * @param creator 组件 + * @param creatorWidth + * @param creatorHeight + */ + public void removeBean(XCreator creator, int creatorWidth, int creatorHeight) { + delete(creator, creatorWidth, creatorHeight); + } + + protected void delete(XCreator creator, int creatorWidth, int creatorHeight) { + } + + protected abstract void addComp(XCreator creator, int x, int y); + + /** + * 增加下一个组件 + * + * @param dragged 组件 + */ + @Override + public void addNextComponent(XCreator dragged) { + container.add(dragged); + LayoutUtils.layoutRootContainer(container); + } + + /** + * 目标控件位置插入组件 + * + * @param target 目标 + * @param added 增加组件 + */ + @Override + public void addBefore(XCreator target, XCreator added) { + int index = ComponentUtils.indexOfComponent(container, target); + + if (index == -1) { + container.add(added, 0); + } else { + container.add(added, index); + } + + LayoutUtils.layoutRootContainer(container); + } + + /** + * 插在目标组件后面 + * + * @param target 目标 + * @param added 增加组件 + */ + @Override + public void addAfter(XCreator target, XCreator added) { + int index = ComponentUtils.indexOfComponent(container, target); + + if (index == -1) { + container.add(added); + } else { + index++; + + if (index >= container.getComponentCount()) { + container.add(added); + } else { + container.add(added, index); + } + } + + LayoutUtils.layoutRootContainer(container); + } + + @Override + public HoverPainter getPainter() { + return new NullPainter(container); + } + + /** + * 是否能接收更多的组件 + * + * @return 能则返回true + */ + @Override + public boolean canAcceptMoreComponent() { + return true; + } + + @Override + public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { + return null; + } + + @Override + public GroupModel getLayoutProperties() { + return null; + } + + + public XLayoutContainer getContainer() { + return this.container; + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java index 3d53eab01..539e60450 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java @@ -1,7 +1,5 @@ package com.fr.design.designer.beans.adapters.layout; -import java.awt.*; - import com.fr.design.beans.GroupModel; import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.HoverPainter; @@ -9,13 +7,14 @@ import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter; import com.fr.design.designer.creator.*; import com.fr.design.designer.properties.BoundsGroupModel; import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel; -import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.gui.LayoutUtils; -import com.fr.form.ui.container.WBodyLayoutType; +import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; +import java.awt.*; + public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { //是不是添加到父容器上 private boolean isAdd2ParentLayout = false; @@ -74,48 +73,39 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout(); if(topLayout != null){ if (topLayout.isEditable()){ - return topLayoutAccept(creator, x, y, topLayout); + return topLayoutAccept(creator, x, y); } //绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局 else if (((XLayoutContainer)topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) { return false; + } else { + return acceptWidget(x, y); } - else { - return acceptWidget(creator, x, y); - } - } - else{ + } else { FRLogger.getLogger().error("top layout is null!"); } return false; } - //toplayout假如可以编辑的话就往里面添加组件 - private boolean topLayoutAccept(XCreator creator, int x, int y, XLayoutContainer topLayout) { - //判断有没有和当前控件重叠 - //先计算当前控件的位置 - int creatorX, creatorY; - if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { - + //topLayout假如可以编辑的话就往里面添加组件 + private boolean topLayoutAccept(XCreator creator, int x, int y) { + //允许组件重叠,可以不判断有没有和当前控件重叠 + //先计算当前控件的位置 + int creatorX, creatorY; + if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); creatorX = creatorRectangle.x; creatorY = creatorRectangle.y; } else { + //这边计算得到的组件其实位置是正确的, + //因为传入的x和y已经加上了宽度或者高度的一半,再减去相同的宽度和高度的一半是没区别的, + // 例如高度为21,那么就是+10-10; + // 高度为20,那么就是+10-10; 没区别 int w = creator.getWidth() / 2; int h = creator.getHeight() / 2; creatorX = x - w; creatorY = y - h; - } - //再判断和布局中其他控件重叠 - Rectangle curRec = new Rectangle(creatorX, creatorY, creator.getWidth(), creator.getHeight()); - WAbsoluteLayout wAbsoluteLayout = (WAbsoluteLayout)topLayout.toData(); - for (int i = 0, count = wAbsoluteLayout.getWidgetCount(); i < count; i++) { - WAbsoluteLayout.BoundsWidget temp = (WAbsoluteLayout.BoundsWidget) wAbsoluteLayout.getWidget(i); - Rectangle rectangle = temp.getBounds(); - if (curRec.intersects(rectangle)){ - return false; - } } if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) { return false; @@ -168,16 +158,15 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { return !ComparatorUtils.equals(trisectAreaDirect, 0); } - //当前绝对布局不可编辑,就当成一个控件,组件添加在周围 - private boolean acceptWidget(XCreator creator, int x, int y){ - isFindRelatedComps = false; - //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 - Component comp = container.getComponentAt(x, y); - boolean isMatchEdge = false; - //如果当前处于边缘地带, 那么就把他贴到父容器上 - XLayoutContainer parent = container.findNearestFit(); - container = parent != null ? parent : container; - isAdd2ParentLayout = true; + //当前绝对布局不可编辑,就当成一个控件,组件添加在周围 + private boolean acceptWidget(int x, int y) { + isFindRelatedComps = false; + //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 + Component comp = container.getComponentAt(x, y); + //如果当前处于边缘地带, 那么就把他贴到父容器上 + XLayoutContainer parent = container.findNearestFit(); + container = parent != null ? parent : container; + isAdd2ParentLayout = true; int componentHeight = comp.getHeight(); int componentWidth = comp.getWidth(); @@ -244,7 +233,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { if (creator.hasTitleStyle()) { addParentCreator(creator); } else { - container.add(creator, creator.toData().getWidgetName()); + container.add(creator, creator.toData().getWidgetName(),0); } XWAbsoluteLayout layout = (XWAbsoluteLayout) container; layout.updateBoundsWidget(creator); @@ -255,7 +244,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { addParentCreator(creator); } else { - container.add(creator, creator.toData().getWidgetName()); + container.add(creator, creator.toData().getWidgetName(),0); } XWFitLayout layout = (XWFitLayout) container; // 更新对应的BoundsWidget @@ -274,7 +263,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { private void addParentCreator(XCreator child) { XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight()); - container.add(parentPanel, child.toData().getWidgetName()); + container.add(parentPanel, child.toData().getWidgetName(),0); } /** @@ -325,17 +314,15 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { int height = creator.getHeight(); int width = creator.getWidth(); if (x < 0) { - width += x; - x = 0; + x = container.getX(); } else if (x + creator.getWidth() > container.getWidth()) { - width = container.getWidth() - x; + x = container.getWidth() - width; } if (y < 0) { - height += y; - y = 0; + y = container.getY(); } else if (y + creator.getHeight() > container.getHeight()) { - height = container.getHeight() - y; + y = container.getHeight() - height; } creator.setBounds(x, y, width, height); diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java index 313c08b02..75190ba3b 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java @@ -2,9 +2,11 @@ package com.fr.design.designer.beans.adapters.layout; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWParameterLayout; import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; import com.fr.design.utils.ComponentUtils; import com.fr.form.ui.PaddingMargin; +import com.fr.form.ui.container.WBorderLayout; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.general.ComparatorUtils; @@ -17,7 +19,7 @@ import java.util.*; * 所以把公共的方法挪动这边父类里来 * Created by zhouping on 2016/8/18. */ -public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ +public class FRBodyLayoutAdapter extends AbstractLayoutAdapter { protected static final int COMP_TOP = 1; protected static final int COMP_BOTTOM = 2; protected static final int COMP_LEFT = 3; @@ -34,7 +36,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ protected static final int BORDER_PROPORTION = 10; //边界三等分或交叉区域大小取组件1/10和默认大小 protected int trisectAreaDirect = 0; - protected int crossPointAreaDirect = 0; + private int crossPointAreaDirect = 0; // 增加删除拉伸控件用的临时list protected java.util.List rightComps; protected java.util.List leftComps; @@ -49,6 +51,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ protected int minHeight = 0; protected int actualVal = 0; // 存在间隔时,add move drag 判断对齐等都要考虑 protected PaddingMargin margin; // 布局容器边距 + /** * 在添加组件状态时,当鼠标移动到某个容器上方时,如果该容器有布局管理器,则会调用该布局 * 管理适配器的accept来决定当前位置是否可以放置,并提供特殊的标识,比如红色区域标识。比 @@ -76,9 +79,10 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ /** * 交叉点区域时,能否对应位置放入组件 + * * @param comp 待放置组件 - * @param x x - * @param y y + * @param x x + * @param y y * @return 能否放入 */ protected boolean canAcceptWhileCrossPoint(Component comp, int x, int y) { @@ -95,7 +99,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ min = isNotDefaultArea ? min : minWidth * 2; } else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_RIGHT_BOTTOM)) { bottomComp = container.getRightBottomComp(cX, cY, cH, cW); - isNotDefaultArea = (bottomComp == null) || (bottomComp.getX()+bottomComp.getWidth() != cX + cW) ; + isNotDefaultArea = (bottomComp == null) || (bottomComp.getX() + bottomComp.getWidth() != cX + cW); rightComp = container.getBottomRightComp(cX, cY, cH, cW); minLength = isNotDefaultArea ? Math.min(cH, rightComp.getHeight()) : Math.min(cW, bottomComp.getWidth()); min = isNotDefaultArea ? min : minWidth * 2; @@ -105,12 +109,12 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ minLength = isNotDefaultArea ? Math.min(cW, bottomComp.getWidth()) : Math.min(cH, leftComp.getHeight()); min = isNotDefaultArea ? minWidth * 2 : min; } else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_RIGHT_TOP)) { - isNotDefaultArea = (rightComp == null) || (rightComp.getY() != cY) ; + isNotDefaultArea = (rightComp == null) || (rightComp.getY() != cY); topComp = container.getRightTopComp(cX, cY, cW); minLength = isNotDefaultArea ? Math.min(cW, topComp.getWidth()) : Math.min(cH, rightComp.getWidth()); - min = isNotDefaultArea ? minWidth * 2 : min ; + min = isNotDefaultArea ? minWidth * 2 : min; } else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_TOP)) { - minLength= Math.min(rightComp.getHeight(), Math.min(cH, leftComp.getHeight())); + minLength = Math.min(rightComp.getHeight(), Math.min(cH, leftComp.getHeight())); } else if (ComparatorUtils.equals(crossPointAreaDirect, COMP_BOTTOM)) { leftComp = container.getBottomLeftComp(cX, cY, cH); rightComp = container.getBottomRightComp(cX, cY, cH, cW); @@ -129,9 +133,10 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ /** * 三等分区域时,能否对应位置放入组件 + * * @param comp 待放置组件 - * @param x x - * @param y y + * @param x x + * @param y y * @return 能否放入 */ protected boolean canAcceptWhileTrisection(Component comp, int x, int y) { @@ -142,28 +147,28 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ upMinHeight = getUpMinHeightComp(cY, x); downMinHeight = getDownMinHeightComp(comp, y); return upMinHeight == 0 ? downMinHeight >= minHeight * 2 + actualVal : (upMinHeight + downMinHeight) >= minHeight * 3 + actualVal; - } else if(ComparatorUtils.equals(trisectAreaDirect, COMP_BOTTOM)) { + } else if (ComparatorUtils.equals(trisectAreaDirect, COMP_BOTTOM)) { upMinHeight = getUpMinHeightComp(cY + cH + actualVal, x); - if (cY + cH + DEFAULT_AREA_LENGTH>container.getHeight() - margin.getBottom()){ + if (cY + cH + DEFAULT_AREA_LENGTH > container.getHeight() - margin.getBottom()) { downMinHeight = 0; } else { Component targetComp = container.getBottomComp(x, cY, cH); downMinHeight = getDownMinHeightComp(targetComp, cY + cH + DEFAULT_AREA_LENGTH + actualVal); } - return downMinHeight == 0 ? (upMinHeight >= minHeight * 2 + actualVal) : ((upMinHeight+downMinHeight) >= minHeight * 3 + actualVal); - } else if(ComparatorUtils.equals(trisectAreaDirect, COMP_LEFT)) { - rightMinWidth = getMinRightWidth(cX, 0, y); - if(cX - DEFAULT_AREA_LENGTH < margin.getLeft()) { + return downMinHeight == 0 ? (upMinHeight >= minHeight * 2 + actualVal) : ((upMinHeight + downMinHeight) >= minHeight * 3 + actualVal); + } else if (ComparatorUtils.equals(trisectAreaDirect, COMP_LEFT)) { + rightMinWidth = getMinRightWidth(cX, 0, y); + if (cX - DEFAULT_AREA_LENGTH < margin.getLeft()) { leftMinWidth = 0; } else { Component targetRightComp = container.getLeftComp(cX, y); leftMinWidth = getMinLeftWidth(targetRightComp, cX - DEFAULT_AREA_LENGTH - actualVal); } - return leftMinWidth == 0 ? (rightMinWidth >= minWidth * 2 + actualVal) : ((leftMinWidth+rightMinWidth) >= minWidth * 3 + actualVal); - } else if(ComparatorUtils.equals(trisectAreaDirect, COMP_RIGHT)) { + return leftMinWidth == 0 ? (rightMinWidth >= minWidth * 2 + actualVal) : ((leftMinWidth + rightMinWidth) >= minWidth * 3 + actualVal); + } else if (ComparatorUtils.equals(trisectAreaDirect, COMP_RIGHT)) { leftMinWidth = getMinLeftWidth(comp, x); rightMinWidth = getMinRightWidth(cX, cW, y); - return rightMinWidth == 0 ? (leftMinWidth >= minWidth * 2 + actualVal) : ((leftMinWidth+rightMinWidth) >= minWidth * 3 + actualVal); + return rightMinWidth == 0 ? (leftMinWidth >= minWidth * 2 + actualVal) : ((leftMinWidth + rightMinWidth) >= minWidth * 3 + actualVal); } return false; } @@ -176,16 +181,16 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ if (cY == margin.getTop()) { return 0; } - int max=container.getWidth() - margin.getRight(); + int max = container.getWidth() - margin.getRight(); int mouseX = x; int minHeight = cY; int bott = 0; if (isFindRelatedComps) { upComps = new ArrayList(); } - for(; mouseX margin.getLeft()) { + while (mouseX > margin.getLeft()) { Component comp = container.getTopComp(mouseX, cY); - bott = comp.getHeight() + comp.getY()+actualVal; + bott = comp.getHeight() + comp.getY() + actualVal; if (bott == cY) { if (comp.getHeight() < minHeight) { minHeight = comp.getHeight(); } - mouseX = comp.getX()-DEFAULT_AREA_LENGTH-actualVal; + mouseX = comp.getX() - DEFAULT_AREA_LENGTH - actualVal; if (isFindRelatedComps) { upComps.add(comp); } - } else{ + } else { break; } } @@ -231,13 +236,13 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ int cX = currentcomp.getX(); int cY = currentcomp.getY(); int minHeight = currentcomp.getHeight(); - int max=container.getWidth() - margin.getRight(); + int max = container.getWidth() - margin.getRight(); if (isFindRelatedComps) { downComps = new ArrayList(); } int mouseX = cX + DEFAULT_AREA_LENGTH; while (mouseX < max) { - Component comp = container.getComponentAt(mouseX, y); + Component comp = container.getComponentAt(mouseX, y); if (comp.getY() == cY) { if (comp.getHeight() < minHeight) { minHeight = comp.getHeight(); @@ -246,12 +251,12 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ if (isFindRelatedComps) { downComps.add(comp); } - }else{ + } else { break; } } mouseX = cX - DEFAULT_AREA_LENGTH - actualVal; - while(mouseX > margin.getLeft()) { + while (mouseX > margin.getLeft()) { Component comp = container.getComponentAt(mouseX, y); if (comp.getY() == cY) { if (comp.getHeight() < minHeight) { @@ -261,7 +266,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ if (isFindRelatedComps) { downComps.add(comp); } - }else{ + } else { break; } } @@ -273,9 +278,9 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ * 判断对齐时考虑间隔 */ private int getMinRightWidth(int cX, int cW, int y) { - int xL = cX + DEFAULT_AREA_LENGTH ; + int xL = cX + DEFAULT_AREA_LENGTH; xL = cW == 0 ? xL : (xL + cW + actualVal); - if (xL > container.getWidth() - margin.getRight()){ + if (xL > container.getWidth() - margin.getRight()) { return 0; } // 以当前组件紧挨着右侧的组件为基准,在y轴方向查找符合条件的组件 @@ -286,7 +291,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ rightComps = new ArrayList(); } int mouseY = targetComp.getY() + DEFAULT_AREA_LENGTH; - while (mouseY margin.getTop()) { + while (mouseY > margin.getTop()) { Component comp = container.getComponentAt(xL, mouseY); if (comp.getX() == targetComp.getX()) { if (comp.getWidth() < minWidth) { @@ -311,7 +316,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ if (isFindRelatedComps) { rightComps.add(comp); } - }else{ + } else { break; } } @@ -329,9 +334,9 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ if (isFindRelatedComps) { leftComps = new ArrayList(); } - int rightx = 0; + int rightx = 0; int mouseY = currentComp.getY() + DEFAULT_AREA_LENGTH; - while(mouseYmargin.getTop()) { + while (mouseY > margin.getTop()) { Component comp = container.getComponentAt(x, mouseY); - rightx = comp.getX()+comp.getWidth(); + rightx = comp.getX() + comp.getWidth(); if (rightx == compRightLength) { if (comp.getWidth() < minWidth) { minWidth = comp.getWidth(); @@ -358,7 +363,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ if (isFindRelatedComps) { leftComps.add(comp); } - }else{ + } else { break; } } @@ -367,13 +372,14 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ /** * 判断是否鼠标在组件的三等分区域,如果组件在布局管理器中间,上下左右都可能会三等分 + * * @param parentComp 鼠标所在区域的组件 - * @param x 坐标x - * @param y 坐标y + * @param x 坐标x + * @param y 坐标y * @return 是则返回true */ public boolean isTrisectionArea(Component parentComp, int x, int y) { - XCreator creator = (XCreator)parentComp; + XCreator creator = (XCreator) parentComp; if (container.getComponentCount() <= 1) { return false; } @@ -382,23 +388,23 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ int xL = parentComp.getX(); int yL = parentComp.getY(); // 组件宽高的十分之一和默认值取大 - int minRangeWidth = Math.max(maxWidth/BORDER_PROPORTION, DEFAULT_AREA_LENGTH); - int minRangeHeight = Math.max(maxHeight/BORDER_PROPORTION, DEFAULT_AREA_LENGTH); - if(y < yL+minRangeHeight ) { + int minRangeWidth = Math.max(maxWidth / BORDER_PROPORTION, DEFAULT_AREA_LENGTH); + int minRangeHeight = Math.max(maxHeight / BORDER_PROPORTION, DEFAULT_AREA_LENGTH); + if (y < yL + minRangeHeight) { // 在组件上侧三等分 trisectAreaDirect = COMP_TOP; - } else if(y > yL + maxHeight - minRangeHeight) { + } else if (y > yL + maxHeight - minRangeHeight) { // 在组件下侧三等分 trisectAreaDirect = COMP_BOTTOM; } else if (x < xL + minRangeWidth) { // 在组件左侧三等分 trisectAreaDirect = COMP_LEFT; - } else if(x > xL + maxWidth - minRangeWidth) { + } else if (x > xL + maxWidth - minRangeWidth) { // 在组件右侧三等分 trisectAreaDirect = COMP_RIGHT; } // tab布局的边界特殊处理,不进行三等分 - if(!creator.getTargetChildrenList().isEmpty()){ + if (!creator.getTargetChildrenList().isEmpty()) { return false; } @@ -407,21 +413,22 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ /** * 是否为组件交叉点区域 或者是相邻三组建中间点 + * * @param currentComp 当前组件 - * @param x 坐标x - * @param y 坐标y + * @param x 坐标x + * @param y 坐标y * @return 是则返回true */ public boolean isCrossPointArea(Component currentComp, int x, int y) { // 3个及以上都会出现交叉点区域(包括边界处的) - if(currentComp == null || container.getComponentCount() <= 2){ + if (currentComp == null || container.getComponentCount() <= 2) { return false; } int cX = currentComp.getX(); int cY = currentComp.getY(); int cW = currentComp.getWidth(); int cH = currentComp.getHeight(); - int areaWidth = Math.max(cW / BORDER_PROPORTION ,DEFAULT_AREA_LENGTH); + int areaWidth = Math.max(cW / BORDER_PROPORTION, DEFAULT_AREA_LENGTH); int areaHeight = Math.max(cH / BORDER_PROPORTION, DEFAULT_AREA_LENGTH); int rx = cX + cW; int by = cY + cH; @@ -432,27 +439,27 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ if (x < objX && y < objY) { //左上角区域 crossPointAreaDirect = cY > margin.getTop() || cX > margin.getLeft() ? COMP_LEFT_TOP : 0; - } else if (y < objY && x > rx - areaWidth){ + } else if (y < objY && x > rx - areaWidth) { //右上角 crossPointAreaDirect = cY > margin.getTop() || rx < containerW ? COMP_RIGHT_TOP : 0; } else if (x < objX && y > by - areaHeight) { //左下角 crossPointAreaDirect = cX > margin.getLeft() || by < containerH ? COMP_LEFT_BOTTOM : 0; - } else if (x > rx-areaWidth && y > by - areaHeight) { + } else if (x > rx - areaWidth && y > by - areaHeight) { //右下角 crossPointAreaDirect = by < containerH || rx < containerW ? COMP_RIGHT_BOTTOM : 0; } else { isMiddlePosition(currentComp, x, y, areaWidth, areaHeight); } // tab布局的边界特殊处理 - XCreator creator = (XCreator)currentComp; - if(!creator.getTargetChildrenList().isEmpty()){ + XCreator creator = (XCreator) currentComp; + if (!creator.getTargetChildrenList().isEmpty()) { return false; } return crossPointAreaDirect != 0; } - private void isMiddlePosition(Component comp, int x, int y, int areaWidth , int areaHeight) { + private void isMiddlePosition(Component comp, int x, int y, int areaWidth, int areaHeight) { int cX = comp.getX(); int cY = comp.getY(); int cW = comp.getWidth(); @@ -479,14 +486,14 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ Component bottomComp = container.getBottomComp(cX, cY, cH); if (x < (cX + areaWidth)) { isCrosspoint = topComp != null && bottomComp != null && topComp.getX() == cX && bottomComp.getX() == cX; - crossPointAreaDirect = isCrosspoint ? COMP_LEFT : 0; + crossPointAreaDirect = isCrosspoint ? COMP_LEFT : 0; } else if (x > (cX + cW - areaWidth)) { topComp = container.getRightTopComp(cX, cY, cW); bottomComp = container.getRightBottomComp(cX, cY, cH, cW); if (topComp != null && bottomComp != null) { - isCrosspoint = topComp.getX() + topComp.getWidth() == cX + cW && bottomComp.getX() + bottomComp.getWidth() == cX+cW; + isCrosspoint = topComp.getX() + topComp.getWidth() == cX + cW && bottomComp.getX() + bottomComp.getWidth() == cX + cW; } - crossPointAreaDirect = isCrosspoint ? COMP_RIGHT : 0; + crossPointAreaDirect = isCrosspoint ? COMP_RIGHT : 0; } } } @@ -513,15 +520,16 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ /** * 平分,正常情况拖入组件时,按照上1/4区域、下1/4区域为上下平分,中左侧1/2区域、中右侧1/2区域为左右平分 + * * @param currentComp 当前位置组件 - * @param child 待放置组件 - * @param x x - * @param y y + * @param child 待放置组件 + * @param x x + * @param y y */ protected void fixHalve(Component currentComp, XCreator child, int x, int y) { - XCreator creator = (XCreator)currentComp; - if(!creator.getTargetChildrenList().isEmpty()){ - fixHalveOfTab(creator,child,x,y); + XCreator creator = (XCreator) currentComp; + if (!creator.getTargetChildrenList().isEmpty()) { + fixHalveOfTab(creator, child, x, y); return; } int maxWidth = currentComp.getWidth(); @@ -536,18 +544,18 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ int finalY = yL; int finalW = maxWidth; int finalH = maxHeight; - if (isDividUp){ + if (isDividUp) { dim.width = maxWidth; dim.height = maxHeight / 2 - actualVal / 2; finalY = yL + dim.height + actualVal; finalH = maxHeight - dim.height - actualVal; - } else if(isDividDown){ + } else if (isDividDown) { // 若当前区域高度非偶数,那么和isDividUp时计算一致,否则永远都是上半部分小1px dim.height = maxHeight / 2 - actualVal / 2; dim.width = maxWidth; finalH = maxHeight - dim.height - actualVal; yL = yL + finalH + actualVal; - } else if(isDividLeft){ + } else if (isDividLeft) { dim.width = maxWidth / 2 - actualVal / 2; dim.height = maxHeight; finalX = xL + dim.width + actualVal; @@ -571,7 +579,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ // 边界判断抄得原来的逻辑 // tab布局的边界拖入新组件,和当前tab布局平分,这时候的actualVal组建间隔是tab里面的组建间隔 // 不应该在外层自适应布局添加 - private void fixHalveOfTab(XCreator currentCreator, XCreator child, int x, int y){ + private void fixHalveOfTab(XCreator currentCreator, XCreator child, int x, int y) { int maxWidth = currentCreator.getWidth(); int maxHeight = currentCreator.getHeight(); int xL = currentCreator.getX(); @@ -582,7 +590,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ int finalY = yL; int finalW = maxWidth; int finalH = maxHeight; - switch(position){ + switch (position) { case COMP_TOP: dim.width = maxWidth; dim.height = maxHeight / 2; @@ -592,7 +600,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ case COMP_BOTTOM: dim.height = maxHeight / 2; dim.width = maxWidth; - finalH = maxHeight-dim.height; + finalH = maxHeight - dim.height; yL = yL + finalH; break; case COMP_LEFT: @@ -619,13 +627,22 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ } } - private int getPositionOfFix(XCreator currentCreator,int x,int y){ + private int getPositionOfFix(XCreator currentCreator, int x, int y) { int position = 0; XLayoutContainer cardLayout = ((XWCardMainBorderLayout) currentCreator).getCardPart(); XLayoutContainer container = (XLayoutContainer) cardLayout.getComponent(0); Rectangle rect = ComponentUtils.getRelativeBounds(container); + /* + * 为了获取到鼠标drop位置的控件, + * 我们之前已经将y值变为相对坐标值; + * 由于在x轴上没有偏移,所以x值一直等于相对坐标值,最多差一个边界值1。 + * 在进行新添加的控件位置计算时, + * 又通过ComponentUtils.getRelativeBounds()方法获取到了绝对坐标, + * 再次计算相对坐标,所以将y值重新变成绝对坐标。 + * */ + y = y + WCardMainBorderLayout.TAB_HEIGHT + this.getParaEditorYOffset(); int tempX = x - rect.x; - int tempY = y - rect.y + WCardMainBorderLayout.TAB_HEIGHT; + int tempY = y - rect.y; int containerX = container.getX(); int containerY = container.getY(); int containerWidth = container.getWidth(); @@ -634,13 +651,13 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ Rectangle currentXY = new Rectangle(tempX, tempY, 1, 1); // 上边缘 Rectangle upEdge = new Rectangle(containerX, containerY, containerWidth, BORDER_PROPORTION); - if(upEdge.intersects(currentXY)){ + if (upEdge.intersects(currentXY)) { position = COMP_TOP; } int bottomY = containerY + containerHeight - BORDER_PROPORTION; // 下边缘 Rectangle bottomEdge = new Rectangle(containerX, bottomY, containerWidth, BORDER_PROPORTION); - if(bottomEdge.intersects(currentXY)){ + if (bottomEdge.intersects(currentXY)) { position = COMP_BOTTOM; } //左右边缘的高度 -10*2 是为了不和上下边缘重合 @@ -648,47 +665,68 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ int leftY = containerY + BORDER_PROPORTION; // 左边缘 Rectangle leftEdge = new Rectangle(containerX, leftY, BORDER_PROPORTION, verticalHeight); - if(leftEdge.intersects(currentXY)){ + if (leftEdge.intersects(currentXY)) { position = COMP_LEFT; } return position; } + /** + * 获取因为参数面板导致的Y坐标偏移 + * + * @return 参数面板导致的Y坐标偏移 + */ + protected int getParaEditorYOffset() { + int offset = 0; + if (container.getParent() != null) { + Component components[] = container.getParent().getComponents(); + for (Component component : components) { + if (component instanceof XWParameterLayout) { + offset = component.getY() + component.getHeight(); + break; + } + } + } + return offset; + } + + /** * 组件交叉区域进行插入时,调整受到变动的其他组件,之前是交叉区域插入也按照三等分逻辑,后面测试中发现有bug,改为和bi一样的鼠标所在侧平分 * 默认左上角、右下角区域是垂直方向插入组件 * 右上角和左下角是水平方向插入组件,这样避免田字块时重复 + * * @param currentComp 当前位置组件 - * @param child 待放置组件 - * @param x x - * @param y y + * @param child 待放置组件 + * @param x x + * @param y y */ protected void fixCrossPointArea(Component currentComp, XCreator child, int x, int y) { //计算前先全部初始化待调整控件所在的list initCompsList(); - switch(crossPointAreaDirect) { - case COMP_LEFT_TOP : + switch (crossPointAreaDirect) { + case COMP_LEFT_TOP: dealCrossPointAtLeftTop(currentComp, child); break; - case COMP_RIGHT_BOTTOM : + case COMP_RIGHT_BOTTOM: dealCrossPointAtRightBottom(currentComp, child); break; - case COMP_LEFT_BOTTOM : + case COMP_LEFT_BOTTOM: dealCrossPointAtLeftBottom(currentComp, child); break; - case COMP_RIGHT_TOP : + case COMP_RIGHT_TOP: dealCrossPointAtRightTop(currentComp, child); break; - case COMP_TOP : + case COMP_TOP: dealCrossPointAtTop(currentComp, child); break; - case COMP_BOTTOM : + case COMP_BOTTOM: dealCrossPointAtBottom(currentComp, child); break; - case COMP_LEFT : + case COMP_LEFT: dealCrossPointAtLeft(currentComp, child); break; - case COMP_RIGHT : + case COMP_RIGHT: dealCrossPointAtRight(currentComp, child); break; } @@ -708,16 +746,16 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ Component topComp = container.getTopComp(cX, cY); Component leftComp = container.getLeftComp(cX, cY); //上方没有组件或者有一个x坐标不相同的组件 - if (topComp==null || topComp.getX()!=cX) { + if (topComp == null || topComp.getX() != cX) { minDH = cH < leftComp.getHeight() ? cH : leftComp.getHeight(); downComps.add(leftComp); downComps.add(currentComp); int dLength = minDH / 2; - childw = leftComp.getWidth()+cW+actualVal; - childh = dLength-actualVal / 2; + childw = leftComp.getWidth() + cW + actualVal; + childh = dLength - actualVal / 2; if (isCalculateChildPos) { childPosition = new int[]{leftComp.getX(), leftComp.getY(), childw, childh}; - } else{ + } else { //先设置child位置,不然leftComp坐标调整后就不对了 child.setLocation(leftComp.getX(), leftComp.getY()); child.setSize(childw, childh); @@ -726,7 +764,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ } else { rightComps.add(currentComp); rightComps.add(topComp); - minRW = cW= minDH) { minDH -= actualVal / 2; if ((minDH * 2 / 3) < minHeight) { dLength = minDH - minHeight; - }else { + } else { dLength = minDH / 3; } uLength = averageH - dLength; - } else{ + } else { minUH -= actualVal / 2; if ((minUH * 2 / 3) < minHeight) { uLength = minUH - minHeight; - }else { + } else { uLength = minUH / 3; } dLength = averageH - uLength; @@ -999,16 +1038,16 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ child.setLocation(margin.getLeft(), margin.getRight()); child.setSize(rightLength - actualVal / 2, height); } else { - childPosition = new int[] {margin.getLeft(), margin.getRight(), rightLength - actualVal / 2, height}; + childPosition = new int[]{margin.getLeft(), margin.getRight(), rightLength - actualVal / 2, height}; } return; - } else if(minRW == 0){ + } else if (minRW == 0) { leftLength = minLW / 2; calculateLeftComps(leftLength, child, leftLength); return; } else if (minRW >= minLW) { minLW -= actualVal / 2; - if(minLW * 2 / 3 < minWidth) { + if (minLW * 2 / 3 < minWidth) { leftLength = minLW - minWidth; } else { leftLength = minLW / 3; @@ -1016,7 +1055,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ rightLength = averageW - leftLength; } else { minRW -= actualVal / 2; - if(minRW * 2 / 3 < minWidth) { + if (minRW * 2 / 3 < minWidth) { rightLength = minRW - minWidth; } else { rightLength = minRW / 3; @@ -1033,12 +1072,12 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ private void calculateBottomComps(int length) { length += actualVal / 2; - for (int i = 0,num = downComps.size(); i < num; i++){ + for (int i = 0, num = downComps.size(); i < num; i++) { Component comp = downComps.get(i); comp.setLocation(comp.getX(), comp.getY() + length); int offset = comp.getHeight() - length; comp.setSize(comp.getWidth(), offset); - XCreator creator = (XCreator)comp; + XCreator creator = (XCreator) comp; creator.recalculateChildHeight(offset); } } @@ -1048,24 +1087,24 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ int childWidth = (upComps.size() - 1) * actualVal; int childX = container.getWidth() - margin.getLeft() - margin.getRight(); int childY = 0; - if(upComps.size() > INDEX_ZERO){ + if (upComps.size() > INDEX_ZERO) { childY = upComps.get(INDEX_ZERO).getY() + upComps.get(INDEX_ZERO).getHeight() - length; } - for (int i = 0,num = upComps.size(); i < num; i++){ + for (int i = 0, num = upComps.size(); i < num; i++) { Component comp = upComps.get(i); childWidth += comp.getWidth(); - if (comp.getX() < childX){ + if (comp.getX() < childX) { childX = comp.getX(); } if (!isCalculateChildPos) { int offset = comp.getHeight() - length; comp.setSize(comp.getWidth(), offset); - XCreator creator = (XCreator)comp; + XCreator creator = (XCreator) comp; creator.recalculateChildHeight(offset); } } childY += actualVal; - averageH -= actualVal/2; + averageH -= actualVal / 2; if (isCalculateChildPos) { childPosition = new int[]{childX, childY, childWidth, averageH}; } else { @@ -1081,25 +1120,25 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ } int childH = (leftComps.size() - 1) * actualVal; int childX = 0; - if(leftComps.size() > INDEX_ZERO){ + if (leftComps.size() > INDEX_ZERO) { childX = leftComps.get(INDEX_ZERO).getX() + leftComps.get(INDEX_ZERO).getWidth() - length; } int childY = container.getHeight() - margin.getBottom(); - for (int i = 0,num = leftComps.size(); i < num; i++){ + for (int i = 0, num = leftComps.size(); i < num; i++) { Component comp = leftComps.get(i); childH += comp.getHeight(); - if (comp.getY() < childY){ + if (comp.getY() < childY) { childY = comp.getY(); } if (!isCalculateChildPos) { int offset = comp.getWidth() - length; comp.setSize(offset, comp.getHeight()); - XCreator creator = (XCreator)comp; + XCreator creator = (XCreator) comp; creator.recalculateChildWidth(offset); } } childX += actualVal; - averageW -= actualVal/2; + averageW -= actualVal / 2; if (isCalculateChildPos) { childPosition = new int[]{childX, childY, averageW, childH}; } else { @@ -1110,33 +1149,34 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter{ private void calculateRightComps(int length) { length += actualVal / 2; - for (int i=0,num=rightComps.size(); i coordinates[i] - DEPENDING_SCOPE && coordinate + diff < coordinates[i] + DEPENDING_SCOPE) { diff = coordinates[i] - coordinate; @@ -554,8 +544,8 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { difference = Math.max(difference, minWidth - getMinWidth(leftComps)); } //重新计算左右两侧组件size、point - if (CalculateLefttRelatComponent(difference)) { - CalculateRightRelatComponent(objx + difference, -difference); + if (calculateLefttRelatComponent(difference)) { + calculateRightRelatComponent(objx + difference, -difference); } } @@ -670,10 +660,9 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { difference = Math.max(difference, minHeight - getMinHeight(upComps)); } //重新计算上下两侧组件size、point - if (CalculateUpRelatComponent(difference)) { - CalculateDownRelatComponent(objY + difference, -difference); + if (calculateUpRelatComponent(difference)) { + calculateDownRelatComponent(objY + difference, -difference); } - ; } /** @@ -753,13 +742,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { int height = creatorHeight; calculateRelatedComponent(x, y, width, height); if (!rightComps.isEmpty() && getAllHeight(rightComps) == height) { - CalculateRightRelatComponent(x, width + actualVal); + calculateRightRelatComponent(x, width + actualVal); } else if (!leftComps.isEmpty() && getAllHeight(leftComps) == height) { - CalculateLefttRelatComponent(width + actualVal); + calculateLefttRelatComponent(width + actualVal); } else if (!downComps.isEmpty() && getAllWidth(downComps) == width) { - CalculateDownRelatComponent(y, height + actualVal); + calculateDownRelatComponent(y, height + actualVal); } else if (!upComps.isEmpty() && getAllWidth(upComps) == width) { - CalculateUpRelatComponent(height + actualVal); + calculateUpRelatComponent(height + actualVal); } else { // 由于布局三等分的存在,可能会出现删除组件时,找不到关联的组件填充,此时特殊处理 calculateNoRelatedComponent(x, y, width, height); @@ -1022,7 +1011,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { setAdjustedSize(tabLayout, offset, isHor); for (int m = 0; m < tabLayout.getComponentCount(); m++) { XCreator childCreator = tabLayout.getXCreator(m); - BoundsWidget wgt = tabLayout.toData().getBoundsWidget(childCreator.toData()); + WAbsoluteLayout.BoundsWidget wgt = (WAbsoluteLayout.BoundsWidget) tabLayout.toData().getBoundsWidget(childCreator.toData()); wgt.setBounds(tabLayout.getComponent(m).getBounds()); } adjustCreatorsSize(percent, tabLayout, isHor); @@ -1065,7 +1054,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { * @param objX 调整后的坐标x * @param objWidth 调整后的宽度 */ - protected void CalculateRightRelatComponent(int objX, int objWidth) { + protected void calculateRightRelatComponent(int objX, int objWidth) { int count = rightComps.size(); for (int i = 0; i < count; i++) { XCreator creator = (XCreator) rightComps.get(i); @@ -1105,7 +1094,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { /** * 删除或拉伸控件左边框时 调整左侧的组件位置大小; */ - protected boolean CalculateLefttRelatComponent(int objWidth) { + protected boolean calculateLefttRelatComponent(int objWidth) { if (isBeyondAdjustWidthScope(objWidth)) { return false; } @@ -1123,7 +1112,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { /** * 删除或拉伸下边框 调整下方的组件位置大小 */ - protected void CalculateDownRelatComponent(int objY, int objHeight) { + protected void calculateDownRelatComponent(int objY, int objHeight) { int count = downComps.size(); for (int i = 0; i < count; i++) { XCreator creator = (XCreator) downComps.get(i); @@ -1163,7 +1152,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { /** * 删除或拉伸上边框 调整上方的组件位置大小 */ - protected boolean CalculateUpRelatComponent(int objHeight) { + protected boolean calculateUpRelatComponent(int objHeight) { if (isBeyondAdjustHeightScope(objHeight)) { return false; } diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java index 8c67a44ab..b1ca803c6 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java @@ -1,94 +1,105 @@ -/** - * - */ -package com.fr.design.designer.beans.adapters.layout; - - -import java.awt.Rectangle; - -import com.fr.design.beans.GroupModel; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWidgetCreator; -import com.fr.design.designer.creator.cardlayout.XWCardLayout; -import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; -import com.fr.design.designer.properties.FRTabFitLayoutPropertiesGroupModel; -import com.fr.design.utils.ComponentUtils; -import com.fr.form.ui.LayoutBorderStyle; -import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; -import com.fr.general.ComparatorUtils; - -/** - * tab布局tabFit适配器 - * - * @author focus - * @date 2014-6-24 - */ -public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter { - //标题栏高度对tab布局内部组件的y坐标造成了偏移 - private static int TAB_HEIGHT = 40; - - /** - * 构造函数 - * @param container XWTabFitLayout容器 - */ - public FRTabFitLayoutAdapter(XLayoutContainer container) { - super(container); - } - - /** - * 返回布局自身属性,方便一些特有设置在layout刷新时处理 - */ - @Override - public GroupModel getLayoutProperties() { - XWTabFitLayout xfl = (XWTabFitLayout) container; - return new FRTabFitLayoutPropertiesGroupModel(xfl); - } - - /** - * 组件的ComponentAdapter在添加组件时,如果发现布局管理器不为空,会继而调用该布局管理器的 - * addComp方法来完成组件的具体添加。在该方法内,布局管理器可以提供额外的功能。 - * @param creator 被添加的新组件 - * @param x 添加的位置x,该位置是相对于container的 - * @param y 添加的位置y,该位置是相对于container的 - * @return 是否添加成功,成功返回true,否则false - */ - @Override - public boolean addBean(XCreator creator, int x, int y) { - // 经过accept判断后,container会被改变,先备份 - XLayoutContainer backUpContainer = container; - Rectangle rect = ComponentUtils.getRelativeBounds(container); - - int posX = x - rect.x; - int posY = y - rect.y; - if (!accept(creator, posX, posY)) { - return false; - } - // posX,posY是新拖入组件相对于容器的位置,若在tab布局的边缘,则需要把新组件添加到 - // 父层自适应布局中,这时候的添加位置就是tab布局所在的位置 - if(this.intersectsEdge(posX, posY, backUpContainer)){ - if(!ComparatorUtils.equals(backUpContainer.getOuterLayout(), backUpContainer.getBackupParent())){ - XWTabFitLayout tabLayout = (XWTabFitLayout)backUpContainer; - y = adjustY(y,tabLayout); - } - addComp(creator, x, y); - ((XWidgetCreator) creator).recalculateChildrenSize(); - return true; - } - // 如果不在边缘,容器为本自适应布局,增加组件的位置就是相对于容器的位置 - addComp(creator, posX, posY); - ((XWidgetCreator) creator).recalculateChildrenSize(); - return true; - } - - // tab布局的纵坐标受到tab高度的影响,判断的上边界取得是里面XWTabFitLayout的上边界, - // 实际计算的时候的纵坐标用了外层的CardMainBorerLayout,需要将tab高度减掉 - private int adjustY(int y,XWTabFitLayout tabLayout){ - XWCardLayout cardLayout = (XWCardLayout) tabLayout.getBackupParent(); - LayoutBorderStyle style = cardLayout.toData().getBorderStyle(); - if(ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)){ - y -= WCardMainBorderLayout.TAB_HEIGHT; - } - return y; - } +/** + * + */ +package com.fr.design.designer.beans.adapters.layout; + + +import com.fr.design.beans.GroupModel; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWParameterLayout; +import com.fr.design.designer.creator.XWidgetCreator; +import com.fr.design.designer.creator.cardlayout.XWCardLayout; +import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; +import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; +import com.fr.design.designer.properties.FRTabFitLayoutPropertiesGroupModel; +import com.fr.design.mainframe.widget.editors.ParameterEditor; +import com.fr.design.utils.ComponentUtils; +import com.fr.form.ui.LayoutBorderStyle; +import com.fr.form.ui.container.WBorderLayout; +import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; +import com.fr.general.ComparatorUtils; + +import java.awt.*; + +/** + * tab布局tabFit适配器 + * + * @author focus + * @date 2014-6-24 + */ +public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter { + + /** + * 构造函数 + * + * @param container XWTabFitLayout容器 + */ + public FRTabFitLayoutAdapter(XLayoutContainer container) { + super(container); + } + + /** + * 返回布局自身属性,方便一些特有设置在layout刷新时处理 + */ + @Override + public GroupModel getLayoutProperties() { + XWTabFitLayout xfl = (XWTabFitLayout) container; + return new FRTabFitLayoutPropertiesGroupModel(xfl); + } + + /** + * 组件的ComponentAdapter在添加组件时,如果发现布局管理器不为空,会继而调用该布局管理器的 + * addComp方法来完成组件的具体添加。在该方法内,布局管理器可以提供额外的功能。 + * + * @param creator 被添加的新组件 + * @param x 添加的位置x,该位置是相对于container的 + * @param y 添加的位置y,该位置是相对于container的 + * @return 是否添加成功,成功返回true,否则false + */ + @Override + public boolean addBean(XCreator creator, int x, int y) { + // 经过accept判断后,container会被改变,先备份 + XLayoutContainer backUpContainer = container; + Rectangle rect = ComponentUtils.getRelativeBounds(container); + int posX = x - rect.x; + int posY = y - rect.y; + if (!accept(creator, posX, posY)) { + return false; + } + // posX,posY是新拖入组件相对于容器的位置,若在tab布局的边缘,则需要把新组件添加到l + // 父层自适应布局中,这时候的添加位置就是tab布局所在的位置 + if (this.intersectsEdge(posX, posY, backUpContainer)) { + if (!ComparatorUtils.equals(backUpContainer.getOuterLayout(), backUpContainer.getBackupParent())) { + XWTabFitLayout tabLayout = (XWTabFitLayout) backUpContainer; + y = adjustY(y, tabLayout); + } + addComp(creator, x, y); + ((XWidgetCreator) creator).recalculateChildrenSize(); + return true; + } + // 如果不在边缘,容器为本自适应布局,增加组件的位置就是相对于容器的位置 + addComp(creator, posX, posY); + ((XWidgetCreator) creator).recalculateChildrenSize(); + return true; + } + + // tab布局的纵坐标受到tab高度以及参数面板高度的影响,判断的上边界取得是里面XWTabFitLayout的上边界, + // 实际计算的时候的纵坐标用了外层的CardMainBorerLayout,需要将tab高度和参数面板高度减掉 + // 将y值变为相对坐标以实现获取到鼠标drop位置的控件 + // TODO 可以直接在这边将x,y都变成相对坐标,这样在后面判断拖进来的新控件放置方式的时候就不用再判断了 + private int adjustY(int y, XWTabFitLayout tabLayout) { + XWCardLayout cardLayout = (XWCardLayout) tabLayout.getBackupParent(); + LayoutBorderStyle style = cardLayout.toData().getBorderStyle(); + y = y - this.getParaEditorYOffset(); + if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) { + y = y - WCardMainBorderLayout.TAB_HEIGHT; + } + return y; + } + + protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) { + return ComponentUtils.getRelativeBounds(mainLayout); + } + } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java b/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java index a9d700770..3538d2fd9 100644 --- a/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java +++ b/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java @@ -3,8 +3,6 @@ */ package com.fr.design.designer.beans.location; -import java.awt.*; - import com.fr.design.beans.location.Absorptionline; import com.fr.design.beans.location.MoveUtils; import com.fr.design.designer.creator.*; @@ -15,6 +13,8 @@ import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.form.ui.container.WParameterLayout; +import java.awt.*; + /** * @author richer * @since 6.5.3 @@ -27,32 +27,30 @@ public abstract class AccessDirection implements Direction { abstract int getCursor(); - protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, - Rectangle oldbounds); - - protected int[] sorption(int x, int y,Rectangle current_bounds, FormDesigner designer) { - // 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理 - if (!designer.hasWAbsoluteLayout()) { - designer.getStateModel().setEquidistantLine(null); - designer.getStateModel().setXAbsorptionline(null); - designer.getStateModel().setYAbsorptionline(null); - return new int[] { x, y }; - } else { - int posy = current_bounds.y; - - Point relativePoint = getRelativePoint(x, y, current_bounds,designer); - sorptionPoint(relativePoint,current_bounds, designer); - return new int[] { relativePoint.x, relativePoint.y }; - } + protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle currentBounds, FormDesigner designer, + Rectangle oldBounds); + + protected int[] sorption(int x, int y, Rectangle currentBounds, FormDesigner designer) { + // 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理 + if (!designer.hasWAbsoluteLayout()) { + designer.getStateModel().setEquidistantLine(null); + designer.getStateModel().setXAbsorptionline(null); + designer.getStateModel().setYAbsorptionline(null); + return new int[]{x, y}; + } else { + Point relativePoint = getRelativePoint(x, y, currentBounds, designer); + sorptionPoint(relativePoint, currentBounds, designer); + return new int[]{relativePoint.x, relativePoint.y}; + } - } + } - protected Point getRelativePoint(int x, int y, Rectangle current_bounds,FormDesigner designer) { - if (x < 0) { - x = 0; - } else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) { - x = designer.getRootComponent().getWidth(); - } + protected Point getRelativePoint(int x, int y, Rectangle currentBounds, FormDesigner designer) { + if (x < 0) { + x = 0; + } else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) { + x = designer.getRootComponent().getWidth(); + } //参数面板可以无下限拉长 if (y < 0) { y = 0; @@ -63,111 +61,101 @@ public abstract class AccessDirection implements Direction { return new Point(x, y); } - protected void sorptionPoint(Point point, Rectangle current_bounds,FormDesigner designer) { - boolean findInX = current_bounds.getWidth() <= MoveUtils.SORPTION_UNIT ? true : false; - boolean findInY = current_bounds.getHeight() <= MoveUtils.SORPTION_UNIT ? true : false; - - WAbsoluteLayout layout =getLayout(designer); - FormSelection selection = designer.getSelectionModel().getSelection(); - - boolean isWidgetsIntersect = false; - for (int i = 0, count = layout.getWidgetCount(); i < count; i++) { - BoundsWidget temp = (BoundsWidget) layout.getWidget(i); - if (!temp.isVisible() || selection.contains(temp.getWidget())) { - continue; - } - Rectangle bounds = getWidgetRelativeBounds(temp.getBounds(), selection); - if (!findInX) { - int x1 = bounds.x; - if (Math.abs(x1 - point.x) <= MoveUtils.SORPTION_UNIT) { - point.x = x1; - findInX = true; - } - int x2 = bounds.x + bounds.width; - if (Math.abs(x2 - point.x) <= MoveUtils.SORPTION_UNIT) { - point.x = x2; - findInX = true; - } - } - if (!findInY) { - int y1 = bounds.y; - if (Math.abs(y1 - point.y) <= MoveUtils.SORPTION_UNIT) { - point.y = y1; - findInY = true; - } - int y2 = bounds.y + bounds.height; - if (Math.abs(y2 - point.y) <= MoveUtils.SORPTION_UNIT) { - point.y = y2; - findInY = true; - } + protected void sorptionPoint(Point point, Rectangle currentBounds, FormDesigner designer) { + boolean findInX = currentBounds.getWidth() <= MoveUtils.SORPTION_UNIT; + boolean findInY = currentBounds.getHeight() <= MoveUtils.SORPTION_UNIT; + WAbsoluteLayout layout = getLayout(designer); + FormSelection selection = designer.getSelectionModel().getSelection(); + for (int i = 0, count = layout.getWidgetCount(); i < count; i++) { + BoundsWidget temp = (BoundsWidget) layout.getWidget(i); + if (!temp.isVisible() || selection.contains(temp.getWidget())) { + continue; + } + Rectangle bounds = getWidgetRelativeBounds(temp.getBounds(), selection); + if (!findInX) { + int x1 = bounds.x; + if (Math.abs(x1 - point.x) <= MoveUtils.SORPTION_UNIT) { + point.x = x1; + findInX = true; + } + int x2 = bounds.x + bounds.width; + if (Math.abs(x2 - point.x) <= MoveUtils.SORPTION_UNIT) { + point.x = x2; + findInX = true; + } + } + if (!findInY) { + int y1 = bounds.y; + if (Math.abs(y1 - point.y) <= MoveUtils.SORPTION_UNIT) { + point.y = y1; + findInY = true; + } + int y2 = bounds.y + bounds.height; + if (Math.abs(y2 - point.y) <= MoveUtils.SORPTION_UNIT) { + point.y = y2; + findInY = true; + } } if (findInX && findInY) { break; } - if (current_bounds.intersects(bounds) && !(layout instanceof WParameterLayout)){ - isWidgetsIntersect = true; - } - } - processRectangleIntersects(designer, point.x, point.y, isWidgetsIntersect); + } + setDesignerStateModelProperties(designer, findInX, findInY, currentBounds, point); + } - designer.getStateModel().setXAbsorptionline(findInX && current_bounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null); - designer.getStateModel().setYAbsorptionline(findInY && current_bounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null); - designer.getStateModel().setEquidistantLine(null); - } + private void setDesignerStateModelProperties(FormDesigner designer, boolean findInX, boolean findInY, Rectangle + currentBounds, Point point) { + designer.getStateModel().setXAbsorptionline(findInX && currentBounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null); + designer.getStateModel().setYAbsorptionline(findInY && currentBounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null); + designer.getStateModel().setEquidistantLine(null); + } - private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection){ - Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height); - XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); - if (parent == null) { - return relativeRec; - } - Rectangle rec = ComponentUtils.getRelativeBounds(parent); - relativeRec.x += rec.x; - relativeRec.y += rec.y; - return relativeRec; - } + private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection) { + Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height); + XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); + if (parent == null) { + return relativeRec; + } + Rectangle rec = ComponentUtils.getRelativeBounds(parent); + relativeRec.x += rec.x; + relativeRec.y += rec.y; + return relativeRec; + } - private void processRectangleIntersects(FormDesigner designer, int x, int y, boolean isIntersects){ - if(isIntersects){ - if(designer.getLocationOnScreen() != null) { - MoveUtils.displayForbidWindow(x + designer.getLocationOnScreen().x, y + designer.getLocationOnScreen().y); - } - designer.setWidgetsIntersect(true); - } - else{ - MoveUtils.hideForbidWindow(); - designer.setWidgetsIntersect(false); - } - } private WAbsoluteLayout getLayout(final FormDesigner designer){ XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator( designer.getTarget().getContainer()); WAbsoluteLayout layout; - if (formLayoutContainer.acceptType(XWBorderLayout.class)){//看起来这边的作用应该是为了区别cpt(得到XWParameterLayout)还是frm(得到XWBorderLayout)的参数界面 - Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent(); - if(container instanceof XWAbsoluteLayout){ - layout = ((XWAbsoluteLayout)container).toData(); - } - else { - layout = (WAbsoluteLayout) designer.getParaComponent().toData(); - } - } else{ + if (formLayoutContainer.acceptType(XWBorderLayout.class)) {//看起来这边的作用应该是为了区别cpt(得到XWParameterLayout)还是frm(得到XWBorderLayout)的参数界面 + Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent(); + if (container instanceof XWAbsoluteLayout) { + layout = ((XWAbsoluteLayout) container).toData(); + } else { + layout = (WAbsoluteLayout) designer.getParaComponent().toData(); + } + } else { layout = (WAbsoluteLayout) designer.getTarget().getContainer(); } - return layout; + return layout; } - /** - * 拖拽 - * @param dx 坐标x - * @param dy 坐标y - * @param designer 设计界面 - */ - public void drag(int dx, int dy, FormDesigner designer) { - Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds()); + /** + * 拖拽 + * + * @param dx 坐标x + * @param dy 坐标y + * @param designer 设计界面 + */ + public void drag(int dx, int dy, FormDesigner designer) { + Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds()); + if (rec != null) { + designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer); + } else { + return; + } //设定控件最小高度21,因每次拖曳至少移动1,防止控件高度等于21时,拖曳导致rec.y的变化使得控件不停的向上或向下移动。 if(rec.height == MINHEIGHT){ ymin = rec.y; @@ -190,10 +178,8 @@ public abstract class AccessDirection implements Direction { rec.width = MINWIDTH; rec.x = xmin; } - if(rec != null) { - designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer); - } - } + + } /** * 更新鼠标指针形状 diff --git a/designer_form/src/com/fr/design/designer/beans/location/Inner.java b/designer_form/src/com/fr/design/designer/beans/location/Inner.java index c54796a0a..b07b18b4a 100644 --- a/designer_form/src/com/fr/design/designer/beans/location/Inner.java +++ b/designer_form/src/com/fr/design/designer/beans/location/Inner.java @@ -9,9 +9,8 @@ import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormSelection; import com.fr.design.utils.ComponentUtils; import com.fr.form.ui.container.WAbsoluteLayout; -import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.stable.ArrayUtils; -import com.fr.third.com.lowagie.text.*; +import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import java.awt.*; import java.awt.Rectangle; @@ -47,89 +46,97 @@ public class Inner extends AccessDirection { return new Point(x, y); } - @Override - protected void sorptionPoint(Point point, Rectangle current_bounds, final FormDesigner designer) { - RectangleDesigner rd = new RectangleDesigner() { - public void setXAbsorptionline(Absorptionline line) { - designer.getStateModel().setXAbsorptionline(line); - } - public void setYAbsorptionline(Absorptionline line) { - designer.getStateModel().setYAbsorptionline(line); - } - - /** - * 获取当前选中块的水平线数组 - * - * @return 块的水平线数组 - * - */ - public int[] getHorizontalLine(){ - return ArrayUtils.EMPTY_INT_ARRAY; - } - - /** - * 获取当前选中块的垂直线数组 - * - * @return 块的垂直线数组 - * - */ - public int[] getVerticalLine(){ - return ArrayUtils.EMPTY_INT_ARRAY; - } - public RectangleIterator createRectangleIterator() { - return getRectangleIterator(designer); - } + private class RectDesigner implements RectangleDesigner { + private FormDesigner designer = null; - /** - * 设置designer内部组件是否重叠的标志位 - * - * @param isIntersects 是否重叠 - */ - @Override - public void setWidgetsIntersects(boolean isIntersects) { - designer.setWidgetsIntersect(isIntersects); - } + public RectDesigner(FormDesigner designer) { + this.designer = designer; + } - /** - * 获取designer内部组件是否重叠的标志位 - * - * @return 重叠 - */ - @Override - public boolean getWidgetsIntersects() { - return designer.isWidgetsIntersect(); - } + public void setXAbsorptionline(Absorptionline line) { + designer.getStateModel().setXAbsorptionline(line); + } + public void setYAbsorptionline(Absorptionline line) { + designer.getStateModel().setYAbsorptionline(line); + } - /** - * 获取designer相对屏幕的位置 - * - * @return 位置 - */ - @Override - public Point getDesignerLocationOnScreen() { - return designer.getLocationOnScreen(); - } + /** + * 获取当前选中块的水平线数组 + * + * @return 块的水平线数组 + * + */ + public int[] getHorizontalLine(){ + return ArrayUtils.EMPTY_INT_ARRAY; + } - /** - * 设置等距线 - * - * @param line 吸附线 - */ - @Override - public void setEquidistantLine(Absorptionline line) { - designer.getStateModel().setEquidistantLine(line); - } + /** + * 获取当前选中块的垂直线数组 + * + * @return 块的垂直线数组 + * + */ + public int[] getVerticalLine(){ + return ArrayUtils.EMPTY_INT_ARRAY; + } + public RectangleIterator createRectangleIterator() { + return getRectangleIterator(designer); + } - @Override - public int getDesignerScrollHorizontalValue() { - return designer.getArea().getHorizontalValue(); - } + /** + * 设置designer内部组件是否重叠的标志位 + * + * @param isIntersects 是否重叠 + */ + @Override + public void setWidgetsIntersected(boolean isIntersects) { + designer.setWidgetsIntersect(isIntersects); + } - @Override - public int getDesignerScrollVerticalValue() { - return designer.getArea().getVerticalValue(); - } - }; + /** + * 获取designer内部组件是否重叠的标志位 + * + * @return 重叠 + */ + @Override + public boolean isWidgetsIntersected() { + return designer.isWidgetsIntersect(); + } + + /** + * 获取designer相对屏幕的位置 + * + * @return 位置 + */ + @Override + public Point getDesignerLocationOnScreen() { + return designer.getLocationOnScreen(); + } + + /** + * 设置等距线 + * + * @param line 吸附线 + */ + @Override + public void setEquidistantLine(Absorptionline line) { + designer.getStateModel().setEquidistantLine(line); + } + + @Override + public int getDesignerScrollHorizontalValue() { + return designer.getArea().getHorizontalValue(); + } + + @Override + public int getDesignerScrollVerticalValue() { + return designer.getArea().getVerticalValue(); + } + } + + @Override + protected void sorptionPoint(Point point, Rectangle current_bounds, final FormDesigner designer) { + RectDesigner rd = new RectDesigner(designer); //判断当前操作的是不是参数面板,要特殊处理 boolean isParameterLayout = ((XCreator)(designer.getSelectionModel().getSelection().getSelectedCreator().getParent())).acceptType(XWParameterLayout.class); point.setLocation(MoveUtils.sorption(point.x, point.y, current_bounds.width, current_bounds.height, rd, isParameterLayout)); diff --git a/designer_form/src/com/fr/design/designer/beans/models/AddingModel.java b/designer_form/src/com/fr/design/designer/beans/models/AddingModel.java index 46798f4d9..9d308b9d4 100644 --- a/designer_form/src/com/fr/design/designer/beans/models/AddingModel.java +++ b/designer_form/src/com/fr/design/designer/beans/models/AddingModel.java @@ -1,133 +1,141 @@ -package com.fr.design.designer.beans.models; - -import java.awt.Rectangle; - -import com.fr.design.designer.creator.XWAbsoluteLayout; -import com.fr.design.mainframe.FormDesigner; -import com.fr.design.designer.beans.AdapterBus; -import com.fr.design.designer.beans.ComponentAdapter; -import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWParameterLayout; -import com.fr.design.utils.ComponentUtils; -import com.fr.general.ComparatorUtils; - -/** - * 添加状态下的model - */ -public class AddingModel { - - // 当前要添加的组件 - private XCreator creator; - // 记录当前鼠标的位置信息 - private int current_x; - private int current_y; - private boolean added; - - public AddingModel(FormDesigner designer, XCreator xCreator) { - String creatorName = getXCreatorName(designer, xCreator); - this.creator = xCreator; - instantiateCreator(designer, creatorName); - // 初始的时候隐藏该组件的图标 - current_x = -this.creator.getWidth(); - current_y = -this.creator.getHeight(); - } - - /** - * 待说明 - * @param designer 设计器 - * @param creatorName 组件名 - */ - public void instantiateCreator(FormDesigner designer, String creatorName) { - creator.toData().setWidgetName(creatorName); - ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator); - adapter.initialize(); - creator.addNotify(); - creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter); - } - - public AddingModel(XCreator xCreator, int x, int y) { - this.creator = xCreator; - this.creator.backupCurrentSize(); - this.creator.backupParent(); - this.creator.setSize(xCreator.initEditorSize()); - current_x = x - (xCreator.getWidth() / 2); - current_y = y - (xCreator.getHeight() / 2); - } - - /** - * 隐藏当前组件的图标 - */ - public void reset() { - current_x = -this.creator.getWidth(); - current_y = -this.creator.getHeight(); - } - - public String getXCreatorName(FormDesigner designer,XCreator x){ - String def= x.createDefaultName(); - if (x.acceptType(XWParameterLayout.class)) { - return def; - } - int i = 0; - while (designer.getTarget().isNameExist(def + i)) { - i++; - } - return def+i; - } - - public int getCurrentX() { - return current_x; - } - - public int getCurrentY() { - return current_y; - } - - - /** - * 移动组件图标到鼠标事件发生的位置 - * @param x 坐标 - * @param y 坐标 - */ - public void moveTo(int x, int y) { - current_x = x - (this.creator.getWidth() / 2); - current_y = y - (this.creator.getHeight() / 2); - } - - public XCreator getXCreator() { - return this.creator; - } - - /** - * 当前组件是否已经添加到某个容器中 - * @return 是返回true - */ - public boolean isCreatorAdded() { - return added; - } - - /** - * 加入容器 - * @param designer 设计器 - * @param container 容器 - * @param x 坐标 - * @param y 坐标 - * @return 成功返回true - */ - public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) { - //考虑不同布局嵌套的情况,获取顶层容器 - XLayoutContainer xLayoutContainer = container.getTopLayout(); - if(xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class)){ - container = xLayoutContainer; - } - - Rectangle rect = ComponentUtils.getRelativeBounds(container); - if(!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())){ - return added = container.getLayoutAdapter().addBean(creator, x + designer.getArea().getHorizontalValue(), y + designer.getArea().getVerticalValue()); - } - return added = container.getLayoutAdapter().addBean(creator, - x + designer.getArea().getHorizontalValue() - rect.x, - y + designer.getArea().getVerticalValue() - rect.y); - } +package com.fr.design.designer.beans.models; + +import java.awt.Rectangle; + +import com.fr.design.designer.creator.XWAbsoluteLayout; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.designer.beans.AdapterBus; +import com.fr.design.designer.beans.ComponentAdapter; +import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWParameterLayout; +import com.fr.design.utils.ComponentUtils; +import com.fr.general.ComparatorUtils; + +/** + * 添加状态下的model + */ +public class AddingModel { + + // 当前要添加的组件 + private XCreator creator; + // 记录当前鼠标的位置信息 + private int currentX; + private int currentY; + private boolean added; + + public AddingModel(FormDesigner designer, XCreator xCreator) { + String creatorName = getXCreatorName(designer, xCreator); + this.creator = xCreator; + instantiateCreator(designer, creatorName); + // 初始的时候隐藏该组件的图标 + currentY = -this.creator.getWidth(); + currentX = -this.creator.getHeight(); + } + + /** + * 待说明 + * + * @param designer 设计器 + * @param creatorName 组件名 + */ + public void instantiateCreator(FormDesigner designer, String creatorName) { + creator.toData().setWidgetName(creatorName); + ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator); + adapter.initialize(); + creator.addNotify(); + creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter); + } + + public AddingModel(XCreator xCreator, int x, int y) { + this.creator = xCreator; + this.creator.backupCurrentSize(); + this.creator.backupParent(); + this.creator.setSize(xCreator.initEditorSize()); + currentX = x - (xCreator.getWidth() / 2); + currentY = y - (xCreator.getHeight() / 2); + } + + /** + * 隐藏当前组件的图标 + */ + public void reset() { + currentX = -this.creator.getWidth(); + currentY = -this.creator.getHeight(); + } + + public String getXCreatorName(FormDesigner designer, XCreator x) { + String def = x.createDefaultName(); + if (x.acceptType(XWParameterLayout.class)) { + return def; + } + int i = 0; + while (designer.getTarget().isNameExist(def + i)) { + i++; + } + return def + i; + } + + public int getCurrentX() { + return currentX; + } + + public int getCurrentY() { + return currentY; + } + + + /** + * 移动组件图标到鼠标事件发生的位置 + * + * @param x 坐标 + * @param y 坐标 + */ + public void moveTo(int x, int y) { + currentX = x - (this.creator.getWidth() / 2); + currentY = y - (this.creator.getHeight() / 2); + } + + public XCreator getXCreator() { + return this.creator; + } + + /** + * 当前组件是否已经添加到某个容器中 + * + * @return 是返回true + */ + public boolean isCreatorAdded() { + return added; + } + + /** + * 加入容器 + * + * @param designer 设计器 + * @param container 容器 + * @param x 坐标 + * @param y 坐标 + * @return 成功返回true + */ + public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) { + //考虑不同布局嵌套的情况,获取顶层容器 + XLayoutContainer xLayoutContainer = container.getTopLayout(); + if (xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class)) { + container = xLayoutContainer; + } + + Rectangle rect = ComponentUtils.getRelativeBounds(container); + if (!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())) { + added = container.getLayoutAdapter().addBean(creator, + x + designer.getArea().getHorizontalValue(), + y + designer.getArea().getVerticalValue()); + return added; + } + added = container.getLayoutAdapter().addBean(creator, + x + designer.getArea().getHorizontalValue() - rect.x, + y + designer.getArea().getVerticalValue() - rect.y); + return added; + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java b/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java index 834b28d74..13eaa18ac 100644 --- a/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java +++ b/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java @@ -1,328 +1,461 @@ -package com.fr.design.designer.beans.models; - -import java.awt.LayoutManager; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.event.MouseEvent; -import java.util.ArrayList; - -import com.fr.design.designer.beans.AdapterBus; -import com.fr.design.designer.beans.LayoutAdapter; -import com.fr.design.designer.beans.events.DesignerEvent; -import com.fr.design.designer.beans.location.Direction; -import com.fr.design.designer.beans.location.Location; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XCreatorUtils; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWFitLayout; -import com.fr.design.designer.creator.XWParameterLayout; -import com.fr.design.form.util.XCreatorConstants; -import com.fr.design.mainframe.FormDesigner; -import com.fr.design.mainframe.FormSelection; -import com.fr.design.mainframe.FormSelectionUtils; -import com.fr.design.utils.gui.LayoutUtils; -import com.fr.stable.ArrayUtils; - -/** - * 该model保存当前选择的组件和剪切版信息 - */ -public class SelectionModel { - private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离 - private static FormSelection CLIP_BOARD = new FormSelection(); - private FormDesigner designer; - private FormSelection selection; - private Rectangle hotspot_bounds; - - public SelectionModel(FormDesigner designer) { - this.designer = designer; - selection = new FormSelection(); - } - - /** - * 重置。清空formSelction以及选择区域 - */ - public void reset() { - selection.reset(); - hotspot_bounds = null; - } - - /** - * formSelction是否为空 - * @return 是否为空 - */ - public static boolean isEmpty(){ - return CLIP_BOARD.isEmpty(); - } - - /** - * 鼠标点击一下,所选中的单个组件。按下Ctrl或者shift键时鼠标可以进行多选 - * @param e 鼠标事件 - */ - public void selectACreatorAtMouseEvent(MouseEvent e) { - if (!e.isControlDown() && !e.isShiftDown()) { - // 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件 - selection.reset(); - } - - // 获取e所在的组件 - XCreator comp = designer.getComponentAt(e); - - //布局组件的顶层布局如不可编辑,要获取其顶层布局 - XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout(); - if(topLayout != null && !topLayout.isEditable()){ - comp = topLayout; - } - - // 如果父层是scale和title两个专属容器,返回其父层,组件本身是不让被选中的 - if (comp != designer.getRootComponent() && comp != designer.getParaComponent()) { - XCreator parentContainer = (XCreator) comp.getParent(); - comp = parentContainer.isDedicateContainer() ? parentContainer : comp; - } - if (selection.removeSelectedCreator(comp) || selection.addSelectedCreator(comp)) { - designer.getEditListenerTable().fireCreatorModified(comp, DesignerEvent.CREATOR_SELECTED); - designer.repaint(); - } - } - - /** - * 将所选组件剪切到剪切板上 - */ - public void cutSelectedCreator2ClipBoard() { - if (hasSelectionComponent()) { - selection.cut2ClipBoard(CLIP_BOARD); - designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED); - designer.repaint(); - } - } - - /** - * 复制当前选中的组件到剪切板 - */ - public void copySelectedCreator2ClipBoard() { - if (!selection.isEmpty()) { - selection.copy2ClipBoard(CLIP_BOARD); - } - } - - /** - * 从剪切板粘帖组件 - * @return 否 - */ - public boolean pasteFromClipBoard() { - if (!CLIP_BOARD.isEmpty()) { - XLayoutContainer parent = null; - if (!hasSelectionComponent()) { - FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),CLIP_BOARD, DELTA_X_Y, DELTA_X_Y); - } else { - parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); - if (parent != null) { - Rectangle rec = selection.getSelctionBounds(); - FormSelectionUtils.paste2Container(designer, parent,CLIP_BOARD, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); - } - } - } else { - Toolkit.getDefaultToolkit().beep(); - } - return false; - } - - public FormSelection getSelection() { - return selection; - } - - /** - * 删除当前所有选择的组件 - */ - public void deleteSelection() { - XCreator[] roots = selection.getSelectedCreators(); - - if (roots.length > 0) { - for (XCreator creator : roots) { - if(creator.acceptType(XWParameterLayout.class)){ - designer.removeParaComponent(); - } - - removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight()); - creator.removeAll(); - // 清除被选中的组件 - selection.reset(); - } - setSelectedCreator(designer.getRootComponent()); - // 触发事件 - designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); - designer.repaint(); - } - } - - /** - * 从选择组件中删除某组件 - * - * @param creator 组件 - * @param creatorWidth 组件之前宽度 - * @param creatorHeight 组件之前高度 - */ - public void removeCreator(XCreator creator, int creatorWidth, int creatorHeight) { - selection.removeCreator(creator); - removeCreatorFromContainer(creator, creatorWidth, creatorHeight); - designer.repaint(); - } - - /** - * 设置选择区域 - */ - public void setHotspotBounds(Rectangle rect) { - hotspot_bounds = rect; - } - - /** - * 获得当前选择区域 - */ - public Rectangle getHotspotBounds() { - return hotspot_bounds; - } - - private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) { - XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator); - if (parent == null) { - return; - } - boolean changeCreator = creator.shouldScaleCreator() || creator.hasTitleStyle(); - if (parent.acceptType(XWFitLayout.class) && changeCreator) { - creator = (XCreator) creator.getParent(); - } - parent.getLayoutAdapter().removeBean(creator, creatorWidth, creatorHeight); - // 删除其根组件,同时就删除了同时被选择的叶子组件 - parent.remove(creator); - LayoutManager layout = parent.getLayout(); - - if (layout != null) { - // 刷新组件容器的布局 - LayoutUtils.layoutContainer(parent); - } - } - - /** - * 是否有组件被选择。如果所选组件是最底层容器,也视为无选择 - * @return 是则返回true - */ - public boolean hasSelectionComponent() { - return !selection.isEmpty() && selection.getSelectedCreator().getParent() != null; - } - - /** - * 移动组件至指定位置 - * @param x 坐标x - * @param y 坐标y - */ - public void move(int x, int y) { - for (XCreator creator : selection.getSelectedCreators()) { - creator.setLocation(creator.getX() + x, creator.getY() + y); - LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator); - if (layoutAdapter != null) { - layoutAdapter.fix(creator); - } - } - designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), - DesignerEvent.CREATOR_SELECTED); - } - - /** - * 释放捕获 - */ - public void releaseDragging() { - designer.setPainter(null); - selection.fixCreator(designer); - designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), - DesignerEvent.CREATOR_RESIZED); - } - - public Direction getDirectionAt(MouseEvent e) { - Direction dir; - if (e.isControlDown() || e.isShiftDown()) { - XCreator creator = designer.getComponentAt(e.getX(), e.getY(), selection.getSelectedCreators()); - if (creator != designer.getRootComponent() && selection.addedable(creator)) { - return Location.add; - } - } - if (hasSelectionComponent()) { - int x = e.getX() + designer.getArea().getHorizontalValue(); - int y = e.getY() + designer.getArea().getVerticalValue(); - dir = getDirection(selection.getRelativeBounds(), x, y); - if (selection.size() == 1) { - if (!ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir.getActual())) { - dir = Location.outer; - } - } - } else { - dir = Location.outer; - } - - if (designer.getDesignerMode().isFormParameterEditor() && dir == Location.outer) { - dir = designer.getLoc2Root(e); - } - return dir; - } - - private Direction getDirection(Rectangle bounds, int x, int y) { - if (x < (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) { - return Location.outer; - } else if ((x >= (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) && (x <= bounds.x)) { - if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { - return Location.outer; - } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { - return Location.left_top; - } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { - return Location.left; - } else if ((y >= (bounds.y + bounds.height)) - && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { - return Location.left_bottom; - } else { - return Location.outer; - } - } else if ((x > bounds.x) && (x < (bounds.x + bounds.width))) { - if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { - return Location.outer; - } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { - return Location.top; - } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { - return Location.inner; - } else if ((y >= (bounds.y + bounds.height)) - && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { - return Location.bottom; - } else { - return Location.outer; - } - } else if ((x >= (bounds.x + bounds.width)) - && (x <= (bounds.x + bounds.width + XCreatorConstants.RESIZE_BOX_SIZ))) { - if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { - return Location.outer; - } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { - return Location.right_top; - } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { - return Location.right; - } else if ((y >= (bounds.y + bounds.height)) - && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { - return Location.right_bottom; - } else { - return Location.outer; - } - } else { - return Location.outer; - } - } - - private void fireCreatorSelected() { - designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), - DesignerEvent.CREATOR_SELECTED); - } - - public void setSelectedCreator(XCreator rootComponent) { - selection.setSelectedCreator(rootComponent); - fireCreatorSelected(); - } - - public void setSelectedCreators(ArrayList rebuildSelection) { - selection.setSelectedCreators(rebuildSelection); - fireCreatorSelected(); - } +package com.fr.design.designer.beans.models; + +import com.fr.design.designer.beans.AdapterBus; +import com.fr.design.designer.beans.LayoutAdapter; +import com.fr.design.designer.beans.events.DesignerEvent; +import com.fr.design.designer.beans.location.Direction; +import com.fr.design.designer.beans.location.Location; +import com.fr.design.designer.creator.*; +import com.fr.design.designer.creator.cardlayout.XWCardLayout; +import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; +import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; +import com.fr.design.form.util.XCreatorConstants; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.FormSelection; +import com.fr.design.mainframe.FormSelectionUtils; +import com.fr.design.utils.ComponentUtils; +import com.fr.design.utils.gui.LayoutUtils; +import com.fr.stable.ArrayUtils; + +import java.awt.*; +import java.awt.event.MouseEvent; +import java.util.ArrayList; + +/** + * 该model保存当前选择的组件和剪切版信息 + */ +public class SelectionModel { + //被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。 + private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离 + private static final double OFFSET_RELATIVE = 0.80; + private static FormSelection clipboard = new FormSelection(); + private FormDesigner designer; + private FormSelection selection; + private Rectangle hotspotBounds; + + public SelectionModel(FormDesigner designer) { + this.designer = designer; + selection = new FormSelection(); + } + + /** + * 重置。清空formSelction以及选择区域 + */ + public void reset() { + selection.reset(); + hotspotBounds = null; + } + + /** + * formSelction是否为空 + * + * @return 是否为空 + */ + public static boolean isEmpty() { + return clipboard.isEmpty(); + } + + /** + * 鼠标点击一下,所选中的单个组件。按下Ctrl或者shift键时鼠标可以进行多选 + * + * @param e 鼠标事件 + */ + public void selectACreatorAtMouseEvent(MouseEvent e) { + if (!e.isControlDown() && !e.isShiftDown()) { + // 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件 + selection.reset(); + } + // 获取e所在的组件 + XCreator comp = designer.getComponentAt(e); + + //布局组件的顶层布局如不可编辑,要获取其顶层布局 + XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout(); + if (topLayout != null && !topLayout.isEditable()) { + comp = topLayout; + } + + // 如果父层是scale和title两个专属容器,返回其父层,组件本身是不让被选中的 + if (comp != designer.getRootComponent() && comp != designer.getParaComponent()) { + XCreator parentContainer = (XCreator) comp.getParent(); + comp = parentContainer.isDedicateContainer() ? parentContainer : comp; + } + if (selection.removeSelectedCreator(comp) || selection.addSelectedCreator(comp)) { + designer.getEditListenerTable().fireCreatorModified(comp, DesignerEvent.CREATOR_SELECTED); + designer.repaint(); + } + } + + /** + * 将所选组件剪切到剪切板上 + */ + public void cutSelectedCreator2ClipBoard() { + if (hasSelectionComponent()) { + selection.cut2ClipBoard(clipboard); + designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED); + designer.repaint(); + } + } + + /** + * 复制当前选中的组件到剪切板 + */ + public void copySelectedCreator2ClipBoard() { + if (!selection.isEmpty()) { + selection.copy2ClipBoard(clipboard); + } + } + + /** + * 从剪切板粘帖组件 + * + * @return 否 + */ + public boolean pasteFromClipBoard() { + if (!clipboard.isEmpty()) { + if (!hasSelectedPasteSource()) { + //未选 + unselectedPaste(); + } else { + //已选 + selectedPaste(); + } + } else { + Toolkit.getDefaultToolkit().beep(); + } + return false; + } + + public FormSelection getSelection() { + return selection; + } + + /** + * 粘贴时未选择组件 + */ + private void unselectedPaste() { + if (designer.getClass().equals(FormDesigner.class)) { + if (selection.getSelectedCreator() instanceof XWFitLayout) { + if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) { + XLayoutContainer container = (XLayoutContainer) selection.getSelectedCreator(); + //tab布局编辑器内部左上角第一个坐标点 + int leftUpX = container.toData().getMargin().getLeft() + 1; + int leftUpY = container.toData().getMargin().getTop() + 1; + //选中第一个坐标点坐在的组件 + selection.setSelectedCreator((XCreator) container.getComponentAt(leftUpX, leftUpY)); + Rectangle rectangle = selection.getRelativeBounds(); + if (hasSelectedPasteSource()) { + selectedPaste(); + } else { + FormSelectionUtils.paste2Container(designer, container, clipboard, + rectangle.x + rectangle.width / 2, + rectangle.y + DELTA_X_Y); + } + } else { + //自适应布局编辑器内部左上角第一个坐标点 + int leftUpX = designer.getRootComponent().toData().getMargin().getLeft() + 1; + int leftUpY = designer.getRootComponent().toData().getMargin().getTop() + 1; + //选中第一个坐标点坐在的组件 + selection.setSelectedCreator((XCreator) designer.getRootComponent().getComponentAt(leftUpX, leftUpY)); + Rectangle rectangle = selection.getRelativeBounds(); + if (hasSelectedPasteSource()) { + selectedPaste(); + } else { + FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), + clipboard, + rectangle.x + rectangle.width / 2, + rectangle.y + DELTA_X_Y); + } + } + } else { + //绝对布局 + //编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层 + //当前选择的就是编辑器表层 + FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), + clipboard, + DELTA_X_Y, + DELTA_X_Y); + } + } else { + //cpt本地组件复用,编辑器就一层,是最底层,使用designer.getRootComponent()就可以获取到 + //使用selection.getSelectedCreator()也应该是可以获取到的。 + FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), + clipboard, + DELTA_X_Y, + DELTA_X_Y); + } + } + + /** + * 粘贴时选择组件 + */ + private void selectedPaste() { + XLayoutContainer container = null; + //获取到编辑器的表层容器(已选的组件的父容器就是表层容器) + container = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); + if (container != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) { + //自适应布局 + + Rectangle selectionRec = selection.getRelativeBounds(); + //获取父容器位置,补充因参数面板高度导致的位置坐标计算偏移 + Rectangle containerRec = ComponentUtils.getRelativeBounds(container); + int positionX, positionY; + + if (container.getClass().equals(XWTabFitLayout.class)) { + //tab内部粘贴不补充高度偏移 + //且不计算参数面板造成的影响,因为在 + //@see com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter#addBean中做了 + positionX = selectionRec.x + selectionRec.width / 2; + positionY = (int) (selectionRec.y + selectionRec.height * OFFSET_RELATIVE); + } else { + //计算自适应布局位置 + positionX = selectionRec.x - containerRec.x + selectionRec.width / 2; + positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE); + } + FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY); + } else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { + //绝对布局 + Rectangle rec = selection.getSelctionBounds(); + FormSelectionUtils.paste2Container(designer, container, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); + } + } + + /** + * 删除当前所有选择的组件 + */ + public void deleteSelection() { + XCreator[] roots = selection.getSelectedCreators(); + + if (roots.length > 0) { + for (XCreator creator : roots) { + if (creator.acceptType(XWParameterLayout.class)) { + designer.removeParaComponent(); + } + removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight()); + creator.removeAll(); + // 清除被选中的组件 + selection.reset(); + } + setSelectedCreator(designer.getRootComponent()); + FormSelectionUtils.rebuildSelection(designer); + // 触发事件 + designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); + designer.repaint(); + } + } + + /** + * 从选择组件中删除某组件 + * + * @param creator 组件 + * @param creatorWidth 组件之前宽度 + * @param creatorHeight 组件之前高度 + */ + public void removeCreator(XCreator creator, int creatorWidth, int creatorHeight) { + selection.removeCreator(creator); + removeCreatorFromContainer(creator, creatorWidth, creatorHeight); + designer.repaint(); + } + + /** + * 设置选择区域 + */ + public void setHotspotBounds(Rectangle rect) { + hotspotBounds = rect; + } + + /** + * 获得当前选择区域 + */ + public Rectangle getHotspotBounds() { + return hotspotBounds; + } + + private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) { + XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator); + if (parent == null) { + return; + } + boolean changeCreator = creator.shouldScaleCreator() || creator.hasTitleStyle(); + if (parent.acceptType(XWFitLayout.class) && changeCreator) { + creator = (XCreator) creator.getParent(); + } + parent.getLayoutAdapter().removeBean(creator, creatorWidth, creatorHeight); + // 删除其根组件,同时就删除了同时被选择的叶子组件 + parent.remove(creator); + LayoutManager layout = parent.getLayout(); + + if (layout != null) { + // 刷新组件容器的布局 + LayoutUtils.layoutContainer(parent); + } + } + + /** + * 是否有组件被选择。如果所选组件是最底层容器,也视为无选择 + * + * @return 是则返回true + * yaoh.wu 不应该通过判断是否是最底层容器来判断是否选择了组件 + * 而是应该判断选择的容器是否是编辑器的最表层容器,也就是点击空白地方选择的容器 + * 但是直接判断选择的容器是否是编辑器最表层类型又会引发拖动时选不上的情况, + * 因此通过判断父容器来实现 + *

+ * 举例:frm组件复用 绝对布局情况下,不选择时有三层容器: + * 底层@see {@link com.fr.design.designer.creator.XWBorderLayout} + * 中层@see {@link XWFitLayout} + * 表层@see {@link com.fr.design.designer.creator.XWAbsoluteBodyLayout} + *

+ * 但是编辑窗口的最外层其实是表层@see {@link com.fr.design.designer.creator.XWAbsoluteBodyLayout}, + * 其他两层不是靠添加组件就可以编辑的。 + */ + public boolean hasSelectedPasteSource() { + XCreator selectionXCreator = selection.getSelectedCreator(); + if (designer.getClass().equals(FormDesigner.class)) { + //frm本地组件复用 + if (selectionXCreator != null) { + //选中的是否是tab布局编辑器本身 + boolean tabEditor = selectionXCreator.getClass().equals(XWCardMainBorderLayout.class) + || selectionXCreator.getClass().equals(XWCardLayout.class) + || selectionXCreator.getClass().equals(XWTabFitLayout.class); + //选中的是否是frm绝对布局编辑器本身 + boolean absoluteEditor = selectionXCreator.getClass().equals(XWAbsoluteBodyLayout.class); + //选中是否是frm绝对画布块编辑器本身 + boolean absoluteCanvas = selectionXCreator.getClass().equals(XWAbsoluteLayout.class); + //选中的是否是相对布局编辑器本身 + boolean relativeEditor = selectionXCreator.getClass().equals(XWFitLayout.class); + + return !(tabEditor || absoluteEditor || absoluteCanvas || relativeEditor); + } else { + return false; + } + } else { + //cpt本地组件复用,selection.getSelectedCreator().getParent()=@XWParameterLayout instanceof @XWAbsoluteLayout + return selectionXCreator != null && selectionXCreator.getParent() != null; + } + } + + /** + * 是否有组件被选择。如果所选组件是最底层容器,也视为无选择 + * + * @return 是则返回true + */ + public boolean hasSelectionComponent() { + return !selection.isEmpty() && selection.getSelectedCreator().getParent() != null; + } + + /** + * 移动组件至指定位置 + * + * @param x 坐标x + * @param y 坐标y + */ + public void move(int x, int y) { + for (XCreator creator : selection.getSelectedCreators()) { + creator.setLocation(creator.getX() + x, creator.getY() + y); + LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator); + if (layoutAdapter != null) { + layoutAdapter.fix(creator); + } + } + designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), + DesignerEvent.CREATOR_SELECTED); + } + + /** + * 释放捕获 + */ + public void releaseDragging() { + designer.setPainter(null); + selection.fixCreator(designer); + designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), + DesignerEvent.CREATOR_RESIZED); + } + + public Direction getDirectionAt(MouseEvent e) { + Direction dir; + if (e.isControlDown() || e.isShiftDown()) { + XCreator creator = designer.getComponentAt(e.getX(), e.getY(), selection.getSelectedCreators()); + if (creator != designer.getRootComponent() && selection.addedable(creator)) { + return Location.add; + } + } + if (hasSelectionComponent()) { + int x = e.getX() + designer.getArea().getHorizontalValue(); + int y = e.getY() + designer.getArea().getVerticalValue(); + dir = getDirection(selection.getRelativeBounds(), x, y); + if (selection.size() == 1 && !ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir + .getActual())) { + dir = Location.outer; + } + } else { + dir = Location.outer; + } + + if (designer.getDesignerMode().isFormParameterEditor() && dir == Location.outer) { + dir = designer.getLoc2Root(e); + } + return dir; + } + + private Direction getDirection(Rectangle bounds, int x, int y) { + if (x < (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) { + return Location.outer; + } else if ((x >= (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) && (x <= bounds.x)) { + if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { + return Location.outer; + } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { + return Location.left_top; + } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { + return Location.left; + } else if ((y >= (bounds.y + bounds.height)) + && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { + return Location.left_bottom; + } else { + return Location.outer; + } + } else if ((x > bounds.x) && (x < (bounds.x + bounds.width))) { + if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { + return Location.outer; + } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { + return Location.top; + } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { + return Location.inner; + } else if ((y >= (bounds.y + bounds.height)) + && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { + return Location.bottom; + } else { + return Location.outer; + } + } else if ((x >= (bounds.x + bounds.width)) + && (x <= (bounds.x + bounds.width + XCreatorConstants.RESIZE_BOX_SIZ))) { + if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { + return Location.outer; + } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { + return Location.right_top; + } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { + return Location.right; + } else if ((y >= (bounds.y + bounds.height)) + && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { + return Location.right_bottom; + } else { + return Location.outer; + } + } else { + return Location.outer; + } + } + + private void fireCreatorSelected() { + designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), + DesignerEvent.CREATOR_SELECTED); + } + + public void setSelectedCreator(XCreator rootComponent) { + selection.setSelectedCreator(rootComponent); + fireCreatorSelected(); + } + + public void setSelectedCreators(ArrayList rebuildSelection) { + selection.setSelectedCreators(rebuildSelection); + fireCreatorSelected(); + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/beans/models/StateModel.java b/designer_form/src/com/fr/design/designer/beans/models/StateModel.java index a623caddc..ff3fcbedc 100644 --- a/designer_form/src/com/fr/design/designer/beans/models/StateModel.java +++ b/designer_form/src/com/fr/design/designer/beans/models/StateModel.java @@ -1,446 +1,476 @@ -package com.fr.design.designer.beans.models; - -import java.awt.Component; -import java.awt.Cursor; -import java.awt.Graphics; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.event.MouseEvent; -import java.util.ArrayList; - -import com.fr.design.beans.location.Absorptionline; -import com.fr.design.mainframe.FormDesigner; -import com.fr.design.mainframe.FormSelectionUtils; -import com.fr.design.designer.beans.AdapterBus; -import com.fr.design.designer.beans.HoverPainter; -import com.fr.design.designer.beans.LayoutAdapter; -import com.fr.design.designer.beans.events.DesignerEvent; -import com.fr.design.designer.beans.location.Direction; -import com.fr.design.designer.beans.location.Location; -import com.fr.design.designer.creator.XConnector; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XCreatorUtils; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWAbsoluteLayout; -import com.fr.design.utils.ComponentUtils; - -/** - * 普通模式下的状态model - */ -public class StateModel { - // 对应的selection model - - private SelectionModel selectionModel; - // 当前鼠标进入拖拽区域的位置类型 - private Direction driection; - - // 当前拖拽的起始位置 - private int current_x; - private int current_y; - - private Point startPoint = new Point(); - private Point currentPoint = new Point(); - - private Absorptionline lineInX; - private Absorptionline lineInY; - //等距线 - private Absorptionline lineEquidistant; - - // 当前是否处于拖拽选择状态 - private boolean selecting; - private boolean dragging; - - private boolean addable; - - private FormDesigner designer; - - public StateModel(FormDesigner designer) { - this.designer = designer; - selectionModel = designer.getSelectionModel(); - } - - /** - * 返回direction - * @return direction方向 - */ - public Direction getDirection() { - return driection; - } - - /** - * 是否有组件正被选中 - * - * @return true 如果至少一个组件被选中 - */ - public boolean isSelecting() { - return selecting; - } - - /** - *是否能拖拽 - * @return 非outer且选中为空 - */ - public boolean dragable() { - return ((driection != Location.outer) && !selecting); - } - - /** - * 拖拽中是否可以转换为添加模式: - * 如果拖拽组件只有一个,鼠标当前所在位置的最底层表单容器与这个组件的容器不同; - * 如果拖拽组件为多个,鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外,还必须是绝对定位布局 - */ - private void checkAddable(MouseEvent e) { - addable = false; - designer.setPainter(null); - - if (driection != Location.inner) { - return; - } - - XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); - XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); - XCreator creator = selectionModel.getSelection().getSelectedCreator(); - Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator); - if (creatorContainer != null && creatorContainer != container - && (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) { - HoverPainter painter = AdapterBus.getContainerPainter(designer, container); - designer.setPainter(painter); - 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(e.getX(), e.getY())); - painter.setCreator(creator); - } - addable = true; - } - } - - private boolean addBean(XLayoutContainer container, int x, int y) { - LayoutAdapter adapter = container.getLayoutAdapter(); - Rectangle r = ComponentUtils.getRelativeBounds(container); - if (selectionModel.getSelection().size() == 1) { - return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), x - + designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue() - r.y); - } - for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { - adapter.addBean(creator, x + designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue()- r.y); - } - return true; - } - - private void adding(int x, int y) { - // 当前鼠标所在的组件 - XCreator hoveredComponent = designer.getComponentAt(x, y, selectionModel.getSelection().getSelectedCreators()); - - // 获取该组件所在的焦点容器 - XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); - - boolean success = false; - - if (container != null) { - // 如果是容器,则调用其acceptComponent接受组件 - success = addBean(container, x, y); - } - - if (success) { - FormSelectionUtils.rebuildSelection(designer); - designer.getEditListenerTable().fireCreatorModified( - selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); - } else { - Toolkit.getDefaultToolkit().beep(); - } - - // 取消提示 - designer.setPainter(null); - } - - /** - *是否拖拽 - * @return dragging状态 - */ - public boolean isDragging() { - return dragging; - } - - /** - *是否可以开始画线 - * @return startPoint不为空返回true - */ - public boolean prepareForDrawLining() { - return startPoint != null; - } - - /** - *设置开始位置 - * @param p point位置 - */ - public void setStartPoint(Point p) { - this.startPoint = p; - } - - /** - *返回开始位置 - * @return 点位置 - */ - public Point getStartPoint() { - return startPoint; - } - - /** - *返回当前点位置 - * @return 点位置 - */ - public Point getEndPoint() { - return currentPoint; - } - - /** - *当前选中组件 - * @param e 鼠标事件 - */ - public void startSelecting(MouseEvent e) { - selecting = true; - selectionModel.setHotspotBounds(new Rectangle()); - current_x = getMouseXY(e).x; - current_y = getMouseXY(e).y; - } - - /** - *当前鼠标的xy - * @param e 鼠标事件 - */ - public void startResizing(MouseEvent e) { - if (!selectionModel.getSelection().isEmpty()) { - driection.backupBounds(designer); - } - current_x = getMouseXY(e).x; - current_y = getMouseXY(e).y; - } - - /** - *起始点开始DrawLine - * @param p 点位置 - */ - public void startDrawLine(Point p) { - this.startPoint = p; - if(p != null) { - try { - designer.setCursor(XConnector.connectorCursor); - } catch (Exception e) { - } - } else { - designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - } - - /** - *鼠标释放时所在的区域及圈中的组件 - * @param e 鼠标事件 - */ - public void selectCreators(MouseEvent e) { - int x = getMouseXY(e).x; - int y = getMouseXY(e).y; - - Rectangle bounds = createCurrentBounds(x, y); - - if ((x != current_x) || (y != current_y)) { - selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); - } - selectionModel.setHotspotBounds(null); - } - - /** - *画所在区域线 - * @param e 鼠标事件 - */ - public void drawLine(MouseEvent e) { - designer.getDrawLineHelper().setDrawLine(true); - Point p = designer.getDrawLineHelper().getNearWidgetPoint(e); - if (p != null) { - currentPoint = p; - } else { - currentPoint.x = e.getX() + designer.getArea().getHorizontalValue(); - currentPoint.y = e.getY() + designer.getArea().getVerticalValue(); - } - } - - private Rectangle createCurrentBounds(int x, int y) { - Rectangle bounds = new Rectangle(); - - bounds.x = Math.min(x, current_x); - bounds.y = Math.min(y, current_y); - bounds.width = Math.max(x, current_x) - bounds.x; - bounds.height = Math.max(y, current_y) - bounds.y; - - return bounds; - } - - private ArrayList getHotspotCreators(Rectangle selection, XCreator root) { - ArrayList creators = new ArrayList(); - - if (!root.isVisible() && !designer.isRoot(root)) { - return creators; - } - - if (root instanceof XLayoutContainer) { - XLayoutContainer container = (XLayoutContainer) root; - int count = container.getXCreatorCount(); - Rectangle clipped = new Rectangle(selection); - - for (int i = count - 1; i >= 0; i--) { - XCreator child = container.getXCreator(i); - - if (selection.contains(child.getBounds())) { - creators.add(child); - } else { - clipped.x = selection.x - child.getX(); - clipped.y = selection.y - child.getY(); - creators.addAll(getHotspotCreators(clipped, child)); - } - } - } - - return creators; - } - - - /** - *重置model - */ - public void resetModel() { - dragging = false; - selecting = false; - } - - /** - *重置 - */ - public void reset() { - driection = Location.outer; - dragging = false; - selecting = false; - } - - /** - *取消拖拽 - */ - public void draggingCancel() { - designer.repaint(); - reset(); - } - - /** - *设置可拉伸方向 - * @param dir 拉伸方向 - */ - public void setDirection(Direction dir) { - if(driection != dir) { - this.driection = dir; - driection.updateCursor(designer); - } - } - - /** - *x吸附线赋值 - * @param line 线 - */ - public void setXAbsorptionline(Absorptionline line) { - this.lineInX = line; - } - - /** - *y吸附线赋值 - * @param line 线 - */ - public void setYAbsorptionline(Absorptionline line) { - this.lineInY = line; - } - - /** - * 等距线赋值 - * @param line 线 - */ - public void setEquidistantLine(Absorptionline line){ - this.lineEquidistant = line; - } - - /** - *画吸附线 - * @param g Graphics类 - */ - public void paintAbsorptionline(Graphics g) { - if(lineInX != null) { - lineInX.paint(g,designer.getArea()); - } - if(lineInY != null) { - lineInY.paint(g,designer.getArea()); - } - if(lineEquidistant != null){ - lineEquidistant.paint(g,designer.getArea()); - } - } - - /** - *拖拽 - * @param e 鼠标事件 - */ - public void dragging(MouseEvent e) { - checkAddable(e); - setDependLinePainter(e); - driection.drag(getMouseXY(e).x-current_x, getMouseXY(e).y-current_y, designer); - this.dragging = true; - } - - // 拖拽时画依附线用到的painter - private void setDependLinePainter(MouseEvent e){ - XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); - XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); - XCreator creator = selectionModel.getSelection().getSelectedCreator(); - HoverPainter painter = AdapterBus.getContainerPainter(designer, container); - designer.setPainter(painter); - if (painter != null) { - painter.setHotspot(new Point(e.getX(), e.getY())); - painter.setCreator(creator); - } - } - - /** - *释放捕获 - * @param e 鼠标事件 - */ - public void releaseDragging(MouseEvent e) { - this.dragging = false; - if (addable) { - adding(e.getX(), e.getY()); - } else if (!selectionModel.getSelection().isEmpty()) { - selectionModel.releaseDragging(); - } - designer.repaint(); - } - - /** - *改变选择区域 - * - * @param e 鼠标事件 - */ - public void changeSelection(MouseEvent e) { - Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); - selectionModel.setHotspotBounds(bounds); - } - - /** - *返回鼠标所在的x、y 考虑滚动条的值 - * - * @param e 鼠标事件 - * @return xy值 - */ - public Point getMouseXY(MouseEvent e) { - Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() - + designer.getArea().getVerticalValue()); - return p1; - } - +package com.fr.design.designer.beans.models; + +import com.fr.design.beans.location.Absorptionline; +import com.fr.design.designer.beans.AdapterBus; +import com.fr.design.designer.beans.HoverPainter; +import com.fr.design.designer.beans.LayoutAdapter; +import com.fr.design.designer.beans.events.DesignerEvent; +import com.fr.design.designer.beans.location.Direction; +import com.fr.design.designer.beans.location.Location; +import com.fr.design.designer.creator.*; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.FormSelectionUtils; +import com.fr.design.utils.ComponentUtils; + +import java.awt.*; +import java.awt.event.MouseEvent; +import java.util.ArrayList; + +/** + * 普通模式下的状态model + */ +public class StateModel { + // 对应的selection model + + private SelectionModel selectionModel; + // 当前鼠标进入拖拽区域的位置类型 + private Direction driection; + + // 当前拖拽的起始位置 + private int currentX; + private int currentY; + + //拖拽组件原始位置大小备份 + private Rectangle selectedPositionBackup; + + private Point startPoint = new Point(); + private Point currentPoint = new Point(); + + private Absorptionline lineInX; + private Absorptionline lineInY; + //等距线 + private Absorptionline lineEquidistant; + + // 当前是否处于拖拽选择状态 + private boolean selecting; + private boolean dragging; + + private boolean addable; + + private FormDesigner designer; + + public StateModel(FormDesigner designer) { + this.designer = designer; + selectionModel = designer.getSelectionModel(); + } + + /** + * 返回direction + * + * @return direction方向 + */ + public Direction getDirection() { + return driection; + } + + /** + * 是否有组件正被选中 + * + * @return true 如果至少一个组件被选中 + */ + public boolean isSelecting() { + return selecting; + } + + /** + * 是否能拖拽 + * + * @return 非outer且选中为空 + */ + public boolean dragable() { + return ((driection != Location.outer) && !selecting); + } + + /** + * 拖拽中是否可以转换为添加模式: + * 如果拖拽组件只有一个,鼠标当前所在位置的最底层表单容器与这个组件的容器不同; + * 如果拖拽组件为多个,鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外,还必须是绝对定位布局 + */ + private void checkAddable(MouseEvent e) { + addable = false; + designer.setPainter(null); + + if (driection != Location.inner) { + return; + } + + XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); + XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); + XCreator creator = selectionModel.getSelection().getSelectedCreator(); + Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator); + if (creatorContainer != null && creatorContainer != container + && (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) { + HoverPainter painter = AdapterBus.getContainerPainter(designer, container); + designer.setPainter(painter); + 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(e.getX(), e.getY())); + painter.setCreator(creator); + } + addable = true; + } + } + + /** + * @param container 容器 + * @param mouseX 鼠标释放位置X + * @param mouseY 鼠标释放位置Y + * @return 是否成功 + */ + private boolean addBean(XLayoutContainer container, int mouseX, int mouseY) { + LayoutAdapter adapter = container.getLayoutAdapter(); + Rectangle rectangleContainer = ComponentUtils.getRelativeBounds(container); + if (selectionModel.getSelection().size() == 1) { + return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), + mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, + mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); + } + for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { + adapter.addBean(creator, + mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, + mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); + } + return true; + } + + /** + * @param mouseReleasedX 鼠标释放位置X + * @param mouseReleasedY 鼠标释放位置Y + */ + private void adding(int mouseReleasedX, int mouseReleasedY) { + // 当前鼠标所在的组件 + XCreator hoveredComponent = designer.getComponentAt(mouseReleasedX, mouseReleasedY, selectionModel.getSelection().getSelectedCreators()); + + // 获取该组件所在的焦点容器 + XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); + + boolean success = false; + + if (container != null) { + // 如果是容器,则调用其acceptComponent接受组件 + success = addBean(container, mouseReleasedX, mouseReleasedY); + } + + if (success) { + FormSelectionUtils.rebuildSelection(designer); + designer.getEditListenerTable().fireCreatorModified( + selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); + } else { + selectionModel.getSelection().setSelectionBounds(selectedPositionBackup, designer); + Toolkit.getDefaultToolkit().beep(); + } + // 取消提示 + designer.setPainter(null); + } + + /** + * 是否拖拽 + * + * @return dragging状态 + */ + public boolean isDragging() { + return dragging; + } + + /** + * 是否可以开始画线 + * + * @return startPoint不为空返回true + */ + public boolean prepareForDrawLining() { + return startPoint != null; + } + + /** + * 设置开始位置 + * + * @param p point位置 + */ + public void setStartPoint(Point p) { + this.startPoint = p; + } + + /** + * 返回开始位置 + * + * @return 点位置 + */ + public Point getStartPoint() { + return startPoint; + } + + /** + * 返回当前点位置 + * + * @return 点位置 + */ + public Point getEndPoint() { + return currentPoint; + } + + /** + * 当前选中组件 + * + * @param e 鼠标事件 + */ + public void startSelecting(MouseEvent e) { + selecting = true; + selectionModel.setHotspotBounds(new Rectangle()); + currentX = getMouseXY(e).x; + currentY = getMouseXY(e).y; + } + + /** + * 当前鼠标的xy + * + * @param e 鼠标事件 + */ + public void startResizing(MouseEvent e) { + if (!selectionModel.getSelection().isEmpty()) { + driection.backupBounds(designer); + } + currentX = getMouseXY(e).x; + currentY = getMouseXY(e).y; + } + + /** + * 起始点开始DrawLine + * + * @param p 点位置 + */ + public void startDrawLine(Point p) { + this.startPoint = p; + if (p != null) { + try { + designer.setCursor(XConnector.connectorCursor); + } catch (Exception e) { + } + } else { + designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + } + + /** + * 鼠标释放时所在的区域及圈中的组件 + * + * @param e 鼠标事件 + */ + public void selectCreators(MouseEvent e) { + int x = getMouseXY(e).x; + int y = getMouseXY(e).y; + + Rectangle bounds = createCurrentBounds(x, y); + + if ((x != currentX) || (y != currentY)) { + selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); + } + selectionModel.setHotspotBounds(null); + } + + /** + * 画所在区域线 + * + * @param e 鼠标事件 + */ + public void drawLine(MouseEvent e) { + designer.getDrawLineHelper().setDrawLine(true); + Point p = designer.getDrawLineHelper().getNearWidgetPoint(e); + if (p != null) { + currentPoint = p; + } else { + currentPoint.x = e.getX() + designer.getArea().getHorizontalValue(); + currentPoint.y = e.getY() + designer.getArea().getVerticalValue(); + } + } + + private Rectangle createCurrentBounds(int x, int y) { + Rectangle bounds = new Rectangle(); + + bounds.x = Math.min(x, currentX); + bounds.y = Math.min(y, currentY); + bounds.width = Math.max(x, currentX) - bounds.x; + bounds.height = Math.max(y, currentY) - bounds.y; + + return bounds; + } + + private ArrayList getHotspotCreators(Rectangle selection, XCreator root) { + ArrayList creators = new ArrayList<>(); + + if (!root.isVisible() && !designer.isRoot(root)) { + return creators; + } + + if (root instanceof XLayoutContainer) { + XLayoutContainer container = (XLayoutContainer) root; + int count = container.getXCreatorCount(); + Rectangle clipped = new Rectangle(selection); + + for (int i = count - 1; i >= 0; i--) { + XCreator child = container.getXCreator(i); + + if (selection.contains(child.getBounds())) { + creators.add(child); + } else { + clipped.x = selection.x - child.getX(); + clipped.y = selection.y - child.getY(); + creators.addAll(getHotspotCreators(clipped, child)); + } + } + } + + return creators; + } + + + /** + * 重置model + */ + public void resetModel() { + dragging = false; + selecting = false; + } + + /** + * 重置 + */ + public void reset() { + driection = Location.outer; + dragging = false; + selecting = false; + } + + /** + * 取消拖拽 + */ + public void draggingCancel() { + designer.repaint(); + reset(); + } + + /** + * 设置可拉伸方向 + * + * @param dir 拉伸方向 + */ + public void setDirection(Direction dir) { + if (driection != dir) { + this.driection = dir; + driection.updateCursor(designer); + } + } + + /** + * x吸附线赋值 + * + * @param line 线 + */ + public void setXAbsorptionline(Absorptionline line) { + this.lineInX = line; + } + + /** + * y吸附线赋值 + * + * @param line 线 + */ + public void setYAbsorptionline(Absorptionline line) { + this.lineInY = line; + } + + /** + * 等距线赋值 + * + * @param line 线 + */ + public void setEquidistantLine(Absorptionline line) { + this.lineEquidistant = line; + } + + /** + * 画吸附线 + * + * @param g Graphics类 + */ + public void paintAbsorptionline(Graphics g) { + if (lineInX != null) { + lineInX.paint(g, designer.getArea()); + } + if (lineInY != null) { + lineInY.paint(g, designer.getArea()); + } + if (lineEquidistant != null) { + lineEquidistant.paint(g, designer.getArea()); + } + } + + /** + * 拖拽 + * + * @param e 鼠标事件 + */ + public void dragging(MouseEvent e) { + //进入dragging状态时备份组件大小和位置 + if (!dragging) { + selectedPositionBackup = selectionModel.getSelection().getRelativeBounds(); + } + checkAddable(e); + setDependLinePainter(e); + driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer); + this.dragging = true; + } + + // 拖拽时画依附线用到的painter + private void setDependLinePainter(MouseEvent e) { + XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); + XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); + XCreator creator = selectionModel.getSelection().getSelectedCreator(); + HoverPainter painter = AdapterBus.getContainerPainter(designer, container); + designer.setPainter(painter); + if (painter != null) { + painter.setHotspot(new Point(e.getX(), e.getY())); + painter.setCreator(creator); + } + } + + /** + * 释放捕获 + * + * @param e 鼠标事件 + */ + public void releaseDragging(MouseEvent e) { + this.dragging = false; + if (addable) { + adding(e.getX(), e.getY()); + } else if (!selectionModel.getSelection().isEmpty()) { + selectionModel.releaseDragging(); + } + designer.repaint(); + } + + /** + * 改变选择区域 + * + * @param e 鼠标事件 + */ + public void changeSelection(MouseEvent e) { + Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); + selectionModel.setHotspotBounds(bounds); + } + + /** + * 返回鼠标所在的x、y 考虑滚动条的值 + * + * @param e 鼠标事件 + * @return xy值 + */ + public Point getMouseXY(MouseEvent e) { + Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() + + designer.getArea().getVerticalValue()); + return p1; + } + } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/beans/painters/AbstractPainter.java b/designer_form/src/com/fr/design/designer/beans/painters/AbstractPainter.java index 06565fe4f..fca5197ae 100644 --- a/designer_form/src/com/fr/design/designer/beans/painters/AbstractPainter.java +++ b/designer_form/src/com/fr/design/designer/beans/painters/AbstractPainter.java @@ -1,93 +1,96 @@ -package com.fr.design.designer.beans.painters; - -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Stroke; - -import com.fr.design.designer.beans.HoverPainter; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.form.util.XCreatorConstants; -import com.fr.general.Inter; - -public abstract class AbstractPainter implements HoverPainter { - - protected Point hotspot; - protected Rectangle hotspot_bounds; - protected XLayoutContainer container; - protected XCreator creator; - - /** - * 构造函数 - * @param container 容器 - */ - public AbstractPainter(XLayoutContainer container) { - this.container = container; - } - - @Override - public void setHotspot(Point p) { - hotspot = p; - } - - /** - * 画初始区域 - * @param g 画图类 - * @param startX 起始x位置 - * @param startY 起始y位置 - */ - public void paint(Graphics g, int startX, int startY) { - if(hotspot_bounds != null){ - drawHotspot(g, hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height, Color.lightGray, true, false); - } - } - - /** - * 设置边界 - * @param rect 位置 - */ - @Override - public void setRenderingBounds(Rectangle rect) { - hotspot_bounds = rect; - } - - @Override - public void setCreator(XCreator component) { - this.creator = component; - } - - protected void drawHotspot(Graphics g, int x, int y, int width, int height, boolean accept) { - Color bColor = accept ? XCreatorConstants.LAYOUT_HOTSPOT_COLOR : XCreatorConstants.LAYOUT_FORBIDDEN_COLOR; - drawHotspot(g, x, y, width, height, bColor, accept, false); - } - - /** - * 自适应布局那边渲染提示,要画整个背景,不是画边框 - */ - protected void drawRegionBackground(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept) { - drawHotspot(g, x, y, width, height, bColor, accept, true); - } - - protected void drawHotspot(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept, boolean drawBackground) { - Graphics2D g2d = (Graphics2D) g; - Color color = g2d.getColor(); - Stroke backup = g2d.getStroke(); - // 设置线条的样式 - g2d.setStroke(XCreatorConstants.STROKE); - g2d.setColor(bColor); - if (!accept) { - g2d.drawString(Inter.getLocText("Cannot-Add_To_This_Area") + "!", x + width / 3, y + height / 2); - } else if (drawBackground) { - g2d.fillRect(x, y, width, height); - } else { - g2d.drawRect(x, y, width, height); - } - g2d.setStroke(backup); - g2d.setColor(color); - } - - +package com.fr.design.designer.beans.painters; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Stroke; + +import com.fr.design.designer.beans.HoverPainter; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.form.util.XCreatorConstants; +import com.fr.general.Inter; + +public abstract class AbstractPainter implements HoverPainter { + + protected Point hotspot; + protected Rectangle hotspot_bounds; + protected XLayoutContainer container; + protected XCreator creator; + + /** + * 构造函数 + * + * @param container 容器 + */ + public AbstractPainter(XLayoutContainer container) { + this.container = container; + } + + @Override + public void setHotspot(Point p) { + hotspot = p; + } + + /** + * 画初始区域 + * + * @param g 画图类 + * @param startX 起始x位置 + * @param startY 起始y位置 + */ + public void paint(Graphics g, int startX, int startY) { + if (hotspot_bounds != null) { + drawHotspot(g, hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height, Color.lightGray, true, false); + } + } + + /** + * 设置边界 + * + * @param rect 位置 + */ + @Override + public void setRenderingBounds(Rectangle rect) { + hotspot_bounds = rect; + } + + @Override + public void setCreator(XCreator component) { + this.creator = component; + } + + protected void drawHotspot(Graphics g, int x, int y, int width, int height, boolean accept) { + Color bColor = accept ? XCreatorConstants.LAYOUT_HOTSPOT_COLOR : XCreatorConstants.LAYOUT_FORBIDDEN_COLOR; + drawHotspot(g, x, y, width, height, bColor, accept, false); + } + + /** + * 自适应布局那边渲染提示,要画整个背景,不是画边框 + */ + protected void drawRegionBackground(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept) { + drawHotspot(g, x, y, width, height, bColor, accept, true); + } + + protected void drawHotspot(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept, boolean drawBackground) { + Graphics2D g2d = (Graphics2D) g; + Color color = g2d.getColor(); + Stroke backup = g2d.getStroke(); + // 设置线条的样式 + g2d.setStroke(XCreatorConstants.STROKE); + g2d.setColor(bColor); + if (!accept) { + g2d.drawString(Inter.getLocText("Cannot-Add_To_This_Area") + "!", x + width / 3, y + height / 2); + } else if (drawBackground) { + g2d.fillRect(x, y, width, height); + } else { + g2d.drawRect(x, y, width, height); + } + g2d.setStroke(backup); + g2d.setColor(color); + } + + } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/creator/DedicateLayoutContainer.java b/designer_form/src/com/fr/design/designer/creator/DedicateLayoutContainer.java index 5b2f35c05..f223e5d8f 100644 --- a/designer_form/src/com/fr/design/designer/creator/DedicateLayoutContainer.java +++ b/designer_form/src/com/fr/design/designer/creator/DedicateLayoutContainer.java @@ -1,88 +1,96 @@ -/** - * - */ -package com.fr.design.designer.creator; - -import com.fr.form.ui.container.WLayout; - -import java.awt.*; -import java.beans.IntrospectionException; -import java.util.ArrayList; - -/** - * 一些控件专属的容器,如标题容器,sclae容器 - * @author jim - * @date 2014-11-7 - */ -public abstract class DedicateLayoutContainer extends XLayoutContainer { - - public DedicateLayoutContainer(WLayout widget, Dimension initSize) { - super(widget, initSize); - } - - /** - * 得到属性名 - * @return 属性名 - * @throws IntrospectionException - */ - public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { - return new CRPropertyDescriptor[0]; - } - - /** - * 返回容器图标 - * - * @return - */ - @Override - public String getIconPath() { - if(this.getXCreator(XWScaleLayout.INDEX) != null){ - return this.getXCreator(XWScaleLayout.INDEX).getIconPath(); - } - return "/com/fr/web/images/form/resources/text_field_16.png"; - } - - - /** - * 控件树不显示此组件 - * @param path 控件树list - */ - public void notShowInComponentTree(ArrayList path) { - path.remove(path.size()-1); - } - - /** - * 重置组件的名称 - * @param name 名称 - */ - public void resetCreatorName(String name) { - super.resetCreatorName(name); - XCreator child = getXCreator(XWScaleLayout.INDEX); - child.toData().setWidgetName(name); - } - - /** - * 返回对应属性表的组件,scale和title返回其子组件 - * @return 组件 - */ - public XCreator getPropertyDescriptorCreator() { - return getXCreator(XWScaleLayout.INDEX); - } - - /** - * 是否作为控件树的叶子节点 - * @return 是则返回true - */ - public boolean isComponentTreeLeaf() { - return true; - } - - /** - * 是否为sclae和title专属容器 - * @return 是则返回true - */ - public boolean isDedicateContainer() { - return true; - } - +/** + * + */ +package com.fr.design.designer.creator; + +import com.fr.form.ui.container.WLayout; + +import java.awt.*; +import java.beans.IntrospectionException; +import java.util.ArrayList; + +/** + * 一些控件专属的容器,如标题容器,sclae容器 + * + * @author jim + * @date 2014-11-7 + */ +public abstract class DedicateLayoutContainer extends XLayoutContainer { + + public DedicateLayoutContainer(WLayout widget, Dimension initSize) { + super(widget, initSize); + } + + /** + * 得到属性名 + * + * @return 属性名 + * @throws IntrospectionException + */ + public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { + return new CRPropertyDescriptor[0]; + } + + /** + * 返回容器图标 + * + * @return + */ + @Override + public String getIconPath() { + if (this.getXCreator(XWScaleLayout.INDEX) != null) { + return this.getXCreator(XWScaleLayout.INDEX).getIconPath(); + } + return "/com/fr/web/images/form/resources/text_field_16.png"; + } + + + /** + * 控件树不显示此组件 + * + * @param path 控件树list + */ + public void notShowInComponentTree(ArrayList path) { + path.remove(path.size() - 1); + } + + /** + * 重置组件的名称 + * + * @param name 名称 + */ + public void resetCreatorName(String name) { + super.resetCreatorName(name); + XCreator child = getXCreator(XWScaleLayout.INDEX); + //实现WTitleLayout的SetWidgetName + child.toData().setWidgetName(name); + } + + /** + * 返回对应属性表的组件,scale和title返回其子组件 + * + * @return 组件 + */ + public XCreator getPropertyDescriptorCreator() { + return getXCreator(XWScaleLayout.INDEX); + } + + /** + * 是否作为控件树的叶子节点 + * + * @return 是则返回true + */ + public boolean isComponentTreeLeaf() { + return true; + } + + /** + * 是否为sclae和title专属容器 + * + * @return 是则返回true + */ + public boolean isDedicateContainer() { + return true; + } + } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/creator/XChartEditor.java b/designer_form/src/com/fr/design/designer/creator/XChartEditor.java index 605532ab1..2ac2c12e3 100644 --- a/designer_form/src/com/fr/design/designer/creator/XChartEditor.java +++ b/designer_form/src/com/fr/design/designer/creator/XChartEditor.java @@ -85,6 +85,13 @@ public class XChartEditor extends XBorderStyleWidgetCreator { return new CRPropertyDescriptor[] { new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(Inter .getLocText("Form-Widget_Name")), + new CRPropertyDescriptor("visible", this.data.getClass()).setI18NName( + Inter.getLocText("FR-Designer_Widget-Visible")).setPropertyChangeListener(new PropertyChangeAdapter() { + + @Override + public void propertyChange() { + makeVisible(toData().isVisible());} + }), new CRPropertyDescriptor("borderStyle", this.data.getClass()).setEditorClass( WLayoutBorderStyleEditor.class).setI18NName( Inter.getLocText("Chart-Style_Name")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") 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 ba2a56ce0..4788bc8f3 100644 --- a/designer_form/src/com/fr/design/designer/creator/XCreator.java +++ b/designer_form/src/com/fr/design/designer/creator/XCreator.java @@ -379,6 +379,14 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo toData().setWidgetName(name); } + /** + * 重置组件的可见性 + * @param visible 可见性 + */ + public void resetVisible(boolean visible){ + toData().setVisible(visible); + } + /** * 返回编辑的子组件,scale为其内部组件 * @return 组件 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 aba6e9e3a..a23733f9d 100644 --- a/designer_form/src/com/fr/design/designer/creator/XElementCase.java +++ b/designer_form/src/com/fr/design/designer/creator/XElementCase.java @@ -10,7 +10,7 @@ import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.fun.impl.AbstractFormElementCaseEditorProvider; import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.*; -import com.fr.design.mainframe.widget.editors.BooleanEditor; +import com.fr.design.mainframe.widget.editors.ElementCaseToolBarEditor; import com.fr.design.mainframe.widget.editors.PaddingMarginEditor; import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; import com.fr.form.FormElementCaseContainerProvider; @@ -34,8 +34,8 @@ import java.beans.PropertyDescriptor; import java.util.Set; public class XElementCase extends XBorderStyleWidgetCreator implements FormElementCaseContainerProvider{ - private UILabel imageLable; - private CoverReportPane coverPanel; + private UILabel imageLable; + private CoverReportPane coverPanel; private FormDesigner designer; private static BufferedImage DEFAULT_BACKGROUND; @@ -62,23 +62,31 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme } /** - * 是否支持设置标题 - * @return 是返回true - */ - public boolean hasTitleStyle() { + * 是否支持设置标题 + * @return 是返回true + */ + public boolean hasTitleStyle() { return true; } - /** - * 返回组件属性值 - * @return 返回组件属性值 - * @throws IntrospectionException 异常 - */ + /** + * 返回组件属性值 + * @return 返回组件属性值 + * @throws IntrospectionException 异常 + */ public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { CRPropertyDescriptor[] propertyTableEditor = new CRPropertyDescriptor[]{ new CRPropertyDescriptor("widgetName", this.data.getClass()) .setI18NName(Inter.getLocText("Form-Widget_Name")), + new CRPropertyDescriptor("visible", this.data.getClass()).setI18NName( + Inter.getLocText("FR-Designer_Widget-Visible")).setPropertyChangeListener(new PropertyChangeAdapter() { + + @Override + public void propertyChange() { + makeVisible(toData().isVisible()); + } + }), new CRPropertyDescriptor("borderStyle", this.data.getClass()).setEditorClass( WLayoutBorderStyleEditor.class).setI18NName( Inter.getLocText("FR-Designer-Widget_Style")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") @@ -92,7 +100,7 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme new CRPropertyDescriptor("margin", this.data.getClass()).setEditorClass(PaddingMarginEditor.class) .setI18NName(Inter.getLocText("FR-Layout_Padding")) .putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), - new CRPropertyDescriptor("showToolBar", this.data.getClass()).setEditorClass(BooleanEditor.class) + new CRPropertyDescriptor("toolBars", this.data.getClass()).setEditorClass(ElementCaseToolBarEditor.class) .setI18NName(Inter.getLocText("Form-EC_toolbar")) .putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") }; @@ -139,30 +147,30 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme return "text_field_16.png"; } - /** - * 返回组件默认名 - * @return 组件类名(小写) - */ - public String createDefaultName() { - return "report"; - } + /** + * 返回组件默认名 + * @return 组件类名(小写) + */ + public String createDefaultName() { + return "report"; + } @Override protected JComponent initEditor() { if (editor == null) { setBorder(DEFALUTBORDER); - editor = new JPanel(); - editor.setBackground(null); - editor.setLayout(null); - imageLable = initImageBackground(); - - coverPanel = new CoverReportPane(); - coverPanel.setPreferredSize(imageLable.getPreferredSize()); - coverPanel.setBounds(imageLable.getBounds()); - - editor.add(coverPanel); - coverPanel.setVisible(false); - editor.add(imageLable); + editor = new JPanel(); + editor.setBackground(null); + editor.setLayout(null); + imageLable = initImageBackground(); + + coverPanel = new CoverReportPane(); + coverPanel.setPreferredSize(imageLable.getPreferredSize()); + coverPanel.setBounds(imageLable.getBounds()); + + editor.add(coverPanel); + coverPanel.setVisible(false); + editor.add(imageLable); } return editor; } @@ -178,7 +186,7 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme } setLabelBackground(image, imageLable); - return imageLable; + return imageLable; } /** @@ -187,16 +195,16 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme private void setLabelBackground(Image image, UILabel imageLable){ ImageIcon icon = new ImageIcon(image); imageLable.setIcon(icon); - imageLable.setOpaque(true); - imageLable.setLayout(null); - imageLable.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight()); + imageLable.setOpaque(true); + imageLable.setLayout(null); + imageLable.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight()); } - /** - * 是否展现覆盖的pane - * @param display 是否 - */ - public void displayCoverPane(boolean display){ + /** + * 是否展现覆盖的pane + * @param display 是否 + */ + public void displayCoverPane(boolean display){ coverPanel.setVisible(display); coverPanel.setBounds(1, 1, (int) editor.getBounds().getWidth(), (int) editor.getBounds().getHeight()); editor.repaint(); @@ -209,41 +217,41 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme coverPanel.destroyHelpDialog(); } - public JComponent getCoverPane(){ - return coverPanel; - } + public JComponent getCoverPane(){ + return coverPanel; + } - /** - * 初始化大小 - * @return 尺寸 - */ + /** + * 初始化大小 + * @return 尺寸 + */ public Dimension initEditorSize() { return BORDER_PREFERRED_SIZE; } - /** - * 是否是报表块 - * @return 是 - */ + /** + * 是否是报表块 + * @return 是 + */ public boolean isReport() { return true; } - /** - * 该组件是否可以拖入参数面板 - * @return 是则返回true - */ - public boolean canEnterIntoParaPane(){ - return false; - } - - /** - * 返回报表块对应的widget - * @return 返回ElementCaseEditor - */ - public ElementCaseEditor toData() { - return ((ElementCaseEditor) data); - } + /** + * 该组件是否可以拖入参数面板 + * @return 是则返回true + */ + public boolean canEnterIntoParaPane(){ + return false; + } + + /** + * 返回报表块对应的widget + * @return 返回ElementCaseEditor + */ + public ElementCaseEditor toData() { + return ((ElementCaseEditor) data); + } public FormElementCaseProvider getElementCase() { return toData().getElementCase(); @@ -286,14 +294,14 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme } - private void switchTab(MouseEvent e,EditingMouseListener editingMouseListener){ - FormDesigner designer = editingMouseListener.getDesigner(); - if (e.getClickCount() == 2 || designer.getCursor().getType() == Cursor.HAND_CURSOR){ - FormElementCaseContainerProvider component = (FormElementCaseContainerProvider) designer.getComponentAt(e); - //切换设计器 - designer.switchTab(component); - } - } + private void switchTab(MouseEvent e,EditingMouseListener editingMouseListener){ + FormDesigner designer = editingMouseListener.getDesigner(); + if (e.getClickCount() == 2 || designer.getCursor().getType() == Cursor.HAND_CURSOR){ + FormElementCaseContainerProvider component = (FormElementCaseContainerProvider) designer.getComponentAt(e); + //切换设计器 + designer.switchTab(component); + } + } @Override public WidgetPropertyUIProvider[] getWidgetPropertyUIProviders() { diff --git a/designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java b/designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java index 254e9a918..edd1c69f0 100644 --- a/designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java +++ b/designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java @@ -30,12 +30,12 @@ import java.util.List; * @since 6.5.3 */ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator implements ContainerListener, ParameterBridge { - - // 布局内部组件默认最小宽度36,最小高度21 - public static int MIN_WIDTH = 36; - public static int MIN_HEIGHT = 21; - - protected static final Dimension LARGEPREFERREDSIZE = new Dimension(200, 200); + + // 布局内部组件默认最小宽度36,最小高度21 + public static int MIN_WIDTH = 36; + public static int MIN_HEIGHT = 21; + + protected static final Dimension LARGEPREFERREDSIZE = new Dimension(200, 200); protected boolean isRefreshing; protected int default_Length = 5; // 取指定点坐在的组件,默认为5保证取四侧相邻的组件时x、y在组件内非边框上 @@ -45,6 +45,7 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme protected boolean editable = false; //鼠标移动到布局画出编辑层 protected boolean isMouseEnter = false; + public void setMouseEnter(boolean mouseEnter) { isMouseEnter = mouseEnter; } @@ -55,12 +56,13 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme } /** - * 得到属性名 + * 得到属性名 + * * @return 属性名 * @throws IntrospectionException */ - public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { - return new CRPropertyDescriptor[] { + public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { + return new CRPropertyDescriptor[]{ new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(Inter .getLocText("FR-Designer_Form-Widget_Name")), new CRPropertyDescriptor("borderStyle", this.data.getClass()).setEditorClass( @@ -68,19 +70,20 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme Inter.getLocText("FR-Engine_Style")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") .setPropertyChangeListener(new PropertyChangeAdapter() { - @Override - public void propertyChange() { - initStyle(); - } - }), + @Override + public void propertyChange() { + initStyle(); + } + }), new CRPropertyDescriptor("margin", this.data.getClass()).setEditorClass(PaddingMarginEditor.class) .setI18NName(Inter.getLocText("FR-Designer_Layout-Padding")) .putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), - }; - } + }; + } /** * 控件名属性 + * * @return * @throws IntrospectionException */ @@ -91,6 +94,7 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme /** * 边距属性 + * * @return * @throws IntrospectionException */ @@ -101,47 +105,50 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme } /** - * 返回对应的wlayout + * 返回对应的wlayout + * * @return wlayout控件 */ public WLayout toData() { return (WLayout) data; } - @Override - protected void initXCreatorProperties() { - super.initXCreatorProperties(); - initBorderStyle(); - this.initLayoutManager(); - this.convert(); - } + @Override + protected void initXCreatorProperties() { + super.initXCreatorProperties(); + initBorderStyle(); + this.initLayoutManager(); + this.convert(); + } @Override - protected JComponent initEditor() { - return this; - } - - /** - * 当前组件zorder位置替换新的控件 - * @param widget 控件 - * @param oldcreator 旧组件 - * @return 组件 - */ - public XCreator replace(Widget widget, XCreator oldcreator) { - int i = this.getComponentZOrder(oldcreator); - if (i != -1) { - this.toData().replace(widget, oldcreator.toData()); - this.convert(); - XCreator creator = (XCreator) this.getComponent(i); - creator.setSize(oldcreator.getSize()); - return creator; - } - return null; - } - - /** - * 初始化时默认的组件大小 - * @return 默认Dimension + protected JComponent initEditor() { + return this; + } + + /** + * 当前组件zorder位置替换新的控件 + * + * @param widget 控件 + * @param oldcreator 旧组件 + * @return 组件 + */ + public XCreator replace(Widget widget, XCreator oldcreator) { + int i = this.getComponentZOrder(oldcreator); + if (i != -1) { + this.toData().replace(widget, oldcreator.toData()); + this.convert(); + XCreator creator = (XCreator) this.getComponent(i); + creator.setSize(oldcreator.getSize()); + return creator; + } + return null; + } + + /** + * 初始化时默认的组件大小 + * + * @return 默认Dimension */ public Dimension initEditorSize() { return LARGEPREFERREDSIZE; @@ -172,7 +179,8 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme /** * 设计界面中有组件添加时,要通知WLayout容器重新paint - * @param e 待说明 + * + * @param e 待说明 */ @Override public void componentAdded(ContainerEvent e) { @@ -188,7 +196,8 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme /** * 设计界面中有组件添加时,要通知WLayout容器重新paint - * @param e 待说明 + * + * @param e 待说明 */ @Override public void componentRemoved(ContainerEvent e) { @@ -203,6 +212,7 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme /** * 根据widget的属性值来获取 + * * @param wgt * @return */ @@ -226,30 +236,32 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme public int getXCreatorCount() { return getComponentCount(); } - + public XCreator getXCreator(int i) { return (XCreator) getComponent(i); } /** * 该组件是否可以拖入参数面板 + * * @return 是则返回true */ - public boolean canEnterIntoParaPane(){ + public boolean canEnterIntoParaPane() { return false; } - + /** - * 是否作为控件树的叶子节点 - * @return 是则返回true - */ - public boolean isComponentTreeLeaf() { - return false; - } + * 是否作为控件树的叶子节点 + * + * @return 是则返回true + */ + public boolean isComponentTreeLeaf() { + return false; + } - public List getAllXCreatorNameList(XCreator xCreator, List namelist){ - for (int i = 0; i < ((XLayoutContainer)xCreator).getXCreatorCount(); i++) { - XCreator creatorSon = ((XLayoutContainer)xCreator).getXCreator(i); + public List getAllXCreatorNameList(XCreator xCreator, List namelist) { + for (int i = 0; i < ((XLayoutContainer) xCreator).getXCreatorCount(); i++) { + XCreator creatorSon = ((XLayoutContainer) xCreator).getXCreator(i); creatorSon.getAllXCreatorNameList(creatorSon, namelist); } return namelist; @@ -257,19 +269,20 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme /** * 是否有查询按钮 - * @param xCreator 控件或容器 - * @return 有无查询按钮 + * + * @param xCreator 控件或容器 + * @return 有无查询按钮 */ public boolean SearchQueryCreators(XCreator xCreator) { - for (int i = 0; i < ((XLayoutContainer)xCreator).getXCreatorCount(); i++) { - XCreator creatorSon = ((XLayoutContainer)xCreator).getXCreator(i); - if(creatorSon.SearchQueryCreators(creatorSon)){ + for (int i = 0; i < ((XLayoutContainer) xCreator).getXCreatorCount(); i++) { + XCreator creatorSon = ((XLayoutContainer) xCreator).getXCreator(i); + if (creatorSon.SearchQueryCreators(creatorSon)) { return true; } } return false; } - + public FRLayoutManager getFRLayout() { LayoutManager layout = getLayout(); if (layout instanceof FRLayoutManager) { @@ -279,111 +292,120 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme return null; } - public abstract LayoutAdapter getLayoutAdapter(); - - public int getIndexOfChild(Object child) { - int count = getComponentCount(); - for (int i = 0; i < count; i++) { - Component comp = getComponent(i); - if (comp == child) { - return i; - } - } - return -1; - } - - /** - * 主要为自适应用 - * 返回指定point的上方组件 - * @param x x位置 - * @param y y位置 - * @return 指定位置的组件 - */ - public Component getTopComp(int x, int y) { - return this.getComponentAt(x, y-default_Length); - } - - /** - * 主要为自适应用 - * 返回指定point的左方组件 - * @param x x位置 - * @param y y位置 - * @return 指定位置的组件 - */ - public Component getLeftComp(int x, int y) { - return this.getComponentAt(x-default_Length, y); - } - - /** - * 返回指定point的右方组件 - * @param x x位置 - * @param y y位置 - * @param w 宽度 - * @return 指定位置的组件 - */ - public Component getRightComp(int x, int y, int w) { - return this.getComponentAt(x+w+default_Length, y); - } - - /** - * 返回指定point的下方组件 - * @param x x位置 - * @param y y位置 - * @param h 高度 - * @return 指定位置的组件 - */ - public Component getBottomComp(int x, int y, int h) { - return this.getComponentAt(x, y+h+default_Length); - } - - /** - * 返回指定point的上方且是右侧的组件 - * @param x x位置 - * @param y y位置 - * @param w 宽度 - * @return 指定位置的组件 - */ - public Component getRightTopComp(int x, int y, int w) { - return this.getComponentAt(x+w-default_Length, y-default_Length); - } - - /** - * 返回指定point的左方且是下侧的组件 - * @param x x位置 - * @param y y位置 - * @param h 高度 - * @return 指定位置的组件 - */ - public Component getBottomLeftComp(int x, int y, int h) { - return this.getComponentAt(x-default_Length, y+h-default_Length); - } - - /** - * 返回指定point的右方且是下侧的组件 - * @param x x位置 - * @param y y位置 - * @param h 高度 - * @param w 宽度 - * @return 指定位置的组件 - */ - public Component getBottomRightComp(int x, int y, int h, int w) { - return this.getComponentAt(x+w+default_Length, y+h-default_Length); - } - - /** - * 返回指定point的下方且是右侧的组件 - * @param x x位置 - * @param y y位置 - * @param h 高度 - * @param w 宽度 - * @return 指定位置的组件 - */ - public Component getRightBottomComp(int x, int y, int h, int w) { - return this.getComponentAt(x+w-default_Length, y+h+default_Length); - } + public abstract LayoutAdapter getLayoutAdapter(); + + public int getIndexOfChild(Object child) { + int count = getComponentCount(); + for (int i = 0; i < count; i++) { + Component comp = getComponent(i); + if (comp == child) { + return i; + } + } + return -1; + } + + /** + * 主要为自适应用 + * 返回指定point的上方组件 + * + * @param x x位置 + * @param y y位置 + * @return 指定位置的组件 + */ + public Component getTopComp(int x, int y) { + return this.getComponentAt(x, y - default_Length); + } + + /** + * 主要为自适应用 + * 返回指定point的左方组件 + * + * @param x x位置 + * @param y y位置 + * @return 指定位置的组件 + */ + public Component getLeftComp(int x, int y) { + return this.getComponentAt(x - default_Length, y); + } + + /** + * 返回指定point的右方组件 + * + * @param x x位置 + * @param y y位置 + * @param w 宽度 + * @return 指定位置的组件 + */ + public Component getRightComp(int x, int y, int w) { + return this.getComponentAt(x + w + default_Length, y); + } + + /** + * 返回指定point的下方组件 + * + * @param x x位置 + * @param y y位置 + * @param h 高度 + * @return 指定位置的组件 + */ + public Component getBottomComp(int x, int y, int h) { + return this.getComponentAt(x, y + h + default_Length); + } + + /** + * 返回指定point的上方且是右侧的组件 + * + * @param x x位置 + * @param y y位置 + * @param w 宽度 + * @return 指定位置的组件 + */ + public Component getRightTopComp(int x, int y, int w) { + return this.getComponentAt(x + w - default_Length, y - default_Length); + } + + /** + * 返回指定point的左方且是下侧的组件 + * + * @param x x位置 + * @param y y位置 + * @param h 高度 + * @return 指定位置的组件 + */ + public Component getBottomLeftComp(int x, int y, int h) { + return this.getComponentAt(x - default_Length, y + h - default_Length); + } + + /** + * 返回指定point的右方且是下侧的组件 + * + * @param x x位置 + * @param y y位置 + * @param h 高度 + * @param w 宽度 + * @return 指定位置的组件 + */ + public Component getBottomRightComp(int x, int y, int h, int w) { + return this.getComponentAt(x + w + default_Length, y + h - default_Length); + } + + /** + * 返回指定point的下方且是右侧的组件 + * + * @param x x位置 + * @param y y位置 + * @param h 高度 + * @param w 宽度 + * @return 指定位置的组件 + */ + public Component getRightBottomComp(int x, int y, int h, int w) { + return this.getComponentAt(x + w - default_Length, y + h + default_Length); + } /** * 是否延迟展示报表内容,也就是说是否要等点击了查询之后才执行报表 + * * @return 如果是true,则表示点击之后才开始计算,false则表示会根据参数默认值直接计算报表并展现 */ public boolean isDelayDisplayContent() { @@ -392,18 +414,20 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme /** * 是否显示参数界面 + * * @return 显示参数界面则返回true,否则返回false */ public boolean isDisplay() { return false; } - public Background getDataBackground(){ + public Background getDataBackground() { return toData().getBackground(); } /** * 获取参数界面的宽度 + * * @return 宽度 */ public int getDesignWidth() { @@ -412,83 +436,82 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme /** * 获取参数面板的对齐方式 + * * @return 左中右三种对齐方式 */ public int getPosition() { return 0; } - + /** * 切换到非添加状态 - * + * * @param designer 表单设计器 */ - public void stopAddingState(FormDesigner designer){ - return; - } - - /** - * 寻找最近的为自适应布局的父容器 - * - * @return 布局容器 - * - * - * @date 2014-12-30-下午3:15:28 - * - */ - public XLayoutContainer findNearestFit(){ - //一层一层网上找, 找到最近的fit那一层就return - XLayoutContainer parent = this.getBackupParent(); - return parent == null ? null : parent.findNearestFit(); - } - + public void stopAddingState(FormDesigner designer) { + } + + /** + * 寻找最近的为自适应布局的父容器 + * + * @return 布局容器 + * @date 2014-12-30-下午3:15:28 + */ + public XLayoutContainer findNearestFit() { + //一层一层网上找, 找到最近的fit那一层就return + XLayoutContainer parent = this.getBackupParent(); + return parent == null ? null : parent.findNearestFit(); + } + /** * 获取容器所有内部组件横坐标值 - * + * * @return 横坐标数组 */ - public int[] getHors(){ - return ArrayUtils.EMPTY_INT_ARRAY; + public int[] getHors() { + return ArrayUtils.EMPTY_INT_ARRAY; } - + /** * 获取容器所有内部组件纵坐标值 - * + * * @return 纵坐标数组 */ - public int[] getVeris(){ - return ArrayUtils.EMPTY_INT_ARRAY; + public int[] getVeris() { + return ArrayUtils.EMPTY_INT_ARRAY; } - public void setDelayDisplayContent(boolean delayPlaying){ + public void setDelayDisplayContent(boolean delayPlaying) { } - public void setPosition(int align){ + public void setPosition(int align) { } - public void setDisplay(boolean showWindow){ + public void setDisplay(boolean showWindow) { } - public void setBackground(Background background){ + public void setBackground(Background background) { } /** * 布局是否可编辑,不可则显示编辑蒙层 + * * @return 可否编辑 */ - public boolean isEditable(){ + public boolean isEditable() { return this.editable; } /** * 设置布局是否可编辑,不可则显示编辑蒙层 + * * @param isEditable 可否编辑 */ - public void setEditable(boolean isEditable){ + public void setEditable(boolean isEditable) { this.editable = isEditable; } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java b/designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java index 06ae6fa78..852cdf122 100644 --- a/designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java @@ -3,44 +3,34 @@ */ package com.fr.design.designer.creator; -import java.awt.*; -import java.awt.event.ContainerEvent; -import java.awt.event.MouseEvent; -import java.awt.image.BufferedImage; -import java.beans.IntrospectionException; -import java.util.ArrayList; -import java.util.HashMap; - import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.ComponentAdapter; import com.fr.design.designer.beans.LayoutAdapter; -import com.fr.design.designer.beans.adapters.layout.AbsoluteLayoutAdapter; import com.fr.design.designer.beans.adapters.layout.FRAbsoluteLayoutAdapter; import com.fr.design.designer.beans.location.Direction; import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.form.layout.FRAbsoluteLayout; -import com.fr.design.form.util.XCreatorConstants; -import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.icon.IconPathConstants; -import com.fr.design.mainframe.*; -import com.fr.design.mainframe.widget.editors.PaddingMarginEditor; -import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; -import com.fr.design.mainframe.widget.renderer.LayoutBorderStyleRenderer; -import com.fr.design.mainframe.widget.renderer.PaddingMarginCellRenderer; +import com.fr.design.mainframe.EditingMouseListener; +import com.fr.design.mainframe.FormArea; +import com.fr.design.mainframe.FormDesigner; import com.fr.form.ui.Connector; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; -import com.fr.form.ui.container.WFitLayout; import com.fr.form.ui.container.WLayout; import com.fr.general.FRScreen; import com.fr.general.IOUtils; import com.fr.general.Inter; -import com.fr.stable.core.PropertyChangeAdapter; -import org.eclipse.swt.internal.gdip.Rect; -import javax.swing.*; +import java.awt.*; +import java.awt.event.ContainerEvent; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import java.beans.IntrospectionException; +import java.util.ArrayList; +import java.util.HashMap; /** * @author richer @@ -48,322 +38,343 @@ import javax.swing.*; */ public class XWAbsoluteLayout extends XLayoutContainer { - private static final int EDIT_BTN_WIDTH = 60; - private static final int EDIT_BTN_HEIGHT = 24; - private int minWidth = WLayout.MIN_WIDTH; - private int minHeight = WLayout.MIN_HEIGHT; - - //由于屏幕分辨率不同,界面上的容器大小可能不是默认的100%,此时拖入组件时,保存的大小按照100%时的计算 - protected double containerPercent = 1.0; - - private HashMap xConnectorMap; - - public XWAbsoluteLayout() { - this(new WAbsoluteLayout(),new Dimension()); - } - - public XWAbsoluteLayout(WAbsoluteLayout widget) { - this(widget,new Dimension()); - } - - public XWAbsoluteLayout(WAbsoluteLayout widget, Dimension initSize) { - super(widget, initSize); - this.xConnectorMap = new HashMap(); - Connector connector; - for (int i = 0; i < widget.connectorCount(); i++) { - connector = widget.getConnectorIndex(i); - xConnectorMap.put(connector, new XConnector(connector, this)); - } - - initPercent(widget); - } - - /** - * 初始化时默认的组件大小 - * - * @return 默认Dimension - */ - @Override - public Dimension initEditorSize() { - return new Dimension(500, 300); - } - - //根据屏幕大小来确定显示的百分比, 1440*900默认100%, 1366*768缩放90% - private void initPercent(WAbsoluteLayout widget){ - Toolkit toolkit = Toolkit.getDefaultToolkit(); - Dimension scrnsize = toolkit.getScreenSize(); - double screenValue = FRScreen.getByDimension(scrnsize).getValue(); - if(screenValue != FormArea.DEFAULT_SLIDER){ - this.setContainerPercent(screenValue / FormArea.DEFAULT_SLIDER); - } - } - - /** - * 返回容器大小的百分比 - * @return the containerPercent - */ - public double getContainerPercent() { - return containerPercent; - } - - /** - * 设置容器大小的百分比 - * @param containerPercent the containerPercent to set - */ - public void setContainerPercent(double containerPercent) { - this.containerPercent = containerPercent; - minWidth = (int) (XWAbsoluteLayout.MIN_WIDTH*containerPercent); - minHeight = (int) (XWAbsoluteLayout.MIN_HEIGHT*containerPercent); - } - - /** - * 返回界面处根据百分比调整后的最小宽度 - * @return 最小宽度 - */ - public int getActualMinWidth() { - return this.minWidth; - } - - /** - * 返回界面处根据百分比调整后的最小高度 - * @return 最小高度 - */ - public int getActualMinHeight() { - return this.minHeight; - } - - /** - * 返回界面处根据百分比调整后的间隔大小(且为偶数) - * @return 间隔 - */ - public int getAcualInterval() { - // adapter那边交叉三等分、删除都要判断是否对齐,所以间隔转为偶数 - int interval = (int) (toData().getCompInterval()*containerPercent); - int val = interval/2; - return val*2; - } - - /** - * 界面容器大小不是默认的时,处理控件的BoundsWidget,且避免出现空隙 - */ - private Rectangle dealWidgetBound(Rectangle rec) { - if (containerPercent == 1.0) { - return rec; - } - rec.x = (int) (rec.x/containerPercent); - rec.y = (int) (rec.y/containerPercent); - rec.width = (int) (rec.width/containerPercent); - rec.height = (int) (rec.height/containerPercent); - return rec; - } - - /** - * 新增删除拉伸后单个组件的BoundsWidget - */ - public void updateBoundsWidget(XCreator xCreator) { - WAbsoluteLayout layout = this.toData(); - if (xCreator.hasTitleStyle()) { - xCreator = (XLayoutContainer)xCreator.getParent(); - } - if (xCreator.acceptType(XWAbsoluteLayout.class)){ - ((XWAbsoluteLayout) xCreator).updateBoundsWidget(); - } - BoundsWidget boundsWidget = layout.getBoundsWidget(xCreator.toData()); - Rectangle rectangle = dealWidgetBound(xCreator.getBounds()); - } - - private Rectangle calculateBound(Rectangle rec, double pw, double ph){ - Rectangle calRec = new Rectangle(0,0,0,0); - calRec.x = (int)(rec.x / pw); - calRec.y = (int)(rec.y / ph); - calRec.width = (int)(rec.width / pw); - calRec.height = (int)(rec.height / ph); - return calRec; - } - - /** - * 新增删除拉伸后每个组件的BoundsWidget - */ - public void updateBoundsWidget() { - WAbsoluteLayout layout = this.toData(); - Rectangle backupBound = this.getBackupBound(); - Rectangle currentBound = this.getBounds(); - if (backupBound != null && layout.getCompState() == WAbsoluteLayout.STATE_FIT) { - double percentW = ((double) backupBound.width / (double) currentBound.width); - double percentH = ((double) backupBound.height / (double) currentBound.height); - for (int index = 0, n = this.getComponentCount(); index < n; index++){ - XCreator creator = (XCreator) this.getComponent(index); - BoundsWidget wgt = layout.getBoundsWidget(creator.toData()); - // 用当前的显示大小计算后调正具体位置 - Rectangle wgtBound = creator.getBounds(); - Rectangle rec = calculateBound(wgtBound, percentW, percentH); - wgt.setBounds(rec); - creator.setBounds(rec); - //绝对布局嵌套,要更新内部的绝对布局 - if (creator.acceptType(XWAbsoluteLayout.class)){ - creator.setBackupBound(wgtBound); - ((XWAbsoluteLayout) creator).updateBoundsWidget(); - } - } - } - } - - /** - * 更新子组件的Bound - * 这边主要用于绝对布局子组件在适应区域选项时 - * 涉及到的不同分辨率下缩放 - * @param minHeight 最小高度 - */ - @Override - public void updateChildBound(int minHeight) { - double prevContainerPercent = FRScreen.getByDimension(toData().getDesigningResolution()).getValue() / FormArea.DEFAULT_SLIDER; - if (toData().getCompState() == 0 && prevContainerPercent != containerPercent) { - for (int i = 0; i < this.getComponentCount(); i++) { - XCreator creator = getXCreator(i); - Rectangle rec = new Rectangle(creator.getBounds()); - rec.x = (int)(rec.x / prevContainerPercent * containerPercent); - rec.y = (int)(rec.y / prevContainerPercent * containerPercent); - rec.height = (int)(rec.height / prevContainerPercent * containerPercent); - rec.width = (int)(rec.width / prevContainerPercent * containerPercent); - BoundsWidget wgt = toData().getBoundsWidget(creator.toData()); - wgt.setBounds(rec); - creator.setBounds(rec); - creator.updateChildBound(minHeight); - } - } - toData().setDesigningResolution(Toolkit.getDefaultToolkit().getScreenSize()); - } - - /** - * 增加对齐线 - * @param connector 对齐线 - */ - public void addConnector(Connector connector) { - xConnectorMap.put(connector, new XConnector(connector, this)); - ((WAbsoluteLayout) data).addConnector(connector); - } - - public XConnector getXConnector(Connector connector) { - return xConnectorMap.get(connector); - } - - /** - * 去除对齐线 - * @param connector 对齐线 - */ - public void removeConnector(Connector connector) { - ((WAbsoluteLayout) data).removeConnector(connector); - xConnectorMap.remove(connector); - } - - /** - * 返回对应的widget容器 - * @return 返回WAbsoluteLayout - */ - @Override - public WAbsoluteLayout toData() { - return (WAbsoluteLayout) data; - } - - @Override - protected String getIconName() { - return "layout_absolute_new.png"; - } - - /** - * 返回默认的容器name - * @return 返回绝对布局容器名 - */ - @Override - public String createDefaultName() { - return "absolute"; - } - - @Override - protected void initLayoutManager() { - this.setLayout(new FRAbsoluteLayout()); - } - - /** - * 是否支持标题样式 - * - * @return 默认false - */ - @Override - public boolean hasTitleStyle() { - return false; - } - - @Override - public void paintComponent(Graphics g) { - super.paintComponent(g); - WAbsoluteLayout layout = (WAbsoluteLayout) data; - Connector[] connector = layout.getConnector(); - for (int i = 0, size = connector.length; i < size; i++) { - connector[i].draw(g); - } - } - - /** - * 转换保存组件信息的wlayout为对应的container - */ - @Override - public void convert() { - isRefreshing = true; - WAbsoluteLayout abs = toData(); - this.removeAll(); - for (int i = 0, count = abs.getWidgetCount(); i < count; i++) { - BoundsWidget bw = (BoundsWidget)abs.getWidget(i); - if (bw != null) { - Rectangle bounds = bw.getBounds(); - XWidgetCreator comp = (XWidgetCreator)XCreatorUtils.createXCreator(bw.getWidget()); - if (!comp.acceptType(XWParameterLayout.class)) { - comp.setDirections(Direction.ALL); - } - add(comp); - comp.setBounds(bounds); - } - } - isRefreshing = false; - } - - /** - * 当前组件zorder位置替换新的控件 - * @param widget 控件 - * @param oldcreator 旧组件 - * @return 组件 - */ - @Override - public XCreator replace(Widget widget, XCreator oldcreator) { - int i = this.getComponentZOrder(oldcreator); - if (i != -1) { - this.toData().replace(new BoundsWidget(widget, oldcreator.getBounds()), - new BoundsWidget(oldcreator.toData(), oldcreator.getBounds())); - this.convert(); - return (XCreator) this.getComponent(i); - } - return null; - } - - /** + private static final int EDIT_BTN_WIDTH = 60; + private static final int EDIT_BTN_HEIGHT = 24; + private int minWidth = WLayout.MIN_WIDTH; + private int minHeight = WLayout.MIN_HEIGHT; + + //由于屏幕分辨率不同,界面上的容器大小可能不是默认的100%,此时拖入组件时,保存的大小按照100%时的计算 + protected double containerPercent = 1.0; + + private HashMap xConnectorMap; + + public XWAbsoluteLayout() { + this(new WAbsoluteLayout(), new Dimension()); + } + + public XWAbsoluteLayout(WAbsoluteLayout widget) { + this(widget, new Dimension()); + } + + public XWAbsoluteLayout(WAbsoluteLayout widget, Dimension initSize) { + super(widget, initSize); + this.xConnectorMap = new HashMap(); + Connector connector; + for (int i = 0; i < widget.connectorCount(); i++) { + connector = widget.getConnectorIndex(i); + xConnectorMap.put(connector, new XConnector(connector, this)); + } + + initPercent(widget); + } + + /** + * 初始化时默认的组件大小 + * + * @return 默认Dimension + */ + @Override + public Dimension initEditorSize() { + return new Dimension(500, 300); + } + + //根据屏幕大小来确定显示的百分比, 1440*900默认100%, 1366*768缩放90% + private void initPercent(WAbsoluteLayout widget) { + Toolkit toolkit = Toolkit.getDefaultToolkit(); + Dimension scrnsize = toolkit.getScreenSize(); + double screenValue = FRScreen.getByDimension(scrnsize).getValue(); + if (screenValue != FormArea.DEFAULT_SLIDER) { + this.setContainerPercent(screenValue / FormArea.DEFAULT_SLIDER); + } + } + + /** + * 返回容器大小的百分比 + * + * @return the containerPercent + */ + public double getContainerPercent() { + return containerPercent; + } + + /** + * 设置容器大小的百分比 + * + * @param containerPercent the containerPercent to set + */ + public void setContainerPercent(double containerPercent) { + this.containerPercent = containerPercent; + minWidth = (int) (XWAbsoluteLayout.MIN_WIDTH * containerPercent); + minHeight = (int) (XWAbsoluteLayout.MIN_HEIGHT * containerPercent); + } + + /** + * 返回界面处根据百分比调整后的最小宽度 + * + * @return 最小宽度 + */ + public int getActualMinWidth() { + return this.minWidth; + } + + /** + * 返回界面处根据百分比调整后的最小高度 + * + * @return 最小高度 + */ + public int getActualMinHeight() { + return this.minHeight; + } + + /** + * 返回界面处根据百分比调整后的间隔大小(且为偶数) + * + * @return 间隔 + */ + public int getAcualInterval() { + // adapter那边交叉三等分、删除都要判断是否对齐,所以间隔转为偶数 + int interval = (int) (toData().getCompInterval() * containerPercent); + int val = interval / 2; + return val * 2; + } + + /** + * 界面容器大小不是默认的时,处理控件的BoundsWidget,且避免出现空隙 + */ + private Rectangle dealWidgetBound(Rectangle rec) { + if (containerPercent == 1.0) { + return rec; + } + rec.x = (int) (rec.x / containerPercent); + rec.y = (int) (rec.y / containerPercent); + rec.width = (int) (rec.width / containerPercent); + rec.height = (int) (rec.height / containerPercent); + return rec; + } + + /** + * 新增删除拉伸后单个组件的BoundsWidget + */ + public void updateBoundsWidget(XCreator xCreator) { + WAbsoluteLayout layout = this.toData(); + if (xCreator.hasTitleStyle()) { + xCreator = (XLayoutContainer) xCreator.getParent(); + } + if (xCreator.acceptType(XWAbsoluteLayout.class)) { + ((XWAbsoluteLayout) xCreator).updateBoundsWidget(); + } + // 如果子组件时tab布局,则tab布局内部的组件的wiget也要更新,否则保存后重新打开大小不对 + ArrayList childrenList = xCreator.getTargetChildrenList(); + if (!childrenList.isEmpty()) { + for (int i = 0; i < childrenList.size(); i++) { + XWTabFitLayout tabLayout = (XWTabFitLayout) childrenList.get(i); + tabLayout.updateBoundsWidget(); + } + } + BoundsWidget boundsWidget = (BoundsWidget) layout.getBoundsWidget(xCreator.toData()); + Rectangle rectangle = dealWidgetBound(xCreator.getBounds()); + } + + private Rectangle calculateBound(Rectangle rec, double pw, double ph) { + Rectangle calRec = new Rectangle(0, 0, 0, 0); + calRec.x = (int) (rec.x / pw); + calRec.y = (int) (rec.y / ph); + calRec.width = (int) (rec.width / pw); + calRec.height = (int) (rec.height / ph); + return calRec; + } + + /** + * 新增删除拉伸后每个组件的BoundsWidget + */ + public void updateBoundsWidget() { + WAbsoluteLayout layout = this.toData(); + Rectangle backupBound = this.getBackupBound(); + Rectangle currentBound = this.getBounds(); + if (backupBound != null && layout.getCompState() == WAbsoluteLayout.STATE_FIT) { + double percentW = ((double) backupBound.width / (double) currentBound.width); + double percentH = ((double) backupBound.height / (double) currentBound.height); + for (int index = 0, n = this.getComponentCount(); index < n; index++) { + XCreator creator = (XCreator) this.getComponent(index); + BoundsWidget wgt = (BoundsWidget) layout.getBoundsWidget(creator.toData()); + // 用当前的显示大小计算后调正具体位置 + Rectangle wgtBound = creator.getBounds(); + Rectangle rec = calculateBound(wgtBound, percentW, percentH); + wgt.setBounds(rec); + creator.setBounds(rec); + //绝对布局嵌套,要更新内部的绝对布局 + if (creator.acceptType(XWAbsoluteLayout.class)) { + creator.setBackupBound(wgtBound); + ((XWAbsoluteLayout) creator).updateBoundsWidget(); + } + } + } + } + + /** + * 更新子组件的Bound + * 这边主要用于绝对布局子组件在适应区域选项时 + * 涉及到的不同分辨率下缩放 + * + * @param minHeight 最小高度 + */ + @Override + public void updateChildBound(int minHeight) { + double prevContainerPercent = FRScreen.getByDimension(toData().getDesigningResolution()).getValue() / FormArea.DEFAULT_SLIDER; + if (toData().getCompState() == 0 && prevContainerPercent != containerPercent) { + for (int i = 0; i < this.getComponentCount(); i++) { + XCreator creator = getXCreator(i); + Rectangle rec = new Rectangle(creator.getBounds()); + rec.x = (int) (rec.x / prevContainerPercent * containerPercent); + rec.y = (int) (rec.y / prevContainerPercent * containerPercent); + rec.height = (int) (rec.height / prevContainerPercent * containerPercent); + rec.width = (int) (rec.width / prevContainerPercent * containerPercent); + BoundsWidget wgt = (BoundsWidget) toData().getBoundsWidget(creator.toData()); + wgt.setBounds(rec); + creator.setBounds(rec); + creator.updateChildBound(minHeight); + } + } + toData().setDesigningResolution(Toolkit.getDefaultToolkit().getScreenSize()); + } + + /** + * 增加对齐线 + * + * @param connector 对齐线 + */ + public void addConnector(Connector connector) { + xConnectorMap.put(connector, new XConnector(connector, this)); + ((WAbsoluteLayout) data).addConnector(connector); + } + + public XConnector getXConnector(Connector connector) { + return xConnectorMap.get(connector); + } + + /** + * 去除对齐线 + * + * @param connector 对齐线 + */ + public void removeConnector(Connector connector) { + ((WAbsoluteLayout) data).removeConnector(connector); + xConnectorMap.remove(connector); + } + + /** + * 返回对应的widget容器 + * + * @return 返回WAbsoluteLayout + */ + @Override + public WAbsoluteLayout toData() { + return (WAbsoluteLayout) data; + } + + @Override + protected String getIconName() { + return "layout_absolute_new.png"; + } + + /** + * 返回默认的容器name + * + * @return 返回绝对布局容器名 + */ + @Override + public String createDefaultName() { + return "absolute"; + } + + @Override + protected void initLayoutManager() { + this.setLayout(new FRAbsoluteLayout()); + } + + /** + * 是否支持标题样式 + * + * @return 默认false + */ + @Override + public boolean hasTitleStyle() { + return false; + } + + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + WAbsoluteLayout layout = (WAbsoluteLayout) data; + Connector[] connector = layout.getConnector(); + for (int i = 0, size = connector.length; i < size; i++) { + connector[i].draw(g); + } + } + + /** + * 转换保存组件信息的wlayout为对应的container + */ + @Override + public void convert() { + isRefreshing = true; + WAbsoluteLayout abs = toData(); + this.removeAll(); + for (int i = 0, count = abs.getWidgetCount(); i < count; i++) { + BoundsWidget bw = (BoundsWidget) abs.getWidget(i); + if (bw != null) { + Rectangle bounds = bw.getBounds(); + XWidgetCreator comp = (XWidgetCreator) XCreatorUtils.createXCreator(bw.getWidget()); + if (!comp.acceptType(XWParameterLayout.class)) { + comp.setDirections(Direction.ALL); + } + add(comp); + comp.setBounds(bounds); + } + } + isRefreshing = false; + } + + /** + * 当前组件zorder位置替换新的控件 + * + * @param widget 控件 + * @param oldcreator 旧组件 + * @return 组件 + */ + @Override + public XCreator replace(Widget widget, XCreator oldcreator) { + int i = this.getComponentZOrder(oldcreator); + if (i != -1) { + this.toData().replace(new BoundsWidget(widget, oldcreator.getBounds()), + new BoundsWidget(oldcreator.toData(), oldcreator.getBounds())); + this.convert(); + return (XCreator) this.getComponent(i); + } + return null; + } + + /** * 组件增加 + * * @param e 容器事件 */ - @Override - public void componentAdded(ContainerEvent e) { - if (isRefreshing) { - return; - } - XWidgetCreator creator = (XWidgetCreator) e.getChild(); - WAbsoluteLayout wabs = this.toData(); - if (!creator.acceptType(XWFitLayout.class)) { - creator.setDirections(Direction.ALL); - } - wabs.addWidget(new BoundsWidget(creator.toData(), creator.getBounds())); - } - - /** + @Override + public void componentAdded(ContainerEvent e) { + if (isRefreshing) { + return; + } + XWidgetCreator creator = (XWidgetCreator) e.getChild(); + WAbsoluteLayout wabs = this.toData(); + if (!creator.acceptType(XWFitLayout.class)) { + creator.setDirections(Direction.ALL); + } + wabs.addWidget(new BoundsWidget(creator.toData(), creator.getBounds())); + } + + /** * 在设计界面中有组件移除的时候,需要通知WLayout容器重新paint + * * @param e 容器事件 */ @Override @@ -377,128 +388,130 @@ public class XWAbsoluteLayout extends XLayoutContainer { BoundsWidget bw = new BoundsWidget(wgt, xwc.getBounds()); wlayout.removeWidget(bw); } - - @Override - public Dimension getMinimumSize() { - return toData().getMinDesignSize(); - } - - @Override - public LayoutAdapter getLayoutAdapter() { - return new FRAbsoluteLayoutAdapter(this); - } - - @Override - public XLayoutContainer getTopLayout() { - XLayoutContainer xTopLayout = XCreatorUtils.getParentXLayoutContainer(this).getTopLayout(); - if (xTopLayout != null && !xTopLayout.isEditable()){ - return xTopLayout; - } - else{ - return this; - } - } - - /** - * 得到属性名 - * @return 属性名 - * @throws java.beans.IntrospectionException - */ - public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { - return new CRPropertyDescriptor[] { - new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName( - Inter.getLocText("FR-Designer_Form-Widget_Name")) - }; - } - - public void paint(Graphics g) { - super.paint(g); - //如果鼠标移动到布局内且布局不可编辑,画出编辑蒙层 - if (isMouseEnter && !this.editable) { - int x = 0; - int y = 0; - int w = getWidth(); - int h = getHeight(); - - Graphics2D g2d = (Graphics2D) g; - Composite oldComposite = g2d.getComposite(); - //画白色的编辑层 - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 60 / 100.0F)); - g2d.setColor(Color.WHITE); - g2d.fillRect(x, y, w, h); - //画编辑按钮所在框 - g2d.setComposite(oldComposite); - g2d.setColor(new Color(176, 196, 222)); - g2d.fillRect((x + w / 2 - EDIT_BTN_WIDTH / 2), (y + h / 2 - EDIT_BTN_HEIGHT / 2), EDIT_BTN_WIDTH, EDIT_BTN_HEIGHT); - //画编辑按钮图标 - BufferedImage image = IOUtils.readImage(IconPathConstants.TD_EDIT_ICON_PATH); - g2d.drawImage( - image, - (x + w / 2 - 23), - (y + h / 2 - image.getHeight() / 2), - image.getWidth(), - image.getHeight(), - null, - this - ); - g2d.setColor(Color.BLACK); - //画编辑文字 - g2d.drawString(Inter.getLocText("FR-Designer_Edit"), x + w / 2 - 2, y + h / 2 + 5); - } - } - - /** - * 响应点击事件 - * - * @param editingMouseListener 鼠标点击,位置处理器 - * @param e 鼠标点击事件 - */ - public void respondClick(EditingMouseListener editingMouseListener,MouseEvent e){ - FormDesigner designer = editingMouseListener.getDesigner(); - SelectionModel selectionModel = editingMouseListener.getSelectionModel(); - boolean isEditing = isEditable() || designer.getCursor().getType() == Cursor.HAND_CURSOR || e.getClickCount() == 2; - setEditable(isEditing); - - selectionModel.selectACreatorAtMouseEvent(e); - designer.repaint(); - - if (editingMouseListener.stopEditing()) { - if (this != designer.getRootComponent()) { - ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this); - editingMouseListener.startEditing(this, isEditing ? adapter.getDesignerEditor() : null, adapter); - } - } - } - - /** - * body大小手动调整的时候 - * 按照比例调整组件的宽度 - * @param percent 比例 - */ - @Override - public void adjustCompWidth(double percent) { - for (int i = 0; i < getComponentCount(); i++) { - XCreator xCreator = (XCreator) getComponent(i); - Rectangle rectangle = xCreator.getBounds(); - xCreator.setBounds((int) (rectangle.x * percent), rectangle.y, (int) (rectangle.width * percent), rectangle.height); - BoundsWidget widget = toData().getBoundsWidget(xCreator.toData()); - widget.setBounds(xCreator.getBounds()); - } - } - - /** - * body大小手动调整的时候 - * 按照比例调整组件的高度 - * @param percent 比例 - */ - @Override - public void adjustCompHeight(double percent) { - for (int i = 0; i < getComponentCount(); i++) { - XCreator xCreator = (XCreator) getComponent(i); - Rectangle rectangle = xCreator.getBounds(); - xCreator.setBounds(rectangle.x, (int) (rectangle.y * percent), rectangle.width, (int) (rectangle.height * percent)); - BoundsWidget widget = toData().getBoundsWidget(xCreator.toData()); - widget.setBounds(xCreator.getBounds()); - } - } + + @Override + public Dimension getMinimumSize() { + return toData().getMinDesignSize(); + } + + @Override + public LayoutAdapter getLayoutAdapter() { + return new FRAbsoluteLayoutAdapter(this); + } + + @Override + public XLayoutContainer getTopLayout() { + XLayoutContainer xTopLayout = XCreatorUtils.getParentXLayoutContainer(this).getTopLayout(); + if (xTopLayout != null && !xTopLayout.isEditable()) { + return xTopLayout; + } else { + return this; + } + } + + /** + * 得到属性名 + * + * @return 属性名 + * @throws java.beans.IntrospectionException + */ + public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { + return new CRPropertyDescriptor[]{ + new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName( + Inter.getLocText("FR-Designer_Form-Widget_Name")) + }; + } + + public void paint(Graphics g) { + super.paint(g); + //如果鼠标移动到布局内且布局不可编辑,画出编辑蒙层 + if (isMouseEnter && !this.editable) { + int x = 0; + int y = 0; + int w = getWidth(); + int h = getHeight(); + + Graphics2D g2d = (Graphics2D) g; + Composite oldComposite = g2d.getComposite(); + //画白色的编辑层 + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 60 / 100.0F)); + g2d.setColor(Color.WHITE); + g2d.fillRect(x, y, w, h); + //画编辑按钮所在框 + g2d.setComposite(oldComposite); + g2d.setColor(new Color(176, 196, 222)); + g2d.fillRect((x + w / 2 - EDIT_BTN_WIDTH / 2), (y + h / 2 - EDIT_BTN_HEIGHT / 2), EDIT_BTN_WIDTH, EDIT_BTN_HEIGHT); + //画编辑按钮图标 + BufferedImage image = IOUtils.readImage(IconPathConstants.TD_EDIT_ICON_PATH); + g2d.drawImage( + image, + (x + w / 2 - 23), + (y + h / 2 - image.getHeight() / 2), + image.getWidth(), + image.getHeight(), + null, + this + ); + g2d.setColor(Color.BLACK); + //画编辑文字 + g2d.drawString(Inter.getLocText("FR-Designer_Edit"), x + w / 2 - 2, y + h / 2 + 5); + } + } + + /** + * 响应点击事件 + * + * @param editingMouseListener 鼠标点击,位置处理器 + * @param e 鼠标点击事件 + */ + public void respondClick(EditingMouseListener editingMouseListener, MouseEvent e) { + FormDesigner designer = editingMouseListener.getDesigner(); + SelectionModel selectionModel = editingMouseListener.getSelectionModel(); + boolean isEditing = isEditable() || designer.getCursor().getType() == Cursor.HAND_CURSOR || e.getClickCount() == 2; + setEditable(isEditing); + + selectionModel.selectACreatorAtMouseEvent(e); + designer.repaint(); + + if (editingMouseListener.stopEditing()) { + if (this != designer.getRootComponent()) { + ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this); + editingMouseListener.startEditing(this, isEditing ? adapter.getDesignerEditor() : null, adapter); + } + } + } + + /** + * body大小手动调整的时候 + * 按照比例调整组件的宽度 + * + * @param percent 比例 + */ + @Override + public void adjustCompWidth(double percent) { + for (int i = 0; i < getComponentCount(); i++) { + XCreator xCreator = (XCreator) getComponent(i); + Rectangle rectangle = xCreator.getBounds(); + xCreator.setBounds((int) (rectangle.x * percent), rectangle.y, (int) (rectangle.width * percent), rectangle.height); + BoundsWidget widget = (BoundsWidget) toData().getBoundsWidget(xCreator.toData()); + widget.setBounds(xCreator.getBounds()); + } + } + + /** + * body大小手动调整的时候 + * 按照比例调整组件的高度 + * + * @param percent 比例 + */ + @Override + public void adjustCompHeight(double percent) { + for (int i = 0; i < getComponentCount(); i++) { + XCreator xCreator = (XCreator) getComponent(i); + Rectangle rectangle = xCreator.getBounds(); + xCreator.setBounds(rectangle.x, (int) (rectangle.y * percent), rectangle.width, (int) (rectangle.height * percent)); + BoundsWidget widget = (BoundsWidget) toData().getBoundsWidget(xCreator.toData()); + widget.setBounds(xCreator.getBounds()); + } + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/creator/XWFitLayout.java b/designer_form/src/com/fr/design/designer/creator/XWFitLayout.java index 483b08fe5..7e0600ba4 100644 --- a/designer_form/src/com/fr/design/designer/creator/XWFitLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/XWFitLayout.java @@ -20,11 +20,11 @@ import com.fr.design.mainframe.FormArea; import com.fr.design.utils.gui.LayoutUtils; import com.fr.form.ui.PaddingMargin; import com.fr.form.ui.Widget; -import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.form.ui.container.WBodyLayoutType; import com.fr.form.ui.container.WFitLayout; import com.fr.form.ui.container.WLayout; import com.fr.general.FRScreen; +import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.general.Inter; import com.fr.stable.ArrayUtils; @@ -351,7 +351,7 @@ public class XWFitLayout extends XLayoutContainer { } for (int i=0, size=comps.size(); i= 0; i--) { + CardSwitchButton tempBtn = (CardSwitchButton) xwCardTagLayout.getXCreator(i).toData(); + tempBtn.setIndex(i + 1); + WTabFitLayout tempTab = (WTabFitLayout) xwCardLayout.getXCreator(i).toData(); + tempTab.setIndex(i + 1); + tempTab.setTabNameIndex(i + 1); + } + } + + @Override + protected int getTabMoveIndex(CardSwitchButton btn) { + return 0; + } +} diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/TabMoveNextAction.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/TabMoveNextAction.java new file mode 100644 index 000000000..f3e34208c --- /dev/null +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/TabMoveNextAction.java @@ -0,0 +1,34 @@ +package com.fr.design.designer.creator.cardlayout; + +import com.fr.design.mainframe.FormDesigner; +import com.fr.form.ui.CardSwitchButton; +import com.fr.form.ui.container.cardlayout.WTabFitLayout; +import com.fr.general.IOUtils; +import com.fr.general.Inter; + +/** + * Created by zhouping on 2017/2/9. + */ +public class TabMoveNextAction extends TabMoveAction { + + public TabMoveNextAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { + super(t, xCardSwitchButton); + this.setName(Inter.getLocText("FR-Designer-Move_Tab_Next")); + this.setSmallIcon(IOUtils.readIcon("com/fr/design/images/control/tab/next.png")); + } + + @Override + protected void changeTabIndex(XWCardTagLayout xwCardTagLayout, XWCardLayout xwCardLayout, int currentIndex, int maxIndex) { + //修改下一个tab的索引号 + CardSwitchButton nextBtn = (CardSwitchButton) xwCardTagLayout.getXCreator(currentIndex + 1).toData(); + nextBtn.setIndex(currentIndex); + WTabFitLayout nextTab = (WTabFitLayout) xwCardLayout.getXCreator(currentIndex + 1).toData(); + nextTab.setIndex(currentIndex); + nextTab.setTabNameIndex(currentIndex); + } + + @Override + protected int getTabMoveIndex(CardSwitchButton currentButton) { + return currentButton.getIndex() + 1; + } +} diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/TabMovePrevAction.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/TabMovePrevAction.java new file mode 100644 index 000000000..94f501c57 --- /dev/null +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/TabMovePrevAction.java @@ -0,0 +1,34 @@ +package com.fr.design.designer.creator.cardlayout; + +import com.fr.design.mainframe.FormDesigner; +import com.fr.form.ui.CardSwitchButton; +import com.fr.form.ui.container.cardlayout.WTabFitLayout; +import com.fr.general.IOUtils; +import com.fr.general.Inter; + +/** + * Created by zhouping on 2017/2/9. + */ +public class TabMovePrevAction extends TabMoveAction { + + public TabMovePrevAction(FormDesigner t, XCardSwitchButton xCardSwitchButton) { + super(t, xCardSwitchButton); + this.setName(Inter.getLocText("FR-Designer-Move_Tab_Prev")); + this.setSmallIcon(IOUtils.readIcon("com/fr/design/images/control/tab/prev.png")); + } + + @Override + protected void changeTabIndex(XWCardTagLayout xwCardTagLayout, XWCardLayout xwCardLayout, int currentIndex, int maxIndex) { + //修改上一个tab的索引号 + CardSwitchButton prevBtn = (CardSwitchButton) xwCardTagLayout.getXCreator(currentIndex - 1).toData(); + prevBtn.setIndex(currentIndex); + WTabFitLayout prevTab = (WTabFitLayout) xwCardLayout.getXCreator(currentIndex - 1).toData(); + prevTab.setIndex(currentIndex); + prevTab.setTabNameIndex(currentIndex); + } + + @Override + protected int getTabMoveIndex(CardSwitchButton currentButton) { + return currentButton.getIndex() - 1; + } +} diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardAddButton.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardAddButton.java index fa4c1d4a9..85e26e877 100644 --- a/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardAddButton.java +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/XCardAddButton.java @@ -89,12 +89,12 @@ public class XCardAddButton extends XButton{ // addbutton对应的XWCardLayout和XWCardTagLayout暂未存入到xml中,重新打开之后先根据父子层获取 if(cardLayout == null && tagLayout ==null ){ - initRalateLayout(); + initRelateLayout(); } int index = cardLayout.toData().getWidgetCount(); //添加新的tab,并将原来的设为未选中状态 - setTabUnselectd(); + setTabUnselected(); addTab(index); this.tagLayout.adjustComponentWidth(); @@ -110,7 +110,7 @@ public class XCardAddButton extends XButton{ LayoutUtils.layoutRootContainer(designer.getRootComponent()); } - private void initRalateLayout(){ + private void initRelateLayout(){ XWCardTitleLayout titleLayout = (XWCardTitleLayout)this.getBackupParent(); this.tagLayout = titleLayout.getTagPart(); @@ -129,7 +129,7 @@ public class XCardAddButton extends XButton{ } //将原来的tab页设置为未选中状态 - private void setTabUnselectd(){ + private void setTabUnselected(){ for(int i=0;i + * void + */ + public void adjustComponentWidth() { + } + + + /** + * 该布局需要隐藏,无需对边框进行操作 + * + * @param + */ public void setBorder(Border border) { - return; - } - - @Override - /** - * 该布局隐藏,点击该布局时选中相应的tab布局主体 - * @param editingMouseListener 监听 - * @param e 鼠标点击事件 - * - */ - public void respondClick(EditingMouseListener editingMouseListener, - MouseEvent e) { - FormDesigner designer = editingMouseListener.getDesigner(); - SelectionModel selectionModel = editingMouseListener.getSelectionModel(); - - XWCardTitleLayout titleLayout = (XWCardTitleLayout) this.getBackupParent(); - if(titleLayout != null){ - XWCardMainBorderLayout mainLayout = (XWCardMainBorderLayout)titleLayout.getBackupParent(); - if(mainLayout != null){ - XWCardLayout cardLayout = mainLayout.getCardPart(); - selectionModel.setSelectedCreator(cardLayout); - } - } - - if (editingMouseListener.stopEditing()) { - if (this != designer.getRootComponent()) { - ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this); - editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter); - } - } - } - - @Override - public XLayoutContainer getTopLayout() { - return this.getBackupParent().getTopLayout(); - } + + } + + @Override + /** + * 该布局隐藏,点击该布局时选中相应的tab布局主体 + * @param editingMouseListener 监听 + * @param e 鼠标点击事件 + * + */ + public void respondClick(EditingMouseListener editingMouseListener, + MouseEvent e) { + FormDesigner designer = editingMouseListener.getDesigner(); + SelectionModel selectionModel = editingMouseListener.getSelectionModel(); + + XWCardTitleLayout titleLayout = (XWCardTitleLayout) this.getBackupParent(); + if (titleLayout != null) { + XWCardMainBorderLayout mainLayout = (XWCardMainBorderLayout) titleLayout.getBackupParent(); + if (mainLayout != null) { + XWCardLayout cardLayout = mainLayout.getCardPart(); + selectionModel.setSelectedCreator(cardLayout); + } + } + + if (editingMouseListener.stopEditing()) { + if (this != designer.getRootComponent()) { + ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this); + editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter); + } + } + } + + @Override + public XLayoutContainer getTopLayout() { + return this.getBackupParent().getTopLayout(); + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java index f4cac3e15..fcf1e503c 100644 --- a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java @@ -1,11 +1,5 @@ package com.fr.design.designer.creator.cardlayout; -import java.awt.*; -import java.beans.IntrospectionException; - -import javax.swing.border.Border; - -import com.fr.base.ScreenResolution; import com.fr.base.background.ColorBackground; import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter; @@ -16,25 +10,25 @@ import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XWFitLayout; import com.fr.design.form.util.XCreatorConstants; import com.fr.design.fun.WidgetPropertyUIProvider; -import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormHierarchyTreePane; import com.fr.design.mainframe.widget.editors.ButtonTypeEditor; -import com.fr.design.mainframe.widget.editors.FontEditor; import com.fr.design.mainframe.widget.editors.ImgBackgroundEditor; -import com.fr.design.mainframe.widget.renderer.FontCellRenderer; import com.fr.design.utils.gui.LayoutUtils; import com.fr.form.ui.CardSwitchButton; -import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.form.ui.container.cardlayout.WTabFitLayout; +import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.general.Background; -import com.fr.general.FRFont; import com.fr.general.FRLogger; import com.fr.general.Inter; import com.fr.stable.ArrayUtils; import com.fr.stable.core.PropertyChangeAdapter; +import javax.swing.border.Border; +import java.awt.*; +import java.beans.IntrospectionException; + /** * @author focus @@ -46,14 +40,10 @@ public class XWTabFitLayout extends XWFitLayout { // tab布局在拖拽导致的缩放里(含间隔时),如果拖拽宽高大于组件宽高,会导致调整的时候找不到原来的组件 // 这里先将拖拽之前的宽高先做备份 private static final Color NORMAL_GRAL = new Color(236,236,236); - private static final String DEFAULT_FONT_NAME = "SimSun"; - public final static Font DEFAULTFT = new Font("Song_TypeFace",0,12); - public final static FRFont DEFAULT_FRFT = FRFont.getInstance(DEFAULT_FONT_NAME, 0, 9); private Dimension referDim; private Background initialBackground; private Background overBackground; private Background clickBackground; - private FRFont font; private XCardSwitchButton xCardSwitchButton; public Dimension getReferDim() { @@ -88,15 +78,6 @@ public class XWTabFitLayout extends XWFitLayout { this.clickBackground = clickBackground; } - @Override - public FRFont getFont() { - return font; - } - - public void setFont(FRFont font) { - this.font = font; - } - public XCardSwitchButton getxCardSwitchButton() { return xCardSwitchButton; } @@ -164,21 +145,7 @@ public class XWTabFitLayout extends XWFitLayout { cardSwitchButton.setClickBackground(clickBackground); } } - ), - //字体 - creatNonListenerStyle(4).setPropertyChangeListener( - new PropertyChangeAdapter() { - @Override - public void propertyChange() { - font = ((WTabFitLayout) data).getFont(); - CardSwitchButton cardSwitchButton = (CardSwitchButton) xCardSwitchButton.toData(); - cardSwitchButton.setFont(font); - UILabel uiLabel = xCardSwitchButton.getLabel(); - uiLabel.setFont(font.applyResolutionNP(ScreenResolution.getScreenResolution())); - uiLabel.setForeground(font.getForeground()); - xCardSwitchButton.setLabel(uiLabel); - } - }), + ) }; } @@ -210,9 +177,6 @@ public class XWTabFitLayout extends XWFitLayout { XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), new CRPropertyDescriptor("clickBackground", this.data.getClass()).setEditorClass( ImgBackgroundEditor.class).setI18NName(Inter.getLocText("FR-Designer_Background-Click")).putKeyValue( - XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), - new CRPropertyDescriptor("font", this.data.getClass()).setI18NName(Inter.getLocText("FR-Designer_FRFont")) - .setEditorClass(FontEditor.class).setRendererClass(FontCellRenderer.class).putKeyValue( XCreatorConstants.PROPERTY_CATEGORY, "Advanced") }; return crPropertyDescriptors[i]; @@ -243,20 +207,15 @@ public class XWTabFitLayout extends XWFitLayout { if (!isStyle) { this.xCardSwitchButton.setCustomStyle(false); this.xCardSwitchButton.setSelectBackground(bg); - this.xCardSwitchButton.getLabel().setFont(DEFAULTFT); cardSwitchButton.setInitialBackground(null); cardSwitchButton.setClickBackground(null); cardSwitchButton.setOverBackground(null); - cardSwitchButton.setFont(DEFAULT_FRFT); } else { Background initialBackground = cardSwitchButton.getInitialBackground(); bg = initialBackground == null ? bg : initialBackground; this.xCardSwitchButton.setSelectBackground(bg); this.xCardSwitchButton.setCustomStyle(true); cardSwitchButton.setCustomStyle(true); - if (font != null) { - cardSwitchButton.setFont(font); - } if (this.initialBackground != null){ this.xCardSwitchButton.setSelectBackground(this.initialBackground); cardSwitchButton.setInitialBackground(this.initialBackground); @@ -466,7 +425,7 @@ public class XWTabFitLayout extends XWFitLayout { private void updateCompsWidget(){ for(int m=0;m(); CRPropertyDescriptor[] propertyTableEditor = null; @@ -55,8 +57,7 @@ public class BodyAppRelayoutTable extends AbstractPropertyTable { groups.add(new PropertyGroup(new ReportAppPropertyGroupModel(Inter.getLocText("FR-Designer_Properties_Mobile"), xCreator, propertyTableEditor, designer))); - TableModel model = new BeanTableModel(); - setModel(model); + setModel(new BeanTableModel()); this.repaint(); } @@ -78,8 +79,9 @@ public class BodyAppRelayoutTable extends AbstractPropertyTable { } /** - * 待说明 + * 触发控件编辑事件 */ + @Override public void firePropertyEdit() { designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_EDITED); } diff --git a/designer_form/src/com/fr/design/designer/properties/mobile/BodyMobilePropertyUI.java b/designer_form/src/com/fr/design/designer/properties/mobile/BodyMobilePropertyUI.java index 70b80bc99..a3a1e5086 100644 --- a/designer_form/src/com/fr/design/designer/properties/mobile/BodyMobilePropertyUI.java +++ b/designer_form/src/com/fr/design/designer/properties/mobile/BodyMobilePropertyUI.java @@ -3,7 +3,6 @@ package com.fr.design.designer.properties.mobile; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XWAbsoluteBodyLayout; import com.fr.design.designer.creator.XWFitLayout; -import com.fr.design.designer.properties.BodyAppRelayoutTable; import com.fr.design.fun.impl.AbstractWidgetPropertyUIProvider; import com.fr.design.gui.itable.AbstractPropertyTable; import com.fr.general.Inter; diff --git a/designer_form/src/com/fr/design/form/mobile/FormMobileAttrPane.java b/designer_form/src/com/fr/design/form/mobile/FormMobileAttrPane.java index eb53e8f8c..6dc1f20ef 100644 --- a/designer_form/src/com/fr/design/form/mobile/FormMobileAttrPane.java +++ b/designer_form/src/com/fr/design/form/mobile/FormMobileAttrPane.java @@ -36,7 +36,7 @@ public class FormMobileAttrPane extends BasicBeanPane{ jPanel2.setLayout(FRGUIPaneFactory.createBorderLayout()); jPanel2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); this.mobileToolBarPane = new MobileToolBarPane(); - this.mobileUseHtmlGroupPane = new MobileUseHtmlGroupPane(); + this.mobileUseHtmlGroupPane = new MobileUseHtmlGroupPane(Inter.getLocText("FR-Designer_Mobile_Form_Analysis_Annotation")); //设置一个JPanel包裹mobileToolBarPane这个Panel,让jPanel的高度等于mobileToolBarPane高度加10,再放入this中 jPanel1.setPreferredSize(new Dimension(0, (int)this.mobileToolBarPane.getPreferredSize().getHeight() + PADDINGHEIGHT)); jPanel2.setPreferredSize(new Dimension(0, (int)this.mobileUseHtmlGroupPane.getPreferredSize().getHeight() + PADDINGHEIGHT)); diff --git a/designer_form/src/com/fr/design/form/mobile/MobileUseHtmlGroupPane.java b/designer_form/src/com/fr/design/form/mobile/MobileUseHtmlGroupPane.java index 45550a842..ab400d4a3 100644 --- a/designer_form/src/com/fr/design/form/mobile/MobileUseHtmlGroupPane.java +++ b/designer_form/src/com/fr/design/form/mobile/MobileUseHtmlGroupPane.java @@ -8,6 +8,10 @@ import com.fr.form.main.mobile.FormMobileAttr; * Created by fanglei on 2016/12/28. */ public class MobileUseHtmlGroupPane extends MobileUseHtmlGroupBeanPane { + public MobileUseHtmlGroupPane(String annotation) { + super(annotation); + } + @Override public void populateBean(FormMobileAttr mobileAttr) { if(mobileAttr != null) { diff --git a/designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java b/designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java index 692359bbd..589be7e83 100644 --- a/designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java +++ b/designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java @@ -1,689 +1,701 @@ -/* - * Copyright(c) 2001-2011, FineReport Inc, All Rights Reserved. - */ -package com.fr.design.form.parameter; - -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Image; -import java.awt.Insets; -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JPanel; - -import com.fr.base.BaseUtils; -import com.fr.base.Parameter; -import com.fr.base.parameter.ParameterUI; -import com.fr.design.DesignModelAdapter; -import com.fr.design.designer.beans.actions.CopyAction; -import com.fr.design.designer.beans.actions.CutAction; -import com.fr.design.designer.beans.actions.FormDeleteAction; -import com.fr.design.designer.beans.actions.PasteAction; -import com.fr.design.designer.beans.adapters.layout.FRAbsoluteLayoutAdapter; -import com.fr.design.designer.beans.events.DesignerEditListener; -import com.fr.design.designer.beans.events.DesignerEvent; -import com.fr.design.designer.beans.location.Direction; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XCreatorUtils; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWAbsoluteLayout; -import com.fr.design.designer.creator.XWParameterLayout; -import com.fr.design.designer.properties.FormWidgetAuthorityEditPane; -import com.fr.design.form.util.XCreatorConstants; -import com.fr.design.mainframe.AuthorityEditPane; -import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.EastRegionContainerPane; -import com.fr.design.mainframe.FormArea; -import com.fr.design.mainframe.FormDesigner; -import com.fr.design.mainframe.FormDesignerModeForSpecial; -import com.fr.design.mainframe.FormParaPane; -import com.fr.design.mainframe.FormWidgetDetailPane; -import com.fr.design.mainframe.WidgetPropertyPane; -import com.fr.design.mainframe.WidgetToolBarPane; -import com.fr.design.parameter.ParaDefinitePane; -import com.fr.design.parameter.ParameterDesignerProvider; -import com.fr.design.parameter.ParameterPropertyPane; -import com.fr.form.main.Form; -import com.fr.form.main.parameter.FormParameterUI; -import com.fr.form.parameter.FormSubmitButton; -import com.fr.form.ui.EditorHolder; -import com.fr.form.ui.WidgetValue; -import com.fr.form.ui.container.WAbsoluteLayout; -import com.fr.form.ui.container.WLayout; -import com.fr.form.ui.container.WParameterLayout; -import com.fr.general.Inter; -import com.fr.stable.ArrayUtils; - -/** - * Created by IntelliJ IDEA. - * User : Richer - * Version: 6.5.5 - * Date : 11-7-5 - * Time : 下午7:46 - * 表单类型的参数设计器 - */ -// TODO ALEX_SEP FormDesigner和FormParaDesignEditor应该共用Form的编辑,但是FormParaDesignEditor不应该直接就是FormDesigner -public class FormParaDesigner extends FormDesigner implements ParameterDesignerProvider { - private static final int NUM_IN_A_LINE = 4; - private static final int H_COMPONENT_GAP = 165; - private static final int V_COMPONENT_GAP = 25; - private static final int FIRST_V_LOCATION = 35; - private static final int FIRST_H_LOCATION = 90; - private static final int SECOND_H_LOCATION = 170; - private static final int ADD_HEIGHT = 20; - private static final int H_GAP = 105; - - private static Image paraImage = BaseUtils.readImage("/com/fr/design/images/form/parameter.png"); - - public FormParaDesigner() { - this(new FormParameterUI()); - } - - public FormParaDesigner(FormParameterUI ui) { - super(gen(ui)); - } - - private static Form gen(Form form) { - WLayout container = form.getContainer(); - if (container == null) { - container = new WParameterLayout(); - } - container.setWidgetName("para"); - form.setContainer(container); - return form; - } - - protected FormDesignerModeForSpecial createFormDesignerTargetMode() { - return new FormParaTargetMode(this); - } - - /** - * 开始编辑参数面板的时候进行的初始化 - */ - public void initBeforeUpEdit() { - WidgetToolBarPane.getInstance(this); - EastRegionContainerPane.getInstance().replaceDownPane( - FormWidgetDetailPane.getInstance(this)); - if (!BaseUtils.isAuthorityEditing()) { - EastRegionContainerPane.getInstance().addParameterPane(ParameterPropertyPane.getInstance(this)); - EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance(this).getPreferredSize().height); - EastRegionContainerPane.getInstance().replaceUpPane( - WidgetPropertyPane.getInstance(this)); - } else { - EastRegionContainerPane.getInstance().removeParameterPane(); - showAuthorityEditPane(); - } - - } - - /** - * 创建权限编辑面板 - * @return 面板 - */ - public AuthorityEditPane createAuthorityEditPane() { - return new FormWidgetAuthorityEditPane(this); - } - - /** - * 内容属性表面板 - * @return 内容属性表面板 - */ - public JPanel getEastUpPane() { - return WidgetPropertyPane.getInstance(this); - } - - /** - * 参数属性表 - * @return 参数属性表 - */ - - public JPanel getEastDownPane() { - return FormWidgetDetailPane.getInstance(this); - } - - /** - * 权限编辑面板 - * @return 权限编辑面板 - */ - public AuthorityEditPane getAuthorityEditPane() { - FormWidgetAuthorityEditPane formWidgetAuthorityEditPane = new FormWidgetAuthorityEditPane(this); - formWidgetAuthorityEditPane.populateDetials(); - return formWidgetAuthorityEditPane; - } - - /** - * 给包含此FormParaDesigner的ParameterDefinitePane添加事件 - * - * @param paraDefinitePane 面板 - */ - public void addListener(final ParaDefinitePane paraDefinitePane) { - this.getEditListenerTable().addListener(new DesignerEditListener() { - - @Override - public void fireCreatorModified(DesignerEvent evt) { - if (evt.getCreatorEventID() == DesignerEvent.CREATOR_ADDED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_CUTED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_RENAMED) { - paraDefinitePane.setParameterArray( - paraDefinitePane.getNoRepeatParas(DesignModelAdapter.getCurrentModelAdapter().getParameters())); - paraDefinitePane.refreshParameter(); - } - } - }); - } - - /** - * 包裹一层FormArea - * - * @return 区域 - */ - public Component createWrapper() { - FormArea area = new FormArea(this, false); - area.setBorder(BorderFactory.createEmptyBorder(0, 13, 0, 0)); - return area; - } - - /** - * 刷新控件 - */ - public void refreshAllNameWidgets() { - XCreatorUtils.refreshAllNameWidgets(this.getRootComponent()); - } - - /** - * 刷新tableData - * - * @param oldName 旧名称 - * @param newName 新名称 - */ - public void refresh4TableData(String oldName, String newName) { - this.getTarget().renameTableData(oldName, newName); - this.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_SELECTED); - } - - /** - * 刷新参数 - * - * @param p 参数面板 - */ - public void refreshParameter(ParaDefinitePane p) { - XLayoutContainer rootContainer = this.getRootComponent(); - java.util.List namelist = getAllXCreatorNameList(rootContainer); - // parameterArray是报表的所有参数, nameList是已经在参数面板添加过控件的参数名 - // 与已有的参数列表比较 如果已经存在 就除去 - Parameter[] ps = p.getParameterArray(); - if (ps != null) { - for (Parameter parameter : ps) { - for (String name : namelist) { - if (name.equalsIgnoreCase(parameter.getName())) { - p.setParameterArray((Parameter[]) ArrayUtils.removeElement(p.getParameterArray(), parameter)); - } - } - } - } - ParameterPropertyPane.getInstance().getParameterToolbarPane().populateBean( - p.getParameterArray() == null ? new Parameter[0] : p.getParameterArray()); - EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance().getPreferredSize().height); - - } - - /** - * 判断这个参数面板是否没有控件 - * - * @return 参数面板是否没有控件 - */ - public boolean isBlank() { - XLayoutContainer rootContainer = this.getRootComponent(); - List xx = getAllXCreatorNameList(rootContainer); - return xx.isEmpty(); - } - - protected void setToolbarButtons(boolean flag) { - DesignerContext.getDesignerFrame().checkCombineUp(!flag, NAME_ARRAY_LIST); - } - - /** - * 看看参数面板中的控件是否有和模板参数同名的 - * - * @param allParameters 参数 - * @return 是否有同名 - */ - public boolean isWithoutParaXCreator(Parameter[] allParameters) { - XLayoutContainer rootContainer = this.getRootComponent(); - List xx = getAllXCreatorNameList(rootContainer); - for (Parameter parameter : allParameters) { - for (String name : xx) { - if (name.equalsIgnoreCase(parameter.getName())) { - return false; - } - } - } - - return true; - } - - /** - * 参数面板控件的名字 - * - * @return 名字 - */ - public List getAllXCreatorNameList() { - XLayoutContainer rootContainer = this.getRootComponent(); - List namelist = new ArrayList(); - for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { - if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { - namelist.addAll(getAllXCreatorNameList((XLayoutContainer) rootContainer.getXCreator(i))); - } else { - namelist.add(rootContainer.getXCreator(i).toData().getWidgetName()); - } - } - return namelist; - } - - private List getAllXCreatorNameList(XLayoutContainer rootContainer) { - List namelist = new ArrayList(); - for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { - if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { - namelist.addAll(getAllXCreatorNameList((XLayoutContainer) rootContainer.getXCreator(i))); - } else { - namelist.add(rootContainer.getXCreator(i).toData().getWidgetName()); - } - } - return namelist; - } - - /** - * 是否有查询按钮 - * - * @return 有无查询按钮 - */ - public boolean isWithQueryButton() { - XLayoutContainer rootContainer = this.getRootComponent(); - return SearchQueryCreators(rootContainer); - } - - /** - * 返回复制粘贴删除等动作 - * @return 同上 - */ - public Action[] getActions() { - if (designer_actions == null) { - designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this), - new FormDeleteAction(this)}; - } - return designer_actions; - } - - private boolean SearchQueryCreators(XLayoutContainer rootContainer) { - boolean b = false; - for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { - if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { - b = SearchQueryCreators((XLayoutContainer) rootContainer.getXCreator(i)); - } else if (rootContainer.getXCreator(i) instanceof XFormSubmit) { - b = true; - } - } - return b; - } - - /** - * 就是getTarget 为了返回ParameterUI接口而不冲突另写个 - * - * @return - */ - public ParameterUI getParaTarget() { - return (FormParameterUI) super.getTarget(); - } - - /** - * ParameterDefinitePane通过ParaDesigner来调用ParameterPropertyPane - * - * @param p 面板 - */ - public void populateParameterPropertyPane(ParaDefinitePane p) { - ParameterPropertyPane.getInstance().populateBean(p); - } - - /** - * 初始化 - */ - public void initWidgetToolbarPane() { - WidgetToolBarPane.getInstance(this); - } - - /** - * populate - * - * @param ui - */ - public void populate(ParameterUI ui) { - if (ui == null) { - return; - } - if (this.getTarget() == ui) { - repaint(); - return; - } - this.setTarget((FormParameterUI) ui.convert()); - this.refreshRoot(); - } - - /** - * 报表直接判断底层是否是绝对布局 - * @return 是则返回true - */ - public boolean hasWAbsoluteLayout() { - return this.getTarget().getContainer() instanceof WAbsoluteLayout; - } - - /** - * 刷新底层容器 - */ - public void refreshRoot() { - XLayoutContainer layoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(this.getTarget() - .getContainer()); - if (layoutContainer == null) { - layoutContainer = new XWParameterLayout(); - } - layoutContainer.setSize(LARGE_PREFERRED_SIZE); - setRootComponent(layoutContainer); - } - - /** - * 是否是报表的参数面板 - * @return 是 - */ - public boolean isFormParaDesigner(){ - return true; - } - - public XLayoutContainer getParaComponent() { - return getRootComponent(); - } - - private void paintLinkParameters(Graphics clipg) { - Parameter[] paras = DesignModelAdapter.getCurrentModelAdapter().getParameters(); - if (paras == null || paras.length == 0) { - return; - } - Graphics g = clipg.create(); - g.setColor(Color.RED); - if (!(this.getRootComponent() instanceof XWAbsoluteLayout)) { - return; - } - XWAbsoluteLayout layout = (XWAbsoluteLayout) this.getRootComponent(); - for (int i = 0; i < layout.getXCreatorCount(); i++) { - XCreator creator = layout.getXCreator(i); - if (!creator.isVisible()) { - continue; - } - for (Parameter p : paras) { - if (p.getName().equalsIgnoreCase(creator.toData().getWidgetName())) { - g.drawImage(paraImage, creator.getX() - 4, creator.getY() + 2, null); - break; - } - } - } - } - - /** - * 得到合适的大小 - * - * @return - */ - public Dimension getPreferredSize() { - return getDesignSize(); - } - - public Dimension getDesignSize() { - return ((FormParameterUI) getTarget()).getDesignSize(); - } - - /** - * 设置高度 - * - * @param height - */ - public void setDesignHeight(int height) { - Dimension dim = getPreferredSize(); - dim.height = height; - ((FormParameterUI) getTarget()).setDesignSize(dim); - } - - /** - * paintContent - * - * @param clipg - */ - public void paintContent(Graphics clipg) { - Dimension dim; - dim = ((FormParameterUI) getTarget()).getDesignSize(); - getRootComponent().setSize(dim); - getRootComponent().paint(clipg); - paintLinkParameters(clipg); - paintOp(clipg, getOutlineBounds()); - } - - private void paintOp(Graphics offg, Rectangle bounds) { - Color oldColor = offg.getColor(); - Insets insets = getOutlineInsets(); - offg.setColor(XCreatorConstants.OP_COLOR); - offg.fillRect(bounds.x, bounds.y + bounds.height, bounds.width + insets.right, insets.bottom); - offg.fillRect(bounds.x + bounds.width, bounds.y, insets.right, bounds.height); - offg.setColor(oldColor); - } - - protected void setRootComponent(XLayoutContainer component) { - component.setDirections(new int[]{Direction.BOTTOM, Direction.RIGHT}); - super.setRootComponent(component); - } - - /** - * 刷新尺寸 - */ - public void populateRootSize() { - ((FormParameterUI) getTarget()).setDesignSize(getRootComponent().getSize()); - if (getParaComponent().acceptType(XWParameterLayout.class)) { - WParameterLayout layout = (WParameterLayout)getParaComponent().toData(); - layout.setDesignWidth(getRootComponent().getWidth()); - } - } - - /** - * 保存参数界面的宽度 - * - * @param width 指定的宽度 - */ - public void updateWidth(int width) { - FormParameterUI parameterUI = ((FormParameterUI) getTarget()); - parameterUI.setDesignSize(new Dimension(width, parameterUI.getDesignSize().height)); - } - - /** - * 保存参数界面的高度 - * - * @param height 指定的高度 - */ - public void updateHeight(int height) { - FormParameterUI parameterUI = ((FormParameterUI) getTarget()); - parameterUI.setDesignSize(new Dimension(parameterUI.getDesignSize().width, height)); - } - - /** - * 在参数很多时,全部添加的时候,可以向下一次排版,若去掉就会在参数面板堆到一起 - * - * @param creator 组件 z - * @param x 长度 - * @param y 长度 c - * @param layout 布局 - * @return 是否扩展 - */ - public boolean prepareForAdd(XCreator creator, int x, int y, XWAbsoluteLayout layout) { - // 参数界面,自动扩展 - if (!isRoot(layout)) { - return false; - } - - Dimension size = layout.getSize(); - Boolean needResize = false; - - if (creator.getWidth() / 2 + x > layout.getWidth()) { - size.width = creator.getWidth() / 2 + x + ADD_HEIGHT; - needResize = true; - } - if (creator.getHeight() / 2 + y > layout.getHeight()) { - size.height = creator.getHeight() / 2 + y + ADD_HEIGHT; - needResize = true; - } - if (needResize) { - layout.setSize(size); - populateRootSize(); - } - return true; - } - - /** - * 加入参数 - * @param parameter 参数 c - * @param currentIndex 位置 w - * @return 是否加入 s - */ - public boolean addingParameter2Editor(Parameter parameter, int currentIndex) { - com.fr.form.ui.Label label = new com.fr.form.ui.Label(); - String name = parameter.getName(); - label.setWidgetName("Label" + name); - label.setWidgetValue(new WidgetValue(name + ":")); - XCreator xCreator = XCreatorUtils.createXCreator(label); - if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) - + FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return false; - } - EditorHolder editor = new EditorHolder(parameter); - xCreator = XCreatorUtils.createXCreator(editor); - if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) - + SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return false; - } - return true; - } - - - /** - * 加入参数 - * @param parameter 参数 c - * @param currentIndex 位置 w - * @return 是否加入 s - */ - public boolean addingParameter2EditorWithQueryButton(Parameter parameter, int currentIndex) { - com.fr.form.ui.Label label = new com.fr.form.ui.Label(); - String name = parameter.getName(); - label.setWidgetName("Label" + name); - label.setWidgetValue(new WidgetValue(name + ":")); - XCreator xCreator = XCreatorUtils.createXCreator(label); - if (!(this.autoAddComponent(xCreator, FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP - * (currentIndex / NUM_IN_A_LINE)))) { - return false; - } - EditorHolder editor = new EditorHolder(parameter); - editor.setWidgetName(name); - xCreator = XCreatorUtils.createXCreator(editor); - if (!(this.autoAddComponent(xCreator, SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP - * (currentIndex / NUM_IN_A_LINE)))) { - return false; - } - FormSubmitButton formSubmitButton = new FormSubmitButton(); - formSubmitButton.setWidgetName("Search"); - formSubmitButton.setText(Inter.getLocText("FR-Designer_Query")); - xCreator = XCreatorUtils.createXCreator(formSubmitButton); - if (!(this.autoAddComponent(xCreator, 270, FIRST_V_LOCATION + V_COMPONENT_GAP - * (currentIndex / NUM_IN_A_LINE)))) { - return false; - } - return true; - } - - /** - * 加入参数 - * @param parameterArray 参数 c - * @param currentIndex 位置 w - * @return 是否加入 s - */ - public void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex) { - for (int i = 0; i < parameterArray.length; i++) { - com.fr.form.ui.Label label = new com.fr.form.ui.Label(); - label.setWidgetName("Label" + parameterArray[i].getName()); - label.setWidgetValue(new WidgetValue(parameterArray[i].getName() + ":")); - XCreator xCreator = XCreatorUtils.createXCreator(label); - - if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) - + FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - break; - } - // 每行显示5组 - EditorHolder editor = new EditorHolder(parameterArray[i]); - editor.setWidgetName(parameterArray[i].getName()); - xCreator = XCreatorUtils.createXCreator(editor); - if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) - + SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - break; - } - currentIndex++; - } - if (!isWithQueryButton()) { - FormSubmitButton formSubmitButton = new FormSubmitButton(); - formSubmitButton.setWidgetName("Search"); - formSubmitButton.setText(Inter.getLocText("FR-Designer_Query")); - XCreator xCreator = XCreatorUtils.createXCreator(formSubmitButton); - if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * 3 + H_GAP, FIRST_V_LOCATION - + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return; - } - } - } - - /** - * 自动添加 - * - * @param xCreator 组件 z - * @param x 位置 w - * @param y 位置 - * @return 是否添加 s - */ - public boolean autoAddComponent(XCreator xCreator, int x, int y) { - XWAbsoluteLayout layout = (XWAbsoluteLayout) this.getRootComponent(); - FRAbsoluteLayoutAdapter adapter = (FRAbsoluteLayoutAdapter) layout.getLayoutAdapter(); - if (prepareForAdd(xCreator, x, y, layout)) { - adapter.addBean(xCreator, x, y); - } - this.getSelectionModel().setSelectedCreator(xCreator); - repaint(); - return true; - } - - /** - * 工具栏 - * @return 工具栏面板 g - */ - public JPanel[] toolbarPanes4Form() { - return new JPanel[]{FormParaPane.getInstance(this)}; - } - - /** - * 复制等按钮 - * @return 按钮组 a - */ - public JComponent[] toolBarButton4Form() { - return new JComponent[]{new CutAction(this).createToolBarComponent(), new CopyAction(this).createToolBarComponent(), new PasteAction(this).createToolBarComponent(), - new FormDeleteAction(this).createToolBarComponent()}; - } +/* + * Copyright(c) 2001-2011, FineReport Inc, All Rights Reserved. + */ +package com.fr.design.form.parameter; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.Insets; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JPanel; + +import com.fr.base.BaseUtils; +import com.fr.base.Parameter; +import com.fr.base.parameter.ParameterUI; +import com.fr.design.DesignModelAdapter; +import com.fr.design.designer.beans.actions.CopyAction; +import com.fr.design.designer.beans.actions.CutAction; +import com.fr.design.designer.beans.actions.FormDeleteAction; +import com.fr.design.designer.beans.actions.PasteAction; +import com.fr.design.designer.beans.adapters.layout.FRAbsoluteLayoutAdapter; +import com.fr.design.designer.beans.events.DesignerEditListener; +import com.fr.design.designer.beans.events.DesignerEvent; +import com.fr.design.designer.beans.location.Direction; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XCreatorUtils; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWAbsoluteLayout; +import com.fr.design.designer.creator.XWParameterLayout; +import com.fr.design.designer.properties.FormWidgetAuthorityEditPane; +import com.fr.design.form.util.XCreatorConstants; +import com.fr.design.mainframe.AuthorityEditPane; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.EastRegionContainerPane; +import com.fr.design.mainframe.FormArea; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.FormDesignerModeForSpecial; +import com.fr.design.mainframe.FormParaPane; +import com.fr.design.mainframe.FormWidgetDetailPane; +import com.fr.design.mainframe.WidgetPropertyPane; +import com.fr.design.mainframe.WidgetToolBarPane; +import com.fr.design.parameter.ParaDefinitePane; +import com.fr.design.parameter.ParameterDesignerProvider; +import com.fr.design.parameter.ParameterPropertyPane; +import com.fr.form.main.Form; +import com.fr.form.main.parameter.FormParameterUI; +import com.fr.form.parameter.FormSubmitButton; +import com.fr.form.ui.EditorHolder; +import com.fr.form.ui.WidgetValue; +import com.fr.form.ui.container.WAbsoluteLayout; +import com.fr.form.ui.container.WLayout; +import com.fr.form.ui.container.WParameterLayout; +import com.fr.general.Inter; +import com.fr.stable.ArrayUtils; + +/** + * Created by IntelliJ IDEA. + * User : Richer + * Version: 6.5.5 + * Date : 11-7-5 + * Time : 下午7:46 + * 表单类型的参数设计器 + */ +// TODO ALEX_SEP FormDesigner和FormParaDesignEditor应该共用Form的编辑,但是FormParaDesignEditor不应该直接就是FormDesigner +public class FormParaDesigner extends FormDesigner implements ParameterDesignerProvider { + private static final int NUM_IN_A_LINE = 4; + private static final int H_COMPONENT_GAP = 165; + private static final int V_COMPONENT_GAP = 25; + private static final int FIRST_V_LOCATION = 35; + private static final int FIRST_H_LOCATION = 90; + private static final int SECOND_H_LOCATION = 170; + private static final int ADD_HEIGHT = 20; + private static final int H_GAP = 105; + + private static Image paraImage = BaseUtils.readImage("/com/fr/design/images/form/parameter.png"); + + public FormParaDesigner() { + this(new FormParameterUI()); + } + + public FormParaDesigner(FormParameterUI ui) { + super(gen(ui)); + } + + private static Form gen(Form form) { + WLayout container = form.getContainer(); + if (container == null) { + container = new WParameterLayout(); + } + container.setWidgetName("para"); + form.setContainer(container); + return form; + } + + protected FormDesignerModeForSpecial createFormDesignerTargetMode() { + return new FormParaTargetMode(this); + } + + /** + * 开始编辑参数面板的时候进行的初始化 + */ + public void initBeforeUpEdit() { + WidgetToolBarPane.getInstance(this); + EastRegionContainerPane.getInstance().replaceDownPane( + FormWidgetDetailPane.getInstance(this)); + if (!BaseUtils.isAuthorityEditing()) { + EastRegionContainerPane.getInstance().addParameterPane(ParameterPropertyPane.getInstance(this)); + EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance(this).getPreferredSize().height); + EastRegionContainerPane.getInstance().replaceUpPane( + WidgetPropertyPane.getInstance(this)); + } else { + EastRegionContainerPane.getInstance().removeParameterPane(); + showAuthorityEditPane(); + } + + } + + /** + * 创建权限编辑面板 + * + * @return 面板 + */ + public AuthorityEditPane createAuthorityEditPane() { + return new FormWidgetAuthorityEditPane(this); + } + + /** + * 内容属性表面板 + * + * @return 内容属性表面板 + */ + public JPanel getEastUpPane() { + return WidgetPropertyPane.getInstance(this); + } + + /** + * 参数属性表 + * + * @return 参数属性表 + */ + + public JPanel getEastDownPane() { + return FormWidgetDetailPane.getInstance(this); + } + + /** + * 权限编辑面板 + * + * @return 权限编辑面板 + */ + public AuthorityEditPane getAuthorityEditPane() { + FormWidgetAuthorityEditPane formWidgetAuthorityEditPane = new FormWidgetAuthorityEditPane(this); + formWidgetAuthorityEditPane.populateDetials(); + return formWidgetAuthorityEditPane; + } + + /** + * 给包含此FormParaDesigner的ParameterDefinitePane添加事件 + * + * @param paraDefinitePane 面板 + */ + public void addListener(final ParaDefinitePane paraDefinitePane) { + this.getEditListenerTable().addListener(new DesignerEditListener() { + + @Override + public void fireCreatorModified(DesignerEvent evt) { + if (evt.getCreatorEventID() == DesignerEvent.CREATOR_ADDED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_CUTED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_RENAMED) { + paraDefinitePane.setParameterArray( + paraDefinitePane.getNoRepeatParas(DesignModelAdapter.getCurrentModelAdapter().getParameters())); + paraDefinitePane.refreshParameter(); + } + } + }); + } + + /** + * 包裹一层FormArea + * + * @return 区域 + */ + public Component createWrapper() { + FormArea area = new FormArea(this, false); + area.setBorder(BorderFactory.createEmptyBorder(0, 13, 0, 0)); + return area; + } + + /** + * 刷新控件 + */ + public void refreshAllNameWidgets() { + XCreatorUtils.refreshAllNameWidgets(this.getRootComponent()); + } + + /** + * 刷新tableData + * + * @param oldName 旧名称 + * @param newName 新名称 + */ + public void refresh4TableData(String oldName, String newName) { + this.getTarget().renameTableData(oldName, newName); + this.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_SELECTED); + } + + /** + * 刷新参数 + * + * @param p 参数面板 + */ + public void refreshParameter(ParaDefinitePane p) { + XLayoutContainer rootContainer = this.getRootComponent(); + java.util.List namelist = getAllXCreatorNameList(rootContainer); + // parameterArray是报表的所有参数, nameList是已经在参数面板添加过控件的参数名 + // 与已有的参数列表比较 如果已经存在 就除去 + Parameter[] ps = p.getParameterArray(); + if (ps != null) { + for (Parameter parameter : ps) { + for (String name : namelist) { + if (name.equalsIgnoreCase(parameter.getName())) { + p.setParameterArray((Parameter[]) ArrayUtils.removeElement(p.getParameterArray(), parameter)); + } + } + } + } + ParameterPropertyPane.getInstance().getParameterToolbarPane().populateBean( + p.getParameterArray() == null ? new Parameter[0] : p.getParameterArray()); + EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance().getPreferredSize().height); + + } + + /** + * 判断这个参数面板是否没有控件 + * + * @return 参数面板是否没有控件 + */ + public boolean isBlank() { + XLayoutContainer rootContainer = this.getRootComponent(); + List xx = getAllXCreatorNameList(rootContainer); + return xx.isEmpty(); + } + + protected void setToolbarButtons(boolean flag) { + DesignerContext.getDesignerFrame().checkCombineUp(!flag, NAME_ARRAY_LIST); + } + + /** + * 看看参数面板中的控件是否有和模板参数同名的 + * + * @param allParameters 参数 + * @return 是否有同名 + */ + public boolean isWithoutParaXCreator(Parameter[] allParameters) { + XLayoutContainer rootContainer = this.getRootComponent(); + List xx = getAllXCreatorNameList(rootContainer); + for (Parameter parameter : allParameters) { + for (String name : xx) { + if (name.equalsIgnoreCase(parameter.getName())) { + return false; + } + } + } + + return true; + } + + /** + * 参数面板控件的名字 + * + * @return 名字 + */ + public List getAllXCreatorNameList() { + XLayoutContainer rootContainer = this.getRootComponent(); + List namelist = new ArrayList(); + for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { + if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { + namelist.addAll(getAllXCreatorNameList((XLayoutContainer) rootContainer.getXCreator(i))); + } else { + namelist.add(rootContainer.getXCreator(i).toData().getWidgetName()); + } + } + return namelist; + } + + private List getAllXCreatorNameList(XLayoutContainer rootContainer) { + List namelist = new ArrayList(); + for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { + if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { + namelist.addAll(getAllXCreatorNameList((XLayoutContainer) rootContainer.getXCreator(i))); + } else { + namelist.add(rootContainer.getXCreator(i).toData().getWidgetName()); + } + } + return namelist; + } + + /** + * 是否有查询按钮 + * + * @return 有无查询按钮 + */ + public boolean isWithQueryButton() { + XLayoutContainer rootContainer = this.getRootComponent(); + return searchQueryCreators(rootContainer); + } + + /** + * 返回复制粘贴删除等动作 + * + * @return 同上 + */ + public Action[] getActions() { + if (designerActions == null) { + designerActions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this), + new FormDeleteAction(this)}; + } + return designerActions; + } + + private boolean searchQueryCreators(XLayoutContainer rootContainer) { + boolean b = false; + for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { + if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { + b = searchQueryCreators((XLayoutContainer) rootContainer.getXCreator(i)); + } else if (rootContainer.getXCreator(i) instanceof XFormSubmit) { + b = true; + } + } + return b; + } + + /** + * 就是getTarget 为了返回ParameterUI接口而不冲突另写个 + * + * @return + */ + public ParameterUI getParaTarget() { + return (FormParameterUI) super.getTarget(); + } + + /** + * ParameterDefinitePane通过ParaDesigner来调用ParameterPropertyPane + * + * @param p 面板 + */ + public void populateParameterPropertyPane(ParaDefinitePane p) { + ParameterPropertyPane.getInstance().populateBean(p); + } + + /** + * 初始化 + */ + public void initWidgetToolbarPane() { + WidgetToolBarPane.getInstance(this); + } + + /** + * populate + * + * @param ui + */ + public void populate(ParameterUI ui) { + if (ui == null) { + return; + } + if (this.getTarget() == ui) { + repaint(); + return; + } + this.setTarget((FormParameterUI) ui.convert()); + this.refreshRoot(); + } + + /** + * 报表直接判断底层是否是绝对布局 + * + * @return 是则返回true + */ + public boolean hasWAbsoluteLayout() { + return this.getTarget().getContainer() instanceof WAbsoluteLayout; + } + + /** + * 刷新底层容器 + */ + public void refreshRoot() { + XLayoutContainer layoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(this.getTarget() + .getContainer()); + if (layoutContainer == null) { + layoutContainer = new XWParameterLayout(); + } + layoutContainer.setSize(LARGE_PREFERRED_SIZE); + setRootComponent(layoutContainer); + } + + /** + * 是否是报表的参数面板 + * + * @return 是 + */ + public boolean isFormParaDesigner() { + return true; + } + + public XLayoutContainer getParaComponent() { + return getRootComponent(); + } + + private void paintLinkParameters(Graphics clipg) { + Parameter[] paras = DesignModelAdapter.getCurrentModelAdapter().getParameters(); + if (paras == null || paras.length == 0) { + return; + } + Graphics g = clipg.create(); + g.setColor(Color.RED); + if (!(this.getRootComponent() instanceof XWAbsoluteLayout)) { + return; + } + XWAbsoluteLayout layout = (XWAbsoluteLayout) this.getRootComponent(); + for (int i = 0; i < layout.getXCreatorCount(); i++) { + XCreator creator = layout.getXCreator(i); + if (!creator.isVisible()) { + continue; + } + for (Parameter p : paras) { + if (p.getName().equalsIgnoreCase(creator.toData().getWidgetName())) { + g.drawImage(paraImage, creator.getX() - 4, creator.getY() + 2, null); + break; + } + } + } + } + + /** + * 得到合适的大小 + * + * @return + */ + public Dimension getPreferredSize() { + return getDesignSize(); + } + + public Dimension getDesignSize() { + return ((FormParameterUI) getTarget()).getDesignSize(); + } + + /** + * 设置高度 + * + * @param height + */ + public void setDesignHeight(int height) { + Dimension dim = getPreferredSize(); + dim.height = height; + ((FormParameterUI) getTarget()).setDesignSize(dim); + } + + /** + * paintContent + * + * @param clipg + */ + public void paintContent(Graphics clipg) { + Dimension dim; + dim = ((FormParameterUI) getTarget()).getDesignSize(); + getRootComponent().setSize(dim); + getRootComponent().paint(clipg); + paintLinkParameters(clipg); + paintOp(clipg, getOutlineBounds()); + } + + private void paintOp(Graphics offg, Rectangle bounds) { + Color oldColor = offg.getColor(); + Insets insets = getOutlineInsets(); + offg.setColor(XCreatorConstants.OP_COLOR); + offg.fillRect(bounds.x, bounds.y + bounds.height, bounds.width + insets.right, insets.bottom); + offg.fillRect(bounds.x + bounds.width, bounds.y, insets.right, bounds.height); + offg.setColor(oldColor); + } + + protected void setRootComponent(XLayoutContainer component) { + component.setDirections(new int[]{Direction.BOTTOM, Direction.RIGHT}); + super.setRootComponent(component); + } + + /** + * 刷新尺寸 + */ + public void populateRootSize() { + ((FormParameterUI) getTarget()).setDesignSize(getRootComponent().getSize()); + if (getParaComponent().acceptType(XWParameterLayout.class)) { + WParameterLayout layout = (WParameterLayout) getParaComponent().toData(); + layout.setDesignWidth(getRootComponent().getWidth()); + } + } + + /** + * 保存参数界面的宽度 + * + * @param width 指定的宽度 + */ + public void updateWidth(int width) { + FormParameterUI parameterUI = ((FormParameterUI) getTarget()); + parameterUI.setDesignSize(new Dimension(width, parameterUI.getDesignSize().height)); + } + + /** + * 保存参数界面的高度 + * + * @param height 指定的高度 + */ + public void updateHeight(int height) { + FormParameterUI parameterUI = ((FormParameterUI) getTarget()); + parameterUI.setDesignSize(new Dimension(parameterUI.getDesignSize().width, height)); + } + + /** + * 在参数很多时,全部添加的时候,可以向下一次排版,若去掉就会在参数面板堆到一起 + * + * @param creator 组件 z + * @param x 长度 + * @param y 长度 c + * @param layout 布局 + * @return 是否扩展 + */ + public boolean prepareForAdd(XCreator creator, int x, int y, XWAbsoluteLayout layout) { + // 参数界面,自动扩展 + if (!isRoot(layout)) { + return false; + } + + Dimension size = layout.getSize(); + Boolean needResize = false; + + if (creator.getWidth() / 2 + x > layout.getWidth()) { + size.width = creator.getWidth() / 2 + x + ADD_HEIGHT; + needResize = true; + } + if (creator.getHeight() / 2 + y > layout.getHeight()) { + size.height = creator.getHeight() / 2 + y + ADD_HEIGHT; + needResize = true; + } + if (needResize) { + layout.setSize(size); + populateRootSize(); + } + return true; + } + + /** + * 加入参数 + * + * @param parameter 参数 c + * @param currentIndex 位置 w + * @return 是否加入 s + */ + public boolean addingParameter2Editor(Parameter parameter, int currentIndex) { + com.fr.form.ui.Label label = new com.fr.form.ui.Label(); + String name = parameter.getName(); + label.setWidgetName("Label" + name); + label.setWidgetValue(new WidgetValue(name + ":")); + XCreator xCreator = XCreatorUtils.createXCreator(label); + if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + + FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { + return false; + } + EditorHolder editor = new EditorHolder(parameter); + xCreator = XCreatorUtils.createXCreator(editor); + if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + + SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { + return false; + } + return true; + } + + + /** + * 加入参数 + * + * @param parameter 参数 c + * @param currentIndex 位置 w + * @return 是否加入 s + */ + public boolean addingParameter2EditorWithQueryButton(Parameter parameter, int currentIndex) { + com.fr.form.ui.Label label = new com.fr.form.ui.Label(); + String name = parameter.getName(); + label.setWidgetName("Label" + name); + label.setWidgetValue(new WidgetValue(name + ":")); + XCreator xCreator = XCreatorUtils.createXCreator(label); + if (!(this.autoAddComponent(xCreator, FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP + * (currentIndex / NUM_IN_A_LINE)))) { + return false; + } + EditorHolder editor = new EditorHolder(parameter); + editor.setWidgetName(name); + xCreator = XCreatorUtils.createXCreator(editor); + if (!(this.autoAddComponent(xCreator, SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP + * (currentIndex / NUM_IN_A_LINE)))) { + return false; + } + FormSubmitButton formSubmitButton = new FormSubmitButton(); + formSubmitButton.setWidgetName("Search"); + formSubmitButton.setText(Inter.getLocText("FR-Designer_Query")); + xCreator = XCreatorUtils.createXCreator(formSubmitButton); + if (!(this.autoAddComponent(xCreator, 270, FIRST_V_LOCATION + V_COMPONENT_GAP + * (currentIndex / NUM_IN_A_LINE)))) { + return false; + } + return true; + } + + /** + * 加入参数 + * + * @param parameterArray 参数 c + * @param currentIndex 位置 w + * @return 是否加入 s + */ + public void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex) { + for (int i = 0; i < parameterArray.length; i++) { + com.fr.form.ui.Label label = new com.fr.form.ui.Label(); + label.setWidgetName("Label" + parameterArray[i].getName()); + label.setWidgetValue(new WidgetValue(parameterArray[i].getName() + ":")); + XCreator xCreator = XCreatorUtils.createXCreator(label); + + if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + + FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { + break; + } + // 每行显示5组 + EditorHolder editor = new EditorHolder(parameterArray[i]); + editor.setWidgetName(parameterArray[i].getName()); + xCreator = XCreatorUtils.createXCreator(editor); + if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + + SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { + break; + } + currentIndex++; + } + if (!isWithQueryButton()) { + FormSubmitButton formSubmitButton = new FormSubmitButton(); + formSubmitButton.setWidgetName("Search"); + formSubmitButton.setText(Inter.getLocText("FR-Designer_Query")); + XCreator xCreator = XCreatorUtils.createXCreator(formSubmitButton); + if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * 3 + H_GAP, FIRST_V_LOCATION + + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { + return; + } + } + } + + /** + * 自动添加 + * + * @param xCreator 组件 z + * @param x 位置 w + * @param y 位置 + * @return 是否添加 s + */ + public boolean autoAddComponent(XCreator xCreator, int x, int y) { + XWAbsoluteLayout layout = (XWAbsoluteLayout) this.getRootComponent(); + FRAbsoluteLayoutAdapter adapter = (FRAbsoluteLayoutAdapter) layout.getLayoutAdapter(); + if (prepareForAdd(xCreator, x, y, layout)) { + adapter.addBean(xCreator, x, y); + } + this.getSelectionModel().setSelectedCreator(xCreator); + repaint(); + return true; + } + + /** + * 工具栏 + * + * @return 工具栏面板 g + */ + public JPanel[] toolbarPanes4Form() { + return new JPanel[]{FormParaPane.getInstance(this)}; + } + + /** + * 复制等按钮 + * + * @return 按钮组 a + */ + public JComponent[] toolBarButton4Form() { + return new JComponent[]{new CutAction(this).createToolBarComponent(), new CopyAction(this).createToolBarComponent(), new PasteAction(this).createToolBarComponent(), + new FormDeleteAction(this).createToolBarComponent()}; + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/gui/xtable/PropertyGroupModel.java b/designer_form/src/com/fr/design/gui/xtable/PropertyGroupModel.java index 8e8cadad1..bb0f0cd3a 100644 --- a/designer_form/src/com/fr/design/gui/xtable/PropertyGroupModel.java +++ b/designer_form/src/com/fr/design/gui/xtable/PropertyGroupModel.java @@ -53,6 +53,9 @@ public class PropertyGroupModel extends AbstractPropertyGroupModel { if(ComparatorUtils.equals(FormConstants.NAME, properties[row].getName())){ creator.resetCreatorName(value.toString()); } + if(ComparatorUtils.equals("visible", properties[row].getName())){ + creator.resetVisible((boolean) value); + } properties[row].firePropertyChanged(); return true; } catch (Exception e) { diff --git a/designer_form/src/com/fr/design/mainframe/ComponentTree.java b/designer_form/src/com/fr/design/mainframe/ComponentTree.java index 4d58c4887..1ceab13c0 100644 --- a/designer_form/src/com/fr/design/mainframe/ComponentTree.java +++ b/designer_form/src/com/fr/design/mainframe/ComponentTree.java @@ -1,21 +1,14 @@ package com.fr.design.mainframe; import java.awt.Component; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; import java.util.ArrayList; import javax.swing.DropMode; -import javax.swing.JPopupMenu; import javax.swing.JTree; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; import com.fr.design.constants.UIConstants; -import com.fr.design.designer.beans.AdapterBus; -import com.fr.design.designer.beans.ComponentAdapter; -import com.fr.design.designer.beans.events.DesignerEditListener; -import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.creator.*; import com.fr.design.designer.treeview.ComponentTreeCellRenderer; import com.fr.design.designer.treeview.ComponentTreeModel; @@ -92,9 +85,9 @@ public class ComponentTree extends JTree { } } - public void setAndScrollSelectionPath(TreePath treepath) { - setSelectionPath(treepath); - scrollPathToVisible(treepath); + public void setAndScrollSelectionPath(TreePath[] treepath) { + setSelectionPaths(treepath); + scrollPathToVisible(treepath[0]); } @@ -112,7 +105,6 @@ public class ComponentTree extends JTree { public TreePath[] getSelectedTreePath() { XCreator[] creators = designer.getSelectionModel().getSelection().getSelectedCreators(); TreePath[] paths = new TreePath[creators.length]; - for (int i = 0; i < paths.length; i++) { paths[i] = buildTreePath(creators[i]); } @@ -141,7 +133,7 @@ public class ComponentTree extends JTree { paths[i] = buildTreePath(searchList.get(i)); } if(paths.length > 0) { - setAndScrollSelectionPath(paths[0]); + setAndScrollSelectionPath(paths); } else { setSelectionPath(); } @@ -217,4 +209,5 @@ public class ComponentTree extends JTree { Object[] components = path.toArray(); return new TreePath(components); } + } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/ConnectorHelper.java b/designer_form/src/com/fr/design/mainframe/ConnectorHelper.java index e592a48c9..215ff8036 100644 --- a/designer_form/src/com/fr/design/mainframe/ConnectorHelper.java +++ b/designer_form/src/com/fr/design/mainframe/ConnectorHelper.java @@ -7,104 +7,104 @@ import java.awt.Rectangle; import java.awt.event.MouseEvent; import java.util.ArrayList; +import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.stable.Constants; import com.fr.base.GraphHelper; import com.fr.design.designer.beans.ConnectorCreator; import com.fr.design.designer.creator.XWAbsoluteLayout; import com.fr.form.ui.Connector; -import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; public class ConnectorHelper { - //这个类是用来画连接线的,暂时用不到 - - public static final int NEAR = 5; - private static double ratio = 0.5; - private ArrayList drawingPoint; - private FormDesigner designer; - private boolean drawing; + //这个类是用来画连接线的,暂时用不到 + + public static final int NEAR = 5; + private static double ratio = 0.5; + private final static int ADSORPTION = 15; // 吸附距离 + private ArrayList drawingPoint; + private FormDesigner designer; + private boolean drawing; + + public ConnectorHelper(FormDesigner formEditor) { + this.designer = formEditor; + } + + public void resetConnector(Connector connector) { + ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(), connector.getStartPoint(), connector.getEndPoint()); + connector.addAll(cc.createPointList()); + } + + public boolean drawLining() { + return this.drawing; + } + + public void setDrawLine(boolean d) { + this.drawing = d; + } - public ConnectorHelper(FormDesigner formEditor) { - this.designer = formEditor; - } - - public void resetConnector(Connector connector) { - ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(),connector.getStartPoint(),connector.getEndPoint()); - connector.addAll(cc.createPointList()); - } - - public boolean drawLining() { - return this.drawing; - } + private boolean near(Point p1, Point p2) { + return p1.x - p2.x < NEAR && p2.x - p1.x < NEAR && p1.y - p2.y < NEAR && p2.y - p1.y < NEAR; + } - public void setDrawLine(boolean d) { - this.drawing = d; - } - - private boolean near(Point p1, Point p2) { - return p1.x - p2.x < NEAR && p2.x - p1.x < NEAR && p1.y - p2.y < NEAR && p2.y - p1.y < NEAR; - } + private Point getNearPoint(MouseEvent e, Rectangle r) { + Point p1 = new Point((int) (r.x + r.getWidth() * ratio), r.y); + Point p2 = new Point((int) (r.x + r.getWidth()), (int) (r.y + r.getHeight() * ratio)); + Point p3 = new Point((int) (r.x + r.getWidth() * (1 - ratio)), (int) (r.y + r.getHeight())); + Point p4 = new Point(r.x, (int) (r.y + r.getHeight() * (1 - ratio))); + Point p = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() + designer.getArea().getVerticalValue()); + if (near(p, p1)) { + return p1; + } else if (near(p, p2)) { + return p2; + } else if (near(p, p3)) { + return p3; + } else if (near(p, p4)) { + return p4; + } + return null; + } - private Point getNearPoint(MouseEvent e, Rectangle r) { - Point p1 = new Point((int) (r.x + r.getWidth() * ratio), r.y); - Point p2 = new Point((int) (r.x + r.getWidth()), (int) (r.y + r.getHeight() * ratio)); - Point p3 = new Point((int) (r.x + r.getWidth() * (1 - ratio)), (int) (r.y + r.getHeight())); - Point p4 = new Point(r.x, (int) (r.y + r.getHeight() * (1 - ratio))); - Point p = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() + designer.getArea().getVerticalValue()); - if (near(p, p1)) { - return p1; - } else if (near(p, p2)) { - return p2; - } else if (near(p, p3)) { - return p3; - } else if (near(p, p4)) { - return p4; - } - return null; - } - - private ArrayList createDefalutNode(Point startPoint, Point endPoint) { - long s = System.currentTimeMillis(); - ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(), new Point(startPoint), new Point(endPoint)); - ArrayList p = cc.createPointList(); - long e = System.currentTimeMillis(); - System.out.println("useTime:" + (e - s)); - return p; - } + private ArrayList createDefalutNode(Point startPoint, Point endPoint) { + long s = System.currentTimeMillis(); + ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(), new Point(startPoint), new Point(endPoint)); + ArrayList p = cc.createPointList(); + long e = System.currentTimeMillis(); + return p; + } - public void drawAuxiliaryLine(Graphics g) { - Point startPoint = designer.getStateModel().getStartPoint(); - Point endPoint = designer.getStateModel().getEndPoint(); - drawingPoint = createDefalutNode(startPoint, endPoint); - Point[] p = drawingPoint.toArray(new Point[drawingPoint.size()]); - g.setColor(Color.green); - for (int i = 0; i < p.length - 1; i++) { - GraphHelper.drawLine(g, p[i].x - designer.getArea().getHorizontalValue(), p[i].y - - designer.getArea().getVerticalValue(), p[i + 1].x - designer.getArea().getHorizontalValue(), - p[i + 1].y - designer.getArea().getVerticalValue(), Constants.LINE_HAIR); - } - } + public void drawAuxiliaryLine(Graphics g) { + Point startPoint = designer.getStateModel().getStartPoint(); + Point endPoint = designer.getStateModel().getEndPoint(); + drawingPoint = createDefalutNode(startPoint, endPoint); + Point[] p = drawingPoint.toArray(new Point[drawingPoint.size()]); + g.setColor(Color.green); + for (int i = 0; i < p.length - 1; i++) { + GraphHelper.drawLine(g, p[i].x - designer.getArea().getHorizontalValue(), p[i].y + - designer.getArea().getVerticalValue(), p[i + 1].x - designer.getArea().getHorizontalValue(), + p[i + 1].y - designer.getArea().getVerticalValue(), Constants.LINE_HAIR); + } + } - public void createDefalutLine() { - if (drawingPoint != null - && drawingPoint.size() > 1 - && ConnectorCreator.getMinimumDistance(drawingPoint.get(0), drawingPoint.get(drawingPoint.size() - 1)) > 15) { - ((XWAbsoluteLayout) designer.getRootComponent()).addConnector(new Connector().addAll(drawingPoint)); - } - drawingPoint = null; - } + public void createDefalutLine() { + if (drawingPoint != null + && drawingPoint.size() > 1 + && ConnectorCreator.getMinimumDistance(drawingPoint.get(0), drawingPoint.get(drawingPoint.size() - 1)) > ADSORPTION) { + ((XWAbsoluteLayout) designer.getRootComponent()).addConnector(new Connector().addAll(drawingPoint)); + } + drawingPoint = null; + } - public Point getNearWidgetPoint(MouseEvent e) { - BoundsWidget widget; - Point p = null; - for (int i = 0, size = designer.getTarget().getContainer().getWidgetCount(); i < size; i++) { - widget = ((BoundsWidget) designer.getTarget().getContainer().getWidget(i)); - if (widget.isVisible()) { - if ((p = getNearPoint(e, widget.getBounds())) != null) { - break; - } - } - } - return p; - } + public Point getNearWidgetPoint(MouseEvent e) { + BoundsWidget widget; + Point p = null; + for (int i = 0, size = designer.getTarget().getContainer().getWidgetCount(); i < size; i++) { + widget = ((BoundsWidget) designer.getTarget().getContainer().getWidget(i)); + if (widget.isVisible()) { + if ((p = getNearPoint(e, widget.getBounds())) != null) { + break; + } + } + } + return p; + } } \ 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 0f916dd1d..61323f4b7 100644 --- a/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java +++ b/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java @@ -1,612 +1,621 @@ -package com.fr.design.mainframe; - -import com.fr.base.BaseUtils; -import com.fr.design.beans.location.MoveUtils; -import com.fr.design.designer.beans.AdapterBus; -import com.fr.design.designer.beans.ComponentAdapter; -import com.fr.design.designer.beans.events.DesignerEditor; -import com.fr.design.designer.beans.events.DesignerEvent; -import com.fr.design.designer.beans.location.Direction; -import com.fr.design.designer.beans.location.Location; -import com.fr.design.designer.beans.models.SelectionModel; -import com.fr.design.designer.beans.models.StateModel; -import com.fr.design.designer.creator.*; -import com.fr.design.form.util.XCreatorConstants; -import com.fr.design.gui.ibutton.UIButton; -import com.fr.design.gui.xpane.ToolTipEditor; -import com.fr.design.icon.IconPathConstants; -import com.fr.design.utils.ComponentUtils; -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; - -/** - * 普通模式下的鼠标点击、位置处理器 - */ -public class EditingMouseListener extends MouseInputAdapter { - - private static final int INDEX = 0; - private FormDesigner designer; - - /** - * 普通模式下对应的model - */ - private StateModel stateModel; - - - private XLayoutContainer xTopLayoutContainer; - private XLayoutContainer clickTopLayout; - - /** - * 获取表单设计器 - * - * @return 表单设计器 - */ - public FormDesigner getDesigner() { - return designer; - } - - /** - * 选择模型,存储当前选择的组件和剪切板 - */ - private SelectionModel selectionModel; - /** - * 获取选择模型 - * - * @return 选择 - */ - public SelectionModel getSelectionModel() { - return selectionModel; - } - - private XCreator last_creator; - private MouseEvent lastPressEvent; - private DesignerEditor current_editor; - private XCreator current_creator; - - //备份开始拖动的位置和大小 - private Rectangle dragBackupBounds; - - /** - * 获取最小移动距离 - * - * @return 最小移动距离 - */ - public int getMinMoveSize() { - return minMoveSize; - } - - private int minDragSize = 5; - private int minMoveSize = 8; - - private static final int EDIT_BTN_WIDTH = 60; - private static final int EDIT_BTN_HEIGHT = 24; - //报表块的编辑按钮不灵敏,范围扩大一点 - private static final int GAP = 10; - - private XElementCase xElementCase; - private XChartEditor xChartEditor; - - private JWindow promptWindow = new JWindow(); - - public EditingMouseListener(FormDesigner designer) { - this.designer = designer; - stateModel = designer.getStateModel(); - selectionModel = designer.getSelectionModel(); - UIButton promptButton = new UIButton(Inter.getLocText("FR-Designer_Forbid_Drag_into_Adapt_Pane"), BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); - this.promptWindow.add(promptButton); - } - - private void promptUser(int x, int y, XLayoutContainer container){ - if (!selectionModel.getSelection().getSelectedCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)){ - promptWidgetForbidEnter(x ,y , container); - } else { - cancelPromptWidgetForbidEnter(); - } - } - - 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(); - this.promptWindow.setSize(promptWindow.getPreferredSize()); - this.promptWindow.setPreferredSize(promptWindow.getPreferredSize()); - promptWindow.setLocation(screen_X + x + GAP, screen_Y + y + GAP); - promptWindow.setVisible(true); - } - - private void cancelPromptWidgetForbidEnter(){ - designer.getRootComponent().setBorder(BorderFactory.createLineBorder(XCreatorConstants.LAYOUT_SEP_COLOR, Constants.LINE_THIN)); - promptWindow.setVisible(false); - } - - - /** - * 按下 - * @param e 鼠标事件 - */ - public void mousePressed(MouseEvent e) { - if (!stopEditing()) { - return; - } - if (!designer.isFocusOwner()) { - // 获取焦点,以便获取热键 - designer.requestFocus(); - } - if (e.isPopupTrigger()) { - // 为触发上下文菜单预留 - } else if (e.getButton() == MouseEvent.BUTTON1) { - - Direction dir = selectionModel.getDirectionAt(e); - if (!BaseUtils.isAuthorityEditing()) { - stateModel.setDirection(dir); - } - - if (dir == Location.outer) { - if (designer.isDrawLineMode()) { - designer.updateDrawLineMode(e); - } else { - if (selectionModel.hasSelectionComponent() - && selectionModel.getSelection().getRelativeBounds().contains( - designer.getArea().getHorizontalValue() + e.getX(), - designer.getArea().getVerticalValue() + e.getY())) { - lastPressEvent = e; - last_creator = selectionModel.getSelection().getSelectedCreator(); - } else { - stateModel.startSelecting(e); - } - } - } else { - stateModel.startResizing(e); - } - } - } - - /** - * 释放 - * @param e 鼠标事件 - */ - public void mouseReleased(MouseEvent e) { - if (e.isPopupTrigger()) { - if (stateModel.isDragging()) { - stateModel.draggingCancel(); - } - } else { - if (designer.isDrawLineMode()) { - if (stateModel.prepareForDrawLining()) { - designer.getDrawLineHelper().setDrawLine(false); - designer.getDrawLineHelper().createDefalutLine(); - } - } else if (stateModel.isSelecting()) { - // 如果当前是区域选择状态,则选择该区域所含的组件 - designer.selectComponents(e); - } - if (stateModel.isDragging()) { - // 当前鼠标所在的组件 - XCreator hoveredComponent = designer.getComponentAt(e.getX(), e.getY()); - if(designer.isWidgetsIntersect() && dragBackupBounds != null && hoveredComponent != null){ - XCreator selectionXCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); - if(selectionXCreator != null){ - selectionXCreator.setBounds(dragBackupBounds.x, dragBackupBounds.y, dragBackupBounds.width, dragBackupBounds.height); - MoveUtils.hideForbidWindow(); - } - } - dragBackupBounds = null; - // 拉伸时鼠标拖动过快,导致所在组件获取会为空 - if (hoveredComponent == null && e.getY() < 0) { - // bug63538 - // 不是拖动过快导致的,而是纵坐标为负值导致的,这时参照横坐标为负值时的做法,取边界位置的组件,为鼠标所在点的组件 - // 如果直接return,界面上已经进行了拖拽不能恢复 - hoveredComponent = designer.getComponentAt(0, 0); - } - // 获取该组件所在的焦点容器 - XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); - - if (container != null) { - boolean formSubmit2Adapt = !selectionModel.getSelection().getSelectedCreator().canEnterIntoAdaptPane() - && container.acceptType(XWFitLayout.class); - if ( !formSubmit2Adapt) { - // 如果是处于拖拽状态,则释放组件 - stateModel.releaseDragging(e); - } else { - selectionModel.deleteSelection(); - designer.setPainter(null); - } - cancelPromptWidgetForbidEnter(); - } - - } - } - lastPressEvent = null; - last_creator = null; - } - - /** - * 激活上下文菜单,待完善 - * 6.56暂时不支持右键 bugid 8777 - */ - private void trigger_popup(MouseEvent e) { - - XCreator creator = selectionModel.getSelection().getSelectedCreator(); - - if (creator == null) { - return; - } - - JPopupMenu popupMenu = null; - ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, creator); - popupMenu = adapter.getContextPopupMenu(e); - - if (popupMenu != null) { - popupMenu.show(designer, e.getX(), e.getY()); - } - // 通知组件已经被选择了 - designer.getEditListenerTable().fireCreatorModified(creator, DesignerEvent.CREATOR_SELECTED); - } - - /** - * 移动 - * @param e 鼠标事件 - */ - public void mouseMoved(MouseEvent e) { - XCreator component = designer.getComponentAt(e); - - setCoverPaneNotDisplay(e, false); - - if(processTopLayoutMouseMove(component, e)){ - return; - } - if (component instanceof XEditorHolder) { - XEditorHolder xcreator = (XEditorHolder) component; - Rectangle rect = xcreator.getBounds(); - int min = rect.x + rect.width / 2 - minMoveSize; - int max = rect.x + rect.width / 2 + minMoveSize; - if (e.getX() > min && e.getX() < max) { - if (designer.getCursor().getType() != Cursor.HAND_CURSOR) { - designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } - return; - } else { - if (designer.getCursor().getType() == Cursor.HAND_CURSOR) { - designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - } - } - Direction dir = selectionModel.getDirectionAt(e); - if (designer.isDrawLineMode() && stateModel.getDirection() == Location.outer) { - designer.updateDrawLineMode(e); - } - if (!BaseUtils.isAuthorityEditing()) { - stateModel.setDirection(dir); - } - - if (component.isReport()) { - xElementCase = (XElementCase)component; - UIButton button = (UIButton)xElementCase.getCoverPane().getComponent(0); - 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 minY = button.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 (xElementCase.getCoverPane().getComponentCount() > 1) { - JComponent button1 = (JComponent) xElementCase.getCoverPane().getComponent(1); - int minX1 = button1.getX() + getParentPositionX(component, 0) - designer.getArea().getHorizontalValue(); - int minY1 = button1.getY() + getParentPositionY(component, 0) - designer.getArea().getVerticalValue(); - 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(); - return; - } - - processChartEditorMouseMove(component, e); - - designer.repaint(); - } - - private void setCoverPaneNotDisplay(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; - } - if(isLinkedHelpDialog){ - xElementCase.destroyHelpDialog(); - } - xElementCase.displayCoverPane(false); - } - if (xChartEditor != null){ - xChartEditor.displayCoverPane(false); - } - - if (xTopLayoutContainer != null) { - xTopLayoutContainer.setMouseEnter(false); - } - designer.repaint(); - } - - private boolean processTopLayoutMouseMove(XCreator component, MouseEvent e){ - XLayoutContainer parent = XCreatorUtils.getHotspotContainer(component).getTopLayout(); - if (parent != null){ - xTopLayoutContainer = parent; - xTopLayoutContainer.setMouseEnter(true); - designer.repaint(); - if(!xTopLayoutContainer.isEditable()) { - if (designer.getCursor().getType() == Cursor.HAND_CURSOR) { - designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - int minX = getParentPositionX(parent, parent.getX()) + parent.getWidth() / 2; - int minY = getParentPositionY(parent, parent.getY()) + parent.getHeight() / 2; - int offsetX = EDIT_BTN_WIDTH / 2 + GAP; - int offsetY = EDIT_BTN_HEIGHT / 2 + GAP; - if (e.getX() > (minX - offsetX) && e.getX() < (minX + offsetX)) { - if (e.getY() > (minY - offsetY) && e.getY() < (minY + offsetY + designer.getParaHeight())) { - designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } - } - return true; - } - } - return false; - } - - private void processChartEditorMouseMove(XCreator component, MouseEvent e){ - if (component instanceof XChartEditor) { - xChartEditor = (XChartEditor)component; - UIButton button = (UIButton)xChartEditor.getCoverPane().getComponent(0); - if(designer.getCursor().getType() ==Cursor.HAND_CURSOR) { - designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - int minX = button.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)); - } - } - xChartEditor.displayCoverPane(true); - xChartEditor.setDirections(Direction.TOP_BOTTOM_LEFT_RIGHT); - designer.repaint(); - } - } - - private int getParentPositionX(XCreator comp, int x){ - return comp.getParent() == null ? - x : getParentPositionX((XCreator)comp.getParent(), comp.getParent().getX() + x); - } - - private int getParentPositionY(XCreator comp, int y) { - return comp.getParent() == null ? - y : getParentPositionY((XCreator) comp.getParent(), comp.getParent().getY() + y); - } - - /** - * 拖拽 - * @param e 鼠标事件 - */ - public void mouseDragged(MouseEvent e) { - if (BaseUtils.isAuthorityEditing()) { - return; - } - // 如果当前是左键拖拽状态,拖拽组件 - if (stateModel.dragable()) { - if (SwingUtilities.isRightMouseButton(e)) { - return; - } else { - stateModel.dragging(e); - // 获取e所在的焦点组件 - XCreator hotspot = designer.getComponentAt(e.getX(), e.getY()); - if(dragBackupBounds == null) { - XCreator selectingXCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); - if(selectingXCreator != null){ - dragBackupBounds = new Rectangle(selectingXCreator.getX(), selectingXCreator.getY(), selectingXCreator.getWidth(), selectingXCreator.getHeight()); - } - } - // 拉伸时鼠标拖动过快,导致所在组件获取会为空 - if (hotspot == null) { - return; - } - // 获取焦点组件所在的焦点容器 - XLayoutContainer container = XCreatorUtils.getHotspotContainer(hotspot); - //提示组件是否可以拖入 - promptUser(e.getX(), e.getY(), container); - } - } else if (designer.isDrawLineMode()) { - if (stateModel.prepareForDrawLining()) { - stateModel.drawLine(e); - } - } else if (stateModel.isSelecting() && (selectionModel.getHotspotBounds() != null)) { - // 如果是拖拽选择区域状态,则更新选择区域 - stateModel.changeSelection(e); - } else { - if ((lastPressEvent == null) || (last_creator == null)) { - return; - } - if (e.getPoint().distance(lastPressEvent.getPoint()) > minDragSize) { - //参数面板和自适应布局不支持拖拽 - if (last_creator.isSupportDrag()){ - designer.startDraggingComponent(last_creator, lastPressEvent, e.getX(), e.getY()); - } - e.consume(); - lastPressEvent = null; - } - } - designer.repaint(); - } - - //当前编辑的组件是在布局中,鼠标点击布局外部,需要一次性将布局及其父布局都置为不可编辑 - private void setTopLayoutUnEditable(XLayoutContainer clickedTopLayout, XLayoutContainer clickingTopLayout){ - //双击的前后点击click为相同对象,过滤掉 - if (clickedTopLayout == null || clickedTopLayout == clickingTopLayout){ - return; - } - //位于同一层级的控件,父布局相同,过滤掉 - if (clickingTopLayout != null && clickedTopLayout.getParent() == clickingTopLayout.getParent()){ - return; - } - //前后点击的位于不同层级,要置为不可编辑 - XLayoutContainer xLayoutContainer = (XLayoutContainer)clickedTopLayout.getParent(); - if (xLayoutContainer == clickingTopLayout){ - return; - } - if (xLayoutContainer != null){ - xLayoutContainer.setEditable(false); - setTopLayoutUnEditable((XLayoutContainer) clickedTopLayout.getParent(), clickingTopLayout); - } - } - - private boolean isCreatorInLayout(XCreator creator, XCreator layout){ - if (creator == layout){ - return true; - } - if(layout.getParent() != null){ - return isCreatorInLayout(creator, (XCreator)layout.getParent()); - } - return false; - } - - private XCreator processTopLayoutMouseClick(XCreator creator){ - XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(creator).getTopLayout(); - if(topLayout != null){ - if (clickTopLayout != null && clickTopLayout != topLayout && !isCreatorInLayout(clickTopLayout, topLayout)){ - clickTopLayout.setEditable(false); - setTopLayoutUnEditable(clickTopLayout, topLayout); - } - clickTopLayout = topLayout; - if(!topLayout.isEditable()) { - creator = topLayout; - } - } - else{ - if(clickTopLayout != null){ - clickTopLayout.setEditable(false); - setTopLayoutUnEditable(clickTopLayout, null); - } - } - - return creator; - } - /** - * 点击 - * @param e 鼠标事件 - */ - public void mouseClicked(MouseEvent e) { - if (e.getButton() != MouseEvent.BUTTON1) { - return; - } - XCreator creator = designer.getComponentAt(e); - - creator = processTopLayoutMouseClick(creator); - - if(creator != null){ - creator.respondClick(this, e); - } - creator.doLayout(); - LayoutUtils.layoutRootContainer(designer.getRootComponent()); - } - - - - /** - * 离开 - * @param e 鼠标事件 - */ - public void mouseExited(MouseEvent e) { - if (designer.getCursor().getType() != Cursor.DEFAULT_CURSOR) { - designer.setCursor(Cursor.getDefaultCursor()); - } - - setCoverPaneNotDisplay(e, true); - - cancelPromptWidgetForbidEnter(); - } - - /** - * 开始编辑 - * @param creator 容器 - * @param designerEditor 设计器 - * @param adapter 适配器 - */ - public void startEditing(XCreator creator, DesignerEditor designerEditor, ComponentAdapter adapter) { - if (designerEditor != null) { - Rectangle rect = ComponentUtils.getRelativeBounds(creator); - current_editor = designerEditor; - current_creator = creator; - Rectangle bounds = new Rectangle(1, 1, creator.getWidth() - 2, creator.getHeight() - 2); - bounds.x += (rect.x - designer.getArea().getHorizontalValue()); - bounds.y += (rect.y - designer.getArea().getVerticalValue()); - designerEditor.getEditorTarget().setBounds(bounds); - designer.add(designerEditor.getEditorTarget()); - designer.invalidate(); - designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - designerEditor.getEditorTarget().requestFocus(); - designer.repaint(); - } - } - - /** - * 停止编辑 - * @return 是否编辑成功 - */ - public boolean stopEditing() { - if (current_editor != null) { - designer.remove(current_editor.getEditorTarget()); - current_editor.fireEditStoped(); - - Container container = current_creator.getParent(); - - if (container != null) { - LayoutUtils.layoutRootContainer(container); - } - designer.invalidate(); - designer.repaint(); - current_creator = null; - current_editor = null; - return true; - } - return true; - } - - /** - * 重置编辑控件大小 - */ - public void resetEditorComponentBounds() { - if (current_editor == null) { - return; - } - - if (current_creator.getParent() == null) { - stopEditing(); - return; - } - - Rectangle rect = ComponentUtils.getRelativeBounds(current_creator); - Rectangle bounds = new Rectangle(1, 1, current_creator.getWidth() - 2, current_creator.getHeight() - 2); - bounds.x += (rect.x - designer.getArea().getHorizontalValue()); - bounds.y += (rect.y - designer.getArea().getVerticalValue()); - if (current_creator instanceof XEditorHolder) { - ToolTipEditor.getInstance().resetBounds((XEditorHolder) current_creator, bounds, current_editor.getEditorTarget().getBounds()); - } - current_editor.getEditorTarget().setBounds(bounds); - } +package com.fr.design.mainframe; + +import com.fr.base.BaseUtils; +import com.fr.design.designer.beans.AdapterBus; +import com.fr.design.designer.beans.ComponentAdapter; +import com.fr.design.designer.beans.events.DesignerEditor; +import com.fr.design.designer.beans.events.DesignerEvent; +import com.fr.design.designer.beans.location.Direction; +import com.fr.design.designer.beans.location.Location; +import com.fr.design.designer.beans.models.SelectionModel; +import com.fr.design.designer.beans.models.StateModel; +import com.fr.design.designer.creator.*; +import com.fr.design.designer.creator.cardlayout.XCardSwitchButton; +import com.fr.design.form.util.XCreatorConstants; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.xpane.ToolTipEditor; +import com.fr.design.icon.IconPathConstants; +import com.fr.design.utils.ComponentUtils; +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; + +/** + * 普通模式下的鼠标点击、位置处理器 + */ +public class EditingMouseListener extends MouseInputAdapter { + + private FormDesigner designer; + + /** + * 普通模式下对应的model + */ + private StateModel stateModel; + + + private XLayoutContainer xTopLayoutContainer; + private XLayoutContainer clickTopLayout; + + /** + * 获取表单设计器 + * + * @return 表单设计器 + */ + public FormDesigner getDesigner() { + return designer; + } + + /** + * 选择模型,存储当前选择的组件和剪切板 + */ + private SelectionModel selectionModel; + + /** + * 获取选择模型 + * + * @return 选择 + */ + public SelectionModel getSelectionModel() { + return selectionModel; + } + + private XCreator lastXCreator; + private MouseEvent lastPressEvent; + private DesignerEditor currentEditor; + private XCreator currentXCreator; + + //备份开始拖动的位置和大小 + private Rectangle dragBackupBounds; + + /** + * 获取最小移动距离 + * + * @return 最小移动距离 + */ + public int getMinMoveSize() { + return minMoveSize; + } + + private int minDragSize = 5; + private int minMoveSize = 8; + + private static final int EDIT_BTN_WIDTH = 60; + private static final int EDIT_BTN_HEIGHT = 24; + //报表块的编辑按钮不灵敏,范围扩大一点 + private static final int GAP = 10; + + private XElementCase xElementCase; + private XChartEditor xChartEditor; + + private JWindow promptWindow = new JWindow(); + + public EditingMouseListener(FormDesigner designer) { + this.designer = designer; + stateModel = designer.getStateModel(); + selectionModel = designer.getSelectionModel(); + UIButton promptButton = new UIButton(Inter.getLocText("FR-Designer_Forbid_Drag_into_Adapt_Pane"), BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); + this.promptWindow.add(promptButton); + } + + private void promptUser(int x, int y, XLayoutContainer container) { + if (!selectionModel.getSelection().getSelectedCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)) { + promptWidgetForbidEnter(x, y, container); + } else { + cancelPromptWidgetForbidEnter(); + } + } + + private void promptWidgetForbidEnter(int x, int y, XLayoutContainer container) { + container.setBorder(BorderFactory.createLineBorder(Color.RED, Constants.LINE_MEDIUM)); + int screenX = (int) designer.getArea().getLocationOnScreen().getX(); + int screenY = (int) designer.getArea().getLocationOnScreen().getY(); + this.promptWindow.setSize(promptWindow.getPreferredSize()); + this.promptWindow.setPreferredSize(promptWindow.getPreferredSize()); + promptWindow.setLocation(screenX + x + GAP, screenY + y + GAP); + promptWindow.setVisible(true); + } + + private void cancelPromptWidgetForbidEnter() { + designer.getRootComponent().setBorder(BorderFactory.createLineBorder(XCreatorConstants.LAYOUT_SEP_COLOR, Constants.LINE_THIN)); + promptWindow.setVisible(false); + } + + + /** + * 按下 + * + * @param e 鼠标事件 + */ + public void mousePressed(MouseEvent e) { + if (!stopEditing()) { + return; + } + if (!designer.isFocusOwner()) { + // 获取焦点,以便获取热键 + designer.requestFocus(); + } + if (e.getButton() == MouseEvent.BUTTON1) { + + Direction dir = selectionModel.getDirectionAt(e); + if (!BaseUtils.isAuthorityEditing()) { + stateModel.setDirection(dir); + } + + if (dir == Location.outer) { + if (designer.isDrawLineMode()) { + designer.updateDrawLineMode(e); + } else { + if (selectionModel.hasSelectionComponent() + && selectionModel.getSelection().getRelativeBounds().contains( + designer.getArea().getHorizontalValue() + e.getX(), + designer.getArea().getVerticalValue() + e.getY())) { + lastPressEvent = e; + lastXCreator = selectionModel.getSelection().getSelectedCreator(); + } else { + stateModel.startSelecting(e); + } + } + } else { + stateModel.startResizing(e); + } + } + } + + /** + * 释放 + * + * @param e 鼠标事件 + */ + public void mouseReleased(MouseEvent e) { + if (e.isPopupTrigger()) { + if (stateModel.isDragging()) { + stateModel.draggingCancel(); + } + } else { + if (designer.isDrawLineMode()) { + if (stateModel.prepareForDrawLining()) { + designer.getDrawLineHelper().setDrawLine(false); + designer.getDrawLineHelper().createDefalutLine(); + } + } else if (stateModel.isSelecting()) { + // 如果当前是区域选择状态,则选择该区域所含的组件 + designer.selectComponents(e); + } + if (stateModel.isDragging()) { + mouseDraggingRelease(e); + } + } + lastPressEvent = null; + lastXCreator = null; + } + + private void mouseDraggingRelease(MouseEvent e) { + // 当前鼠标所在的组件 + XCreator hoveredComponent = designer.getComponentAt(e.getX(), e.getY()); + if (designer.isWidgetsIntersect() && dragBackupBounds != null && hoveredComponent != null) { + XCreator selectionXCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); + if (selectionXCreator != null) { + selectionXCreator.setBounds(dragBackupBounds.x, dragBackupBounds.y, dragBackupBounds.width, dragBackupBounds.height); + } + } + dragBackupBounds = null; + // 拉伸时鼠标拖动过快,导致所在组件获取会为空 + if (hoveredComponent == null && e.getY() < 0) { + // bug63538 + // 不是拖动过快导致的,而是纵坐标为负值导致的,这时参照横坐标为负值时的做法,取边界位置的组件,为鼠标所在点的组件 + // 如果直接return,界面上已经进行了拖拽不能恢复 + hoveredComponent = designer.getComponentAt(0, 0); + } + // 获取该组件所在的焦点容器 + XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); + + if (container != null) { + boolean formSubmit2Adapt = !selectionModel.getSelection().getSelectedCreator().canEnterIntoAdaptPane() + && container.acceptType(XWFitLayout.class); + if (!formSubmit2Adapt) { + // 如果是处于拖拽状态,则释放组件 + stateModel.releaseDragging(e); + } else { + selectionModel.deleteSelection(); + designer.setPainter(null); + } + cancelPromptWidgetForbidEnter(); + } + } + + /** + * TODO 激活上下文菜单,待完善 + * 6.56暂时不支持右键 bugid 8777 + */ + private void triggerPopup(MouseEvent e) { + XCreator creator = selectionModel.getSelection().getSelectedCreator(); + if (creator == null) { + return; + } + JPopupMenu popupMenu = null; + ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, creator); + popupMenu = adapter.getContextPopupMenu(e); + + if (popupMenu != null) { + popupMenu.show(designer, e.getX(), e.getY()); + } + // 通知组件已经被选择了 + designer.getEditListenerTable().fireCreatorModified(creator, DesignerEvent.CREATOR_SELECTED); + } + + /** + * 移动 + * + * @param e 鼠标事件 + */ + public void mouseMoved(MouseEvent e) { + XCreator component = designer.getComponentAt(e); + + setCoverPaneNotDisplay(e, false); + + if (processTopLayoutMouseMove(component, e)) { + return; + } + if (component instanceof XEditorHolder) { + XEditorHolder xcreator = (XEditorHolder) component; + Rectangle rect = xcreator.getBounds(); + int min = rect.x + rect.width / 2 - minMoveSize; + int max = rect.x + rect.width / 2 + minMoveSize; + if (e.getX() > min && e.getX() < max) { + if (designer.getCursor().getType() != Cursor.HAND_CURSOR) { + designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } + return; + } else { + if (designer.getCursor().getType() == Cursor.HAND_CURSOR) { + designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + } + } + Direction dir = selectionModel.getDirectionAt(e); + if (designer.isDrawLineMode() && stateModel.getDirection() == Location.outer) { + designer.updateDrawLineMode(e); + } + if (!BaseUtils.isAuthorityEditing()) { + stateModel.setDirection(dir); + } + + if (component.isReport()) { + elementCaseMouseMoved(e, component); + designer.repaint(); + return; + } + + processChartEditorMouseMove(component, e); + + designer.repaint(); + } + + private void elementCaseMouseMoved(MouseEvent e, XCreator component) { + xElementCase = (XElementCase) component; + UIButton button = (UIButton) xElementCase.getCoverPane().getComponent(0); + 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 minY = button.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 (xElementCase.getCoverPane().getComponentCount() > 1) { + JComponent button1 = (JComponent) xElementCase.getCoverPane().getComponent(1); + int minX1 = button1.getX() + getParentPositionX(component, 0) - designer.getArea().getHorizontalValue(); + int minY1 = button1.getY() + getParentPositionY(component, 0) - designer.getArea().getVerticalValue(); + 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); + } + + private void setCoverPaneNotDisplay(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; + } + if (isLinkedHelpDialog) { + xElementCase.destroyHelpDialog(); + } + xElementCase.displayCoverPane(false); + } + if (xChartEditor != null) { + xChartEditor.displayCoverPane(false); + } + + if (xTopLayoutContainer != null) { + xTopLayoutContainer.setMouseEnter(false); + } + designer.repaint(); + } + + private boolean processTopLayoutMouseMove(XCreator component, MouseEvent e) { + XLayoutContainer parent = XCreatorUtils.getHotspotContainer(component).getTopLayout(); + if (parent != null) { + xTopLayoutContainer = parent; + xTopLayoutContainer.setMouseEnter(true); + designer.repaint(); + if (!xTopLayoutContainer.isEditable()) { + if (designer.getCursor().getType() == Cursor.HAND_CURSOR) { + designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + int minX = getParentPositionX(parent, parent.getX()) + parent.getWidth() / 2; + int minY = getParentPositionY(parent, parent.getY()) + parent.getHeight() / 2; + int offsetX = EDIT_BTN_WIDTH / 2 + GAP; + int offsetY = EDIT_BTN_HEIGHT / 2 + GAP; + if (e.getX() > (minX - offsetX) && e.getX() < (minX + offsetX)) { + if (e.getY() > (minY - offsetY) && e.getY() < (minY + offsetY + designer.getParaHeight())) { + designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } + } + return true; + } + } + return false; + } + + private void processChartEditorMouseMove(XCreator component, MouseEvent e) { + if (component instanceof XChartEditor) { + xChartEditor = (XChartEditor) component; + UIButton button = (UIButton) xChartEditor.getCoverPane().getComponent(0); + if (designer.getCursor().getType() == Cursor.HAND_CURSOR) { + designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + int minX = button.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)); + } + } + xChartEditor.displayCoverPane(true); + xChartEditor.setDirections(Direction.TOP_BOTTOM_LEFT_RIGHT); + designer.repaint(); + } + } + + private int getParentPositionX(XCreator comp, int x) { + return comp.getParent() == null ? + x : getParentPositionX((XCreator) comp.getParent(), comp.getParent().getX() + x); + } + + private int getParentPositionY(XCreator comp, int y) { + return comp.getParent() == null ? + y : getParentPositionY((XCreator) comp.getParent(), comp.getParent().getY() + y); + } + + /** + * 拖拽 + * + * @param e 鼠标事件 + */ + public void mouseDragged(MouseEvent e) { + if (BaseUtils.isAuthorityEditing()) { + return; + } + // 如果当前是左键拖拽状态,拖拽组件 + if (stateModel.dragable()) { + if (SwingUtilities.isRightMouseButton(e)) { + return; + } else { + stateModel.dragging(e); + // 获取e所在的焦点组件 + XCreator hotspot = designer.getComponentAt(e.getX(), e.getY()); + if (dragBackupBounds == null) { + XCreator selectingXCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); + if (selectingXCreator != null) { + dragBackupBounds = new Rectangle(selectingXCreator.getX(), selectingXCreator.getY(), selectingXCreator.getWidth(), selectingXCreator.getHeight()); + } + } + // 拉伸时鼠标拖动过快,导致所在组件获取会为空 + if (hotspot == null) { + return; + } + // 获取焦点组件所在的焦点容器 + XLayoutContainer container = XCreatorUtils.getHotspotContainer(hotspot); + //提示组件是否可以拖入 + promptUser(e.getX(), e.getY(), container); + } + } else if (designer.isDrawLineMode()) { + if (stateModel.prepareForDrawLining()) { + stateModel.drawLine(e); + } + } else if (stateModel.isSelecting() && (selectionModel.getHotspotBounds() != null)) { + // 如果是拖拽选择区域状态,则更新选择区域 + stateModel.changeSelection(e); + } else { + if ((lastPressEvent == null) || (lastXCreator == null)) { + return; + } + if (e.getPoint().distance(lastPressEvent.getPoint()) > minDragSize) { + //参数面板和自适应布局不支持拖拽 + if (lastXCreator.isSupportDrag()) { + designer.startDraggingComponent(lastXCreator, lastPressEvent, e.getX(), e.getY()); + } + e.consume(); + lastPressEvent = null; + } + } + designer.repaint(); + } + + //当前编辑的组件是在布局中,鼠标点击布局外部,需要一次性将布局及其父布局都置为不可编辑 + private void setTopLayoutUnEditable(XLayoutContainer clickedTopLayout, XLayoutContainer clickingTopLayout) { + //双击的前后点击click为相同对象,过滤掉 + if (clickedTopLayout == null || clickedTopLayout == clickingTopLayout) { + return; + } + //位于同一层级的控件,父布局相同,过滤掉 + if (clickingTopLayout != null && clickedTopLayout.getParent() == clickingTopLayout.getParent()) { + return; + } + //前后点击的位于不同层级,要置为不可编辑 + XLayoutContainer xLayoutContainer = (XLayoutContainer) clickedTopLayout.getParent(); + if (xLayoutContainer == clickingTopLayout) { + return; + } + if (xLayoutContainer != null) { + xLayoutContainer.setEditable(false); + setTopLayoutUnEditable((XLayoutContainer) clickedTopLayout.getParent(), clickingTopLayout); + } + } + + private boolean isCreatorInLayout(XCreator creator, XCreator layout) { + if (creator.equals(layout)) { + return true; + } + if (layout.getParent() != null) { + return isCreatorInLayout(creator, (XCreator) layout.getParent()); + } + return false; + } + + private XCreator processTopLayoutMouseClick(XCreator creator) { + XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(creator).getTopLayout(); + if (topLayout != null) { + if (clickTopLayout != null && !clickTopLayout.equals(topLayout) && !isCreatorInLayout(clickTopLayout, + topLayout)) { + clickTopLayout.setEditable(false); + setTopLayoutUnEditable(clickTopLayout, topLayout); + } + clickTopLayout = topLayout; + if (!topLayout.isEditable()) { + creator = topLayout; + } + } else { + if (clickTopLayout != null) { + clickTopLayout.setEditable(false); + setTopLayoutUnEditable(clickTopLayout, null); + } + } + + return creator; + } + + /** + * 点击 + * + * @param e 鼠标事件 + */ + public void mouseClicked(MouseEvent e) { + XCreator creator = designer.getComponentAt(e); + + if (e.getButton() != MouseEvent.BUTTON1 && !creator.acceptType(XCardSwitchButton.class)) { + return; + } + + creator = processTopLayoutMouseClick(creator); + + if (creator != null) { + creator.respondClick(this, e); + } + creator.doLayout(); + LayoutUtils.layoutRootContainer(designer.getRootComponent()); + } + + + /** + * 离开 + * + * @param e 鼠标事件 + */ + public void mouseExited(MouseEvent e) { + if (designer.getCursor().getType() != Cursor.DEFAULT_CURSOR) { + designer.setCursor(Cursor.getDefaultCursor()); + } + + setCoverPaneNotDisplay(e, true); + + cancelPromptWidgetForbidEnter(); + } + + /** + * 开始编辑 + * + * @param creator 容器 + * @param designerEditor 设计器 + * @param adapter 适配器 + */ + public void startEditing(XCreator creator, DesignerEditor designerEditor, ComponentAdapter adapter) { + if (designerEditor != null) { + Rectangle rect = ComponentUtils.getRelativeBounds(creator); + currentEditor = designerEditor; + currentXCreator = creator; + Rectangle bounds = new Rectangle(1, 1, creator.getWidth() - 2, creator.getHeight() - 2); + bounds.x += (rect.x - designer.getArea().getHorizontalValue()); + bounds.y += (rect.y - designer.getArea().getVerticalValue()); + designerEditor.getEditorTarget().setBounds(bounds); + designer.add(designerEditor.getEditorTarget()); + designer.invalidate(); + designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + designerEditor.getEditorTarget().requestFocus(); + designer.repaint(); + } + } + + /** + * 停止编辑 + * + * @return 是否编辑成功 + */ + public boolean stopEditing() { + if (currentEditor != null) { + designer.remove(currentEditor.getEditorTarget()); + currentEditor.fireEditStoped(); + + Container container = currentXCreator.getParent(); + + if (container != null) { + LayoutUtils.layoutRootContainer(container); + } + designer.invalidate(); + designer.repaint(); + currentXCreator = null; + currentEditor = null; + return true; + } + return true; + } + + /** + * 重置编辑控件大小 + */ + public void resetEditorComponentBounds() { + if (currentEditor == null) { + return; + } + + if (currentXCreator.getParent() == null) { + stopEditing(); + return; + } + + Rectangle rect = ComponentUtils.getRelativeBounds(currentXCreator); + Rectangle bounds = new Rectangle(1, 1, currentXCreator.getWidth() - 2, currentXCreator.getHeight() - 2); + bounds.x += (rect.x - designer.getArea().getHorizontalValue()); + bounds.y += (rect.y - designer.getArea().getVerticalValue()); + if (currentXCreator instanceof XEditorHolder) { + ToolTipEditor.getInstance().resetBounds((XEditorHolder) currentXCreator, bounds, currentEditor.getEditorTarget().getBounds()); + } + currentEditor.getEditorTarget().setBounds(bounds); + } } \ 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 6390b64f8..486ad2694 100644 --- a/designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java +++ b/designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java @@ -43,7 +43,7 @@ public class FormCreatorDropTarget extends DropTarget { * 当前添加模式对应的model */ private AddingModel addingModel; - private final static int GAP = 30; + private static final int GAP = 30; private JWindow promptWindow = new JWindow(); private UIButton promptButton = new UIButton("", BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); @@ -59,10 +59,11 @@ public class FormCreatorDropTarget extends DropTarget { XCreator hoveredComponent = designer.getComponentAt(x, y); // 获取该组件所在的焦点容器 XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); - //cardTagLayout里用到 - container.stopAddingState(designer); boolean success = false; if (container != null) { + //XWCardTagLayout 切换添加状态到普通状态 + container.stopAddingState(designer); + // 如果是容器,则调用其acceptComponent接受组件 AddingModel model = designer.getAddingModel(); @@ -129,9 +130,7 @@ public class FormCreatorDropTarget extends DropTarget { //提示组件是否可以拖入 promptUser(x, y, container); if (container != null) { - dealWithContainer(x, y, container); - } else { // 如果鼠标不在任何组件上,则取消提示器 designer.setPainter(null); @@ -197,11 +196,9 @@ public class FormCreatorDropTarget extends DropTarget { 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(); - this.promptWindow.setSize(promptWindow.getPreferredSize()); - this.promptWindow.setPreferredSize(promptWindow.getPreferredSize()); - promptWindow.setLocation(screen_X + x + GAP, screen_Y + y + GAP); + int screenX = designer.getArea().getLocationOnScreen().x; + int screenY = designer.getArea().getLocationOnScreen().y; + promptWindow.setLocation(screenX + x + GAP, screenY + y + GAP); promptWindow.setVisible(true); } diff --git a/designer_form/src/com/fr/design/mainframe/FormDesigner.java b/designer_form/src/com/fr/design/mainframe/FormDesigner.java index a3b197e91..3aa9e24ee 100644 --- a/designer_form/src/com/fr/design/mainframe/FormDesigner.java +++ b/designer_form/src/com/fr/design/mainframe/FormDesigner.java @@ -6,7 +6,10 @@ import com.fr.design.DesignState; import com.fr.design.designer.TargetComponent; import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.Painter; +import com.fr.design.designer.beans.actions.CopyAction; +import com.fr.design.designer.beans.actions.CutAction; import com.fr.design.designer.beans.actions.FormDeleteAction; +import com.fr.design.designer.beans.actions.PasteAction; import com.fr.design.designer.beans.adapters.layout.FRParameterLayoutAdapter; import com.fr.design.designer.beans.events.CreatorEventListenerTable; import com.fr.design.designer.beans.events.DesignerEditListener; @@ -43,7 +46,6 @@ import com.fr.form.ui.container.WFitLayout; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; import com.fr.general.Inter; -import com.fr.plugin.ExtraClassManager; import com.fr.stable.ArrayUtils; import com.fr.stable.bridge.StableFactory; @@ -65,11 +67,10 @@ import java.util.List; /** * 设计界面组件。该组件是界面设计工具的核心,主要负责的是被设计界面的显示,界面设计操作状态的 显示,编辑状态的显示等等。 */ -public class FormDesigner extends TargetComponent

implements TreeSelectionListener, InvocationHandler, BaseFormDesigner ,ParaDefinitePane{ +public class FormDesigner extends TargetComponent implements TreeSelectionListener, InvocationHandler, BaseFormDesigner, ParaDefinitePane { protected static final ArrayList NAME_ARRAY_LIST = new ArrayList( Arrays.asList(new String[]{Inter.getLocText("M_Edit-Cut"), Inter.getLocText("M_Edit-Copy"), Inter.getLocText("M_Edit-Delete")}) ); - private static final int BORDER_WIDTH = 6; //底层容器的默认大小 protected static final Dimension LARGE_PREFERRED_SIZE = new Dimension(WBorderLayout.DEFAULT_WIDTH, WBorderLayout.DEFAULT_HEIGHT); private int paraHeight = 0; @@ -81,7 +82,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection private XLayoutContainer paraComponent; private boolean drawLineMode; private FormArea formArea; - private ConnectorHelper ConnectorHelper; + private ConnectorHelper connectorHelper; private boolean isReportBlockEditing = false; //组件重叠 @@ -104,7 +105,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection // 编辑状态的事件表 private CreatorEventListenerTable edit; - protected Action[] designer_actions; + protected Action[] designerActions; private FormDesignerModeForSpecial desigerMode; private Action switchAction; private FormElementCaseContainerProvider elementCaseContainer; @@ -159,7 +160,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection ParameterPropertyPane.getInstance().populateBean(this); } - public Parameter[] getNoRepeatParas(Parameter[] paras){ + public Parameter[] getNoRepeatParas(Parameter[] paras) { List paraList = new ArrayList(); java.util.Set set = new java.util.HashSet(); for (Parameter p : paras) { @@ -171,23 +172,23 @@ public class FormDesigner extends TargetComponent implements TreeSelection return paraList.toArray(new Parameter[paraList.size()]); } - public void setParameterArray(Parameter[] ps){ + public void setParameterArray(Parameter[] ps) { parameterArray = ps; } - public Parameter[] getParameterArray(){ + public Parameter[] getParameterArray() { return parameterArray; } /** * 刷新参数 */ - public void refreshParameter(){ + public void refreshParameter() { XLayoutContainer rootContainer = this.getParaComponent(); - if (rootContainer != null){ + if (rootContainer != null) { java.util.List namelist = new ArrayList(); - rootContainer.getAllXCreatorNameList(rootContainer,namelist); + rootContainer.getAllXCreatorNameList(rootContainer, namelist); // parameterArray是报表的所有参数, nameList是已经在参数面板添加过控件的参数名 // 与已有的参数列表比较 如果已经存在 就除去 Parameter[] ps = getParameterArray(); @@ -201,7 +202,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance(this).getPreferredSize().height); } - private void removeSame(Parameter[] parameters, List namelist){ + private void removeSame(Parameter[] parameters, List namelist) { for (Parameter parameter : parameters) { for (String name : namelist) { if (name.equalsIgnoreCase(parameter.getName())) { @@ -214,20 +215,22 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 是否有查询按钮 - * @return 有无查询按钮 + * + * @return 有无查询按钮 */ - public boolean isWithQueryButton(){ + public boolean isWithQueryButton() { XLayoutContainer rootContainer = this.getParaComponent(); return rootContainer != null && rootContainer.SearchQueryCreators(rootContainer); } /** * 加入参数到参数面板 + * * @param parameter 参数 * @return 是否加入 */ - public void addingParameter2Editor(Parameter parameter){ - if(getParaComponent() == null){ + public void addingParameter2Editor(Parameter parameter) { + if (getParaComponent() == null) { addParaPaneTooltips(); return; } @@ -242,11 +245,11 @@ public class FormDesigner extends TargetComponent implements TreeSelection if (!(this.autoAddComponent(xLabel, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return ; + return; } if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return ; + return; } currentIndex++; parameterArray = (Parameter[]) ArrayUtils.removeElement(parameterArray, parameter); @@ -256,11 +259,12 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 加入参数到参数面板,有查询按钮 + * * @param parameter 参数 * @return 是否加入 */ - public void addingParameter2EditorWithQueryButton(Parameter parameter){ - if(getParaComponent() == null){ + public void addingParameter2EditorWithQueryButton(Parameter parameter) { + if (getParaComponent() == null) { addParaPaneTooltips(); return; } @@ -276,12 +280,12 @@ public class FormDesigner extends TargetComponent implements TreeSelection if (!(this.autoAddComponent(xLabel, FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return ; + return; } if (!(this.autoAddComponent(xCreator, SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return ; + return; } FormSubmitButton formSubmitButton = new FormSubmitButton(); formSubmitButton.setWidgetName("Search"); @@ -289,7 +293,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection xCreator = XCreatorUtils.createXCreator(formSubmitButton); if (!(this.autoAddComponent(xCreator, 270, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return ; + return; } currentIndex = currentIndex + NUM_IN_A_LINE - currentIndex % NUM_IN_A_LINE; parameterArray = (Parameter[]) ArrayUtils.removeElement(parameterArray, parameter); @@ -300,8 +304,8 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 一键添加所有参数 */ - public void addingAllParameter2Editor(){ - if(getParaComponent() == null){ + public void addingAllParameter2Editor() { + if (getParaComponent() == null) { addParaPaneTooltips(); return; } @@ -350,16 +354,17 @@ public class FormDesigner extends TargetComponent implements TreeSelection EastRegionContainerPane.getInstance().refreshDownPane(); } - private void addParaPaneTooltips(){ - JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(),Inter.getLocText("FR-Designer-Form-Please_Drag_ParaPane"), + private void addParaPaneTooltips() { + JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer-Form-Please_Drag_ParaPane"), Inter.getLocText("FR-Designer_Tooltips"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); } /** * 自动添加组件 - * @param xCreator 组件 - * @param x 横坐标 - * @param y 纵坐标 + * + * @param xCreator 组件 + * @param x 横坐标 + * @param y 纵坐标 * @return 是否添加成功 */ public boolean autoAddComponent(XCreator xCreator, int x, int y) { @@ -375,10 +380,11 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 在参数很多时,全部添加的时候,可以向下一次排版,若去掉就会在参数面板堆到一起 + * * @param creator 组件 - * @param x 长度 - * @param y 长度 - * @param layout 布局 + * @param x 长度 + * @param y 长度 + * @param layout 布局 * @return 是否扩展 */ public boolean prepareForAdd(XCreator creator, int x, int y, XWParameterLayout layout) { @@ -404,9 +410,9 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 加入参数面板 */ - public void addParaComponent(){ + public void addParaComponent() { if (paraComponent != null) { - return ; + return; } paraHeight = WBorderLayout.DEFAULT_SIZE; paraComponent = new XWParameterLayout(); @@ -414,7 +420,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection paraComponent.setSize(paraComponent.initEditorSize()); XWBorderLayout formLayoutContainer = (XWBorderLayout) rootComponent.getParent(); formLayoutContainer.toData().setNorthSize(paraHeight); - formLayoutContainer.add(paraComponent,WBorderLayout.NORTH); + formLayoutContainer.add(paraComponent, WBorderLayout.NORTH); //设下northSize,增加para后,重置border大小,这时候para和root的大小会自适应调整 formLayoutContainer.setSize(formLayoutContainer.getWidth(), formLayoutContainer.getHeight() + paraHeight); selectionModel.reset(); @@ -424,30 +430,33 @@ public class FormDesigner extends TargetComponent implements TreeSelection } /** - * 返回根节点父容器 - * @return 父容器 + * 返回根节点父容器 + * + * @return 父容器 */ - public Component getTopContainer(){ - if(rootComponent != null){ + public Component getTopContainer() { + if (rootComponent != null) { // 返回root所在的父容器,非designer return LayoutUtils.getTopContainer(rootComponent); } - return XCreatorUtils.createXCreator(this.getTarget().getContainer()); + return XCreatorUtils.createXCreator(this.getTarget().getContainer()); } /** * 返回参数界面高度 - * @return para高度 + * + * @return para高度 */ - public int getParaHeight(){ + public int getParaHeight() { return paraHeight; } /** * 重置para的高度 - * @param height 高度 + * + * @param height 高度 */ - public void setParaHeight(int height){ + public void setParaHeight(int height) { XWBorderLayout container = (XWBorderLayout) getTopContainer(); container.toData().setNorthSize(height); container.setSize(container.getWidth(), container.getHeight() + height - getParaHeight()); @@ -457,7 +466,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 删除参数界面 */ - public void removeParaComponent(){ + public void removeParaComponent() { XWBorderLayout formLayoutContainer = (XWBorderLayout) getTopContainer(); formLayoutContainer.toData().removeWidget(paraComponent.toData()); paraHeight = 0; @@ -472,41 +481,42 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 切换 - * @param elementCaseContainer 容器 + * + * @param elementCaseContainer 容器 */ - public void switchTab(FormElementCaseContainerProvider elementCaseContainer){ - if(this.switchAction == null){ + public void switchTab(FormElementCaseContainerProvider elementCaseContainer) { + if (this.switchAction == null) { return; } this.elementCaseContainer = elementCaseContainer; this.switchAction.actionPerformed(null); } - public void setElementCaseContainer(FormElementCaseContainerProvider elementCaseContainer){ + public void setElementCaseContainer(FormElementCaseContainerProvider elementCaseContainer) { this.elementCaseContainer = elementCaseContainer; } - public FormElementCaseProvider getElementCase(){ + public FormElementCaseProvider getElementCase() { return this.elementCaseContainer.getElementCase(); } - public String getElementCaseContainerName(){ + public String getElementCaseContainerName() { return this.elementCaseContainer.getElementCaseContainerName(); } - public void setElementCase(FormElementCaseProvider elementCase){ + public void setElementCase(FormElementCaseProvider elementCase) { this.elementCaseContainer.setElementCase(elementCase); } - public void setElementCaseBackground(BufferedImage image){ + public void setElementCaseBackground(BufferedImage image) { this.elementCaseContainer.setBackground(image); } - public Dimension getElementCaseContainerSize(){ + public Dimension getElementCaseContainerSize() { return this.elementCaseContainer.getSize(); } - public FormElementCaseContainerProvider getElementCaseContainer(){ + public FormElementCaseContainerProvider getElementCaseContainer() { return this.elementCaseContainer; } @@ -524,6 +534,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 增加监听事件 + * * @param listener 界面组件编辑事件 */ public void addDesignerEditListener(DesignerEditListener listener) { @@ -539,15 +550,15 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 表单则判断参数面板是否为绝对布局 + * * @return 是则返回true */ public boolean hasWAbsoluteLayout() { - if (paraComponent != null && paraComponent.acceptType(XWParameterLayout.class)){ + if (paraComponent != null && paraComponent.acceptType(XWParameterLayout.class)) { return true; - } - else{ + } else { if (this.getSelectionModel().getSelection().getSelectedCreator().getParent() != null - && ((XLayoutContainer)this.getSelectionModel().getSelection().getSelectedCreator().getParent()).acceptType(XWAbsoluteLayout.class)){ + && ((XLayoutContainer) this.getSelectionModel().getSelection().getSelectedCreator().getParent()).acceptType(XWAbsoluteLayout.class)) { return true; } } @@ -555,7 +566,8 @@ public class FormDesigner extends TargetComponent implements TreeSelection } /** - * 设置是否为报表块编辑 + * 设置是否为报表块编辑 + * * @param isEditing 是否为报表块编辑 */ public void setReportBlockEditing(boolean isEditing) { @@ -564,25 +576,27 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 是否为报表块编辑 + * * @return 是否为报表块编辑 */ public boolean isReportBlockEditing() { return this.isReportBlockEditing; } - public void setWidgetsIntersect(boolean isWidgetsIntersect){ + public void setWidgetsIntersect(boolean isWidgetsIntersect) { this.isWidgetsIntersect = isWidgetsIntersect; } - public boolean isWidgetsIntersect(){ + public boolean isWidgetsIntersect() { return this.isWidgetsIntersect; } /** * 是否重命名控件 + * * @param creator 组件 * @param newName 新的组件名 - * @return 组件名有变化,且不和其他一样返回true + * @return 组件名有变化,且不和其他一样返回true */ public boolean renameCreator(XCreator creator, String newName) { if (ComparatorUtils.equals(creator.toData().getWidgetName(), newName)) { @@ -598,6 +612,12 @@ public class FormDesigner extends TargetComponent implements TreeSelection return true; } + public void showMessageDialog(String message) { + JOptionPane.showMessageDialog(this, message, Inter.getLocText("FR-Designer_Alert"), JOptionPane.WARNING_MESSAGE); + FormSelectionUtils.rebuildSelection(this); + repaint(); + } + /** * 保存参数界面的宽度 * @@ -609,16 +629,17 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 更新界面布局,重绘 - * @param proxy 动态代理类 + * + * @param proxy 动态代理类 * @param method 接口方法 - * @param args 参数 + * @param args 参数 * @return 不返回任何对象 */ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if(rootComponent != null){ + if (rootComponent != null) { LayoutUtils.layoutRootContainer(rootComponent); } - if(paraComponent != null){ + if (paraComponent != null) { LayoutUtils.layoutRootContainer(paraComponent); } repaint(); @@ -654,6 +675,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 增加组件事件 + * * @param h 动态代理 */ public void addInvocationHandler(InvocationHandler h) { @@ -678,7 +700,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection } /** - * 设置其UI类为DesignerUI,负责渲染 + * 设置其UI类为DesignerUI,负责渲染 */ @Override public void updateUI() { @@ -741,15 +763,13 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 更新边框线状态 + * * @param e 鼠标事件 */ public void updateDrawLineMode(MouseEvent e) { - Point p = ConnectorHelper.getNearWidgetPoint(e); - if (p == null) { - XComponent comp = getComponentAt(e); - if (comp == rootComponent) { - p = new Point(e.getX() + formArea.getHorizontalValue(), e.getY() + formArea.getVerticalValue()); - } + Point p = connectorHelper.getNearWidgetPoint(e); + if (p == null && getComponentAt(e) == rootComponent) { + p = new Point(e.getX() + formArea.getHorizontalValue(), e.getY() + formArea.getVerticalValue()); } stateModel.startDrawLine(p); } @@ -761,7 +781,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection // 撤销恢复操作都会refreshRoot,这时候的target.getContainer里的widget会和之前不一样,所以不用root判断来取 XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(this.getTarget().getContainer()); // 布局默认都是1,底层的border改为0,不然没意义 - this.getTarget().getContainer().setMargin(new PaddingMargin(0,0,0,0)); + this.getTarget().getContainer().setMargin(new PaddingMargin(0, 0, 0, 0)); formLayoutContainer.setBorder(null); if (formLayoutContainer.acceptType(XWBorderLayout.class)) { WBorderLayout borderLayout = (WBorderLayout) formLayoutContainer.toData(); @@ -774,7 +794,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection refreshNorth(northWidget, formLayoutContainer); refreshCenter(centerWidget, formLayoutContainer); - } else { + } else { formLayoutContainer.setSize(LARGE_PREFERRED_SIZE); setRootComponent(formLayoutContainer); } @@ -790,9 +810,9 @@ public class FormDesigner extends TargetComponent implements TreeSelection } XLayoutContainer northContainer = (XLayoutContainer) XCreatorUtils.createXCreator(northWidget); - paraHeight = ((XWBorderLayout)formLayoutContainer).toData().getNorthSize(); + paraHeight = ((XWBorderLayout) formLayoutContainer).toData().getNorthSize(); paraComponent = northContainer; - northContainer.setSize(0,paraHeight); + northContainer.setSize(0, paraHeight); formLayoutContainer.add(northContainer, WBorderLayout.NORTH); } @@ -841,14 +861,16 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 是否是报表的参数面板 - * @return 否(表单的) + * + * @return 否(表单的) */ - public boolean isFormParaDesigner(){ + public boolean isFormParaDesigner() { return false; } /** - * 是否为底层容器 + * 是否为底层容器 + * * @param comp 组件 * @return 是则返回true */ @@ -923,10 +945,10 @@ public class FormDesigner extends TargetComponent implements TreeSelection } public SelectionModel getSelectionModel() { - if (paraComponent!=null){ - paraComponent.setSize(paraComponent.getWidth(),getParaHeight()); + if (paraComponent != null) { + paraComponent.setSize(paraComponent.getWidth(), getParaHeight()); Rectangle rec = rootComponent.getBounds(); - rootComponent.setBounds(rec.x,getParaHeight(),rec.width,rec.height); + rootComponent.setBounds(rec.x, getParaHeight(), rec.width, rec.height); } return selectionModel; } @@ -941,6 +963,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 拖拽准备 + * * @param xCreator 组件 */ public void startDraggingBean(XCreator xCreator) { @@ -953,11 +976,12 @@ public class FormDesigner extends TargetComponent implements TreeSelection } /** - * 拖拽时相关处理 - * @param xCreator 组件 + * 拖拽时相关处理 + * + * @param xCreator 组件 * @param lastPressEvent 鼠标事件 - * @param x 坐标x - * @param y 坐标y + * @param x 坐标x + * @param y 坐标y */ public void startDraggingComponent(XCreator xCreator, MouseEvent lastPressEvent, int x, int y) { // 根据所选择的组件的BeanInfo生成相应的AddingModel @@ -978,6 +1002,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 改变组件值 + * * @param e 组件选择事件 */ @Override @@ -993,7 +1018,6 @@ public class FormDesigner extends TargetComponent implements TreeSelection } if (!BaseUtils.isAuthorityEditing()) { - selectionModel.setSelectedCreators(selected); TreePath path = e.getNewLeadSelectionPath(); @@ -1024,6 +1048,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 是否支持权限编辑 + * * @return 是则返回true */ public boolean isSupportAuthority() { @@ -1048,7 +1073,8 @@ public class FormDesigner extends TargetComponent implements TreeSelection } /** - * 是否含有action名 + * 是否含有action名 + * * @param name action名 * @return 有则返回true */ @@ -1058,6 +1084,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 显示组件 + * * @param comp 组件 */ public void makeVisible(XCreator comp) { @@ -1088,16 +1115,16 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回复制粘贴删除等动作 + * 鼠标右键菜单 + * * @return 同上 */ public Action[] getActions() { - if (designer_actions == null) { - //先把复制粘贴按钮去掉,只留下删除 -// designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this), -// new FormDeleteAction(this)}; - designer_actions = new Action[]{new FormDeleteAction(this)}; + if (designerActions == null) { + designerActions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this), + new FormDeleteAction(this)}; } - return designer_actions; + return designerActions; } protected Border getOuterBorder() { @@ -1120,6 +1147,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回表单区域 + * * @return 表单区域 */ public FormArea getArea() { @@ -1128,6 +1156,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 设置上层区域 + * * @param formArea 表单区域 */ public void setParent(FormArea formArea) { @@ -1136,14 +1165,15 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 绘制组件根节点 + * * @param clipg 图形 */ public void paintContent(Graphics clipg) { rootComponent.paint(clipg); } - public void paintPara(Graphics clipg){ - if(paraComponent != null){ + public void paintPara(Graphics clipg) { + if (paraComponent != null) { paraComponent.paint(clipg); } } @@ -1157,14 +1187,16 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回连线类 + * * @return ConnectorHelper类 */ public ConnectorHelper getDrawLineHelper() { - return ConnectorHelper; + return connectorHelper; } /** - * 是否画线模式 + * 是否画线模式 + * * @return 是则返回true */ public boolean isDrawLineMode() { @@ -1173,6 +1205,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 设置DrawLineMode + * * @param mode 是or或 */ public void setDrawLineMode(boolean mode) { @@ -1199,6 +1232,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回表单控件权限编辑pane + * * @return 同上 */ public AuthorityEditPane createAuthorityEditPane() { @@ -1249,6 +1283,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 粘贴 + * * @return 否 */ @Override @@ -1259,6 +1294,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 剪切 + * * @return 否 */ @Override @@ -1273,6 +1309,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 工具栏菜单 + * * @return 同上 */ @Override @@ -1286,6 +1323,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 模版菜单 + * * @return 同上 */ @Override @@ -1295,6 +1333,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 权限菜单 + * * @return 同上 */ public ShortCut[] shortCuts4Authority() { @@ -1304,6 +1343,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回ToolBarDef + * * @return 同上 */ @Override @@ -1313,10 +1353,12 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回工具栏按钮组件 + * * @return 同上 */ public JComponent[] toolBarButton4Form() { - return new JComponent[0]; + return new JComponent[]{new CutAction(this).createToolBarComponent(), new CopyAction(this).createToolBarComponent(), new PasteAction(this).createToolBarComponent(), + new FormDeleteAction(this).createToolBarComponent()}; } diff --git a/designer_form/src/com/fr/design/mainframe/FormEditToolBar.java b/designer_form/src/com/fr/design/mainframe/FormEditToolBar.java new file mode 100644 index 000000000..c2c487ef5 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/FormEditToolBar.java @@ -0,0 +1,481 @@ +package com.fr.design.mainframe; + +import com.fr.design.actions.UpdateAction; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.gui.itoolbar.UIToolbar; +import com.fr.design.javascript.JavaScriptActionPane; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.menu.ToolBarDef; +import com.fr.design.style.background.BackgroundPane; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.design.widget.IconDefinePane; +import com.fr.form.ui.*; +import com.fr.form.ui.Button; +import com.fr.form.web.button.Export; +import com.fr.general.Background; +import com.fr.general.IOUtils; +import com.fr.general.Inter; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.*; + +/** + * Created by harry on 2017-3-2. + */ +public class FormEditToolBar extends BasicPane { + + private JList list; + private DefaultListModel listModel; + private JPanel right; + private CardLayout card; + private ButtonPane bp; + private FormToolBarButton lastButton; + private Background background = null; + private UICheckBox defaultCheckBox; + + private ListSelectionListener listSelectionListener = new ListSelectionListener() { + public void valueChanged(ListSelectionEvent evt) { + if (lastButton != null) { + lastButton.setWidget(bp.update()); + } + if (list.getSelectedValue() instanceof FormToolBarButton) { + lastButton = (FormToolBarButton) list.getSelectedValue(); + if (lastButton.getWidget() instanceof Button) { + card.show(right, "button"); + bp.populate(lastButton.getWidget()); + } else { + bp.populate(lastButton.getWidget()); + card.show(right, "none"); + } + } + } + }; + + + private ActionListener actioner = new ActionListener() { + /** + * + */ + public void actionPerformed(ActionEvent arg0) { + final BackgroundPane backgroundPane = new BackgroundPane(); + BasicDialog dialog = backgroundPane.showWindow(DesignerContext.getDesignerFrame()); + backgroundPane.populate(FormEditToolBar.this.background); + dialog.addDialogActionListener(new DialogActionAdapter() { + public void doOk() { + FormEditToolBar.this.background = backgroundPane.update(); + if (FormEditToolBar.this.background != null) { + FormEditToolBar.this.defaultCheckBox.setSelected(false); + } + } + }); + dialog.setVisible(true); + } + }; + + public FormEditToolBar() { + initComponent(); + } + + /** + * 初始化 + */ + public void initComponent() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + JPanel left = FRGUIPaneFactory.createBorderLayout_S_Pane(); + listModel = new DefaultListModel(); + list = new JList(listModel); + list.setCellRenderer(render); + left.add(new JScrollPane(list), BorderLayout.CENTER); + if (listModel.getSize() > 0) { + list.setSelectedIndex(0); + } + + ToolBarDef toolbarDef = new ToolBarDef(); + toolbarDef.addShortCut(new MoveUpItemAction()); + toolbarDef.addShortCut(new MoveDownItemAction()); + toolbarDef.addShortCut(new RemoveAction()); + UIToolbar toolBar = ToolBarDef.createJToolBar(); + toolbarDef.updateToolBar(toolBar); + left.add(toolBar, BorderLayout.NORTH); + + right = FRGUIPaneFactory.createCardLayout_S_Pane(); + card = new CardLayout(); + right.setLayout(card); + bp = new ButtonPane(); + right.add("none", FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane()); + right.add("button", bp); + + JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, left, right); + // splitPane.setDividerLocation(left.getMinimumSize().width); + splitPane.setDividerLocation(120); + this.add(splitPane); + list.addListSelectionListener(listSelectionListener); + JPanel backgroundPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + UIButton bgButton = new UIButton(Inter.getLocText("FR-Designer-Output_Background_Set")); + defaultCheckBox = new UICheckBox(Inter.getLocText("FR-Designer-Output_Default_Background")); + bgButton.addActionListener(actioner); + backgroundPane.add(defaultCheckBox); + backgroundPane.add(bgButton); + backgroundPane.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("FR-Designer-Output_Background_Set"))); + this.add(backgroundPane, BorderLayout.SOUTH); + } + + ListCellRenderer render = new DefaultListCellRenderer() { + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + + if (value instanceof FormToolBarButton) { + FormToolBarButton button = (FormToolBarButton) value; + this.setText(button.getNameOption().optionName()); + this.setIcon(button.getNameOption().optionIcon()); + } + return this; + } + }; + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("FR-Designer_Edit"); + } + + public void populate(FormToolBar ftoolbar) { + this.populate(ftoolbar, null); + } + + public void populate(FormToolBar ftoolbar, FormToolBarButton button) { + if (ftoolbar == null) { + return; + } + for (int i = 0; i < ftoolbar.getButtonlist().size(); i++) { + listModel.addElement(ftoolbar.getButtonlist().get(i)); + } + this.list.validate(); + this.list.repaint(); + if (ftoolbar.getButtonlist().size() > 0) { + this.list.setSelectedIndex(0); + } + if (button != null) { + this.list.setSelectedValue(button, true); + } + this.background = ftoolbar.getBackground(); + + this.defaultCheckBox.setSelected(ftoolbar.isDefault() ? true : false); + } + + public FormToolBar update() { + if (this.list.getSelectedIndex() > -1) { + for (int i = 0; i < listModel.getSize(); i++) { + this.list.setSelectedIndex(i); + FormToolBarButton toolBarButton = (FormToolBarButton) this.list.getSelectedValue(); + Widget widget = this.bp.update(); + toolBarButton.setWidget(widget); + if (widget instanceof Button) { + String iconname = ((Button) widget).getIconName(); + if (StringUtils.isNotBlank(iconname)) { + Image iimage = WidgetManager.getProviderInstance().getIconManager().getIconImage(iconname); + toolBarButton.setIcon(new ImageIcon(iimage)); + } + } + } + } + java.util.List list = new ArrayList(); + for (int i = 0; i < listModel.size(); i++) { + list.add((FormToolBarButton) listModel.get(i)); + } + FormToolBar ftoolBar = new FormToolBar(); + ftoolBar.setButtonlist(list); + + ftoolBar.setDefault(this.defaultCheckBox.isSelected()); + if (!ftoolBar.isDefault()) { + ftoolBar.setBackground(this.background); + } + return ftoolBar; + } + + private class MoveUpItemAction extends UpdateAction { + public MoveUpItemAction() { + this.setName(Inter.getLocText("Utils-Move_Up")); + this.setMnemonic('U'); + this.setSmallIcon(IOUtils.readIcon("/com/fr/design/images/control/up.png")); + } + + /** + * + */ + public void actionPerformed(ActionEvent evt) { + int selectedIndex = list.getSelectedIndex(); + if (selectedIndex == -1) { + return; + } + + // 上移 + if (selectedIndex > 0) { + DefaultListModel listModel = (DefaultListModel) list.getModel(); + + Object selecteObj1 = listModel.get(selectedIndex - 1); + listModel.set(selectedIndex - 1, listModel.get(selectedIndex)); + listModel.set(selectedIndex, selecteObj1); + + list.setSelectedIndex(selectedIndex - 1); + list.ensureIndexIsVisible(selectedIndex - 1); + list.validate(); + } + } + } + + private class MoveDownItemAction extends UpdateAction { + public MoveDownItemAction() { + this.setName(Inter.getLocText("Utils-Move_Down")); + this.setMnemonic('D'); + this.setSmallIcon(IOUtils.readIcon("/com/fr/design/images/control/down.png")); + } + + /** + * + */ + public void actionPerformed(ActionEvent evt) { + int selectedIndex = list.getSelectedIndex(); + if (selectedIndex == -1) { + return; + } + + // 下移 + if (selectedIndex == -1) { + return; + } + + if (selectedIndex < list.getModel().getSize() - 1) { + DefaultListModel listModel = (DefaultListModel) list.getModel(); + + Object selecteObj1 = listModel.get(selectedIndex + 1); + listModel.set(selectedIndex + 1, listModel.get(selectedIndex)); + listModel.set(selectedIndex, selecteObj1); + + list.setSelectedIndex(selectedIndex + 1); + list.ensureIndexIsVisible(selectedIndex + 1); + list.validate(); + } + } + } + + public class RemoveAction extends UpdateAction { + public RemoveAction() { + this.setName(Inter.getLocText("FR-Designer_Delete")); + this.setSmallIcon(IOUtils.readIcon("/com/fr/base/images/cell/control/remove.png")); + } + + /** + * 动作 + * @param e 事件 + */ + public void actionPerformed(ActionEvent e) { + int i = list.getSelectedIndex(); + if (i < 0 || !(listModel.getElementAt(i) instanceof FormToolBarButton)) { + return; + } + int val = JOptionPane.showConfirmDialog(FormEditToolBar.this, Inter.getLocText("FR-Designer_Are_You_Sure_To_Delete_The_Data") + "?", "Message", JOptionPane.YES_NO_OPTION); + if (val != JOptionPane.YES_OPTION) { + return; + } + listModel.removeElementAt(i); + list.validate(); + if (listModel.size() > 0) { + list.setSelectedIndex(0); + } else { + card.show(right, "none"); + } + } + } + + public class ButtonPane extends BasicPane { + private CardLayout card; + private JPanel centerPane; + private UICheckBox icon, text, excelP, excelO; + private Widget widget; + private UITextField nameField; + private IconDefinePane iconPane; + private UIButton button; + private JavaScriptActionPane javaScriptPane; + + public ButtonPane() { + this.initComponents(); + } + + /** + * 初始化元素 + */ + public void initComponents() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + JPanel north = FRGUIPaneFactory.createBorderLayout_S_Pane(); + icon = new UICheckBox(Inter.getLocText("FR-Designer_Show_Icon")); + text = new UICheckBox(Inter.getLocText("FR-Designer_Show_Text")); + + north.add(icon, BorderLayout.NORTH); + north.add(text, BorderLayout.CENTER); + + nameField = new UITextField(8); + iconPane = new IconDefinePane(); + javaScriptPane = JavaScriptActionPane.createDefault(); + + double p = TableLayout.PREFERRED; + double rowSize[] = {p, p}; + double columnSize[] = {p, p}; + + Component[][] coms = new Component[][]{{new UILabel(Inter.getLocText(new String[]{"Widget", "Printer-Alias"}) + ":"), nameField}, {new UILabel(Inter.getLocText(new String[]{"Widget", "Icon"}) + ":"), iconPane}}; + + JPanel nameIconPane = TableLayoutHelper.createTableLayoutPane(coms, rowSize, columnSize); + + north.add(nameIconPane, BorderLayout.SOUTH); + + north.setBorder(BorderFactory.createTitledBorder(Inter.getLocText(new String[]{"Form-Button", "Property", "Set"}))); + this.add(north, BorderLayout.NORTH); + JPanel none = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + centerPane = FRGUIPaneFactory.createCardLayout_S_Pane(); + card = new CardLayout(); + centerPane.setLayout(card); + centerPane.add("custom", getCustomPane()); + centerPane.add("export", getExport()); + centerPane.add("none", none); + + this.add(centerPane, BorderLayout.CENTER); + } + + + private JPanel getCustomPane() { + JPanel customPane = FRGUIPaneFactory.createCenterFlowInnerContainer_S_Pane(); + + button = new UIButton(Inter.getLocText("FR-Designer_User_Defined_Event")); + customPane.add(button); + customPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("FR-Designer_Edit") + "JS", null)); + button.addActionListener(l); + return customPane; + } + + private JPanel getExport() { + JPanel export = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane(); + // export.setLayout(new BoxLayout(export, BoxLayout.Y_AXIS)); + excelP = new UICheckBox(Inter.getLocText("FR-Designer-Output_Excel_Page")); + excelO = new UICheckBox(Inter.getLocText("FR-Designer-Output_Excel_Simple")); + export.add(excelP); + export.add(Box.createVerticalStrut(2)); + export.add(excelO); + export.add(Box.createVerticalStrut(2)); + + export.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText(new String[]{"Form-Button", "Property", "Set"}), null)); + return export; + } + + @Override + protected String title4PopupWindow() { + return "Button"; + } + + ActionListener l = new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (!(widget instanceof CustomToolBarButton)) { + return; + } + if (javaScriptPane == null || ((CustomToolBarButton)widget).getJSImpl() == null) { + javaScriptPane = JavaScriptActionPane.createDefault(); + } + javaScriptPane.setPreferredSize(new Dimension(750, 500)); + BasicDialog dialog = javaScriptPane.showWindow(SwingUtilities.getWindowAncestor(ButtonPane.this)); + dialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + ((CustomToolBarButton) widget).setJSImpl(javaScriptPane.updateBean()); + } + }); + dialog.setVisible(true); + } + }; + + /** + * 更新 + * @param widget 对应组件 + */ + public void populate(Widget widget) { + this.widget = widget; + card.show(centerPane, "none"); + if (widget instanceof Button) { + populateDefault(); + } + if (widget instanceof Export) { + populateExport(); + } else if (widget instanceof CustomToolBarButton) { + populateCustomToolBarButton(); + } + } + + private void populateExport(){ + card.show(centerPane, "export"); + Export export = (Export) widget; + this.excelP.setSelected(export.isExcelPAvailable()); + this.excelO.setSelected(export.isExcelOAvailable()); + } + + private void populateCustomToolBarButton(){ + card.show(centerPane, "custom"); + CustomToolBarButton customToolBarButton = (CustomToolBarButton) widget; + if (customToolBarButton.getJSImpl() != null) { + this.javaScriptPane.populateBean(customToolBarButton.getJSImpl()); + } + } + + + + private void populateDefault(){ + Button button = (Button) widget; + this.icon.setSelected(button.isShowIcon()); + this.text.setSelected(button.isShowText()); + this.nameField.setText(button.getText()); + this.iconPane.populate(((Button) widget).getIconName()); + } + + /** + * 更新 + * + * @return 对应组件 + */ + public Widget update() { + if (widget instanceof Export) { + updateExport(); + } else if (widget instanceof CustomToolBarButton) { + ((CustomToolBarButton) widget).setJSImpl(this.javaScriptPane.updateBean()); + } + if (widget instanceof Button) { + updateDefault(); + } + + return widget; + } + + private void updateDefault(){ + ((Button) widget).setShowIcon(this.icon.isSelected()); + ((Button) widget).setShowText(this.text.isSelected()); + ((Button) widget).setText(this.nameField.getText()); + ((Button) widget).setIconName(this.iconPane.update()); + } + + + private void updateExport(){ + Export export = (Export) widget; + export.setExcelPAvailable(this.excelP.isSelected()); + export.setExcelOAvailable(this.excelO.isSelected()); + } + } +} diff --git a/designer_form/src/com/fr/design/mainframe/FormParaWidgetPane.java b/designer_form/src/com/fr/design/mainframe/FormParaWidgetPane.java index cb111bb92..6187bbd48 100644 --- a/designer_form/src/com/fr/design/mainframe/FormParaWidgetPane.java +++ b/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,14 +26,14 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -public class FormParaWidgetPane extends JPanel{ - private static FormParaWidgetPane THIS; - private List predifinedwidgeList = new ArrayList(); +public class FormParaWidgetPane extends JPanel { + private static FormParaWidgetPane THIS; + private List predifinedwidgeList = new ArrayList(); private JWindow chartTypeWindow; private JWindow widgetTypeWindow; private WidgetOption[] widgetOptions = null; - private WidgetOption[] chartOptions = null; + private WidgetOption[] chartOptions = null; private WidgetOption[] layoutOptions = null; private int widgetButtonWidth = 22; private int widgetButtonHeight = 20; @@ -46,49 +45,49 @@ 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 FormDesigner designer; - - public static final FormParaWidgetPane getInstance(FormDesigner designer) { - if(THIS == null) { - THIS = new FormParaWidgetPane(); - } - THIS.designer = designer; - THIS.setTarget(designer); - return THIS; - } - - public FormParaWidgetPane() { - setLayout(new FlowLayout(FlowLayout.LEFT)); + private UILabel paraLabel; + + private FormDesigner designer; + + public static final FormParaWidgetPane getInstance(FormDesigner designer) { + if (THIS == null) { + THIS = new FormParaWidgetPane(); + } + THIS.designer = designer; + THIS.setTarget(designer); + return THIS; + } + + public FormParaWidgetPane() { + setLayout(new FlowLayout(FlowLayout.LEFT)); DesignerContext.getDesignerFrame().getCenterTemplateCardPane().addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { - if (FormParaWidgetPane.this.getParent() != null) { - JPanel fother = (JPanel)FormParaWidgetPane.this.getParent(); + if (FormParaWidgetPane.this.getParent() != null) { + 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){ - return; + + if (delta_wdith == 0) { + return; } - + Dimension d = fother.getSize(); - setPreferredSize(new Dimension(d.width - delta_wdith, d.height)); - LayoutUtils.layoutContainer(fother); - } + setPreferredSize(new Dimension(d.width - delta_wdith, d.height)); + LayoutUtils.layoutContainer(fother); + } } }); initFormParaComponent(); - } + } private void initFormParaComponent() { @@ -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,115 +122,113 @@ 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"))); add(createJSeparator()); } - - private void loadPredefinedWidget() { - predifinedwidgeList.clear(); - if(designer != null) { - WidgetOption[] designerPre = designer.getDesignerMode().getPredefinedWidgetOptions(); - for(int i = 0; i < designerPre.length; i++) { - predifinedwidgeList.add(designerPre[i]); - } - } - WidgetManagerProvider mgr = WidgetManager.getProviderInstance(); - Iterator nameIt = mgr.getWidgetConfigNameIterator(); - while (nameIt.hasNext()) { - String name = nameIt.next(); - WidgetConfig widgetConfig = mgr.getWidgetConfig(name); - if (widgetConfig instanceof UserDefinedWidgetConfig) { - Widget widget = ((UserDefinedWidgetConfig) widgetConfig).getWidget(); - String widgetClassName = widget.getClass().getName(); - if (isButtonWidget(widgetClassName)) { - // ... - continue; - } - if (!XCreatorUtils.createXCreator(widget).canEnterIntoParaPane()){ + + private void loadPredefinedWidget() { + predifinedwidgeList.clear(); + if (designer != null) { + WidgetOption[] designerPre = designer.getDesignerMode().getPredefinedWidgetOptions(); + for (int i = 0; i < designerPre.length; i++) { + predifinedwidgeList.add(designerPre[i]); + } + } + WidgetManagerProvider mgr = WidgetManager.getProviderInstance(); + Iterator nameIt = mgr.getWidgetConfigNameIterator(); + while (nameIt.hasNext()) { + String name = nameIt.next(); + WidgetConfig widgetConfig = mgr.getWidgetConfig(name); + if (widgetConfig instanceof UserDefinedWidgetConfig) { + Widget widget = ((UserDefinedWidgetConfig) widgetConfig).getWidget(); + String widgetClassName = widget.getClass().getName(); + if (isButtonWidget(widgetClassName)) { + // ... + continue; + } + if (!XCreatorUtils.createXCreator(widget).canEnterIntoParaPane()) { //预定义控件工具栏这儿不显示工具栏中没有的预定义控件 continue; } - predifinedwidgeList.add(new UserDefinedWidgetOption(name)); - } - } - } + predifinedwidgeList.add(new UserDefinedWidgetOption(name)); + } + } + } private boolean isButtonWidget(String widgetClassName) { return widgetClassName.endsWith("DeleteRowButton") || widgetClassName.endsWith("AppendRowButton") || widgetClassName.endsWith("TreeNodeToogleButton"); } - private void setTarget(FormDesigner designer) { - if (designer == null) { - return; - } + private void setTarget(FormDesigner designer) { + if (designer == null) { + return; + } initFormParaComponent(); - } + } - 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) { - JPanel componentsPara = new JPanel(new FlowLayout(FlowLayout.LEFT)); - WidgetOption[] chartOptions = loadChartOptions(); - for (WidgetOption chartOption : chartOptions) { - 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)); - chartTypeWindow = new PopUpWindow(componentsPara, Inter.getLocText("FR-Designer-Form-ToolBar_Chart")); - chartTypeWindow.setLocation((int)jSeparatorLayout.getLocationOnScreen().getX() + 1, (int)jSeparatorLayout.getLocationOnScreen().getY()); - chartTypeWindow.setSize(chartTypeWindow.getPreferredSize()); + JPanel componentsPara = new JPanel(new FlowLayout(FlowLayout.LEFT)); + WidgetOption[] chartOptions = loadChartOptions(); + for (WidgetOption chartOption : chartOptions) { + componentsPara.add(new ToolBarButton(chartOption)); } + 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.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 +236,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 +265,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)); - return jSeparator; + 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)); - return jSeparator; + 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){ - return; + 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 +332,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)); } } @@ -347,8 +345,9 @@ public class FormParaWidgetPane extends JPanel{ } /** - * 响应界面改变事件 - * @param evt 事件 + * 响应界面改变事件 + * + * @param evt 事件 */ public void fireCreatorModified(DesignerEvent evt) { button.setEnabled(designer.getParaComponent() == null); @@ -356,14 +355,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,17 +374,14 @@ 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()) { - PopUpWindow.this.setVisible(false); - } + 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 +393,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 +404,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 +416,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; } diff --git a/designer_form/src/com/fr/design/mainframe/FormSelection.java b/designer_form/src/com/fr/design/mainframe/FormSelection.java index c81fc5841..ff809371c 100644 --- a/designer_form/src/com/fr/design/mainframe/FormSelection.java +++ b/designer_form/src/com/fr/design/mainframe/FormSelection.java @@ -8,300 +8,312 @@ import com.fr.base.FRContext; import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.location.Direction; -import com.fr.design.designer.creator.XComponent; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XCreatorUtils; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWAbsoluteLayout; -import com.fr.design.designer.creator.XWParameterLayout; +import com.fr.design.designer.creator.*; import com.fr.form.ui.Widget; import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.gui.LayoutUtils; public class FormSelection { - private ArrayList selection; - private Rectangle backupBounds; - private ArrayList recs = new ArrayList(); - - public FormSelection() { - selection = new ArrayList(); - } - - /** - * 重置选中的组件 - */ - public void reset() { - selection.clear(); - } - - /** - * 是否没有选中的组件 - * @return 为空返回true - */ - public boolean isEmpty() { - return selection.isEmpty(); - } - - /** - * 选中的组件数量 - * @return 选中的组件数量 - */ - public int size() { - return selection.size(); - } - - /** - * 去除选中的组件中指定组件 - * @param creator 待去除组件 - */ - public void removeCreator(XCreator creator) { - selection.remove(creator); - } - - /** - * 是否成功删除选择的组件 - * @param comp 组件 - * @return 是则返回true - */ - public boolean removeSelectedCreator(XCreator comp) { - if (selection.size() > 1 && selection.contains(comp)) { - removeCreator(comp); - return true; - } - return false; - } - - /** - * 成功增加选中的组件 - * @param creator 组件 - * @return 成功增加返回true - */ - public boolean addSelectedCreator(XCreator creator) { - if (addedable(creator)) { - selection.add(creator); - return true; - } - return false; - } - - /** - * 是否是可以增加的 - * @param creator 组件 - * @return 是则返回true - */ - public boolean addedable(XCreator creator) { - if (selection.isEmpty()) { - return true; - } - XLayoutContainer container = XCreatorUtils.getParentXLayoutContainer(creator); - if (!(container instanceof XWAbsoluteLayout)) { - return false; - } - for (XCreator selected : selection) { - if (selected == creator || XCreatorUtils.getParentXLayoutContainer(selected) != container) { - return false; - } - } - return true; - } - - /** - * 返回选中的第一个组件,为空返回null - * @return 返回选中组件 - */ - public XCreator getSelectedCreator() { - return !selection.isEmpty() ? selection.get(0) : null; - } - - /** - * 返回选中的所有组件 - * @return 所有组件s - */ - public XCreator[] getSelectedCreators() { - return selection.toArray(new XCreator[selection.size()]); - } - - public Widget[] getSelectedWidgets() { - Widget[] selectWidget = new Widget[selection.size()]; - for (int i = 0; i < selection.size(); i++) { - selectWidget[i] = selection.get(i).toData(); - } - return selectWidget; - } - - public void setSelectedCreator(XCreator creator) { - reset(); - selection.add(creator); - } - - public void setSelectedCreators(ArrayList selections) { - reset(); - for (XCreator creator : selections) { - if (addedable(creator)) { - selection.add(creator); - } - } - } - - /** - * 是否包含当前控件 - * @param widget 控件 - * @return 是则返回true - */ - public boolean contains(Widget widget) { - for (XCreator creator : selection) { - if (creator.toData() == widget) { - return true; - } - } - return false; - } - - public int[] getDirections() { - if (this.selection.size() > 1) { - return Direction.ALL; - } else if (this.selection.size() == 1) { - return this.selection.get(0).getDirections(); - } else { - return new int[0]; - } - } - - /** - * 备份组件的bound - */ - public void backupBounds() { - backupBounds = getRelativeBounds(); - recs.clear(); - for (XComponent comp : selection) { - recs.add(comp.getBounds()); - } - } - - public Rectangle getBackupBounds() { - return backupBounds; - } - - public Rectangle getRelativeBounds() { - Rectangle bounds = getSelctionBounds(); - XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.get(0)); - if (parent == null) { - return bounds; - } - Rectangle rec = ComponentUtils.getRelativeBounds(parent); - bounds.x += rec.x; - bounds.y += rec.y; - return bounds; - } - - public Rectangle getSelctionBounds() { - if(selection.isEmpty()) { - return new Rectangle(); - } - Rectangle bounds = selection.get(0).getBounds(); - for (int i = 1, len = selection.size(); i < len; i++) { - bounds = bounds.union(selection.get(i).getBounds()); - } - return bounds; - } - - public void setSelectionBounds(Rectangle rec, FormDesigner designer) { - XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.get(0)); - Rectangle backupBounds = new Rectangle(this.backupBounds); - if (parent != null) { - Rectangle r = ComponentUtils.getRelativeBounds(parent); - rec.x -= r.x; - rec.y -= r.y; - backupBounds.x -= r.x; - backupBounds.y -= r.y; - } - - int size = selection.size(); - if (size == 1) { - XCreator creator = selection.get(0); - creator.setBounds(rec); - if(creator.acceptType(XWParameterLayout.class)){ - designer.setParaHeight((int)rec.getHeight()); + private ArrayList selection; + private Rectangle backupBounds; + private ArrayList recs = new ArrayList(); + + public FormSelection() { + selection = new ArrayList(); + } + + /** + * 重置选中的组件 + */ + public void reset() { + selection.clear(); + } + + /** + * 是否没有选中的组件 + * + * @return 为空返回true + */ + public boolean isEmpty() { + return selection.isEmpty(); + } + + /** + * 选中的组件数量 + * + * @return 选中的组件数量 + */ + public int size() { + return selection.size(); + } + + /** + * 去除选中的组件中指定组件 + * + * @param creator 待去除组件 + */ + public void removeCreator(XCreator creator) { + selection.remove(creator); + } + + /** + * 是否成功删除选择的组件 + * + * @param comp 组件 + * @return 是则返回true + */ + public boolean removeSelectedCreator(XCreator comp) { + if (selection.size() > 1 && selection.contains(comp)) { + removeCreator(comp); + return true; + } + return false; + } + + /** + * 成功增加选中的组件 + * + * @param creator 组件 + * @return 成功增加返回true + */ + public boolean addSelectedCreator(XCreator creator) { + if (addedable(creator)) { + selection.add(creator); + return true; + } + return false; + } + + /** + * 是否是可以增加的 + * + * @param creator 组件 + * @return 是则返回true + */ + public boolean addedable(XCreator creator) { + if (selection.isEmpty()) { + return true; + } + XLayoutContainer container = XCreatorUtils.getParentXLayoutContainer(creator); + if (!(container instanceof XWAbsoluteLayout)) { + return false; + } + for (XCreator selected : selection) { + if (selected == creator || XCreatorUtils.getParentXLayoutContainer(selected) != container) { + return false; + } + } + return true; + } + + /** + * 返回选中的第一个组件,为空返回null + * + * @return 返回选中组件 + */ + public XCreator getSelectedCreator() { + return !selection.isEmpty() ? selection.get(0) : null; + } + + /** + * 返回选中的所有组件 + * + * @return 所有组件s + */ + public XCreator[] getSelectedCreators() { + return selection.toArray(new XCreator[selection.size()]); + } + + public Widget[] getSelectedWidgets() { + Widget[] selectWidget = new Widget[selection.size()]; + for (int i = 0; i < selection.size(); i++) { + selectWidget[i] = selection.get(i).toData(); + } + return selectWidget; + } + + public void setSelectedCreator(XCreator creator) { + reset(); + selection.add(creator); + } + + public void setSelectedCreators(ArrayList selections) { + reset(); + for (XCreator creator : selections) { + if (addedable(creator)) { + selection.add(creator); + } + } + } + + /** + * 是否包含当前控件 + * + * @param widget 控件 + * @return 是则返回true + */ + public boolean contains(Widget widget) { + for (XCreator creator : selection) { + if (creator.toData() == widget) { + return true; + } + } + return false; + } + + public int[] getDirections() { + if (this.selection.size() > 1) { + return Direction.ALL; + } else if (this.selection.size() == 1) { + return this.selection.get(0).getDirections(); + } else { + return new int[0]; + } + } + + /** + * 备份组件的bound + */ + public void backupBounds() { + backupBounds = getRelativeBounds(); + recs.clear(); + for (XComponent comp : selection) { + recs.add(comp.getBounds()); + } + } + + public Rectangle getBackupBounds() { + return backupBounds; + } + + public Rectangle getRelativeBounds() { + Rectangle bounds = getSelctionBounds(); + XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.get(0)); + if (parent == null) { + return bounds; + } + Rectangle rec = ComponentUtils.getRelativeBounds(parent); + bounds.x += rec.x; + bounds.y += rec.y; + return bounds; + } + + public Rectangle getSelctionBounds() { + if (selection.isEmpty()) { + return new Rectangle(); + } + Rectangle bounds = selection.get(0).getBounds(); + for (int i = 1, len = selection.size(); i < len; i++) { + bounds = bounds.union(selection.get(i).getBounds()); + } + return bounds; + } + + public void setSelectionBounds(Rectangle rec, FormDesigner designer) { + XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.get(0)); + Rectangle backupBounds = new Rectangle(this.backupBounds); + if (parent != null) { + Rectangle r = ComponentUtils.getRelativeBounds(parent); + rec.x -= r.x; + rec.y -= r.y; + backupBounds.x -= r.x; + backupBounds.y -= r.y; + } + + int size = selection.size(); + if (size == 1) { + XCreator creator = selection.get(0); + creator.setBounds(rec); + if (creator.acceptType(XWParameterLayout.class)) { + designer.setParaHeight((int) rec.getHeight()); designer.getArea().doLayout(); } - LayoutUtils.layoutContainer(creator); - } else if (size > 1) { - for (int i = 0; i < selection.size(); i++) { - Rectangle newBounds = new Rectangle(recs.get(i)); - newBounds.x = rec.x + (newBounds.x - backupBounds.x) * rec.width / backupBounds.width; - newBounds.y = rec.y + (newBounds.y - backupBounds.y) * rec.height / backupBounds.height; - newBounds.width = rec.width * newBounds.width / backupBounds.width; - newBounds.height = rec.height * newBounds.height / backupBounds.height; - XCreator creator = selection.get(i); - creator.setBounds(newBounds); - if(creator.acceptType(XWParameterLayout.class)){ - designer.setParaHeight((int)rec.getHeight()); + LayoutUtils.layoutContainer(creator); + } else if (size > 1) { + for (int i = 0; i < selection.size(); i++) { + Rectangle newBounds = new Rectangle(recs.get(i)); + newBounds.x = rec.x + (newBounds.x - backupBounds.x) * rec.width / backupBounds.width; + newBounds.y = rec.y + (newBounds.y - backupBounds.y) * rec.height / backupBounds.height; + newBounds.width = rec.width * newBounds.width / backupBounds.width; + newBounds.height = rec.height * newBounds.height / backupBounds.height; + XCreator creator = selection.get(i); + creator.setBounds(newBounds); + if (creator.acceptType(XWParameterLayout.class)) { + designer.setParaHeight((int) rec.getHeight()); designer.getArea().doLayout(); } - } - LayoutUtils.layoutRootContainer(designer.getRootComponent()); - } - } - - /** - * 调整组件大小 - * @param designer 设计界面组件 - */ - public void fixCreator(FormDesigner designer) { - for (XCreator creator : selection) { - LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator); - if (layoutAdapter != null) { - creator.setBackupBound(backupBounds); - layoutAdapter.fix(creator); - } - } - } - - private void removeCreatorFromContainer(XCreator creator) { - XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator); - if (parent == null) { - return; - } - // 删除其根组件,同时就删除了同时被选择的叶子组件 - parent.remove(creator); - LayoutManager layout = parent.getLayout(); - - if (layout != null) { - // 刷新组件容器的布局 - LayoutUtils.layoutContainer(parent); - } - } - - /** - * 剪切选中的所有组件 - * @param clipBoard 剪切板 - */ - public void cut2ClipBoard(FormSelection clipBoard) { - clipBoard.reset(); - clipBoard.selection.addAll(selection); - - for (XCreator creator : selection) { - removeCreatorFromContainer(creator); - } - reset(); - } - - /** - * 复制选中的所有组件 - * @param clipBoard 复制板 - */ - public void copy2ClipBoard(FormSelection clipBoard) { - clipBoard.reset(); - - for (XCreator root : selection) { - try { - XCreator creator = XCreatorUtils.createXCreator((Widget) root.toData().clone()); - creator.setBounds(root.getBounds()); - clipBoard.selection.add(creator); - } catch (CloneNotSupportedException e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } - } + } + LayoutUtils.layoutRootContainer(designer.getRootComponent()); + } + } + + /** + * 调整组件大小 + * + * @param designer 设计界面组件 + */ + public void fixCreator(FormDesigner designer) { + for (XCreator creator : selection) { + LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator); + if (layoutAdapter != null) { + creator.setBackupBound(backupBounds); + layoutAdapter.fix(creator); + } + } + } + + private void removeCreatorFromContainer(XCreator creator) { + XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator); + if (parent == null) { + return; + } + boolean changeCreator = creator.shouldScaleCreator() || creator.hasTitleStyle(); + if (parent.acceptType(XWFitLayout.class) && changeCreator) { + creator = (XCreator) creator.getParent(); + } + parent.getLayoutAdapter().removeBean(creator, creator.getWidth(), creator.getHeight()); + // 删除其根组件,同时就删除了同时被选择的叶子组件 + parent.remove(creator); + LayoutManager layout = parent.getLayout(); + + if (layout != null) { + // 刷新组件容器的布局 + LayoutUtils.layoutContainer(parent); + } + } + + /** + * 剪切选中的所有组件 + * + * @param clipBoard 剪切板 + */ + public void cut2ClipBoard(FormSelection clipBoard) { + clipBoard.reset(); + clipBoard.selection.addAll(selection); + + for (XCreator creator : selection) { + removeCreatorFromContainer(creator); + } + reset(); + } + + /** + * 复制选中的所有组件 + * + * @param clipBoard 复制板 + */ + public void copy2ClipBoard(FormSelection clipBoard) { + clipBoard.reset(); + + for (XCreator root : selection) { + try { + XCreator creator = XCreatorUtils.createXCreator((Widget) root.toData().clone()); + creator.setBounds(root.getBounds()); + clipBoard.selection.add(creator); + } catch (CloneNotSupportedException e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java index fc6391225..7a03782c2 100644 --- a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java +++ b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java @@ -1,126 +1,244 @@ -package com.fr.design.mainframe; - -import java.awt.Component; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import com.fr.base.FRContext; -import com.fr.general.ComparatorUtils; -import com.fr.design.designer.beans.LayoutAdapter; -import com.fr.design.designer.beans.events.DesignerEvent; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XCreatorUtils; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWAbsoluteLayout; -import com.fr.form.main.ClonedWidgetCreator; -import com.fr.form.ui.Widget; - -public class FormSelectionUtils { - - public static void paste2Container(FormDesigner designer, XLayoutContainer parent, FormSelection selection, int x, - int y) { - LayoutAdapter adapter = parent.getLayoutAdapter(); - if (selection.size() == 1) { - try { - XCreator creator = selection.getSelectedCreator(); - Widget cloned = new ClonedWidgetCreator(designer.getTarget()).clonedWidgetWithNoRepeatName(creator - .toData()); - XCreator clondCreator = XCreatorUtils.createXCreator(cloned, creator.getSize()); - if (adapter.addBean(clondCreator, x + clondCreator.getWidth() / 2, y + clondCreator.getHeight() / 2)) { - designer.getSelectionModel().getSelection().setSelectedCreator(clondCreator); - designer.getEditListenerTable().fireCreatorModified(clondCreator, DesignerEvent.CREATOR_PASTED); - return; - } - } catch (CloneNotSupportedException e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } else if (selection.size() > 1) { - if (parent instanceof XWAbsoluteLayout) { - designer.getSelectionModel().getSelection().reset(); - Rectangle rec = selection.getSelctionBounds(); - for (XCreator creator : selection.getSelectedCreators()) { - try { - Widget cloned = new ClonedWidgetCreator(designer.getTarget()) - .clonedWidgetWithNoRepeatName(creator.toData()); - XCreator clondCreator = XCreatorUtils.createXCreator(cloned, creator.getSize()); - // 设置位置,移动20x20,防止被粘帖的组件重叠,照顾表单布局情况下 - adapter.addBean(clondCreator, x + creator.getX() - rec.x + clondCreator.getWidth() / 2, y - + creator.getY() - rec.y + clondCreator.getHeight() / 2); - designer.getSelectionModel().getSelection().addSelectedCreator(clondCreator); - } catch (CloneNotSupportedException e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } - designer.getEditListenerTable().fireCreatorModified( - designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); - return; - } - } - Toolkit.getDefaultToolkit().beep(); - } - - public static void rebuildSelection(FormDesigner designer) { - ArrayList newSelection = new ArrayList(); - List widgetList = new ArrayList(); - for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) { - widgetList.add(comp.toData()); - } - designer.getSelectionModel().setSelectedCreators( - rebuildSelection(designer.getRootComponent(), widgetList, newSelection)); - } - - public static ArrayList rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { - List selectionWidget = new ArrayList(); - if(selectWidgets != null){ - selectionWidget.addAll(Arrays.asList(selectWidgets)); - } - return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList()); - } - - private static ArrayList rebuildSelection(XCreator rootComponent, List selectionWidget, - ArrayList newSelection) { - FormSelectionUtils._rebuild(rootComponent, selectionWidget, newSelection); - if (newSelection.isEmpty()) { - newSelection.add(rootComponent); - } - return newSelection; - } - - private static void _rebuild(XCreator root, List selectionWidget, List newSelection) { - if (selectionWidget.isEmpty()) { - return; - } - for (Widget x : selectionWidget) { - if (ComparatorUtils.equals(x, root.toData())) { - if (!newSelection.contains(root)) { - newSelection.add(root); - selectionWidget.remove(x); - } - break; - } - } - - int count = root.getComponentCount(); - for (int i = 0; i < count && !selectionWidget.isEmpty(); i++) { - Component c = root.getComponent(i); - if (c instanceof XCreator) { - XCreator creator = (XCreator) c; - for (Widget x : selectionWidget) { - if (ComparatorUtils.equals(x, creator.toData())) { - newSelection.add(creator); - selectionWidget.remove(x); - break; - } - } - if (c instanceof XLayoutContainer) { - _rebuild((XLayoutContainer) c, selectionWidget, newSelection); - } else { - continue; - } - } - } - } +package com.fr.design.mainframe; + +import com.fr.base.FRContext; +import com.fr.design.designer.beans.LayoutAdapter; +import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter; +import com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter; +import com.fr.design.designer.beans.events.DesignerEvent; +import com.fr.design.designer.creator.*; +import com.fr.design.utils.ComponentUtils; +import com.fr.form.ui.Widget; +import com.fr.form.ui.container.WTitleLayout; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class FormSelectionUtils { + + //组件复制时坐标偏移 + private static final int DELAY_X_Y = 20; + + //组件重命名后缀 + private static final String POSTFIX = "_c"; + + private FormSelectionUtils() { + + } + + /** + * 粘贴到容器 + */ + public static void paste2Container(FormDesigner designer, XLayoutContainer parent, + FormSelection clipboard, int x, int y) { + LayoutAdapter adapter = parent.getLayoutAdapter(); + if (parent instanceof XWAbsoluteLayout) { + //绝对布局 + absolutePaste(designer, clipboard, adapter, x, y); + return; + } else if (parent instanceof XWFitLayout) { + //相对布局 + relativePaste(designer, clipboard, adapter, x, y); + return; + } + Toolkit.getDefaultToolkit().beep(); + } + + /** + * 绝对布局粘贴 + */ + private static void absolutePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { + + designer.getSelectionModel().getSelection().reset(); + Rectangle rec = clipboard.getSelctionBounds(); + for (XCreator creator : clipboard.getSelectedCreators()) { + try { + Widget copied = copyWidget(designer, creator); + XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); + // 获取位置 + Point point = getPasteLocation((AbstractLayoutAdapter) adapter, + copiedCreator, + x + creator.getX() - rec.x + copiedCreator.getWidth() / 2, + y + creator.getY() - rec.y + copiedCreator.getHeight() / 2); + if (!adapter.accept(copiedCreator, point.x, point.y)) { + designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Large_To_Paste")); + return; + } + boolean addSuccess = adapter.addBean(copiedCreator, point.x, point.y); + if (addSuccess) { + designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); + } + } catch (CloneNotSupportedException e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + rebuildSelection(designer); + designer.getEditListenerTable().fireCreatorModified( + designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); + + } + + /** + * 相对布局粘贴 + */ + private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { + + //@see FRTabFitLayoutAdapter + Rectangle tabContainerRect = ComponentUtils.getRelativeBounds(designer.getSelectionModel().getSelection() + .getSelectedCreator().getParent()); + + designer.getSelectionModel().getSelection().reset(); + for (XCreator creator : clipboard.getSelectedCreators()) { + try { + Widget copied = copyWidget(designer, creator); + XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); + if (adapter.getClass().equals(FRTabFitLayoutAdapter.class)) { + if (!adapter.accept(copiedCreator, x - tabContainerRect.x, y - tabContainerRect.y)) { + designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste")); + return; + } + } else { + if (!adapter.accept(copiedCreator, x, y)) { + designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste")); + return; + } + } + boolean addSuccess = adapter.addBean(copiedCreator, x, y); + if (addSuccess) { + designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); + } + } catch (CloneNotSupportedException e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + rebuildSelection(designer); + designer.getEditListenerTable().fireCreatorModified( + designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); + } + + /** + * 组件复用绝对布局获取粘贴组件位置 + */ + private static Point getPasteLocation(AbstractLayoutAdapter layoutAdapter, XCreator copiedCreator, int x, int y) { + //当宽度为奇数时 设置偏移 + int xoffset = (copiedCreator.getWidth() & 1) == 1 ? 1 : 0; + //当高度为奇数时 设置偏移 + int yoffset = (copiedCreator.getHeight() & 1) == 1 ? 1 : 0; + + if (!layoutAdapter.accept(copiedCreator, x, y)) { + XLayoutContainer container = layoutAdapter.getContainer(); + boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + xoffset > container.getWidth(); + boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + yoffset > container.getHeight(); + + boolean isEdge = (x - DELAY_X_Y == container.getWidth() - copiedCreator.getWidth() / 2 - xoffset) + && (y - DELAY_X_Y == container.getHeight() - copiedCreator.getHeight() / 2 - yoffset); + + y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y; + if (xOut) { + if (isEdge) { + //向左偏移 + x = container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X_Y - xoffset; + } + //紧贴下边界 + else { + x = container.getWidth() - copiedCreator.getWidth() / 2 - xoffset; + } + } + } + return new Point(x, y); + } + + + /** + * 拷贝组件 + */ + private static Widget copyWidget(FormDesigner formDesigner, XCreator xCreator) throws + CloneNotSupportedException { + ArrayList nameSpace = new ArrayList<>(); + Widget copied = (Widget) xCreator.toData().clone(); + //重命名拷贝的组件 + String name = getCopiedName(formDesigner, copied, nameSpace); + if (copied instanceof WTitleLayout) { + XWTitleLayout xwTitleLayout = new XWTitleLayout((WTitleLayout) copied, xCreator.getSize()); + xwTitleLayout.resetCreatorName(name); + } else { + copied.setWidgetName(name); + } + return copied; + } + + /** + * 组件拷贝命名规则 + */ + private static String getCopiedName(FormDesigner formDesigner, Widget copied, ArrayList nameSpace) { + StringBuilder name = new StringBuilder(copied.getWidgetName()); + do { + name.append(POSTFIX); + } while (formDesigner.getTarget().isNameExist(name.toString()) || nameSpace.contains(name.toString())); + nameSpace.add(name.toString()); + return name.toString(); + } + + public static void rebuildSelection(FormDesigner designer) { + ArrayList newSelection = new ArrayList<>(); + List widgetList = new ArrayList<>(); + for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) { + widgetList.add(comp.toData()); + } + designer.getSelectionModel().setSelectedCreators( + rebuildSelection(designer.getRootComponent(), widgetList, newSelection)); + } + + public static ArrayList rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { + List selectionWidget = new ArrayList<>(); + if (selectWidgets != null) { + selectionWidget.addAll(Arrays.asList(selectWidgets)); + } + return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList()); + } + + private static ArrayList rebuildSelection(XCreator rootComponent, List selectionWidget, + ArrayList newSelection) { + FormSelectionUtils.rebuild(rootComponent, selectionWidget, newSelection); + if (newSelection.isEmpty()) { + newSelection.add(rootComponent); + } + return newSelection; + } + + private static void rebuild(XCreator root, List selectionWidget, List newSelection) { + if (selectionWidget.isEmpty()) { + return; + } + for (Widget x : selectionWidget) { + if (ComparatorUtils.equals(x, root.toData())) { + if (!newSelection.contains(root)) { + newSelection.add(root); + selectionWidget.remove(x); + } + break; + } + } + + int count = root.getComponentCount(); + for (int i = 0; i < count && !selectionWidget.isEmpty(); i++) { + Component c = root.getComponent(i); + if (c instanceof XCreator) { + XCreator creator = (XCreator) c; + for (Widget x : selectionWidget) { + if (ComparatorUtils.equals(x, creator.toData())) { + newSelection.add(creator); + selectionWidget.remove(x); + break; + } + } + if (c instanceof XLayoutContainer) { + rebuild((XLayoutContainer) c, selectionWidget, newSelection); + } + } + } + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/FormSettingToolBar.java b/designer_form/src/com/fr/design/mainframe/FormSettingToolBar.java new file mode 100644 index 000000000..c84776789 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/FormSettingToolBar.java @@ -0,0 +1,84 @@ +package com.fr.design.mainframe; + +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.IOUtils; +import com.fr.general.Inter; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * Created by harry on 2017-3-2. + */ +public class FormSettingToolBar extends JPanel { + private Icon setIcon = IOUtils.readIcon("com/fr/design/images/toolbarbtn/toolbarbtnsetting.png"); + private Icon delIcon = IOUtils.readIcon("com/fr/design/images/toolbarbtn/toolbarbtnclear.png"); + private UIButton setButton; + private UIButton delButton; + private FormToolBarPane toolBarPane; + + public FormSettingToolBar(String name, FormToolBarPane toolBarPane) { + super(); + this.setBackground(Color.lightGray); + this.add(new UILabel(name)); + this.toolBarPane = toolBarPane; + setButton = GUICoreUtils.createTransparentButton(setIcon, setIcon, setIcon); + setButton.setToolTipText(Inter.getLocText("FR-Designer_Edit_Button_ToolBar")); + setButton.setAction(new SetAction()); + delButton = GUICoreUtils.createTransparentButton(delIcon, delIcon, delIcon); + delButton.setToolTipText(Inter.getLocText("FR-Designer_Remove_Button_ToolBar")); + delButton.setAction(new DelAction()); + this.add(setButton); + this.add(delButton); + } + + public void setEnabled(boolean b) { + setButton.setEnabled(b); + delButton.setEnabled(b); + } + + public void addActionListener(ActionListener l){ + setButton.addActionListener(l); + delButton.addActionListener(l); + } + + private class SetAction extends AbstractAction { + + public SetAction() { + this.putValue(Action.SMALL_ICON, setIcon); + } + + @Override + public void actionPerformed(ActionEvent arg0) { + final FormEditToolBar tb = new FormEditToolBar(); + tb.populate(toolBarPane.getFToolBar()); + BasicDialog dialog = tb.showWindow(DesignerContext.getDesignerFrame()); + dialog.addDialogActionListener(new DialogActionAdapter() { + public void doOk() { + toolBarPane.setFToolBar(tb.update()); + } + }); + dialog.setVisible(true); + } + } + + private class DelAction extends AbstractAction { + + public DelAction() { + this.putValue(Action.SMALL_ICON, delIcon); + } + + @Override + public void actionPerformed(ActionEvent arg0) { + toolBarPane.removeAll(); + toolBarPane.removeButtonList(); + toolBarPane.repaint(); + } + } +} diff --git a/designer_form/src/com/fr/design/mainframe/FormToolBar.java b/designer_form/src/com/fr/design/mainframe/FormToolBar.java new file mode 100644 index 000000000..860144dc8 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/FormToolBar.java @@ -0,0 +1,68 @@ +package com.fr.design.mainframe; + +import com.fr.form.ui.ToolBar; +import com.fr.form.ui.Widget; +import com.fr.general.Background; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by harry on 2017-3-2. + */ +public class FormToolBar { + private List buttonlist = new ArrayList(); + private Background background = null; + private boolean isDefault = true; + + public List getButtonlist() { + return buttonlist; + } + + public void setButtonlist(List buttonlist) { + if (buttonlist == null || buttonlist.size() < 0) { + this.buttonlist = new ArrayList(); + } else { + this.buttonlist = buttonlist; + } + } + + public void addButton(FormToolBarButton toolBarButton) { + this.buttonlist.add(toolBarButton); + } + + public void removeButton(FormToolBarButton toolBarButton) { + this.buttonlist.remove(toolBarButton); + } + + public void clearButton() { + this.buttonlist.clear(); + } + + public Background getBackground() { + return background; + } + + public void setBackground(Background background) { + this.background = background; + } + + public boolean isDefault() { + return isDefault; + } + + public void setDefault(boolean isDefault) { + this.isDefault = isDefault; + } + + public ToolBar getToolBar() { + Widget[] widgets = new Widget[this.getButtonlist().size()]; + for (int j = 0; j < this.getButtonlist().size(); j++) { + widgets[j] = this.getButtonlist().get(j).getWidget(); + } + ToolBar toolBar = new ToolBar(widgets); + toolBar.setBackground(this.background); + toolBar.setDefault(this.isDefault); + return toolBar; + } +} diff --git a/designer_form/src/com/fr/design/mainframe/FormToolBarButton.java b/designer_form/src/com/fr/design/mainframe/FormToolBarButton.java new file mode 100644 index 000000000..a9651c7fa --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/FormToolBarButton.java @@ -0,0 +1,164 @@ +package com.fr.design.mainframe; + +import com.fr.base.BaseUtils; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.core.WidgetOption; +import com.fr.design.roleAuthority.ReportAndFSManagePane; +import com.fr.design.utils.gui.GUIPaintUtils; +import com.fr.form.ui.Widget; +import com.fr.form.ui.WidgetManager; +import com.fr.stable.Constants; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +/** + * Created by harry on 2017-3-2. + */ +public class FormToolBarButton extends JButton implements MouseListener { + private Widget widget; + private WidgetOption widgetOption; + + public FormToolBarButton(Icon icon, Widget widget) { + this(null, icon, widget); + } + + public FormToolBarButton(String text, Icon icon, Widget widget) { + super(text, icon); + setBackground(null); + setRolloverEnabled(true); + this.widget = widget; + if (widget instanceof com.fr.form.ui.Button) { + com.fr.form.ui.Button button = (com.fr.form.ui.Button) widget; + String iconName = button.getIconName(); + if (StringUtils.isNotEmpty(iconName)) { + Image iimage = WidgetManager.getProviderInstance().getIconManager().getIconImage(iconName); + if (iimage != null) { + setIcon(new ImageIcon(iimage)); + } + } + } + this.addMouseListener(this); + setMargin(new Insets(0, 0, 0, 0)); + } + + /** + * 改变按钮的权限细粒度状态 + * + * @param selectedRole 选择的角色 + * @param isVisible 是否可见 + */ + public void changeAuthorityState(String selectedRole, boolean isVisible) { + this.widget.changeOnlyVisibleAuthorityState(selectedRole, isVisible); + } + + /** + * 是都做过权限细粒度 + * + * @param role 选择的角色 + * @return 若是对应的该角色做过权限细粒度,则返回true + */ + public boolean isDoneAuthorityEdited(String role) { + return this.widget.isDoneVisibleAuthority(role); + } + + public Widget getWidget() { + return this.widget; + } + + + public void setWidget(Widget widget) { + this.widget = widget; + } + + public WidgetOption getNameOption() { + return this.widgetOption; + } + + public void setNameOption(WidgetOption widgetOption) { + this.widgetOption = widgetOption; + } + + + protected void paintBorder(Graphics g) { + paintBorder(g, this); + } + + protected void paintBorder(Graphics g, FormToolBarButton b) { + String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName(); + GUIPaintUtils.drawBorder((Graphics2D) g, 0, 0, b.getWidth(), b.getHeight(), true, Constants.NULL, b.isDoneAuthorityEdited(selectedRoles)); + } + + /** + * 处理鼠标点击事件 + * + * @param e 鼠标点击事件 + */ + public void mouseClicked(MouseEvent e) { + //该button只在报表块工具栏中使用, + //parent只有FormToolBarPane一种,故可以直接强转 + final FormToolBarPane toolBarPane = (FormToolBarPane) this.getParent(); + if (BaseUtils.isAuthorityEditing()) { + auhtorityMouseAction(); + return; + } + if (e.getClickCount() >= 2) { + final FormEditToolBar editToolBar = new FormEditToolBar(); + editToolBar.populate(toolBarPane.getFToolBar(), this); + BasicDialog dialog = editToolBar.showWindow(DesignerContext.getDesignerFrame()); + dialog.addDialogActionListener(new DialogActionAdapter() { + public void doOk() { + toolBarPane.setFToolBar(editToolBar.update()); + } + }); + dialog.setVisible(true); + } + } + + + private void auhtorityMouseAction() { + if (this.isEnabled()) { + this.setSelected(!this.isSelected()); + } + } + + /** + * 鼠标进入事件 + * + * @param e 鼠标进入事件 + */ + public void mouseEntered(MouseEvent e) { + + } + + /** + * 鼠标退出事件 + * + * @param e 鼠标退出事件 + */ + public void mouseExited(MouseEvent e) { + + } + + /** + * 鼠标按下事件 + * + * @param e 鼠标事件 + */ + public void mousePressed(MouseEvent e) { + + } + + /** + * 鼠标释放事件 + * + * @param e 鼠标事件 + */ + public void mouseReleased(MouseEvent e) { + + } +} diff --git a/designer_form/src/com/fr/design/mainframe/FormToolBarPane.java b/designer_form/src/com/fr/design/mainframe/FormToolBarPane.java new file mode 100644 index 000000000..e64259b27 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/FormToolBarPane.java @@ -0,0 +1,233 @@ +package com.fr.design.mainframe; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.core.WidgetOption; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.form.ui.ToolBar; +import com.fr.form.ui.Widget; + +import javax.swing.*; +import java.awt.*; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.List; + +/** + * Created by harry on 2017-3-2. + */ +public class FormToolBarPane extends BasicBeanPane { + + private FormToolBar ftoolbar = new FormToolBar(); + + public FormToolBarPane() { + super(); + this.initComponent(); + } + + + /** + * 添加鼠标监听 + * + * @param mouselistener 鼠标监听 + */ + public void addAuthorityListener(MouseListener mouselistener) { + List list = ftoolbar.getButtonlist(); + for (int i = 0; i < list.size(); i++) { + list.get(i).addMouseListener(mouselistener); + } + } + + public FormToolBarPane(FormToolBarButton button) { + super(); + this.initComponent(); + this.add(button); + } + + /** + * 初始化组件 + */ + public void initComponent() { + this.addMouseListener(listener); + this.setLayout(FRGUIPaneFactory.createBoxFlowLayout()); + this.setTransferHandler(new ToolBarHandler(TransferHandler.COPY)); + this.setBorder(BorderFactory.createTitledBorder("")); + } + + /** + * 删除鼠标事件 + */ + public void removeDefaultMouseListener() { + this.removeMouseListener(listener); + } + + @Override + protected String title4PopupWindow() { + return "Toolbar"; + } + + public void setSelectedButton(FormToolBarButton button) { + this.ftoolbar.addButton(button); + } + + /** + * 添加组件 + * + * @param comp 组件 + * + * @return 被添加的组件 + */ + public Component add(Component comp) { + if (comp instanceof FormToolBarButton) { + this.ftoolbar.addButton((FormToolBarButton) comp); + } + return super.add(comp); + } + + private Component addComp(Component comp) { + return super.add(comp); + } + + + public void removeButtonList() { + this.ftoolbar.clearButton(); + } + + protected void setFToolBar(FormToolBar ftoolbar) { + if (ftoolbar == null) { + ftoolbar = new FormToolBar(); + } + this.ftoolbar = ftoolbar; + this.setToolBar(this.ftoolbar.getButtonlist()); + } + + public List getToolBarButtons() { + return ftoolbar.getButtonlist(); + } + + protected FormToolBar getFToolBar() { + return this.ftoolbar; + } + + public boolean isEmpty() { + return this.ftoolbar.getButtonlist().size() <= 0; + } + + private void setToolBar(List list) { + if (list == null || list.size() < 0) { + return; + } + this.removeAll(); + for (int i = 0; i < list.size(); i++) { + this.addComp(list.get(i)); + } + this.validate(); + this.repaint(); + + } + + @Override + public void populateBean(ToolBar toolbar) { + this.removeAll(); + this.getFToolBar().clearButton(); + for (int j = 0; j < toolbar.getWidgetSize(); j++) { + Widget widget = toolbar.getWidget(j); + WidgetOption no = WidgetOption.getToolBarButton(widget.getClass()); + if (no == null){ + //如果装了什么插件, 放到了工具栏上, 后来删除了插件, 模板里还存着之前的控件 + continue; + } + + FormToolBarButton button = new FormToolBarButton(no.optionIcon(), widget); + button.setNameOption(no); + this.add(button); + this.validate(); + this.repaint(); + } + this.getFToolBar().setBackground(toolbar.getBackground()); + this.getFToolBar().setDefault(toolbar.isDefault()); + } + + @Override + public ToolBar updateBean() { + return this.ftoolbar.getToolBar(); + } + + MouseListener listener = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() >= 2 && !SwingUtilities.isRightMouseButton(e)) { + final FormEditToolBar tb = new FormEditToolBar(); + tb.populate(getFToolBar()); + BasicDialog dialog = tb.showWindow(SwingUtilities.getWindowAncestor(FormToolBarPane.this)); + dialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + FormToolBarPane.this.setFToolBar(tb.update()); + } + }); + dialog.setVisible(true); + } + } + }; + + + /* + * 拖拽属性设置 + */ + private class ToolBarHandler extends TransferHandler { + private int action; + + public ToolBarHandler(int action) { + this.action = action; + } + + + @Override + public boolean canImport(TransferHandler.TransferSupport support) { + if (!support.isDrop()) { + return false; + } + + if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { + return false; + } + + boolean actionSupported = (action & support.getSourceDropActions()) == action; + if (actionSupported) { + support.setDropAction(action); + return true; + } + + return false; + } + + @Override + public boolean importData(TransferHandler.TransferSupport support) { + if (!canImport(support)) { + return false; + } + WidgetOption data; + try { + data = (WidgetOption) support.getTransferable().getTransferData(DataFlavor.stringFlavor); + } catch (UnsupportedFlavorException e) { + return false; + } catch (java.io.IOException e) { + return false; + } + + Widget widget = data.createWidget(); + FormToolBarButton btn = new FormToolBarButton(data.optionIcon(), widget); + btn.setNameOption(data); + FormToolBarPane.this.add(btn); + FormToolBarPane.this.validate(); + FormToolBarPane.this.repaint(); + return true; + } + + } +} diff --git a/designer_form/src/com/fr/design/mainframe/FormWebWidgetConstants.java b/designer_form/src/com/fr/design/mainframe/FormWebWidgetConstants.java new file mode 100644 index 000000000..4bf970234 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/FormWebWidgetConstants.java @@ -0,0 +1,54 @@ +package com.fr.design.mainframe; + +import com.fr.design.gui.core.WidgetOption; +import com.fr.design.gui.core.WidgetOptionFactory; +import com.fr.form.ui.CustomToolBarButton; +import com.fr.form.web.button.ExcelO; +import com.fr.form.web.button.ExcelP; +import com.fr.form.web.button.Export; +import com.fr.form.web.button.page.*; +import com.fr.general.IOUtils; +import com.fr.general.Inter; + +/** + * Created by harry on 2017-3-3. + */ +public class FormWebWidgetConstants { + + private FormWebWidgetConstants() { + } + + public static WidgetOption[] getFormElementCaseToolBarInstance() { + return new WidgetOption[]{FIRST, PREVIOUS, PAGENAVI, NEXT, LAST, EXPORT, EXCELP, EXCELO, CUSTOM_BUTTON}; + } + + // 当前页/总页数 + public static final WidgetOption PAGENAVI = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"HJS-Current_Page", "HF-Number_of_Page"}, new String[]{"/", ""}), + IOUtils.readIcon("/com/fr/web/images/pageNumber.png"), PageNavi.class); + // 首页 + public static final WidgetOption FIRST = WidgetOptionFactory.createByWidgetClass(Inter.getLocText("FR-Engine_ReportServerP-First"), IOUtils.readIcon("/com/fr/web/images/first.png"), + First.class); + // 末页 + public static final WidgetOption LAST = WidgetOptionFactory.createByWidgetClass(Inter.getLocText("FR-Engine_ReportServerP-Last"), IOUtils.readIcon("/com/fr/web/images/last.png"), + Last.class); + // 前一页 + public static final WidgetOption PREVIOUS = WidgetOptionFactory.createByWidgetClass(Inter.getLocText("FR-Engine_ReportServerP-Previous"), + IOUtils.readIcon("/com/fr/web/images/previous.png"), Previous.class); + // 后一页 + public static final WidgetOption NEXT = WidgetOptionFactory.createByWidgetClass(Inter.getLocText("FR-Engine_ReportServerP-Next"), IOUtils.readIcon("/com/fr/web/images/next.png"), + Next.class); + + // 导出成Excel 分页导出 + public static final WidgetOption EXCELP = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"Excel", "FR-Designer_Export_Excel_Page"}, new String[]{"(", ")"}), + IOUtils.readIcon("/com/fr/web/images/excel.png"), ExcelP.class); + // 导出成Excel 原样导出 + public static final WidgetOption EXCELO = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"Excel", "FR-Designer_Export_Excel_Simple"}, new String[]{"(", ")"}), + IOUtils.readIcon("/com/fr/web/images/excel.png"), ExcelO.class); + // 导出 + public static final WidgetOption EXPORT = WidgetOptionFactory + .createByWidgetClass(Inter.getLocText("FR-Engine_Export"), IOUtils.readIcon("/com/fr/web/images/export.png"), Export.class); + + public static final WidgetOption CUSTOM_BUTTON = WidgetOptionFactory + .createByWidgetClass(Inter.getLocText(new String[]{"Custom", "Form-Button"}), CustomToolBarButton.class); + +} diff --git a/designer_form/src/com/fr/design/mainframe/JForm.java b/designer_form/src/com/fr/design/mainframe/JForm.java index 7c912ede0..ba491e351 100644 --- a/designer_form/src/com/fr/design/mainframe/JForm.java +++ b/designer_form/src/com/fr/design/mainframe/JForm.java @@ -1,790 +1,791 @@ -package com.fr.design.mainframe; - -import com.fr.base.BaseUtils; -import com.fr.design.DesignState; -import com.fr.design.actions.core.WorkBookSupportable; -import com.fr.design.actions.file.WebPreviewUtils; -import com.fr.design.mainframe.actions.FormMobileAttrAction; -import com.fr.design.cell.FloatElementsProvider; -import com.fr.design.constants.UIConstants; -import com.fr.design.designer.beans.actions.FormDeleteAction; -import com.fr.design.designer.beans.events.DesignerEditListener; -import com.fr.design.designer.beans.events.DesignerEvent; -import com.fr.design.designer.creator.*; -import com.fr.design.designer.properties.FormWidgetAuthorityEditPane; -import com.fr.design.event.TargetModifiedEvent; -import com.fr.design.event.TargetModifiedListener; -import com.fr.design.gui.frpane.HyperlinkGroupPane; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.imenu.UIMenuItem; -import com.fr.design.gui.xpane.FormHyperlinkGroupPane; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.mainframe.actions.EmbeddedFormExportExportAction; -import com.fr.design.mainframe.actions.TemplateParameterAction; -import com.fr.design.mainframe.form.FormECCompositeProvider; -import com.fr.design.mainframe.form.FormECDesignerProvider; -import com.fr.design.mainframe.toolbar.ToolBarMenuDock; -import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; -import com.fr.design.menu.KeySetUtils; -import com.fr.design.menu.MenuDef; -import com.fr.design.menu.ShortCut; -import com.fr.design.menu.ToolBarDef; -import com.fr.design.parameter.ParameterPropertyPane; -import com.fr.design.roleAuthority.RolesAlreadyEditedPane; -import com.fr.design.utils.gui.LayoutUtils; -import com.fr.file.FILE; -import com.fr.form.FormElementCaseContainerProvider; -import com.fr.form.FormElementCaseProvider; -import com.fr.form.main.Form; -import com.fr.form.ui.Widget; -import com.fr.form.ui.container.WBorderLayout; -import com.fr.form.ui.container.WLayout; -import com.fr.general.ComparatorUtils; -import com.fr.general.FRLogger; -import com.fr.general.Inter; -import com.fr.stable.ArrayUtils; -import com.fr.stable.Constants; -import com.fr.stable.bridge.StableFactory; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.image.BufferedImage; -import java.util.HashMap; - -public class JForm extends JTemplate implements BaseJForm { - private static final String FORM_CARD = "FORM"; - private static final String ELEMENTCASE_CARD = "ELEMENTCASE"; - - private static final String[] CARDNAME = new String[]{FORM_CARD, ELEMENTCASE_CARD}; - private static final int TOOLBARPANEDIMHEIGHT_FORM = 60; - - //表单设计器 - private FormDesigner formDesign; - //格子设计器 - private FormECDesignerProvider elementCaseDesign; - - //中间编辑区域, carllayout布局 - private JPanel tabCenterPane; - private CardLayout cardLayout; - //当前编辑的组件对象 - private JComponent editingComponent; - private FormECCompositeProvider reportComposite; - - //FORM_TAB代表是否点击编辑,用于点击编辑前后菜单的显示 - protected int index = FORM_TAB; - - public JForm() { - super(new Form(new WBorderLayout("form")), "Form"); - } - - public JForm(Form form, FILE file) { - super(form, file); - } - - public int getMenuState() { - - return DesignState.JFORM; - } - - @Override - protected boolean accept(Object o) { - return !(o instanceof FloatElementsProvider); - } - - /** - * 是否是报表 - * - * @return 否 - */ - public boolean isJWorkBook() { - return false; - } - - /** - * 返回当前支持的超链界面pane - * - * @return 超链连接界面 - */ - public HyperlinkGroupPane getHyperLinkPane() { - return new FormHyperlinkGroupPane(); - } - - //表单返回 FORM_TAB or ELEMENTCASE_TAB - public int getEditingReportIndex() { - return this.index; - } - - public void setAuthorityMode(boolean isUpMode) { - return; - } - - public int getToolBarHeight() { - return TOOLBARPANEDIMHEIGHT_FORM; - } - - /** - * 菜单栏上的文件按钮 - * - * @return 菜单数组 - */ - public ShortCut[] shortcut4FileMenu() { - return (ShortCut[]) ArrayUtils.addAll( - super.shortcut4FileMenu(), new ShortCut[]{this.createWorkBookExportMenu()} - ); - } - - private MenuDef createWorkBookExportMenu() { - MenuDef exportMenuDef = new MenuDef(KeySetUtils.EXPORT.getMenuName()); - exportMenuDef.setIconPath("/com/fr/design/images/m_file/export.png"); - exportMenuDef.addShortCut(new EmbeddedFormExportExportAction(this)); - - return exportMenuDef; - } - - /** - * 取消格式 - */ - public void cancelFormat() { - return; - } - - /** - * 重新计算大小 - */ - public void doResize() { - formDesign.getRootComponent().setSize(formDesign.getSize()); - LayoutUtils.layoutRootContainer(formDesign.getRootComponent()); - } - - @Override - protected JPanel createCenterPane() { - tabCenterPane = FRGUIPaneFactory.createCardLayout_S_Pane(); - cardLayout = (CardLayout) tabCenterPane.getLayout(); - - JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - centerPane.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 0, new Color(85, 85, 85))); - formDesign = new FormDesigner(this.getTarget(), new TabChangeAction(BaseJForm.ELEMENTCASE_TAB, this)); - WidgetToolBarPane.getInstance(formDesign); - FormArea area = new FormArea(formDesign); - centerPane.add(area, BorderLayout.CENTER); - tabCenterPane.add(centerPane, FORM_CARD, FORM_TAB); - - this.add(tabCenterPane, BorderLayout.CENTER); - - formDesign.addTargetModifiedListener(new TargetModifiedListener() { - - @Override - public void targetModified(TargetModifiedEvent e) { - JForm.this.fireTargetModified();// 调用保存*, 调用刷新界面, 刷新工具栏按钮 - } - }); - formDesign.addDesignerEditListener(new DesignerEditListener() { - - @Override - public void fireCreatorModified(DesignerEvent evt) { - if (evt.getCreatorEventID() == DesignerEvent.CREATOR_CUTED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED) { - setPropertyPaneChange(formDesign.getRootComponent()); - } else if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { - setPropertyPaneChange(evt.getAffectedCreator()); - } - } - }); - return tabCenterPane; - } - - public FormDesigner getFormDesign() { - return formDesign; - } - - public void setFormDesign(FormDesigner formDesign) { - this.formDesign = formDesign; - } - - /** - * 去除选择 - */ - public void removeTemplateSelection() { - return; - } - - public void setSheetCovered(boolean isCovered) { - - } - - /** - * 刷新容器 - */ - public void refreshContainer() { - - } - - /** - * 去除参数面板选择 - */ - public void removeParameterPaneSelection() { - return; - } - - /** - * 创建权限细粒度编辑面板 - * - * @return 权限细粒度编辑面板 - */ - public AuthorityEditPane createAuthorityEditPane() { - FormWidgetAuthorityEditPane formWidgetAuthorityEditPane = new FormWidgetAuthorityEditPane(formDesign); - formWidgetAuthorityEditPane.populateDetials(); - return formWidgetAuthorityEditPane; - } - - - private void setPropertyPaneChange(XComponent comp) { - if (comp == null) { - return; - } - editingComponent = comp.createToolPane(this, formDesign); - if (BaseUtils.isAuthorityEditing()) { - EastRegionContainerPane.getInstance().replaceUpPane( - ComparatorUtils.equals(editingComponent.getClass(), NoSupportAuthorityEdit.class) ? editingComponent : createAuthorityEditPane()); - } else { - EastRegionContainerPane.getInstance().replaceUpPane(editingComponent); - - } - } - - public JComponent getEditingPane() { - return editingComponent; - } - - - public ToolBarMenuDockPlus getToolBarMenuDockPlus() { - return this; - } - - - @Override - /** - *焦点放到JForm - */ - public void requestFocus() { - super.requestFocus(); - formDesign.requestFocus(); - } - - /** - * 焦点放到JForm - */ - public void requestGridFocus() { - super.requestFocus(); - formDesign.requestFocus(); - } - - @Override - /** - * 保存文件的后缀名 - * - * @return 返回后缀名 - */ - public String suffix() { - // daniel改成三个字 - return ".frm"; - } - - /** - * 刷新 - */ - public void refreshRoot() { - // formDesign子类的target重置 - this.formDesign.setTarget(this.getTarget()); - this.formDesign.refreshRoot(); - FormHierarchyTreePane.getInstance().refreshRoot(); - } - - /** - * 刷新s - */ - public void refreshAllNameWidgets() { - if (formDesign.getParaComponent() != null) { - XCreatorUtils.refreshAllNameWidgets(formDesign.getParaComponent()); - } - XCreatorUtils.refreshAllNameWidgets(formDesign.getRootComponent()); - } - - /** - * 刷新 - */ - public void refreshSelectedWidget() { - formDesign.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_SELECTED); - } - - @Override - /** - *复制 f - */ - public void copy() { - this.formDesign.copy(); - } - - @Override - /** - * - * 粘贴 - * @return 是否成功 - */ - public boolean paste() { - return this.formDesign.paste(); - } - - @Override - /** - * - * 剪切 - * @return 是否成功 - */ - public boolean cut() { - return this.formDesign.cut(); - } - - // //////////////////////////////////////////////////////////////////// - // ////////////////for toolbarMenuAdapter////////////////////////////// - // //////////////////////////////////////////////////////////////////// - - - @Override - /** - * 目标菜单 - * - * @return 菜单 - */ - public MenuDef[] menus4Target() { - return this.index == FORM_TAB ? - (MenuDef[]) ArrayUtils.addAll(super.menus4Target(), this.formDesign.menus4Target()) : - (MenuDef[]) ArrayUtils.addAll(super.menus4Target(), this.elementCaseDesign.menus4Target()); - } - - @Override - /** - * 模板的工具 - * - * @return 工具 - */ - public ToolBarDef[] toolbars4Target() { - return this.index == FORM_TAB ? - this.formDesign.toolbars4Target() : - this.elementCaseDesign.toolbars4Target(); - } - - @Override - /** - * 模板菜单 - * - * @return 返回菜单 - */ - public ShortCut[] shortcut4TemplateMenu() { - if (this.index == FORM_TAB) { - return (ShortCut[]) ArrayUtils.addAll(new ShortCut[]{ - new TemplateParameterAction(this), - new FormMobileAttrAction(this) - }, new ShortCut[0]); - } else { - return (ShortCut[]) ArrayUtils.addAll(new ShortCut[]{ - new TemplateParameterAction(this), - new FormMobileAttrAction(this) - }, this.elementCaseDesign.shortcut4TemplateMenu()); - } - } - - /** - * 权限细粒度模板菜单 - * 表单中去掉此菜单项 - * - * @return 菜单 - */ - public ShortCut[] shortCuts4Authority() { - return new ShortCut[0]; - } - - @Override - /** - * undo的表单state - * - * @return 表单State - */ - protected FormUndoState createUndoState() { - FormUndoState cur = new FormUndoState(this, this.formDesign.getArea()); - if (this.formDesign.isReportBlockEditing()) { - cur.setFormReportType(BaseUndoState.STATE_FORM_REPORT); - } - return cur; - } - - /** - * 应用UndoState - * - * @param o undo的状态 - */ - public void applyUndoState4Form(BaseUndoState o) { - this.applyUndoState((FormUndoState) o); - } - - /** - * 可以撤销 - * - * @return 是则返回true - */ - public boolean canUndo() { - //报表块最多撤销至编辑报表块的第一步,不能撤销表单中的操作 - boolean inECUndoForm = undoState.getFormReportType() == BaseUndoState.STATE_BEFORE_FORM_REPORT && formDesign.isReportBlockEditing(); - return !inECUndoForm && this.getUndoManager().canUndo(); - } - - // 返回当前的body, - // 假如当前body是自适应的话就沿用, - // 假如当前body是绝对布局的话就返回绝对布局body - private XLayoutContainer selectedBodyLayout() { - XLayoutContainer rootLayout = formDesign.getRootComponent(); - for (int i = 0; i < rootLayout.getComponentCount(); i++){ - if (rootLayout.getXCreator(i).acceptType(XWAbsoluteBodyLayout.class)){ - rootLayout = (XWAbsoluteBodyLayout)rootLayout.getXCreator(i); - } - } - return rootLayout; - } - @Override - /** - * 应用undoState的表单数据 - */ - protected void applyUndoState(FormUndoState u) { - try { - //JForm的target重置 - this.setTarget((Form) u.getForm().clone()); - if (this.index == FORM_TAB) { - JForm.this.refreshRoot(); - this.formDesign.getArea().setAreaSize(u.getAreaSize(), u.getHorizontalValue(), u.getVerticalValue(), u.getWidthValue(), u.getHeightValue(), u.getSlideValue()); - //撤销的时候要重新选择的body布局 - this.formDesign.getSelectionModel().setSelectedCreators(FormSelectionUtils.rebuildSelection(formDesign.getRootComponent(), - formDesign.getRootComponent() == selectedBodyLayout() ? u.getSelectWidgets() : new Widget[]{selectedBodyLayout().toData()})); - } else { - String widgetName = this.formDesign.getElementCaseContainerName(); - //这儿太坑了,u.getForm() 与 getTarget内容不一样 - FormElementCaseProvider dataTable = getTarget().getElementCaseByName(widgetName); - this.reportComposite.setSelectedWidget(dataTable); - //下面这句话是防止撤销之后直接退出编辑再编辑撤销的东西会回来,因为撤销不会保存EC - formDesign.setElementCase(dataTable); - } - } catch (CloneNotSupportedException e) { - throw new RuntimeException(e); - } - - if (BaseUtils.isAuthorityEditing()) { - this.authorityUndoState = u; - } else { - this.undoState = u; - } - - } - - @Override - /** - * - */ - protected FormModelAdapter createDesignModel() { - return new FormModelAdapter(this); - } - - @Override - /** - * 表单的工具栏 - * - * @return 表单工具栏 - */ - public JPanel[] toolbarPanes4Form() { - return this.index == FORM_TAB ? - new JPanel[]{FormParaWidgetPane.getInstance(formDesign)} : - new JPanel[0]; - } - - /** - * 表单的工具按钮 - * - * @return 工具按钮 - */ - public JComponent[] toolBarButton4Form() { - return this.index == FORM_TAB ? - new JComponent[]{ - //自适应布局里的复制粘贴意义不大, 先屏蔽掉 -// new CutAction(formDesign).createToolBarComponent(), -// new CopyAction(formDesign).createToolBarComponent(), -// new PasteAction(formDesign).createToolBarComponent(), - new FormDeleteAction(formDesign).createToolBarComponent()} : - elementCaseDesign.toolBarButton4Form(); - } - - /** - * 权限细粒度状态下的工具面板 - * - * @return 工具面板 - */ - public JComponent toolBar4Authority() { - JPanel panel = new JPanel(new BorderLayout()) { - public Dimension getPreferredSize() { - Dimension dim = super.getPreferredSize(); - dim.height = ToolBarMenuDock.PANLE_HEIGNT; - return dim; - } - }; - UILabel uiLabel = new UILabel(Inter.getLocText(new String[]{"DashBoard-FormBook", "Privilege", "Edit"})); - uiLabel.setHorizontalAlignment(SwingConstants.CENTER); - uiLabel.setFont(new Font(Inter.getLocText("FR-Designer-All_MSBold"), 0, 14)); - uiLabel.setForeground(new Color(150, 150, 150)); - panel.add(uiLabel, BorderLayout.CENTER); - return panel; - } - - - public JPanel getEastUpPane() { - if (BaseUtils.isAuthorityEditing()) { - if (formDesign.isSupportAuthority()) { - return new AuthorityPropertyPane(this); - } else { - return new NoSupportAuthorityEdit(); - } - } else { - if (editingComponent == null) { - editingComponent = formDesign.getRootComponent().createToolPane(this, formDesign); - } - return (JPanel) editingComponent; - } - } - - public JPanel getEastDownPane() { - return formDesign.getEastDownPane(); - } - - @Override - /** - * - */ - public Icon getPreviewLargeIcon() { - return UIConstants.RUN_BIG_ICON; - } - - @Override - /** - * 创建菜单项Preview - * - * @return 菜单 - */ - public UIMenuItem[] createMenuItem4Preview() { - UIMenuItem form = new UIMenuItem(Inter.getLocText("M-Form_Preview"), UIConstants.RUN_SMALL_ICON); - form.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - WebPreviewUtils.onFormPreview(JForm.this); - } - }); - return new UIMenuItem[]{form}; - } - - /** - * 刷新参数 - */ - public void populateParameter() { - formDesign.populateParameterPropertyPane(); - } - - @Override - /** - * 刷新工具区域 - */ - public void refreshToolArea() { - populateParameter(); - DesignerContext.getDesignerFrame().resetToolkitByPlus(JForm.this); - //表单切换后拖不进去组件是因为找不到designer - WidgetToolBarPane.getInstance(formDesign); - if (BaseUtils.isAuthorityEditing()) { - if (formDesign.isSupportAuthority()) { - EastRegionContainerPane.getInstance().replaceUpPane(new AuthorityPropertyPane(this)); - } else { - EastRegionContainerPane.getInstance().replaceUpPane(new NoSupportAuthorityEdit()); - } - EastRegionContainerPane.getInstance().replaceDownPane(RolesAlreadyEditedPane.getInstance()); - return; - } - - if (formDesign.isReportBlockEditing()) { - if (elementCaseDesign != null) { - EastRegionContainerPane.getInstance().removeParameterPane(); - EastRegionContainerPane.getInstance().replaceDownPane(elementCaseDesign.getEastDownPane()); - EastRegionContainerPane.getInstance().replaceUpPane(elementCaseDesign.getEastUpPane()); - return; - } - } - - EastRegionContainerPane.getInstance().replaceUpPane(WidgetPropertyPane.getInstance(formDesign)); - EastRegionContainerPane.getInstance().addParameterPane(ParameterPropertyPane.getInstance(formDesign)); - EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance(formDesign).getPreferredSize().height); - if (EastRegionContainerPane.getInstance().getDownPane() == null) { - new Thread() { - public void run() { - try { - Thread.sleep(1500); - } catch (InterruptedException e) { - FRLogger.getLogger().error(e.getMessage(), e); - } - JPanel pane = new JPanel(); - pane.setLayout(new BorderLayout()); - pane.add(FormWidgetDetailPane.getInstance(formDesign), BorderLayout.CENTER); - EastRegionContainerPane.getInstance().replaceDownPane(pane); - } - }.start(); - } else { - JPanel pane = new JPanel(); - pane.setLayout(new BorderLayout()); - pane.add(FormWidgetDetailPane.getInstance(formDesign), BorderLayout.CENTER); - EastRegionContainerPane.getInstance().replaceDownPane(pane); - - } - } - - public String getEditingCreatorName() { - return formDesign.getSelectionModel().getSelection().getSelectedCreator().toData().getWidgetName(); - } - - public WLayout getRootLayout() { - return formDesign.getRootComponent().toData(); - } - - /** - * 选择的是否是表单主体 - * - * @return 是则返回true - */ - public boolean isSelectRootPane() { - return (formDesign.getRootComponent() == formDesign.getSelectionModel().getSelection().getSelectedCreator()) - || (formDesign.getSelectionModel().getSelection().getSelectedCreator().acceptType(XWAbsoluteBodyLayout.class)); - - } - - /** - * 只在Form和ElementCase之间切换 - * - * @param index 切换位置 - */ - public void tabChanged(int index) { - if (index == ELEMENTCASE_TAB) { - formDesign.setReportBlockEditing(true); - ecTabAction(); - } else { - formDesign.setReportBlockEditing(false); - formTabAction(); - } - this.index = index; - refreshToolArea(); - this.cardLayout.show(tabCenterPane, CARDNAME[index]); - if (elementCaseDesign != null && index == ELEMENTCASE_TAB) { - //报表块编辑失焦,进入报表块可直接编辑A1 - elementCaseDesign.requestFocus(); - //进入编辑报表块,触发一次保存,记住编辑报表块前的表单状态 - //防止报表块中撤销到表单 - JForm.this.fireTargetModified(); - } - } - - /** - * 在Form和ElementCase, 以及ElementCase和ElementCase之间切换 - * - * @param index 切换位置 - * @param ecContainer ElementCase所在container - */ - public void tabChanged(int index, FormElementCaseContainerProvider ecContainer) { - if (index == ELEMENTCASE_CHANGE_TAB) { - saveImage(); - //更新FormDesign中的控件容器 - formDesign.setElementCaseContainer(ecContainer); - //如果只是内部ElementCase之间的切换, 那么不需要下面的界面变动 - return; - } - - tabChanged(index); - } - - /** - * 格子编辑组件 - */ - private FormECDesignerProvider initElementCaseDesign() { - HashMap designerClass = new HashMap(); - designerClass.put(Constants.ARG_0, FormElementCaseProvider.class); - - Object[] designerArg = new Object[]{formDesign.getElementCase()}; - return StableFactory.getMarkedInstanceObjectFromClass(FormECDesignerProvider.XML_TAG, designerArg, designerClass, FormECDesignerProvider.class); - } - - /** - * 整个报表块编辑区域 - */ - private FormECCompositeProvider initComposite() { - Object[] compositeArg = new Object[]{this, elementCaseDesign, formDesign.getElementCaseContainer()}; - HashMap compoClass = new HashMap(); - compoClass.put(Constants.ARG_0, BaseJForm.class); - compoClass.put(Constants.ARG_2, FormElementCaseContainerProvider.class); - return StableFactory.getMarkedInstanceObjectFromClass(FormECCompositeProvider.XML_TAG, compositeArg, compoClass, FormECCompositeProvider.class); - } - - /** - * 切换格子编辑 - */ - private void ecTabAction() { - elementCaseDesign = initElementCaseDesign(); - reportComposite = initComposite(); - - tabCenterPane.add((Component) reportComposite, ELEMENTCASE_CARD, 1); - reportComposite.addTargetModifiedListener(new TargetModifiedListener() { - - @Override - public void targetModified(TargetModifiedEvent e) { - JForm.this.fireTargetModified(); - FormElementCaseProvider te = elementCaseDesign.getEditingElementCase(); - formDesign.setElementCase(te); - } - }); - } - - private void saveImage() { - //触发一次保存, 把缩略图保存起来 - JForm.this.fireTargetModified(); - //用formDesign的size是为了当报表块被拉伸时, 它对应的背景图片需要足够大才不会显示成空白 - BufferedImage image = elementCaseDesign.getElementCaseImage(formDesign.getSize()); - formDesign.setElementCaseBackground(image); - } - - /** - * 切换form编辑 - */ - private void formTabAction() { - saveImage(); - } - - /** - * 取小图标,主要用于多TAB标签栏 - * - * @return 图表 - */ - public Icon getIcon() { - return BaseUtils.readIcon("/com/fr/web/images/form/new_form3.png"); - } - - @Override - public boolean acceptToolbarItem(Class clazz) { - return WorkBookSupportable.class.isAssignableFrom(clazz); - } - - @Override - public Widget getSelectElementCase() { - FormSelection selection = formDesign.getSelectionModel().getSelection(); - XCreator creator = selection.getSelectedCreator(); - return creator.toData(); - } +package com.fr.design.mainframe; + +import com.fr.base.BaseUtils; +import com.fr.design.DesignState; +import com.fr.design.actions.core.WorkBookSupportable; +import com.fr.design.actions.file.WebPreviewUtils; +import com.fr.design.cell.FloatElementsProvider; +import com.fr.design.constants.UIConstants; +import com.fr.design.designer.beans.actions.CopyAction; +import com.fr.design.designer.beans.actions.CutAction; +import com.fr.design.designer.beans.actions.FormDeleteAction; +import com.fr.design.designer.beans.actions.PasteAction; +import com.fr.design.designer.beans.events.DesignerEditListener; +import com.fr.design.designer.beans.events.DesignerEvent; +import com.fr.design.designer.creator.*; +import com.fr.design.designer.properties.FormWidgetAuthorityEditPane; +import com.fr.design.event.TargetModifiedEvent; +import com.fr.design.event.TargetModifiedListener; +import com.fr.design.gui.frpane.HyperlinkGroupPane; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.imenu.UIMenuItem; +import com.fr.design.gui.xpane.FormHyperlinkGroupPane; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.actions.EmbeddedFormExportExportAction; +import com.fr.design.mainframe.actions.FormMobileAttrAction; +import com.fr.design.mainframe.actions.TemplateParameterAction; +import com.fr.design.mainframe.form.FormECCompositeProvider; +import com.fr.design.mainframe.form.FormECDesignerProvider; +import com.fr.design.mainframe.templateinfo.JFormProcessInfo; +import com.fr.design.mainframe.templateinfo.TemplateProcessInfo; +import com.fr.design.mainframe.toolbar.ToolBarMenuDock; +import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; +import com.fr.design.menu.KeySetUtils; +import com.fr.design.menu.MenuDef; +import com.fr.design.menu.ShortCut; +import com.fr.design.menu.ToolBarDef; +import com.fr.design.parameter.ParameterPropertyPane; +import com.fr.design.roleAuthority.RolesAlreadyEditedPane; +import com.fr.design.utils.gui.LayoutUtils; +import com.fr.file.FILE; +import com.fr.form.FormElementCaseContainerProvider; +import com.fr.form.FormElementCaseProvider; +import com.fr.form.main.Form; +import com.fr.form.ui.Widget; +import com.fr.form.ui.container.WBorderLayout; +import com.fr.form.ui.container.WLayout; +import com.fr.general.ComparatorUtils; +import com.fr.general.FRLogger; +import com.fr.general.Inter; +import com.fr.stable.ArrayUtils; +import com.fr.stable.Constants; +import com.fr.stable.bridge.StableFactory; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; +import java.util.HashMap; + +public class JForm extends JTemplate implements BaseJForm { + private static final String FORM_CARD = "FORM"; + private static final String ELEMENTCASE_CARD = "ELEMENTCASE"; + + private static final String[] CARDNAME = new String[]{FORM_CARD, ELEMENTCASE_CARD}; + private static final int TOOLBARPANEDIMHEIGHT_FORM = 60; + + //表单设计器 + private FormDesigner formDesign; + //格子设计器 + private FormECDesignerProvider elementCaseDesign; + + //中间编辑区域, carllayout布局 + private JPanel tabCenterPane; + private CardLayout cardLayout; + //当前编辑的组件对象 + private JComponent editingComponent; + private FormECCompositeProvider reportComposite; + + //FORM_TAB代表是否点击编辑,用于点击编辑前后菜单的显示 + protected int index = FORM_TAB; + + public JForm() { + super(new Form(new WBorderLayout("form")), "Form"); + } + + public JForm(Form form, FILE file) { + super(form, file); + } + + public int getMenuState() { + + return DesignState.JFORM; + } + + public TemplateProcessInfo getProcessInfo() { + if (processInfo == null) { + processInfo = new JFormProcessInfo(template); + } + return processInfo; + } + + @Override + protected boolean accept(Object o) { + return !(o instanceof FloatElementsProvider); + } + + /** + * 是否是报表 + * + * @return 否 + */ + public boolean isJWorkBook() { + return false; + } + + /** + * 返回当前支持的超链界面pane + * + * @return 超链连接界面 + */ + public HyperlinkGroupPane getHyperLinkPane() { + return new FormHyperlinkGroupPane(); + } + + //表单返回 FORM_TAB or ELEMENTCASE_TAB + public int getEditingReportIndex() { + return this.index; + } + + public void setAuthorityMode(boolean isUpMode) { + return; + } + + public int getToolBarHeight() { + return TOOLBARPANEDIMHEIGHT_FORM; + } + + /** + * 菜单栏上的文件按钮 + * + * @return 菜单数组 + */ + public ShortCut[] shortcut4FileMenu() { + return (ShortCut[]) ArrayUtils.addAll( + super.shortcut4FileMenu(), new ShortCut[]{this.createWorkBookExportMenu()} + ); + } + + private MenuDef createWorkBookExportMenu() { + MenuDef exportMenuDef = new MenuDef(KeySetUtils.EXPORT.getMenuName()); + exportMenuDef.setIconPath("/com/fr/design/images/m_file/export.png"); + exportMenuDef.addShortCut(new EmbeddedFormExportExportAction(this)); + + return exportMenuDef; + } + + /** + * 取消格式 + */ + public void cancelFormat() { + return; + } + + /** + * 重新计算大小 + */ + public void doResize() { + formDesign.getRootComponent().setSize(formDesign.getSize()); + LayoutUtils.layoutRootContainer(formDesign.getRootComponent()); + } + + @Override + protected JPanel createCenterPane() { + tabCenterPane = FRGUIPaneFactory.createCardLayout_S_Pane(); + cardLayout = (CardLayout) tabCenterPane.getLayout(); + + JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + centerPane.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 0, new Color(85, 85, 85))); + formDesign = new FormDesigner(this.getTarget(), new TabChangeAction(BaseJForm.ELEMENTCASE_TAB, this)); + WidgetToolBarPane.getInstance(formDesign); + FormArea area = new FormArea(formDesign); + centerPane.add(area, BorderLayout.CENTER); + tabCenterPane.add(centerPane, FORM_CARD, FORM_TAB); + + this.add(tabCenterPane, BorderLayout.CENTER); + + formDesign.addTargetModifiedListener(new TargetModifiedListener() { + + @Override + public void targetModified(TargetModifiedEvent e) { + JForm.this.fireTargetModified();// 调用保存*, 调用刷新界面, 刷新工具栏按钮 + } + }); + formDesign.addDesignerEditListener(new DesignerEditListener() { + + @Override + public void fireCreatorModified(DesignerEvent evt) { + if (evt.getCreatorEventID() == DesignerEvent.CREATOR_CUTED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED) { + setPropertyPaneChange(formDesign.getRootComponent()); + } else if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { + setPropertyPaneChange(evt.getAffectedCreator()); + } + } + }); + return tabCenterPane; + } + + public FormDesigner getFormDesign() { + return formDesign; + } + + public void setFormDesign(FormDesigner formDesign) { + this.formDesign = formDesign; + } + + /** + * 去除选择 + */ + public void removeTemplateSelection() { + return; + } + + public void setSheetCovered(boolean isCovered) { + + } + + /** + * 刷新容器 + */ + public void refreshContainer() { + + } + + /** + * 去除参数面板选择 + */ + public void removeParameterPaneSelection() { + return; + } + + /** + * 创建权限细粒度编辑面板 + * + * @return 权限细粒度编辑面板 + */ + public AuthorityEditPane createAuthorityEditPane() { + FormWidgetAuthorityEditPane formWidgetAuthorityEditPane = new FormWidgetAuthorityEditPane(formDesign); + formWidgetAuthorityEditPane.populateDetials(); + return formWidgetAuthorityEditPane; + } + + + private void setPropertyPaneChange(XComponent comp) { + if (comp == null) { + return; + } + editingComponent = comp.createToolPane(this, formDesign); + if (BaseUtils.isAuthorityEditing()) { + EastRegionContainerPane.getInstance().replaceUpPane( + ComparatorUtils.equals(editingComponent.getClass(), NoSupportAuthorityEdit.class) ? editingComponent : createAuthorityEditPane()); + } else { + EastRegionContainerPane.getInstance().replaceUpPane(editingComponent); + + } + } + + public JComponent getEditingPane() { + return editingComponent; + } + + + public ToolBarMenuDockPlus getToolBarMenuDockPlus() { + return this; + } + + + /** + * 焦点放到JForm + */ + @Override + public void requestFocus() { + super.requestFocus(); + formDesign.requestFocus(); + } + + /** + * 焦点放到JForm + */ + public void requestGridFocus() { + super.requestFocus(); + formDesign.requestFocus(); + } + + /** + * 保存文件的后缀名 + * + * @return 返回后缀名 + */ + @Override + public String suffix() { + // daniel改成三个字 + return ".frm"; + } + + /** + * 刷新 + */ + public void refreshRoot() { + // formDesign子类的target重置 + this.formDesign.setTarget(this.getTarget()); + this.formDesign.refreshRoot(); + FormHierarchyTreePane.getInstance().refreshRoot(); + } + + /** + * 刷新s + */ + public void refreshAllNameWidgets() { + if (formDesign.getParaComponent() != null) { + XCreatorUtils.refreshAllNameWidgets(formDesign.getParaComponent()); + } + XCreatorUtils.refreshAllNameWidgets(formDesign.getRootComponent()); + } + + /** + * 刷新 + */ + public void refreshSelectedWidget() { + formDesign.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_SELECTED); + } + + + /** + * 复制 + */ + @Override + public void copy() { + this.formDesign.copy(); + } + + + /** + * 粘贴 + * + * @return 是否成功 + */ + @Override + public boolean paste() { + return this.formDesign.paste(); + } + + + /** + * 剪切 + * + * @return 是否成功 + */ + @Override + public boolean cut() { + return this.formDesign.cut(); + } + + // //////////////////////////////////////////////////////////////////// + // ////////////////for toolbarMenuAdapter////////////////////////////// + // //////////////////////////////////////////////////////////////////// + + + /** + * 目标菜单 + * + * @return 菜单 + */ + @Override + public MenuDef[] menus4Target() { + return this.index == FORM_TAB ? + (MenuDef[]) ArrayUtils.addAll(super.menus4Target(), this.formDesign.menus4Target()) : + (MenuDef[]) ArrayUtils.addAll(super.menus4Target(), this.elementCaseDesign.menus4Target()); + } + + + /** + * 模板的工具 + * + * @return 工具 + */ + @Override + public ToolBarDef[] toolbars4Target() { + return this.index == FORM_TAB ? + this.formDesign.toolbars4Target() : + this.elementCaseDesign.toolbars4Target(); + } + + + /** + * 模板菜单 + * + * @return 返回菜单 + */ + @Override + public ShortCut[] shortcut4TemplateMenu() { + if (this.index == FORM_TAB) { + return (ShortCut[]) ArrayUtils.addAll(new ShortCut[]{ + new TemplateParameterAction(this), + new FormMobileAttrAction(this) + }, new ShortCut[0]); + } else { + return (ShortCut[]) ArrayUtils.addAll(new ShortCut[]{ + new TemplateParameterAction(this), + new FormMobileAttrAction(this) + }, this.elementCaseDesign.shortcut4TemplateMenu()); + } + } + + /** + * 权限细粒度模板菜单 + * 表单中去掉此菜单项 + * + * @return 菜单 + */ + public ShortCut[] shortCuts4Authority() { + return new ShortCut[0]; + } + + @Override + protected FormUndoState createUndoState() { + FormUndoState cur = new FormUndoState(this, this.formDesign.getArea()); + if (this.formDesign.isReportBlockEditing()) { + cur.setFormReportType(BaseUndoState.STATE_FORM_REPORT); + } + return cur; + } + + /** + * 应用UndoState + * + * @param o undo的状态 + */ + public void applyUndoState4Form(BaseUndoState o) { + this.applyUndoState((FormUndoState) o); + } + + /** + * 可以撤销 + * + * @return 是则返回true + */ + public boolean canUndo() { + //报表块最多撤销至编辑报表块的第一步,不能撤销表单中的操作 + boolean inECUndoForm = undoState.getFormReportType() == BaseUndoState.STATE_BEFORE_FORM_REPORT && formDesign.isReportBlockEditing(); + return !inECUndoForm && this.getUndoManager().canUndo(); + } + + // 返回当前的body, + // 假如当前body是自适应的话就沿用, + // 假如当前body是绝对布局的话就返回绝对布局body + private XLayoutContainer selectedBodyLayout() { + XLayoutContainer rootLayout = formDesign.getRootComponent(); + for (int i = 0; i < rootLayout.getComponentCount(); i++) { + if (rootLayout.getXCreator(i).acceptType(XWAbsoluteBodyLayout.class)) { + rootLayout = (XWAbsoluteBodyLayout) rootLayout.getXCreator(i); + } + } + return rootLayout; + } + + @Override + protected void applyUndoState(FormUndoState u) { + try { + //JForm的target重置 + this.setTarget((Form) u.getForm().clone()); + if (this.index == FORM_TAB) { + JForm.this.refreshRoot(); + this.formDesign.getArea().setAreaSize(u.getAreaSize(), u.getHorizontalValue(), u.getVerticalValue(), u.getWidthValue(), u.getHeightValue(), u.getSlideValue()); + //撤销的时候要重新选择的body布局 + this.formDesign.getSelectionModel().setSelectedCreators(FormSelectionUtils.rebuildSelection(formDesign.getRootComponent(), + formDesign.getRootComponent() == selectedBodyLayout() ? u.getSelectWidgets() : new Widget[]{selectedBodyLayout().toData()})); + } else { + String widgetName = this.formDesign.getElementCaseContainerName(); + //这儿太坑了,u.getForm() 与 getTarget内容不一样 + FormElementCaseProvider dataTable = getTarget().getElementCaseByName(widgetName); + this.reportComposite.setSelectedWidget(dataTable); + //下面这句话是防止撤销之后直接退出编辑再编辑撤销的东西会回来,因为撤销不会保存EC + formDesign.setElementCase(dataTable); + } + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + + if (BaseUtils.isAuthorityEditing()) { + this.authorityUndoState = u; + } else { + this.undoState = u; + } + + } + + @Override + protected FormModelAdapter createDesignModel() { + return new FormModelAdapter(this); + } + + @Override + public JPanel[] toolbarPanes4Form() { + return this.index == FORM_TAB ? + new JPanel[]{FormParaWidgetPane.getInstance(formDesign)} : + new JPanel[0]; + } + + /** + * 表单的工具按钮 + * + * @return 工具按钮 + */ + public JComponent[] toolBarButton4Form() { + return this.index == FORM_TAB ? + new JComponent[]{ + new CutAction(formDesign).createToolBarComponent(), + new CopyAction(formDesign).createToolBarComponent(), + new PasteAction(formDesign).createToolBarComponent(), + new FormDeleteAction(formDesign).createToolBarComponent()} : + elementCaseDesign.toolBarButton4Form(); + } + + /** + * 权限细粒度状态下的工具面板 + * + * @return 工具面板 + */ + public JComponent toolBar4Authority() { + JPanel panel = new JPanel(new BorderLayout()) { + public Dimension getPreferredSize() { + Dimension dim = super.getPreferredSize(); + dim.height = ToolBarMenuDock.PANLE_HEIGNT; + return dim; + } + }; + UILabel uiLabel = new UILabel(Inter.getLocText(new String[]{"DashBoard-FormBook", "Privilege", "Edit"})); + uiLabel.setHorizontalAlignment(SwingConstants.CENTER); + uiLabel.setFont(new Font(Inter.getLocText("FR-Designer-All_MSBold"), 0, 14)); + uiLabel.setForeground(new Color(150, 150, 150)); + panel.add(uiLabel, BorderLayout.CENTER); + return panel; + } + + + public JPanel getEastUpPane() { + if (BaseUtils.isAuthorityEditing()) { + if (formDesign.isSupportAuthority()) { + return new AuthorityPropertyPane(this); + } else { + return new NoSupportAuthorityEdit(); + } + } else { + if (editingComponent == null) { + editingComponent = formDesign.getRootComponent().createToolPane(this, formDesign); + } + return (JPanel) editingComponent; + } + } + + public JPanel getEastDownPane() { + return formDesign.getEastDownPane(); + } + + @Override + /** + * + */ + public Icon getPreviewLargeIcon() { + return UIConstants.RUN_BIG_ICON; + } + + @Override + /** + * 创建菜单项Preview + * + * @return 菜单 + */ + public UIMenuItem[] createMenuItem4Preview() { + UIMenuItem form = new UIMenuItem(Inter.getLocText("M-Form_Preview"), UIConstants.RUN_SMALL_ICON); + form.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + WebPreviewUtils.onFormPreview(JForm.this); + } + }); + return new UIMenuItem[]{form}; + } + + /** + * 刷新参数 + */ + public void populateParameter() { + formDesign.populateParameterPropertyPane(); + } + + @Override + /** + * 刷新工具区域 + */ + public void refreshToolArea() { + populateParameter(); + DesignerContext.getDesignerFrame().resetToolkitByPlus(JForm.this); + //表单切换后拖不进去组件是因为找不到designer + WidgetToolBarPane.getInstance(formDesign); + if (BaseUtils.isAuthorityEditing()) { + if (formDesign.isSupportAuthority()) { + EastRegionContainerPane.getInstance().replaceUpPane(new AuthorityPropertyPane(this)); + } else { + EastRegionContainerPane.getInstance().replaceUpPane(new NoSupportAuthorityEdit()); + } + EastRegionContainerPane.getInstance().replaceDownPane(RolesAlreadyEditedPane.getInstance()); + return; + } + + if (formDesign.isReportBlockEditing()) { + if (elementCaseDesign != null) { + EastRegionContainerPane.getInstance().removeParameterPane(); + EastRegionContainerPane.getInstance().replaceDownPane(elementCaseDesign.getEastDownPane()); + EastRegionContainerPane.getInstance().replaceUpPane(elementCaseDesign.getEastUpPane()); + return; + } + } + + EastRegionContainerPane.getInstance().replaceUpPane(WidgetPropertyPane.getInstance(formDesign)); + EastRegionContainerPane.getInstance().addParameterPane(ParameterPropertyPane.getInstance(formDesign)); + EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance(formDesign).getPreferredSize().height); + if (EastRegionContainerPane.getInstance().getDownPane() == null) { + new Thread() { + public void run() { + try { + Thread.sleep(1500); + } catch (InterruptedException e) { + FRLogger.getLogger().error(e.getMessage(), e); + } + JPanel pane = new JPanel(); + pane.setLayout(new BorderLayout()); + pane.add(FormWidgetDetailPane.getInstance(formDesign), BorderLayout.CENTER); + EastRegionContainerPane.getInstance().replaceDownPane(pane); + } + }.start(); + } else { + JPanel pane = new JPanel(); + pane.setLayout(new BorderLayout()); + pane.add(FormWidgetDetailPane.getInstance(formDesign), BorderLayout.CENTER); + EastRegionContainerPane.getInstance().replaceDownPane(pane); + + } + } + + public String getEditingCreatorName() { + return formDesign.getSelectionModel().getSelection().getSelectedCreator().toData().getWidgetName(); + } + + public WLayout getRootLayout() { + return formDesign.getRootComponent().toData(); + } + + /** + * 选择的是否是表单主体 + * + * @return 是则返回true + */ + public boolean isSelectRootPane() { + return (formDesign.getRootComponent() == formDesign.getSelectionModel().getSelection().getSelectedCreator()) + || (formDesign.getSelectionModel().getSelection().getSelectedCreator().acceptType(XWAbsoluteBodyLayout.class)); + + } + + /** + * 只在Form和ElementCase之间切换 + * + * @param index 切换位置 + */ + public void tabChanged(int index) { + if (index == ELEMENTCASE_TAB) { + formDesign.setReportBlockEditing(true); + ecTabAction(); + } else { + formDesign.setReportBlockEditing(false); + formTabAction(); + } + this.index = index; + refreshToolArea(); + this.cardLayout.show(tabCenterPane, CARDNAME[index]); + if (elementCaseDesign != null && index == ELEMENTCASE_TAB) { + //报表块编辑失焦,进入报表块可直接编辑A1 + elementCaseDesign.requestFocus(); + //进入编辑报表块,触发一次保存,记住编辑报表块前的表单状态 + //防止报表块中撤销到表单 + JForm.this.fireTargetModified(); + } + } + + /** + * 在Form和ElementCase, 以及ElementCase和ElementCase之间切换 + * + * @param index 切换位置 + * @param ecContainer ElementCase所在container + */ + public void tabChanged(int index, FormElementCaseContainerProvider ecContainer) { + if (index == ELEMENTCASE_CHANGE_TAB) { + saveImage(); + //更新FormDesign中的控件容器 + formDesign.setElementCaseContainer(ecContainer); + //如果只是内部ElementCase之间的切换, 那么不需要下面的界面变动 + return; + } + + tabChanged(index); + } + + /** + * 格子编辑组件 + */ + private FormECDesignerProvider initElementCaseDesign() { + HashMap designerClass = new HashMap(); + designerClass.put(Constants.ARG_0, FormElementCaseProvider.class); + + Object[] designerArg = new Object[]{formDesign.getElementCase()}; + return StableFactory.getMarkedInstanceObjectFromClass(FormECDesignerProvider.XML_TAG, designerArg, designerClass, FormECDesignerProvider.class); + } + + /** + * 整个报表块编辑区域 + */ + private FormECCompositeProvider initComposite() { + Object[] compositeArg = new Object[]{this, elementCaseDesign, formDesign.getElementCaseContainer()}; + HashMap compoClass = new HashMap(); + compoClass.put(Constants.ARG_0, BaseJForm.class); + compoClass.put(Constants.ARG_2, FormElementCaseContainerProvider.class); + return StableFactory.getMarkedInstanceObjectFromClass(FormECCompositeProvider.XML_TAG, compositeArg, compoClass, FormECCompositeProvider.class); + } + + /** + * 切换格子编辑 + */ + private void ecTabAction() { + elementCaseDesign = initElementCaseDesign(); + reportComposite = initComposite(); + + tabCenterPane.add((Component) reportComposite, ELEMENTCASE_CARD, 1); + reportComposite.addTargetModifiedListener(new TargetModifiedListener() { + + @Override + public void targetModified(TargetModifiedEvent e) { + JForm.this.fireTargetModified(); + FormElementCaseProvider te = elementCaseDesign.getEditingElementCase(); + formDesign.setElementCase(te); + } + }); + } + + private void saveImage() { + //触发一次保存, 把缩略图保存起来 + JForm.this.fireTargetModified(); + //用formDesign的size是为了当报表块被拉伸时, 它对应的背景图片需要足够大才不会显示成空白 + BufferedImage image = elementCaseDesign.getElementCaseImage(formDesign.getSize()); + formDesign.setElementCaseBackground(image); + } + + /** + * 切换form编辑 + */ + private void formTabAction() { + saveImage(); + } + + /** + * 取小图标,主要用于多TAB标签栏 + * + * @return 图表 + */ + public Icon getIcon() { + return BaseUtils.readIcon("/com/fr/web/images/form/new_form3.png"); + } + + @Override + public boolean acceptToolbarItem(Class clazz) { + return WorkBookSupportable.class.isAssignableFrom(clazz); + } + + @Override + public Widget getSelectElementCase() { + FormSelection selection = formDesign.getSelectionModel().getSelection(); + XCreator creator = selection.getSelectedCreator(); + return creator.toData(); + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/MobileBodyWidgetTable.java b/designer_form/src/com/fr/design/mainframe/MobileBodyWidgetTable.java deleted file mode 100644 index 90e2316a6..000000000 --- a/designer_form/src/com/fr/design/mainframe/MobileBodyWidgetTable.java +++ /dev/null @@ -1,267 +0,0 @@ -package com.fr.design.mainframe; - -import java.awt.Color; -import java.awt.Component; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; - -import javax.swing.BorderFactory; -import javax.swing.JLabel; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.JTableHeader; -import javax.swing.table.TableModel; - -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itable.HeaderRenderer; -import com.fr.form.ui.Widget; -import com.fr.form.ui.container.WFitLayout; -import com.fr.general.ComparatorUtils; -import com.fr.general.Inter; -import com.fr.stable.StringUtils; - -/** - * Created with IntelliJ IDEA. - * User: zx - * Date: 14-9-15 - * Time: 下午4:52 - */ -public class MobileBodyWidgetTable extends JTable { - - private FormDesigner designer; - protected TableModel defaultmodel; - private String[][] cellData; - private String[] headers = {Inter.getLocText("Form-Widget_Name")}; - public static final int WIDGET_TABLE_ROW_HEIGHT = 22; - private UILabel moveComponent = new UILabel(); - private int selectedRow = -1; - private int GAP = 10; - private boolean draging = false; - - - public MobileBodyWidgetTable(FormDesigner designer) { - this.designer = designer; - cellData = getData(); - this.setRowHeight(WIDGET_TABLE_ROW_HEIGHT); - JTableHeader header = getTableHeader(); - header.setReorderingAllowed(false); - header.setPreferredSize(new Dimension(0, WIDGET_TABLE_ROW_HEIGHT)); - HeaderRenderer headerRenderer = new HeaderRenderer(); - headerRenderer.setHorizontalAlignment(JLabel.CENTER); - header.setDefaultRenderer(headerRenderer); - this.setGridColor(new Color(212, 208, 200)); - this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - this.setColumnSelectionAllowed(false); - this.setRowSelectionAllowed(false); - this.setFillsViewportHeight(true); - defaultmodel = new BeanTableModel(); - this.setModel(defaultmodel); - this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); - this.repaint(); - this.setDefaultRenderer(Object.class,new MobileWidgetTableCellRenderer()); - refresh(); - this.addMouseListener(mouseAdapter); - this.addMouseMotionListener(mouseAdapter); - add(moveComponent); - } - - private MouseAdapter mouseAdapter = new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - if(getSelectedRow() != -1){ - String widgetName = cellData[getSelectedRow()][0]; - if (StringUtils.isNotEmpty(widgetName)){ - XLayoutContainer root = getEditingDesigner().getRootComponent(); - int count = root.getXCreatorCount(); - for (int i = 0;i < count ;i++){ - XCreator xCreator = root.getXCreator(i).getEditingChildCreator(); - Widget widget = xCreator.toData(); - if (ComparatorUtils.equals(widgetName, widget.getWidgetName())) { - getEditingDesigner().getSelectionModel().setSelectedCreator(xCreator); - setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); - selectedRow = getSelectedRow(); - } - } - } - } - } - public void mouseExited(MouseEvent e) { - draging = false; - moveComponent.setVisible(false); - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - - @Override - public void mouseMoved(MouseEvent e) { - int overRow = 0; - for (int i = 0;i < getRowCount();i++) { - if (e.getY() > i * WIDGET_TABLE_ROW_HEIGHT && e.getY() <= (i + 1) * WIDGET_TABLE_ROW_HEIGHT){ - overRow = i; - } - } - if (overRow == getSelectedRow()) { - setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); - } else { - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - } - - @Override - public void mouseDragged(MouseEvent e) { - int width = getColumnModel().getColumn(0).getWidth(); - if (getCursor().getType() == Cursor.MOVE_CURSOR){ - draging = true; - //下面这句话太重要了,拖拽过程中选中的不变 - getInstance().setRowSelectionInterval(selectedRow,selectedRow); - moveComponent.setText(getValueAt(getSelectedRow(), getSelectedColumn()).toString()); - moveComponent.setLocation(0, e.getY() - GAP); - moveComponent.setPreferredSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT)); - moveComponent.setSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT)); - moveComponent.setVisible(true); - moveComponent.setForeground(Color.lightGray); - moveComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray)); - } - } - @Override - public void mouseReleased(MouseEvent e) { - if(!draging){ - return; - } - draging = false; - moveComponent.setVisible(false); - int toIndex = e.getY() < GAP ? 0 : (int)Math.rint((e.getY() - GAP)/WIDGET_TABLE_ROW_HEIGHT) + 1; - ((WFitLayout) designer.getRootComponent().toData()).adjustOrder(getSelectedRow(), toIndex); - getInstance().setRowSelectionInterval(0,getRowCount() - 1); - refresh(); - getInstance().repaint(); - designer.fireTargetModified(); - } - }; - - public MobileBodyWidgetTable getInstance(){ - return this; - } - - public FormDesigner getEditingDesigner(){ - return designer; - } - - /** - * 刷新 - */ - public void refresh(){ - XCreator creator = designer.getSelectionModel().getSelection().getSelectedCreator(); - cellData = getData(); - if(creator != null){ - String widgetName =creator.toData().getWidgetName(); - int row = -1; - for (int i =0; i < cellData.length;i++){ - if(ComparatorUtils.equals(widgetName, cellData[i][0])){ - row = i; - break; - } - } - selectedRow = row; - changeSelection(row,0,false,false); - if(row == -1){ - this.clearSelection(); - } - } - } - - private String[][] getData(){ - if(designer.isFormParaDesigner()){ - return new String[0][0]; - } - XLayoutContainer paraContainer = designer.getRootComponent(); - if(paraContainer == null || !paraContainer.acceptType(WFitLayout.class)){ - return new String[0][0]; - } - - WFitLayout fitLayout = (WFitLayout) (paraContainer.toData()); - ArrayList strings = fitLayout.getMobileWidgetList(); - String[][] widgetName = new String[strings.size()][2]; - for(int i = 0;i < strings.size();i++){ - widgetName[i][0] = strings.get(i); - } - return widgetName; - } - - private class MobileWidgetTableCellRenderer extends DefaultTableCellRenderer { - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, - boolean hasFocus, int row, int column) { - if (getCursor().getType() == Cursor.MOVE_CURSOR){ - if(selectedRow > -1 && selectedRow < getRowCount()){ - //拖拽过程中选中的不变 - getInstance().setRowSelectionInterval(selectedRow,selectedRow); - } - } - super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - return this; - } - - } - - public class BeanTableModel extends DefaultTableModel { - public BeanTableModel() { - super(cellData,headers); - } - - @Override - public int getRowCount() { - return cellData.length; - } - - @Override - public int getColumnCount() { - return 1; - } - - - @Override - public Object getValueAt(int row, int column) { - if (row >= getRowCount() || column >= getColumnCount()) { - return null; - } - - return cellData[row][0]; - } - - @Override - public String getColumnName(int column) { - return headers[0]; - } - - - @Override - public void setValueAt(Object aValue, int row, int column) { - if (row >= getRowCount() || column >= getColumnCount()) { - return; - } - if (aValue == null) { - cellData[row] = null; - return; - } - cellData[row][0] = aValue.toString(); - } - - /** - * 是否可编辑 - * @param row 行号 - * @param column 列号 - * @return 是否可编辑 - */ - public boolean isCellEditable(int row, int column) { - return false; - } - - } - -} \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/MobileParaWidgetTable.java b/designer_form/src/com/fr/design/mainframe/MobileParaWidgetTable.java new file mode 100644 index 000000000..80fa7f895 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/MobileParaWidgetTable.java @@ -0,0 +1,431 @@ +package com.fr.design.mainframe; + + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Component; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.geom.RoundRectangle2D; +import java.util.EventObject; + +import javax.swing.AbstractCellEditor; +import javax.swing.BorderFactory; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.JTableHeader; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableColumn; +import javax.swing.table.TableModel; + +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itable.GroupRenderer; +import com.fr.design.gui.itable.HeaderRenderer; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWParameterLayout; +import com.fr.form.ui.Label; +import com.fr.form.ui.Widget; +import com.fr.form.ui.container.WParameterLayout; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.stable.StringUtils; + +/** + * MobileParaWidgetTable主要显示参数面板容器的控件列表,与MobileWidgetTable的区别就是该表多了UITextField这一列 + * Created with IntelliJ IDEA. + * User: zx + * Date: 14-7-9 + * Time: 上午11:26 + * Modified by fanglei during 2017/1/22 - 2017/2/ + */ +class MobileParaWidgetTable extends JTable { + + private FormDesigner designer; + private String[][] cellData ; + private String[] headers = {Inter.getLocText("FR-Utils_Label"), Inter.getLocText("Form-Widget_Name")}; + private static final int WIDGET_TABLE_ROW_HEIGHT = 22; + private static final int UITEXTFIELD_WIDTH = 40; + private UILabel moveComponent = new UILabel(); // 作为拖动时候随鼠标移动的那个半透明控件 + private int selectedRow = -1; + private int selectedColumn = -1; + private int GAP = 11; + private boolean draging = false; + + MobileParaWidgetTable(FormDesigner designer) { + this.designer = designer; + this.cellData = getData(); + this.setTableProperties(); + this.setDefaultEditor(Object.class, new MobileCellEditor()); + TableModel defaultModel = new BeanTableModel(); + this.setModel(defaultModel); + this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); + TableColumn tc = this.getColumn(this.getColumnName(0)); + tc.setPreferredWidth(UITEXTFIELD_WIDTH); + this.repaint(); + this.setDefaultRenderer(Object.class,new MobileWidgetTableCellRenderer()); + refreshData(); + this.addMouseListener(mouseAdapter); + this.addMouseMotionListener(mouseAdapter); + add(moveComponent); + } + + private void setTableProperties() { + JTableHeader header = getTableHeader(); + header.setReorderingAllowed(false); + header.setPreferredSize(new Dimension(0, WIDGET_TABLE_ROW_HEIGHT)); + header.setDefaultRenderer(new HeaderRenderer()); + + this.setRowHeight(WIDGET_TABLE_ROW_HEIGHT); + this.setGridColor(new Color(212, 208, 200)); + this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + this.setColumnSelectionAllowed(false); + this.setRowSelectionAllowed(false); + this.setFillsViewportHeight(true); + } + + private MouseAdapter mouseAdapter = new MouseAdapter() { + /** + * 鼠标按下时处理的事件(设置当前选中的行列) + * @param e + */ + @Override + public void mousePressed(MouseEvent e) { + getInstance().setCellSelected(); + } + + /** + * 鼠标放开时处理的事件(如果是正在拖动则执行换位操作,重新绘制属性表,如果不是则什么也不做) + * @param e + */ + @Override + public void mouseReleased(MouseEvent e) { + if(!draging){ + return; + } + draging = false; + moveComponent.setVisible(false); + int toIndex = e.getY() < GAP ? 0 : (int)Math.rint((e.getY() - GAP)/WIDGET_TABLE_ROW_HEIGHT) + 1; + //当鼠标放开时,将选中的容器调整至新的顺序 + ((WParameterLayout) designer.getParaComponent().toData()).adjustOrder(selectedRow, toIndex); + //拿取排序后表格数据,然后重绘表格 + getInstance().refreshData(); + getInstance().repaint(); + designer.fireTargetModified(); + getInstance().setCellSelected(); + } + + /** + * 设置鼠标在属性表区域移动时候的事件 + * @param e + */ + @Override + public void mouseMoved(MouseEvent e) { + int overColumn = e.getX() < getColumnModel().getColumn(0).getWidth() ? 0 : 1; // 判断当前鼠标在哪一列 + int overRow = -1; + for (int i = 0;i < getRowCount();i++) { + if (e.getY() > i * WIDGET_TABLE_ROW_HEIGHT && e.getY() <= (i + 1) * WIDGET_TABLE_ROW_HEIGHT) { + overRow = i; //判断当前鼠标在哪一行 + } + } + //如果鼠标移动到当前选中的行列上面的时候,并且不能在第一列 + if (overRow == selectedRow && overColumn == selectedColumn && overColumn !=0) { + //把当前选中的那一列行的光标改成(除了第一列)移动样式MOVE_CURSOR + setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + } else { + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + } + + /** + * 鼠标拖动事件(如果鼠标当前是MOVE_CURSOR状态则执行开始拖动的代码, + * 绘制一个moveComponent来跟随鼠标移动) + * @param e + */ + @Override + public void mouseDragged(MouseEvent e) { + int width = getColumnModel().getColumn(1).getWidth(); + //如果点击选中的是第二列,就可以拖动 + if (selectedColumn == 1){ + setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + draging = true; + moveComponent.setText(getValueAt(selectedRow, selectedColumn).toString()); + moveComponent.setLocation(getColumnModel().getColumn(0).getWidth(), e.getY() - GAP); + moveComponent.setSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT)); + moveComponent.setVisible(true); + moveComponent.setForeground(Color.lightGray); + moveComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray)); + } + } + + /** + * 设置鼠标单击时处理的事件(单击第二列的控件列表进入控件属性表) + * @param e + */ + @Override + public void mouseClicked(MouseEvent e) { + if(getSelectedRow() != -1 && getSelectedColumn() == 1){ + String widgetName = cellData[getSelectedRow()][getSelectedColumn()]; + if (StringUtils.isNotEmpty(widgetName)){ + int count = getEditingDesigner().getParaComponent().getComponentCount(); + for (int i = 0; i < count; i++){ + XCreator xCreator = (XCreator)getEditingDesigner().getParaComponent().getComponent(i); + Widget widget = xCreator.toData(); + if (!widget.acceptType(Label.class) && ComparatorUtils.equals(widgetName,widget.getWidgetName())) { + //设置选中的component,这句代码控制点击之后跳转到相应component属性表 + getEditingDesigner().getSelectionModel().setSelectedCreator(xCreator); + } + } + } + } + } + + /** + * 鼠标离开属性表区域事件 + * @param e + */ + @Override + public void mouseExited(MouseEvent e) { + draging = false; + moveComponent.setVisible(false); + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + }; + + public MobileParaWidgetTable getInstance(){ + return this; + } + + private FormDesigner getEditingDesigner(){ + return designer; + } + + /** + * 设置当前get到的行列的单元格为选中状态 + */ + private void setCellSelected() { + selectedRow = getSelectedRow(); + selectedColumn = getSelectedColumn(); + if (selectedRow != -1) { + this.setRowSelectionInterval(selectedRow, selectedRow); + } + if (selectedColumn != -1) { + this.setColumnSelectionInterval(selectedColumn, selectedColumn); + } + } + + /** + * 重新get排序后的数据 + */ + public void refreshData(){ + cellData = getData(); + } + + /** + * 获取参数面板的控件列表 + * + * @return String[][] 二维数组,[0][0]widgetTag, [0][1]widgetName + */ + private String[][] getData(){ + XLayoutContainer paraContainer = designer.getParaComponent(); + if(paraContainer == null || !paraContainer.acceptType(XWParameterLayout.class)){ + return new String[0][0]; + } + + WParameterLayout para = (WParameterLayout) (paraContainer.toData()); + return para.getWidgetNameTag(); + } + + /** + * 自定义的tableRender类 + */ + private class MobileWidgetTableCellRenderer extends DefaultTableCellRenderer{ + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, + boolean hasFocus, int row, int column) { + super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + if (column == 0){ + UITextField uiTableTextField; + if (getSelectedColumn() == column && getSelectedRow() == row){ + uiTableTextField = new UITableTextField(value.toString()); + } else { + uiTableTextField = new UITextField(value.toString()); + } + return uiTableTextField; + } + return this; + } + + } + + /** + * 自定义的tableEditor类 + */ + private class MobileCellEditor extends AbstractCellEditor implements TableCellEditor { + UITableTextField uiTableTextField; + MobileCellEditor(){ + uiTableTextField = new UITableTextField(); + uiTableTextField.addFocusListener(new FocusAdapter() { + @Override + public void focusLost(FocusEvent evt) { + stopCellEditing(); + designer.fireTargetModified(); + } + }); + uiTableTextField.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent e) { + firePropertyChange(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + firePropertyChange(); + } + + @Override + public void changedUpdate(DocumentEvent e) { + firePropertyChange(); + } + }); + } + + /** + * cell改变,相应的nametag改变 + */ + + private void firePropertyChange(){ + ((WParameterLayout) designer.getParaComponent().toData()).add2NameTagMap(uiTableTextField.getText(), + cellData[getSelectedRow()][1]); + ((WParameterLayout) designer.getParaComponent().toData()).setNameTagModified(cellData[getSelectedRow()][1], + true); + } + + @Override + public Object getCellEditorValue(){ + return uiTableTextField.getText(); + } + + /** + * 双击以编辑, 表示只有双击的情况下才可以编辑 + */ + @Override + public boolean isCellEditable(EventObject anEvent) { + return !(anEvent instanceof MouseEvent) || ((MouseEvent) anEvent).getClickCount() >= 2; + } + + @Override + public Component getTableCellEditorComponent( JTable table,Object value, + boolean isSelected,int row,int column){ + uiTableTextField.setText(value.toString()); + return uiTableTextField; + } + } + + /** + * BeanTableModel类继承DefaultTableModel类,指定了表格的表头和内容 + */ + private class BeanTableModel extends DefaultTableModel { + BeanTableModel() { + super(cellData, headers); + } + + @Override + public int getRowCount() { + return cellData.length; + } + + @Override + public int getColumnCount() { + return headers.length; + } + + + @Override + public Object getValueAt(int row, int column) { + if (row >= getRowCount() || column >= getColumnCount()) { + return null; + } + Object[] rowValue = cellData[row]; + if (column > -1 && column < rowValue.length) { + return cellData[row][column]; + } + return null; + } + + @Override + public String getColumnName(int column) { + if (column == 0) { + return headers[0]; + } else { + return headers[1]; + } + } + + + @Override + public void setValueAt(Object aValue, int row, int column) { + if (row >= getRowCount() || column >= getColumnCount()) { + return; + } + if (aValue == null) { + cellData[row][column] = null; + return; + } + cellData[row][column] = aValue.toString(); + } + + /** + * 是否可编辑 控件标签列可以编辑,控件名不可编辑 + * @param row 行号 + * @param column 列号 + * @return 是否可编辑 + */ + public boolean isCellEditable(int row, int column) { + if(column ==1){ + return false; + } + return true; + } + + } + + /** + * 继承自JTextField类,重写了编辑框的样式 + */ + private class UITableTextField extends UITextField { + public UITableTextField(){ + super(); + } + + public UITableTextField(String string){ + super(string); + } + + protected void paintBorder(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + if (this.isFocusOwner()) { + g2d.setStroke(new BasicStroke(1.5f)); + } else { + g2d.setStroke(new BasicStroke(1f)); + } + RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, this.getWidth() - 2, this.getHeight() - 2, 4, 4); + g2d.setColor(Color.orange); + g2d.draw(rect); + } + + } +} \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java b/designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java index fb8f5fc86..c9a858797 100644 --- a/designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java +++ b/designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java @@ -1,385 +1,348 @@ -package com.fr.design.mainframe; - - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Component; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.geom.RoundRectangle2D; -import java.util.EventObject; - -import javax.swing.AbstractCellEditor; -import javax.swing.BorderFactory; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.JTableHeader; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableColumn; -import javax.swing.table.TableModel; - -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itable.HeaderRenderer; -import com.fr.design.gui.itextfield.UITextField; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWParameterLayout; -import com.fr.form.ui.Label; -import com.fr.form.ui.Widget; -import com.fr.form.ui.container.WParameterLayout; -import com.fr.general.ComparatorUtils; -import com.fr.general.Inter; -import com.fr.stable.StringUtils; - -/** - * Created with IntelliJ IDEA. - * User: zx - * Date: 14-7-9 - * Time: 上午11:26 - */ -public class MobileWidgetTable extends JTable { - - private FormDesigner designer; - protected TableModel defaultmodel; - private String[][] cellData ; - private String[] headers = {Inter.getLocText("FR-Utils_Label"),Inter.getLocText("Form-Widget_Name")}; - public static final int WIDGET_TABLE_ROW_HEIGHT = 22; - private UILabel moveComponent = new UILabel(); - private int selectedRow = -1; - private int GAP = 10; - private boolean draging = false; - - public MobileWidgetTable(FormDesigner designer) { - this.designer = designer; - this.cellData = getData(); - this.setRowHeight(WIDGET_TABLE_ROW_HEIGHT); - JTableHeader header = getTableHeader(); - header.setReorderingAllowed(false); - header.setPreferredSize(new Dimension(0, WIDGET_TABLE_ROW_HEIGHT)); - header.setDefaultRenderer(new HeaderRenderer()); - this.setGridColor(new Color(212, 208, 200)); - this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - this.setColumnSelectionAllowed(false); - this.setRowSelectionAllowed(false); - this.setFillsViewportHeight(true); - this.setDefaultEditor(Object.class,new MobileCellEditor()); - defaultmodel = new BeanTableModel(); - this.setModel(defaultmodel); - this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); - TableColumn tc = this.getColumn(this.getColumnName(0)); - tc.setPreferredWidth(30); - this.repaint(); - this.setDefaultRenderer(Object.class,new MobileWidgetTableCellRenderer()); - refresh(); - this.addMouseListener(mouseAdapter); - this.addMouseMotionListener(mouseAdapter); - add(moveComponent); - } - - private MouseAdapter mouseAdapter = new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - if(getSelectedRow() != -1 && getSelectedColumn() == 1){ - String widgetName = cellData[getSelectedRow()][getSelectedColumn()]; - if (StringUtils.isNotEmpty(widgetName)){ - int count = getEditingDesigner().getParaComponent().getComponentCount(); - for (int i = 0;i < count ;i++){ - XCreator xCreator = (XCreator)getEditingDesigner().getParaComponent().getComponent(i); - Widget widget = xCreator.toData(); - if (!widget.acceptType(Label.class) && ComparatorUtils.equals(widgetName,widget.getWidgetName())) { - getEditingDesigner().getSelectionModel().setSelectedCreator(xCreator); - setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); - selectedRow = getSelectedRow(); - } - } - } - } - } - public void mouseExited(MouseEvent e) { - draging = false; - moveComponent.setVisible(false); - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - - @Override - public void mouseMoved(MouseEvent e) { - int overColumn = e.getX() < getColumnModel().getColumn(0).getWidth() ? 0 : 1; - int overRow = -1; - for (int i = 0;i < getRowCount();i++) { - if (e.getY() > i * WIDGET_TABLE_ROW_HEIGHT && e.getY() <= (i + 1) * WIDGET_TABLE_ROW_HEIGHT){ - overRow = i; - } - } - if (overRow == getSelectedRow() && overColumn == getSelectedColumn() && overColumn !=0) { - setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); - } else { - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - } - - @Override - public void mouseDragged(MouseEvent e) { - if (e.getX() < getColumnModel().getColumn(0).getWidth()) { - draging = false; - moveComponent.setVisible(false); - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - int width = getColumnModel().getColumn(1).getWidth(); - if (getCursor().getType() == Cursor.MOVE_CURSOR){ - draging = true; - //下面这句话太重要了,拖拽过程中选中的不变 - getInstance().setRowSelectionInterval(selectedRow,selectedRow); - moveComponent.setText(getValueAt(getSelectedRow(), getSelectedColumn()).toString()); - moveComponent.setLocation(getColumnModel().getColumn(0).getWidth(), e.getY() - GAP); - moveComponent.setPreferredSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT)); - moveComponent.setSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT)); - moveComponent.setVisible(true); - moveComponent.setForeground(Color.lightGray); - moveComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray)); - } - } - @Override - public void mouseReleased(MouseEvent e) { - if(!draging){ - return; - } - draging = false; - moveComponent.setVisible(false); - int toIndex = e.getY() < GAP ? 0 : (int)Math.rint((e.getY() - GAP)/WIDGET_TABLE_ROW_HEIGHT) + 1; - ((WParameterLayout) designer.getParaComponent().toData()).adjustOrder(getSelectedRow(), toIndex); - getInstance().setRowSelectionInterval(0,getRowCount() - 1); - refresh(); - getInstance().repaint(); - designer.fireTargetModified(); - } - }; - - public MobileWidgetTable getInstance(){ - return this; - } - - public FormDesigner getEditingDesigner(){ - return designer; - } - - /** - * 刷新 - */ - public void refresh(){ - XCreator creator = designer.getSelectionModel().getSelection().getSelectedCreator(); - cellData = getData(); - if(creator != null){ - String widgetName =creator.toData().getWidgetName(); - int row = -1; - int column = -1; - for (int i =0; i < cellData.length;i++){ - if(ComparatorUtils.equals(widgetName, cellData[i][0])){ - row = i; - column = 0; - break; - } - if(ComparatorUtils.equals(widgetName, cellData[i][1])){ - row = i; - column = 1; - break; - } - } - selectedRow = row; - changeSelection(row,column,false,false); - if(row == -1){ - this.clearSelection(); - } - } - } - - private String[][] getData(){ - XLayoutContainer paraContainer = designer.getParaComponent(); - if(paraContainer == null || !paraContainer.acceptType(XWParameterLayout.class)){ - return new String[0][0]; - } - - WParameterLayout para = (WParameterLayout) (paraContainer.toData()); - return para.getWidgetNameTag(); - } - - private class MobileWidgetTableCellRenderer extends DefaultTableCellRenderer{ - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, - boolean hasFocus, int row, int column) { - if (getCursor().getType() == Cursor.MOVE_CURSOR){ - if(selectedRow > -1 && selectedRow < getRowCount()){ - //拖拽过程中选中的不变 - getInstance().setRowSelectionInterval(selectedRow,selectedRow); - } - } - super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - if (column == 0){ - UITextField uiTableTextField; - if (getSelectedColumn() == column && getSelectedRow() == row){ - uiTableTextField = new UITableTextField(value.toString()); - } else { - uiTableTextField = new UITextField(value.toString()); - } - return uiTableTextField; - } - return this; - } - - } - private class MobileCellEditor extends AbstractCellEditor implements TableCellEditor { - UITableTextField uiTableTextField; - MobileCellEditor(){ - uiTableTextField = new UITableTextField(); - uiTableTextField.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent evt) { - stopCellEditing(); - designer.fireTargetModified(); - } - }); - uiTableTextField.getDocument().addDocumentListener(new DocumentListener() { - @Override - public void insertUpdate(DocumentEvent e) { - firePropertyChange(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - firePropertyChange(); - } - - @Override - public void changedUpdate(DocumentEvent e) { - firePropertyChange(); - } - }); - } - - /** - * cell改变,相应的nametag改变 - */ - public void firePropertyChange(){ - ((WParameterLayout) designer.getParaComponent().toData()).add2NameTagMap(uiTableTextField.getText(), - cellData[getSelectedRow()][1]); - } - - public Object getCellEditorValue(){ - return uiTableTextField.getText(); - } - - /* - * 双击以编辑 - */ - public boolean isCellEditable(EventObject anEvent) { - if (anEvent instanceof MouseEvent) { - return ((MouseEvent)anEvent).getClickCount() >= 2; - } - return true; - } - - public Component getTableCellEditorComponent( JTable table,Object value, - boolean isSelected,int row,int column){ - uiTableTextField.setText(value.toString()); - return uiTableTextField; - } - } - - public class BeanTableModel extends DefaultTableModel { - public BeanTableModel() { - super(cellData,headers); - } - - @Override - public int getRowCount() { - return cellData.length; - } - - @Override - public int getColumnCount() { - return 2; - } - - - @Override - public Object getValueAt(int row, int column) { - if (row >= getRowCount() || column >= getColumnCount()) { - return null; - } - Object[] rowValue = cellData[row]; - if (column > -1 && column < rowValue.length) { - return cellData[row][column]; - } - return null; - } - - @Override - public String getColumnName(int column) { - if (column == 0) { - return headers[0]; - } else { - return headers[1]; - } - } - - - @Override - public void setValueAt(Object aValue, int row, int column) { - if (row >= getRowCount() || column >= getColumnCount()) { - return; - } - if (aValue == null) { - cellData[row][column] = null; - return; - } - cellData[row][column] = aValue.toString(); - } - - /** - * 是否可编辑 - * @param row 行号 - * @param column 列号 - * @return 是否可编辑 - */ - public boolean isCellEditable(int row, int column) { - if(column ==1){ - return false; - } - return true; - } - - } - - private class UITableTextField extends UITextField { - public UITableTextField(){ - super(); - } - - public UITableTextField(String string){ - super(string); - } - - protected void paintBorder(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - if (this.isFocusOwner()) { - g2d.setStroke(new BasicStroke(1.5f)); - } else { - g2d.setStroke(new BasicStroke(1f)); - } - RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, this.getWidth() - 2, this.getHeight() - 2, 4, 4); - g2d.setColor(Color.orange); - g2d.draw(rect); - } - - } +package com.fr.design.mainframe; + +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.table.*; + +import com.fr.design.designer.creator.XCreator; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itable.GroupRenderer; +import com.fr.form.ui.Widget; +import com.fr.form.ui.container.*; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.stable.StringUtils; + +/** + * MobileWidgetTable类主要显示各种容器的控件列表(body,tab,绝对布局快,不包括参数面板) + * Created with IntelliJ IDEA. + * User: zx + * Date: 14-9-15 + * Time: 下午4:52 + * Modified by fanglei at 2017/01/23 + */ +public class MobileWidgetTable extends JTable { + + private FormDesigner designer; + private String[][] cellData; + private String[] headers = {Inter.getLocText("Form-Widget_Name")}; + private static final int WIDGET_TABLE_ROW_HEIGHT = 22; + private UILabel moveComponent = new UILabel(); // 作为拖动时候随鼠标移动的那个半透明控件 + private int selectedRow = -1; + private static final int GAP = 11; + private boolean draging = false; + private boolean collapsed = false; // 控件列表是否折叠 + + @Override + public TableCellRenderer getCellRenderer(int row, int column) { + //第一行渲染成为标题的样子 + if (row == 0) { + return new GroupRenderer(); + } + return super.getCellRenderer(row, column); + } + + + public MobileWidgetTable(FormDesigner designer) { + this.designer = designer; + cellData = getData(); + this.setTableProperties(); + TableModel defaultModel = new BeanTableModel(); + this.setModel(defaultModel); + this.repaint(); + this.setDefaultRenderer(Object.class, new DefaultTableCellRenderer()); + refreshData(); + this.addMouseListener(mouseAdapter); + this.addMouseMotionListener(mouseAdapter); + add(moveComponent); + } + + private void setTableProperties() { + JTableHeader header = getTableHeader(); + header.setReorderingAllowed(false); + header.setPreferredSize(new Dimension(0, 0)); // 隐藏表头 + GroupRenderer headerRenderer = new GroupRenderer(); + headerRenderer.setPreferredSize(new Dimension(0, 0)); //这行代码隐藏表头。因为要实现折叠效果,表头不好监听事件 + headerRenderer.setHorizontalAlignment(JLabel.LEFT); + header.setDefaultRenderer(headerRenderer); + + this.setRowHeight(WIDGET_TABLE_ROW_HEIGHT); + this.setGridColor(new Color(212, 208, 200)); + this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + this.setColumnSelectionAllowed(false); + this.setRowSelectionAllowed(false); + this.setFillsViewportHeight(false); + this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); + } + + private MouseAdapter mouseAdapter = new MouseAdapter() { + /** + * 鼠标按下时处理的事件(设置当前选中的行列) + * @param e + */ + @Override + public void mousePressed(MouseEvent e) { + getInstance().setCellSelected(); + if (selectedRow == 0 && !e.isPopupTrigger() && e.getClickCount() == 1 && e.getX() < WIDGET_TABLE_ROW_HEIGHT / 2) { // 如果是点击在第一行 + toggleCollapse(); + } + } + + /** + * 鼠标放开时处理的事件(如果是正在拖动则执行换位操作,重新绘制属性表,如果不是则什么也不做) + * 所谓的换行就是简单的重新拿到一次表格数据然后重新绘制表格 + * @param e + */ + @Override + public void mouseReleased(MouseEvent e) { + if (!draging) { + return; + } + draging = false; + moveComponent.setVisible(false); + int toIndex = e.getY() < GAP ? 0 : (int) Math.rint((e.getY() - GAP) / WIDGET_TABLE_ROW_HEIGHT) + 1; + //当鼠标放开时,将选中的容器调整至新的顺序 + ((WSortLayout) designer.getSelectionModel().getSelection().getSelectedCreator().toData()).adjustOrder(selectedRow - 1, toIndex - 1); + //拿取排序后表格数据,然后重绘表格 + getInstance().refreshData(); + getInstance().repaint(); + designer.fireTargetModified(); + getInstance().setCellSelected(); + } + + /** + * 设置鼠标在属性表区域移动时候的事件 + * @param e + */ + @Override + public void mouseMoved(MouseEvent e) { + int overRow = 0; + for (int i = 0; i < getRowCount(); i++) { + if (e.getY() > i * WIDGET_TABLE_ROW_HEIGHT && e.getY() <= (i + 1) * WIDGET_TABLE_ROW_HEIGHT) { + overRow = i; //判断鼠标在哪一行 + } + } + //如果鼠标移动到当前选中的行上面的时候 + if (overRow == selectedRow && selectedRow > 0) { + //把当前选中的那一行的光标改成(除了第一列)移动样式MOVE_CURSOR + setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + } else { + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + } + + /** + * 鼠标拖动事件(如果鼠标当前是MOVE_CURSOR状态则执行开始拖动的代码, + * 绘制一个moveComponent来跟随鼠标移动) + * @param e + */ + @Override + public void mouseDragged(MouseEvent e) { + int width = getColumnModel().getColumn(0).getWidth(); + //如果当前选中的行的范围是合理的话,就可以拖动 + if (selectedRow < getRowCount() && selectedRow > 0) { + setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + draging = true; + moveComponent.setText(getValueAt(selectedRow, 0).toString()); + moveComponent.setLocation(0, e.getY() - GAP); + moveComponent.setSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT)); + moveComponent.setVisible(true); + moveComponent.setForeground(Color.lightGray); + moveComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray)); + } + } + + /** + * 设置鼠标单击时处理的事件(单击控件列表进入控件属性表) + * @param e + */ + @Override + public void mouseClicked(MouseEvent e) { + if (selectedRow > 0) { + //当前点击的控件的名字 + String widgetName = cellData[selectedRow][0]; + if (StringUtils.isNotEmpty(widgetName)) { + //当前选择的容器 + XCreator selectedContainer = designer.getSelectionModel().getSelection().getSelectedCreator(); + WLayout selectedWidget = (WLayout) selectedContainer.toData(); + //当前选择的容器中的控件数量 + int count = selectedWidget.getWidgetCount(); + for (int i = 0; i < count; i++) { + XCreator xCreator = (XCreator) selectedContainer.getComponent(i); + Widget widget = xCreator.toData(); + if (ComparatorUtils.equals(widgetName, widget.getWidgetName())) { + getEditingDesigner().getSelectionModel().setSelectedCreator(xCreator); + } + } + } + } else if (selectedRow == 0) { // 如果是点击在第一行 + if (!e.isPopupTrigger() && e.getClickCount() > 1) { + toggleCollapse(); + } + } + } + + /** + * 鼠标离开属性表区域事件 + * @param e + */ + public void mouseExited(MouseEvent e) { + draging = false; + moveComponent.setVisible(false); + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + }; + + public MobileWidgetTable getInstance() { + return this; + } + + public FormDesigner getEditingDesigner() { + return designer; + } + + /** + * 设置当前get到的行列的单元格为选中状态 + */ + private void setCellSelected() { + selectedRow = getSelectedRow(); + if (selectedRow != -1) { + this.setRowSelectionInterval(selectedRow, selectedRow); + this.setColumnSelectionInterval(0, 0); + } + } + + /** + * 切换属性组折叠属性true/false + */ + private void toggleCollapse() { + this.setCollapsed(!this.isCollapsed()); + //这里获取表格的父控件是为了当表格被折叠了后,装表格的父控件也要相应的重新布局一下 + //比如折叠之后表格行数应该比原来的少,占用父容器空间应该小点,不重新布局父容器,表格大小不会改变 + Container parent = MobileWidgetTable.this.getParent(); + if (parent != null) { + parent.revalidate(); + } + repaint(); + } + + /** + * 重新get排序后的数据 + */ + public void refreshData() { + cellData = getData(); + } + + /** + * 获取选中控件的控件列表 + * + * @return String[][] 二维数组,[0][0]widgetName + */ + private String[][] getData() { + if (designer.isFormParaDesigner()) { + return new String[0][0]; + } + + //选择的控件 + XCreator selectedCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); + Widget selectedModel = selectedCreator != null ? selectedCreator.toData() : null; + + if (selectedModel == null) { + return new String[0][0]; + } + + // 选择的控件有两种类型,一种是WLayout,代表容器,一种是Widget,代表控件 + if (selectedModel.acceptType(WSortLayout.class)) { + List mobileWidgetList = ((WSortLayout) selectedModel).getOrderedMobileWidgetList(); + String[][] widgetName = new String[mobileWidgetList.size() + 1][1]; + widgetName[0][0] = Inter.getLocText("FR-Designer_WidgetOrder"); + for (int i = 0; i < mobileWidgetList.size(); i++) { + widgetName[i + 1][0] = mobileWidgetList.get(i); + } + return widgetName; + } else { + return new String[0][0]; + } + } + + public boolean isCollapsed() { + return collapsed; + } + + public void setCollapsed(boolean collapsed) { + this.collapsed = collapsed; + } + + /** + * 自定义的tableEditor类 + */ + public class BeanTableModel extends DefaultTableModel { + public BeanTableModel() { + super(cellData, headers); + } + + @Override + public int getRowCount() { + if (isCollapsed()) { + return 1; + } + return cellData.length; + } + + @Override + public int getColumnCount() { + return 1; + } + + + @Override + public Object getValueAt(int row, int column) { + if (row >= getRowCount() || column >= getColumnCount()) { + return null; + } + if (row == 0) { + return (isCollapsed() ? "+" : "-") + cellData[row][0]; + } + + return cellData[row][0]; + } + + @Override + public String getColumnName(int column) { + return headers[0]; + } + + + @Override + public void setValueAt(Object aValue, int row, int column) { + if (row >= getRowCount() || column >= getColumnCount()) { + return; + } + if (aValue == null) { + cellData[row] = null; + return; + } + cellData[row][0] = aValue.toString(); + } + + /** + * 是否可编辑 + * + * @param row 行号 + * @param column 列号 + * @return 是否可编辑 + */ + public boolean isCellEditable(int row, int column) { + return false; + } + + } + } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java b/designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java index a5ec30471..201ab203e 100644 --- a/designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java +++ b/designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java @@ -1,289 +1,375 @@ -package com.fr.design.mainframe; - -import com.fr.base.BaseUtils; -import com.fr.design.ExtraDesignClassManager; -import com.fr.design.designer.beans.events.DesignerEditListener; -import com.fr.design.designer.beans.events.DesignerEvent; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XCreatorUtils; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWParameterLayout; -import com.fr.design.designer.properties.EventPropertyTable; -import com.fr.design.designer.properties.WidgetPropertyTable; -import com.fr.design.fun.WidgetPropertyUIProvider; -import com.fr.design.gui.frpane.UITabbedPane; -import com.fr.design.gui.icontainer.UIScrollPane; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itable.AbstractPropertyTable; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.general.Inter; -import com.fr.stable.ArrayUtils; - -import javax.swing.*; -import javax.swing.border.LineBorder; -import java.awt.*; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -/** - * 控件属性表Docking - */ -public class WidgetPropertyPane extends FormDockView implements BaseWidgetPropertyPane { - - private WidgetPropertyTable propertyTable; - private EventPropertyTable eventTable; - private List widgetPropertyTables; - private FormDesigner designer; - private JPanel wsp; - private MobileWidgetTable mobileWidgetTable; - private MobileBodyWidgetTable mobileBodyWidgetTable; - private UIScrollPane downPanel; - private JPanel centerPane; - private CardLayout cardLayout; - public static final String PARA = "para"; - public static final String BODY = "body"; - public static final int NODE_LENGTH = 2; - public boolean isrefresh = true; - - - public static WidgetPropertyPane getInstance() { - if (HOLDER.singleton == null) { - HOLDER.singleton = new WidgetPropertyPane(); - } - return HOLDER.singleton; - } - - public static WidgetPropertyPane getInstance(FormDesigner formEditor) { - HOLDER.singleton.setEditingFormDesigner(formEditor); - HOLDER.singleton.refreshDockingView(); - return HOLDER.singleton; - } - - private static class HOLDER { - private static WidgetPropertyPane singleton = new WidgetPropertyPane(); - } - - private WidgetPropertyPane() { - setLayout(FRGUIPaneFactory.createBorderLayout()); - } - - public class mobileWidgetDesignerAdapter implements DesignerEditListener { - - public mobileWidgetDesignerAdapter() { - } - - /** - * 响应界面改变事件 - * @param evt 事件 - */ - public void fireCreatorModified(DesignerEvent evt) { - if (evt.getCreatorEventID() == DesignerEvent.CREATOR_RESIZED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_ADDED) { - int value = downPanel.getVerticalScrollBar().getValue(); - if(hasSelectParaPane(getEditingFormDesigner())){ - cardLayout.show(centerPane,PARA); - mobileWidgetTable.refresh(); - } else { - cardLayout.show(centerPane,BODY); - mobileBodyWidgetTable.refresh(); - } - //出现滚动条 - downPanel.doLayout(); - //控件列表选中某组件,触发表单中选中控件,选中事件又触发列表刷新,滚动条回到0 - //此处设置滚动条值为刷新前 - downPanel.getVerticalScrollBar().setValue(value); - } - } - } - - @Override - public String getViewTitle() { - return Inter.getLocText("Form-Widget_Property_Table"); - } - - @Override - public Icon getViewIcon() { - return BaseUtils.readIcon("/com/fr/design/images/m_report/attributes.png"); - } - - @Override - public void refreshDockingView() { - designer = this.getEditingFormDesigner(); - removeAll(); - if (designer == null) { - clearDockingView(); - return; - } - widgetPropertyTables = new ArrayList(); - propertyTable = new WidgetPropertyTable(designer); - designer.addDesignerEditListener(new WidgetPropertyDesignerAdapter(propertyTable)); - propertyTable.setBorder(null); - UIScrollPane psp = new UIScrollPane(propertyTable); - psp.setBorder(null); - eventTable = new EventPropertyTable(designer); - designer.addDesignerEditListener(new EventPropertyDesignerAdapter(eventTable)); - eventTable.setBorder(null); - UIScrollPane esp = new UIScrollPane(eventTable); - esp.setBorder(null); - wsp = FRGUIPaneFactory.createBorderLayout_S_Pane(); - wsp.setBorder(null); - mobileWidgetTable = new MobileWidgetTable(designer); - mobileBodyWidgetTable = new MobileBodyWidgetTable(designer); - designer.addDesignerEditListener(new mobileWidgetDesignerAdapter()); - centerPane = FRGUIPaneFactory.createCardLayout_S_Pane(); - cardLayout = (CardLayout) centerPane.getLayout(); - centerPane.add(mobileWidgetTable,PARA); - centerPane.add(mobileBodyWidgetTable,BODY); - if(hasSelectParaPane(designer)){ - cardLayout.show(centerPane,PARA); - } else { - cardLayout.show(centerPane,BODY); - } - downPanel = new UIScrollPane(centerPane); - downPanel.setBorder(new LineBorder(Color.gray)); - wsp.add(downPanel,BorderLayout.CENTER); - - UITabbedPane tabbedPane = new UITabbedPane(); - initTabPane(psp, esp, tabbedPane); - WidgetPropertyUIProvider[] widgetAttrProviders = getExtraPropertyUIProviders(); - addWidgetAttr(widgetAttrProviders); - add(tabbedPane, BorderLayout.CENTER); - propertyTable.initPropertyGroups(null); - eventTable.refresh(); - for (AbstractPropertyTable propertyTable : widgetPropertyTables) { - propertyTable.initPropertyGroups(designer); - } - isrefresh = false; - } - - private void addWidgetAttr(WidgetPropertyUIProvider[] widgetAttrProviders) { - if (widgetAttrProviders.length == 0) { - UILabel upLabel = new UILabel(Inter.getLocText("FR-Widget_Mobile_Table"), SwingConstants.CENTER); - upLabel.setBorder(BorderFactory.createEmptyBorder(6,0,6,0)); - wsp.add(upLabel, BorderLayout.NORTH); - } else { - for (WidgetPropertyUIProvider widgetAttrProvider : widgetAttrProviders) { - AbstractPropertyTable propertyTable = widgetAttrProvider.createWidgetAttrTable(); - widgetPropertyTables.add(propertyTable); - designer.addDesignerEditListener(new WidgetPropertyDesignerAdapter(propertyTable)); - UIScrollPane uiScrollPane = new UIScrollPane(propertyTable); - uiScrollPane.setBorder(null); - wsp.add(uiScrollPane); - - } - } - } - - private void initTabPane(UIScrollPane psp, UIScrollPane esp, UITabbedPane tabbedPane) { - tabbedPane.setOpaque(true); - tabbedPane.setBorder(null); - tabbedPane.setTabPlacement(SwingConstants.BOTTOM); - tabbedPane.addTab(Inter.getLocText("FR-Designer_Properties"), psp); - tabbedPane.addTab(Inter.getLocText("FR-Designer_Event"), esp); - tabbedPane.addTab(Inter.getLocText("FR-Widget_Mobile_Terminal"), wsp); - } - - // - /** - * 选中的组件是否在参数面板里 - * @param designer 设计器 - * @return 是则返回true - */ - public boolean hasSelectParaPane(FormDesigner designer){ - XCreator xCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); - if(xCreator == null){ - xCreator = designer.getRootComponent(); - } - XLayoutContainer container = XCreatorUtils.getHotspotContainer(xCreator); - return xCreator.acceptType(XWParameterLayout.class) || container.acceptType(XWParameterLayout.class); - } - - /** - * 获取当前控件扩展的属性tab - * 来源有两个: - * 1, 各个控件从各自的Xcreator里扩展; - * 2, 所有的控件从插件里扩展. - * - * @return 扩展的tab - */ - private WidgetPropertyUIProvider[] getExtraPropertyUIProviders() { - FormSelection selection = designer.getSelectionModel().getSelection(); - WidgetPropertyUIProvider[] embeddedPropertyUIProviders = null; - if (selection != null && selection.getSelectedCreator() != null) { - embeddedPropertyUIProviders = selection.getSelectedCreator().getWidgetPropertyUIProviders(); - } - Set set = ExtraDesignClassManager.getInstance().getArray(WidgetPropertyUIProvider.XML_TAG); - WidgetPropertyUIProvider[] widgetAttrProviders = ArrayUtils.addAll(embeddedPropertyUIProviders, set.toArray(new WidgetPropertyUIProvider[set.size()])); - return widgetAttrProviders; - } - - public void setEditingFormDesigner(BaseFormDesigner editor) { - FormDesigner fd = (FormDesigner) editor; - super.setEditingFormDesigner(fd); - } - - public void clearDockingView() { - propertyTable = null; - eventTable = null; - if (widgetPropertyTables != null) { - widgetPropertyTables.clear(); - } - JScrollPane psp = new JScrollPane(); - psp.setBorder(null); - this.add(psp, BorderLayout.CENTER); - } - - public class WidgetPropertyDesignerAdapter implements DesignerEditListener { - AbstractPropertyTable propertyTable; - - public WidgetPropertyDesignerAdapter(AbstractPropertyTable propertyTable) { - this.propertyTable = propertyTable; - } - - @Override - public void fireCreatorModified(DesignerEvent evt) { - if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { - propertyTable.initPropertyGroups(designer); - } else if (evt.getCreatorEventID() == DesignerEvent.CREATOR_RESIZED) { - repaint(); - } - } - - @Override - public boolean equals(Object o) { - return o instanceof WidgetPropertyDesignerAdapter && ((WidgetPropertyDesignerAdapter) o).propertyTable == this.propertyTable; - } - } - - public class EventPropertyDesignerAdapter implements DesignerEditListener { - EventPropertyTable propertyTable; - - public EventPropertyDesignerAdapter(EventPropertyTable eventTable) { - this.propertyTable = eventTable; - } - - @Override - public void fireCreatorModified(DesignerEvent evt) { - if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { - propertyTable.refresh(); - } - } - - @Override - public boolean equals(Object o) { - return o instanceof EventPropertyDesignerAdapter; - } - } - - @Override - public Location preferredLocation() { - return Location.WEST_BELOW; - } +package com.fr.design.mainframe; + +import com.fr.base.BaseUtils; +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.designer.beans.events.DesignerEditListener; +import com.fr.design.designer.beans.events.DesignerEvent; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XCreatorUtils; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWParameterLayout; +import com.fr.design.designer.properties.EventPropertyTable; +import com.fr.design.designer.properties.WidgetPropertyTable; +import com.fr.design.fun.WidgetPropertyUIProvider; +import com.fr.design.gui.frpane.UITabbedPane; +import com.fr.design.gui.icontainer.UIScrollPane; +import com.fr.design.gui.itable.AbstractPropertyTable; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.form.ui.Widget; +import com.fr.general.Inter; +import com.fr.stable.ArrayUtils; + +import javax.swing.*; +import javax.swing.border.LineBorder; +import javax.swing.table.JTableHeader; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * 控件属性表绘制 + * Modified by fanglei + */ +public class WidgetPropertyPane extends FormDockView implements BaseWidgetPropertyPane { + + private static final String PARA = "para"; + private static final String BODY = "body"; + private WidgetPropertyTable propertyTable; // 控件的属性表 + private EventPropertyTable eventTable; // 控件的事件表 + private List widgetPropertyTables; // 这个变量应该是保存控件拓展的属性tab + private FormDesigner designer; // 当前designer + private UIScrollPane psp; // 用来装载属性表table的容器 + private UIScrollPane esp; //用来装载事件table的容器 + private JPanel wsp; // 装载移动端tab的容器,包括移动端属性表和控件拓展的移动端属性表 + private MobileParaWidgetTable mobileParaWidgetTable; // 参数面板的移动端属性tab(和body的移动端属性tab区别是没有标签名column) + private MobileWidgetTable mobileWidgetTable; // body的移动端属性tab + private UIScrollPane downPanel; // 这个滚动容器是用于装载centerPane的 + private JPanel centerPane; // 此centerPane采用的是cardLayout布局,装载着mobileWidgetTable和mobileBodyWidgetTable + private CardLayout cardLayout; // 卡片布局,选中参数面板时显示mobileWidgetTable,选中body时显示mobileBodyWidgetTable + private JTableHeader header;//把表头单独get出来作为一个组件 + + public static WidgetPropertyPane getInstance() { + if (HOLDER.singleton == null) { + HOLDER.singleton = new WidgetPropertyPane(); + } + return HOLDER.singleton; + } + + public static WidgetPropertyPane getInstance(FormDesigner formEditor) { + HOLDER.singleton.setEditingFormDesigner(formEditor); + HOLDER.singleton.refreshDockingView(); + return HOLDER.singleton; + } + + private static class HOLDER { + private static WidgetPropertyPane singleton = new WidgetPropertyPane(); + } + + private WidgetPropertyPane() { + setLayout(FRGUIPaneFactory.createBorderLayout()); + } + + @Override + public String getViewTitle() { + return Inter.getLocText("Form-Widget_Property_Table"); + } + + @Override + public Icon getViewIcon() { + return BaseUtils.readIcon("/com/fr/design/images/m_report/attributes.png"); + } + + @Override + /** + * 绘制属性表tab + */ + public void refreshDockingView() { + designer = this.getEditingFormDesigner(); + removeAll(); + if (designer == null) { + clearDockingView(); + return; + } + widgetPropertyTables = new ArrayList(); + + //依次创建属性表、事件表、移动端表,再将它们整合到TabPane中去 + this.createPropertyTable(); + this.createEventTable(); + this.createMobileWidgetTable(); + this.createTabPane(); + + this.initTables(); + } + + /** + * 初始化属性表,事件表,移动端拓展的属性表 + */ + private void initTables() { + propertyTable.initPropertyGroups(null); + eventTable.refresh(); + for (AbstractPropertyTable propertyTable : widgetPropertyTables) { + propertyTable.initPropertyGroups(designer); + } + } + + /** + * 创建属性表table + */ + private void createPropertyTable() { + propertyTable = new WidgetPropertyTable(designer); + designer.addDesignerEditListener(new WidgetPropertyDesignerAdapter(propertyTable)); + propertyTable.setBorder(null); + psp = new UIScrollPane(propertyTable); // 用来装载属性表table + psp.setBorder(null); + } + + /** + * 创建事件表(事件选项卡不是JTable) + */ + private void createEventTable() { + eventTable = new EventPropertyTable(designer); + designer.addDesignerEditListener(new EventPropertyDesignerAdapter(eventTable)); + eventTable.setBorder(null); + esp = new UIScrollPane(eventTable); //用来装载事件table + esp.setBorder(null); + } + + /** + * 创建移动端控件列表 + */ + private void createMobileWidgetTable() { + //加上表头后,这里不再使用borderLayout布局,而采用BoxLayout布局 + wsp = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); + wsp.setBorder(null); + mobileParaWidgetTable = new MobileParaWidgetTable(designer); + mobileWidgetTable = new MobileWidgetTable(designer); + designer.addDesignerEditListener(new mobileWidgetDesignerAdapter()); + centerPane = FRGUIPaneFactory.createCardLayout_S_Pane(); + cardLayout = (CardLayout) centerPane.getLayout(); + centerPane.add(mobileParaWidgetTable, PARA); + // 采用卡片布局的容器必须指定卡片名字,如果没有卡片名字 + // 就会出现:Exception in thread "main" java.lang.IllegalArgumentException: + // cannot add to layout: constraint must be a string + // 第二个参数代表卡片的名字。后来show方法调用时通过名字找到要显示的卡片 + centerPane.add(mobileWidgetTable, BODY); //这两句代码,是把JTable放到一个JPanel中去了,表头不会显示, + //只有放到JScrollPanel中去表头才能正常显示,这就是MobileWidgetTable中定义了表头却没有显示的原因! + //解决方案:MobileWidgetTable实在无法直接放到JScrollPanel中去的时候,应该把表头get出来单独作为一个组件显示 + + if (hasSelectParaPane(designer)) { + cardLayout.show(centerPane, PARA); + header = mobileParaWidgetTable.getTableHeader(); + } else { + cardLayout.show(centerPane, BODY); + header = mobileWidgetTable.getTableHeader(); + } + downPanel = new UIScrollPane(centerPane); + downPanel.setBorder(new LineBorder(Color.GRAY)); + + //获取拓展移动端属性tab + WidgetPropertyUIProvider[] widgetAttrProviders = getExtraPropertyUIProviders(); + + addWidgetAttr(widgetAttrProviders); + } + + /** + * 将属性表,事件表,移动端控件列表整合到TabPane里面去 + */ + private void createTabPane() { + UITabbedPane tabbedPane = new UITabbedPane(); // tab选项卡容器 + initTabPane(tabbedPane); + add(tabbedPane, BorderLayout.CENTER); + } + + /** + * 获取当前控件扩展的属性tab + * 来源有两个: + * 1, 各个控件从各自的Xcreator里扩展(例如手机重布局的tab就是从Xcreator中扩展的); + * 2, 所有的控件从插件里扩展. + * + * @return 扩展的tab + */ + private WidgetPropertyUIProvider[] getExtraPropertyUIProviders() { + FormSelection selection = designer.getSelectionModel().getSelection(); + WidgetPropertyUIProvider[] embeddedPropertyUIProviders = null; + if (selection != null && selection.getSelectedCreator() != null) { + embeddedPropertyUIProviders = selection.getSelectedCreator().getWidgetPropertyUIProviders(); + } + Set set = ExtraDesignClassManager.getInstance().getArray(WidgetPropertyUIProvider.XML_TAG); + return ArrayUtils.addAll(embeddedPropertyUIProviders, set.toArray(new WidgetPropertyUIProvider[set.size()])); + } + + /** + * 判断是将拓展的tab放入属性表还是将原来的tab放入属性表 + * + * @param widgetAttrProviders 拓展的tab + */ + private void addWidgetAttr(WidgetPropertyUIProvider[] widgetAttrProviders) { + if (widgetAttrProviders.length == 0) { // 判断有没有拓展的tab,没有就使用原来的 + wsp.add(header); + wsp.add(downPanel); + } else { + for (WidgetPropertyUIProvider widgetAttrProvider : widgetAttrProviders) { + AbstractPropertyTable propertyTable = widgetAttrProvider.createWidgetAttrTable(); + widgetPropertyTables.add(propertyTable); + designer.addDesignerEditListener(new WidgetPropertyDesignerAdapter(propertyTable)); + UIScrollPane uiScrollPane = new UIScrollPane(getExtraBodyTable(propertyTable)); + wsp.add(uiScrollPane); + } + } + } + + /** + * 如果是body的拓展属性表,那么要额外加上一张控件顺序表 + * + * @return + */ + private Component getExtraBodyTable(AbstractPropertyTable abstractPropertyTable) { + Widget selection = designer.getSelectionModel().getSelection().getSelectedCreator().toData(); + if (selection.getWidgetName().equals("body")) { + JPanel jPanel = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); + jPanel.add(abstractPropertyTable); + MobileWidgetTable mobileWidgetTable = new MobileWidgetTable(designer); + jPanel.add(mobileWidgetTable.getTableHeader()); + jPanel.add(mobileWidgetTable); + return jPanel; + } + return abstractPropertyTable; + } + + private void initTabPane(UITabbedPane tabbedPane) { + tabbedPane.setOpaque(true); + tabbedPane.setBorder(null); + tabbedPane.setTabPlacement(SwingConstants.BOTTOM); + tabbedPane.addTab(Inter.getLocText("FR-Designer_Properties"), psp); + tabbedPane.addTab(Inter.getLocText("FR-Designer_Event"), esp); + tabbedPane.addTab(Inter.getLocText("FR-Widget_Mobile_Terminal"), wsp); + } + + + /** + * 选中的组件是否在参数面板里 + * + * @param designer 设计器 + * @return 是则返回true + */ + public boolean hasSelectParaPane(FormDesigner designer) { + XCreator xCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); + if (xCreator == null) { + xCreator = designer.getRootComponent(); + } + XLayoutContainer container = XCreatorUtils.getHotspotContainer(xCreator); + + boolean xCreatorAccept = xCreator.acceptType(XWParameterLayout.class); + boolean containerAccept = container!=null && container.acceptType(XWParameterLayout.class); + + return xCreatorAccept || containerAccept; + } + + public void setEditingFormDesigner(BaseFormDesigner editor) { + FormDesigner fd = (FormDesigner) editor; + super.setEditingFormDesigner(fd); + } + + private void clearDockingView() { + propertyTable = null; + eventTable = null; + if (widgetPropertyTables != null) { + widgetPropertyTables.clear(); + } + JScrollPane psp = new JScrollPane(); + psp.setBorder(null); + this.add(psp, BorderLayout.CENTER); + } + + /** + * 属性表监听界面事件(编辑,删除,选中,改变大小) + */ + private class WidgetPropertyDesignerAdapter implements DesignerEditListener { + AbstractPropertyTable propertyTable; + + WidgetPropertyDesignerAdapter(AbstractPropertyTable propertyTable) { + this.propertyTable = propertyTable; + } + + @Override + public void fireCreatorModified(DesignerEvent evt) { + if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { + propertyTable.initPropertyGroups(designer); + } else if (evt.getCreatorEventID() == DesignerEvent.CREATOR_RESIZED) { + repaint(); + } + } + + @Override + public boolean equals(Object o) { + return o instanceof WidgetPropertyDesignerAdapter && ((WidgetPropertyDesignerAdapter) o).propertyTable == this.propertyTable; + } + } + + /** + * 事件表监听界面事件(编辑,选中) + */ + private class EventPropertyDesignerAdapter implements DesignerEditListener { + EventPropertyTable propertyTable; + + EventPropertyDesignerAdapter(EventPropertyTable eventTable) { + this.propertyTable = eventTable; + } + + @Override + public void fireCreatorModified(DesignerEvent evt) { + if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { + propertyTable.refresh(); + } + } + + @Override + public boolean equals(Object o) { + return o instanceof EventPropertyDesignerAdapter; + } + } + + /** + * 移动端属性表监听界面事件(改变大小,编辑,选中,增加控件) + */ + private class mobileWidgetDesignerAdapter implements DesignerEditListener { + + mobileWidgetDesignerAdapter() { + } + + /** + * 响应界面改变事件 + * + * @param evt 事件 + */ + public void fireCreatorModified(DesignerEvent evt) { + if (evt.getCreatorEventID() == DesignerEvent.CREATOR_RESIZED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_ADDED) { + int value = downPanel.getVerticalScrollBar().getValue(); + if (hasSelectParaPane(getEditingFormDesigner())) { + cardLayout.show(centerPane, PARA); + mobileParaWidgetTable.refreshData(); + } else { + cardLayout.show(centerPane, BODY); + mobileWidgetTable.refreshData(); + } + //出现滚动条 + downPanel.doLayout(); + //控件列表选中某组件,触发表单中选中控件,选中事件又触发列表刷新,滚动条回到0 + //此处设置滚动条值为刷新前 + downPanel.getVerticalScrollBar().setValue(value); + } + } + } + + @Override + public Location preferredLocation() { + return Location.WEST_BELOW; + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/templateinfo/JFormProcessInfo.java b/designer_form/src/com/fr/design/mainframe/templateinfo/JFormProcessInfo.java new file mode 100644 index 000000000..15f501b13 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/templateinfo/JFormProcessInfo.java @@ -0,0 +1,40 @@ +package com.fr.design.mainframe.templateinfo; + +import com.fr.form.main.Form; +import com.fr.form.ui.container.WLayout; + +/** + * Created by plough on 2017/3/17. + */ +public class JFormProcessInfo extends TemplateProcessInfo { + public JFormProcessInfo(Form form) { + super(form); + } + + // 获取模板类型 + public int getReportType() { + return 2; + } + + // 获取模板格子数 + public int getCellCount() { + return 0; + } + // 获取模板悬浮元素个数 + public int getFloatCount() { + return 0; + } + // 获取模板聚合块个数 + public int getBlockCount() { + return 0; + } + // 获取模板控件数 + public int getWidgetCount() { + int widgetCount = 0; + for (int i = 0; i < template.getContainer().getWidgetCount(); i++) { + WLayout wl = (WLayout) template.getContainer().getWidget(i); + widgetCount += wl.getWidgetCount(); + } + return widgetCount; + } +} diff --git a/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java index 0d7b224f6..62c9aa067 100644 --- a/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java +++ b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java @@ -65,7 +65,6 @@ public class UITreeComboBox extends JComboBox{ * @param o Object */ public void setSelectedItem(Object o){ - tree.setSelectionPath((TreePath)o); getModel().setSelectedItem(o); } @@ -110,7 +109,7 @@ public class UITreeComboBox extends JComboBox{ int index, boolean isSelected, boolean cellHasFocus){ if(tree != null && tree.getSelectedTreePath().length > 0){ TreePath path = tree.getSelectedTreePath()[0]; - tree.setAndScrollSelectionPath(path); + tree.setAndScrollSelectionPath(tree.getSelectedTreePath()); Object node = path.getLastPathComponent(); value = node; TreeCellRenderer r = tree.getCellRenderer(); @@ -132,7 +131,7 @@ public class UITreeComboBox extends JComboBox{ if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { TreePath[] paths = tree.getSelectedTreePath(); if (tree != null && paths.length > 0) { - tree.setAndScrollSelectionPath(paths[0]); + tree.setAndScrollSelectionPath(paths); setSelectedItem(paths[0]); MenuSelectionManager.defaultManager().clearSelectedPath(); } @@ -141,7 +140,7 @@ public class UITreeComboBox extends JComboBox{ tree.refreshUI(); TreePath[] paths = tree.getSelectedTreePath(); if (tree != null && paths.length > 0) { - tree.setAndScrollSelectionPath(paths[0]); + tree.setAndScrollSelectionPath(paths); setSelectedItem(paths[0]); MenuSelectionManager.defaultManager().clearSelectedPath(); } diff --git a/designer_form/src/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java b/designer_form/src/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java new file mode 100644 index 000000000..1695892ba --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java @@ -0,0 +1,57 @@ +package com.fr.design.mainframe.widget.accessibles; + +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.core.WidgetOption; +import com.fr.design.mainframe.FormWebWidgetConstants; +import com.fr.design.mainframe.widget.editors.ElementCaseToolBarPane; +import com.fr.design.mainframe.widget.wrappers.ElementCaseToolBarWrapper; +import com.fr.form.web.FormToolBarManager; +import com.fr.stable.ArrayUtils; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Created by harry on 2017-2-23. + */ +public class AccessibleElementCaseToolBarEditor extends UneditableAccessibleEditor { + private ElementCaseToolBarPane pane; + + public AccessibleElementCaseToolBarEditor() { + super(new ElementCaseToolBarWrapper()); + } + + @Override + protected void showEditorPane() { + if (pane == null) { + pane = new ElementCaseToolBarPane(); + pane.setDefaultToolBar(getDefaultToolBarManager(), getToolBarInstance()); + } + BasicDialog dlg = pane.showToolBarWindow(SwingUtilities.getWindowAncestor(this), new DialogActionAdapter() { + + @Override + public void doOk() { + setValue(pane.updateBean()); + fireStateChanged(); + } + }); + FormToolBarManager[] managers = (FormToolBarManager[]) getValue(); + pane.setCheckBoxSelected(ArrayUtils.isNotEmpty(managers)); + pane.populateBean((FormToolBarManager[]) getValue()); + dlg.setVisible(true); + } + + private FormToolBarManager getDefaultToolBarManager() { + return FormToolBarManager.createDefaultToolBar(); + } + + private WidgetOption[] getToolBarInstance() { + List defaultOptions = Arrays.asList(FormWebWidgetConstants.getFormElementCaseToolBarInstance()); + List options = new ArrayList(); + options.addAll(defaultOptions); + return options.toArray(new WidgetOption[options.size()]); + } +} diff --git a/designer_form/src/com/fr/design/mainframe/widget/editors/ElementCaseToolBarEditor.java b/designer_form/src/com/fr/design/mainframe/widget/editors/ElementCaseToolBarEditor.java new file mode 100644 index 000000000..de252c984 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/widget/editors/ElementCaseToolBarEditor.java @@ -0,0 +1,13 @@ +package com.fr.design.mainframe.widget.editors; + +import com.fr.design.mainframe.widget.accessibles.AccessibleElementCaseToolBarEditor; +import com.fr.design.mainframe.widget.accessibles.AccessiblePropertyEditor; + +/** + * Created by harry on 2017-2-23. + */ +public class ElementCaseToolBarEditor extends AccessiblePropertyEditor { + public ElementCaseToolBarEditor() { + super(new AccessibleElementCaseToolBarEditor()); + } +} diff --git a/designer_form/src/com/fr/design/mainframe/widget/editors/ElementCaseToolBarPane.java b/designer_form/src/com/fr/design/mainframe/widget/editors/ElementCaseToolBarPane.java new file mode 100644 index 000000000..624dc956a --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/widget/editors/ElementCaseToolBarPane.java @@ -0,0 +1,304 @@ +package com.fr.design.mainframe.widget.editors; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.gui.core.WidgetOption; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.FormSettingToolBar; +import com.fr.design.mainframe.FormToolBarButton; +import com.fr.design.mainframe.FormToolBarPane; +import com.fr.form.ui.Widget; +import com.fr.form.web.FormToolBarManager; +import com.fr.form.web.Location; +import com.fr.general.IOUtils; +import com.fr.general.Inter; +import com.fr.stable.ArrayUtils; +import com.fr.stable.Constants; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.image.ImageObserver; +import java.util.*; +import java.util.List; + +/** + * Created by harry on 2017-2-23. + */ +public class ElementCaseToolBarPane extends BasicBeanPane { + private static final int COLUMN = 2; + private int row = 6; + private DefaultTableModel toolbarButtonTableModel; + private JTable layoutTable; + private UICheckBox isUseToolBarCheckBox = new UICheckBox(Inter.getLocText("FR-Designer_Use_ToolBar") + ":"); // 是否使用工具栏 + + private FormToolBarPane northToolBar; + private FormToolBarPane southToolBar; + private FormToolBarManager defaultToolBar; + + + public ElementCaseToolBarPane() { + toolbarButtonTableModel = new TableModel(row ,COLUMN); + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + JPanel north = FRGUIPaneFactory.createBorderLayout_S_Pane(); + UIButton defaultButton = new UIButton(Inter.getLocText("FR-Designer_Restore_Default")); + // 恢复默认按钮 + defaultButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + northToolBar.removeButtonList(); + northToolBar.removeAll(); + southToolBar.removeButtonList(); + southToolBar.removeAll(); + if (defaultToolBar == null) { + return; + } + FormToolBarManager toolBarManager = defaultToolBar; + toolBarManager.setToolBarLocation(Location.createTopEmbedLocation()); + FormToolBarManager[] tbm = new FormToolBarManager[] { toolBarManager }; + populateBean(tbm); + ElementCaseToolBarPane.this.repaint(); + } + }); + + north.add(isUseToolBarCheckBox, BorderLayout.WEST); + JPanel aa = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); + aa.add(defaultButton); + north.add(aa, BorderLayout.CENTER); + this.add(north, BorderLayout.NORTH); + + northToolBar = new FormToolBarPane(); + northToolBar.setPreferredSize(new Dimension(ImageObserver.WIDTH, 26)); + northToolBar.setBackground(Color.lightGray); + + UIButton topButton = new UIButton(IOUtils.readIcon("com/fr/design/images/arrow/arrow_up.png")); + topButton.setBorder(null); + topButton.setOpaque(false); + topButton.setContentAreaFilled(false); + topButton.setFocusPainted(false); + topButton.setRequestFocusEnabled(false); + topButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (isSelectedtable()) { + WidgetOption no = (WidgetOption)layoutTable.getValueAt(layoutTable.getSelectedRow(), layoutTable.getSelectedColumn()); + Widget widget = no.createWidget(); + FormToolBarButton tb = new FormToolBarButton(no.optionIcon(), widget); + tb.setNameOption(no); + northToolBar.add(tb); + northToolBar.validate(); + northToolBar.repaint(); + } else { + JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_ChooseOneButton")); + } + } + }); + + UIButton downButton = new UIButton(IOUtils.readIcon("com/fr/design/images/arrow/arrow_down.png")); + downButton.setBorder(null); + downButton.setMargin(null); + downButton.setOpaque(false); + downButton.setContentAreaFilled(false); + downButton.setFocusPainted(false); + downButton.setRequestFocusEnabled(false); + downButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (isSelectedtable()) { + WidgetOption no = (WidgetOption)layoutTable.getValueAt(layoutTable.getSelectedRow(), layoutTable.getSelectedColumn()); + Widget widget = no.createWidget(); + FormToolBarButton tb = new FormToolBarButton(no.optionIcon(), widget); + tb.setNameOption(no); + southToolBar.add(tb); + southToolBar.validate(); + southToolBar.repaint(); + } else { + JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_ChooseOneButton")); + } + } + }); + + initLayoutTable(); + + JPanel center = FRGUIPaneFactory.createBorderLayout_S_Pane(); + center.setBackground(Color.white); + center.add(topButton, BorderLayout.NORTH); + JPanel small = FRGUIPaneFactory.createBorderLayout_S_Pane(); + small.setBackground(Color.white); + small.add(new UILabel(StringUtils.BLANK), BorderLayout.NORTH); + small.add(layoutTable, BorderLayout.CENTER); + center.add(small, BorderLayout.CENTER); + center.add(downButton, BorderLayout.SOUTH); + southToolBar = new FormToolBarPane(); + southToolBar.setPreferredSize(new Dimension(ImageObserver.WIDTH, 26)); + southToolBar.setBackground(Color.lightGray); + JPanel movePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + JPanel northContentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + FormSettingToolBar top = new FormSettingToolBar(Inter.getLocText("FR-Designer_ToolBar_Top"), northToolBar); + northContentPane.add(top, BorderLayout.EAST); + northContentPane.add(northToolBar, BorderLayout.CENTER); + northContentPane.setBackground(Color.lightGray); + + JPanel southContentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + FormSettingToolBar bottom = new FormSettingToolBar(Inter.getLocText("FR-Designer_ToolBar_Bottom"), southToolBar); + southContentPane.add(bottom, BorderLayout.EAST); + southContentPane.add(southToolBar, BorderLayout.CENTER); + southContentPane.setBackground(Color.lightGray); + + movePane.add(northContentPane, BorderLayout.NORTH); + movePane.add(center, BorderLayout.CENTER); + movePane.add(southContentPane, BorderLayout.SOUTH); + + this.add(new JScrollPane(movePane), BorderLayout.CENTER); + + isUseToolBarCheckBox.setSelected(false); + } + + private void initLayoutTable() { + layoutTable = new JTable(toolbarButtonTableModel); + layoutTable.setDefaultRenderer(Object.class, tableRenderer); + layoutTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + layoutTable.setColumnSelectionAllowed(false); + layoutTable.setRowSelectionAllowed(false); + layoutTable.setBackground(Color.white); + int columnWidth = Integer.parseInt(Inter.getLocText("FR-Designer_LayoutTable_Column_Width")); + for (int i = 0; i < layoutTable.getColumnModel().getColumnCount(); i++) { + layoutTable.getColumnModel().getColumn(i).setPreferredWidth(columnWidth); + } + layoutTable.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() > 1 && !SwingUtilities.isRightMouseButton(e)) { + WidgetOption no = (WidgetOption)layoutTable.getValueAt(layoutTable.getSelectedRow(), layoutTable.getSelectedColumn()); + Widget widget = no.createWidget(); + FormToolBarButton tb = new FormToolBarButton(no.optionIcon(), widget); + tb.setNameOption(no); + northToolBar.add(tb); + northToolBar.validate(); + northToolBar.repaint(); + } + } + }); + } + + private boolean isSelectedtable() { + for (int i = 0; i < layoutTable.getColumnCount(); i++) { + if (layoutTable.isColumnSelected(i)) { + return true; + } + } + return false; + } + + /** + * 是否被选中 + * @return 同上 + */ + public boolean isUseToolbar() { + return this.isUseToolBarCheckBox.isSelected(); + } + + public void setDefaultToolBar(FormToolBarManager defaultToolBar, WidgetOption[] buttonArray) { + this.defaultToolBar = defaultToolBar; + if (buttonArray != null) { + for (int i = 0; i < buttonArray.length; i++) { + toolbarButtonTableModel.setValueAt(buttonArray[i], i % row, i / row); + } + } + + } + + DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer() { + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + + if (value instanceof WidgetOption) { + WidgetOption nameOption = (WidgetOption)value; + this.setText(nameOption.optionName()); + + Icon icon = nameOption.optionIcon(); + if (icon != null) { + this.setIcon(icon); + } + } + if (value == null) { + this.setText(StringUtils.EMPTY); + this.setIcon(null); + } + return this; + } + }; + + @Override + protected String title4PopupWindow() { + return Inter.getLocText(new String[]{"Form-EC_toolbar", "Set"}); + } + + public void setCheckBoxSelected(boolean b) { + this.isUseToolBarCheckBox.setSelected(b); + } + + @Override + public void populateBean(FormToolBarManager[] toolBarManager) { + if (ArrayUtils.isEmpty(toolBarManager)) { + defaultToolBar.setToolBarLocation(Location.createTopEmbedLocation()); + toolBarManager = new FormToolBarManager[] { defaultToolBar }; + } + if (ArrayUtils.isEmpty(toolBarManager)) { + return; + } + for (int i = 0; i < toolBarManager.length; i++) { + Location location = toolBarManager[i].getToolBarLocation(); + if (location instanceof Location.Embed) { + if (((Location.Embed)location).getPosition() == Constants.TOP) { + northToolBar.populateBean(toolBarManager[i].getToolBar()); + } else if (((Location.Embed)location).getPosition() == Constants.BOTTOM) { + southToolBar.populateBean(toolBarManager[i].getToolBar()); + } + } + } + } + + @Override + public FormToolBarManager[] updateBean() { + if(!isUseToolbar()){ + return new FormToolBarManager[0]; + } + List toolBarManagerList = new ArrayList(); + if (!northToolBar.isEmpty()) { + FormToolBarManager north = new FormToolBarManager(); + north.setToolBar(northToolBar.updateBean()); + north.setToolBarLocation(Location.createTopEmbedLocation()); + toolBarManagerList.add(north); + } + + if (!southToolBar.isEmpty()) { + FormToolBarManager south = new FormToolBarManager(); + south.setToolBar(southToolBar.updateBean()); + south.setToolBarLocation(Location.createBottomEmbedLocation()); + toolBarManagerList.add(south); + } + return toolBarManagerList.toArray(new FormToolBarManager[toolBarManagerList.size()]); + } + + private class TableModel extends DefaultTableModel { + public TableModel(int i, int j) { + super(i, j); + } + + // 禁止jtable的双击编辑功能 + public boolean isCellEditable(int row, int column) { + return false; + } + } +} diff --git a/designer_form/src/com/fr/design/mainframe/widget/wrappers/ElementCaseToolBarWrapper.java b/designer_form/src/com/fr/design/mainframe/widget/wrappers/ElementCaseToolBarWrapper.java new file mode 100644 index 000000000..e244c2a22 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/widget/wrappers/ElementCaseToolBarWrapper.java @@ -0,0 +1,34 @@ +package com.fr.design.mainframe.widget.wrappers; + +import com.fr.design.Exception.ValidationException; +import com.fr.design.designer.properties.Decoder; +import com.fr.design.designer.properties.Encoder; +import com.fr.form.web.FormToolBarManager; +import com.fr.general.Inter; + +/** + * Created by harry on 2017-3-1. + */ +public class ElementCaseToolBarWrapper implements Encoder, Decoder { + @Override + public Object decode(String txt) { + return null; + } + + @Override + public void validate(String txt) throws ValidationException { + + } + + @Override + public String encode(Object v) { + if (v == null) { + return null; + } + FormToolBarManager[] toolBarManager = (FormToolBarManager[])v; + if (toolBarManager.length != 0) { + return Inter.getLocText("FR-Designer_Open"); + } + return Inter.getLocText("FR-Designer_Close"); + } +}