Added code to paint the focus for the slider.

2006-05-17  Lillian Angel  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicSliderUI.java
        (focusGained): Implemented.
        (focusLost): Implemented.
        (paint): Added code to paint the focus.
        * javax/swing/plaf/metal/MetalSliderUI.java
        (paintThumb): Added code to set the thumbColor.
        (paintFocus): Implemented properly.

Index: javax/swing/plaf/basic/BasicSliderUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicSliderUI.java,v
retrieving revision 1.29
diff -u -r1.29 BasicSliderUI.java
--- javax/swing/plaf/basic/BasicSliderUI.java	18 Apr 2006 08:40:10 -0000	1.29
+++ javax/swing/plaf/basic/BasicSliderUI.java	17 May 2006 15:29:03 -0000
@@ -38,8 +38,6 @@
 
 package javax.swing.plaf.basic;
 
-import gnu.classpath.NotImplementedException;
-
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.ComponentOrientation;
@@ -70,6 +68,7 @@
 import javax.swing.JLabel;
 import javax.swing.JSlider;
 import javax.swing.LookAndFeel;
+import javax.swing.RepaintManager;
 import javax.swing.SwingUtilities;
 import javax.swing.Timer;
 import javax.swing.UIManager;
@@ -209,9 +208,9 @@
      * @param e A [EMAIL PROTECTED] FocusEvent}.
      */
     public void focusGained(FocusEvent e)
-      throws NotImplementedException
     {
-      // FIXME: implement.
+      slider.repaint();
+      hasFocus = true;
     }
 
     /**
@@ -221,9 +220,9 @@
      * @param e A [EMAIL PROTECTED] FocusEvent}.
      */
     public void focusLost(FocusEvent e)
-      throws NotImplementedException
     {
-      // FIXME: implement.
+      slider.repaint();
+      hasFocus = false;
     }
   }
 
@@ -592,6 +591,9 @@
 
   /** The focus color. */
   private transient Color focusColor;
+  
+  /** True if the slider has focus. */
+  private transient boolean hasFocus;
 
   /**
    * Creates a new Basic look and feel Slider UI.
@@ -1548,9 +1550,11 @@
       paintTicks(g);
     if (slider.getPaintLabels())
       paintLabels(g);
-
-    //FIXME: Paint focus.
+    
     paintThumb(g);
+    
+    if (hasFocus)
+      paintFocus(g);
   }
 
   /**
@@ -1602,7 +1606,7 @@
     Color saved_color = g.getColor();
 
     g.setColor(getFocusColor());
-
+    
     g.drawRect(focusRect.x, focusRect.y, focusRect.width, focusRect.height);
 
     g.setColor(saved_color);
@@ -1989,7 +1993,7 @@
   public void paintThumb(Graphics g)
   {
     Color saved_color = g.getColor();
-    
+
     Point a = new Point(thumbRect.x, thumbRect.y);
     Point b = new Point(a);
     Point c = new Point(a);
@@ -1997,11 +2001,11 @@
     Point e = new Point(a);
 
     Polygon bright;
-    Polygon light;  // light shadow
-    Polygon dark;   // dark shadow
+    Polygon light; // light shadow
+    Polygon dark; // dark shadow
     Polygon all;
 
-    // This will be in X-dimension if the slider is inverted and y if it isn't.           
+    // This will be in X-dimension if the slider is inverted and y if it isn't.
     int turnPoint;
 
     if (slider.getOrientation() == JSlider.HORIZONTAL)
@@ -2016,13 +2020,15 @@
         bright = new Polygon(new int[] { b.x - 1, a.x, e.x, d.x },
                              new int[] { b.y, a.y, e.y, d.y }, 4);
 
-        dark = new Polygon(new int[] { b.x, c.x, d.x + 1 },
-                           new int[] { b.y, c.y - 1, d.y }, 3);
-    
-    light = new Polygon(new int[] { b.x - 1, c.x - 1, d.x + 1 },
-                        new int[] { b.y + 1, c.y - 1, d.y - 1 }, 3);
-    
-        all = new Polygon(new int[] { a.x + 1, b.x - 2, c.x - 2, d.x, e.x + 1 },
+        dark = new Polygon(new int[] { b.x, c.x, d.x + 1 }, new int[] { b.y,
+                                                                       c.y - 1,
+                                                                       d.y }, 3);
+
+        light = new Polygon(new int[] { b.x - 1, c.x - 1, d.x + 1 },
+                            new int[] { b.y + 1, c.y - 1, d.y - 1 }, 3);
+
+        all = new Polygon(
+                          new int[] { a.x + 1, b.x - 2, c.x - 2, d.x, e.x + 1 },
                           new int[] { a.y + 1, b.y + 1, c.y - 1, d.y - 1, e.y },
                           5);
       }
@@ -2038,15 +2044,16 @@
         bright = new Polygon(new int[] { c.x - 1, b.x, a.x, e.x },
                              new int[] { c.y - 1, b.y, a.y, e.y - 1 }, 4);
 
-        dark = new Polygon(new int[] { c.x, d.x, e.x },
-                           new int[] { c.y, d.y, e.y }, 3);
+        dark = new Polygon(new int[] { c.x, d.x, e.x }, new int[] { c.y, d.y,
+                                                                   e.y }, 3);
 
-    light = new Polygon(new int[] { c.x - 1, d.x, e.x + 1},
-                       new int[] { c.y, d.y - 1, e.y - 1}, 3);
-        all = new Polygon(new int[] { a.x + 1, b.x, c.x - 2, c.x - 2, d.x, 
-                                      e.x + 1 },
-                          new int[] { a.y + 1, b.y + 1, c.y - 1, c.y, d.y - 2, 
-                                      e.y - 2 }, 6);
+        light = new Polygon(new int[] { c.x - 1, d.x, e.x + 1 },
+                            new int[] { c.y, d.y - 1, e.y - 1 }, 3);
+        all = new Polygon(new int[] { a.x + 1, b.x, c.x - 2, c.x - 2, d.x,
+                                     e.x + 1 }, new int[] { a.y + 1, b.y + 1,
+                                                           c.y - 1, c.y,
+                                                           d.y - 2, e.y - 2 },
+                          6);
       }
 
     g.setColor(Color.WHITE);
@@ -2057,7 +2064,7 @@
 
     g.setColor(Color.GRAY);
     g.drawPolyline(light.xpoints, light.ypoints, light.npoints);
-    
+
     g.setColor(Color.LIGHT_GRAY);
     g.drawPolyline(all.xpoints, all.ypoints, all.npoints);
     g.fillPolygon(all);
Index: javax/swing/plaf/metal/MetalSliderUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalSliderUI.java,v
retrieving revision 1.10
diff -u -r1.10 MetalSliderUI.java
--- javax/swing/plaf/metal/MetalSliderUI.java	11 May 2006 17:05:55 -0000	1.10
+++ javax/swing/plaf/metal/MetalSliderUI.java	17 May 2006 15:29:03 -0000
@@ -192,10 +192,13 @@
    */
   public void paintThumb(Graphics g) 
   {
+    Color save = g.getColor();
+    g.setColor(thumbColor);
     if (slider.getOrientation() == JSlider.HORIZONTAL)
       horizThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y);
     else
       vertThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y);
+    g.setColor(save);
   }
   
   /**
@@ -323,7 +326,8 @@
    */
   public void paintFocus(Graphics g)
   {
-    // do nothing as focus is shown by different color on thumb control
+    thumbColor = getFocusColor();
+    paintThumb(g);
   }
   
   /**

Reply via email to