1 /*
2 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1185 * argument to <code>DecimalFormat</code>
1186 *
1187 * @see #getTextField
1188 * @see SpinnerNumberModel
1189 * @see java.text.DecimalFormat
1190 */
1191 public NumberEditor(JSpinner spinner, String decimalFormatPattern) {
1192 this(spinner, new DecimalFormat(decimalFormatPattern));
1193 }
1194
1195
1196 /**
1197 * Construct a <code>JSpinner</code> editor that supports displaying
1198 * and editing the value of a <code>SpinnerNumberModel</code>
1199 * with a <code>JFormattedTextField</code>. <code>This</code>
1200 * <code>NumberEditor</code> becomes both a <code>ChangeListener</code>
1201 * on the spinner and a <code>PropertyChangeListener</code>
1202 * on the new <code>JFormattedTextField</code>.
1203 *
1204 * @param spinner the spinner whose model <code>this</code> editor will monitor
1205 * @param decimalFormatPattern the initial pattern for the
1206 * <code>DecimalFormat</code> object that's used to display
1207 * and parse the value of the text field.
1208 * @exception IllegalArgumentException if the spinners model is not
1209 * an instance of <code>SpinnerNumberModel</code>
1210 *
1211 * @see #getTextField
1212 * @see SpinnerNumberModel
1213 * @see java.text.DecimalFormat
1214 */
1215 private NumberEditor(JSpinner spinner, DecimalFormat format) {
1216 super(spinner);
1217 if (!(spinner.getModel() instanceof SpinnerNumberModel)) {
1218 throw new IllegalArgumentException(
1219 "model not a SpinnerNumberModel");
1220 }
1221
1222 SpinnerNumberModel model = (SpinnerNumberModel)spinner.getModel();
1223 NumberFormatter formatter = new NumberEditorFormatter(model,
1224 format);
1225 DefaultFormatterFactory factory = new DefaultFormatterFactory(
|
1 /*
2 * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1185 * argument to <code>DecimalFormat</code>
1186 *
1187 * @see #getTextField
1188 * @see SpinnerNumberModel
1189 * @see java.text.DecimalFormat
1190 */
1191 public NumberEditor(JSpinner spinner, String decimalFormatPattern) {
1192 this(spinner, new DecimalFormat(decimalFormatPattern));
1193 }
1194
1195
1196 /**
1197 * Construct a <code>JSpinner</code> editor that supports displaying
1198 * and editing the value of a <code>SpinnerNumberModel</code>
1199 * with a <code>JFormattedTextField</code>. <code>This</code>
1200 * <code>NumberEditor</code> becomes both a <code>ChangeListener</code>
1201 * on the spinner and a <code>PropertyChangeListener</code>
1202 * on the new <code>JFormattedTextField</code>.
1203 *
1204 * @param spinner the spinner whose model <code>this</code> editor will monitor
1205 * @param format the initial pattern for the
1206 * <code>DecimalFormat</code> object that's used to display
1207 * and parse the value of the text field.
1208 * @exception IllegalArgumentException if the spinners model is not
1209 * an instance of <code>SpinnerNumberModel</code>
1210 *
1211 * @see #getTextField
1212 * @see SpinnerNumberModel
1213 * @see java.text.DecimalFormat
1214 */
1215 private NumberEditor(JSpinner spinner, DecimalFormat format) {
1216 super(spinner);
1217 if (!(spinner.getModel() instanceof SpinnerNumberModel)) {
1218 throw new IllegalArgumentException(
1219 "model not a SpinnerNumberModel");
1220 }
1221
1222 SpinnerNumberModel model = (SpinnerNumberModel)spinner.getModel();
1223 NumberFormatter formatter = new NumberEditorFormatter(model,
1224 format);
1225 DefaultFormatterFactory factory = new DefaultFormatterFactory(
|