From 69b56064780d2b2860dfd88c4c54bad695c2aa0e Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 8 Nov 2018 10:44:33 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-11612=20=E5=85=A8=E5=B1=80=E6=B0=B4?= =?UTF-8?q?=E5=8D=B0=3D>=E5=9F=BA=E7=A1=80=E9=9D=A2=E6=9D=BF=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractTemplateServerSettingPane.java | 91 +++++++++++++++++++ .../printsettings/ReportPrintSettingPane.java | 65 +++---------- 2 files changed, 103 insertions(+), 53 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/dialog/AbstractTemplateServerSettingPane.java diff --git a/designer-base/src/main/java/com/fr/design/dialog/AbstractTemplateServerSettingPane.java b/designer-base/src/main/java/com/fr/design/dialog/AbstractTemplateServerSettingPane.java new file mode 100644 index 0000000000..46c1036107 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/dialog/AbstractTemplateServerSettingPane.java @@ -0,0 +1,91 @@ +package com.fr.design.dialog; + +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.utils.gui.GUICoreUtils; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.FlowLayout; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +/** + * 封装了"为该模版单独设置、采用服务器设置"选项功能的设置面板 + * Created by plough on 2018/11/7. + */ +public abstract class AbstractTemplateServerSettingPane extends BasicPane { + private static final String[] CHOOSEITEM = new String[] { + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_I_Want_To_Set_Single"), + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Using_Server_Report_View_Settings") + }; + + protected static final int SINGLE_SET = 0; + protected static final int SERVER_SET = 1; + + protected UIComboBox chooseComboBox; + private JPanel contentPane; + + protected AbstractTemplateServerSettingPane() { + initComponents(); + } + + private void initComponents() { + chooseComboBox = new UIComboBox(CHOOSEITEM); + chooseComboBox.addItemListener(itemListener); + UILabel belowSetLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Blow_Set") + ":"); + JPanel buttonPane = GUICoreUtils.createFlowPane(new Component[] { + belowSetLabel, chooseComboBox}, FlowLayout.LEFT, 0, 0); + buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 20, 0, 0)); + + this.setLayout(new BorderLayout()); + this.add(buttonPane, BorderLayout.NORTH); + this.contentPane = getContentPane(); + this.add(contentPane, BorderLayout.CENTER); + } + + /** + * 包含设置项的主面板 + */ + protected abstract JPanel getContentPane(); + + private ItemListener itemListener = new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + if (isUsingServerSettings()) { + populateServerSettings(); + setSettingPaneEnabled(false); + } else { + setSettingPaneEnabled(true); + } + } + } + }; + + private void setSettingPaneEnabled(boolean enabled) { + // GUICoreUtils.setEnabled 会遍历所有 Component。所以要先设置外层,如果是生效的,再设置内层 + GUICoreUtils.setEnabled(contentPane, enabled); + if (enabled) { + checkContentPaneEnabled(); + } + } + + protected boolean isUsingServerSettings() { + return chooseComboBox.getSelectedIndex() == SERVER_SET; + } + + /** + * 整个配置面板设置为可用后,可能还需要检测面板中部分区域的可用性 + */ + protected void checkContentPaneEnabled() { + // do nothing + } + + /** + * 读取服务器配置并 populate 到主面板中 + */ + protected abstract void populateServerSettings(); +} diff --git a/designer-realize/src/main/java/com/fr/design/webattr/printsettings/ReportPrintSettingPane.java b/designer-realize/src/main/java/com/fr/design/webattr/printsettings/ReportPrintSettingPane.java index 22bd3693a3..014b20cb34 100644 --- a/designer-realize/src/main/java/com/fr/design/webattr/printsettings/ReportPrintSettingPane.java +++ b/designer-realize/src/main/java/com/fr/design/webattr/printsettings/ReportPrintSettingPane.java @@ -1,77 +1,36 @@ package com.fr.design.webattr.printsettings; import com.fr.base.print.PrintSettingsAttrMark; -import com.fr.design.dialog.BasicPane; -import com.fr.design.gui.icombobox.UIComboBox; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.utils.gui.GUICoreUtils; - +import com.fr.design.dialog.AbstractTemplateServerSettingPane; import com.fr.report.core.ReportUtils; -import javax.swing.BorderFactory; import javax.swing.JPanel; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.FlowLayout; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; /** * 模版->打印设置 * Created by plough on 2018/3/6. */ -public class ReportPrintSettingPane extends BasicPane { - private static final String[] CHOOSEITEM = new String[] { - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_I_Want_To_Set_Single"), - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Using_Server_Report_View_Settings") - }; - private static final int SINGLE_SET = 0; - private static final int SERVER_SET = 1; +public class ReportPrintSettingPane extends AbstractTemplateServerSettingPane { - private UIComboBox chooseComboBox; private PrintSettingPane printSettingPane; public ReportPrintSettingPane() { - initComponents(); - } - - private void initComponents() { - chooseComboBox = new UIComboBox(CHOOSEITEM); - chooseComboBox.addItemListener(itemListener); - UILabel belowSetLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Blow_Set") + ":"); - JPanel buttonPane = GUICoreUtils.createFlowPane(new Component[] { - belowSetLabel, chooseComboBox}, FlowLayout.LEFT, 0, 0); - buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 20, 0, 0)); - - printSettingPane = new PrintSettingPane(); - this.setLayout(new BorderLayout()); - this.add(buttonPane, BorderLayout.NORTH); - this.add(printSettingPane, BorderLayout.CENTER); } - private ItemListener itemListener = new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - if (e.getStateChange() == ItemEvent.SELECTED) { - if (chooseComboBox.getSelectedIndex() == 0) { - setSettingPaneEnabled(true); - } else { - populateServerSettings(); - setSettingPaneEnabled(false); - } - } + @Override + protected JPanel getContentPane() { + if (printSettingPane == null) { + printSettingPane = new PrintSettingPane(); } - }; + return printSettingPane; + } - private void setSettingPaneEnabled(boolean enabled) { - // GUICoreUtils.setEnabled 会遍历所有 Component。所以要先设置外层,如果是生效的,再设置内层 - GUICoreUtils.setEnabled(printSettingPane, enabled); - if (enabled) { - printSettingPane.checkEnabled(); - } + @Override + protected void checkContentPaneEnabled() { + printSettingPane.checkEnabled(); } - private void populateServerSettings() { + protected void populateServerSettings() { PrintSettingsAttrMark printSettings = ReportUtils.getPrintSettingsFromServerConfig(); printSettingPane.populate(printSettings); }