📄 jspinner.java
字号:
/* JSpinner.java -- Copyright (C) 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.Insets;import java.awt.LayoutManager;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.text.DecimalFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.plaf.SpinnerUI;import javax.swing.text.DateFormatter;/** * A JSpinner is a component which typically contains a numeric value and a * way to manipulate the value. * * @author Ka-Hing Cheung * * @since 1.4 */public class JSpinner extends JComponent{ /** * DOCUMENT ME! */ public static class DefaultEditor extends JPanel implements ChangeListener, PropertyChangeListener, LayoutManager { private JSpinner spinner; /** The JFormattedTextField that backs the editor. */ JFormattedTextField ftf; /** * For compatability with Sun's JDK 1.4.2 rev. 5 */ private static final long serialVersionUID = -5317788736173368172L; /** * Creates a new <code>DefaultEditor</code> object. * * @param spinner the <code>JSpinner</code> associated with this editor */ public DefaultEditor(JSpinner spinner) { super(); setLayout(this); this.spinner = spinner; ftf = new JFormattedTextField(); add(ftf); ftf.setValue(spinner.getValue()); spinner.addChangeListener(this); } /** * Returns the <code>JSpinner</code> object for this editor. */ public JSpinner getSpinner() { return spinner; } /** * DOCUMENT ME! */ public void commitEdit() throws ParseException { // TODO: Implement this properly. } /** * DOCUMENT ME! * * @param spinner DOCUMENT ME! */ public void dismiss(JSpinner spinner) { spinner.removeChangeListener(this); } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public JFormattedTextField getTextField() { return ftf; } /** * DOCUMENT ME! * * @param parent DOCUMENT ME! */ public void layoutContainer(Container parent) { Insets insets = getInsets(); Dimension size = getSize(); ftf.setBounds(insets.left, insets.top, size.width - insets.left - insets.right, size.height - insets.top - insets.bottom); } /** * DOCUMENT ME! * * @param parent DOCUMENT ME! * * @return DOCUMENT ME! */ public Dimension minimumLayoutSize(Container parent) { Insets insets = getInsets(); Dimension minSize = ftf.getMinimumSize(); return new Dimension(minSize.width + insets.left + insets.right, minSize.height + insets.top + insets.bottom); } /** * DOCUMENT ME! * * @param parent DOCUMENT ME! * * @return DOCUMENT ME! */ public Dimension preferredLayoutSize(Container parent) { Insets insets = getInsets(); Dimension prefSize = ftf.getPreferredSize(); return new Dimension(prefSize.width + insets.left + insets.right, prefSize.height + insets.top + insets.bottom); } /** * DOCUMENT ME! * * @param event DOCUMENT ME! */ public void propertyChange(PropertyChangeEvent event) { // TODO: Implement this properly. } /** * DOCUMENT ME! * * @param event DOCUMENT ME! */ public void stateChanged(ChangeEvent event) { // TODO: Implement this properly. } public void removeLayoutComponent(Component child) { // Nothing to do here. } /** * DOCUMENT ME! * * @param name DOCUMENT ME! * @param child DOCUMENT ME! */ public void addLayoutComponent(String name, Component child) { // Nothing to do here. } } /** * DOCUMENT ME! */ public static class NumberEditor extends DefaultEditor { /** * For compatability with Sun's JDK */ private static final long serialVersionUID = 3791956183098282942L; /** * Creates a new NumberEditor object. * * @param spinner DOCUMENT ME! */ public NumberEditor(JSpinner spinner) { super(spinner); } /** * Creates a new NumberEditor object. * * @param spinner DOCUMENT ME! */ public NumberEditor(JSpinner spinner, String decimalFormatPattern) { super(spinner); } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public DecimalFormat getFormat() { return null; } public SpinnerNumberModel getModel() { return (SpinnerNumberModel) getSpinner().getModel(); } } /** * A <code>JSpinner</code> editor used for the {@link SpinnerListModel}. * This editor uses a <code>JFormattedTextField</code> to edit the values * of the spinner. * * @author Roman Kennke (kennke@aicas.com) */ public static class ListEditor extends DefaultEditor { /** * Creates a new instance of <code>ListEditor</code>. * * @param spinner the spinner for which this editor is used */ public ListEditor(JSpinner spinner) { super(spinner); } public SpinnerListModel getModel() { return (SpinnerListModel) getSpinner().getModel(); } } /** * An editor class for a <code>JSpinner</code> that is used * for displaying and editing dates (e.g. that uses * <code>SpinnerDateModel</code> as model). * * The editor uses a {@link JTextField} with the value * displayed by a {@link DateFormatter} instance. */ public static class DateEditor extends DefaultEditor { /** The serialVersionUID. */ private static final long serialVersionUID = -4279356973770397815L; /** The DateFormat instance used to format the date. */ SimpleDateFormat dateFormat; /** * Creates a new instance of DateEditor for the specified * <code>JSpinner</code>. * * @param spinner the <code>JSpinner</code> for which to * create a <code>DateEditor</code> instance */ public DateEditor(JSpinner spinner) { super(spinner); init(new SimpleDateFormat()); } /** * Creates a new instance of DateEditor for the specified * <code>JSpinner</code> using the specified date format * pattern. * * @param spinner the <code>JSpinner</code> for which to * create a <code>DateEditor</code> instance * @param dateFormatPattern the date format to use
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -