Browse Source

基础控件类抽取需要的代码单独作一个方法,在子类中重写

master
Lee 9 years ago
parent
commit
758e1f73ad
  1. 21
      designer_base/src/com/fr/design/mainframe/widget/editors/FormattedEditor.java
  2. 23
      designer_form/src/com/fr/design/mainframe/widget/editors/DoubleEditor.java

21
designer_base/src/com/fr/design/mainframe/widget/editors/FormattedEditor.java

@ -4,6 +4,7 @@ import java.awt.BorderLayout;
import java.awt.Component; import java.awt.Component;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.text.Format; import java.text.Format;
import java.text.ParseException; import java.text.ParseException;
@ -32,17 +33,21 @@ public class FormattedEditor extends AbstractPropertyEditor {
textField = new JFormattedTextField(format); textField = new JFormattedTextField(format);
panel.add(textField, BorderLayout.CENTER); panel.add(textField, BorderLayout.CENTER);
textField.setBorder(null); textField.setBorder(null);
textField.addKeyListener(new KeyAdapter() { textField.addKeyListener(createKeyListener());
}
protected KeyListener createKeyListener() {
return new KeyAdapter() {
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
try { try {
textField.commitEdit(); textField.commitEdit();
} catch (ParseException e1) {
return; return;
} catch (ParseException e1) { }
return; firePropertyChanged();
} }
} };
});
} }
@Override @Override

23
designer_form/src/com/fr/design/mainframe/widget/editors/DoubleEditor.java

@ -1,11 +1,34 @@
package com.fr.design.mainframe.widget.editors; package com.fr.design.mainframe.widget.editors;
import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.text.ParseException;
public class DoubleEditor extends FormattedEditor { public class DoubleEditor extends FormattedEditor {
private JFormattedTextField textField;
public DoubleEditor() { public DoubleEditor() {
super(NumberFormat.getNumberInstance()); super(NumberFormat.getNumberInstance());
textField = (JFormattedTextField) super.getCustomEditor();
}
@Override
public KeyListener createKeyListener() {
return new KeyAdapter() {
public void keyReleased(KeyEvent e) {
try {
textField.commitEdit();
return;
} catch (ParseException e1) {
return;
}
}
};
} }
@Override @Override

Loading…
Cancel
Save