From 3cf5553cd355cf40d5b03f6f15a79cdd080843ec Mon Sep 17 00:00:00 2001 From: hzzz Date: Fri, 26 May 2017 09:53:18 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-2773=20mac=E4=B8=AD=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE=E7=9A=84=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/AuthorityToolBarPane.java | 366 +++- designer/src/com/fr/grid/GridKeyListener.java | 5 +- .../src/com/fr/grid/GridMouseAdapter.java | 1605 ++++++++--------- .../common/inputevent/InputEventBaseOnOS.java | 21 + .../gui/icombobox/ExtendedComboBox.java | 4 +- .../fr/design/gui/icombobox/UIComboBoxUI.java | 3 +- .../com/fr/design/gui/ilist/CheckBoxList.java | 3 +- .../com/fr/design/gui/itable/TableSorter.java | 4 +- .../UserObjectRefreshJTree.java | 3 +- .../fr/design/roleAuthority/UIRoleTreeUI.java | 3 +- .../designer/beans/models/SelectionModel.java | 5 +- 11 files changed, 1205 insertions(+), 817 deletions(-) create mode 100644 designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java diff --git a/designer/src/com/fr/design/mainframe/AuthorityToolBarPane.java b/designer/src/com/fr/design/mainframe/AuthorityToolBarPane.java index 80f40cadf..fcb6988b9 100644 --- a/designer/src/com/fr/design/mainframe/AuthorityToolBarPane.java +++ b/designer/src/com/fr/design/mainframe/AuthorityToolBarPane.java @@ -1 +1,365 @@ -package com.fr.design.mainframe; import com.fr.base.ConfigManager; import com.fr.base.ConfigManagerProvider; import com.fr.base.FRContext; import com.fr.design.beans.BasicBeanPane; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.mainframe.toolbar.AuthorityEditToolBarComponent; import com.fr.design.mainframe.toolbar.ToolBarMenuDock; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.design.webattr.ReportWebWidgetConstants; import com.fr.design.webattr.ToolBarButton; import com.fr.design.webattr.ToolBarPane; import com.fr.form.ui.Button; import com.fr.form.ui.ToolBar; import com.fr.form.ui.Widget; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import com.fr.main.TemplateWorkBook; import com.fr.report.web.Location; import com.fr.report.web.ToolBarManager; import com.fr.report.web.WebContent; import com.fr.stable.ArrayUtils; import com.fr.web.attr.ReportWebAttr; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.List; /** * Author : daisy * Date: 13-9-9 * Time: 下午4:58 */ public class AuthorityToolBarPane extends BasicBeanPane implements AuthorityEditToolBarComponent { private static final int SMALL_GAP = 13; private static final int GAP = 25; private static final int PRE_GAP = 9; private static final int COMBOX_WIDTH = 144; private static final String[] CHOOSEITEM = new String[]{Inter.getLocText("M-Page_Preview"), Inter.getLocText(new String[]{"Face_Write", "PageSetup-Page"}), Inter.getLocText("M-Data_Analysis")}; private UIComboBox choseComboBox; private ToolBarPane toolBarPane; private AuthorityEditToolBarPane authorityEditToolBarPane = null; private int selectedIndex = -1; private UILabel title = null; private MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (!toolBarPane.isEnabled()) { return; } java.util.List buttonlists = toolBarPane.getToolBarButtons(); int oldIndex = selectedIndex; selectedIndex = pressButtonIndex(e, buttonlists); //实现shift多选 if (e.isShiftDown()) { if (oldIndex == -1) { removeSelection(); ((ToolBarButton) e.getSource()).setSelected(true); } else { int max = oldIndex >= selectedIndex ? oldIndex : selectedIndex; int min = oldIndex <= selectedIndex ? oldIndex : selectedIndex; for (int i = min; i <= max; i++) { buttonlists.get(i).setSelected(true); } } } else if (!e.isControlDown()) { //实现单选 removeSelection(); if (selectedIndex != -1) { ((ToolBarButton) e.getSource()).setSelected(true); } } authorityEditToolBarPane.populate(); EastRegionContainerPane.getInstance().replaceUpPane(authorityEditToolBarPane); } }; private int pressButtonIndex(MouseEvent e, java.util.List buttonlists) { if (!(e.getSource() instanceof ToolBarButton)) { return -1; } ToolBarButton button = (ToolBarButton) e.getSource(); for (int i = 0; i < buttonlists.size(); i++) { if (ComparatorUtils.equals(button, buttonlists.get(i))) { return i; } } return -1; } /** * 去掉选择 */ public void removeSelection() { for (ToolBarButton button : toolBarPane.getToolBarButtons()) { button.setSelected(false); } } private ItemListener itemListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.DESELECTED) { selectedIndex = -1; populateToolBarPane(); authorityEditToolBarPane = new AuthorityEditToolBarPane(toolBarPane.getToolBarButtons()); authorityEditToolBarPane.setAuthorityToolBarPane(AuthorityToolBarPane.this); EastRegionContainerPane.getInstance().replaceUpPane(authorityEditToolBarPane); EastRegionContainerPane.getInstance().replaceDownPane(RolesAlreadyEditedPane.getInstance()); } } }; public AuthorityToolBarPane() { this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 3)); this.setBorder(BorderFactory.createEmptyBorder(0, PRE_GAP, 0, 0)); title = new UILabel(Inter.getLocText(new String[]{"ReportServerP-Toolbar", "Choose_Role"})); title.setHorizontalAlignment(SwingConstants.CENTER); this.add(title, 0); choseComboBox = new UIComboBox(CHOOSEITEM) { public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); dim.width = COMBOX_WIDTH; return dim; } }; choseComboBox.addItemListener(itemListener); //默认选择第一个 choseComboBox.setSelectedIndex(0); this.add(createGapPanel(SMALL_GAP)); this.add(choseComboBox); toolBarPane = new ToolBarPane(); toolBarPane.setBorder(null); toolBarPane.removeDefaultMouseListener(); this.add(createGapPanel(GAP)); this.add(toolBarPane); populateDefaultToolBarWidgets(); populateBean(getReportWebAttr()); toolBarPane.addAuthorityListener(mouseListener); authorityEditToolBarPane = new AuthorityEditToolBarPane(toolBarPane.getToolBarButtons()); authorityEditToolBarPane.setAuthorityToolBarPane(this); checkToolBarPaneEnable(); } private JPanel createGapPanel(final int gap) { return new JPanel() { public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); dim.width = gap; return dim; } }; } private void populateToolBarPane() { toolBarPane.removeAll(); populateDefaultToolBarWidgets(); populateBean(getReportWebAttr()); toolBarPane.addAuthorityListener(mouseListener); toolBarPane.repaint(); authorityEditToolBarPane = new AuthorityEditToolBarPane(toolBarPane.getToolBarButtons()); checkToolBarPaneEnable(); } /** * 使用普通用户远程设计时,如果工具栏使用的是“采用服务器设置”,则工具栏按钮为灰不可用 */ private void checkToolBarPaneEnable() { List toolBarButtons = toolBarPane.getToolBarButtons(); boolean isnotEnable = ComparatorUtils.equals(title.getText(), Inter.getLocText(new String[]{"Server", "ReportServerP-Toolbar", "Choose_Role"})) && !FRContext.getCurrentEnv().isRoot(); for (ToolBarButton button : toolBarButtons) { button.setEnabled(!isnotEnable); } toolBarPane.setEnabled(!isnotEnable); } /** * 更新权限工具栏面板 */ public void populateAuthority() { toolBarPane.repaint(); } private ReportWebAttr getReportWebAttr() { JTemplate editingTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (!editingTemplate.isJWorkBook()) { return null; } JWorkBook editingWorkBook = (JWorkBook) editingTemplate; TemplateWorkBook wbTpl = editingWorkBook.getTarget(); return wbTpl.getReportWebAttr(); } //将该报表的设置过权限的属性记录一下 public void setAuthorityWebAttr(Widget widget, boolean isSelected, String selectedRole) { JTemplate editingTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (!editingTemplate.isJWorkBook()) { return; } JWorkBook editingWorkBook = (JWorkBook) editingTemplate; TemplateWorkBook wbTpl = editingWorkBook.getTarget(); ReportWebAttr rw = wbTpl.getReportWebAttr(); ConfigManagerProvider cm = ConfigManager.getProviderInstance(); ReportWebAttr webAttr = ((ReportWebAttr) cm.getGlobalAttribute(ReportWebAttr.class)); //wbTpl.clear先清空 //再将所有的保存进去 //看是存在服务器还存在模板里面 if (choseComboBox.getSelectedIndex() == 0) { //分页 if (rw == null || rw.getWebPage() == null) { dealWithWebContent(webAttr.getWebPage(), widget, isSelected, selectedRole); } } else if (choseComboBox.getSelectedIndex() == 1) { //填报 if (rw == null || rw.getWebPage() == null) { dealWithWebContent(webAttr.getWebWrite(), widget, isSelected, selectedRole); } } else { //view if (rw == null || rw.getWebPage() == null) { dealWithWebContent(webAttr.getWebView(), widget, isSelected, selectedRole); } } } private void dealWithWebContent(WebContent wc, Widget widget, boolean isSelected, String selectedRole) { ToolBarManager[] managers = wc.getToolBarManagers(); if (managers == null) { return; } for (int i = 0; i < managers.length; i++) { ToolBar tb = managers[i].getToolBar(); for (int j = 0; j < tb.getWidgetSize(); j++) { if (widget instanceof Button && tb.getWidget(j) instanceof Button) { if (ComparatorUtils.equals(((Button) widget).getIconName(), ((Button) tb.getWidget(j)).getIconName())) { if (!isSelected) { tb.getWidget(j).getWidgetPrivilegeControl().addInvisibleRole(selectedRole); } else { tb.getWidget(j).getWidgetPrivilegeControl().removeInvisibleRole(selectedRole); } } } } } wc.setToolBarManagers(managers); } public void populateBean(ReportWebAttr reportWebAttr) { this.remove(title); // 如果是空值就说明采用服务器配置了 if (reportWebAttr == null || this.getWebContent(reportWebAttr) == null) { title = new UILabel(Inter.getLocText(new String[]{"Server", "ReportServerP-Toolbar", "Choose_Role"})); populateServerSettings(); this.add(title, 0); return; } // 模板设置 T webContent = this.getWebContent(reportWebAttr); title = new UILabel(Inter.getLocText(new String[]{"the_template", "ReportServerP-Toolbar", "Choose_Role"})); this.add(title, 0); populate(webContent.getToolBarManagers()); } public ReportWebAttr updateBean() { return null; } public void populate(ToolBarManager[] toolBarManager) { if (ArrayUtils.isEmpty(toolBarManager)) { return; } if (toolBarManager.length == 0) { return; } for (int i = 0; i < toolBarManager.length; i++) { toolBarPane.populateBean(toolBarManager[i].getToolBar()); } } public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); dim.height = ToolBarMenuDock.PANLE_HEIGNT; return dim; } public void populateBean(ToolBarManager[] toolBarManager) { if (ArrayUtils.isEmpty(toolBarManager)) { return; } for (int i = 0; i < toolBarManager.length; i++) { Location location = toolBarManager[i].getToolBarLocation(); if (location instanceof Location.Embed) { toolBarPane.populateBean(toolBarManager[i].getToolBar()); } } } private void populateServerSettings() { ConfigManagerProvider cm = ConfigManager.getProviderInstance(); ReportWebAttr webAttr = ((ReportWebAttr) cm.getGlobalAttribute(ReportWebAttr.class)); if (this.getWebContent(webAttr) != null) { populate(this.getWebContent(webAttr).getToolBarManagers()); } } protected String title4PopupWindow() { return null; } private T getWebContent(ReportWebAttr reportWebAttr) { if (choseComboBox.getSelectedIndex() == 0) { return reportWebAttr == null ? null : (T) reportWebAttr.getWebPage(); } else if (choseComboBox.getSelectedIndex() == 1) { return reportWebAttr == null ? null : (T) reportWebAttr.getWebWrite(); } else { return reportWebAttr == null ? null : (T) reportWebAttr.getWebView(); } } private void populateDefaultToolBarWidgets() { if (choseComboBox.getSelectedIndex() == 0) { ReportWebWidgetConstants.getPageToolBarInstance(); } else if (choseComboBox.getSelectedIndex() == 1) { ReportWebWidgetConstants.getWriteToolBarInstance(); } else { ReportWebWidgetConstants.getViewToolBarInstance(); } } private ToolBarManager getDefaultToolBarManager() { if (choseComboBox.getSelectedIndex() == 0) { return ToolBarManager.createDefaultToolBar(); } else if (choseComboBox.getSelectedIndex() == 1) { return ToolBarManager.createDefaultWriteToolBar(); } else { return ToolBarManager.createDefaultViewToolBar(); } } } \ No newline at end of file +package com.fr.design.mainframe; + +import com.fr.base.ConfigManager; +import com.fr.base.ConfigManagerProvider; +import com.fr.base.FRContext; +import com.fr.common.inputevent.InputEventBaseOnOS; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.file.HistoryTemplateListPane; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.mainframe.toolbar.AuthorityEditToolBarComponent; +import com.fr.design.mainframe.toolbar.ToolBarMenuDock; +import com.fr.design.roleAuthority.RolesAlreadyEditedPane; +import com.fr.design.webattr.ReportWebWidgetConstants; +import com.fr.design.webattr.ToolBarButton; +import com.fr.design.webattr.ToolBarPane; +import com.fr.form.ui.Button; +import com.fr.form.ui.ToolBar; +import com.fr.form.ui.Widget; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; +import com.fr.main.TemplateWorkBook; +import com.fr.report.web.Location; +import com.fr.report.web.ToolBarManager; +import com.fr.report.web.WebContent; +import com.fr.stable.ArrayUtils; +import com.fr.web.attr.ReportWebAttr; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.util.List; + +/** + * Author : daisy + * Date: 13-9-9 + * Time: 下午4:58 + */ +public class AuthorityToolBarPane extends BasicBeanPane implements AuthorityEditToolBarComponent { + private static final int SMALL_GAP = 13; + private static final int GAP = 25; + private static final int PRE_GAP = 9; + private static final int COMBOX_WIDTH = 144; + + private static final String[] CHOOSEITEM = new String[]{Inter.getLocText("M-Page_Preview"), Inter.getLocText(new String[]{"Face_Write", "PageSetup-Page"}), Inter.getLocText("M-Data_Analysis")}; + private UIComboBox choseComboBox; + private ToolBarPane toolBarPane; + private AuthorityEditToolBarPane authorityEditToolBarPane = null; + private int selectedIndex = -1; + private UILabel title = null; + private MouseListener mouseListener = new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (!toolBarPane.isEnabled()) { + return; + } + java.util.List buttonlists = toolBarPane.getToolBarButtons(); + int oldIndex = selectedIndex; + selectedIndex = pressButtonIndex(e, buttonlists); + //实现shift多选 + if (e.isShiftDown()) { + if (oldIndex == -1) { + removeSelection(); + ((ToolBarButton) e.getSource()).setSelected(true); + } else { + int max = oldIndex >= selectedIndex ? oldIndex : selectedIndex; + int min = oldIndex <= selectedIndex ? oldIndex : selectedIndex; + for (int i = min; i <= max; i++) { + buttonlists.get(i).setSelected(true); + } + } + } else if (!InputEventBaseOnOS.isControlDown(e)) { + //实现单选 + removeSelection(); + if (selectedIndex != -1) { + ((ToolBarButton) e.getSource()).setSelected(true); + } + } + authorityEditToolBarPane.populate(); + EastRegionContainerPane.getInstance().replaceUpPane(authorityEditToolBarPane); + } + + }; + + + private int pressButtonIndex(MouseEvent e, java.util.List buttonlists) { + if (!(e.getSource() instanceof ToolBarButton)) { + return -1; + } + ToolBarButton button = (ToolBarButton) e.getSource(); + for (int i = 0; i < buttonlists.size(); i++) { + if (ComparatorUtils.equals(button, buttonlists.get(i))) { + return i; + } + } + return -1; + } + + /** + * 去掉选择 + */ + public void removeSelection() { + for (ToolBarButton button : toolBarPane.getToolBarButtons()) { + button.setSelected(false); + } + } + + + private ItemListener itemListener = new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.DESELECTED) { + selectedIndex = -1; + populateToolBarPane(); + authorityEditToolBarPane = new AuthorityEditToolBarPane(toolBarPane.getToolBarButtons()); + authorityEditToolBarPane.setAuthorityToolBarPane(AuthorityToolBarPane.this); + EastRegionContainerPane.getInstance().replaceUpPane(authorityEditToolBarPane); + EastRegionContainerPane.getInstance().replaceDownPane(RolesAlreadyEditedPane.getInstance()); + } + } + }; + + public AuthorityToolBarPane() { + this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 3)); + this.setBorder(BorderFactory.createEmptyBorder(0, PRE_GAP, 0, 0)); + title = new UILabel(Inter.getLocText(new String[]{"ReportServerP-Toolbar", "Choose_Role"})); + title.setHorizontalAlignment(SwingConstants.CENTER); + this.add(title, 0); + choseComboBox = new UIComboBox(CHOOSEITEM) { + public Dimension getPreferredSize() { + Dimension dim = super.getPreferredSize(); + dim.width = COMBOX_WIDTH; + return dim; + } + }; + choseComboBox.addItemListener(itemListener); + //默认选择第一个 + choseComboBox.setSelectedIndex(0); + this.add(createGapPanel(SMALL_GAP)); + this.add(choseComboBox); + toolBarPane = new ToolBarPane(); + toolBarPane.setBorder(null); + toolBarPane.removeDefaultMouseListener(); + this.add(createGapPanel(GAP)); + this.add(toolBarPane); + populateDefaultToolBarWidgets(); + populateBean(getReportWebAttr()); + toolBarPane.addAuthorityListener(mouseListener); + authorityEditToolBarPane = new AuthorityEditToolBarPane(toolBarPane.getToolBarButtons()); + authorityEditToolBarPane.setAuthorityToolBarPane(this); + checkToolBarPaneEnable(); + } + + private JPanel createGapPanel(final int gap) { + return new JPanel() { + public Dimension getPreferredSize() { + Dimension dim = super.getPreferredSize(); + dim.width = gap; + return dim; + } + }; + } + + + private void populateToolBarPane() { + toolBarPane.removeAll(); + populateDefaultToolBarWidgets(); + populateBean(getReportWebAttr()); + toolBarPane.addAuthorityListener(mouseListener); + toolBarPane.repaint(); + authorityEditToolBarPane = new AuthorityEditToolBarPane(toolBarPane.getToolBarButtons()); + checkToolBarPaneEnable(); + } + + /** + * 使用普通用户远程设计时,如果工具栏使用的是“采用服务器设置”,则工具栏按钮为灰不可用 + */ + private void checkToolBarPaneEnable() { + List toolBarButtons = toolBarPane.getToolBarButtons(); + boolean isnotEnable = ComparatorUtils.equals(title.getText(), Inter.getLocText(new String[]{"Server", "ReportServerP-Toolbar", "Choose_Role"})) + && !FRContext.getCurrentEnv().isRoot(); + for (ToolBarButton button : toolBarButtons) { + button.setEnabled(!isnotEnable); + } + toolBarPane.setEnabled(!isnotEnable); + } + + /** + * 更新权限工具栏面板 + */ + public void populateAuthority() { + toolBarPane.repaint(); + } + + + private ReportWebAttr getReportWebAttr() { + JTemplate editingTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (!editingTemplate.isJWorkBook()) { + return null; + } + JWorkBook editingWorkBook = (JWorkBook) editingTemplate; + TemplateWorkBook wbTpl = editingWorkBook.getTarget(); + return wbTpl.getReportWebAttr(); + } + + + //将该报表的设置过权限的属性记录一下 + public void setAuthorityWebAttr(Widget widget, boolean isSelected, String selectedRole) { + JTemplate editingTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (!editingTemplate.isJWorkBook()) { + return; + } + JWorkBook editingWorkBook = (JWorkBook) editingTemplate; + TemplateWorkBook wbTpl = editingWorkBook.getTarget(); + + ReportWebAttr rw = wbTpl.getReportWebAttr(); + ConfigManagerProvider cm = ConfigManager.getProviderInstance(); + ReportWebAttr webAttr = ((ReportWebAttr) cm.getGlobalAttribute(ReportWebAttr.class)); + + //wbTpl.clear先清空 + //再将所有的保存进去 + //看是存在服务器还存在模板里面 + if (choseComboBox.getSelectedIndex() == 0) { + //分页 + if (rw == null || rw.getWebPage() == null) { + dealWithWebContent(webAttr.getWebPage(), widget, isSelected, selectedRole); + } + } else if (choseComboBox.getSelectedIndex() == 1) { + //填报 + if (rw == null || rw.getWebPage() == null) { + dealWithWebContent(webAttr.getWebWrite(), widget, isSelected, selectedRole); + } + } else { + //view + if (rw == null || rw.getWebPage() == null) { + dealWithWebContent(webAttr.getWebView(), widget, isSelected, selectedRole); + } + } + + } + + private void dealWithWebContent(WebContent wc, Widget widget, boolean isSelected, String selectedRole) { + ToolBarManager[] managers = wc.getToolBarManagers(); + if (managers == null) { + return; + } + for (int i = 0; i < managers.length; i++) { + ToolBar tb = managers[i].getToolBar(); + for (int j = 0; j < tb.getWidgetSize(); j++) { + if (widget instanceof Button && tb.getWidget(j) instanceof Button) { + if (ComparatorUtils.equals(((Button) widget).getIconName(), + ((Button) tb.getWidget(j)).getIconName())) { + if (!isSelected) { + tb.getWidget(j).getWidgetPrivilegeControl().addInvisibleRole(selectedRole); + } else { + tb.getWidget(j).getWidgetPrivilegeControl().removeInvisibleRole(selectedRole); + } + } + } + } + } + wc.setToolBarManagers(managers); + } + + + public void populateBean(ReportWebAttr reportWebAttr) { + this.remove(title); + // 如果是空值就说明采用服务器配置了 + if (reportWebAttr == null || this.getWebContent(reportWebAttr) == null) { + title = new UILabel(Inter.getLocText(new String[]{"Server", "ReportServerP-Toolbar", "Choose_Role"})); + populateServerSettings(); + this.add(title, 0); + return; + } + // 模板设置 + T webContent = this.getWebContent(reportWebAttr); + title = new UILabel(Inter.getLocText(new String[]{"the_template", "ReportServerP-Toolbar", "Choose_Role"})); + this.add(title, 0); + populate(webContent.getToolBarManagers()); + } + + public ReportWebAttr updateBean() { + return null; + } + + public void populate(ToolBarManager[] toolBarManager) { + if (ArrayUtils.isEmpty(toolBarManager)) { + return; + } + if (toolBarManager.length == 0) { + return; + } + for (int i = 0; i < toolBarManager.length; i++) { + toolBarPane.populateBean(toolBarManager[i].getToolBar()); + } + } + + + public Dimension getPreferredSize() { + Dimension dim = super.getPreferredSize(); + dim.height = ToolBarMenuDock.PANLE_HEIGNT; + return dim; + } + + + public void populateBean(ToolBarManager[] toolBarManager) { + if (ArrayUtils.isEmpty(toolBarManager)) { + return; + } + for (int i = 0; i < toolBarManager.length; i++) { + Location location = toolBarManager[i].getToolBarLocation(); + if (location instanceof Location.Embed) { + toolBarPane.populateBean(toolBarManager[i].getToolBar()); + } + } + } + + + private void populateServerSettings() { + ConfigManagerProvider cm = ConfigManager.getProviderInstance(); + ReportWebAttr webAttr = ((ReportWebAttr) cm.getGlobalAttribute(ReportWebAttr.class)); + if (this.getWebContent(webAttr) != null) { + populate(this.getWebContent(webAttr).getToolBarManagers()); + } + } + + protected String title4PopupWindow() { + return null; + } + + + private T getWebContent(ReportWebAttr reportWebAttr) { + if (choseComboBox.getSelectedIndex() == 0) { + return reportWebAttr == null ? null : (T) reportWebAttr.getWebPage(); + } else if (choseComboBox.getSelectedIndex() == 1) { + return reportWebAttr == null ? null : (T) reportWebAttr.getWebWrite(); + } else { + return reportWebAttr == null ? null : (T) reportWebAttr.getWebView(); + } + + } + + private void populateDefaultToolBarWidgets() { + if (choseComboBox.getSelectedIndex() == 0) { + ReportWebWidgetConstants.getPageToolBarInstance(); + } else if (choseComboBox.getSelectedIndex() == 1) { + ReportWebWidgetConstants.getWriteToolBarInstance(); + } else { + ReportWebWidgetConstants.getViewToolBarInstance(); + } + } + + private ToolBarManager getDefaultToolBarManager() { + if (choseComboBox.getSelectedIndex() == 0) { + return ToolBarManager.createDefaultToolBar(); + } else if (choseComboBox.getSelectedIndex() == 1) { + return ToolBarManager.createDefaultWriteToolBar(); + } else { + return ToolBarManager.createDefaultViewToolBar(); + } + + } + + +} \ No newline at end of file diff --git a/designer/src/com/fr/grid/GridKeyListener.java b/designer/src/com/fr/grid/GridKeyListener.java index 8e3148bf5..e60097fd6 100644 --- a/designer/src/com/fr/grid/GridKeyListener.java +++ b/designer/src/com/fr/grid/GridKeyListener.java @@ -1,5 +1,6 @@ package com.fr.grid; +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.mainframe.ElementCasePane; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.FloatSelection; @@ -71,7 +72,7 @@ public class GridKeyListener implements KeyListener { // Richie:Ctrl + A全选单元格 case KeyEvent.VK_A: boolean macOS = OperatingSystem.isMacOS() && evt.isMetaDown(); - boolean windows = OperatingSystem.isWindows() && evt.isControlDown(); + boolean windows = OperatingSystem.isWindows() && InputEventBaseOnOS.isControlDown(evt); if (macOS || windows) { reportPane.setSelection(new CellSelection(0, 0, report.getColumnCount(), report.getRowCount())); isNeedRepaint = true; @@ -168,7 +169,7 @@ public class GridKeyListener implements KeyListener { return; } KeyEvent newEvt = KeyEventWork.processKeyEvent(evt); - if (newEvt == null || evt.isControlDown()) {// uneditable. + if (newEvt == null || InputEventBaseOnOS.isControlDown(evt)) {// uneditable. return; } char ch = evt.getKeyChar(); diff --git a/designer/src/com/fr/grid/GridMouseAdapter.java b/designer/src/com/fr/grid/GridMouseAdapter.java index 9f14df471..8a4053353 100644 --- a/designer/src/com/fr/grid/GridMouseAdapter.java +++ b/designer/src/com/fr/grid/GridMouseAdapter.java @@ -1,26 +1,14 @@ package com.fr.grid; -import java.awt.Cursor; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; -import java.util.HashMap; -import java.util.Map; - -import javax.swing.JPopupMenu; -import javax.swing.SwingUtilities; - import com.fr.base.BaseUtils; import com.fr.base.DynamicUnitList; import com.fr.base.ScreenResolution; +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.constants.UIConstants; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.ElementCasePane; import com.fr.design.present.CellWriteAttrPane; +import com.fr.design.utils.gui.GUICoreUtils; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.FloatSelection; import com.fr.grid.selection.Selection; @@ -37,7 +25,12 @@ import com.fr.stable.ColumnRow; import com.fr.stable.StringUtils; import com.fr.stable.unit.FU; import com.fr.stable.unit.OLDPIX; -import com.fr.design.utils.gui.GUICoreUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.util.HashMap; +import java.util.Map; /** * the MouseListener of the Grid @@ -45,800 +38,800 @@ import com.fr.design.utils.gui.GUICoreUtils; * @editor zhou 2012-3-22下午1:53:59 */ public class GridMouseAdapter implements MouseListener, MouseWheelListener, MouseMotionListener { - private static final int WIDGET_WIDTH = 13; - private static final int TIME_DELAY = 100; - private static final int TOOLTIP_X = 30; - private static final int TOOLTIP_X_Y_FIX = 4; - private static final double COPY_CROSS_INNER_DISTANCE = 1.5; - private static final double COPY_CROSS_OUTER_DISTANCE = 2.5; - /** - * 拖拽时候刷新时间间隔 - */ - private static int DRAG_REFRESH_TIME = 10; - /** - * 对应的表格-Grid - */ - private Grid grid; - /** - * the Point(x,y) where the mouse pressed - */ - private int oldEvtX = 0; - private int oldEvtY = 0; - // the old location, used for Move float element. - private int oldLocationX; - private int oldLocationY; - private long lastMouseMoveTime = 0; // 最后的MouseMove时间. - // 保存各个悬浮元素到oldLocation距离 - private Map floatNamePointMap; - /** - * august:因为CellSelection里面没有记录的变量了,必须要有个变量来存按住shift键的位置之前的鼠标的位置 - * 用户可能一直按住shift键不放,所以按住shift键之前的鼠标位置是必须有的. - */ - private ColumnRow tempOldSelectedCell; - - private int ECBlockGap = 40; - - protected GridMouseAdapter(Grid grid) { - this.grid = grid; - } - - /** - * @param evt - */ - public void mousePressed(MouseEvent evt) { - if (!grid.isEnabled()) { - return; - } - oldEvtX = evt.getX(); - oldEvtY = evt.getY(); - grid.stopEditing(); - - if (!grid.hasFocus() && grid.isRequestFocusEnabled()) { - grid.requestFocus(); - } - - if (grid.getDrawingFloatElement() != null) { - doWithDrawingFloatElement(); - } else { - if (SwingUtilities.isRightMouseButton(evt)) { - doWithRightButtonPressed(); - } else { - doWithLeftButtonPressed(evt); - } - // 用户没有按住Shift键时,tempOldSelectedCell是一直变化的。如果一直按住shift,是不变的 - ElementCasePane ePane = grid.getElementCasePane(); - if (!evt.isShiftDown() && ePane.getSelection() instanceof CellSelection) { - tempOldSelectedCell = GridUtils.getAdjustEventColumnRow(ePane, oldEvtX, oldEvtY); - } - } - - } - - /** - * 将悬浮元素(只有文本和公式)添加到鼠标点击的位置 - */ - private void doWithDrawingFloatElement() { - ElementCasePane reportPane = grid.getElementCasePane(); - TemplateElementCase report = reportPane.getEditingElementCase(); - DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); - DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); - - int horizentalScrollValue = grid.getHorizontalValue(); - int verticalScrollValue = grid.getVerticalValue(); - int resolution = ScreenResolution.getScreenResolution(); - FU evtX_fu = FU.valueOfPix(this.oldEvtX, resolution); - FU evtY_fu = FU.valueOfPix(this.oldEvtY, resolution); - - FU leftDistance = FU.getInstance(evtX_fu.toFU() + columnWidthList.getRangeValue(0, horizentalScrollValue).toFU()); - FU topDistance = FU.getInstance(evtY_fu.toFU() + rowHeightList.getRangeValue(0, verticalScrollValue).toFU()); - - grid.getDrawingFloatElement().setLeftDistance(leftDistance); - grid.getDrawingFloatElement().setTopDistance(topDistance); - - report.addFloatElement(grid.getDrawingFloatElement()); - reportPane.setSelection(new FloatSelection(grid.getDrawingFloatElement().getName())); - } - - /** - * 处理右击事件,弹出右键菜单. - */ - private void doWithRightButtonPressed() { - ElementCasePane reportPane = grid.getElementCasePane(); - Object[] tmpFloatElementCursor = GridUtils.getAboveFloatElementCursor(reportPane, this.oldEvtX, this.oldEvtY); - if (!ArrayUtils.isEmpty(tmpFloatElementCursor)) { - FloatElement selectedFloatElement = (FloatElement) tmpFloatElementCursor[0]; - reportPane.setSelection(new FloatSelection(selectedFloatElement.getName())); - } else { - ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(reportPane, this.oldEvtX, this.oldEvtY); - if (!reportPane.getSelection().containsColumnRow(selectedCellPoint)) { - GridUtils.doSelectCell(reportPane, selectedCellPoint.getColumn(), selectedCellPoint.getRow()); - } - } - reportPane.repaint(); - JPopupMenu cellPopupMenu = reportPane.createPopupMenu(); - if (cellPopupMenu != null) { - GUICoreUtils.showPopupMenu(cellPopupMenu, this.grid, this.oldEvtX - 1, this.oldEvtY - 1); - } - } - - /** - * 处理左击事件 - */ - private void doWithLeftButtonPressed(MouseEvent evt) { - if(BaseUtils.isAuthorityEditing()){ - grid.setEditable(false); - } - - ElementCasePane reportPane = grid.getElementCasePane(); - TemplateElementCase report = reportPane.getEditingElementCase(); - boolean isShiftDown = evt.isShiftDown(); - boolean isControlDown = evt.isControlDown(); - int clickCount = evt.getClickCount(); - // peter:需要判断是否在可移动CellSelection的区域 - grid.setDragType(isMoveCellSelection(this.oldEvtX, this.oldEvtY)); - if (clickCount >= 2) { - grid.setDragType(GridUtils.DRAG_NONE); - } - if (grid.getDragType() != GridUtils.DRAG_NONE) {// Drag的标志. - Selection selection = reportPane.getSelection(); - if (selection instanceof CellSelection) { - // peter:设置DragRecatagle的标志. - if (grid.getDragRectangle() == null) { - grid.setDragRectangle(new Rectangle()); - } - CellSelection cs = ((CellSelection) selection).clone(); - grid.getDragRectangle().setBounds(cs.toRectangle()); - return; - } - } - // peter:选择GridSelection,支持Shift - doOneClickSelection(this.oldEvtX, this.oldEvtY, isShiftDown, isControlDown); - // 得到点击所在的column and row - ColumnRow columnRow = GridUtils.getEventColumnRow(reportPane, this.oldEvtX, this.oldEvtY); - TemplateCellElement cellElement = report.getTemplateCellElement(columnRow.getColumn(), columnRow.getRow()); - if (clickCount >= 2 && !BaseUtils.isAuthorityEditing()) { - grid.startEditing(); - } - if (clickCount == 1 && cellElement != null && cellElement.getWidget() != null && !BaseUtils.isAuthorityEditing()) { - showWidetWindow(cellElement, report); - } - reportPane.repaint(); - } - - /** - * 显示控件编辑窗口 - * - * @param cellElement - * @param report - */ - - private void showWidetWindow(TemplateCellElement cellElement, TemplateElementCase report) { - int resolution = ScreenResolution.getScreenResolution(); - DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); - DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); - double fixed_pos_x = this.oldEvtX - columnWidthList.getRangeValue(grid.getHorizontalValue(), cellElement.getColumn()).toPixD(resolution); - double fixed_pos_y = this.oldEvtY - rowHeightList.getRangeValue(grid.getVerticalValue(), cellElement.getRow()).toPixD(resolution); - double cell_width = columnWidthList.getRangeValue(cellElement.getColumn(), cellElement.getColumn() + cellElement.getColumnSpan()).toPixD(resolution); - double cell_height = rowHeightList.getRangeValue(cellElement.getRow(), cellElement.getRow() + cellElement.getRowSpan()).toPixD(resolution); - if (fitSizeToShow(cell_width, cell_height, fixed_pos_x, fixed_pos_y)) { - CellWriteAttrPane.showWidgetWindow(grid.getElementCasePane()); - } - } - - private boolean fitSizeToShow(double cell_width, double cell_height, double fixed_pos_x, double fixed_pos_y) { - return cell_width - fixed_pos_x > 0 && cell_height - fixed_pos_y > 0 - && cell_width - fixed_pos_x < WIDGET_WIDTH && cell_height - fixed_pos_y < WIDGET_WIDTH; - } - - /** - * @param evt - */ - public void mouseReleased(MouseEvent evt) { - if (!grid.isEnabled() || !grid.isEditable()) { - return; - } - boolean isDataChanged = false; - ElementCasePane reportPane = grid.getElementCasePane(); - Selection selection = reportPane.getSelection(); - if (grid.getDrawingFloatElement() != null) { - if (grid.getDrawingFloatElement().getWidth().equal_zero() && grid.getDrawingFloatElement().getHeight().equal_zero()) { - grid.getDrawingFloatElement().setWidth(new OLDPIX(100)); - grid.getDrawingFloatElement().setHeight(new OLDPIX(100)); - } - grid.setDrawingFloatElement(null); - } else if (selection instanceof FloatSelection) { - grid.setCursor(Cursor.getDefaultCursor()); - } - if (grid.getDragType() == GridUtils.DRAG_CELLSELECTION) { - if (selection instanceof CellSelection) { - grid.getElementCasePane().cut(); - // mouse release的时候要判断下是否在reportPane范围内 - if (outOfBounds(evt, reportPane)) { - GridUtils.doSelectCell(reportPane, grid.getDragRectangle().x, grid.getDragRectangle().y); - } else { - mousePressed(evt); - } - grid.getElementCasePane().paste(); - isDataChanged = true; - } - } else if (grid.getDragType() == GridUtils.DRAG_CELLSELECTION_BOTTOMRIGHT_CORNER) { - if (selection instanceof CellSelection) { - CellSelection cs = (CellSelection) selection; - // august:智能拖拽扩展单元格值 - IntelliElements.iterating(reportPane, cs.toRectangle(), grid.getDragRectangle()); - if (grid.getDragRectangle() != null) { - reportPane.setSelection(new CellSelection(grid.getDragRectangle().x, grid.getDragRectangle().y, grid.getDragRectangle().width, grid.getDragRectangle().height)); - } - isDataChanged = true; - } - } else if (grid.getDragType() == GridUtils.DRAG_FLOAT) { - isDataChanged = true; - } - grid.setDragType(GridUtils.DRAG_NONE); - grid.setDragRectangle(null); - if (isDataChanged) { + private static final int WIDGET_WIDTH = 13; + private static final int TIME_DELAY = 100; + private static final int TOOLTIP_X = 30; + private static final int TOOLTIP_X_Y_FIX = 4; + private static final double COPY_CROSS_INNER_DISTANCE = 1.5; + private static final double COPY_CROSS_OUTER_DISTANCE = 2.5; + /** + * 拖拽时候刷新时间间隔 + */ + private static int DRAG_REFRESH_TIME = 10; + /** + * 对应的表格-Grid + */ + private Grid grid; + /** + * the Point(x,y) where the mouse pressed + */ + private int oldEvtX = 0; + private int oldEvtY = 0; + // the old location, used for Move float element. + private int oldLocationX; + private int oldLocationY; + private long lastMouseMoveTime = 0; // 最后的MouseMove时间. + // 保存各个悬浮元素到oldLocation距离 + private Map floatNamePointMap; + /** + * august:因为CellSelection里面没有记录的变量了,必须要有个变量来存按住shift键的位置之前的鼠标的位置 + * 用户可能一直按住shift键不放,所以按住shift键之前的鼠标位置是必须有的. + */ + private ColumnRow tempOldSelectedCell; + + private int ECBlockGap = 40; + + protected GridMouseAdapter(Grid grid) { + this.grid = grid; + } + + /** + * @param evt + */ + public void mousePressed(MouseEvent evt) { + if (!grid.isEnabled()) { + return; + } + oldEvtX = evt.getX(); + oldEvtY = evt.getY(); + grid.stopEditing(); + + if (!grid.hasFocus() && grid.isRequestFocusEnabled()) { + grid.requestFocus(); + } + + if (grid.getDrawingFloatElement() != null) { + doWithDrawingFloatElement(); + } else { + if (SwingUtilities.isRightMouseButton(evt)) { + doWithRightButtonPressed(); + } else { + doWithLeftButtonPressed(evt); + } + // 用户没有按住Shift键时,tempOldSelectedCell是一直变化的。如果一直按住shift,是不变的 + ElementCasePane ePane = grid.getElementCasePane(); + if (!evt.isShiftDown() && ePane.getSelection() instanceof CellSelection) { + tempOldSelectedCell = GridUtils.getAdjustEventColumnRow(ePane, oldEvtX, oldEvtY); + } + } + + } + + /** + * 将悬浮元素(只有文本和公式)添加到鼠标点击的位置 + */ + private void doWithDrawingFloatElement() { + ElementCasePane reportPane = grid.getElementCasePane(); + TemplateElementCase report = reportPane.getEditingElementCase(); + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + + int horizentalScrollValue = grid.getHorizontalValue(); + int verticalScrollValue = grid.getVerticalValue(); + int resolution = ScreenResolution.getScreenResolution(); + FU evtX_fu = FU.valueOfPix(this.oldEvtX, resolution); + FU evtY_fu = FU.valueOfPix(this.oldEvtY, resolution); + + FU leftDistance = FU.getInstance(evtX_fu.toFU() + columnWidthList.getRangeValue(0, horizentalScrollValue).toFU()); + FU topDistance = FU.getInstance(evtY_fu.toFU() + rowHeightList.getRangeValue(0, verticalScrollValue).toFU()); + + grid.getDrawingFloatElement().setLeftDistance(leftDistance); + grid.getDrawingFloatElement().setTopDistance(topDistance); + + report.addFloatElement(grid.getDrawingFloatElement()); + reportPane.setSelection(new FloatSelection(grid.getDrawingFloatElement().getName())); + } + + /** + * 处理右击事件,弹出右键菜单. + */ + private void doWithRightButtonPressed() { + ElementCasePane reportPane = grid.getElementCasePane(); + Object[] tmpFloatElementCursor = GridUtils.getAboveFloatElementCursor(reportPane, this.oldEvtX, this.oldEvtY); + if (!ArrayUtils.isEmpty(tmpFloatElementCursor)) { + FloatElement selectedFloatElement = (FloatElement) tmpFloatElementCursor[0]; + reportPane.setSelection(new FloatSelection(selectedFloatElement.getName())); + } else { + ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(reportPane, this.oldEvtX, this.oldEvtY); + if (!reportPane.getSelection().containsColumnRow(selectedCellPoint)) { + GridUtils.doSelectCell(reportPane, selectedCellPoint.getColumn(), selectedCellPoint.getRow()); + } + } + reportPane.repaint(); + JPopupMenu cellPopupMenu = reportPane.createPopupMenu(); + if (cellPopupMenu != null) { + GUICoreUtils.showPopupMenu(cellPopupMenu, this.grid, this.oldEvtX - 1, this.oldEvtY - 1); + } + } + + /** + * 处理左击事件 + */ + private void doWithLeftButtonPressed(MouseEvent evt) { + if (BaseUtils.isAuthorityEditing()) { + grid.setEditable(false); + } + + ElementCasePane reportPane = grid.getElementCasePane(); + TemplateElementCase report = reportPane.getEditingElementCase(); + boolean isShiftDown = evt.isShiftDown(); + boolean isControlDown = InputEventBaseOnOS.isControlDown(evt); + int clickCount = evt.getClickCount(); + // peter:需要判断是否在可移动CellSelection的区域 + grid.setDragType(isMoveCellSelection(this.oldEvtX, this.oldEvtY)); + if (clickCount >= 2) { + grid.setDragType(GridUtils.DRAG_NONE); + } + if (grid.getDragType() != GridUtils.DRAG_NONE) {// Drag的标志. + Selection selection = reportPane.getSelection(); + if (selection instanceof CellSelection) { + // peter:设置DragRecatagle的标志. + if (grid.getDragRectangle() == null) { + grid.setDragRectangle(new Rectangle()); + } + CellSelection cs = ((CellSelection) selection).clone(); + grid.getDragRectangle().setBounds(cs.toRectangle()); + return; + } + } + // peter:选择GridSelection,支持Shift + doOneClickSelection(this.oldEvtX, this.oldEvtY, isShiftDown, isControlDown); + // 得到点击所在的column and row + ColumnRow columnRow = GridUtils.getEventColumnRow(reportPane, this.oldEvtX, this.oldEvtY); + TemplateCellElement cellElement = report.getTemplateCellElement(columnRow.getColumn(), columnRow.getRow()); + if (clickCount >= 2 && !BaseUtils.isAuthorityEditing()) { + grid.startEditing(); + } + if (clickCount == 1 && cellElement != null && cellElement.getWidget() != null && !BaseUtils.isAuthorityEditing()) { + showWidetWindow(cellElement, report); + } + reportPane.repaint(); + } + + /** + * 显示控件编辑窗口 + * + * @param cellElement + * @param report + */ + + private void showWidetWindow(TemplateCellElement cellElement, TemplateElementCase report) { + int resolution = ScreenResolution.getScreenResolution(); + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + double fixed_pos_x = this.oldEvtX - columnWidthList.getRangeValue(grid.getHorizontalValue(), cellElement.getColumn()).toPixD(resolution); + double fixed_pos_y = this.oldEvtY - rowHeightList.getRangeValue(grid.getVerticalValue(), cellElement.getRow()).toPixD(resolution); + double cell_width = columnWidthList.getRangeValue(cellElement.getColumn(), cellElement.getColumn() + cellElement.getColumnSpan()).toPixD(resolution); + double cell_height = rowHeightList.getRangeValue(cellElement.getRow(), cellElement.getRow() + cellElement.getRowSpan()).toPixD(resolution); + if (fitSizeToShow(cell_width, cell_height, fixed_pos_x, fixed_pos_y)) { + CellWriteAttrPane.showWidgetWindow(grid.getElementCasePane()); + } + } + + private boolean fitSizeToShow(double cell_width, double cell_height, double fixed_pos_x, double fixed_pos_y) { + return cell_width - fixed_pos_x > 0 && cell_height - fixed_pos_y > 0 + && cell_width - fixed_pos_x < WIDGET_WIDTH && cell_height - fixed_pos_y < WIDGET_WIDTH; + } + + /** + * @param evt + */ + public void mouseReleased(MouseEvent evt) { + if (!grid.isEnabled() || !grid.isEditable()) { + return; + } + boolean isDataChanged = false; + ElementCasePane reportPane = grid.getElementCasePane(); + Selection selection = reportPane.getSelection(); + if (grid.getDrawingFloatElement() != null) { + if (grid.getDrawingFloatElement().getWidth().equal_zero() && grid.getDrawingFloatElement().getHeight().equal_zero()) { + grid.getDrawingFloatElement().setWidth(new OLDPIX(100)); + grid.getDrawingFloatElement().setHeight(new OLDPIX(100)); + } + grid.setDrawingFloatElement(null); + } else if (selection instanceof FloatSelection) { + grid.setCursor(Cursor.getDefaultCursor()); + } + if (grid.getDragType() == GridUtils.DRAG_CELLSELECTION) { + if (selection instanceof CellSelection) { + grid.getElementCasePane().cut(); + // mouse release的时候要判断下是否在reportPane范围内 + if (outOfBounds(evt, reportPane)) { + GridUtils.doSelectCell(reportPane, grid.getDragRectangle().x, grid.getDragRectangle().y); + } else { + mousePressed(evt); + } + grid.getElementCasePane().paste(); + isDataChanged = true; + } + } else if (grid.getDragType() == GridUtils.DRAG_CELLSELECTION_BOTTOMRIGHT_CORNER) { + if (selection instanceof CellSelection) { + CellSelection cs = (CellSelection) selection; + // august:智能拖拽扩展单元格值 + IntelliElements.iterating(reportPane, cs.toRectangle(), grid.getDragRectangle()); + if (grid.getDragRectangle() != null) { + reportPane.setSelection(new CellSelection(grid.getDragRectangle().x, grid.getDragRectangle().y, grid.getDragRectangle().width, grid.getDragRectangle().height)); + } + isDataChanged = true; + } + } else if (grid.getDragType() == GridUtils.DRAG_FLOAT) { + isDataChanged = true; + } + grid.setDragType(GridUtils.DRAG_NONE); + grid.setDragRectangle(null); + if (isDataChanged) { reportPane.setSupportDefaultParentCalculate(true); - reportPane.fireTargetModified(); + reportPane.fireTargetModified(); reportPane.setSupportDefaultParentCalculate(false); - } - doWithFormatBrush(reportPane); - reportPane.repaint(); - } - - private void doWithFormatBrush(ElementCasePane reportPane) { - if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_NULL) { - return; - } - - if (reportPane.getCellNeedTOFormat() != null) { - reportPane.getFormatBrushAction().updateFormatBrush(DesignerContext.getReferencedStyle(), reportPane.getCellNeedTOFormat(), reportPane); - reportPane.fireTargetModified(); - - } - if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_ONCE) { - reportPane.cancelFormatBrush(); - } - if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_MORE) { - reportPane.getFormatBrush().setSelected(true); - } - } - - private boolean outOfBounds(MouseEvent evt, ElementCasePane reportPane) { - return evt.getY() > reportPane.getHeight() || evt.getY() < 0 || evt.getX() > reportPane.getWidth() || evt.getX() < 0; - } - - /** - * @param evt - */ - public void mouseMoved(final MouseEvent evt) { - ElementCasePane reportPane = grid.getElementCasePane(); - boolean isGridForSelection = !grid.isEnabled() || !grid.isEditable(); - if (isGridForSelection || grid.isEditing()) { - if (grid.IsNotShowingTableSelectPane()) { - grid.setCursor(UIConstants.CELL_DEFAULT_CURSOR); - return; - } - if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) { - grid.setCursor(UIConstants.FORMAT_BRUSH_CURSOR); - } else { - grid.setCursor(GUICoreUtils.createCustomCursor(BaseUtils.readImage("com/fr/design/images/buttonicon/select.png"), - new Point(0, 0), "select", grid)); - } - - return; - } - // peter:停留一段时间. - long systemCurrentTime = System.currentTimeMillis(); - if (systemCurrentTime - lastMouseMoveTime <= TIME_DELAY) { - return; - } - lastMouseMoveTime = systemCurrentTime;// 记录最后一次的时间. - mouseMoveOnGrid(evt.getX(), evt.getY()); - } - - /** - * @param evt - */ - public void mouseDragged(MouseEvent evt) { - if (!grid.isEnabled()) { - return; - } - - boolean isControlDown = evt.isControlDown(); - - long systemCurrentTime = System.currentTimeMillis(); - if (systemCurrentTime - lastMouseMoveTime <= DRAG_REFRESH_TIME) {// alex:Drag - return; - } else { - lastMouseMoveTime = systemCurrentTime; - } - - // right mouse cannot Drag.. - if (SwingUtilities.isRightMouseButton(evt)) { - return; - } - - doWithMouseDragged(evt.getX(), evt.getY(), isControlDown); - } - - private void doWithMouseDragged(int evtX, int evtY, boolean isControlDown) { - ElementCasePane reportPane = grid.getElementCasePane(); - - if (reportPane.mustInVisibleRange()) { - Grid grid = reportPane.getGrid(); - if (evtX > grid.getWidth() - 2 || evtY > grid.getHeight() - 2) { - return; - } - } - Selection selection = reportPane.getSelection(); - - if (selection instanceof FloatSelection && !BaseUtils.isAuthorityEditing()) { - doWithFloatElementDragged(evtX, evtY, (FloatSelection) selection); - grid.setDragType(GridUtils.DRAG_FLOAT); - } else if (grid.getDragType() == GridUtils.DRAG_CELLSELECTION_BOTTOMRIGHT_CORNER && !BaseUtils.isAuthorityEditing()) { - doWithCellElementDragged(evtX, evtY, (CellSelection) selection); - } else if (grid.getDragType() == GridUtils.DRAG_CELLSELECTION && !BaseUtils.isAuthorityEditing()) { - // peter:获得调整过的Selected Column Row. - ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(reportPane, evtX, evtY); - if (selectedCellPoint.getColumn() != grid.getDragRectangle().x || selectedCellPoint.getRow() != grid.getDragRectangle().y) { - grid.getDragRectangle().x = selectedCellPoint.getColumn(); - grid.getDragRectangle().y = selectedCellPoint.getRow(); - } - } else {// august: 拖拽选中多个单元格 - doShiftSelectCell(evtX, evtY); - } - grid.getElementCasePane().repaint(); - } - - /** - * 拖拽悬浮元素 - * - * @param evtX - * @param evtY - * @param fs - */ - - private void doWithFloatElementDragged(int evtX, int evtY, FloatSelection fs) { - ElementCase report = grid.getElementCasePane().getEditingElementCase(); - int resolution = ScreenResolution.getScreenResolution(); - String floatName = fs.getSelectedFloatName(); - FloatElement floatElement = report.getFloatElement(floatName); - int cursorType = grid.getCursor().getType(); - - if (cursorType == Cursor.NW_RESIZE_CURSOR || cursorType == Cursor.NE_RESIZE_CURSOR || cursorType == Cursor.SE_RESIZE_CURSOR || cursorType == Cursor.SW_RESIZE_CURSOR) { - DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); - DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); - FU floatX1_fu = FU.valueOfPix(Math.min(oldEvtX, evtX), resolution); - FU floatY1_fu = FU.valueOfPix(Math.min(oldEvtY, evtY), resolution); - FU leftDistance = floatX1_fu.add(columnWidthList.getRangeValue(0, grid.getHorizontalValue())); - FU topDistance = floatY1_fu.add(rowHeightList.getRangeValue(0, grid.getVerticalValue())); - floatElement.setLeftDistance(leftDistance); - floatElement.setTopDistance(topDistance); - floatElement.setWidth(FU.valueOfPix(Math.max(oldEvtX, evtX), resolution).subtract(floatX1_fu)); - floatElement.setHeight(FU.valueOfPix(Math.max(oldEvtY, evtY), resolution).subtract(floatY1_fu)); - } else if (cursorType == Cursor.S_RESIZE_CURSOR || cursorType == Cursor.N_RESIZE_CURSOR) { - DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); - FU floatY1_fu = FU.valueOfPix(Math.min(oldEvtY, evtY), resolution); - FU topDistance = floatY1_fu.add(rowHeightList.getRangeValue(0, grid.getVerticalValue())); - floatElement.setTopDistance(topDistance); - floatElement.setHeight(FU.valueOfPix(Math.max(oldEvtY, evtY), resolution).subtract(floatY1_fu)); - } else if (cursorType == Cursor.W_RESIZE_CURSOR || cursorType == Cursor.E_RESIZE_CURSOR) { - DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); - FU floatX1_fu = FU.valueOfPix(Math.min(oldEvtX, evtX), resolution); - FU leftDistance = floatX1_fu.add(columnWidthList.getRangeValue(0, grid.getHorizontalValue())); - floatElement.setLeftDistance(leftDistance); - floatElement.setWidth(FU.valueOfPix(Math.max(oldEvtX, evtX), resolution).subtract(floatX1_fu)); - } else if (cursorType == Cursor.MOVE_CURSOR) { - DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); - DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); - int horizentalValue = grid.getHorizontalValue(); - int verticalValue = grid.getVerticalValue(); - String floatElementName = fs.getSelectedFloatName(); - FloatElement tempFolatElement = report.getFloatElement(floatElementName); - Point tempFolatElementPoint = floatNamePointMap.get(floatElementName); - int floatX1ForTempFloatElement = tempFolatElementPoint.x + Math.max(oldLocationX + (evtX - oldEvtX), 0); - int floatY1ForTempFloatElement = tempFolatElementPoint.y + Math.max(oldLocationY + (evtY - oldEvtY), 0); - FU floatX1ForTempFloatElement_fu = FU.valueOfPix(floatX1ForTempFloatElement, resolution); - FU leftDistance = floatX1ForTempFloatElement_fu.add(columnWidthList.getRangeValue(0, horizentalValue)); - FU floatY1ForTempFloatElement_fu = FU.valueOfPix(floatY1ForTempFloatElement, resolution); - FU topDistance = floatY1ForTempFloatElement_fu.add(rowHeightList.getRangeValue(0, verticalValue)); - tempFolatElement.setLeftDistance(leftDistance); - tempFolatElement.setTopDistance(topDistance); - } - - } - - /** - * 拖拽单元格 - * - * @param evtX - * @param evtY - * @param cs - */ - - private void doWithCellElementDragged(int evtX, int evtY, CellSelection cs) { - ElementCasePane reportPane = grid.getElementCasePane(); - java.awt.Rectangle cellRectangle = cs.toRectangle(); - - ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(reportPane, evtX, evtY); - if (cellRectangle.contains(selectedCellPoint.getColumn(), selectedCellPoint.getRow())) { - grid.getDragRectangle().setBounds(cellRectangle); - } else { - int xDistance = evtX - this.oldEvtX; - int yDistance = evtY - this.oldEvtY; - if (Math.abs(yDistance) > Math.abs(xDistance)) { - grid.getDragRectangle().x = cellRectangle.x; - grid.getDragRectangle().width = cellRectangle.width; - if (yDistance >= 0) { - // 聚合报表要求拖拽的时候要在本块的内部进行 不能无限往下拖 - if (reportPane instanceof ECBlockPane && evtY > reportPane.getBounds().height - ECBlockGap) { - return; - } - grid.getDragRectangle().y = cellRectangle.y; - grid.getDragRectangle().height = selectedCellPoint.getRow() - cellRectangle.y + 1; - } else { - if (selectedCellPoint.getRow() >= cellRectangle.y && selectedCellPoint.getRow() < cellRectangle.y + cellRectangle.height) { - grid.getDragRectangle().y = cellRectangle.y; - grid.getDragRectangle().height = cellRectangle.height; - } else { - grid.getDragRectangle().y = cellRectangle.y; - grid.getDragRectangle().height = cellRectangle.y - selectedCellPoint.getRow() + cellRectangle.height; - } - } - } else { - grid.getDragRectangle().y = cellRectangle.y; - grid.getDragRectangle().height = cellRectangle.height; - if (xDistance >= 0) { - if (reportPane instanceof ECBlockPane && evtX > reportPane.getBounds().width - ECBlockGap) { - return; - } - grid.getDragRectangle().x = cellRectangle.x; - grid.getDragRectangle().width = selectedCellPoint.getColumn() - cellRectangle.x + 1; - } else { - if (selectedCellPoint.getColumn() >= cellRectangle.x && selectedCellPoint.getColumn() < cellRectangle.x + cellRectangle.width) { - grid.getDragRectangle().x = cellRectangle.x; - grid.getDragRectangle().width = cellRectangle.width; - } else { - grid.getDragRectangle().x = selectedCellPoint.getColumn(); - grid.getDragRectangle().width = cellRectangle.x - selectedCellPoint.getColumn() + cellRectangle.width; - } - } - } - } - reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn() + 1, selectedCellPoint.getRow() + 1); - } - - private void doShiftSelectCell(double evtX, double evtY) { - ElementCasePane reportPane = grid.getElementCasePane(); - Selection s = reportPane.getSelection(); - if (s instanceof FloatSelection) { - return; - } - ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(reportPane, evtX, evtY); - int selectedCellPointX = selectedCellPoint.getColumn(); - int selectedCellPointY = selectedCellPoint.getRow(); - CellSelection gridSelection = ((CellSelection) s).clone(); - //反向选择单元格 - int tempOldSelectedCellX = tempOldSelectedCell.getColumn(); - int tempOldSelectedCellY = tempOldSelectedCell.getRow(); + } + doWithFormatBrush(reportPane); + reportPane.repaint(); + } + + private void doWithFormatBrush(ElementCasePane reportPane) { + if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_NULL) { + return; + } + + if (reportPane.getCellNeedTOFormat() != null) { + reportPane.getFormatBrushAction().updateFormatBrush(DesignerContext.getReferencedStyle(), reportPane.getCellNeedTOFormat(), reportPane); + reportPane.fireTargetModified(); + + } + if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_ONCE) { + reportPane.cancelFormatBrush(); + } + if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_MORE) { + reportPane.getFormatBrush().setSelected(true); + } + } + + private boolean outOfBounds(MouseEvent evt, ElementCasePane reportPane) { + return evt.getY() > reportPane.getHeight() || evt.getY() < 0 || evt.getX() > reportPane.getWidth() || evt.getX() < 0; + } + + /** + * @param evt + */ + public void mouseMoved(final MouseEvent evt) { + ElementCasePane reportPane = grid.getElementCasePane(); + boolean isGridForSelection = !grid.isEnabled() || !grid.isEditable(); + if (isGridForSelection || grid.isEditing()) { + if (grid.IsNotShowingTableSelectPane()) { + grid.setCursor(UIConstants.CELL_DEFAULT_CURSOR); + return; + } + if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) { + grid.setCursor(UIConstants.FORMAT_BRUSH_CURSOR); + } else { + grid.setCursor(GUICoreUtils.createCustomCursor(BaseUtils.readImage("com/fr/design/images/buttonicon/select.png"), + new Point(0, 0), "select", grid)); + } + + return; + } + // peter:停留一段时间. + long systemCurrentTime = System.currentTimeMillis(); + if (systemCurrentTime - lastMouseMoveTime <= TIME_DELAY) { + return; + } + lastMouseMoveTime = systemCurrentTime;// 记录最后一次的时间. + mouseMoveOnGrid(evt.getX(), evt.getY()); + } + + /** + * @param evt + */ + public void mouseDragged(MouseEvent evt) { + if (!grid.isEnabled()) { + return; + } + + boolean isControlDown = InputEventBaseOnOS.isControlDown(evt); + + long systemCurrentTime = System.currentTimeMillis(); + if (systemCurrentTime - lastMouseMoveTime <= DRAG_REFRESH_TIME) {// alex:Drag + return; + } else { + lastMouseMoveTime = systemCurrentTime; + } + + // right mouse cannot Drag.. + if (SwingUtilities.isRightMouseButton(evt)) { + return; + } + + doWithMouseDragged(evt.getX(), evt.getY(), isControlDown); + } + + private void doWithMouseDragged(int evtX, int evtY, boolean isControlDown) { + ElementCasePane reportPane = grid.getElementCasePane(); + + if (reportPane.mustInVisibleRange()) { + Grid grid = reportPane.getGrid(); + if (evtX > grid.getWidth() - 2 || evtY > grid.getHeight() - 2) { + return; + } + } + Selection selection = reportPane.getSelection(); + + if (selection instanceof FloatSelection && !BaseUtils.isAuthorityEditing()) { + doWithFloatElementDragged(evtX, evtY, (FloatSelection) selection); + grid.setDragType(GridUtils.DRAG_FLOAT); + } else if (grid.getDragType() == GridUtils.DRAG_CELLSELECTION_BOTTOMRIGHT_CORNER && !BaseUtils.isAuthorityEditing()) { + doWithCellElementDragged(evtX, evtY, (CellSelection) selection); + } else if (grid.getDragType() == GridUtils.DRAG_CELLSELECTION && !BaseUtils.isAuthorityEditing()) { + // peter:获得调整过的Selected Column Row. + ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(reportPane, evtX, evtY); + if (selectedCellPoint.getColumn() != grid.getDragRectangle().x || selectedCellPoint.getRow() != grid.getDragRectangle().y) { + grid.getDragRectangle().x = selectedCellPoint.getColumn(); + grid.getDragRectangle().y = selectedCellPoint.getRow(); + } + } else {// august: 拖拽选中多个单元格 + doShiftSelectCell(evtX, evtY); + } + grid.getElementCasePane().repaint(); + } + + /** + * 拖拽悬浮元素 + * + * @param evtX + * @param evtY + * @param fs + */ + + private void doWithFloatElementDragged(int evtX, int evtY, FloatSelection fs) { + ElementCase report = grid.getElementCasePane().getEditingElementCase(); + int resolution = ScreenResolution.getScreenResolution(); + String floatName = fs.getSelectedFloatName(); + FloatElement floatElement = report.getFloatElement(floatName); + int cursorType = grid.getCursor().getType(); + + if (cursorType == Cursor.NW_RESIZE_CURSOR || cursorType == Cursor.NE_RESIZE_CURSOR || cursorType == Cursor.SE_RESIZE_CURSOR || cursorType == Cursor.SW_RESIZE_CURSOR) { + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + FU floatX1_fu = FU.valueOfPix(Math.min(oldEvtX, evtX), resolution); + FU floatY1_fu = FU.valueOfPix(Math.min(oldEvtY, evtY), resolution); + FU leftDistance = floatX1_fu.add(columnWidthList.getRangeValue(0, grid.getHorizontalValue())); + FU topDistance = floatY1_fu.add(rowHeightList.getRangeValue(0, grid.getVerticalValue())); + floatElement.setLeftDistance(leftDistance); + floatElement.setTopDistance(topDistance); + floatElement.setWidth(FU.valueOfPix(Math.max(oldEvtX, evtX), resolution).subtract(floatX1_fu)); + floatElement.setHeight(FU.valueOfPix(Math.max(oldEvtY, evtY), resolution).subtract(floatY1_fu)); + } else if (cursorType == Cursor.S_RESIZE_CURSOR || cursorType == Cursor.N_RESIZE_CURSOR) { + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + FU floatY1_fu = FU.valueOfPix(Math.min(oldEvtY, evtY), resolution); + FU topDistance = floatY1_fu.add(rowHeightList.getRangeValue(0, grid.getVerticalValue())); + floatElement.setTopDistance(topDistance); + floatElement.setHeight(FU.valueOfPix(Math.max(oldEvtY, evtY), resolution).subtract(floatY1_fu)); + } else if (cursorType == Cursor.W_RESIZE_CURSOR || cursorType == Cursor.E_RESIZE_CURSOR) { + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + FU floatX1_fu = FU.valueOfPix(Math.min(oldEvtX, evtX), resolution); + FU leftDistance = floatX1_fu.add(columnWidthList.getRangeValue(0, grid.getHorizontalValue())); + floatElement.setLeftDistance(leftDistance); + floatElement.setWidth(FU.valueOfPix(Math.max(oldEvtX, evtX), resolution).subtract(floatX1_fu)); + } else if (cursorType == Cursor.MOVE_CURSOR) { + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + int horizentalValue = grid.getHorizontalValue(); + int verticalValue = grid.getVerticalValue(); + String floatElementName = fs.getSelectedFloatName(); + FloatElement tempFolatElement = report.getFloatElement(floatElementName); + Point tempFolatElementPoint = floatNamePointMap.get(floatElementName); + int floatX1ForTempFloatElement = tempFolatElementPoint.x + Math.max(oldLocationX + (evtX - oldEvtX), 0); + int floatY1ForTempFloatElement = tempFolatElementPoint.y + Math.max(oldLocationY + (evtY - oldEvtY), 0); + FU floatX1ForTempFloatElement_fu = FU.valueOfPix(floatX1ForTempFloatElement, resolution); + FU leftDistance = floatX1ForTempFloatElement_fu.add(columnWidthList.getRangeValue(0, horizentalValue)); + FU floatY1ForTempFloatElement_fu = FU.valueOfPix(floatY1ForTempFloatElement, resolution); + FU topDistance = floatY1ForTempFloatElement_fu.add(rowHeightList.getRangeValue(0, verticalValue)); + tempFolatElement.setLeftDistance(leftDistance); + tempFolatElement.setTopDistance(topDistance); + } + + } + + /** + * 拖拽单元格 + * + * @param evtX + * @param evtY + * @param cs + */ + + private void doWithCellElementDragged(int evtX, int evtY, CellSelection cs) { + ElementCasePane reportPane = grid.getElementCasePane(); + java.awt.Rectangle cellRectangle = cs.toRectangle(); + + ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(reportPane, evtX, evtY); + if (cellRectangle.contains(selectedCellPoint.getColumn(), selectedCellPoint.getRow())) { + grid.getDragRectangle().setBounds(cellRectangle); + } else { + int xDistance = evtX - this.oldEvtX; + int yDistance = evtY - this.oldEvtY; + if (Math.abs(yDistance) > Math.abs(xDistance)) { + grid.getDragRectangle().x = cellRectangle.x; + grid.getDragRectangle().width = cellRectangle.width; + if (yDistance >= 0) { + // 聚合报表要求拖拽的时候要在本块的内部进行 不能无限往下拖 + if (reportPane instanceof ECBlockPane && evtY > reportPane.getBounds().height - ECBlockGap) { + return; + } + grid.getDragRectangle().y = cellRectangle.y; + grid.getDragRectangle().height = selectedCellPoint.getRow() - cellRectangle.y + 1; + } else { + if (selectedCellPoint.getRow() >= cellRectangle.y && selectedCellPoint.getRow() < cellRectangle.y + cellRectangle.height) { + grid.getDragRectangle().y = cellRectangle.y; + grid.getDragRectangle().height = cellRectangle.height; + } else { + grid.getDragRectangle().y = cellRectangle.y; + grid.getDragRectangle().height = cellRectangle.y - selectedCellPoint.getRow() + cellRectangle.height; + } + } + } else { + grid.getDragRectangle().y = cellRectangle.y; + grid.getDragRectangle().height = cellRectangle.height; + if (xDistance >= 0) { + if (reportPane instanceof ECBlockPane && evtX > reportPane.getBounds().width - ECBlockGap) { + return; + } + grid.getDragRectangle().x = cellRectangle.x; + grid.getDragRectangle().width = selectedCellPoint.getColumn() - cellRectangle.x + 1; + } else { + if (selectedCellPoint.getColumn() >= cellRectangle.x && selectedCellPoint.getColumn() < cellRectangle.x + cellRectangle.width) { + grid.getDragRectangle().x = cellRectangle.x; + grid.getDragRectangle().width = cellRectangle.width; + } else { + grid.getDragRectangle().x = selectedCellPoint.getColumn(); + grid.getDragRectangle().width = cellRectangle.x - selectedCellPoint.getColumn() + cellRectangle.width; + } + } + } + } + reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn() + 1, selectedCellPoint.getRow() + 1); + } + + private void doShiftSelectCell(double evtX, double evtY) { + ElementCasePane reportPane = grid.getElementCasePane(); + Selection s = reportPane.getSelection(); + if (s instanceof FloatSelection) { + return; + } + ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(reportPane, evtX, evtY); + int selectedCellPointX = selectedCellPoint.getColumn(); + int selectedCellPointY = selectedCellPoint.getRow(); + CellSelection gridSelection = ((CellSelection) s).clone(); + //反向选择单元格 + int tempOldSelectedCellX = tempOldSelectedCell.getColumn(); + int tempOldSelectedCellY = tempOldSelectedCell.getRow(); // int tempOldSelectedCellX = gridSelection.getEditRectangle().x; // int tempOldSelectedCellY = gridSelection.getEditRectangle().y; - int column = selectedCellPointX >= tempOldSelectedCellX ? tempOldSelectedCellX : selectedCellPointX; - int row = selectedCellPointY >= tempOldSelectedCellY ? tempOldSelectedCellY : selectedCellPointY; - int columnSpan = Math.abs(selectedCellPointX - tempOldSelectedCellX) + 1; - int rowSpan = Math.abs(selectedCellPointY - tempOldSelectedCellY) + 1; - Rectangle oldrectangle = new Rectangle(column, row, columnSpan, rowSpan); - // ajust them to got the correct selected bounds. - Rectangle newrectangle = grid.caculateIntersectsUnion(reportPane.getEditingElementCase(), oldrectangle); - gridSelection.setBounds(newrectangle.x, newrectangle.y, newrectangle.width, newrectangle.height); - gridSelection.clearCellRectangles(gridSelection.getCellRectangleCount() - 1); - gridSelection.addCellRectangle(newrectangle); - reportPane.setSelection(gridSelection); - if (!reportPane.mustInVisibleRange()) { - reportPane.ensureColumnRowVisible(selectedCellPointX, selectedCellPointY); - } - } - - - private void doControlSelectCell(double evtX, double evtY) { - ElementCasePane reportPane = grid.getElementCasePane(); - ElementCase report = reportPane.getEditingElementCase(); - //上一次选中的单元格 - Selection s = reportPane.getSelection(); - if (s instanceof FloatSelection) { - return; - } - - ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(reportPane, evtX, evtY); - //拷贝,而不是直接强制使用以监听单元格选择变化 - CellSelection gridSelection = ((CellSelection) s).clone(); - gridSelection.setSelectedType(((CellSelection) s).getSelectedType()); - CellElement cellElement = report.getCellElement(selectedCellPoint.getColumn(), selectedCellPoint.getRow()); - if (cellElement == null) { - gridSelection.setBounds(selectedCellPoint.getColumn(), selectedCellPoint.getRow(), 1, 1); - int point = gridSelection.containsCell(selectedCellPoint.getColumn(), selectedCellPoint.getRow()); - if (point == -1) { - gridSelection.addCellRectangle(new Rectangle(selectedCellPoint.getColumn(), selectedCellPoint.getRow(), 1, 1)); - } else { - gridSelection.clearCellRectangles(point); - } - - } else { - gridSelection.setBounds(cellElement.getColumn(), cellElement.getRow(), cellElement.getColumnSpan(), cellElement.getRowSpan()); - gridSelection.addCellRectangle(new Rectangle(cellElement.getColumn(), cellElement.getRow(), cellElement.getColumnSpan(), cellElement.getRowSpan())); - - - } - - reportPane.setSelection(gridSelection); - - if (!reportPane.mustInVisibleRange()) { - reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn(), selectedCellPoint.getRow()); - } - - - } - - - /** - * 鼠标在Grid上面移动. - */ - private void mouseMoveOnGrid(int evtX, int evtY) { - grid.setToolTipText(null); - if (grid.getDrawingFloatElement() != null) { - grid.setCursor(UIConstants.DRAW_CURSOR); // august:是否是将要画悬浮元素,就是那个笔的形状 - } else { - Object[] floatElementCursor = GridUtils.getAboveFloatElementCursor(grid.getElementCasePane(), evtX, evtY); - if (!ArrayUtils.isEmpty(floatElementCursor)) {// 鼠标在悬浮元素上移动 - grid.setCursor((Cursor) floatElementCursor[1]); - } else {// 鼠标在单元格上移动 - doMouseMoveOnCells(evtX, evtY); - } - } - } - - /** - * 鼠标在单元格上移动 - * - * @param evtX - * @param evtY - */ - private void doMouseMoveOnCells(int evtX, int evtY) { - ElementCasePane reportPane = grid.getElementCasePane(); - TemplateElementCase report = reportPane.getEditingElementCase(); - //如果是格式刷状态 - if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) { - grid.setCursor(UIConstants.FORMAT_BRUSH_CURSOR); - } else { - grid.setCursor(UIConstants.CELL_DEFAULT_CURSOR); - } - ColumnRow selectedCellColumnRow = GridUtils.getEventColumnRow(reportPane, evtX, evtY); - TemplateCellElement curCellElement = report.getTemplateCellElement(selectedCellColumnRow.getColumn(), selectedCellColumnRow.getRow()); - - if (curCellElement != null) { - setCursorAndToolTips(curCellElement, report); - } - - int dragType = isMoveCellSelection(evtX, evtY); - if (dragType == GridUtils.DRAG_CELLSELECTION) {// 判断是否移动选中的区域. - grid.setCursor(new Cursor(Cursor.MOVE_CURSOR)); - } // peter:判断是否复制移动的角落. - else if (dragType == GridUtils.DRAG_CELLSELECTION_BOTTOMRIGHT_CORNER) { - grid.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); - } - - } - - /** - * 只根据CellGUIAttr里面的tooltips显示了,原先的显示条件属性、形态、控件等无意义 - * - * @param curCellElement - * @param report - */ - private void setCursorAndToolTips(TemplateCellElement curCellElement, TemplateElementCase report) { - int resolution = ScreenResolution.getScreenResolution(); - // 计算相对Grid的显示位置. - DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); - DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); - - CellGUIAttr cellGUIAttr = curCellElement.getCellGUIAttr(); - if (cellGUIAttr == null) { - cellGUIAttr = CellGUIAttr.DEFAULT_CELLGUIATTR; - } - grid.setToolTipText(cellGUIAttr.getTooltipText()); - double tooltipX = columnWidthList.getRangeValue(grid.getHorizontalValue(), curCellElement.getColumn()).toPixD(resolution) + TOOLTIP_X_Y_FIX; - double tooltipY = rowHeightList.getRangeValue(grid.getVerticalValue(), curCellElement.getRow() + curCellElement.getRowSpan()).toPixD(resolution) + TOOLTIP_X_Y_FIX; - - // peter:显示tooltip - if (StringUtils.isNotBlank(grid.getToolTipText())) { - grid.setTooltipLocation(tooltipX + TOOLTIP_X, tooltipY); - } - } - - /** - * 是否移动CellSelection - */ - private int isMoveCellSelection(double evtX, double evtY) { - ElementCasePane reportPane = grid.getElementCasePane(); - - // p:判断是否在选中区域的边框,可以移动CellSelelction选中区域 - Selection selection = reportPane.getSelection(); - if (!(selection instanceof CellSelection)) { - return GridUtils.DRAG_NONE; - } - - if ((selection instanceof CellSelection) - && ((CellSelection) selection).getCellRectangleCount() != 1) {// p:没有选择Cell. - return GridUtils.DRAG_NONE; - } - - CellSelection cs = (CellSelection) selection; - - ElementCase report = reportPane.getEditingElementCase(); - - // peter:计算相对Grid的显示位置. - DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); - DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); - - int resolution = ScreenResolution.getScreenResolution(); - - double leftColDistance = columnWidthList.getRangeValue(grid.getHorizontalValue(), cs.getColumn()).toPixD(resolution); - double rightColDistance = columnWidthList.getRangeValue(grid.getHorizontalValue(), cs.getColumn() + cs.getColumnSpan()).toPixD(resolution); - double topRowDistance = rowHeightList.getRangeValue(grid.getVerticalValue(), cs.getRow()).toPixD(resolution); - double bottomRowDistance = rowHeightList.getRangeValue(grid.getVerticalValue(), cs.getRow() + cs.getRowSpan()).toPixD(resolution); - - // 首先判断是否在可以复制的右下角落. - if (fitCellSelectionBottomRight(evtX, evtY, rightColDistance, bottomRowDistance)) { - return GridUtils.DRAG_CELLSELECTION_BOTTOMRIGHT_CORNER; - } - - // 这个dist值调小一点,尽量让用户不使用drag and drop 来编辑报表支持 - double dist = 1.0; - if (fitCellSelection(evtX, leftColDistance, rightColDistance, dist)) { - if (evtY >= (topRowDistance - dist) && evtY <= (bottomRowDistance + dist)) { - return GridUtils.DRAG_CELLSELECTION; - } - } else if (fitCellSelection(evtY, topRowDistance, bottomRowDistance, dist)) { - if (evtX >= (leftColDistance - dist) && evtX <= (rightColDistance + dist)) { - return GridUtils.DRAG_CELLSELECTION; - } - } - - return GridUtils.DRAG_NONE; - } - - private boolean fitCellSelection(double evt, double d1, double d2, double dist) { - return (evt >= (d1 - dist) && evt <= (d1 + dist)) - || (evt >= (d2 - dist) && evt <= (d2 + dist)); - } - - private boolean fitCellSelectionBottomRight(double evtX, double evtY, double rightColDistance, double bottomRowDistance) { - return evtX > rightColDistance - COPY_CROSS_INNER_DISTANCE && evtX < rightColDistance + COPY_CROSS_OUTER_DISTANCE - && evtY > bottomRowDistance - COPY_CROSS_INNER_DISTANCE && bottomRowDistance < bottomRowDistance + COPY_CROSS_OUTER_DISTANCE; - } - - /** - * Do one click selection - */ - private void doOneClickSelection(int evtX, int evtY, boolean isShiftDown, boolean isControlDown) { - ElementCasePane reportPane = grid.getElementCasePane(); - // check float elements. - Object[] tmpFloatElementCursor = GridUtils.getAboveFloatElementCursor(reportPane, evtX, evtY); - if (!ArrayUtils.isEmpty(tmpFloatElementCursor)) {// p:选中了悬浮元素. - doSelectFloatElement(tmpFloatElementCursor, evtX, evtY); - } else if (isShiftDown) { - doShiftSelectCell(evtX, evtY); - } else if (isControlDown) { - doControlSelectCell(evtX, evtY); - } else { - ColumnRow selectedCellPoint = GridUtils.getEventColumnRow(reportPane, evtX, evtY); - int type = reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn(), selectedCellPoint.getRow()); - if (type == ElementCasePane.NO_OVER) { - GridUtils.doSelectCell(reportPane, selectedCellPoint.getColumn(), selectedCellPoint.getRow()); - } else if (type == ElementCasePane.VERTICAL_OVER) { - //聚合报表块选在下边界的时候,有时会向下移,阻止向下移 - GridUtils.doSelectCell(reportPane, selectedCellPoint.getColumn(), selectedCellPoint.getRow() - 1); - } else if (type == ElementCasePane.HORIZONTAL_OVER) { - //聚合报表块选在右边界的时候,有时会向右移,阻止向右移 - GridUtils.doSelectCell(reportPane, selectedCellPoint.getColumn() - 1, selectedCellPoint.getRow()); - } else { - GridUtils.doSelectCell(reportPane, selectedCellPoint.getColumn() - 1, selectedCellPoint.getRow() - 1); - } - - return; - } - - } - - /** - * 选中悬浮元素 - * - * @param tmpFloatElementCursor - * @param evtX - * @param evtY - */ - - private void doSelectFloatElement(Object[] tmpFloatElementCursor, int evtX, int evtY) { - ElementCasePane reportPane = grid.getElementCasePane(); - ElementCase report = reportPane.getEditingElementCase(); - FloatElement floatElement = (FloatElement) tmpFloatElementCursor[0]; - String floatName = floatElement.getName(); - reportPane.setSelection(new FloatSelection(floatName)); - double[] floatArray = GridUtils.caculateFloatElementLocations(floatElement, ReportHelper.getColumnWidthList(report), ReportHelper.getRowHeightList(report), reportPane - .getGrid().getVerticalValue(), reportPane.getGrid().getHorizontalValue()); - - int cursorType = ((Cursor) tmpFloatElementCursor[1]).getType(); - if (cursorType == Cursor.MOVE_CURSOR) { - this.oldEvtX = evtX; - this.oldEvtY = evtY; - FloatElement el = report.getFloatElement(floatName); - int resolution = ScreenResolution.getScreenResolution(); - int verticalValue = grid.getVerticalValue(); - int horizentalValue = grid.getHorizontalValue(); - DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); - DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); - this.oldLocationX = FU.getInstance(el.getLeftDistance().toFU() - columnWidthList.getRangeValue(0, horizentalValue).toFU()).toPixI(resolution); - this.oldLocationY = FU.getInstance(el.getTopDistance().toFU() - rowHeightList.getRangeValue(0, verticalValue).toFU()).toPixI(resolution); - if (floatNamePointMap == null) { - floatNamePointMap = new HashMap(); - } - floatNamePointMap.clear(); - FloatElement tempFolatElement = report.getFloatElement(floatName); - int floatX1ForTempFloatElement = FU.getInstance(tempFolatElement.getLeftDistance().toFU() - columnWidthList.getRangeValue(0, horizentalValue).toFU()) - .toPixI(resolution) - oldLocationX; - int floatY1ForTempFloatElement = FU.getInstance(tempFolatElement.getTopDistance().toFU() - rowHeightList.getRangeValue(0, verticalValue).toFU()).toPixI(resolution) - - oldLocationY; - floatNamePointMap.put(floatName, new Point(floatX1ForTempFloatElement, floatY1ForTempFloatElement)); - } else if (cursorType == Cursor.NW_RESIZE_CURSOR) { - setOld_X_AndOld_Y(floatArray[2], floatArray[3]); - } else if (cursorType == Cursor.NE_RESIZE_CURSOR) { - setOld_X_AndOld_Y(floatArray[0], floatArray[3]); - } else if (cursorType == Cursor.SE_RESIZE_CURSOR) { - setOld_X_AndOld_Y(floatArray[0], floatArray[1]); - } else if (cursorType == Cursor.SW_RESIZE_CURSOR) { - setOld_X_AndOld_Y(floatArray[2], floatArray[1]); - } else if (cursorType == Cursor.N_RESIZE_CURSOR) { - setOld_X_AndOld_Y(floatArray[0], floatArray[3]); - } else if (cursorType == Cursor.S_RESIZE_CURSOR) { - setOld_X_AndOld_Y(floatArray[0], floatArray[1]); - } else if (cursorType == Cursor.W_RESIZE_CURSOR) { - setOld_X_AndOld_Y(floatArray[2], floatArray[1]); - } else if (cursorType == Cursor.E_RESIZE_CURSOR) { - setOld_X_AndOld_Y(floatArray[0], floatArray[1]); - } - } - - private void setOld_X_AndOld_Y(double x, double y) { - this.oldEvtX = (int) x; - this.oldEvtY = (int) y; - } - - /** - * @param e - */ - public void mouseWheelMoved(MouseWheelEvent e) { - ElementCasePane reportPane = grid.getElementCasePane(); - if (reportPane.isHorizontalScrollBarVisible()) { - reportPane.getVerticalScrollBar().setValue(reportPane.getVerticalScrollBar().getValue() + e.getWheelRotation() * 3); - } - } - - /** - * @param e - */ - public void mouseClicked(MouseEvent e) { - } - - /** - * @param e - */ - public void mouseEntered(MouseEvent e) { - } - - /** - * @param e - */ - public void mouseExited(MouseEvent e) { - } + int column = selectedCellPointX >= tempOldSelectedCellX ? tempOldSelectedCellX : selectedCellPointX; + int row = selectedCellPointY >= tempOldSelectedCellY ? tempOldSelectedCellY : selectedCellPointY; + int columnSpan = Math.abs(selectedCellPointX - tempOldSelectedCellX) + 1; + int rowSpan = Math.abs(selectedCellPointY - tempOldSelectedCellY) + 1; + Rectangle oldrectangle = new Rectangle(column, row, columnSpan, rowSpan); + // ajust them to got the correct selected bounds. + Rectangle newrectangle = grid.caculateIntersectsUnion(reportPane.getEditingElementCase(), oldrectangle); + gridSelection.setBounds(newrectangle.x, newrectangle.y, newrectangle.width, newrectangle.height); + gridSelection.clearCellRectangles(gridSelection.getCellRectangleCount() - 1); + gridSelection.addCellRectangle(newrectangle); + reportPane.setSelection(gridSelection); + if (!reportPane.mustInVisibleRange()) { + reportPane.ensureColumnRowVisible(selectedCellPointX, selectedCellPointY); + } + } + + + private void doControlSelectCell(double evtX, double evtY) { + ElementCasePane reportPane = grid.getElementCasePane(); + ElementCase report = reportPane.getEditingElementCase(); + //上一次选中的单元格 + Selection s = reportPane.getSelection(); + if (s instanceof FloatSelection) { + return; + } + + ColumnRow selectedCellPoint = GridUtils.getAdjustEventColumnRow(reportPane, evtX, evtY); + //拷贝,而不是直接强制使用以监听单元格选择变化 + CellSelection gridSelection = ((CellSelection) s).clone(); + gridSelection.setSelectedType(((CellSelection) s).getSelectedType()); + CellElement cellElement = report.getCellElement(selectedCellPoint.getColumn(), selectedCellPoint.getRow()); + if (cellElement == null) { + gridSelection.setBounds(selectedCellPoint.getColumn(), selectedCellPoint.getRow(), 1, 1); + int point = gridSelection.containsCell(selectedCellPoint.getColumn(), selectedCellPoint.getRow()); + if (point == -1) { + gridSelection.addCellRectangle(new Rectangle(selectedCellPoint.getColumn(), selectedCellPoint.getRow(), 1, 1)); + } else { + gridSelection.clearCellRectangles(point); + } + + } else { + gridSelection.setBounds(cellElement.getColumn(), cellElement.getRow(), cellElement.getColumnSpan(), cellElement.getRowSpan()); + gridSelection.addCellRectangle(new Rectangle(cellElement.getColumn(), cellElement.getRow(), cellElement.getColumnSpan(), cellElement.getRowSpan())); + + + } + + reportPane.setSelection(gridSelection); + + if (!reportPane.mustInVisibleRange()) { + reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn(), selectedCellPoint.getRow()); + } + + + } + + + /** + * 鼠标在Grid上面移动. + */ + private void mouseMoveOnGrid(int evtX, int evtY) { + grid.setToolTipText(null); + if (grid.getDrawingFloatElement() != null) { + grid.setCursor(UIConstants.DRAW_CURSOR); // august:是否是将要画悬浮元素,就是那个笔的形状 + } else { + Object[] floatElementCursor = GridUtils.getAboveFloatElementCursor(grid.getElementCasePane(), evtX, evtY); + if (!ArrayUtils.isEmpty(floatElementCursor)) {// 鼠标在悬浮元素上移动 + grid.setCursor((Cursor) floatElementCursor[1]); + } else {// 鼠标在单元格上移动 + doMouseMoveOnCells(evtX, evtY); + } + } + } + + /** + * 鼠标在单元格上移动 + * + * @param evtX + * @param evtY + */ + private void doMouseMoveOnCells(int evtX, int evtY) { + ElementCasePane reportPane = grid.getElementCasePane(); + TemplateElementCase report = reportPane.getEditingElementCase(); + //如果是格式刷状态 + if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) { + grid.setCursor(UIConstants.FORMAT_BRUSH_CURSOR); + } else { + grid.setCursor(UIConstants.CELL_DEFAULT_CURSOR); + } + ColumnRow selectedCellColumnRow = GridUtils.getEventColumnRow(reportPane, evtX, evtY); + TemplateCellElement curCellElement = report.getTemplateCellElement(selectedCellColumnRow.getColumn(), selectedCellColumnRow.getRow()); + + if (curCellElement != null) { + setCursorAndToolTips(curCellElement, report); + } + + int dragType = isMoveCellSelection(evtX, evtY); + if (dragType == GridUtils.DRAG_CELLSELECTION) {// 判断是否移动选中的区域. + grid.setCursor(new Cursor(Cursor.MOVE_CURSOR)); + } // peter:判断是否复制移动的角落. + else if (dragType == GridUtils.DRAG_CELLSELECTION_BOTTOMRIGHT_CORNER) { + grid.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); + } + + } + + /** + * 只根据CellGUIAttr里面的tooltips显示了,原先的显示条件属性、形态、控件等无意义 + * + * @param curCellElement + * @param report + */ + private void setCursorAndToolTips(TemplateCellElement curCellElement, TemplateElementCase report) { + int resolution = ScreenResolution.getScreenResolution(); + // 计算相对Grid的显示位置. + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + + CellGUIAttr cellGUIAttr = curCellElement.getCellGUIAttr(); + if (cellGUIAttr == null) { + cellGUIAttr = CellGUIAttr.DEFAULT_CELLGUIATTR; + } + grid.setToolTipText(cellGUIAttr.getTooltipText()); + double tooltipX = columnWidthList.getRangeValue(grid.getHorizontalValue(), curCellElement.getColumn()).toPixD(resolution) + TOOLTIP_X_Y_FIX; + double tooltipY = rowHeightList.getRangeValue(grid.getVerticalValue(), curCellElement.getRow() + curCellElement.getRowSpan()).toPixD(resolution) + TOOLTIP_X_Y_FIX; + + // peter:显示tooltip + if (StringUtils.isNotBlank(grid.getToolTipText())) { + grid.setTooltipLocation(tooltipX + TOOLTIP_X, tooltipY); + } + } + + /** + * 是否移动CellSelection + */ + private int isMoveCellSelection(double evtX, double evtY) { + ElementCasePane reportPane = grid.getElementCasePane(); + + // p:判断是否在选中区域的边框,可以移动CellSelelction选中区域 + Selection selection = reportPane.getSelection(); + if (!(selection instanceof CellSelection)) { + return GridUtils.DRAG_NONE; + } + + if ((selection instanceof CellSelection) + && ((CellSelection) selection).getCellRectangleCount() != 1) {// p:没有选择Cell. + return GridUtils.DRAG_NONE; + } + + CellSelection cs = (CellSelection) selection; + + ElementCase report = reportPane.getEditingElementCase(); + + // peter:计算相对Grid的显示位置. + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + + int resolution = ScreenResolution.getScreenResolution(); + + double leftColDistance = columnWidthList.getRangeValue(grid.getHorizontalValue(), cs.getColumn()).toPixD(resolution); + double rightColDistance = columnWidthList.getRangeValue(grid.getHorizontalValue(), cs.getColumn() + cs.getColumnSpan()).toPixD(resolution); + double topRowDistance = rowHeightList.getRangeValue(grid.getVerticalValue(), cs.getRow()).toPixD(resolution); + double bottomRowDistance = rowHeightList.getRangeValue(grid.getVerticalValue(), cs.getRow() + cs.getRowSpan()).toPixD(resolution); + + // 首先判断是否在可以复制的右下角落. + if (fitCellSelectionBottomRight(evtX, evtY, rightColDistance, bottomRowDistance)) { + return GridUtils.DRAG_CELLSELECTION_BOTTOMRIGHT_CORNER; + } + + // 这个dist值调小一点,尽量让用户不使用drag and drop 来编辑报表支持 + double dist = 1.0; + if (fitCellSelection(evtX, leftColDistance, rightColDistance, dist)) { + if (evtY >= (topRowDistance - dist) && evtY <= (bottomRowDistance + dist)) { + return GridUtils.DRAG_CELLSELECTION; + } + } else if (fitCellSelection(evtY, topRowDistance, bottomRowDistance, dist)) { + if (evtX >= (leftColDistance - dist) && evtX <= (rightColDistance + dist)) { + return GridUtils.DRAG_CELLSELECTION; + } + } + + return GridUtils.DRAG_NONE; + } + + private boolean fitCellSelection(double evt, double d1, double d2, double dist) { + return (evt >= (d1 - dist) && evt <= (d1 + dist)) + || (evt >= (d2 - dist) && evt <= (d2 + dist)); + } + + private boolean fitCellSelectionBottomRight(double evtX, double evtY, double rightColDistance, double bottomRowDistance) { + return evtX > rightColDistance - COPY_CROSS_INNER_DISTANCE && evtX < rightColDistance + COPY_CROSS_OUTER_DISTANCE + && evtY > bottomRowDistance - COPY_CROSS_INNER_DISTANCE && bottomRowDistance < bottomRowDistance + COPY_CROSS_OUTER_DISTANCE; + } + + /** + * Do one click selection + */ + private void doOneClickSelection(int evtX, int evtY, boolean isShiftDown, boolean isControlDown) { + ElementCasePane reportPane = grid.getElementCasePane(); + // check float elements. + Object[] tmpFloatElementCursor = GridUtils.getAboveFloatElementCursor(reportPane, evtX, evtY); + if (!ArrayUtils.isEmpty(tmpFloatElementCursor)) {// p:选中了悬浮元素. + doSelectFloatElement(tmpFloatElementCursor, evtX, evtY); + } else if (isShiftDown) { + doShiftSelectCell(evtX, evtY); + } else if (isControlDown) { + doControlSelectCell(evtX, evtY); + } else { + ColumnRow selectedCellPoint = GridUtils.getEventColumnRow(reportPane, evtX, evtY); + int type = reportPane.ensureColumnRowVisible(selectedCellPoint.getColumn(), selectedCellPoint.getRow()); + if (type == ElementCasePane.NO_OVER) { + GridUtils.doSelectCell(reportPane, selectedCellPoint.getColumn(), selectedCellPoint.getRow()); + } else if (type == ElementCasePane.VERTICAL_OVER) { + //聚合报表块选在下边界的时候,有时会向下移,阻止向下移 + GridUtils.doSelectCell(reportPane, selectedCellPoint.getColumn(), selectedCellPoint.getRow() - 1); + } else if (type == ElementCasePane.HORIZONTAL_OVER) { + //聚合报表块选在右边界的时候,有时会向右移,阻止向右移 + GridUtils.doSelectCell(reportPane, selectedCellPoint.getColumn() - 1, selectedCellPoint.getRow()); + } else { + GridUtils.doSelectCell(reportPane, selectedCellPoint.getColumn() - 1, selectedCellPoint.getRow() - 1); + } + + return; + } + + } + + /** + * 选中悬浮元素 + * + * @param tmpFloatElementCursor + * @param evtX + * @param evtY + */ + + private void doSelectFloatElement(Object[] tmpFloatElementCursor, int evtX, int evtY) { + ElementCasePane reportPane = grid.getElementCasePane(); + ElementCase report = reportPane.getEditingElementCase(); + FloatElement floatElement = (FloatElement) tmpFloatElementCursor[0]; + String floatName = floatElement.getName(); + reportPane.setSelection(new FloatSelection(floatName)); + double[] floatArray = GridUtils.caculateFloatElementLocations(floatElement, ReportHelper.getColumnWidthList(report), ReportHelper.getRowHeightList(report), reportPane + .getGrid().getVerticalValue(), reportPane.getGrid().getHorizontalValue()); + + int cursorType = ((Cursor) tmpFloatElementCursor[1]).getType(); + if (cursorType == Cursor.MOVE_CURSOR) { + this.oldEvtX = evtX; + this.oldEvtY = evtY; + FloatElement el = report.getFloatElement(floatName); + int resolution = ScreenResolution.getScreenResolution(); + int verticalValue = grid.getVerticalValue(); + int horizentalValue = grid.getHorizontalValue(); + DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report); + DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report); + this.oldLocationX = FU.getInstance(el.getLeftDistance().toFU() - columnWidthList.getRangeValue(0, horizentalValue).toFU()).toPixI(resolution); + this.oldLocationY = FU.getInstance(el.getTopDistance().toFU() - rowHeightList.getRangeValue(0, verticalValue).toFU()).toPixI(resolution); + if (floatNamePointMap == null) { + floatNamePointMap = new HashMap(); + } + floatNamePointMap.clear(); + FloatElement tempFolatElement = report.getFloatElement(floatName); + int floatX1ForTempFloatElement = FU.getInstance(tempFolatElement.getLeftDistance().toFU() - columnWidthList.getRangeValue(0, horizentalValue).toFU()) + .toPixI(resolution) - oldLocationX; + int floatY1ForTempFloatElement = FU.getInstance(tempFolatElement.getTopDistance().toFU() - rowHeightList.getRangeValue(0, verticalValue).toFU()).toPixI(resolution) + - oldLocationY; + floatNamePointMap.put(floatName, new Point(floatX1ForTempFloatElement, floatY1ForTempFloatElement)); + } else if (cursorType == Cursor.NW_RESIZE_CURSOR) { + setOld_X_AndOld_Y(floatArray[2], floatArray[3]); + } else if (cursorType == Cursor.NE_RESIZE_CURSOR) { + setOld_X_AndOld_Y(floatArray[0], floatArray[3]); + } else if (cursorType == Cursor.SE_RESIZE_CURSOR) { + setOld_X_AndOld_Y(floatArray[0], floatArray[1]); + } else if (cursorType == Cursor.SW_RESIZE_CURSOR) { + setOld_X_AndOld_Y(floatArray[2], floatArray[1]); + } else if (cursorType == Cursor.N_RESIZE_CURSOR) { + setOld_X_AndOld_Y(floatArray[0], floatArray[3]); + } else if (cursorType == Cursor.S_RESIZE_CURSOR) { + setOld_X_AndOld_Y(floatArray[0], floatArray[1]); + } else if (cursorType == Cursor.W_RESIZE_CURSOR) { + setOld_X_AndOld_Y(floatArray[2], floatArray[1]); + } else if (cursorType == Cursor.E_RESIZE_CURSOR) { + setOld_X_AndOld_Y(floatArray[0], floatArray[1]); + } + } + + private void setOld_X_AndOld_Y(double x, double y) { + this.oldEvtX = (int) x; + this.oldEvtY = (int) y; + } + + /** + * @param e + */ + public void mouseWheelMoved(MouseWheelEvent e) { + ElementCasePane reportPane = grid.getElementCasePane(); + if (reportPane.isHorizontalScrollBarVisible()) { + reportPane.getVerticalScrollBar().setValue(reportPane.getVerticalScrollBar().getValue() + e.getWheelRotation() * 3); + } + } + + /** + * @param e + */ + public void mouseClicked(MouseEvent e) { + } + + /** + * @param e + */ + public void mouseEntered(MouseEvent e) { + } + + /** + * @param e + */ + public void mouseExited(MouseEvent e) { + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java b/designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java new file mode 100644 index 000000000..cee80d334 --- /dev/null +++ b/designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java @@ -0,0 +1,21 @@ +package com.fr.common.inputevent; + +import com.fr.stable.OperatingSystem; + +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; + +/** + * Created by hzzz on 2017/5/26. + */ +public class InputEventBaseOnOS { + private static final boolean isMacOS = OperatingSystem.isMacOS(); + + public static boolean isControlDown(MouseEvent e) { + return isMacOS ? e.isMetaDown() : e.isControlDown(); + } + + public static boolean isControlDown(KeyEvent e) { + return isMacOS ? e.isMetaDown() : e.isControlDown(); + } +} diff --git a/designer_base/src/com/fr/design/gui/icombobox/ExtendedComboBox.java b/designer_base/src/com/fr/design/gui/icombobox/ExtendedComboBox.java index 47ddbdac3..512b5713b 100644 --- a/designer_base/src/com/fr/design/gui/icombobox/ExtendedComboBox.java +++ b/designer_base/src/com/fr/design/gui/icombobox/ExtendedComboBox.java @@ -1,5 +1,7 @@ package com.fr.design.gui.icombobox; +import com.fr.common.inputevent.InputEventBaseOnOS; + import java.awt.Component; import java.awt.Dimension; import java.awt.Point; @@ -76,7 +78,7 @@ public class ExtendedComboBox extends UIComboBox { protected JList createList() { return new JList(comboBox.getModel()) { public void processMouseEvent(MouseEvent e) { - if (e.isControlDown()) { + if (InputEventBaseOnOS.isControlDown(e)) { // Fix for 4234053. Filter out the Control // Key from the list. // ie., don't allow CTRL key deselection. diff --git a/designer_base/src/com/fr/design/gui/icombobox/UIComboBoxUI.java b/designer_base/src/com/fr/design/gui/icombobox/UIComboBoxUI.java index ae1089fa9..f5cd1eabb 100644 --- a/designer_base/src/com/fr/design/gui/icombobox/UIComboBoxUI.java +++ b/designer_base/src/com/fr/design/gui/icombobox/UIComboBoxUI.java @@ -16,6 +16,7 @@ import javax.swing.plaf.basic.BasicComboBoxUI; import javax.swing.plaf.basic.BasicComboPopup; import javax.swing.plaf.basic.ComboPopup; +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.constants.UIConstants; import sun.swing.DefaultLookup; @@ -209,7 +210,7 @@ public class UIComboBoxUI extends BasicComboBoxUI implements MouseListener { @Override public void processMouseEvent(MouseEvent e) { - if (e.isControlDown()) { + if (InputEventBaseOnOS.isControlDown(e)) { e = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers() ^ DEFAULT_MODIFIER, e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger()); } diff --git a/designer_base/src/com/fr/design/gui/ilist/CheckBoxList.java b/designer_base/src/com/fr/design/gui/ilist/CheckBoxList.java index 0ef0f829a..fa21465cb 100644 --- a/designer_base/src/com/fr/design/gui/ilist/CheckBoxList.java +++ b/designer_base/src/com/fr/design/gui/ilist/CheckBoxList.java @@ -22,6 +22,7 @@ import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.stable.StringUtils; @@ -176,7 +177,7 @@ public class CheckBoxList extends JComponent { @Override protected void processMouseEvent(MouseEvent e) { if (e.getX() < 20) { - if (e.isControlDown() || e.isAltDown() || e.isShiftDown() || e.isMetaDown()) { + if (InputEventBaseOnOS.isControlDown(e) || e.isAltDown() || e.isShiftDown() || e.isMetaDown()) { int[] indices = getSelectedIndices(); if (indices.length == 0) { super.processMouseEvent(e); diff --git a/designer_base/src/com/fr/design/gui/itable/TableSorter.java b/designer_base/src/com/fr/design/gui/itable/TableSorter.java index 0ea84af03..93b2c5154 100644 --- a/designer_base/src/com/fr/design/gui/itable/TableSorter.java +++ b/designer_base/src/com/fr/design/gui/itable/TableSorter.java @@ -15,6 +15,8 @@ import java.util.List; import java.util.Map; import javax.swing.Icon; + +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.gui.ilable.UILabel; import javax.swing.JTable; import javax.swing.event.TableModelEvent; @@ -396,7 +398,7 @@ public class TableSorter extends AbstractTableModel { int column = columnModel.getColumn(viewColumn).getModelIndex(); if (column != -1) { int status = getSortingStatus(column); - if (!e.isControlDown()) { + if (!InputEventBaseOnOS.isControlDown(e)) { cancelSorting(); } // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or diff --git a/designer_base/src/com/fr/design/gui/itree/refreshabletree/UserObjectRefreshJTree.java b/designer_base/src/com/fr/design/gui/itree/refreshabletree/UserObjectRefreshJTree.java index b463ca7eb..0224a4349 100644 --- a/designer_base/src/com/fr/design/gui/itree/refreshabletree/UserObjectRefreshJTree.java +++ b/designer_base/src/com/fr/design/gui/itree/refreshabletree/UserObjectRefreshJTree.java @@ -1,5 +1,6 @@ package com.fr.design.gui.itree.refreshabletree; +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.general.NameObject; import com.fr.design.gui.itree.refreshabletree.loader.ChildrenLoaderFactory; import com.fr.general.ComparatorUtils; @@ -147,7 +148,7 @@ public abstract class UserObjectRefreshJTree> extends } } // marks:鼠标在上次选中的paths上,则将上次的paths设为的树的路径,否则将鼠标所在的节点设为选中的节点 - if (!(e.isShiftDown() || e.isControlDown())) { + if (!(e.isShiftDown() || InputEventBaseOnOS.isControlDown(e))) { if (isFind) { setSelectionPaths(oldPaths); } else { diff --git a/designer_base/src/com/fr/design/roleAuthority/UIRoleTreeUI.java b/designer_base/src/com/fr/design/roleAuthority/UIRoleTreeUI.java index e6b049b33..9b996410a 100644 --- a/designer_base/src/com/fr/design/roleAuthority/UIRoleTreeUI.java +++ b/designer_base/src/com/fr/design/roleAuthority/UIRoleTreeUI.java @@ -1,5 +1,6 @@ package com.fr.design.roleAuthority; +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.gui.itree.UITreeUI; import javax.swing.tree.TreePath; @@ -15,7 +16,7 @@ import java.awt.event.MouseEvent; public class UIRoleTreeUI extends UITreeUI { protected void selectPathForEvent(TreePath path, MouseEvent event) { /* Adjust from the anchor point. */ - if (event.isControlDown() && tree.isPathSelected(path)) { + if (InputEventBaseOnOS.isControlDown(event) && tree.isPathSelected(path)) { tree.removeSelectionPath(path); } else if (event.isShiftDown()) { tree.setAnchorSelectionPath(null); 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 13eaa18ac..2fde27019 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,5 +1,6 @@ package com.fr.design.designer.beans.models; +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.events.DesignerEvent; @@ -61,7 +62,7 @@ public class SelectionModel { * @param e 鼠标事件 */ public void selectACreatorAtMouseEvent(MouseEvent e) { - if (!e.isControlDown() && !e.isShiftDown()) { + if (!InputEventBaseOnOS.isControlDown(e) && !e.isShiftDown()) { // 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件 selection.reset(); } @@ -372,7 +373,7 @@ public class SelectionModel { public Direction getDirectionAt(MouseEvent e) { Direction dir; - if (e.isControlDown() || e.isShiftDown()) { + if (InputEventBaseOnOS.isControlDown(e) || e.isShiftDown()) { XCreator creator = designer.getComponentAt(e.getX(), e.getY(), selection.getSelectedCreators()); if (creator != designer.getRootComponent() && selection.addedable(creator)) { return Location.add;