This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui][PATCH] Fixing the BasicArrowButtons


Hi,

This patch reimplements BasicArrowButton. They paint themselves
correctly when disabled and IMO look better now. ScrollBars now use
BasicArrowButtons. Also one minor change to the SplitPaneDivider.

Cheers,

Kim

2004-09-11  Kim Ho  <kho@redhat.com>

	* javax/swing/plaf/basic/BasicArrowButton.java:
	Jalopy. Reimplement.
	* javax/swing/plaf/basic/BasicScrollBarUI.java:
	Jalopy.
	(arrowIcon, upIcon, downIcon, leftIcon,
	rightIcon): Removed.
	(createIncreaseButton): Use BasicArrowButton.
	(createDecreaseButton): Ditto.
	* javax/swing/plaf/basic/BasicSplitPaneDivider.java:
	(createRightOneTouchButton): Remove button border.
	(createLeftOneTouchButton): Ditto.
? javax/swing/colorchooser/DefaultHSBChooserPanel.java.back
? javax/swing/plaf/basic/.BasicArrowButton.java.swp
? javax/swing/plaf/basic/.BasicScrollBarUI.java.swp
? javax/swing/plaf/basic/.BasicSplitPaneDivider.java.swp
Index: javax/swing/plaf/basic/BasicArrowButton.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicArrowButton.java,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 BasicArrowButton.java
--- javax/swing/plaf/basic/BasicArrowButton.java	25 Aug 2004 21:49:48 -0000	1.1.2.5
+++ javax/swing/plaf/basic/BasicArrowButton.java	11 Sep 2004 20:10:40 -0000
@@ -40,14 +40,14 @@
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
-import java.awt.Insets;
 import java.awt.Graphics;
+import java.awt.Insets;
 import java.awt.Polygon;
 import java.awt.Rectangle;
-import javax.swing.border.Border;
 import javax.swing.Icon;
 import javax.swing.JButton;
 import javax.swing.SwingConstants;
+import javax.swing.border.Border;
 
 
 /**
@@ -55,163 +55,79 @@
  */
 public class BasicArrowButton extends JButton implements SwingConstants
 {
-  /**
-   * A private helper class that draws icons.
-   */
-  private class arrowIcon implements Icon
-  {
-    /** The polygon that describes the icon. */
-    private Polygon arrow;
-
-    /** The size of the icon. */
-    private int size = 10;
-
-    /**
-     * Creates a new arrowIcon object using the given arrow polygon.
-     *
-     * @param arrow The polygon that describes the arrow.
-     */
-    public arrowIcon(Polygon arrow)
-    {
-      this.arrow = arrow;
-    }
-
-    /**
-     * Returns the height of the icon.
-     *
-     * @return The height of the icon.
-     */
-    public int getIconHeight()
-    {
-      return size;
-    }
-
-    /**
-     * Returns the width of the icon.
-     *
-     * @return The width of the icon.
-     */
-    public int getIconWidth()
-    {
-      return size;
-    }
-
-    /**
-     * Sets the size of the icon.
-     *
-     * @param size The size of the icon.
-     */
-    public void setSize(int size)
-    {
-      this.size = size;
-    }
-
-    /**
-     * Sets the arrow polygon.
-     *
-     * @param arrow The arrow polygon.
-     */
-    public void setArrow(Polygon arrow)
-    {
-      this.arrow = arrow;
-    }
-
-    /**
-     * Paints the icon.
-     *
-     * @param c The Component to paint for.
-     * @param g The Graphics object to draw with.
-     * @param x The X coordinate to draw at.
-     * @param y The Y coordinate to draw at.
-     */
-    public void paintIcon(Component c, Graphics g, int x, int y)
-    {
-      Color arrowColor;
-      if (c.isEnabled())
-	arrowColor = darkShadow;
-      else
-	arrowColor = shadow;
-
-      paintIconImpl(g, x, y, arrowColor);
-    }
-
-    /**
-     * This method does the actual painting work.
-     *
-     * @param g The Graphics object to paint with.
-     * @param x The x coordinate to paint at.
-     * @param y The y coordinate to paint at.
-     * @param arrowColor The color to paint the arrow with.
-     */
-    public void paintIconImpl(Graphics g, int x, int y, Color arrowColor)
-    {
-      g.translate(x, y);
+  /** The default size of the Arrow buttons. */
+  private static int defaultSize = 10;
 
-      Color saved = g.getColor();
-
-      g.setColor(arrowColor);
-
-      g.fillPolygon(arrow);
-
-      g.setColor(saved);
-      g.translate(-x, -y);
-    }
-  }
+  /** The Polygon that points up. */
+  private static Polygon upIcon = new Polygon(new int[] { 0, 5, 9 },
+                                              new int[] { 7, 2, 7 }, 3);
+
+  /** The Polygon that points down. */
+  private static Polygon downIcon = new Polygon(new int[] { 1, 5, 9 },
+                                                new int[] { 3, 7, 3 }, 3);
+
+  /** The Polygon that points left. */
+  private static Polygon leftIcon = new Polygon(new int[] { 7, 3, 7 },
+                                                new int[] { 1, 5, 9 }, 3);
+
+  /** The Polygon that points right. */
+  private static Polygon rightIcon = new Polygon(new int[] { 3, 7, 3 },
+                                                 new int[] { 1, 5, 9 }, 3);
 
   /** The direction to point in. */
   protected int direction;
 
-  /** The color the arrow is painted in if disabled and the bottom and
-   * right edges of the button. */
-  private transient Color shadow = Color.gray;
-
-  /** The color the arrow is painted in if enabled and the bottom and
-   * right edges of the button. */
-  private transient Color darkShadow = Color.BLACK;
+  /**
+   * The color the arrow is painted in if disabled and the bottom and right
+   * edges of the button.
+   */
+  private transient Color shadow = Color.GRAY;
+
+  /**
+   * The color the arrow is painted in if enabled and the bottom and right
+   * edges of the button.
+   */
+  private transient Color darkShadow = Color.DARK_GRAY;
 
   /** The top and left edges of the button. */
-  private transient Color highlight = Color.BLACK;
-  
+  private transient Color highlight = Color.WHITE;
+
   /** The border around the ArrowButton. */
-  private transient Border tmpBorder = new Border()
-  {
-    public Insets getBorderInsets(Component c)
+  private transient Border buttonBorder = new Border()
     {
-      return new Insets(0, 0, 0, 0);
-    }
-    
-    public boolean isBorderOpaque()
-    {
-      return false;
-    }
-    
-    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
-    {
-      Rectangle bounds = getBounds();
+      public Insets getBorderInsets(Component c)
+      {
+	return new Insets(2, 2, 2, 2);
+      }
+
+      public boolean isBorderOpaque()
+      {
+	return true;
+      }
 
-      Color saved = g.getColor();
-      g.setColor(highlight);
+      public void paintBorder(Component c, Graphics g, int x, int y, int w,
+                              int h)
+      {
+	System.out.println("PAINTING BORDER");
+	Color saved = g.getColor();
+	g.setColor(highlight);
 
-      g.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height);
-      g.drawLine(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y);
+	g.drawLine(x + 1, y + 1, x + w - 1, y + 1);
+	g.drawLine(x + 1, y + 1, x + 1, y + h - 1);
 
-      g.setColor(shadow);
+	g.setColor(shadow);
 
-      g.drawLine(bounds.x + 1, bounds.y + bounds.height - 1,
-                 bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
-      g.drawLine(bounds.x + bounds.width - 1, bounds.y + 1,
-                 bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
+	g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
+	g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
 
-      g.setColor(darkShadow);
+	g.setColor(darkShadow);
 
-      g.drawLine(bounds.x, bounds.y + bounds.height, bounds.x + bounds.width,
-                 bounds.y + bounds.height);
-      g.drawLine(bounds.x + bounds.width, bounds.y, bounds.x + bounds.width,
-                 bounds.y + bounds.height);
+	g.drawLine(x, y + h, x + w, y + h);
+	g.drawLine(x + w, y, x + w, y + h);
 
-      g.setColor(saved);
-    }
-  };
+	g.setColor(saved);
+      }
+    };
 
   /**
    * Creates a new BasicArrowButton object.
@@ -221,12 +137,12 @@
   public BasicArrowButton(int direction)
   {
     super();
+    setBorder(buttonBorder);
     setDirection(direction);
-    setBorder(tmpBorder);
   }
 
   /**
-   * Creates a new BasicArrowButton object with the given colors and 
+   * Creates a new BasicArrowButton object with the given colors and
    * direction.
    *
    * @param direction The direction to point in.
@@ -246,6 +162,16 @@
   }
 
   /**
+   * This method returns whether the focus can traverse to this component.
+   *
+   * @return Whether the focus can traverse to this component.
+   */
+  public boolean isFocusTraversable()
+  {
+    return false;
+  }
+
+  /**
    * This method returns the direction of the arrow.
    *
    * @return The direction of the arrow.
@@ -262,22 +188,25 @@
    */
   public void setDirection(int dir)
   {
-    Polygon arrow = getArrow(dir, 10);
-    if (getIcon() == null)
-      setIcon(new arrowIcon(arrow));
-    else
-      ((arrowIcon) getIcon()).setArrow(arrow);
     this.direction = dir;
   }
 
   /**
-   * This method paints the arrow button.
+   * This method paints the arrow button. The painting is delegated to the
+   * paintTriangle method.
    *
    * @param g The Graphics object to paint with.
    */
   public void paint(Graphics g)
   {
     super.paint(g);
+    Insets insets = getInsets();
+    Rectangle bounds = getBounds();
+    int x = insets.left
+            + (bounds.width - insets.left - insets.right - defaultSize) / 2;
+    int y = insets.top
+            + (bounds.height - insets.left - insets.right - defaultSize) / 2;
+    paintTriangle(g, x, y, defaultSize, direction, isEnabled());
   }
 
   /**
@@ -287,7 +216,11 @@
    */
   public Dimension getPreferredSize()
   {
-    return new Dimension(getIcon().getIconWidth(), getIcon().getIconHeight());
+    Insets insets = getInsets();
+    int w = defaultSize + insets.left + insets.right;
+    int h = defaultSize + insets.top + insets.bottom;
+
+    return new Dimension(w, h);
   }
 
   /**
@@ -311,8 +244,8 @@
   }
 
   /**
-   * The method paints a triangle with the given size and direction at
-   * the given x and y coordinates.
+   * The method paints a triangle with the given size and direction at the
+   * given x and y coordinates.
    *
    * @param g The Graphics object to paint with.
    * @param x The x coordinate to paint at.
@@ -324,61 +257,90 @@
   public void paintTriangle(Graphics g, int x, int y, int size, int direction,
                             boolean isEnabled)
   {
-    Polygon arrow = getArrow(direction, size);
-    arrowIcon arrowI = new arrowIcon(arrow);
-    arrowI.setSize(size);
-
-    Color arrowColor;
-    if (isEnabled())
-      arrowColor = darkShadow;
-    else
-      arrowColor = shadow;
-
-    arrowI.paintIconImpl(g, x, y, arrowColor);
-  }
-
-  /**
-   * This is a private helper that creates polygons for a given size 
-   * and direction.
-   *
-   * @param direction The direction of the arrow.
-   * @param size The size of the arrow.
-   *
-   * @return A new arrow polygon.
-   */
-  private Polygon getArrow(int direction, int size)
-  {
-    Polygon arrow;
-    double dsize = (double) size;
-		
-		int one = (int) (dsize * 1 / 10);
-    int two = (int) (dsize * 2 / 10);
-		int five = (int) (dsize * 5 / 10);
-    int eight = (int) (dsize * 8 / 10);
-		
+    Polygon arrow = null;
     switch (direction)
       {
       case NORTH:
-	arrow = new Polygon(new int[] { eight, five, one },
-	                    new int[] { eight, one, eight }, 3);
+	arrow = upIcon;
 	break;
       case SOUTH:
-	arrow = new Polygon(new int[] { eight, five, two },
-	                    new int[] { two, eight, two }, 3);
+	arrow = downIcon;
 	break;
       case EAST:
       case RIGHT:
-	arrow = new Polygon(new int[] { two, eight, two },
-	                    new int[] { two, five, eight }, 3);
+	arrow = rightIcon;
 	break;
       case WEST:
       case LEFT:
-	arrow = new Polygon(new int[] { eight, two, eight },
-	                    new int[] { two, five, eight }, 3);
+	arrow = leftIcon;
 	break;
-      default:
-	throw new IllegalArgumentException("Invalid direction given.");
       }
-    return arrow;
+
+    int[] xPoints = arrow.xpoints;
+    int[] yPoints = arrow.ypoints;
+    int x1;
+    int y1;
+    int x2;
+    int y2;
+    x1 = y1 = x2 = y2 = 0;
+
+    if (size != defaultSize)
+      {
+	float scale = size * 1f / defaultSize;
+	for (int i = 0; i < 3; i++)
+	  {
+	    xPoints[i] *= scale;
+	    yPoints[i] *= scale;
+	  }
+      }
+    g.translate(x, y);
+
+    switch (direction)
+      {
+      case NORTH:
+	x1 = xPoints[0] + 2;
+	y1 = yPoints[0];
+	y2 = y1;
+	x2 = xPoints[2] - 1;
+	break;
+      case SOUTH:
+	x1 = xPoints[1];
+	y1 = yPoints[1] + 1;
+	x2 = xPoints[2] - 1;
+	y2 = yPoints[2];
+	break;
+      case LEFT:
+      case WEST:
+	x1 = xPoints[0] + 1;
+	y1 = yPoints[0] + 1;
+	x2 = x1;
+	y2 = yPoints[2] + 1;
+	break;
+      case RIGHT:
+      case EAST:
+	x1 = xPoints[2];
+	y1 = yPoints[2] + 1;
+	x2 = xPoints[1] - 1;
+	y2 = yPoints[1] + 1;
+	break;
+      }
+    Color saved = g.getColor();
+
+    if (isEnabled)
+      {
+	g.setColor(Color.DARK_GRAY);
+
+	if (arrow != null)
+	  g.fillPolygon(xPoints, yPoints, 3);
+      }
+    else
+      {
+	g.setColor(Color.GRAY);
+	g.fillPolygon(xPoints, yPoints, 3);
+	g.setColor(Color.WHITE);
+	g.drawLine(x1, y1, x2, y2);
+      }
+    g.setColor(saved);
+    g.translate(-x, -y);
   }
 }
Index: javax/swing/plaf/basic/BasicScrollBarUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicScrollBarUI.java,v
retrieving revision 1.1.2.10
diff -u -r1.1.2.10 BasicScrollBarUI.java
--- javax/swing/plaf/basic/BasicScrollBarUI.java	30 Jul 2004 21:34:35 -0000	1.1.2.10
+++ javax/swing/plaf/basic/BasicScrollBarUI.java	11 Sep 2004 20:10:41 -0000
@@ -54,7 +54,6 @@
 import java.awt.event.MouseMotionListener;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
-
 import javax.swing.BoundedRangeModel;
 import javax.swing.Icon;
 import javax.swing.JButton;
@@ -78,15 +77,14 @@
                                                              SwingConstants
 {
   /**
-   * A helper class that listens to the two JButtons on each end
-   * of the JScrollBar.
+   * A helper class that listens to the two JButtons on each end of the
+   * JScrollBar.
    */
   protected class ArrowButtonListener extends MouseAdapter
   {
     /**
-     * Move the thumb in the direction specified by the 
-     * button's arrow. If this button is held down, then
-     * it should keep moving the thumb.
+     * Move the thumb in the direction specified by the  button's arrow. If
+     * this button is held down, then it should keep moving the thumb.
      *
      * @param e The MouseEvent fired by the JButton.
      */
@@ -113,8 +111,7 @@
   }
 
   /**
-   * A helper class that listens to the ScrollBar's model
-   * for ChangeEvents.
+   * A helper class that listens to the ScrollBar's model for ChangeEvents.
    */
   protected class ModelListener implements ChangeListener
   {
@@ -127,7 +124,7 @@
     {
       //       System.err.println(this + ".stateChanged()");
       calculatePreferredSize();
-      layoutContainer(scrollbar);		  
+      layoutContainer(scrollbar);
       getThumbBounds();
       scrollbar.repaint();
     }
@@ -157,19 +154,19 @@
 	  decrButton.removeMouseListener(buttonListener);
 	  incrButton = createIncreaseButton(scrollbar.getOrientation());
 	  decrButton = createDecreaseButton(scrollbar.getOrientation());
-          incrButton.addMouseListener(buttonListener);
-          decrButton.addMouseListener(buttonListener);	  
-          calculatePreferredSize();
-          layoutContainer(scrollbar);		  
-	}
+	  incrButton.addMouseListener(buttonListener);
+	  decrButton.addMouseListener(buttonListener);
+	  calculatePreferredSize();
+	  layoutContainer(scrollbar);
+        }
       layoutContainer(scrollbar);
       scrollbar.repaint();
     }
   }
 
   /**
-   * A helper class that listens for events from
-   * the timer that is used to move the thumb.
+   * A helper class that listens for events from the timer that is used to
+   * move the thumb.
    */
   protected class ScrollListener implements ActionListener
   {
@@ -180,8 +177,8 @@
     private transient boolean block;
 
     /**
-     * Creates a new ScrollListener object.
-     * The default is scrolling positively with block movement.
+     * Creates a new ScrollListener object. The default is scrolling
+     * positively with block movement.
      */
     public ScrollListener()
     {
@@ -190,8 +187,8 @@
     }
 
     /**
-     * Creates a new ScrollListener object using
-     * the given direction and block.
+     * Creates a new ScrollListener object using the given direction and
+     * block.
      *
      * @param dir The direction to move in.
      * @param block Whether movement will be in blocks.
@@ -234,8 +231,7 @@
 	  // Only need to check it if it's block scrolling
 	  // We only block scroll if the click occurs
 	  // in the track.
-	  
-	  if (!trackListener.shouldScroll(direction))
+	  if (! trackListener.shouldScroll(direction))
 	    {
 	      trackHighlight = NO_HIGHLIGHT;
 	      scrollbar.repaint();
@@ -260,13 +256,14 @@
     /** The current Y coordinate of the mouse. */
     protected int currentMouseY;
 
-    /** The offset between the current mouse cursor and the 
-        current value of the scrollbar. */
+    /**
+     * The offset between the current mouse cursor and the  current value of
+     * the scrollbar.
+     */
     protected int offset;
 
     /**
-     * This method is called when the mouse is being
-     * dragged.
+     * This method is called when the mouse is being dragged.
      *
      * @param e The MouseEvent given.
      */
@@ -275,15 +272,15 @@
       currentMouseX = e.getX();
       currentMouseY = e.getY();
       if (scrollbar.getValueIsAdjusting())
-      {
-        int value;
-        if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
-	  value = valueForXPosition(currentMouseX) - offset;
-	else
-	  value = valueForYPosition(currentMouseY) - offset;
-	
-	scrollbar.setValue(value);
-      }
+        {
+	  int value;
+	  if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
+	    value = valueForXPosition(currentMouseX) - offset;
+	  else
+	    value = valueForYPosition(currentMouseY) - offset;
+
+	  scrollbar.setValue(value);
+        }
     }
 
     /**
@@ -298,9 +295,8 @@
     }
 
     /**
-     * This method is called when the mouse is
-     * pressed. When it is pressed, the thumb should
-     * move in blocks towards the cursor.
+     * This method is called when the mouse is pressed. When it is pressed,
+     * the thumb should move in blocks towards the cursor.
      *
      * @param e The MouseEvent given.
      */
@@ -318,7 +314,7 @@
       if (value == scrollbar.getValue())
 	return;
 
-      if (!thumbRect.contains(e.getPoint()))
+      if (! thumbRect.contains(e.getPoint()))
         {
 	  scrollTimer.stop();
 	  scrollListener.setScrollByBlock(true);
@@ -344,13 +340,13 @@
 	  // to that value.
 	  scrollbar.setValueIsAdjusting(true);
 	  offset = value - scrollbar.getValue();
-	}
-      scrollbar.repaint();      
+        }
+      scrollbar.repaint();
     }
 
     /**
-     * This method is called when the mouse is released.
-     * It should stop movement on the thumb
+     * This method is called when the mouse is released. It should stop
+     * movement on the thumb
      *
      * @param e The MouseEvent given.
      */
@@ -358,32 +354,32 @@
     {
       trackHighlight = NO_HIGHLIGHT;
       scrollTimer.stop();
-      
+
       if (scrollbar.getValueIsAdjusting())
-        scrollbar.setValueIsAdjusting(false);
+	scrollbar.setValueIsAdjusting(false);
       scrollbar.repaint();
     }
-    
+
     /**
-     * A helper method that decides whether we should
-     * keep scrolling in the given direction.
+     * A helper method that decides whether we should keep scrolling in the
+     * given direction.
      *
      * @param direction The direction to check for.
      *
      * @return Whether the thumb should keep scrolling.
      */
-    public boolean shouldScroll (int direction)
+    public boolean shouldScroll(int direction)
     {
       int value;
       if (scrollbar.getOrientation() == HORIZONTAL)
-        value = valueForXPosition(currentMouseX);
+	value = valueForXPosition(currentMouseX);
       else
-        value = valueForYPosition(currentMouseY);
+	value = valueForYPosition(currentMouseY);
 
       if (direction == POSITIVE_SCROLL)
-        return (value > scrollbar.getValue());
+	return (value > scrollbar.getValue());
       else
-        return (value < scrollbar.getValue());
+	return (value < scrollbar.getValue());
     }
   }
 
@@ -393,8 +389,7 @@
   /** The listener that listens to the model. */
   protected ModelListener modelListener;
 
-  /** The listener that listens to the scrollbar for property
-      changes. */
+  /** The listener that listens to the scrollbar for property changes. */
   protected PropertyChangeListener propertyChangeListener;
 
   /** The listener that listens to the timer. */
@@ -427,8 +422,7 @@
   /** The outer light shadow for the thumb. */
   protected Color thumbLightShadowColor;
 
-  /** The color that is used when the mouse press
-      occurs in the track. */
+  /** The color that is used when the mouse press occurs in the track. */
   protected Color trackHighlightColor;
 
   /** The color of the track. */
@@ -471,88 +465,6 @@
   protected JScrollBar scrollbar;
 
   /**
-   * A helper class that allows us to draw icons for 
-   * the JButton.
-   */
-  private static class arrowIcon implements Icon
-  {
-    /** The polygon that describes the icon. */
-    private Polygon arrow;
-
-    /**
-     * Creates a new arrowIcon object.
-     *
-     * @param arrow The polygon that describes the arrow.
-     */
-    public arrowIcon(Polygon arrow)
-    {
-      this.arrow = arrow;
-    }
-
-    /**
-     * Returns the height of the icon.
-     *
-     * @return The height of the icon.
-     */
-    public int getIconHeight()
-    {
-      return 10;
-    }
-
-    /**
-     * Returns the width of the icon.
-     *
-     * @return The width of the icon.
-     */
-    public int getIconWidth()
-    {
-      return 10;
-    }
-
-    /**
-     * Paints the icon.
-     *
-     * @param c The Component to paint for.
-     * @param g The Graphics object to draw with.
-     * @param x The X coordinate to draw at.
-     * @param y The Y coordinate to draw at.
-     */
-    public void paintIcon(Component c, Graphics g, int x, int y)
-    {
-      g.translate(x, y);
-
-      Color saved = g.getColor();
-
-      g.setColor(Color.BLACK);
-
-      g.fillPolygon(arrow);
-
-      g.setColor(saved);
-      g.translate(-x, -y);
-    }
-  }
-
-  /** The Icon that points up. */
-  private static Icon upIcon = new arrowIcon(new Polygon(new int[] { 2, 5, 8 },
-                                                         new int[] { 7, 3, 7 },
-                                                         3));
-
-  /** The Icon that points down. */
-  private static Icon downIcon = new arrowIcon(new Polygon(new int[] { 2, 5, 8 },
-                                                           new int[] { 3, 7, 3 },
-                                                           3));
-
-  /** The Icon that points left. */
-  private static Icon leftIcon = new arrowIcon(new Polygon(new int[] { 7, 3, 7 },
-                                                           new int[] { 2, 5, 8 },
-                                                           3));
-
-  /** The Icon that points right. */
-  private static Icon rightIcon = new arrowIcon(new Polygon(new int[] { 3, 7, 3},
-                                                            new int[] { 2, 5, 8}, 
-                                                            3));
-
-  /**
    * This method adds a component to the layout.
    *
    * @param name The name to associate with the component that is added.
@@ -565,19 +477,19 @@
   }
 
   /**
-   * This method configures the scrollbar's colors. This can be 
-   * done by looking up the standard colors from the Look and Feel defaults.
+   * This method configures the scrollbar's colors. This can be  done by
+   * looking up the standard colors from the Look and Feel defaults.
    */
   protected void configureScrollBarColors()
   {
     UIDefaults defaults = UIManager.getLookAndFeelDefaults();
-  
+
     trackColor = defaults.getColor("ScrollBar.track");
     trackHighlightColor = defaults.getColor("ScrollBar.trackHighlight");
     thumbColor = defaults.getColor("ScrollBar.thumb");
     thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight");
     thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow");
-    thumbLightShadowColor = defaults.getColor("ScrollBar.thumbLightShadow");  
+    thumbLightShadowColor = defaults.getColor("ScrollBar.thumbLightShadow");
   }
 
   /**
@@ -590,9 +502,9 @@
     return new ArrowButtonListener();
   }
 
-  /** 
-   * This method creates a new JButton with the appropriate
-   * icon for the orientation.
+  /**
+   * This method creates a new JButton with the appropriate icon for the
+   * orientation.
    *
    * @param orientation The orientation this JButton uses.
    *
@@ -601,26 +513,22 @@
   protected JButton createIncreaseButton(int orientation)
   {
     if (incrButton == null)
+      incrButton = new BasicArrowButton((orientation == SwingConstants.HORIZONTAL)
+                                        ? SwingConstants.EAST
+                                        : SwingConstants.SOUTH);
+    else
       {
-        incrButton = new JButton();      
-        incrButton.setMargin(new Insets(0,0,0,0));
-        incrButton.setHorizontalAlignment(SwingConstants.CENTER);
-        incrButton.setHorizontalTextPosition(SwingConstants.CENTER);
-        incrButton.setVerticalAlignment(SwingConstants.CENTER);
-        incrButton.setVerticalTextPosition(SwingConstants.CENTER);
+	if (orientation == SwingConstants.HORIZONTAL)
+	  ((BasicArrowButton) incrButton).setDirection(SwingConstants.EAST);
+	else
+	  ((BasicArrowButton) incrButton).setDirection(SwingConstants.SOUTH);
       }
-    
-    if (orientation == SwingConstants.HORIZONTAL)
-      incrButton.setIcon(rightIcon);
-    else
-      incrButton.setIcon(downIcon);
-
     return incrButton;
   }
 
   /**
-   * This method creates a new JButton with the appropriate
-   * icon for the orientation.
+   * This method creates a new JButton with the appropriate icon for the
+   * orientation.
    *
    * @param orientation The orientation this JButton uses.
    *
@@ -629,20 +537,16 @@
   protected JButton createDecreaseButton(int orientation)
   {
     if (decrButton == null)
+      decrButton = new BasicArrowButton((orientation == SwingConstants.HORIZONTAL)
+                                        ? SwingConstants.WEST
+                                        : SwingConstants.NORTH);
+    else
       {
-        decrButton = new JButton();
-        decrButton.setMargin(new Insets(0,0,0,0));
-        decrButton.setHorizontalAlignment(SwingConstants.CENTER);
-        decrButton.setHorizontalTextPosition(SwingConstants.CENTER);
-        decrButton.setVerticalAlignment(SwingConstants.CENTER);
-        decrButton.setVerticalTextPosition(SwingConstants.CENTER);
+	if (orientation == SwingConstants.HORIZONTAL)
+	  ((BasicArrowButton) decrButton).setDirection(SwingConstants.WEST);
+	else
+	  ((BasicArrowButton) decrButton).setDirection(SwingConstants.NORTH);
       }
-
-    if (orientation == SwingConstants.HORIZONTAL)
-      decrButton.setIcon(leftIcon);
-    else
-      decrButton.setIcon(upIcon);
-
     return decrButton;
   }
 
@@ -743,13 +647,12 @@
   }
 
   /**
-   * This method calculates the preferred size since
-   * calling getPreferredSize() returns a cached value.
+   * This method calculates the preferred size since calling
+   * getPreferredSize() returns a cached value.
    */
   private void calculatePreferredSize()
   {
     // System.err.println(this + ".calculatePreferredSize()");
-
     int height;
     int width;
     height = width = 0;
@@ -790,11 +693,11 @@
   }
 
   /**
-   * This method returns a cached value of the preferredSize.
-   * The only restrictions are: If the scrollbar is horizontal, the
-   * height should be the maximum of the height of the JButtons and 
-   * the minimum width of the thumb. For vertical scrollbars, the 
-   * calculation is similar (swap width for height and vice versa).
+   * This method returns a cached value of the preferredSize. The only
+   * restrictions are: If the scrollbar is horizontal, the height should be
+   * the maximum of the height of the JButtons and  the minimum width of the
+   * thumb. For vertical scrollbars, the  calculation is similar (swap width
+   * for height and vice versa).
    *
    * @param c The JComponent to measure.
    *
@@ -807,9 +710,8 @@
   }
 
   /**
-   * This method returns the thumb's bounds based on the 
-   * current value of the scrollbar. This method updates the
-   * cached value and returns that.
+   * This method returns the thumb's bounds based on the  current value of the
+   * scrollbar. This method updates the cached value and returns that.
    *
    * @return The thumb bounds.
    */
@@ -821,24 +723,22 @@
     int extent = scrollbar.getVisibleAmount();
 
     // System.err.println(this + ".getThumbBounds()");
-
     if (max == min)
-    {
-      thumbRect.x = trackRect.x;
-      thumbRect.y = trackRect.y;
-      if (scrollbar.getOrientation() == HORIZONTAL)
       {
-	thumbRect.width = getMinimumThumbSize().width;
-	thumbRect.height = trackRect.height;
-      }
-      else
-      {
-        thumbRect.width = trackRect.width;
-	thumbRect.height = getMinimumThumbSize().height;
+	thumbRect.x = trackRect.x;
+	thumbRect.y = trackRect.y;
+	if (scrollbar.getOrientation() == HORIZONTAL)
+	  {
+	    thumbRect.width = getMinimumThumbSize().width;
+	    thumbRect.height = trackRect.height;
+	  }
+	else
+	  {
+	    thumbRect.width = trackRect.width;
+	    thumbRect.height = getMinimumThumbSize().height;
+	  }
+	return thumbRect;
       }
-      return thumbRect;
-    }
-               
 
     if (scrollbar.getOrientation() == HORIZONTAL)
       {
@@ -852,8 +752,7 @@
     else
       {
 	thumbRect.x = trackRect.x;
-	thumbRect.y = trackRect.y
-	              + value * trackRect.height / (max - min);
+	thumbRect.y = trackRect.y + value * trackRect.height / (max - min);
 
 	thumbRect.width = trackRect.width;
 	thumbRect.height = extent * trackRect.height / (max - min);
@@ -862,8 +761,8 @@
   }
 
   /**
-   * This method calculates the bounds of the track. This method
-   * updates the cached value and returns it.
+   * This method calculates the bounds of the track. This method updates the
+   * cached value and returns it.
    *
    * @return The track's bounds.
    */
@@ -889,8 +788,8 @@
   }
 
   /**
-   * This method installs any addition Components that 
-   * are a part of or related to this scrollbar.
+   * This method installs any addition Components that  are a part of or
+   * related to this scrollbar.
    */
   protected void installComponents()
   {
@@ -901,8 +800,8 @@
   }
 
   /**
-   * This method installs the defaults for the scrollbar specified
-   * by the Basic Look and Feel.
+   * This method installs the defaults for the scrollbar specified by the
+   * Basic Look and Feel.
    */
   protected void installDefaults()
   {
@@ -926,9 +825,8 @@
   }
 
   /**
-   * This method installs any listeners for the scrollbar.
-   * This method also installs listeners for things such as
-   * the JButtons and the timer.
+   * This method installs any listeners for the scrollbar. This method also
+   * installs listeners for things such as the JButtons and the timer.
    */
   protected void installListeners()
   {
@@ -951,10 +849,9 @@
   }
 
   /**
-   * This method installs the UI for the component.
-   * This can include setting up listeners, defaults, 
-   * and components. This also includes initializing any data
-   * objects.
+   * This method installs the UI for the component. This can include setting
+   * up listeners, defaults,  and components. This also includes initializing
+   * any data objects.
    *
    * @param c The JComponent to install.
    */
@@ -977,7 +874,7 @@
 	configureScrollBarColors();
 
 	calculatePreferredSize();
-        layoutContainer(scrollbar);	
+	layoutContainer(scrollbar);
       }
   }
 
@@ -1073,9 +970,9 @@
   }
 
   /**
-   * This method is called when repainting and the mouse is 
-   * pressed in the track. It paints the track below the thumb
-   * with the trackHighlight color.
+   * This method is called when repainting and the mouse is  pressed in the
+   * track. It paints the track below the thumb with the trackHighlight
+   * color.
    *
    * @param g The Graphics object to paint with.
    */
@@ -1088,15 +985,15 @@
       g.fillRect(trackRect.x, trackRect.y, thumbRect.x - trackRect.x,
                  trackRect.height);
     else
-      g.fillRect(trackRect.x, trackRect.y, trackRect.width, 
+      g.fillRect(trackRect.x, trackRect.y, trackRect.width,
                  thumbRect.y - trackRect.y);
     g.setColor(saved);
   }
 
   /**
-   * This method is called when repainting and the mouse is 
-   * pressed in the track. It paints the track above the thumb
-   * with the trackHighlight color.
+   * This method is called when repainting and the mouse is  pressed in the
+   * track. It paints the track above the thumb with the trackHighlight
+   * color.
    *
    * @param g The Graphics objet to paint with.
    */
@@ -1109,11 +1006,10 @@
       g.fillRect(thumbRect.x + thumbRect.width, trackRect.y,
                  trackRect.x + trackRect.width - thumbRect.x - thumbRect.width,
                  trackRect.height);
-    else   
-      g.fillRect(trackRect.x, thumbRect.y + thumbRect.height, 
-                 trackRect.width,
-                 trackRect.y + trackRect.height - thumbRect.y - 
-		 thumbRect.height);
+    else
+      g.fillRect(trackRect.x, thumbRect.y + thumbRect.height, trackRect.width,
+                 trackRect.y + trackRect.height - thumbRect.y
+                 - thumbRect.height);
     g.setColor(saved);
   }
 
@@ -1217,25 +1113,25 @@
   }
 
   /**
-   * The method scrolls the thumb by a block in the 
-   * direction specified.
+   * The method scrolls the thumb by a block in the  direction specified.
    *
    * @param direction The direction to scroll.
    */
   protected void scrollByBlock(int direction)
   {
-    scrollbar.setValue(scrollbar.getValue() + scrollbar.getBlockIncrement(direction));
+    scrollbar.setValue(scrollbar.getValue()
+                       + scrollbar.getBlockIncrement(direction));
   }
 
   /**
-   * The method scrolls the thumb by a unit in the
-   * direction specified.
+   * The method scrolls the thumb by a unit in the direction specified.
    *
    * @param direction The direction to scroll.
    */
   protected void scrollByUnit(int direction)
   {
-    scrollbar.setValue(scrollbar.getValue() + scrollbar.getUnitIncrement(direction));
+    scrollbar.setValue(scrollbar.getValue()
+                       + scrollbar.getUnitIncrement(direction));
   }
 
   /**
@@ -1255,8 +1151,8 @@
   }
 
   /**
-   * This method uninstalls any components that 
-   * are a part of or related to this scrollbar.
+   * This method uninstalls any components that  are a part of or related to
+   * this scrollbar.
    */
   protected void uninstallComponents()
   {
@@ -1267,8 +1163,8 @@
   }
 
   /**
-   * This method uninstalls any defaults that this
-   * scrollbar acquired from the Basic Look and Feel defaults.
+   * This method uninstalls any defaults that this scrollbar acquired from the
+   * Basic Look and Feel defaults.
    */
   protected void uninstallDefaults()
   {
@@ -1278,8 +1174,8 @@
   }
 
   /**
-   * This method uninstalls any keyboard
-   * actions this scrollbar acquired during install.
+   * This method uninstalls any keyboard actions this scrollbar acquired
+   * during install.
    */
   protected void uninstallKeyboardActions()
   {
@@ -1287,22 +1183,21 @@
   }
 
   /**
-   * This method uninstalls any listeners that
-   * were registered during install.
+   * This method uninstalls any listeners that were registered during install.
    */
   protected void uninstallListeners()
   {
     scrollTimer.removeActionListener(scrollListener);
-    
+
     scrollbar.getModel().removeChangeListener(modelListener);
     scrollbar.removePropertyChangeListener(propertyChangeListener);
-    
+
     decrButton.removeMouseListener(buttonListener);
     incrButton.removeMouseListener(buttonListener);
-    
+
     scrollbar.removeMouseListener(trackListener);
     scrollbar.removeMouseMotionListener(trackListener);
-    
+
     propertyChangeListener = null;
     modelListener = null;
     buttonListener = null;
@@ -1311,10 +1206,9 @@
   }
 
   /**
-   * This method uninstalls the UI. This includes
-   * removing any defaults, listeners, and components
-   * that this UI may have initialized. It also nulls
-   * any instance data.
+   * This method uninstalls the UI. This includes removing any defaults,
+   * listeners, and components that this UI may have initialized. It also
+   * nulls any instance data.
    *
    * @param c The Component to uninstall for.
    */
@@ -1323,19 +1217,19 @@
     uninstallDefaults();
     uninstallListeners();
     uninstallComponents();
-    
+
     scrollTimer = null;
-    
+
     thumbRect = null;
     trackRect = null;
-    
+
     trackColor = null;
     trackHighlightColor = null;
     thumbColor = null;
     thumbHighlightColor = null;
     thumbDarkShadowColor = null;
     thumbLightShadowColor = null;
-    
+
     scrollbar = null;
   }
 
Index: javax/swing/plaf/basic/BasicSplitPaneDivider.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicSplitPaneDivider.java,v
retrieving revision 1.1.26.3
diff -u -r1.1.26.3 BasicSplitPaneDivider.java
--- javax/swing/plaf/basic/BasicSplitPaneDivider.java	12 Jul 2004 19:52:46 -0000	1.1.26.3
+++ javax/swing/plaf/basic/BasicSplitPaneDivider.java	11 Sep 2004 20:10:42 -0000
@@ -153,32 +153,36 @@
   // left (top), middle, right(bottom)
   //    0          1          2
 
-  /** Keeps track of where the divider should be placed when using one touch expand
-   * buttons. */
+  /**
+   * Keeps track of where the divider should be placed when using one touch
+   * expand buttons.
+   */
   private transient int currentDividerLocation = 1;
-  
+
+  /** DOCUMENT ME! */
   private transient Border tmpBorder = new Border()
-  {
-    public Insets getBorderInsets(Component c)
-    {
-      return new Insets(2, 2, 2, 2);
-    }
-    
-    public boolean isBorderOpaque()
     {
-      return false;
-    }
-    
-    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
-    {
-      Color saved = g.getColor();
-      g.setColor(Color.BLACK);
-      
-      g.drawRect(x + 2, y + 2, width - 4, height - 4);
-      
-      g.setColor(saved);
-    }
-  };
+      public Insets getBorderInsets(Component c)
+      {
+	return new Insets(2, 2, 2, 2);
+      }
+
+      public boolean isBorderOpaque()
+      {
+	return false;
+      }
+
+      public void paintBorder(Component c, Graphics g, int x, int y,
+                              int width, int height)
+      {
+	Color saved = g.getColor();
+	g.setColor(Color.BLACK);
+
+	g.drawRect(x + 2, y + 2, width - 4, height - 4);
+
+	g.setColor(saved);
+      }
+    };
 
   /**
    * Constructs a new divider.
@@ -420,7 +424,7 @@
     if (orientation == JSplitPane.VERTICAL_SPLIT)
       dir = SwingConstants.NORTH;
     JButton button = new BasicArrowButton(dir);
-    button.setBorderPainted(false);
+    button.setBorder(null);
 
     return button;
   }
@@ -437,7 +441,7 @@
     if (orientation == JSplitPane.VERTICAL_SPLIT)
       dir = SwingConstants.SOUTH;
     JButton button = new BasicArrowButton(dir);
-    button.setBorderPainted(false);
+    button.setBorder(null);
     return button;
   }
 
@@ -484,11 +488,10 @@
   }
 
   /**
-   * This helper method moves the divider to one of the 
-   * three locations when using one touch expand buttons.
-   * Location 0 is the left (or top) most location.
-   * Location 1 is the middle.
-   * Location 2 is the right (or bottom) most location.
+   * This helper method moves the divider to one of the  three locations when
+   * using one touch expand buttons. Location 0 is the left (or top) most
+   * location. Location 1 is the middle. Location 2 is the right (or bottom)
+   * most location.
    *
    * @param locationIndex The location to move to.
    */
@@ -612,8 +615,10 @@
    */
   protected class DragController
   {
-    /** The difference between where the mouse is clicked and the 
-     * initial divider location. */
+    /**
+     * The difference between where the mouse is clicked and the  initial
+     * divider location.
+     */
     transient int offset;
 
     /**
@@ -650,8 +655,8 @@
     }
 
     /**
-     * This method returns one of the two paramters
-     * for the orientation. In this case, it returns x.
+     * This method returns one of the two paramters for the orientation. In
+     * this case, it returns x.
      *
      * @param x The x coordinate.
      * @param y The y coordinate.
@@ -664,8 +669,8 @@
     }
 
     /**
-     * This method is called to pass on the drag information
-     * to the UI through dragDividerTo.
+     * This method is called to pass on the drag information to the UI through
+     * dragDividerTo.
      *
      * @param newX The x coordinate of the MouseEvent.
      * @param newY The y coordinate of the MouseEvent.
@@ -677,8 +682,8 @@
     }
 
     /**
-     * This method is called to pass on the drag information 
-     * to the UI through dragDividerTo.
+     * This method is called to pass on the drag information  to the UI
+     * through dragDividerTo.
      *
      * @param e The MouseEvent.
      */
@@ -689,8 +694,8 @@
     }
 
     /**
-     * This method is called to finish the drag session 
-     * by calling finishDraggingTo.
+     * This method is called to finish the drag session  by calling
+     * finishDraggingTo.
      *
      * @param x The x coordinate of the MouseEvent.
      * @param y The y coordinate of the MouseEvent.
@@ -701,8 +706,8 @@
     }
 
     /**
-     * This method is called to finish the drag session 
-     * by calling finishDraggingTo.
+     * This method is called to finish the drag session  by calling
+     * finishDraggingTo.
      *
      * @param e The MouseEvent.
      */
@@ -710,10 +715,10 @@
     {
       finishDraggingTo(positionForMouseEvent(e));
     }
-    
+
     /**
-     * This is a helper method that includes the offset
-     * in the needed location.
+     * This is a helper method that includes the offset in the needed
+     * location.
      *
      * @param x The x coordinate of the MouseEvent.
      * @param y The y coordinate of the MouseEvent.
@@ -727,8 +732,8 @@
   }
 
   /**
-   * This is a helper class that controls dragging when 
-   * the orientation is VERTICAL_SPLIT.
+   * This is a helper class that controls dragging when  the orientation is
+   * VERTICAL_SPLIT.
    */
   protected class VerticalDragController extends DragController
   {
@@ -744,8 +749,8 @@
     }
 
     /**
-     * This method returns one of the two parameters given
-     * the orientation. In this case, it returns y.
+     * This method returns one of the two parameters given the orientation. In
+     * this case, it returns y.
      *
      * @param x The x coordinate of the MouseEvent.
      * @param y The y coordinate of the MouseEvent.
@@ -758,8 +763,7 @@
     }
 
     /**
-     * This method returns the new location of the divider
-     * given a MouseEvent.
+     * This method returns the new location of the divider given a MouseEvent.
      *
      * @param e The MouseEvent.
      *
@@ -771,8 +775,8 @@
     }
 
     /**
-     * This is a helper method that includes the offset
-     * in the needed location.
+     * This is a helper method that includes the offset in the needed
+     * location.
      *
      * @param x The x coordinate of the MouseEvent.
      * @param y The y coordinate of the MouseEvent.
@@ -782,12 +786,11 @@
     int adjust(int x, int y)
     {
       return getNeededLocation(x, y) + getY() - offset;
-    }        
+    }
   }
 
   /**
-   * This helper class acts as the Layout Manager for
-   * the divider.
+   * This helper class acts as the Layout Manager for the divider.
    */
   protected class DividerLayout implements LayoutManager
   {
@@ -858,8 +861,8 @@
     }
 
     /**
-     * This method changes the button orientation when
-     * the orientation of the SplitPane changes.
+     * This method changes the button orientation when the orientation of the
+     * SplitPane changes.
      */
     private void changeButtonOrientation()
     {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]