Browse Source

代码上传

master
kerry 7 years ago
parent
commit
df65a17ef8
  1. 262
      designer_base/src/com/fr/design/gui/frpane/RegPane.java

262
designer_base/src/com/fr/design/gui/frpane/RegPane.java

@ -16,6 +16,8 @@ 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;
@ -53,9 +55,10 @@ public class RegPane extends BasicPane {
private RegPhonePane regPhonePane;
private DefaultRegPane defaultRegPane;
private CustomRegRexPane customRegRexPane;
protected RegErrorMsgPane regErrorMsgPane;
public UIComboBox getRegComboBox() {
public UIComboBox getRegComboBox(){
return regComboBox;
}
@ -68,25 +71,21 @@ public class RegPane extends BasicPane {
this.initComponents();
}
private void initComponents() {
this.setLayout(new BorderLayout());
private void initComponents(){
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel contentPane = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane();
this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
this.add(contentPane, BorderLayout.NORTH);
contentPane.add(new UILabel(Inter.getLocText("FR-Designer_Input_Rule")));
regComboBox = new UIComboBox(regType);
regComboBox.setPreferredSize(new Dimension(140, 20));
regComboBox.setRenderer(listCellRender);
UILabel uiLabel = new UILabel();
uiLabel.setPreferredSize(new Dimension(20, 20));
contentPane.add(uiLabel);
contentPane.add(regComboBox);
double f = TableLayout.FILL;
double p = TableLayout.PREFERRED;
Component[][] components = new Component[][]{
new Component[]{new UILabel(Inter.getLocText("FR-Designer_Input_Rule") + " "), regComboBox},
};
double[] rowSize = {p};
double[] columnSize = {p, f};
int[][] rowCount = {{1, 1}};
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_LARGE);
panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 0, 0));
this.add(panel, BorderLayout.NORTH);
regErrorMsgPane = new RegErrorMsgPane();
final JPanel cardPane = FRGUIPaneFactory.createCardLayout_S_Pane();
detailedCardLayout = new CardLayout();
cardPane.setLayout(detailedCardLayout);
@ -94,26 +93,35 @@ public class RegPane extends BasicPane {
cardPane.add((regLengthPane = new RegLengthPane()), "Length");
cardPane.add((regPhonePane = new RegPhonePane()), "Phone");
cardPane.add((customRegRexPane = new CustomRegRexPane()), "Custom");
cardPane.setBorder(BorderFactory.createEmptyBorder(8, 12, 0, 0));
this.add(cardPane, BorderLayout.CENTER);
regComboBox.addActionListener(new ActionListener() {
this.add(regErrorMsgPane, BorderLayout.SOUTH);
regComboBox.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
RegExp regExp = (RegExp) regComboBox.getSelectedItem();
if (regExp instanceof PhoneReg) {
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");
} else {
if (regExp instanceof LengthReg) {
if (regExp instanceof LengthReg){
cardPane.setPreferredSize(new Dimension(220, 60));
detailedCardLayout.show(cardPane, "Length");
} else if (regExp instanceof CustomReg) {
} 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");
}
fireRegChangeAction();
}
if(regExp instanceof NoneReg){
regErrorMsgPane.setVisible(false);
return;
}
regErrorMsgPane.setVisible(true);
}
});
}
@ -146,19 +154,21 @@ public class RegPane extends BasicPane {
} else {
defaultRegPane.populate(regex);
}
regErrorMsgPane.populate(regex);
}
public RegExp update() {
RegExp regExp = (RegExp) regComboBox.getSelectedItem();
if (regExp instanceof LengthReg) {
public RegExp update(){
RegExp regExp = (RegExp)regComboBox.getSelectedItem();
regErrorMsgPane.update();
if (regExp instanceof LengthReg){
return regLengthPane.update();
} else if (regExp instanceof PhoneReg) {
} else if(regExp instanceof PhoneReg) {
return regPhonePane.update();
} else if (regExp instanceof NoneReg || regExp instanceof MailReg || regExp instanceof IDCardReg
} else if(regExp instanceof NoneReg || regExp instanceof MailReg || regExp instanceof IDCardReg
|| regExp instanceof PostCardReg || regExp instanceof PhoneReg || regExp instanceof MobileReg) {
return regExp;
} else if (regExp instanceof CustomReg) {
}
else if (regExp instanceof CustomReg){
if (customRegRexPane.isEmpty()) {
return new NoneReg();
}
@ -177,7 +187,7 @@ public class RegPane extends BasicPane {
private static class DefaultRegPane extends DisplayPane {
public RegExp regRex;
public DefaultRegPane() {
public DefaultRegPane(){
}
@ -203,7 +213,10 @@ public class RegPane extends BasicPane {
* 添加电话规则监听器
*
* @param listener 监听器
*
*
* @date 2014-12-3-下午7:30:55
*
*/
public void addPhoneRegListener(PhoneRegListener listener) {
this.listenerList.add(PhoneRegListener.class, listener);
@ -213,7 +226,10 @@ public class RegPane extends BasicPane {
* 移除电话规则监听器
*
* @param listener 监听器
*
*
* @date 2014-12-3-下午7:30:55
*
*/
public void removePhoneRegListener(PhoneRegListener listener) {
this.listenerList.remove(PhoneRegListener.class, listener);
@ -223,7 +239,10 @@ public class RegPane extends BasicPane {
* 添加正则监听器
*
* @param listener 监听器
*
*
* @date 2014-12-3-下午7:29:48
*
*/
public void addRegChangeListener(RegChangeListener listener) {
this.listenerList.add(RegChangeListener.class, listener);
@ -233,7 +252,10 @@ public class RegPane extends BasicPane {
* 移除正则监听器
*
* @param listener 监听器
*
*
* @date 2014-12-3-下午7:29:48
*
*/
public void removeRegChangeListener(RegChangeListener listener) {
this.listenerList.remove(RegChangeListener.class, listener);
@ -241,45 +263,41 @@ public class RegPane extends BasicPane {
public class PhoneRegEvent extends EventObject {
private String phoneRegString;
public PhoneRegEvent(Object source, String phoneRegString) {
super(source);
this.setPhoneRegString(phoneRegString);
}
public void setPhoneRegString(String phoneRegString) {
this.phoneRegString = phoneRegString;
}
public String getPhoneRegString() {
return phoneRegString;
}
}
public class RegChangeEvent extends EventObject {
private String regString;
public RegChangeEvent(Object source, String regString) {
super(source);
this.setRegString(regString);
}
public void setRegString(String regString) {
this.regString = regString;
}
public String getRegString() {
return regString;
}
}
public interface PhoneRegListener extends EventListener {
public interface PhoneRegListener extends EventListener{
/**
* 电话规则变化监听
*
* @param e 变化事件
*
*
* @date 2014-12-3-下午7:29:01
*
*/
void phoneRegChangeAction(PhoneRegEvent e);
@ -290,29 +308,28 @@ public class RegPane extends BasicPane {
/**
* 正则表达规则变化监听
*
*
* @date 2014-12-3-下午7:29:01
*
*/
void regChangeAction();
}
protected void firePhoneRegAction(String phoneReg) {
Object[] listeners = listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == PhoneRegListener.class) {
((PhoneRegListener) listeners[i + 1]).phoneRegChangeAction(new PhoneRegEvent(this, phoneReg));
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==PhoneRegListener.class) {
((PhoneRegListener)listeners[i+1]).phoneRegChangeAction(new PhoneRegEvent(this , phoneReg));
}
}
}
protected void fireRegChangeAction() {
Object[] listeners = listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == RegChangeListener.class) {
((RegChangeListener) listeners[i + 1]).regChangeAction();
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==RegChangeListener.class) {
((RegChangeListener)listeners[i+1]).regChangeAction();
}
}
}
private class RegPhonePane extends DisplayPane {
private static final String EMB_REG1 = "025-85679591";
private static final String EMB_REG2 = "02585679591";
@ -322,19 +339,20 @@ public class RegPane extends BasicPane {
private UIComboBox dataTypeComboBox;
private final String[] dataType = {EMB_REG1, EMB_REG2, EMB_REG3, Inter.getLocText("FR-Designer_Custom")};
DefaultComboBoxModel DefaultComboBoxModel = new DefaultComboBoxModel(dataType);
DefaultComboBoxModel DefaultComboBoxModel= new DefaultComboBoxModel(dataType);
public RegPhonePane() {
this.setLayout(FRGUIPaneFactory.createLabelFlowLayout());
this.add(new UILabel(Inter.getLocText("FR-Designer_Data_Type") + ":"));
this.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 5));
this.setLayout(FRGUIPaneFactory.createBorderLayout());
dataTypeComboBox = new UIComboBox(DefaultComboBoxModel);
JTextField editFiled = (JTextField) (dataTypeComboBox.getEditor().getEditorComponent());
JTextField editFiled = (JTextField)(dataTypeComboBox.getEditor().getEditorComponent());
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(new Component[][]{new Component[]{new UILabel(Inter.getLocText("FR-Designer_Data_Type")), dataTypeComboBox}}, TableLayoutHelper.FILL_LASTCOLUMN, 18, 7);
this.add(panel);
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])) {
if(e.getStateChange() == ItemEvent.SELECTED) {
if(ComparatorUtils.equals(e.getItem(), dataType[3])) {
dataTypeComboBox.setSelectedItem(null);
dataTypeComboBox.setEditable(true);
firePhoneRegAction(EMB_REG1);
@ -347,9 +365,7 @@ public class RegPane extends BasicPane {
});
dataTypeComboBox.setSelectedIndex(0);
firePhoneRegAction(dataTypeComboBox.getSelectedItem().toString());
this.add(dataTypeComboBox);
}
@Override
protected String title4PopupWindow() {
return "PHONE";
@ -357,17 +373,17 @@ public class RegPane extends BasicPane {
@Override
public void populate(RegExp regRex) {
if (!(regRex instanceof PhoneReg)) {
return;
if(!(regRex instanceof PhoneReg)) {
return ;
}
String regstr = ((PhoneReg) regRex).getRegString();
if (checkEmbedded(regstr)) {
String regstr = ((PhoneReg)regRex).getRegString();
if (checkEmbedded(regstr)){
DefaultComboBoxModel.addElement(regstr);
}
dataTypeComboBox.setSelectedItem(((PhoneReg) regRex).getRegString());
dataTypeComboBox.setSelectedItem(((PhoneReg)regRex).getRegString());
}
private boolean checkEmbedded(String regstr) {
private boolean checkEmbedded(String regstr){
return !ComparatorUtils.equals(EMB_REG1, regstr) &&
!ComparatorUtils.equals(EMB_REG2, regstr) &&
!ComparatorUtils.equals(EMB_REG3, regstr);
@ -376,7 +392,7 @@ public class RegPane extends BasicPane {
@Override
public RegExp update() {
PhoneReg regRex = new PhoneReg();
regRex.setRegString((String) (dataTypeComboBox.getSelectedItem()));
regRex.setRegString((String)(dataTypeComboBox.getSelectedItem()));
return regRex;
}
}
@ -385,22 +401,25 @@ public class RegPane extends BasicPane {
private UISpinner minLenSpinner;
private UISpinner maxLenSpinner;
public RegLengthPane() {
this.setLayout(new BorderLayout());
public RegLengthPane(){
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 5));
this.setPreferredSize(new Dimension(210, 56));
minLenSpinner = new UISpinner(0, Integer.MAX_VALUE, 1, 0);
maxLenSpinner = new UISpinner(0, Integer.MAX_VALUE, 1, 0);
double f = TableLayout.FILL;
double p = TableLayout.PREFERRED;
Component[][] components = new Component[][]{
new Component[]{new UILabel(Inter.getLocText("FR-Designer_Reg_Min_Length")), minLenSpinner},
new Component[]{new UILabel(Inter.getLocText("FR-Designer_Reg_Max_Length")), maxLenSpinner},
new Component[]{new UILabel(Inter.getLocText("FR-Designer_Reg_Min_Length") + ":"), minLenSpinner },
new Component[]{new UILabel(Inter.getLocText("FR-Designer_Reg_Max_Length") + ":"), maxLenSpinner},
};
double[] rowSize = {p, p};
double[] columnSize = {p, f};
int[][] rowCount = {{1, 1}, {1, 1}};
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, 8, 5);
double[] columnSize = {p,f};
int[][] rowCount = {{1, 1},{1, 1}};
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_SMALL, LayoutConstants.VGAP_MEDIUM);
this.add(panel);
this.add(panel, BorderLayout.CENTER);
}
@Override
@ -410,20 +429,20 @@ public class RegPane extends BasicPane {
@Override
public void populate(RegExp regRex) {
if (!(regRex instanceof LengthReg)) {
if (!(regRex instanceof LengthReg)){
return;
}
int minLength = ((LengthReg) regRex).getMinLen();
int maxLength = ((LengthReg) regRex).getMaxLen();
int minLength = ((LengthReg)regRex).getMinLen();
int maxLength = ((LengthReg)regRex).getMaxLen();
minLenSpinner.setValue(minLength);
maxLenSpinner.setValue(maxLength);
}
@Override
public RegExp update() {
int startLength = ((Number) minLenSpinner.getValue()).intValue();
int endLength = ((Number) maxLenSpinner.getValue()).intValue();
int startLength = ((Number)minLenSpinner.getValue()).intValue();
int endLength = ((Number)maxLenSpinner.getValue()).intValue();
LengthReg regRex = new LengthReg();
regRex.setMinLen(startLength);
regRex.setMaxLen(endLength);
@ -432,22 +451,14 @@ public class RegPane extends BasicPane {
}
}
private static class CustomRegRexPane extends DisplayPane {
private static class CustomRegRexPane extends DisplayPane{
private UITextField regTextField;
public CustomRegRexPane() {
this.setLayout(new BorderLayout());
regTextField = new UITextField(12);
double f = TableLayout.FILL;
double p = TableLayout.PREFERRED;
Component[][] components = new Component[][]{
new Component[]{new UILabel(Inter.getLocText("FR-Designer_Reg_Expressions")), regTextField},
};
double[] rowSize = {p};
double[] columnSize = {p, f};
int[][] rowCount = {{1, 1}};
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, 2, 1);
public CustomRegRexPane(){
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 5));
regTextField = new UITextField();
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(new Component[][]{new Component[]{new UILabel(Inter.getLocText("FR-Designer_Reg_Expressions")), regTextField}}, TableLayoutHelper.FILL_LASTCOLUMN, 18, 7);
this.add(panel);
}
@ -458,7 +469,7 @@ public class RegPane extends BasicPane {
@Override
public void populate(RegExp regRex) {
if (!(regRex instanceof CustomReg)) {
if (!(regRex instanceof CustomReg)){
return;
}
regTextField.setText(regRex.toRegText());
@ -474,26 +485,77 @@ public class RegPane extends BasicPane {
}
}
ListCellRenderer listCellRender = new UIComboBoxRenderer() {
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
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof NoneReg) {
if (value instanceof NoneReg){
this.setText(Inter.getLocText("FR-Designer_None"));
} else if (value instanceof LengthReg) {
} else if (value instanceof LengthReg){
this.setText(Inter.getLocText("FR-Designer_Length"));
} else if (value instanceof MailReg) {
} else if (value instanceof MailReg){
this.setText(Inter.getLocText("FR-Designer_Email"));
} else if (value instanceof PhoneReg) {
} else if (value instanceof PhoneReg){
this.setText(Inter.getLocText("FR-Designer_Phone"));
} else if (value instanceof MobileReg) {
this.setText(Inter.getLocText("FR-Designer_MobilePhone"));
} else if (value instanceof IDCardReg) {
} else if (value instanceof IDCardReg){
this.setText(Inter.getLocText("FR-Designer_IDCard"));
} else if (value instanceof PostCardReg) {
} else if (value instanceof PostCardReg){
this.setText(Inter.getLocText("FR-Designer_PostCode"));
} else if (value instanceof CustomReg) {
} else if (value instanceof CustomReg){
this.setText(Inter.getLocText("FR-Designer_Custom"));
}
return this;

Loading…
Cancel
Save