[Patch][gui] javax.swing

Michael Koch konqueror@gmx.de
Fri Dec 24 11:45:00 GMT 2004


Hi list,


I just commited the attached patch to fix stuff all over Swing.


Michael


2004-12-24  Michael Koch  <konqueror@gmx.de>

	* javax/swing/JFormattedTextField.java: Implemented.
	* javax/swing/JWindow.java
	(JWindow): New constructors.
	(initWindow): Renamed from initFrame.
	* javax/swing/UIDefaults.java
	(ActiveValue): Made interface static.
	(LazyValue): Likewise.
	* javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
	(TitlePaneLayout.TitlePaneLayout): New constructor.
	* javax/swing/plaf/basic/BasicSliderUI.java
	(ChangeHandler): Made public.
	(FocusHandler): Likewise.
	(PropertyChangeHandler): Likewise.
	(ScrollListener): Likewise.
	* javax/swing/plaf/basic/BasicTabbedPaneUI.java
	(FocusHandler): Likewise.
	(MouseHandler): Likewise.
	* javax/swing/plaf/basic/BasicTextPaneUI.java
	(BasicTextPaneUI): Extend BasicEditorPaneUI.
	* javax/swing/plaf/basic/BasicToolBarUI.java
	(BasicToolBarUI): Simplified. Reworked javadoc.
	(canDock): Simplified. Make public.
	(DockingListener): Made public.
	* javax/swing/text/JTextComponent.java
	(navigationFilter): New field.
	(getNavigationFilter): New method.
	(setNavigationFilter): Likewise.

-------------- next part --------------
Index: javax/swing/JFormattedTextField.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JFormattedTextField.java,v
retrieving revision 1.3.2.7
diff -u -r1.3.2.7 JFormattedTextField.java
--- javax/swing/JFormattedTextField.java	30 Nov 2004 08:16:19 -0000	1.3.2.7
+++ javax/swing/JFormattedTextField.java	24 Dec 2004 09:51:23 -0000
@@ -43,6 +43,8 @@
 import java.text.Format;
 import java.text.ParseException;
 
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
 import javax.swing.text.Document;
 import javax.swing.text.DocumentFilter;
 import javax.swing.text.NavigationFilter;
@@ -59,6 +61,8 @@
   {
     private static final long serialVersionUID = -5193212041738979680L;
     
+    private JFormattedTextField textField;
+    
     public AbstractFormatter ()
     {
       //Do nothing here.
@@ -72,7 +76,7 @@
 
     protected Action[] getActions ()
     {
-      throw new InternalError ("not implemented");
+      return textField.getActions();
     }
 
     protected DocumentFilter getDocumentFilter ()
@@ -82,32 +86,35 @@
 
     protected JFormattedTextField getFormattedTextField ()
     {
-      throw new InternalError ("not implemented");
+      return textField;
     }
 
     protected NavigationFilter getNavigationFilter ()
     {
-      throw new InternalError ("not implemented");
+      return textField.getNavigationFilter();
     }
 
-    public void install (JFormattedTextField ftf)
+    public void install(JFormattedTextField textField)
     {
-      throw new InternalError ("not implemented");
+      if (this.textField != null)
+	uninstall();
+      
+      this.textField = textField;
     }
 
     public void uninstall ()
     {
-      throw new InternalError ("not implemented");
+      this.textField = null;
     }
 
     protected void invalidEdit ()
     {
-      throw new InternalError ("not implemented");
+      textField.invalidEdit();
     }
 
     protected void setEditValid (boolean valid)
     {
-      throw new InternalError ("not implemented");
+      textField.editValid = valid;
     }
 
     public abstract Object stringToValue (String text)
@@ -127,16 +134,34 @@
     public abstract AbstractFormatter getFormatter (JFormattedTextField tf);
   }
 
+  static class FormatterFactoryWrapper extends AbstractFormatterFactory
+  {
+    AbstractFormatter formatter;
+
+    public FormatterFactoryWrapper(AbstractFormatter formatter)
+    {
+      this.formatter = formatter;
+    }
+
+    public AbstractFormatter getFormatter(JFormattedTextField tf)
+    {
+      return formatter;
+    }
+  }
+
   public static final int COMMIT = 0;
   public static final int COMMIT_OR_REVERT = 1;
   public static final int REVERT = 2;
   public static final int PERSIST = 3;
 
   private Object value;
+  private int focusLostBehavior = COMMIT_OR_REVERT;
+  private AbstractFormatterFactory formatterFactory;
+  private boolean editValid = true;
   
   public JFormattedTextField ()
   {
-    this((AbstractFormatterFactory) null);
+    this((AbstractFormatterFactory) null, null);
   }
 
   public JFormattedTextField (Format format)
@@ -146,7 +171,7 @@
 
   public JFormattedTextField (AbstractFormatter formatter)
   {
-    throw new InternalError ("not implemented");
+    this(new FormatterFactoryWrapper(formatter), null);
   }
 
   public JFormattedTextField (AbstractFormatterFactory factory)
@@ -156,7 +181,8 @@
 
   public JFormattedTextField (AbstractFormatterFactory factory, Object value)
   {
-    throw new InternalError ("not implemented");
+    this.formatterFactory = factory;
+    this.value = value;
   }
 
   public JFormattedTextField (Object value)
@@ -177,17 +203,20 @@
 
   public int getFocusLostBehaviour ()
   {
-    throw new InternalError ("not implemented");
+    return focusLostBehavior;
   }
 
   public AbstractFormatter getFormatter ()
   {
-    throw new InternalError ("not implemented");
+    if (formatterFactory == null)
+      return null;
+    
+    return formatterFactory.getFormatter(this);
   }
 
   public AbstractFormatterFactory getFormatterFactory ()
   {
-    throw new InternalError ("not implemented");
+    return formatterFactory;
   }
 
   public String getUIClassID ()
@@ -202,12 +231,12 @@
 
   protected void invalidEdit ()
   {
-    throw new InternalError ("not implemented");
+    UIManager.getLookAndFeel().provideErrorFeedback(this);
   }
 
   public boolean isEditValid ()
   {
-    throw new InternalError ("not implemented");
+    return editValid;
   }
 
   protected void processFocusEvent (FocusEvent evt)
@@ -215,33 +244,58 @@
     throw new InternalError ("not implemented");
   }
 
-  public void setDocument(Document newdoc)
+  public void setDocument(Document newDocument)
   {
-    Document olddoc = getDocument();
+    Document oldDocument = getDocument();
 
-    if (olddoc == newdoc)
+    if (oldDocument == newDocument)
       return;
     
-    super.setDocument(newdoc);
+    super.setDocument(newDocument);
   }
 
   public void setLostFocusBehavior (int behavior)
   {
-    throw new InternalError ("not implemented");
+    if (behavior != COMMIT
+	&& behavior != COMMIT_OR_REVERT
+	&& behavior != PERSIST
+	&& behavior != REVERT)
+      throw new IllegalArgumentException("invalid behavior");
+
+    this.focusLostBehavior = behavior;
   }
 
   protected void setFormatter (AbstractFormatter formatter)
   {
-    throw new InternalError ("not implemented");
+    AbstractFormatter oldFormatter = null;
+    
+    if (formatterFactory != null)
+      oldFormatter = formatterFactory.getFormatter(this);
+
+    if (oldFormatter == formatter)
+      return;
+
+    setFormatterFactory(new FormatterFactoryWrapper(formatter));
+    firePropertyChange("formatter", oldFormatter, formatter);
   }
 
   public void setFormatterFactory (AbstractFormatterFactory factory)
   {
-    throw new InternalError ("not implemented");
+    if (formatterFactory == factory)
+      return;
+    
+    AbstractFormatterFactory oldFactory = formatterFactory;
+    formatterFactory = factory;
+    firePropertyChange("formatterFactory", oldFactory, factory);
   }
 
   public void setValue (Object newValue)
   {
+    if (value == newValue)
+      return;
+    
+    Object oldValue = value;
     value = newValue;
+    firePropertyChange("value", oldValue, newValue);
   }
 }
Index: javax/swing/JWindow.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JWindow.java,v
retrieving revision 1.3.18.9
diff -u -r1.3.18.9 JWindow.java
--- javax/swing/JWindow.java	22 Dec 2004 21:40:29 -0000	1.3.18.9
+++ javax/swing/JWindow.java	24 Dec 2004 09:51:23 -0000
@@ -44,6 +44,7 @@
 import java.awt.Dimension;
 import java.awt.Frame;
 import java.awt.Graphics;
+import java.awt.GraphicsConfiguration;
 import java.awt.LayoutManager;
 import java.awt.Window;
 import java.awt.event.KeyEvent;
@@ -62,22 +63,42 @@
 {
   private static final long serialVersionUID = 5420698392125238833L;
   
+  private boolean checking;
+  
+  protected JRootPane rootPane;
   protected AccessibleContext accessibleContext;
 
   public JWindow()
   {
     super(SwingUtilities.getOwnerFrame());
+    windowInit();
   }
 
-  public JWindow(Frame f)
+  public JWindow(GraphicsConfiguration gc)
   {
-    super(f);
+    super(SwingUtilities.getOwnerFrame(), gc);
+    windowInit();
+  }
+  
+  public JWindow(Frame owner)
+  {
+    super(owner);
+    windowInit();
   }
 
-  private boolean checking;
-  protected JRootPane rootPane;
+  public JWindow(Window owner)
+  {
+    super(owner);
+    windowInit();
+  }
+
+  public JWindow(Window owner, GraphicsConfiguration gc)
+  {
+    super(owner, gc);
+    windowInit();
+  }
 
-  protected void frameInit()
+  protected void windowInit()
   {
     super.setLayout(new BorderLayout(1, 1));
     getRootPane(); // will do set/create
Index: javax/swing/UIDefaults.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/UIDefaults.java,v
retrieving revision 1.7.2.7
diff -u -r1.7.2.7 UIDefaults.java
--- javax/swing/UIDefaults.java	22 Oct 2004 12:41:18 -0000	1.7.2.7
+++ javax/swing/UIDefaults.java	24 Dec 2004 09:51:23 -0000
@@ -68,7 +68,7 @@
   private Locale defaultLocale;
   private PropertyChangeSupport propertyChangeSupport;
 
-  public interface ActiveValue
+  public static interface ActiveValue
   {
     Object createValue(UIDefaults table);
   }
@@ -92,7 +92,7 @@
     }
   }
 
-  public interface LazyValue
+  public static interface LazyValue
   {
     Object createValue(UIDefaults table);
   }
Index: javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 BasicInternalFrameTitlePane.java
--- javax/swing/plaf/basic/BasicInternalFrameTitlePane.java	23 Oct 2004 20:52:01 -0000	1.1.2.4
+++ javax/swing/plaf/basic/BasicInternalFrameTitlePane.java	24 Dec 2004 09:51:23 -0000
@@ -288,6 +288,14 @@
   protected class TitlePaneLayout implements LayoutManager
   {
     /**
+     * Creates a new <code>TitlePaneLayout</code> object.
+     */
+    public TitlePaneLayout()
+    {
+      // Do nothing.
+    }
+
+    /**
      * This method is called when adding a Component to the Container.
      *
      * @param name The name to reference the added Component by.
Index: javax/swing/plaf/basic/BasicSliderUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicSliderUI.java,v
retrieving revision 1.1.2.16
diff -u -r1.1.2.16 BasicSliderUI.java
--- javax/swing/plaf/basic/BasicSliderUI.java	23 Oct 2004 20:52:01 -0000	1.1.2.16
+++ javax/swing/plaf/basic/BasicSliderUI.java	24 Dec 2004 09:51:23 -0000
@@ -139,7 +139,7 @@
   /**
    * Helper class that listens to the {@link JSlider}'s model for changes.
    */
-  protected class ChangeHandler implements ChangeListener
+  public class ChangeHandler implements ChangeListener
   {
     /**
      * Called when the slider's model has been altered. The UI delegate should
@@ -182,7 +182,7 @@
   /**
    * Helper class that listens for focus events.
    */
-  protected class FocusHandler implements FocusListener
+  public class FocusHandler implements FocusListener
   {
     /**
      * Called when the {@link JSlider} has gained focus.  It should repaint
@@ -211,7 +211,7 @@
    * Helper class that listens for changes to the properties of the {@link
    * JSlider}.
    */
-  protected class PropertyChangeHandler implements PropertyChangeListener
+  public class PropertyChangeHandler implements PropertyChangeListener
   {
     /**
      * Called when one of the properties change. The UI should recalculate any
@@ -247,7 +247,7 @@
    * for listening to the timer and moving the thumb in the proper direction
    * every interval.
    */
-  protected class ScrollListener implements ActionListener
+  public class ScrollListener implements ActionListener
   {
     /** Indicates which direction the thumb should scroll. */
     private transient int direction;
Index: javax/swing/plaf/basic/BasicTabbedPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java,v
retrieving revision 1.3.16.15
diff -u -r1.3.16.15 BasicTabbedPaneUI.java
--- javax/swing/plaf/basic/BasicTabbedPaneUI.java	23 Oct 2004 20:52:01 -0000	1.3.16.15
+++ javax/swing/plaf/basic/BasicTabbedPaneUI.java	24 Dec 2004 09:51:24 -0000
@@ -84,7 +84,7 @@
   /**
    * A helper class that handles focus.
    */
-  protected class FocusHandler extends FocusAdapter
+  public class FocusHandler extends FocusAdapter
   {
     /**
      * This method is called when the component gains focus.
@@ -112,7 +112,7 @@
    * sets the index appropriately. In SCROLL_TAB_MODE, this class also
    * handles the mouse clicks on the scrolling buttons.
    */
-  protected class MouseHandler extends MouseAdapter
+  public class MouseHandler extends MouseAdapter
   {
     /**
      * This method is called when the mouse is pressed. The index cannot
Index: javax/swing/plaf/basic/BasicTextPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicTextPaneUI.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 BasicTextPaneUI.java
--- javax/swing/plaf/basic/BasicTextPaneUI.java	10 Nov 2004 07:19:49 -0000	1.1.2.1
+++ javax/swing/plaf/basic/BasicTextPaneUI.java	24 Dec 2004 09:51:24 -0000
@@ -46,15 +46,16 @@
 import javax.swing.text.PlainView;
 import javax.swing.text.View;
 
-public class BasicTextPaneUI extends BasicTextUI
+public class BasicTextPaneUI extends BasicEditorPaneUI
 {
-  public static ComponentUI createUI(JComponent comp)
+  public BasicTextPaneUI()
   {
-    return new BasicTextPaneUI();
+    // Do nothing here.
   }
 
-  public BasicTextPaneUI()
+  public static ComponentUI createUI(JComponent comp)
   {
+    return new BasicTextPaneUI();
   }
 
   public View create(Element elem)
Index: javax/swing/plaf/basic/BasicToolBarUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicToolBarUI.java,v
retrieving revision 1.1.2.11
diff -u -r1.1.2.11 BasicToolBarUI.java
--- javax/swing/plaf/basic/BasicToolBarUI.java	22 Oct 2004 12:41:25 -0000	1.1.2.11
+++ javax/swing/plaf/basic/BasicToolBarUI.java	24 Dec 2004 09:51:24 -0000
@@ -152,11 +152,11 @@
   private transient int cachedOrientation;
 
   /**
-   * This method creates a new BasicToolBarUI object for the given JToolBar.
+   * This method creates a new <code>BasicToolBarUI</code> object for the given JToolBar.
    */
   public BasicToolBarUI()
   {
-    super();
+    // Do nothing here.
   }
 
   /**
@@ -168,12 +168,9 @@
    *
    * @return Whether the JToolBar can dock.
    */
-  protected boolean canDock(Component c, Point p)
+  public boolean canDock(Component c, Point p)
   {
-    if (areaOfClick(c, p) != -1)
-      return true;
-
-    return false;
+    return areaOfClick(c, p) != -1;
   }
 
   /**
@@ -937,7 +934,7 @@
    * This is the MouseHandler class that allows the user to drag the JToolBar
    * in and out of the parent and dock it if it can.
    */
-  protected class DockingListener implements MouseInputListener
+  public class DockingListener implements MouseInputListener
   {
     /** Whether the JToolBar is being dragged. */
     protected boolean isDragging;
Index: javax/swing/text/JTextComponent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/JTextComponent.java,v
retrieving revision 1.4.2.27
diff -u -r1.4.2.27 JTextComponent.java
--- javax/swing/text/JTextComponent.java	16 Dec 2004 15:49:53 -0000	1.4.2.27
+++ javax/swing/text/JTextComponent.java	24 Dec 2004 09:51:24 -0000
@@ -651,6 +651,7 @@
   private static Hashtable keymaps = new Hashtable();
   private Keymap keymap;
   private char focusAccelerator = '\0';
+  private NavigationFilter navigationFilter;
   
   /**
    * Get a Keymap from the global keymap table, by name.
@@ -970,6 +971,7 @@
       }
     catch (BadLocationException e)
       {
+	// This can never happen.
       }
   }
 
@@ -1511,4 +1513,20 @@
   {
     return focusAccelerator;
   }
+
+  /**
+   * @since 1.4
+   */
+  public NavigationFilter getNavigationFilter()
+  {
+    return navigationFilter;
+  }
+
+  /**
+   * @since 1.4
+   */
+  public void setNavigationFilter(NavigationFilter filter)
+  {
+    navigationFilter = filter;
+  }
 }


More information about the Java-patches mailing list