From 7e5e7816510f17f572ce4a99ef2dbd293fcff788 Mon Sep 17 00:00:00 2001 From: hades Date: Tue, 12 Nov 2019 17:20:36 +0800 Subject: [PATCH] =?UTF-8?q?MOBILE-23952=20=E6=96=87=E6=9C=AC=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E5=8F=AA=E8=83=BD=E6=89=AB=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/gui/ibutton/ModeButtonGroup.java | 36 +++++++++++++++ .../mobile/ScanCodeMobileDefinePane.java | 44 +++++++++++++------ .../widget/ui/mobile/ScanCodeMobilePane.java | 42 ++++++++++++------ 3 files changed, 94 insertions(+), 28 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/gui/ibutton/ModeButtonGroup.java diff --git a/designer-base/src/main/java/com/fr/design/gui/ibutton/ModeButtonGroup.java b/designer-base/src/main/java/com/fr/design/gui/ibutton/ModeButtonGroup.java new file mode 100644 index 0000000000..c13498705a --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ibutton/ModeButtonGroup.java @@ -0,0 +1,36 @@ +package com.fr.design.gui.ibutton; + + +import javax.swing.*; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * 互斥的按钮 + * @author hades + * @version 10.0 + * Created by hades on 2019/11/12 + */ +public class ModeButtonGroup extends ButtonGroup { + + private Map buttonMap = new LinkedHashMap<>(); + + public void put(T t, AbstractButton button) { + add(button); + buttonMap.put(t, button); + } + + public void setSelectButton(T t) { + buttonMap.get(t).setSelected(true); + } + + public T getCurrentSelected() { + for (Map.Entry entry : buttonMap.entrySet()) { + if (entry.getValue().isSelected()) { + return entry.getKey(); + } + } + return buttonMap.entrySet().iterator().next().getKey(); + } + +} diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ScanCodeMobileDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ScanCodeMobileDefinePane.java index dfa902d862..444569fbcd 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ScanCodeMobileDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ScanCodeMobileDefinePane.java @@ -1,24 +1,24 @@ package com.fr.design.widget.ui.designer.mobile; import com.fr.base.mobile.MobileScanCodeAttr; -import com.fr.base.mobile.ScanCodeState; +import com.fr.base.mobile.TextInputMode; import com.fr.design.designer.creator.XCreator; import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.gui.frpane.AttributeChangeListener; -import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ibutton.ModeButtonGroup; +import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.FormDesigner; import com.fr.form.ui.TextEditor; -import javax.swing.BorderFactory; -import javax.swing.JPanel; -import java.awt.BorderLayout; +import javax.swing.*; +import java.awt.*; public class ScanCodeMobileDefinePane extends MobileWidgetDefinePane { private XCreator xCreator; - private UICheckBox appScanCodeCheck; + private ModeButtonGroup buttonGroup; public ScanCodeMobileDefinePane(XCreator xCreator) { this.xCreator = xCreator; @@ -33,14 +33,31 @@ public class ScanCodeMobileDefinePane extends MobileWidgetDefinePane { } private UIExpandablePane getMobileSettingsPane() { - JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); - appScanCodeCheck = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Support_Scan_Code"), true); - appScanCodeCheck.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); + JPanel panel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, FlowLayout.LEADING, 0, 10); + buttonGroup = new ModeButtonGroup<>(); + UIRadioButton scanCodeAndManualInput = new UIRadioButton( + com.fr.design.i18n.Toolkit.i18nText("Fine-Design__Mobile_Support_Scan_Code_And_Manual_Input"), true); + UIRadioButton onlyManualInput = new UIRadioButton( + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Mobile_Only_Support_Manual_Input"), false); + UIRadioButton onlyScanCodeInput = new UIRadioButton( + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Mobile_Only_Support_Scan_Code_Input"), false); + scanCodeAndManualInput.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + onlyManualInput.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + onlyScanCodeInput.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + buttonGroup.put(TextInputMode.SUPPORT_SCAN_CODE_And_MANUAL, scanCodeAndManualInput); + buttonGroup.put(TextInputMode.ONLY_SUPPORT_MANUAL, onlyManualInput); + buttonGroup.put(TextInputMode.ONLY_SUPPORT_SCAN_CODE, onlyScanCodeInput); + buttonGroup.add(scanCodeAndManualInput); + buttonGroup.add(onlyManualInput); + buttonGroup.add(onlyScanCodeInput); panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); - panel.add(appScanCodeCheck); + panel.add(scanCodeAndManualInput); + panel.add(onlyManualInput); + panel.add(onlyScanCodeInput); final JPanel panelWrapper = FRGUIPaneFactory.createBorderLayout_S_Pane(); panelWrapper.add(panel, BorderLayout.NORTH); - return new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"), 280, 20, panelWrapper); + return new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"), 280, 20, + panelWrapper); } private void bindListeners2Widgets() { @@ -61,15 +78,14 @@ public class ScanCodeMobileDefinePane extends MobileWidgetDefinePane { @Override public void populate(FormDesigner designer) { MobileScanCodeAttr mobileScanCodeAttr = ((TextEditor) xCreator.toData()).getMobileScanCodeAttr(); - ScanCodeState scanCodeState = mobileScanCodeAttr.getScanCodeState(); - appScanCodeCheck.setSelected(scanCodeState.getState()); + buttonGroup.setSelectButton(mobileScanCodeAttr.getTextInputMode()); this.bindListeners2Widgets(); } @Override public void update() { MobileScanCodeAttr mobileScanCodeAttr = ((TextEditor) xCreator.toData()).getMobileScanCodeAttr(); - mobileScanCodeAttr.setScanCodeState(ScanCodeState.parse(appScanCodeCheck.isSelected())); + mobileScanCodeAttr.setTextInputMode(buttonGroup.getCurrentSelected()); DesignerContext.getDesignerFrame().getSelectedJTemplate().fireTargetModified(); } diff --git a/designer-realize/src/main/java/com/fr/design/widget/ui/mobile/ScanCodeMobilePane.java b/designer-realize/src/main/java/com/fr/design/widget/ui/mobile/ScanCodeMobilePane.java index e9c798ec95..74807add94 100644 --- a/designer-realize/src/main/java/com/fr/design/widget/ui/mobile/ScanCodeMobilePane.java +++ b/designer-realize/src/main/java/com/fr/design/widget/ui/mobile/ScanCodeMobilePane.java @@ -1,49 +1,63 @@ package com.fr.design.widget.ui.mobile; import com.fr.base.mobile.MobileScanCodeAttr; -import com.fr.base.mobile.ScanCodeState; +import com.fr.base.mobile.TextInputMode; import com.fr.design.foldablepane.UIExpandablePane; -import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ibutton.ModeButtonGroup; +import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.widget.mobile.WidgetMobilePane; import com.fr.form.ui.TextEditor; import com.fr.form.ui.Widget; -import javax.swing.BorderFactory; -import javax.swing.JPanel; -import java.awt.BorderLayout; +import javax.swing.*; +import java.awt.*; public class ScanCodeMobilePane extends WidgetMobilePane { - private UICheckBox appScanCodeCheck; + private ModeButtonGroup buttonGroup; + @Override protected void init() { this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.add(getMobileSettingPane(), BorderLayout.NORTH); } private UIExpandablePane getMobileSettingPane() { - JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); - appScanCodeCheck = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Support_Scan_Code"), true); - appScanCodeCheck.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); + JPanel panel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, FlowLayout.LEADING, 0, 10); + buttonGroup = new ModeButtonGroup<>(); + UIRadioButton scanCodeAndManualInput = new UIRadioButton( + com.fr.design.i18n.Toolkit.i18nText("Fine-Design__Mobile_Support_Scan_Code_And_Manual_Input"), true); + UIRadioButton onlyManualInput = new UIRadioButton( + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Mobile_Only_Support_Manual_Input"), false); + UIRadioButton onlyScanCodeInput = new UIRadioButton( + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Mobile_Only_Support_Scan_Code_Input"), false); + scanCodeAndManualInput.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + onlyManualInput.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + onlyScanCodeInput.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + buttonGroup.put(TextInputMode.SUPPORT_SCAN_CODE_And_MANUAL, scanCodeAndManualInput); + buttonGroup.put(TextInputMode.ONLY_SUPPORT_MANUAL, onlyManualInput); + buttonGroup.put(TextInputMode.ONLY_SUPPORT_SCAN_CODE, onlyScanCodeInput); panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); - panel.add(appScanCodeCheck); + panel.add(scanCodeAndManualInput); + panel.add(onlyManualInput); + panel.add(onlyScanCodeInput); final JPanel panelWrapper = FRGUIPaneFactory.createBorderLayout_S_Pane(); panelWrapper.add(panel, BorderLayout.NORTH); - return new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"), 280, 20, panelWrapper); + return new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"), 280, 20, + panelWrapper); } @Override public void populate(Widget widget) { MobileScanCodeAttr mobileScanCodeAttr = ((TextEditor) widget).getMobileScanCodeAttr(); - ScanCodeState scanCodeState = mobileScanCodeAttr.getScanCodeState(); - appScanCodeCheck.setSelected(scanCodeState.getState()); + buttonGroup.setSelectButton(mobileScanCodeAttr.getTextInputMode()); } @Override public void update(Widget widget) { MobileScanCodeAttr mobileScanCodeAttr = ((TextEditor) widget).getMobileScanCodeAttr(); - mobileScanCodeAttr.setScanCodeState(ScanCodeState.parse(appScanCodeCheck.isSelected())); + mobileScanCodeAttr.setTextInputMode(buttonGroup.getCurrentSelected()); }