[kaffe] CVS kaffe (dalibor): Resynced with GNU Classpath: Added JSpinner

Kaffe CVS cvs-commits at kaffe.org
Sun Aug 15 14:04:09 PDT 2004


PatchSet 5066 
Date: 2004/08/15 20:50:38
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: Added JSpinner

2004-08-15  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/javax/swing/AbstractSpinnerModel.java,
        libraries/javalib/javax/swing/JSpinner.java,
        libraries/javalib/javax/swing/SpinnerNumberModel.java,
        libraries/javalib/javax/swing/plaf/basic/BasicSpinnerUI.java:
        New files. Taken from GNU Classpath.

        * libraries/javalib/javax/swing/plaf/basic/BasicLookAndFeel.java:
        Resynced with GNU Classpath.

        2004-08-14  Ka-Hing Cheung  <kahing at javabsp.org>

        * javax/swing/AbstractSpinnerModel.java,
        javax/swing/JSpinner.java,
        javax/swing/SpinnerNumberModel.java,
        javax/swing/plaf/basic/BasicSpinnerUI.java:
        New files.
        * javax/swing/plaf/basic/BasicLookAndFeel.java
        (initClassDefaults): Added defaults for BasicSpinnerUI.

Members: 
	ChangeLog:1.2624->1.2625 
	libraries/javalib/Makefile.am:1.219->1.220 
	libraries/javalib/Makefile.in:1.296->1.297 
	libraries/javalib/all.files:1.13->1.14 
	libraries/javalib/javax/swing/AbstractSpinnerModel.java:INITIAL->1.1 
	libraries/javalib/javax/swing/JSpinner.java:INITIAL->1.1 
	libraries/javalib/javax/swing/SpinnerNumberModel.java:INITIAL->1.1 
	libraries/javalib/javax/swing/plaf/basic/BasicLookAndFeel.java:1.3->1.4 
	libraries/javalib/javax/swing/plaf/basic/BasicSpinnerUI.java:INITIAL->1.1 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2624 kaffe/ChangeLog:1.2625
--- kaffe/ChangeLog:1.2624	Sun Aug 15 20:02:05 2004
+++ kaffe/ChangeLog	Sun Aug 15 20:50:38 2004
@@ -1,5 +1,26 @@
 2004-08-15  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/javax/swing/AbstractSpinnerModel.java,
+	libraries/javalib/javax/swing/JSpinner.java,
+	libraries/javalib/javax/swing/SpinnerNumberModel.java,
+	libraries/javalib/javax/swing/plaf/basic/BasicSpinnerUI.java:
+	New files. Taken from GNU Classpath.
+
+	* libraries/javalib/javax/swing/plaf/basic/BasicLookAndFeel.java:
+	Resynced with GNU Classpath.
+
+	2004-08-14  Ka-Hing Cheung  <kahing at javabsp.org>
+
+        * javax/swing/AbstractSpinnerModel.java,
+        javax/swing/JSpinner.java,
+        javax/swing/SpinnerNumberModel.java,
+        javax/swing/plaf/basic/BasicSpinnerUI.java:
+        New files.
+        * javax/swing/plaf/basic/BasicLookAndFeel.java
+        (initClassDefaults): Added defaults for BasicSpinnerUI.
+
+2004-08-15  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/clib/awt/classpath-gtk/gtk-peer/Makefile.am:
 	Add gtk_cairo_c_source_files when GTK_CAIRO is set.
 
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.219 kaffe/libraries/javalib/Makefile.am:1.220
--- kaffe/libraries/javalib/Makefile.am:1.219	Sat Aug 14 15:03:28 2004
+++ kaffe/libraries/javalib/Makefile.am	Sun Aug 15 20:50:40 2004
@@ -2967,6 +2967,7 @@
 	javax/swing/AbstractCellEditor.java \
 	javax/swing/AbstractListModel.java \
 	javax/swing/AbstractSet.java \
+	javax/swing/AbstractSpinnerModel.java \
 	javax/swing/Action.java \
 	javax/swing/ActionMap.java \
 	javax/swing/BorderFactory.java \
@@ -3031,6 +3032,7 @@
 	javax/swing/JScrollPane.java \
 	javax/swing/JSeparator.java \
 	javax/swing/JSlider.java \
+	javax/swing/JSpinner.java \
 	javax/swing/JSplitPane.java \
 	javax/swing/JTabbedPane.java \
 	javax/swing/JTable.java \
@@ -3066,6 +3068,7 @@
 	javax/swing/SizeRequirements.java \
 	javax/swing/SizeSequence.java \
 	javax/swing/SpinnerModel.java \
+	javax/swing/SpinnerNumberModel.java \
 	javax/swing/Spring.java \
 	javax/swing/SpringLayout.java \
 	javax/swing/SwingConstants.java \
@@ -3214,6 +3217,7 @@
 	javax/swing/plaf/basic/BasicScrollPaneUI.java \
 	javax/swing/plaf/basic/BasicSeparatorUI.java \
 	javax/swing/plaf/basic/BasicSliderUI.java \
+	javax/swing/plaf/basic/BasicSpinnerUI.java \
 	javax/swing/plaf/basic/BasicSplitPaneDivider.java \
 	javax/swing/plaf/basic/BasicSplitPaneUI.java \
 	javax/swing/plaf/basic/BasicTabbedPaneUI.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.296 kaffe/libraries/javalib/Makefile.in:1.297
--- kaffe/libraries/javalib/Makefile.in:1.296	Sun Aug 15 20:03:12 2004
+++ kaffe/libraries/javalib/Makefile.in	Sun Aug 15 20:50:40 2004
@@ -3497,6 +3497,7 @@
 	javax/swing/AbstractCellEditor.java \
 	javax/swing/AbstractListModel.java \
 	javax/swing/AbstractSet.java \
+	javax/swing/AbstractSpinnerModel.java \
 	javax/swing/Action.java \
 	javax/swing/ActionMap.java \
 	javax/swing/BorderFactory.java \
@@ -3561,6 +3562,7 @@
 	javax/swing/JScrollPane.java \
 	javax/swing/JSeparator.java \
 	javax/swing/JSlider.java \
+	javax/swing/JSpinner.java \
 	javax/swing/JSplitPane.java \
 	javax/swing/JTabbedPane.java \
 	javax/swing/JTable.java \
@@ -3596,6 +3598,7 @@
 	javax/swing/SizeRequirements.java \
 	javax/swing/SizeSequence.java \
 	javax/swing/SpinnerModel.java \
+	javax/swing/SpinnerNumberModel.java \
 	javax/swing/Spring.java \
 	javax/swing/SpringLayout.java \
 	javax/swing/SwingConstants.java \
@@ -3750,6 +3753,7 @@
 	javax/swing/plaf/basic/BasicScrollPaneUI.java \
 	javax/swing/plaf/basic/BasicSeparatorUI.java \
 	javax/swing/plaf/basic/BasicSliderUI.java \
+	javax/swing/plaf/basic/BasicSpinnerUI.java \
 	javax/swing/plaf/basic/BasicSplitPaneDivider.java \
 	javax/swing/plaf/basic/BasicSplitPaneUI.java \
 	javax/swing/plaf/basic/BasicTabbedPaneUI.java \
Index: kaffe/libraries/javalib/all.files
diff -u kaffe/libraries/javalib/all.files:1.13 kaffe/libraries/javalib/all.files:1.14
--- kaffe/libraries/javalib/all.files:1.13	Mon Aug  9 14:38:03 2004
+++ kaffe/libraries/javalib/all.files	Sun Aug 15 20:50:43 2004
@@ -2485,6 +2485,7 @@
 javax/swing/AbstractCellEditor.java
 javax/swing/AbstractListModel.java
 javax/swing/AbstractSet.java
+javax/swing/AbstractSpinnerModel.java
 javax/swing/Action.java
 javax/swing/ActionMap.java
 javax/swing/BorderFactory.java
@@ -2549,6 +2550,7 @@
 javax/swing/JScrollPane.java
 javax/swing/JSeparator.java
 javax/swing/JSlider.java
+javax/swing/JSpinner.java
 javax/swing/JSplitPane.java
 javax/swing/JTabbedPane.java
 javax/swing/JTable.java
@@ -2584,6 +2586,7 @@
 javax/swing/SizeRequirements.java
 javax/swing/SizeSequence.java
 javax/swing/SpinnerModel.java
+javax/swing/SpinnerNumberModel.java
 javax/swing/Spring.java
 javax/swing/SpringLayout.java
 javax/swing/SwingConstants.java
@@ -2726,6 +2729,7 @@
 javax/swing/plaf/basic/BasicScrollPaneUI.java
 javax/swing/plaf/basic/BasicSeparatorUI.java
 javax/swing/plaf/basic/BasicSliderUI.java
+javax/swing/plaf/basic/BasicSpinnerUI.java
 javax/swing/plaf/basic/BasicSplitPaneDivider.java
 javax/swing/plaf/basic/BasicSplitPaneUI.java
 javax/swing/plaf/basic/BasicTabbedPaneUI.java
===================================================================
Checking out kaffe/libraries/javalib/javax/swing/AbstractSpinnerModel.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/javax/swing/AbstractSpinnerModel.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/javax/swing/AbstractSpinnerModel.java	Sun Aug 15 21:04:08 2004
@@ -0,0 +1,115 @@
+/* AbstractSpinnerModel.java --
+   Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the 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, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.util.EventListener;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.EventListenerList;
+
+/**
+ * AbstractSpinnerModel
+ * @author	Ka-Hing Cheung
+ * @version	1.0
+ */
+public abstract class AbstractSpinnerModel implements SpinnerModel
+{
+  private ChangeEvent changeEvent = new ChangeEvent(this);
+  
+  protected EventListenerList listenerList = new EventListenerList();
+
+  /**
+   * Creates an <code>AbstractSpinnerModel</code>.
+   */
+  public AbstractSpinnerModel()
+  {
+  }
+
+  /**
+   * Adds a <code>ChangeListener</code>.
+   *
+   * @param listener the listener to add
+   */
+  public void addChangeListener(ChangeListener listener)
+  {
+    listenerList.add(ChangeListener.class, listener);
+  }
+
+  /**
+   * Gets all the listeners that are of a particular type.
+   *
+   * @param c the type of listener
+   * @return the listeners that are of the specific type
+   */
+  public EventListener[] getListeners(Class c)
+  {
+    return listenerList.getListeners(c);
+  }
+
+  /**
+   * Gets all the <code>ChangeListener</code>s.
+   *
+   * @return all the <code>ChangeListener</code>s
+   */
+  public ChangeListener[] getChangeListeners()
+  {
+    return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
+  }
+
+  /**
+   * Remove a particular listener.
+   *
+   * @param listener the listener to remove
+   */
+  public void removeChangeListener(ChangeListener listener)
+  {
+    listenerList.remove(ChangeListener.class, listener);
+  }
+
+  /**
+   * Fires a <code>ChangeEvent</code> to all the <code>ChangeListener</code>s
+   * added to this model
+   */
+  protected void fireStateChanged()
+  {
+    ChangeListener[] listeners = getChangeListeners();
+
+    for(int i = 0; i < listeners.length; ++i)
+      listeners[i].stateChanged(changeEvent);
+  }
+}
===================================================================
Checking out kaffe/libraries/javalib/javax/swing/JSpinner.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/javax/swing/JSpinner.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/javax/swing/JSpinner.java	Sun Aug 15 21:04:08 2004
@@ -0,0 +1,374 @@
+/* JSpinner.java --
+   Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the 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, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.LayoutManager;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.text.DecimalFormat;
+import java.text.ParseException;
+import javax.swing.border.EtchedBorder;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.EventListenerList;
+import javax.swing.plaf.SpinnerUI;
+import java.util.EventListener;
+
+/**
+ * A JSpinner is a component which typically contains a numeric value and a
+ * way to manipulate the value.
+ *
+ * @author	Ka-Hing Cheung
+ * @version	1.0
+ */
+public class JSpinner extends JComponent 
+{
+  public static class StubEditor extends JLabel implements ChangeListener
+  {
+    private JLabel label;
+    private JButton up;
+    private JButton down;
+    private JSpinner spinner;
+    
+    public StubEditor(JSpinner spinner)
+    {
+      this.spinner = spinner;
+      setBorder(new EtchedBorder());
+      setHorizontalAlignment(SwingConstants.TRAILING);
+      stateChanged(null); /* fill in the label */
+    }
+
+    public void stateChanged(ChangeEvent evt)
+    {
+      setText(String.valueOf(spinner.getValue()));
+    }
+  }
+
+  public static class DefaultEditor extends JPanel
+    implements ChangeListener, PropertyChangeListener, LayoutManager
+  {
+    public DefaultEditor(JSpinner spinner)
+    {
+      spinner.addChangeListener(this);
+    } /* TODO */
+
+    public void commitEdit()
+    {
+    } /* TODO */
+
+    public void dismiss(JSpinner spinner)
+    {
+      spinner.removeChangeListener(this);
+    }
+
+    public JFormattedTextField getTextField()
+    {
+      return null;
+    } /* TODO */
+
+    public void layoutContainer(Container parent)
+    {
+
+    } /* TODO */
+
+    public Dimension minimumLayoutSize(Container parent)
+    {
+      return null;
+    } /* TODO */
+
+    public Dimension preferredLayoutSize(Container parent)
+    {
+      return null;
+    } /* TODO */
+
+    public void propertyChange(PropertyChangeEvent evt)
+    {
+
+    } /* TODO */
+
+    public void stateChanged(ChangeEvent evt)
+    {
+
+    } /* TODO */
+
+    /* no-ops */
+    public void removeLayoutComponent(Component child)
+    {
+    }
+
+    public void addLayoutComponent(String name, Component child)
+    {
+    }
+  }
+
+  public static class NumberEditor extends DefaultEditor
+  {
+    public NumberEditor(JSpinner spinner)
+    {
+      super(spinner);
+    }
+
+    public DecimalFormat getFormat()
+    {
+      return null;
+    }
+  }
+
+  private SpinnerModel model;
+  private JComponent editor;
+  private EventListenerList listenerList = new EventListenerList();
+  
+  private ChangeListener listener = new ChangeListener()
+    {
+      public void stateChanged(ChangeEvent evt)
+      {
+        fireStateChanged();
+      }
+    };
+
+  /**
+   * Creates a JSpinner with <code>SpinnerNumberModel</code>
+   *
+   * @see javax.swing.SpinnerNumberModel
+   */
+  public JSpinner()
+  {
+    this(new SpinnerNumberModel());
+  }
+
+  /**
+   * Creates a JSpinner with the specific model and sets the default editor
+   */
+  public JSpinner(SpinnerModel model)
+  {
+    this.model = model;
+    model.addChangeListener(listener);
+    setEditor(createEditor(model));
+    updateUI();
+  }
+
+  /**
+   * If the editor is <code>JSpinner.DefaultEditor</code>, then forwards the
+   * call to it, otherwise do nothing.
+   */
+  public void commitEdit() throws ParseException
+  {
+    if(editor instanceof DefaultEditor)
+      ((DefaultEditor)editor).commitEdit();
+  }
+
+  /**
+   * Gets the current editor
+   *
+   * @return the current editor
+   * @see #setEditor
+   */
+  public JComponent getEditor()
+  {
+    return editor;
+  }
+
+  /**
+   * Changes the current editor to the new editor. This methods should remove
+   * the old listeners (if any) and adds the new listeners (if any).
+   *
+   * @param editor the new editor
+   * @see #getEditor
+   */
+  public void setEditor(JComponent editor)
+  {
+    if(editor == null)
+      throw new IllegalArgumentException("editor may not be null");
+
+    if(this.editor instanceof DefaultEditor)
+      ((DefaultEditor)editor).dismiss(this);
+    else if(this.editor instanceof ChangeListener)
+      removeChangeListener((ChangeListener)this.editor);
+
+    if(editor instanceof ChangeListener)
+      addChangeListener((ChangeListener)editor);
+
+    this.editor = editor;
+  }
+
+  /**
+   * Gets the underly model.
+   *
+   * @return the underly model
+   */
+  public SpinnerModel getModel()
+  {
+    return model;
+  }
+
+  /**
+   * Gets the next value without changing the current value.
+   *
+   * @return the next value
+   * @see javax.swing.SpinnerModel#getNextValue
+   */
+  public Object getNextValue()
+  {
+    return model.getNextValue();
+  }
+
+  /**
+   * Gets the previous value without changing the current value.
+   *
+   * @return the previous value
+   * @see javax.swing.SpinnerModel#getPreviousValue
+   */
+  public Object getPreviousValue()
+  {
+    return model.getPreviousValue();
+  }
+
+  /**
+   * Gets the <code>SpinnerUI</code> that handles this spinner
+   *
+   * @return the <code>SpinnerUI</code>
+   */
+  public SpinnerUI getUI()
+  {
+    return (SpinnerUI)ui;
+  }
+
+  /**
+   * Gets the current value of the spinner, according to the underly model, not
+   * the UI.
+   *
+   * @return the current value
+   * @see javax.swing.SpinnerModel#getValue
+   */
+  public Object getValue()
+  {
+    return model.getValue();
+  }
+
+  /**
+   * This method returns a name to identify which look and feel class will be
+   * the UI delegate for this spinner.
+   *
+   * @return The UIClass identifier. "SpinnerUI"
+   */
+  public String getUIClassID()
+  {
+    return "SpinnerUI";
+  }
+
+  /**
+   * This method resets the spinner's UI delegate to the default UI for the
+   * current look and feel.
+   */
+  public void updateUI()
+  {
+    setUI((SpinnerUI) UIManager.getUI(this));
+  }
+
+  /**
+   * This method sets the spinner's UI delegate.
+   *
+   * @param ui The spinner's UI delegate.
+   */
+  public void setUI(SpinnerUI ui)
+  {
+    super.setUI(ui);
+  }
+
+  /**
+   * Adds a <code>ChangeListener</code> 
+   *
+   * @param listener the listener to add
+   */
+  public void addChangeListener(ChangeListener listener)
+  {
+    listenerList.add(ChangeListener.class, listener);
+  }
+
+  /**
+   * Remove a particular listener
+   *
+   * @param listener the listener to remove
+   */
+  public void removeChangeListener(ChangeListener listener)
+  {
+    listenerList.remove(ChangeListener.class, listener);
+  }
+
+  /**
+   * Gets all the <code>ChangeListener</code>s
+   *
+   * @return all the <code>ChangeListener</code>s
+   */
+  public ChangeListener[] getChangeListeners()
+  {
+    return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
+  }
+
+  /**
+   * Fires a <code>ChangeEvent</code> to all the <code>ChangeListener</code>s
+   * added to this <code>JSpinner</code>
+   */
+  protected void fireStateChanged()
+  {
+    ChangeEvent evt = new ChangeEvent(this);
+    ChangeListener[] listeners = getChangeListeners();
+
+    for(int i = 0; i < listeners.length; ++i)
+      listeners[i].stateChanged(evt);
+  }
+
+  /**
+   * Creates an editor for this <code>JSpinner</code>. Really, it should be a
+   * <code>JSpinner.DefaultEditor</code>, but since that should be implemented
+   * by a JFormattedTextField, and one is not written, I am just using a dummy
+   * one backed by a JLabel.
+   *
+   * @return the default editor
+   */
+  protected JComponent createEditor(SpinnerModel model)
+  {
+    return new StubEditor(this);
+  } /* TODO */
+}
===================================================================
Checking out kaffe/libraries/javalib/javax/swing/SpinnerNumberModel.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/javax/swing/SpinnerNumberModel.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/javax/swing/SpinnerNumberModel.java	Sun Aug 15 21:04:09 2004
@@ -0,0 +1,256 @@
+/* SpinnerNumberModel.java --
+   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the 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, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing;
+
+/**
+ * SpinnerNumberModel
+ * @author	Ka-Hing Cheung
+ * @version	1.0
+ */
+public class SpinnerNumberModel extends AbstractSpinnerModel
+{
+  private Number value;
+  private Comparable minimum;
+  private Comparable maximum;
+  private Number stepSize;
+
+  /**
+   * Creates a <code>SpinnerNumberModel</code> with initial value 0, step 1,
+   * and no maximum nor minimum.
+   */
+  public SpinnerNumberModel()
+  {
+    this(new Integer(0), null, null, new Integer(1));
+  }
+
+  /**
+   * Creates a <code>SpinnerNumberModel</code> with double precision
+   *
+   * @param value the initial value
+   * @param minimum the minimum value
+   * @param maximum the maximum value
+   * @param stepSize the step size
+   * @throws IllegalArgumentException if minimum &lt;= value &lt;= maximum does not
+   *                                  hold
+   */
+  public SpinnerNumberModel(double value, double minimum, double maximum,
+                            double stepSize)
+  {
+    this(new Double(value), new Double(minimum), new Double(maximum),
+         new Double(stepSize));
+  }
+
+  /**
+   * Creates a <code>SpinnerNumberModel</code> with integer precision
+   *
+   * @param value the initial value
+   * @param minimum the minimum value
+   * @param maximum the maximum value
+   * @param stepSize the step size
+   * @throws IllegalArgumentException if minimum &lt;= value &lt;= maximum does not
+   *                                  hold
+   */
+  public SpinnerNumberModel(int value, int minimum, int maximum, int stepSize)
+  {
+    this(new Integer(value), new Integer(minimum), new Integer(maximum),
+         new Integer(stepSize));
+  }
+
+  /**
+   * Creates a <code>SpinnerNumberModel</code> with <code>Number</code>s and
+   * <code>Comparable</code>s.
+   *
+   * @param value the initial value
+   * @param minimum the minimum value, if null there's no minimum
+   * @param maximum the maximum value, if null there's no maximum
+   * @param stepSize the step size
+   * @throws IllegalArgumentException if minimum &lt;= value &lt;= maximum does not
+   *                                  hold
+   */
+  public SpinnerNumberModel(Number value, Comparable minimum, 
+                            Comparable maximum, Number stepSize)
+  {
+    if(stepSize == null)
+      throw new IllegalArgumentException("stepSize may not be null");
+    if(value == null)
+      throw new IllegalArgumentException("value may not be null");
+    if(minimum != null)
+      {
+	if(minimum.compareTo(value) > 0)
+	 throw new IllegalArgumentException("minimum is not <= value");
+      }
+    else
+      {
+	minimum = new Comparable() 
+	  {
+	    public int compareTo(Object obj)
+	    {
+	      return -1;
+	    }
+	  };
+      }
+    
+    if(maximum != null)
+      {
+	if(maximum.compareTo(value) < 0)
+	  throw new IllegalArgumentException("maximum is not >= value");
+      }
+    else
+      {
+	maximum = new Comparable() 
+	  {
+	    public int compareTo(Object obj)
+	    {
+	      return 1;
+	    }
+	  };
+      }
+    
+    this.value = value;
+    this.stepSize = stepSize;
+    this.minimum = minimum;
+    this.maximum = maximum;
+  }
+
+  /**
+   * Sets the new value and fire a change event
+   *
+   * @param value the new value
+   * @throws IllegalArgumentException if minimum &lt;= value &lt;= maximum does not
+   *                                  hold
+   */
+  public void setValue(Object value)
+  {
+    if(! (value instanceof Number))
+      throw new IllegalArgumentException("value must be a Number");
+
+    this.value = (Number) value;
+    fireStateChanged();
+  }
+
+  /**
+   * Gets the current value
+   *
+   * @return the current value
+   */
+  public Object getValue()
+  {
+    return value;
+  }
+
+  /**
+   * Gets the next value without changing the current value, or null if the
+   * current value is maximum.
+   *
+   * @return the next value
+   */
+  public Object getNextValue()
+  {
+    Number num;
+
+    if(value instanceof Double)
+      {
+        num = new Double(value.doubleValue() + stepSize.doubleValue());
+      }
+    else if(value instanceof Float)
+      {
+        num = new Double(value.floatValue() + stepSize.floatValue());
+      }
+    else if(value instanceof Long)
+      {
+        num = new Long(value.longValue() + stepSize.longValue());
+      }
+    else if(value instanceof Integer)
+      {
+        num = new Integer(value.intValue() + stepSize.intValue());
+      }
+    else if(value instanceof Short)
+      {
+        num = new Short((short) (value.shortValue() + stepSize.shortValue()));
+      }
+    else
+      {
+        num = new Byte((byte) (value.byteValue() + stepSize.byteValue()));
+      }
+
+    return maximum.compareTo(num) >= 0 ? num : null;
+  }
+
+  /**
+   * Gets the previous value without changing the current value, or null if the
+   * current value is minimum.
+   *
+   * @return the previous value
+   */
+  public Object getPreviousValue()
+  {
+    Number num;
+
+    if(value instanceof Double)
+      {
+        num = new Double(value.doubleValue() - stepSize.doubleValue());
+      }
+    else if(value instanceof Float)
+      {
+        num = new Double(value.floatValue() - stepSize.floatValue());
+      }
+    else if(value instanceof Long)
+      {
+        num = new Long(value.longValue() - stepSize.longValue());
+      }
+    else if(value instanceof Integer)
+      {
+        num = new Integer(value.intValue() - stepSize.intValue());
+      }
+    else if(value instanceof Short)
+      {
+        num = new Short((short) (value.shortValue() - stepSize.shortValue()));
+      }
+    else
+      {
+        num = new Byte((byte) (value.byteValue() - stepSize.byteValue()));
+      }
+
+    return maximum.compareTo(num) >= 0 ? num : null;
+  }
+
+  public Number getNumber()
+  {
+    return value;
+  }
+}
Index: kaffe/libraries/javalib/javax/swing/plaf/basic/BasicLookAndFeel.java
diff -u kaffe/libraries/javalib/javax/swing/plaf/basic/BasicLookAndFeel.java:1.3 kaffe/libraries/javalib/javax/swing/plaf/basic/BasicLookAndFeel.java:1.4
--- kaffe/libraries/javalib/javax/swing/plaf/basic/BasicLookAndFeel.java:1.3	Sun Aug  8 19:46:07 2004
+++ kaffe/libraries/javalib/javax/swing/plaf/basic/BasicLookAndFeel.java	Sun Aug 15 20:50:44 2004
@@ -131,6 +131,7 @@
       "SeparatorUI", "javax.swing.plaf.basic.BasicSeparatorUI",
       "SliderUI", "javax.swing.plaf.basic.BasicSliderUI",
       "SplitPaneUI", "javax.swing.plaf.basic.BasicSplitPaneUI",
+      "SpinnerUI", "javax.swing.plaf.basic.BasicSpinnerUI",
       "StandardDialogUI", "javax.swing.plaf.basic.BasicStandardDialogUI",
       "TabbedPaneUI", "javax.swing.plaf.basic.BasicTabbedPaneUI",
       "TableHeaderUI", "javax.swing.plaf.basic.BasicTableHeaderUI",
===================================================================
Checking out kaffe/libraries/javalib/javax/swing/plaf/basic/BasicSpinnerUI.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/javax/swing/plaf/basic/BasicSpinnerUI.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/javax/swing/plaf/basic/BasicSpinnerUI.java	Sun Aug 15 21:04:09 2004
@@ -0,0 +1,508 @@
+/* SpinnerUI.java --
+   Copyright (C) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the 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, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from

*** Patch too long, truncated ***




More information about the kaffe mailing list