From 2c7bd711c77ee96db0b2bde352c8d021027c054e Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 14 Jul 2016 17:11:35 +0800 Subject: [PATCH 1/3] new file: FillBugSpinner.java --- .../design/gui/ispinner/FillBugSpinner.java | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 designer_base/src/com/fr/design/gui/ispinner/FillBugSpinner.java diff --git a/designer_base/src/com/fr/design/gui/ispinner/FillBugSpinner.java b/designer_base/src/com/fr/design/gui/ispinner/FillBugSpinner.java new file mode 100644 index 000000000..f4a83d046 --- /dev/null +++ b/designer_base/src/com/fr/design/gui/ispinner/FillBugSpinner.java @@ -0,0 +1,123 @@ +package com.fr.design.gui.ispinner; + +import java.text.ParseException; +import java.util.List; + +import javax.swing.JComponent; +import javax.swing.JFormattedTextField; +import javax.swing.JSpinner; +import javax.swing.SpinnerDateModel; +import javax.swing.SpinnerListModel; +import javax.swing.SpinnerModel; +import javax.swing.SpinnerNumberModel; +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.DefaultFormatterFactory; +import javax.swing.text.DocumentFilter; + +import com.fr.stable.StableUtils; +//_kerry: 用来修复Spinner输入数字自动填充的bug +public class FillBugSpinner extends UIBasicSpinner { + public FillBugSpinner(SpinnerModel model) { + super(model); + } + + protected JComponent createEditor(SpinnerModel model) { + if (model instanceof SpinnerDateModel) { + return new DateEditor(this); + } else if (model instanceof SpinnerListModel) { + return new FillBugEditor(this); + } else if (model instanceof SpinnerNumberModel) { + return new NumberEditor(this); + } else { + return new DefaultEditor(this); + } + } + + private class FillBugEditor extends DefaultEditor { + public FillBugEditor(JSpinner spinner) { + super(spinner); + if (!(spinner.getModel() instanceof SpinnerListModel)) { + throw new IllegalArgumentException( + "model not a SpinnerListModel"); + } + getTextField().setEditable(true); + getTextField().setFormatterFactory( + new DefaultFormatterFactory(new ListFormatter())); + } + + public SpinnerListModel getModel() { + return (SpinnerListModel) (getSpinner().getModel()); + } + + private class ListFormatter extends + JFormattedTextField.AbstractFormatter { + private DocumentFilter filter; + + public String valueToString(Object value) throws ParseException { + if (value == null) { + return ""; + } + return value.toString(); + } + + public Object stringToValue(String string) + throws ParseException { + //add将行数转换成ABC + return string; + } + + protected DocumentFilter getDocumentFilter() { + if (filter == null) { + filter = new Filter(); + } + return filter; + } + + private class Filter extends DocumentFilter { + public void replace(FilterBypass fb, int offset, + int length, String string, AttributeSet attrs) + throws BadLocationException { + if (string != null + && (offset + length) == fb.getDocument() + .getLength()) { + List list = getModel().getList(); + Object next = null; + for (int counter = 0; counter < list.size(); counter++) { + Object value = list.get(counter); + String str = value.toString(); + + if (str != null + && str.startsWith(fb.getDocument() + .getText(0, offset) + + string)) { + next = value; + break; + } + } + + String value = (next != null) ? next.toString() + : null; + + if (value != null) { + fb.remove(0, offset + length); + fb.insertString(0, value, null); + getFormattedTextField().select( + offset + string.length(), + value.length()); + return; + } + } + super.replace(fb, offset, length, string, attrs); + } + + public void insertString(FilterBypass fb, int offset, + String string, AttributeSet attr) + throws BadLocationException { + replace(fb, offset, 0, string, attr); + } + } + } + } + +} \ No newline at end of file From bd157e87caf7737bb0b1add78b1c40dd461f6cab Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 14 Jul 2016 17:18:22 +0800 Subject: [PATCH 2/3] modified: ../columnrow/ColumnRowPane.java --- .../src/com/fr/design/gui/columnrow/ColumnRowPane.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/designer_base/src/com/fr/design/gui/columnrow/ColumnRowPane.java b/designer_base/src/com/fr/design/gui/columnrow/ColumnRowPane.java index c599c5ce8..4df552986 100644 --- a/designer_base/src/com/fr/design/gui/columnrow/ColumnRowPane.java +++ b/designer_base/src/com/fr/design/gui/columnrow/ColumnRowPane.java @@ -22,6 +22,7 @@ import com.fr.design.event.UIObserverListener; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.ispinner.UIBasicSpinner; import com.fr.design.gui.ispinner.UpperCaseSpinner; +import com.fr.design.gui.ispinner.FillBugSpinner; import com.fr.general.ComparatorUtils; import com.fr.stable.ColumnRow; import com.fr.stable.StableUtils; @@ -119,7 +120,7 @@ public class ColumnRowPane extends JPanel implements UIObserver { protected void initRowSpinner() { - rowSpinner = new UIBasicSpinner((new SpinnerListModel(rowarray))) { + rowSpinner = new FillBugSpinner((new SpinnerListModel(rowarray))) { public boolean shouldResponseChangeListener() { return false; } From cf9bc90531395a6b0fc896ec64ad99e0808a51b1 Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 14 Jul 2016 17:48:56 +0800 Subject: [PATCH 3/3] modified: ../columnrow/ColumnRowPane.java --- .../src/com/fr/design/gui/columnrow/ColumnRowPane.java | 4 ++-- .../ispinner/{FillBugSpinner.java => ColumnRowSpinner.java} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename designer_base/src/com/fr/design/gui/ispinner/{FillBugSpinner.java => ColumnRowSpinner.java} (97%) diff --git a/designer_base/src/com/fr/design/gui/columnrow/ColumnRowPane.java b/designer_base/src/com/fr/design/gui/columnrow/ColumnRowPane.java index 4df552986..f0622bf85 100644 --- a/designer_base/src/com/fr/design/gui/columnrow/ColumnRowPane.java +++ b/designer_base/src/com/fr/design/gui/columnrow/ColumnRowPane.java @@ -22,7 +22,7 @@ import com.fr.design.event.UIObserverListener; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.ispinner.UIBasicSpinner; import com.fr.design.gui.ispinner.UpperCaseSpinner; -import com.fr.design.gui.ispinner.FillBugSpinner; +import com.fr.design.gui.ispinner.ColumnRowSpinner; import com.fr.general.ComparatorUtils; import com.fr.stable.ColumnRow; import com.fr.stable.StableUtils; @@ -120,7 +120,7 @@ public class ColumnRowPane extends JPanel implements UIObserver { protected void initRowSpinner() { - rowSpinner = new FillBugSpinner((new SpinnerListModel(rowarray))) { + rowSpinner = new ColumnRowSpinner((new SpinnerListModel(rowarray))) { public boolean shouldResponseChangeListener() { return false; } diff --git a/designer_base/src/com/fr/design/gui/ispinner/FillBugSpinner.java b/designer_base/src/com/fr/design/gui/ispinner/ColumnRowSpinner.java similarity index 97% rename from designer_base/src/com/fr/design/gui/ispinner/FillBugSpinner.java rename to designer_base/src/com/fr/design/gui/ispinner/ColumnRowSpinner.java index f4a83d046..adce548df 100644 --- a/designer_base/src/com/fr/design/gui/ispinner/FillBugSpinner.java +++ b/designer_base/src/com/fr/design/gui/ispinner/ColumnRowSpinner.java @@ -17,8 +17,8 @@ import javax.swing.text.DocumentFilter; import com.fr.stable.StableUtils; //_kerry: 用来修复Spinner输入数字自动填充的bug -public class FillBugSpinner extends UIBasicSpinner { - public FillBugSpinner(SpinnerModel model) { +public class ColumnRowSpinner extends UIBasicSpinner { + public ColumnRowSpinner(SpinnerModel model) { super(model); }