Here comes some Basic LAF fixes, some of which I did on my way back from
FOSDEM and which have been lying around here since then. This are mostly
some optimizations to avoid unnecessary Rectangle creations.

Also included here is some _very_ basic support for HTML on Labels, based
on my previous work with HTML. The biggest problem remaining for now is
the layout, the labels are still layouted as if all the HTML code was
renderered, so it's much too wide. But you shouldn't see any <html>
tags on labels any more. :-)

2006-03-03  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicHTML.java
        (isHTMLString): Check for string beeing null.
        * javax/swing/plaf/basic/BasicInternalFrameUI.java
        (BasicInternalFrameListener.internalFrameActivated): Implemented.
        (BasicInternalFrameListener.internalFrameDeactivated): Implemented.
        (InternalFrameLayout): Don't touch the glass pane here.
        (installUI): Fix handling of glass pane.
        * javax/swing/plaf/basic/BasicLabelUI.java
        (vr): New field.
        (ir): New field.
        (tr): New field.
        (BasicLabelUI): Initialize new fields.
        (getPreferredSize): Avoid creating new Rectangles by using
        SwingUtilities method.
        (paint): Avoid creating new Rectangles by reusing
        new fields. Added some preliminary handling of HTML inside the
        label.
        (installComponents): Handle HTML by calling BasicHTML.updateRenderer.
        (uninstallComponents): Clear HTML renderer.
        (propertyChange): Check for HTML text and install renderer if
        appropriate.
        * javax/swing/plaf/basic/BasicListUI.java
        (getCellBounds): Avoid creating new Rectangle by using SwingUtilities
        method.
        * javax/swing/plaf/basic/BasicTextUI.java
        (RootView.getStartOffset): Implemented.
        (RootView.getEndOffset): Implemented.
        (RootView.getDocument): Implemented.

/Roman
Index: javax/swing/plaf/basic/BasicHTML.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicHTML.java,v
retrieving revision 1.3
diff -u -r1.3 BasicHTML.java
--- javax/swing/plaf/basic/BasicHTML.java	3 Mar 2006 10:19:34 -0000	1.3
+++ javax/swing/plaf/basic/BasicHTML.java	3 Mar 2006 11:02:10 -0000
@@ -423,7 +423,7 @@
   {
     // We consider a string to be HTML if it contains both the '<' and '>'
     // character at least once.
-    return s.contains("<") && s.contains(">");
+    return (s != null) && s.contains("<") && s.contains(">");
   }
 
   /**
Index: javax/swing/plaf/basic/BasicInternalFrameUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicInternalFrameUI.java,v
retrieving revision 1.26
diff -u -r1.26 BasicInternalFrameUI.java
--- javax/swing/plaf/basic/BasicInternalFrameUI.java	14 Feb 2006 22:44:53 -0000	1.26
+++ javax/swing/plaf/basic/BasicInternalFrameUI.java	3 Mar 2006 11:02:10 -0000
@@ -92,7 +92,7 @@
      */
     public void internalFrameActivated(InternalFrameEvent e)
     {
-      // FIXME: Implement.
+      frame.getGlassPane().setVisible(false);
     }
 
     /**
@@ -122,7 +122,7 @@
      */
     public void internalFrameDeactivated(InternalFrameEvent e)
     {
-      // FIXME: Implement.
+      frame.getGlassPane().setVisible(true);
     }
 
     /**
@@ -462,8 +462,6 @@
       dims.width -= insets.left + insets.right;
       dims.height -= insets.top + insets.bottom;
 
-      frame.getRootPane().getGlassPane().setBounds(0, 0, dims.width,
-                                                   dims.height);
       int nh = 0;
       int sh = 0;
       int ew = 0;
@@ -1128,14 +1126,15 @@
       {
         frame = (JInternalFrame) c;
 
-        ((JComponent) frame.getRootPane().getGlassPane()).setOpaque(false);
-        frame.getRootPane().getGlassPane().setVisible(true);
-
         installDefaults();
         installListeners();
         installComponents();
         installKeyboardActions();
 
+        ((JComponent) frame.getRootPane().getGlassPane()).setOpaque(false);
+        if (! frame.isSelected())
+          frame.getRootPane().getGlassPane().setVisible(true);
+
         frame.setOpaque(true);
         frame.invalidate();
       }
Index: javax/swing/plaf/basic/BasicLabelUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicLabelUI.java,v
retrieving revision 1.21
diff -u -r1.21 BasicLabelUI.java
--- javax/swing/plaf/basic/BasicLabelUI.java	24 Nov 2005 20:31:32 -0000	1.21
+++ javax/swing/plaf/basic/BasicLabelUI.java	3 Mar 2006 11:02:10 -0000
@@ -53,6 +53,7 @@
 import javax.swing.SwingUtilities;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.LabelUI;
+import javax.swing.text.View;
 
 /**
  * This is the Basic Look and Feel class for the JLabel.  One BasicLabelUI
@@ -64,11 +65,22 @@
   protected static BasicLabelUI labelUI;
 
   /**
+   * These fields hold the rectangles for the whole label,
+   * the icon and the text.
+   */
+  private Rectangle vr;
+  private Rectangle ir;
+  private Rectangle tr;
+
+  /**
    * Creates a new BasicLabelUI object.
    */
   public BasicLabelUI()
   {
     super();
+    vr = new Rectangle();
+    ir = new Rectangle();
+    tr = new Rectangle();
   }
 
   /**
@@ -99,13 +111,11 @@
   public Dimension getPreferredSize(JComponent c)
   {
     JLabel lab = (JLabel) c;
-    Rectangle vr = new Rectangle();
-    Rectangle ir = new Rectangle();
-    Rectangle tr = new Rectangle();
     Insets insets = lab.getInsets();
     FontMetrics fm = lab.getFontMetrics(lab.getFont());
     layoutCL(lab, fm, lab.getText(), lab.getIcon(), vr, ir, tr);
-    Rectangle cr = tr.union(ir);
+    Rectangle cr = SwingUtilities.computeUnion(tr.x, tr.y, tr.width, tr.height,
+                                               ir);
     return new Dimension(insets.left + cr.width + insets.right, insets.top
         + cr.height + insets.bottom);
 
@@ -148,11 +158,6 @@
   public void paint(Graphics g, JComponent c)
   {
     JLabel b = (JLabel) c;
-
-    Rectangle tr = new Rectangle();
-    Rectangle ir = new Rectangle();
-    Rectangle vr = new Rectangle();
-
     FontMetrics fm = g.getFontMetrics();
     vr = SwingUtilities.calculateInnerArea(c, vr);
 
@@ -168,13 +173,21 @@
     if (icon != null)
       icon.paintIcon(b, g, ir.x, ir.y);        
 
-    if (text != null && !text.equals(""))
-    {
-      if (b.isEnabled())
-        paintEnabledText(b, g, text, tr.x, tr.y + fm.getAscent());
-      else
-        paintDisabledText(b, g, text, tr.x, tr.y + fm.getAscent());
-    }
+    Object htmlRenderer = b.getClientProperty(BasicHTML.propertyKey);
+    if (htmlRenderer == null)
+      {
+        if (text != null && !text.equals(""))
+          {
+            if (b.isEnabled())
+              paintEnabledText(b, g, text, tr.x, tr.y + fm.getAscent());
+            else
+              paintDisabledText(b, g, text, tr.x, tr.y + fm.getAscent());
+          }
+      }
+    else
+      {
+        ((View) htmlRenderer).paint(g, tr);
+      }
   }
 
   /**
@@ -312,7 +325,7 @@
    */
   protected void installComponents(JLabel c)
   {
-    //FIXME: fix javadoc + implement.
+    BasicHTML.updateRenderer(c, c.getText());
   }
 
   /**
@@ -322,7 +335,8 @@
    */
   protected void uninstallComponents(JLabel c)
   {
-    //FIXME: fix javadoc + implement.
+    c.putClientProperty(BasicHTML.propertyKey, null);
+    c.putClientProperty(BasicHTML.documentBaseKey, null);
   }
 
   /**
@@ -402,6 +416,11 @@
    */
   public void propertyChange(PropertyChangeEvent e)
   {
-    // What to do here?
+    if (e.getPropertyName().equals("text"))
+      {
+        String text = (String) e.getNewValue();
+        JLabel l = (JLabel) e.getSource();
+        BasicHTML.updateRenderer(l, text);
+      }
   }
 }
Index: javax/swing/plaf/basic/BasicListUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicListUI.java,v
retrieving revision 1.54
diff -u -r1.54 BasicListUI.java
--- javax/swing/plaf/basic/BasicListUI.java	30 Jan 2006 13:47:15 -0000	1.54
+++ javax/swing/plaf/basic/BasicListUI.java	3 Mar 2006 11:02:10 -0000
@@ -64,6 +64,7 @@
 import javax.swing.ListModel;
 import javax.swing.ListSelectionModel;
 import javax.swing.LookAndFeel;
+import javax.swing.SwingUtilities;
 import javax.swing.UIDefaults;
 import javax.swing.UIManager;
 import javax.swing.event.ListDataEvent;
@@ -739,9 +740,8 @@
     for (int i = minIndex + 1; i <= maxIndex; i++)
       {
         Point hiLoc = indexToLocation(list, i);
-        Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, width,
-                                           getCellHeight(i));
-        bounds = bounds.union(hibounds);
+        bounds = SwingUtilities.computeUnion(hiLoc.x, hiLoc.y, width,
+                                             getCellHeight(i), bounds);
       }
 
     return bounds;
Index: javax/swing/plaf/basic/BasicTextUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTextUI.java,v
retrieving revision 1.71
diff -u -r1.71 BasicTextUI.java
--- javax/swing/plaf/basic/BasicTextUI.java	21 Feb 2006 14:03:19 -0000	1.71
+++ javax/swing/plaf/basic/BasicTextUI.java	3 Mar 2006 11:02:10 -0000
@@ -365,6 +365,38 @@
     {
       return view.getNextVisualPositionFrom(pos, b, a, d, biasRet);
     }
+
+    /**
+     * Returns the startOffset of this view, which is always the beginning
+     * of the document.
+     *
+     * @return the startOffset of this view
+     */
+    public int getStartOffset()
+    {
+      return 0;
+    }
+
+    /**
+     * Returns the endOffset of this view, which is always the end
+     * of the document.
+     *
+     * @return the endOffset of this view
+     */
+    public int getEndOffset()
+    {
+      return getDocument().getLength();
+    }
+
+    /**
+     * Returns the document associated with this view.
+     *
+     * @return the document associated with this view
+     */
+    public Document getDocument()
+    {
+      return textComponent.getDocument();
+    }
   }
 
   /**

Reply via email to