|
|
|
@ -1,16 +1,14 @@
|
|
|
|
|
package com.fr.design.gui.frpane; |
|
|
|
|
|
|
|
|
|
import com.fr.design.constants.LayoutConstants; |
|
|
|
|
import com.fr.design.designer.IntervalConstants; |
|
|
|
|
import com.fr.design.dialog.BasicPane; |
|
|
|
|
import com.fr.design.gui.core.ReactiveCardPane; |
|
|
|
|
import com.fr.design.gui.icombobox.UIComboBox; |
|
|
|
|
import com.fr.design.gui.icombobox.UIComboBoxRenderer; |
|
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
|
import com.fr.design.gui.ispinner.UISpinner; |
|
|
|
|
import com.fr.design.gui.itextfield.UITextField; |
|
|
|
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
|
|
|
import com.fr.design.layout.TableLayout; |
|
|
|
|
import com.fr.design.layout.TableLayoutHelper; |
|
|
|
|
import com.fr.form.ui.reg.*; |
|
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
|
|
|
|
|
@ -18,13 +16,14 @@ 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.ItemEvent; |
|
|
|
|
import java.awt.event.ItemListener; |
|
|
|
|
import java.util.EventListener; |
|
|
|
|
import java.util.EventObject; |
|
|
|
|
|
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.cell; |
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.row; |
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.column; |
|
|
|
|
|
|
|
|
|
public class RegPane extends BasicPane { |
|
|
|
|
public static final RegExp[] ALL_REG_TYPE = { |
|
|
|
|
new NoneReg(), |
|
|
|
@ -54,7 +53,7 @@ public class RegPane extends BasicPane {
|
|
|
|
|
private RegPhonePane regPhonePane; |
|
|
|
|
private DefaultRegPane defaultRegPane; |
|
|
|
|
private CustomRegRexPane customRegRexPane; |
|
|
|
|
|
|
|
|
|
protected JPanel corePane; |
|
|
|
|
|
|
|
|
|
public UIComboBox getRegComboBox(){ |
|
|
|
|
return regComboBox; |
|
|
|
@ -71,49 +70,51 @@ public class RegPane extends BasicPane {
|
|
|
|
|
|
|
|
|
|
private void initComponents(){ |
|
|
|
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
|
this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
|
|
|
|
corePane = column(LayoutConstants.VERTICAL_GAP).getComponent(); |
|
|
|
|
this.add(corePane); |
|
|
|
|
|
|
|
|
|
regComboBox = new UIComboBox(regType); |
|
|
|
|
regComboBox.setRenderer(listCellRender); |
|
|
|
|
|
|
|
|
|
JPanel contentPane = TableLayoutHelper.createGapTableLayoutPane(new Component[][]{ |
|
|
|
|
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Input_Rule")), regComboBox}}, TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W1, IntervalConstants.INTERVAL_L1); |
|
|
|
|
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
|
|
|
|
|
jPanel.add(contentPane, BorderLayout.NORTH); |
|
|
|
|
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
final JPanel cardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); |
|
|
|
|
detailedCardLayout = new CardLayout(); |
|
|
|
|
cardPane.setLayout(detailedCardLayout); |
|
|
|
|
cardPane.add((defaultRegPane = new DefaultRegPane()), "Default"); |
|
|
|
|
cardPane.add((regLengthPane = new RegLengthPane()), "Length"); |
|
|
|
|
cardPane.add((regPhonePane = new RegPhonePane()), "Phone"); |
|
|
|
|
cardPane.add((customRegRexPane = new CustomRegRexPane()), "Custom"); |
|
|
|
|
centerPane.add(cardPane, BorderLayout.NORTH); |
|
|
|
|
jPanel.add(centerPane, BorderLayout.CENTER); |
|
|
|
|
this.add(jPanel, BorderLayout.NORTH); |
|
|
|
|
regComboBox.addActionListener(new ActionListener(){ |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
RegExp regExp = (RegExp)regComboBox.getSelectedItem(); |
|
|
|
|
if(regExp instanceof PhoneReg) { |
|
|
|
|
cardPane.setPreferredSize(new Dimension(220, 30)); |
|
|
|
|
Object selectItem = regPhonePane.dataTypeComboBox.getSelectedItem(); |
|
|
|
|
String regString = selectItem == null ? StringUtils.EMPTY : selectItem.toString(); |
|
|
|
|
firePhoneRegAction(regString); |
|
|
|
|
detailedCardLayout.show(cardPane, "Phone"); |
|
|
|
|
JPanel comboPane = row( |
|
|
|
|
cell(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Input_Rule"))).weight(1.2), |
|
|
|
|
cell(regComboBox).weight(3) |
|
|
|
|
).getComponent(); |
|
|
|
|
|
|
|
|
|
defaultRegPane = new DefaultRegPane(); |
|
|
|
|
regLengthPane = new RegLengthPane(); |
|
|
|
|
regPhonePane = new RegPhonePane(); |
|
|
|
|
customRegRexPane = new CustomRegRexPane(); |
|
|
|
|
|
|
|
|
|
final ReactiveCardPane cardPane = ReactiveCardPane.create() |
|
|
|
|
.addSupplier("Length", () -> regLengthPane) |
|
|
|
|
.addSupplier("Phone", () -> regPhonePane) |
|
|
|
|
.addSupplier("Custom", () -> customRegRexPane); |
|
|
|
|
cardPane.setVisible(false); |
|
|
|
|
|
|
|
|
|
corePane.add(comboPane); |
|
|
|
|
corePane.add(cardPane); |
|
|
|
|
initComboListener(cardPane); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initComboListener(ReactiveCardPane cardPane) { |
|
|
|
|
regComboBox.addActionListener(e -> { |
|
|
|
|
RegExp regExp = (RegExp)regComboBox.getSelectedItem(); |
|
|
|
|
if(regExp instanceof PhoneReg) { |
|
|
|
|
Object selectItem = regPhonePane.dataTypeComboBox.getSelectedItem(); |
|
|
|
|
String regString = selectItem == null ? StringUtils.EMPTY : selectItem.toString(); |
|
|
|
|
firePhoneRegAction(regString); |
|
|
|
|
cardPane.select("Phone").populate(); |
|
|
|
|
} else { |
|
|
|
|
if (regExp instanceof LengthReg){ |
|
|
|
|
cardPane.select("Length").populate(); |
|
|
|
|
} else if (regExp instanceof CustomReg){ |
|
|
|
|
cardPane.select("Custom").populate(); |
|
|
|
|
} else { |
|
|
|
|
if (regExp instanceof LengthReg){ |
|
|
|
|
cardPane.setPreferredSize(new Dimension(220, 60)); |
|
|
|
|
detailedCardLayout.show(cardPane, "Length"); |
|
|
|
|
} else if (regExp instanceof CustomReg){ |
|
|
|
|
cardPane.setPreferredSize(new Dimension(220, 30)); |
|
|
|
|
detailedCardLayout.show(cardPane, "Custom"); |
|
|
|
|
} else { |
|
|
|
|
cardPane.setPreferredSize(new Dimension(0,0 )); |
|
|
|
|
detailedCardLayout.show(cardPane, "Default"); |
|
|
|
|
} |
|
|
|
|
cardPane.setVisible(false); |
|
|
|
|
} |
|
|
|
|
fireRegChangeAction(); |
|
|
|
|
} |
|
|
|
|
fireRegChangeAction(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -174,16 +175,24 @@ public class RegPane extends BasicPane {
|
|
|
|
|
public abstract void populate(RegExp regRex); |
|
|
|
|
|
|
|
|
|
public abstract RegExp update(); |
|
|
|
|
|
|
|
|
|
public DisplayPane() { |
|
|
|
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
|
this.add(createContentPane(), BorderLayout.CENTER); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected JPanel createContentPane() { |
|
|
|
|
return new JPanel(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static class DefaultRegPane extends DisplayPane { |
|
|
|
|
public RegExp regRex; |
|
|
|
|
|
|
|
|
|
public DefaultRegPane(){ |
|
|
|
|
|
|
|
|
|
this.setVisible(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected String title4PopupWindow() { |
|
|
|
|
return "Default"; |
|
|
|
@ -328,38 +337,40 @@ public class RegPane extends BasicPane {
|
|
|
|
|
private static final String EMB_REG3 = "025 85679591"; |
|
|
|
|
private static final int LIMIT_LENGTH = 20; |
|
|
|
|
private static final String REG_PATTERN = "0123456789-*# "; |
|
|
|
|
private static final int CUSTOM_OPTION_INDEX = 3; |
|
|
|
|
|
|
|
|
|
private UIComboBox dataTypeComboBox; |
|
|
|
|
private final String[] dataType = {EMB_REG1, EMB_REG2, EMB_REG3, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom")}; |
|
|
|
|
DefaultComboBoxModel DefaultComboBoxModel= new DefaultComboBoxModel(dataType); |
|
|
|
|
public RegPhonePane() { |
|
|
|
|
this.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L6, IntervalConstants.INTERVAL_L5, 0, 0)); |
|
|
|
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
|
dataTypeComboBox = new UIComboBox(DefaultComboBoxModel); |
|
|
|
|
private DefaultComboBoxModel defaultComboBoxModel; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected JPanel createContentPane() { |
|
|
|
|
String[] dataType = {EMB_REG1, EMB_REG2, EMB_REG3, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom")}; |
|
|
|
|
defaultComboBoxModel = new DefaultComboBoxModel(dataType); |
|
|
|
|
dataTypeComboBox = new UIComboBox(defaultComboBoxModel); |
|
|
|
|
JTextField editFiled = (JTextField)(dataTypeComboBox.getEditor().getEditorComponent()); |
|
|
|
|
UILabel dataTypeLable = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Data_Type")); |
|
|
|
|
dataTypeLable.setPreferredSize(new Dimension(60, 20)); |
|
|
|
|
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(new Component[][]{new Component[]{dataTypeLable, dataTypeComboBox}}, TableLayoutHelper.FILL_LASTCOLUMN, 10, 0); |
|
|
|
|
this.add(panel); |
|
|
|
|
UILabel dataTypeLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Data_Type")); |
|
|
|
|
|
|
|
|
|
editFiled.setDocument(new LimitedDocument(LIMIT_LENGTH, REG_PATTERN)); |
|
|
|
|
dataTypeComboBox.addItemListener(new ItemListener() { |
|
|
|
|
@Override |
|
|
|
|
public void itemStateChanged(ItemEvent e) { |
|
|
|
|
if(e.getStateChange() == ItemEvent.SELECTED) { |
|
|
|
|
if(ComparatorUtils.equals(e.getItem(), dataType[3])) { |
|
|
|
|
dataTypeComboBox.setSelectedItem(null); |
|
|
|
|
dataTypeComboBox.setEditable(true); |
|
|
|
|
firePhoneRegAction(EMB_REG1); |
|
|
|
|
} else { |
|
|
|
|
dataTypeComboBox.setEditable(false); |
|
|
|
|
firePhoneRegAction(dataTypeComboBox.getSelectedItem().toString()); |
|
|
|
|
} |
|
|
|
|
dataTypeComboBox.addItemListener(e -> { |
|
|
|
|
if(e.getStateChange() == ItemEvent.SELECTED) { |
|
|
|
|
if(ComparatorUtils.equals(e.getItem(), dataType[CUSTOM_OPTION_INDEX])) { |
|
|
|
|
dataTypeComboBox.setSelectedItem(null); |
|
|
|
|
dataTypeComboBox.setEditable(true); |
|
|
|
|
firePhoneRegAction(EMB_REG1); |
|
|
|
|
} else { |
|
|
|
|
dataTypeComboBox.setEditable(false); |
|
|
|
|
firePhoneRegAction(dataTypeComboBox.getSelectedItem().toString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
dataTypeComboBox.setSelectedIndex(0); |
|
|
|
|
firePhoneRegAction(dataTypeComboBox.getSelectedItem().toString()); |
|
|
|
|
|
|
|
|
|
return row( |
|
|
|
|
cell(dataTypeLabel).weight(1.2), cell(dataTypeComboBox).weight(3) |
|
|
|
|
).getComponent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected String title4PopupWindow() { |
|
|
|
|
return "PHONE"; |
|
|
|
@ -372,7 +383,7 @@ public class RegPane extends BasicPane {
|
|
|
|
|
} |
|
|
|
|
String regstr = ((PhoneReg)regRex).getRegString(); |
|
|
|
|
if (checkEmbedded(regstr)){ |
|
|
|
|
DefaultComboBoxModel.addElement(regstr); |
|
|
|
|
defaultComboBoxModel.addElement(regstr); |
|
|
|
|
} |
|
|
|
|
dataTypeComboBox.setSelectedItem(((PhoneReg)regRex).getRegString()); |
|
|
|
|
} |
|
|
|
@ -394,34 +405,21 @@ public class RegPane extends BasicPane {
|
|
|
|
|
private static class RegLengthPane extends DisplayPane { |
|
|
|
|
private UISpinner minLenSpinner; |
|
|
|
|
private UISpinner maxLenSpinner; |
|
|
|
|
private final int DEFAULT_WIDTH = 60; |
|
|
|
|
|
|
|
|
|
public RegLengthPane(){ |
|
|
|
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
|
this.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L6, IntervalConstants.INTERVAL_L5, 0, 0)); |
|
|
|
|
this.setPreferredSize(new Dimension(210, 56)); |
|
|
|
|
@Override |
|
|
|
|
protected JPanel createContentPane() { |
|
|
|
|
minLenSpinner = new UISpinner(0, Integer.MAX_VALUE, 1, 0); |
|
|
|
|
maxLenSpinner = new UISpinner(0, Integer.MAX_VALUE, 1, 0); |
|
|
|
|
UILabel minLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Reg_Min_Length")); |
|
|
|
|
UILabel maxLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Reg_Max_Length")); |
|
|
|
|
int minLabelWidth = Math.max(minLabel.getPreferredSize().width, DEFAULT_WIDTH); |
|
|
|
|
int maxLabelWidth = Math.max(maxLabel.getPreferredSize().width, DEFAULT_WIDTH); |
|
|
|
|
|
|
|
|
|
minLabel.setPreferredSize(new Dimension(minLabelWidth, 20)); |
|
|
|
|
maxLabel.setPreferredSize(new Dimension(maxLabelWidth, 20)); |
|
|
|
|
double f = TableLayout.FILL; |
|
|
|
|
double p = TableLayout.PREFERRED; |
|
|
|
|
Component[][] components = new Component[][]{ |
|
|
|
|
new Component[]{minLabel, minLenSpinner }, |
|
|
|
|
new Component[]{maxLabel, maxLenSpinner}, |
|
|
|
|
}; |
|
|
|
|
double[] rowSize = {p, p}; |
|
|
|
|
double[] columnSize = {p,f}; |
|
|
|
|
int[][] rowCount = {{1, 1},{1, 1}}; |
|
|
|
|
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, 10, LayoutConstants.VGAP_MEDIUM); |
|
|
|
|
this.add(panel); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return column(LayoutConstants.VERTICAL_GAP, |
|
|
|
|
row( |
|
|
|
|
cell(minLabel).weight(1.2), cell(minLenSpinner).weight(3) |
|
|
|
|
), |
|
|
|
|
row( |
|
|
|
|
cell(maxLabel).weight(1.2), cell(maxLenSpinner).weight(3) |
|
|
|
|
) |
|
|
|
|
).getComponent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -453,15 +451,16 @@ public class RegPane extends BasicPane {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static class CustomRegRexPane extends DisplayPane{ |
|
|
|
|
private static class CustomRegRexPane extends DisplayPane { |
|
|
|
|
private UITextField regTextField; |
|
|
|
|
|
|
|
|
|
public CustomRegRexPane(){ |
|
|
|
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
|
this.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L6, IntervalConstants.INTERVAL_L5, 0, 0)); |
|
|
|
|
@Override |
|
|
|
|
protected JPanel createContentPane() { |
|
|
|
|
regTextField = new UITextField(); |
|
|
|
|
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(new Component[][]{new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Reg_Expressions")), regTextField}}, TableLayoutHelper.FILL_LASTCOLUMN, 10, LayoutConstants.VGAP_MEDIUM); |
|
|
|
|
this.add(panel); |
|
|
|
|
return row( |
|
|
|
|
cell(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Reg_Expressions"))).weight(1.2), |
|
|
|
|
cell(regTextField).weight(3) |
|
|
|
|
).getComponent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|