diff --git a/designer/src/com/fr/design/widget/ui/PasswordDefinePane.java b/designer/src/com/fr/design/widget/ui/PasswordDefinePane.java index c8b285b646..c8112b7515 100644 --- a/designer/src/com/fr/design/widget/ui/PasswordDefinePane.java +++ b/designer/src/com/fr/design/widget/ui/PasswordDefinePane.java @@ -1,5 +1,6 @@ package com.fr.design.widget.ui; +import com.fr.design.gui.frpane.RegFieldPane; import com.fr.design.gui.frpane.RegPane; import com.fr.form.ui.Password; import com.fr.form.ui.TextEditor; @@ -12,7 +13,7 @@ public class PasswordDefinePane extends TextFieldEditorDefinePane { return new Password(); } - protected RegPane createRegPane() { - return new RegPane(RegPane.PASSWORD_REG_TYPE); + protected RegFieldPane createRegPane() { + return new RegFieldPane(RegPane.PASSWORD_REG_TYPE); } } \ No newline at end of file diff --git a/designer/src/com/fr/design/widget/ui/TextAreaDefinePane.java b/designer/src/com/fr/design/widget/ui/TextAreaDefinePane.java index da2c2a07bb..d83a99e1b9 100644 --- a/designer/src/com/fr/design/widget/ui/TextAreaDefinePane.java +++ b/designer/src/com/fr/design/widget/ui/TextAreaDefinePane.java @@ -1,5 +1,6 @@ package com.fr.design.widget.ui; +import com.fr.design.gui.frpane.RegFieldPane; import com.fr.design.gui.frpane.RegPane; import com.fr.form.ui.TextArea; import com.fr.form.ui.TextEditor; @@ -12,7 +13,7 @@ public class TextAreaDefinePane extends TextFieldEditorDefinePane { return new TextArea(); } - protected RegPane createRegPane() { - return new RegPane(RegPane.TEXTAREA_REG_TYPE); + protected RegFieldPane createRegPane() { + return new RegFieldPane(RegPane.TEXTAREA_REG_TYPE); } } \ No newline at end of file diff --git a/designer/src/com/fr/design/widget/ui/TextFieldEditorDefinePane.java b/designer/src/com/fr/design/widget/ui/TextFieldEditorDefinePane.java index 0f2a419071..33981226d6 100644 --- a/designer/src/com/fr/design/widget/ui/TextFieldEditorDefinePane.java +++ b/designer/src/com/fr/design/widget/ui/TextFieldEditorDefinePane.java @@ -1,5 +1,6 @@ package com.fr.design.widget.ui; +import com.fr.design.gui.frpane.RegFieldPane; import com.fr.design.gui.frpane.RegPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.form.ui.TextEditor; @@ -9,13 +10,11 @@ import com.fr.stable.StringUtils; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; public class TextFieldEditorDefinePane extends FieldEditorDefinePane { - protected RegPane regPane; + protected RegFieldPane regPane; private WaterMarkDictPane waterMarkDictPane; public TextFieldEditorDefinePane() { @@ -51,13 +50,6 @@ public class TextFieldEditorDefinePane extends FieldEditorDefinePane waterMarkDictPane.removeInputKeyListener(this); } }); - //监听填写规则下拉框的值的变化 - regPane.getRegComboBox().addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - RegExp regExp = (RegExp) regPane.getRegComboBox().getSelectedItem(); - - } - }); JPanel content = FRGUIPaneFactory.createBorderLayout_S_Pane(); waterMarkDictPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); content.add(waterMarkDictPane, BorderLayout.CENTER); @@ -70,8 +62,8 @@ public class TextFieldEditorDefinePane extends FieldEditorDefinePane } - protected RegPane createRegPane() { - return new RegPane(); + protected RegFieldPane createRegPane() { + return new RegFieldPane(); } @Override @@ -81,14 +73,14 @@ public class TextFieldEditorDefinePane extends FieldEditorDefinePane @Override protected void populateSubFieldEditorBean(TextEditor e) { - this.regPane.populate(e.getRegex()); + this.regPane.populate(e); waterMarkDictPane.populate(e); } @Override protected TextEditor updateSubFieldEditorBean() { TextEditor ob = newTextEditorInstance(); - ob.setRegex(this.regPane.update()); + this.regPane.update(ob); waterMarkDictPane.update(ob); return ob; diff --git a/designer_base/src/com/fr/design/gui/frpane/RegFieldPane.java b/designer_base/src/com/fr/design/gui/frpane/RegFieldPane.java new file mode 100644 index 0000000000..ae91035d89 --- /dev/null +++ b/designer_base/src/com/fr/design/gui/frpane/RegFieldPane.java @@ -0,0 +1,108 @@ +package com.fr.design.gui.frpane; + +import com.fr.design.dialog.BasicPane; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.form.ui.TextEditor; +import com.fr.form.ui.reg.NoneReg; +import com.fr.form.ui.reg.RegExp; +import com.fr.general.Inter; + +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import java.awt.*; + +/** + * Created by kerry on 2017/9/4. + */ +public class RegFieldPane extends RegPane { + protected RegErrorMsgPane regErrorMsgPane; + + public RegFieldPane(){ + this(ALL_REG_TYPE); + } + + public RegFieldPane(RegExp[] types) { + super(types); + initComponents(); + } + + public void initComponents() { + regErrorMsgPane = new RegErrorMsgPane(); + final RegChangeListener regChangeListener = new RegChangeListener() { + + @Override + public void regChangeAction() { + RegExp regExp = (RegExp)getRegComboBox().getSelectedItem(); + if(regExp instanceof NoneReg){ + regErrorMsgPane.setVisible(false); + return; + } + regErrorMsgPane.setVisible(true); + } + }; + this.addRegChangeListener(regChangeListener); + this.add(regErrorMsgPane, BorderLayout.CENTER); + } + + @Override + protected String title4PopupWindow() { + return "RegFieldPane"; + } + + public void populate(TextEditor textEditor) { + populate(textEditor.getRegex()); + regErrorMsgPane.populate(textEditor); + } + + public void update(TextEditor textEditor) { + textEditor.setRegex(update()); + regErrorMsgPane.update(textEditor); + } + + private static class RegErrorMsgPane extends BasicPane { + private UITextField regErrorMsgField; + + public RegErrorMsgPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); + initRegErrorMsgField(); + JPanel panel = TableLayoutHelper.createGapTableLayoutPane(new Component[][]{new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget_Error_Tip")), regErrorMsgField}}, TableLayoutHelper.FILL_LASTCOLUMN, 18, 7); + this.add(panel); + } + + private void initRegErrorMsgField() { + regErrorMsgField = new UITextField(); + regErrorMsgField.getDocument().addDocumentListener(new DocumentListener() { + public void changedUpdate(DocumentEvent e) { + regErrorMsgField.setToolTipText(regErrorMsgField.getText()); + } + + public void insertUpdate(DocumentEvent e) { + regErrorMsgField.setToolTipText(regErrorMsgField.getText()); + } + + public void removeUpdate(DocumentEvent e) { + regErrorMsgField.setToolTipText(regErrorMsgField.getText()); + } + }); + } + + @Override + protected String title4PopupWindow() { + return "CUSTOM"; + } + + public void populate(TextEditor textEditor) { + regErrorMsgField.setText(textEditor.getRegErrorMessage()); + } + + public void update(TextEditor textEditor) { + textEditor.setRegErrorMessage(regErrorMsgField.getText()); + } + } + +} diff --git a/designer_base/src/com/fr/design/gui/frpane/RegPane.java b/designer_base/src/com/fr/design/gui/frpane/RegPane.java index c6e16bbe96..84201cdef0 100644 --- a/designer_base/src/com/fr/design/gui/frpane/RegPane.java +++ b/designer_base/src/com/fr/design/gui/frpane/RegPane.java @@ -16,8 +16,6 @@ import com.fr.general.Inter; import com.fr.stable.StringUtils; import javax.swing.*; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -55,7 +53,6 @@ public class RegPane extends BasicPane { private RegPhonePane regPhonePane; private DefaultRegPane defaultRegPane; private CustomRegRexPane customRegRexPane; - protected RegErrorMsgPane regErrorMsgPane; public UIComboBox getRegComboBox(){ @@ -78,9 +75,10 @@ public class RegPane extends BasicPane { regComboBox.setRenderer(listCellRender); JPanel contentPane = TableLayoutHelper.createGapTableLayoutPane(new Component[][]{new Component[]{new UILabel(Inter.getLocText("FR-Designer_Input_Rule")), regComboBox}}, TableLayoutHelper.FILL_LASTCOLUMN, 18, 7); - this.add(contentPane, BorderLayout.NORTH); + JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + + jPanel.add(contentPane, BorderLayout.NORTH); JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - regErrorMsgPane = new RegErrorMsgPane(); final JPanel cardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); detailedCardLayout = new CardLayout(); cardPane.setLayout(detailedCardLayout); @@ -89,8 +87,8 @@ public class RegPane extends BasicPane { cardPane.add((regPhonePane = new RegPhonePane()), "Phone"); cardPane.add((customRegRexPane = new CustomRegRexPane()), "Custom"); centerPane.add(cardPane, BorderLayout.NORTH); - centerPane.add(regErrorMsgPane, BorderLayout.CENTER); - this.add(centerPane, BorderLayout.CENTER); + jPanel.add(centerPane, BorderLayout.CENTER); + this.add(jPanel, BorderLayout.NORTH); regComboBox.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { RegExp regExp = (RegExp)regComboBox.getSelectedItem(); @@ -113,11 +111,6 @@ public class RegPane extends BasicPane { } fireRegChangeAction(); } - if(regExp instanceof NoneReg){ - regErrorMsgPane.setVisible(false); - return; - } - regErrorMsgPane.setVisible(true); } }); } @@ -150,12 +143,10 @@ public class RegPane extends BasicPane { } else { defaultRegPane.populate(regex); } - regErrorMsgPane.populate(regex); } public RegExp update(){ RegExp regExp = (RegExp)regComboBox.getSelectedItem(); - regErrorMsgPane.update(); if (regExp instanceof LengthReg){ return regLengthPane.update(); } else if(regExp instanceof PhoneReg) { @@ -174,6 +165,9 @@ public class RegPane extends BasicPane { } } + + + private static abstract class DisplayPane extends BasicPane { public abstract void populate(RegExp regRex); @@ -481,56 +475,6 @@ public class RegPane extends BasicPane { } } - private static class RegErrorMsgPane extends DisplayPane{ - private UITextField regErrorMsgField; - - public RegErrorMsgPane(){ - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - this.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); - initRegErrorMsgField(); - JPanel panel = TableLayoutHelper.createGapTableLayoutPane(new Component[][]{new Component[]{new UILabel(Inter.getLocText("FR-Designer_Widget_Error_Tip")), regErrorMsgField}}, TableLayoutHelper.FILL_LASTCOLUMN, 18, 7); - this.add(panel); - } - - private void initRegErrorMsgField(){ - regErrorMsgField = new UITextField(); - regErrorMsgField.getDocument().addDocumentListener(new DocumentListener() { - public void changedUpdate(DocumentEvent e) { - regErrorMsgField.setToolTipText(regErrorMsgField.getText()); - } - - public void insertUpdate(DocumentEvent e) { - regErrorMsgField.setToolTipText(regErrorMsgField.getText()); - } - - public void removeUpdate(DocumentEvent e) { - regErrorMsgField.setToolTipText(regErrorMsgField.getText()); - } - }); - } - - @Override - protected String title4PopupWindow() { - return "CUSTOM"; - } - - @Override - public void populate(RegExp regRex) { - if (!(regRex instanceof CustomReg)){ - return; - } - regErrorMsgField.setText(regRex.toRegText()); - } - - @Override - public RegExp update() { - return new CustomReg(regErrorMsgField.getText()); - } - - public boolean isEmpty() { - return StringUtils.isEmpty(regErrorMsgField.getText()); - } - } ListCellRenderer listCellRender = new UIComboBoxRenderer(){ @Override diff --git a/designer_form/src/com/fr/design/widget/ui/designer/PasswordDefinePane.java b/designer_form/src/com/fr/design/widget/ui/designer/PasswordDefinePane.java index e3c529b43d..c01f30d337 100644 --- a/designer_form/src/com/fr/design/widget/ui/designer/PasswordDefinePane.java +++ b/designer_form/src/com/fr/design/widget/ui/designer/PasswordDefinePane.java @@ -1,9 +1,9 @@ package com.fr.design.widget.ui.designer; import com.fr.design.designer.creator.XCreator; +import com.fr.design.gui.frpane.RegFieldPane; import com.fr.design.gui.frpane.RegPane; -import com.fr.form.ui.Password; -import com.fr.form.ui.TextEditor; + public class PasswordDefinePane extends TextFieldEditorDefinePane { @@ -12,12 +12,7 @@ public class PasswordDefinePane extends TextFieldEditorDefinePane { } private static final long serialVersionUID = 4737910705071750562L; - @Override - protected TextEditor newTextEditorInstance() { - return new Password(); - } - - protected RegPane createRegPane() { - return new RegPane(RegPane.PASSWORD_REG_TYPE); + protected RegFieldPane createRegPane() { + return new RegFieldPane(RegPane.PASSWORD_REG_TYPE); } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/widget/ui/designer/TextAreaDefinePane.java b/designer_form/src/com/fr/design/widget/ui/designer/TextAreaDefinePane.java index 0fc4d617e3..211db396ba 100644 --- a/designer_form/src/com/fr/design/widget/ui/designer/TextAreaDefinePane.java +++ b/designer_form/src/com/fr/design/widget/ui/designer/TextAreaDefinePane.java @@ -1,6 +1,7 @@ package com.fr.design.widget.ui.designer; import com.fr.design.designer.creator.XCreator; +import com.fr.design.gui.frpane.RegFieldPane; import com.fr.design.gui.frpane.RegPane; import com.fr.form.ui.TextArea; import com.fr.form.ui.TextEditor; @@ -10,12 +11,8 @@ public class TextAreaDefinePane extends TextFieldEditorDefinePane { public TextAreaDefinePane(XCreator xCreator) { super(xCreator); } - @Override - protected TextEditor newTextEditorInstance() { - return new TextArea(); - } - protected RegPane createRegPane() { - return new RegPane(RegPane.TEXTAREA_REG_TYPE); + protected RegFieldPane createRegPane() { + return new RegFieldPane(RegPane.TEXTAREA_REG_TYPE); } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/widget/ui/designer/TextFieldEditorDefinePane.java b/designer_form/src/com/fr/design/widget/ui/designer/TextFieldEditorDefinePane.java index cc5abe66e1..7ea30f8710 100644 --- a/designer_form/src/com/fr/design/widget/ui/designer/TextFieldEditorDefinePane.java +++ b/designer_form/src/com/fr/design/widget/ui/designer/TextFieldEditorDefinePane.java @@ -1,6 +1,7 @@ package com.fr.design.widget.ui.designer; import com.fr.design.designer.creator.XCreator; +import com.fr.design.gui.frpane.RegFieldPane; import com.fr.design.gui.frpane.RegPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; @@ -17,7 +18,7 @@ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; public class TextFieldEditorDefinePane extends FieldEditorDefinePane { - protected RegPane regPane; + protected RegFieldPane regPane; private UITextField waterMarkDictPane; FormWidgetValuePane formWidgetValuePane; @@ -55,15 +56,6 @@ public class TextFieldEditorDefinePane extends FieldEditorDefinePane waterMarkDictPane.removeKeyListener(this); } }); - //监听填写规则下拉框的值的变化 -// regPane.getRegComboBox().addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent e) { -// RegExp regExp = (RegExp) regPane.getRegComboBox().getSelectedItem(); -//// regErrorMsgTextField.setEnabled(regExp.errorMessageEditable()); -// -// } -// }); - formWidgetValuePane = new FormWidgetValuePane(creator.toData(), false); double f = TableLayout.FILL; @@ -90,8 +82,8 @@ public class TextFieldEditorDefinePane extends FieldEditorDefinePane - protected RegPane createRegPane() { - return new RegPane(); + protected RegFieldPane createRegPane() { + return new RegFieldPane(); } @Override @@ -101,7 +93,7 @@ public class TextFieldEditorDefinePane extends FieldEditorDefinePane @Override protected void populateSubFieldEditorBean(TextEditor e) { - this.regPane.populate(e.getRegex()); + this.regPane.populate(e); waterMarkDictPane.setText(e.getWaterMark()); formWidgetValuePane.populate(e); } @@ -109,14 +101,11 @@ public class TextFieldEditorDefinePane extends FieldEditorDefinePane @Override protected TextEditor updateSubFieldEditorBean() { TextEditor ob = (TextEditor)creator.toData(); - ob.setRegex(this.regPane.update()); + this.regPane.update(ob); ob.setWaterMark(waterMarkDictPane.getText()); formWidgetValuePane.update(ob); return ob; } - protected TextEditor newTextEditorInstance() { - return new TextEditor(); - } } \ No newline at end of file