harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r440748 [21/25] - in /incubator/harmony/enhanced/classlib/trunk/modules: accessibility/src/main/java/javax/accessibility/ awt/ awt/make/ awt/src/main/java/common/java/awt/ awt/src/main/java/common/java/awt/datatransfer/ awt/src/main/java/co...
Date Wed, 06 Sep 2006 16:06:30 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DebugGraphics.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DebugGraphics.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DebugGraphics.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DebugGraphics.java Wed Sep  6 09:06:15 2006
@@ -24,32 +24,108 @@
 import java.awt.Color;
 import java.awt.Font;
 import java.awt.FontMetrics;
+import java.awt.Frame;
 import java.awt.Graphics;
+import java.awt.Graphics2D;
 import java.awt.Image;
+import java.awt.Point;
+import java.awt.Polygon;
 import java.awt.Rectangle;
 import java.awt.Shape;
-import java.awt.image.BufferedImage;
+import java.awt.event.ActionEvent;
 import java.awt.image.ImageObserver;
 import java.io.PrintStream;
 import java.text.AttributedCharacterIterator;
+import java.util.HashMap;
+
+import org.apache.harmony.x.swing.Utilities;
 
 public class DebugGraphics extends Graphics {
+    private abstract static class FlashAction extends AbstractAction {
+        private Graphics g;
+        public FlashAction(final Graphics g) {
+            this.g = g;
+        }
+        
+        public void actionPerformed(final ActionEvent e) {
+            for (int i = 0; i < flashCount; i++) {
+                Color oldColor = g.getColor();
+                paint(g);
+                sleep(flashTime);
+                g.setColor(flashColor);
+                paint(g);
+                sleep(flashTime);
+                g.setColor(oldColor);
+            }
+        }        
+        
+        private void sleep(final int millis) {
+            try {
+                Thread.sleep(millis);
+            } catch (InterruptedException e) {
+                
+            }
+        }
+        public abstract void paint(final Graphics g);
+    }
+    
+    private abstract class BufferedDrawAction extends AbstractAction {        
+        public void actionPerformed(final ActionEvent e) {
+            if (externalFrames == null) {
+                externalFrames = new HashMap();
+            }
+            Frame externalFrame = (Frame)externalFrames.get(component);
+            if (externalFrame == null || !externalFrame.isDisplayable()) {
+                externalFrame = new Frame();
+                externalFrames.put(component, externalFrame);                            
+                externalFrame.setVisible(true);
+            }
+            if (component != null) {
+                externalFrame.setSize(Utilities.addInsets(component.getSize(), externalFrame.getInsets()));
+            } else {
+                externalFrame.setSize(200, 200);
+            }
+            
+            Graphics g = externalFrame.getGraphics();
+            g.clearRect(0, 0, 200, 200);
+            externalFrame.paint(g);
+            g.translate(externalFrame.getInsets().left, externalFrame.getInsets().top);
+            ((Graphics2D)g).setTransform(((Graphics2D)originalGraphics).getTransform());
+            
+            g.setColor(originalGraphics.getColor());                        
+            
+            if (isFlashing()) {
+                new FlashAction(g) {
+                    public void paint(Graphics g) {
+                        BufferedDrawAction.this.paint(g);
+                    }                    
+                }.actionPerformed(null);
+            }         
+            g.drawRect(0, 0, 40, 40);
+            paint(g);
+        }                
+        public abstract void paint(final Graphics g);
+    }
+    
     public static final int NONE_OPTION = -1;
     public static final int LOG_OPTION = 1;
     public static final int FLASH_OPTION = 2;
     public static final int BUFFERED_OPTION = 4;
 
+    private static int debugGraphicsCount; 
+    private static HashMap externalFrames;
+    
     private Graphics originalGraphics;
     private JComponent component;
     private int debugOptions;
+    private int thisNumber;
     private boolean drawingBuffer;
-
-    private static Color flashColor;
-    private static int flashCount;
-    private static int flashTime;
+    
+    private static Color flashColor = Color.RED;
+    private static int flashCount = 2;
+    private static int flashTime = 100;
     private static PrintStream logStream = System.out;
 
-
     public static void setFlashColor(final Color flashColor) {
         DebugGraphics.flashColor = flashColor;
     }
@@ -82,14 +158,10 @@
         return logStream;
     }
 
-
     public DebugGraphics(final Graphics g, final JComponent c) {
-        if (g != null) {
-            originalGraphics = g.create();
-        } else {
-            originalGraphics = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB).createGraphics();
-        }
+        originalGraphics = g.create();
         component = c;
+        thisNumber = debugGraphicsCount++;
     }
 
     public DebugGraphics(final Graphics g) {
@@ -100,40 +172,88 @@
         this(null, null);
     }
 
-
-
     public int getDebugOptions() {
         return debugOptions;
     }
 
     public void setDebugOptions(final int options) {
-        debugOptions = options;
+        boolean wasLogging = isLogging();
+        if (options == NONE_OPTION) {
+            debugOptions = 0;
+        } else {
+            debugOptions |= options;
+        }
+        if (isLogging() && !wasLogging) {
+            log("logging enabled");
+        }
+        if (!isLogging() && wasLogging) {
+            log("logging disabled");
+        }
     }
 
-
     public boolean isDrawingBuffer() {
         return drawingBuffer;
     }
 
-
     public void clearRect(final int x, final int y, final int width, final int height) {
+        if (isLogging()) {
+            log("Clearing rect: " + new Rectangle(x, y, width, height));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillRect(x, y, width, height);    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+            new BufferedDrawAction() {
+                public void paint(Graphics g) {
+                    g.fillRect(x, y, width, height);
+                }                
+            }.actionPerformed(null);
+        }
         originalGraphics.clearRect(x, y, width, height);
     }
 
     public void clipRect(final int x, final int y, final int width, final int height) {
+        if (isLogging()) {
+            log("Setting clipRect: " + new Rectangle(x, y, width, height));
+        }
+        if (isFlashing()) {
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.clipRect(x, y, width, height);
     }
 
     public void copyArea(final int x, final int y, final int width, final int height, final int destX, final int destY) {
+        if (isLogging()) {
+            log("Copying area from: " + new Rectangle(x, y, width, height) + " to : " + new Point(destX, destY));
+        }
+        if (isFlashing()) {
+            fillRect(x, y, width, height);
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillRect(x, y, width, height);    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.copyArea(x, y, width, height, destX, destY);
     }
 
     public Graphics create() {
-        return new DebugGraphics(originalGraphics, component);
+        DebugGraphics result = new DebugGraphics(originalGraphics, component);
+        result.setDebugOptions(debugOptions);
+        return result;
     }
 
     public Graphics create(final int x, final int y, final int width, final int height) {
-        return originalGraphics.create(x, y, width, height);
+        DebugGraphics result = new DebugGraphics(originalGraphics.create(x, y, width, height), component);
+        result.setDebugOptions(debugOptions);
+        return result;
     }
 
     public void dispose() {
@@ -141,98 +261,407 @@
     }
 
     public void draw3DRect(final int x, final int y, final int width, final int height, final boolean raised) {
+        if (isLogging()) {
+            log("Drawing 3D rect: " + new Rectangle(x, y, width, height) + ", raised bezel: " + raised);
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.draw3DRect(x, y, width, height, raised);    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.draw3DRect(x, y, width, height, raised);
     }
 
     public void drawArc(final int x, final int y, final int width, final int height, final int startAngle, final int arcAngle) {
+        if (isLogging()) {
+            log("Drawing arc: " + new Rectangle(x, y, width, height) + ", startAngle: " + startAngle + ", arcAngle: " + arcAngle);
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.drawArc(x, y, width, height, startAngle, arcAngle);    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.drawArc(x, y, width, height, startAngle, arcAngle);
     }
 
     public void drawBytes(final byte[] data, final int offset, final int length, final int x, final int y) {
+        if (isLogging()) {
+            log("Drawing bytes at: " + new Point(x, y));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.drawBytes(data, offset, length, x, y);    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.drawBytes(data, offset, length, x, y);
     }
 
     public void drawChars(final char[] data, final int offset, final int length, final int x, final int y) {
+        if (isLogging()) {
+            log("Drawing chars at: " + new Point(x, y));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.drawChars(data, offset, length, x, y);    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.drawChars(data, offset, length, x, y);
     }
 
     public boolean drawImage(final Image img, final int x, final int y, final Color bgcolor, final ImageObserver observer) {
+        if (isLogging()) {
+            log("Drawing image: " + img + " at " + new Point(x, y) + ", bgcolor: " + bgcolor);
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillRect(x, y, img.getHeight(observer), img.getHeight(observer));    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         return originalGraphics.drawImage(img, x, y, bgcolor, observer);
     }
 
     public boolean drawImage(final Image img, final int x, final int y, final ImageObserver observer) {
+        if (isLogging()) {
+            log("Drawing image: " + img + " at " + new Point(x, y));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillRect(x, y, img.getHeight(observer), img.getHeight(observer));    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         return originalGraphics.drawImage(img, x, y, observer);
     }
 
-    public boolean drawImage(final Image img, final int x, final int y, final int width, final int height, final Color bgcolor, final ImageObserver observer) {
-        return originalGraphics.drawImage(img, x, y, width, height, bgcolor, observer);
+    public boolean drawImage(final Image img, final int x, final int y, final int width, final int height,
+                             final Color bgcolor, final ImageObserver observer) {
+
+        if (isLogging()) {
+            log("Drawing image: " + img + " at " + new Rectangle(x, y, width, height) + ", bgcolor: " + bgcolor);
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillRect(x, y, img.getHeight(observer), img.getHeight(observer));    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
+        return originalGraphics.drawImage(img, x, y, width, height, bgcolor,
+                                          observer);
     }
 
-    public boolean drawImage(final Image img, final int x, final int y, final int width, final int height, final ImageObserver observer) {
+    public boolean drawImage(final Image img, final int x, final int y, final int width, final int height,
+                             final ImageObserver observer) {
+        if (isLogging()) {
+            log("Drawing image: " + img + " at " + new Rectangle(x, y, width, height));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillRect(x, y, img.getHeight(observer), img.getHeight(observer));    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         return originalGraphics.drawImage(img, x, y, width, height, observer);
     }
 
-    public boolean drawImage(final Image img, final int dx1, final int dy1, final int dx2, final int dy2, final int sx1, final int sy1, final int sx2, final int sy2, final Color bgcolor, final ImageObserver observer) {
+    public boolean drawImage(final Image img, final int dx1, final int dy1, final int dx2, final int dy2, 
+                             final int sx1, final int sy1, final int sx2, final int sy2,
+                             final Color bgcolor, final ImageObserver observer) {
+        if (isLogging()) {
+            log("Drawing image: " + img + ", destination: " + new Rectangle(dx1, dy1, dx2, dy2) + ", source: "
+                + new Rectangle(sx1, sy1, sx2, sy2) + ", bgcolor: " + bgcolor);
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillRect(dx1, dy1, dx2 - dx1, dy2 - dy1);    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         return originalGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
     }
 
-    public boolean drawImage(final Image img, final int dx1, final int dy1, final int dx2, final int dy2, final int sx1, final int sy1, final int sx2, final int sy2, final ImageObserver observer) {
+    public boolean drawImage(final Image img, final int dx1, final int dy1, final int dx2, final int dy2,
+                             final int sx1, final int sy1, final int sx2, final int sy2,
+                             final ImageObserver observer) {
+
+        if (isLogging()) {
+            log("Drawing image: " + img + ", destination: " + new Rectangle(dx1, dy1, dx2, dy2) + ", source: "
+                + new Rectangle(sx1, sy1, sx2, sy2));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillRect(dx1, dy1, dx2 - dx1, dy2 - dy1);    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         return originalGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
     }
 
     public void drawLine(final int x1, final int y1, final int x2, final int y2) {
+        if (isLogging()) {
+            log("Drawing line: from (" + x1 + ", " + y1 + ") to (" + x2 + ", " + y2 + ")");
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.drawLine(x1, y1, x2, y2);
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {            
+            new BufferedDrawAction() {
+                public void paint(Graphics g) {
+                    g.drawLine(x1, y1, x2, y2);                    
+                }                
+            }.actionPerformed(null);
+        }
         originalGraphics.drawLine(x1, y1, x2, y2);
     }
 
     public void drawOval(final int x, final int y, final int width, final int height) {
+        if (isLogging()) {
+            log("Drawing oval: " + new Rectangle(x, y, width, height));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.drawOval(x, y, width, height);
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.drawOval(x, y, width, height);
     }
 
     public void drawPolygon(final int[] xPoints, final int[] yPoints, final int nPoints) {
+        if (isLogging()) {
+            log("Drawing polygon: " + new Polygon(xPoints, yPoints, nPoints));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.drawPolygon(xPoints, yPoints, nPoints);
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.drawPolygon(xPoints, yPoints, nPoints);
     }
 
     public void drawPolyline(final int[] xPoints, final int[] yPoints, final int nPoints) {
+        if (isLogging()) {
+            log("Drawing polyline: " + new Polygon(xPoints, yPoints, nPoints));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.drawPolyline(xPoints, yPoints, nPoints);
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.drawPolyline(xPoints, yPoints, nPoints);
     }
 
     public void drawRect(final int x, final int y, final int width, final int height) {
+        if (isLogging()) {
+            log("Drawing rectangle: " + new Rectangle(x, y, width, height));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.drawRect(x, y, width, height);
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.drawRect(x, y, width, height);
     }
 
     public void drawRoundRect(final int x, final int y, final int width, final int height, final int arcWidth, final int arcHeight) {
+        if (isLogging()) {
+            log("Drawing round rectangle: " + new Rectangle(x, y, width, height) + ", arcWidth " + arcWidth + ", arcHeight " + arcHeight);
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
     }
 
     public void drawString(final AttributedCharacterIterator iterator, final int x, final int y) {
+        if (isLogging()) {
+            log("Drawing string: " + iterator + " at " + new Point(x, y));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.drawString(iterator, x, y);
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.drawString(iterator, x, y);
     }
 
     public void drawString(final String str, final int x, final int y) {
+        if (isLogging()) {
+            log("Drawing string: " + str + " at " + new Point(x, y));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.drawString(str, x, y);
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.drawString(str, x, y);
     }
 
     public void fill3DRect(final int x, final int y, final int width, final int height, final boolean raised) {
+        if (isLogging()) {
+            log("Filling 3D rect: " + new Rectangle(x, y, width, height) + ", raised bezel: " + raised);
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fill3DRect(x, y, width, height, raised);
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.fill3DRect(x, y, width, height, raised);
     }
 
     public void fillArc(final int x, final int y, final int width, final int height, final int startAngle, final int arcAngle) {
+        if (isLogging()) {
+            log("Filling arc: " + new Rectangle(x, y, width, height) + ", startAngle: " + startAngle + ", arcAngle: " + arcAngle);
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillArc(x, y, width, height, startAngle, arcAngle);    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
     }
 
     public void fillOval(final int x, final int y, final int width, final int height) {
+        if (isLogging()) {
+            log("Filling oval: " + new Rectangle(x, y, width, height));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillOval(x, y, width, height);    
+                }                
+            }.actionPerformed(null);          
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.fillOval(x, y, width, height);
     }
 
     public void fillPolygon(final int[] xPoints, final int[] yPoints, final int nPoints) {
+        if (isLogging()) {
+            log("Filling polygon: " + new Polygon(xPoints, yPoints, nPoints));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillPolygon(xPoints, yPoints, nPoints);   
+                }                
+            }.actionPerformed(null);           
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.fillPolygon(xPoints, yPoints, nPoints);
     }
 
     public void fillRect(final int x, final int y, final int width, final int height) {
+        if (isLogging()) {
+            log("Filling rectangle: " + new Rectangle(x, y, width, height));
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillRect(x, y, width, height);    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+            new BufferedDrawAction() {
+                public void paint(Graphics g) {
+                    g.fillRect(x, y, width, height);
+                }                
+            }.actionPerformed(null);
+        }
         originalGraphics.fillRect(x, y, width, height);
-    }
+    }    
 
-    public void fillRoundRect(final int x, final int y, final int width, final int height, final int arcWidth, final int arcHeight) {
+    public void fillRoundRect(final int x, final int y, final int width, final int height, final int arcWidth,final int arcHeight) {
+        if (isLogging()) {
+            log("Filling round rectangle: " + new Rectangle(x, y, width, height) + ", arcWidth " + arcWidth + ", arcHeight " + arcHeight);
+        }
+        if (isFlashing()) {
+            new FlashAction(originalGraphics) {
+                public void paint(Graphics g) {
+                    g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);    
+                }                
+            }.actionPerformed(null);
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
     }
 
@@ -261,30 +690,100 @@
     }
 
     public void setClip(final int x, final int y, final int width, final int height) {
+        if (isLogging()) {
+            log("Setting new clipRect: " + new Rectangle(x, y, width, height));
+        }
+        if (isFlashing()) {
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.setClip(x, y, width, height);
     }
 
     public void setClip(final Shape shape) {
+        if (isLogging()) {
+            log("Setting clip: " + shape);
+        }
+        if (isFlashing()) {
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.setClip(shape);
     }
 
     public void setColor(final Color c) {
+        if (isLogging()) {
+            log("Setting color: " + c);
+        }
+        if (isFlashing()) {
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.setColor(c);
     }
 
     public void setFont(final Font font) {
+        if (isLogging()) {
+            log("Setting font: " + font);
+        }
+        if (isFlashing()) {
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.setFont(font);
     }
 
     public void setPaintMode() {
+        if (isLogging()) {
+            log("Setting paint mode");
+        }
+        if (isFlashing()) {
+        }
+        if (isBuffered()) {
+        }       
         originalGraphics.setPaintMode();
     }
 
     public void setXORMode(final Color c) {
+        if (isLogging()) {
+            log("Setting XOR mode, color : " + c);
+        }
+        if (isFlashing()) {
+        }
+        if (isBuffered()) {
+        }       
         originalGraphics.setXORMode(c);
     }
 
     public void translate(final int x, final int y) {
+        if (isLogging()) {
+            log("Translating by: " + new Point(x, y));
+        }
+        if (isFlashing()) {
+        }
+        if (isBuffered()) {
+        }
         originalGraphics.translate(x, y);
+    }
+
+    private String getName() {
+        return "DebugGraphics(" + thisNumber + ", mode " + debugOptions + ")";
+    }
+
+    private void log(final String text) {
+        logStream.println(getName() + " " + text);
+    }
+    
+    private boolean isLogging() {
+        return (debugOptions & LOG_OPTION) != 0;
+    }
+
+    private boolean isFlashing() {
+        return (debugOptions & FLASH_OPTION) != 0;
+    }
+
+    private boolean isBuffered() {
+//        return (debugOptions & BUFFERED_OPTION) != 0;
+        return false;
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DefaultCellEditor.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DefaultCellEditor.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DefaultCellEditor.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DefaultCellEditor.java Wed Sep  6 09:06:15 2006
@@ -32,6 +32,8 @@
 import javax.swing.table.TableCellEditor;
 import javax.swing.tree.TreeCellEditor;
 
+import org.apache.harmony.x.swing.StringConstants;
+
 public class DefaultCellEditor extends AbstractCellEditor implements TableCellEditor, TreeCellEditor {
     protected class EditorDelegate implements ActionListener, ItemListener, Serializable {
         protected Object value;
@@ -127,6 +129,8 @@
         };
         comboBox.addActionListener(delegate);
         setClickCountToStart(1);
+        
+        comboBox.putClientProperty(StringConstants.IS_TABLE_EDITOR, Boolean.TRUE);
     }
 
     public Component getComponent() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DefaultListSelectionModel.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DefaultListSelectionModel.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DefaultListSelectionModel.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/DefaultListSelectionModel.java Wed Sep  6 09:06:15 2006
@@ -163,7 +163,7 @@
         if (!isValidInterval(intervalEnd1, intervalEnd2)) {
             return;
         }
-        
+
         Selection oldSelection = (Selection)selection.clone();
         selection.clear();
 
@@ -174,12 +174,12 @@
         if (!isValidInterval(intervalEnd1, intervalEnd2)) {
             return;
         }
-        
+
         Selection oldSelection = (Selection)selection.clone();
         if (selectionMode == SINGLE_SELECTION || selectionMode == SINGLE_INTERVAL_SELECTION) {
             selection.clear();
         }
-        
+
         setSelectionAndUpdateLeadAnchor(intervalEnd1, intervalEnd2, oldSelection);
     }
 
@@ -187,7 +187,7 @@
         if (!isValidInterval(intervalEnd1, intervalEnd2)) {
             return;
         }
-        
+
         Segment interval = new Segment(intervalEnd1, intervalEnd2);
         Selection oldSelection = (Selection)selection.clone();
 
@@ -230,7 +230,7 @@
         if (!isValidInterval(index, length)) {
             return;
         }
-        
+
         Selection oldSelection = (Selection)selection.clone();
         int insertionIndex = before ? index : index + 1;
         selection.insertIndices(index, length, selectionMode != SINGLE_SELECTION);
@@ -252,7 +252,7 @@
         if (!isValidInterval(intervalEnd1, intervalEnd2)) {
             return;
         }
-        
+
         Selection oldSelection = (Selection)selection.clone();
 
         Segment removalInterval = new Segment(intervalEnd1, intervalEnd2);
@@ -280,7 +280,10 @@
     }
 
     public void setLeadSelectionIndex(final int leadIndex) {
-        if (leadIndex < 0) {
+        if (leadIndex < 0 && anchorSelectionIndex < 0) {
+            leadSelectionIndex = leadIndex;
+        }
+        if (leadIndex < 0 || anchorSelectionIndex < 0) {
             return;
         }
 
@@ -301,6 +304,16 @@
         doNotification(selection.getDifferenceBounds(oldSelection), anchorSelectionIndex, oldLead);
     }
 
+    public void moveLeadSelectionIndex(final int leadIndex) {
+        if (leadIndex < 0 || leadSelectionIndex == leadIndex) {
+            return;
+        }
+
+        int oldIndex = leadSelectionIndex;
+        leadSelectionIndex = leadIndex;
+        doNotification(null, anchorSelectionIndex, oldIndex);
+    }
+
     public int getLeadSelectionIndex() {
         return leadSelectionIndex;
     }
@@ -465,8 +478,6 @@
 
     private void setSelectionAndUpdateLeadAnchor(final int intervalEnd1, final int intervalEnd2,
                                                  final Selection oldSelection) {
-        
-        
         int oldAnchor = anchorSelectionIndex;
         int oldLead = leadSelectionIndex;
 
@@ -480,7 +491,7 @@
 
         doNotification(selection.getDifferenceBounds(oldSelection), oldAnchor, oldLead);
     }
-    
+
     private boolean isValidInterval(final int n1, final int n2) {
         return n1 >= 0 && n2 >= 0;
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JColorChooser.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JColorChooser.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JColorChooser.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JColorChooser.java Wed Sep  6 09:06:15 2006
@@ -50,8 +50,6 @@
     public static final String PREVIEW_PANEL_PROPERTY = "previewPanel";
     public static final String CHOOSER_PANELS_PROPERTY = "chooserPanels";
     
-    protected AccessibleContext accessibleContext;
-
     private ColorSelectionModel colorSelectionModel;
     private boolean dragEnabled;
     private JComponent previewPanel;
@@ -122,15 +120,13 @@
         };
         
         String okText = UIManager.getString("ColorChooser.okText");
-        JButton okButton = new JButton(okText);
-        if (okListener != null) {
-            okButton.addActionListener(okListener);
-        }
+        final JButton okButton = new JButton(okText);
+        okButton.addActionListener(okListener);
+        
         String cancelText = UIManager.getString("ColorChooser.cancelText");
-        JButton cancelButton = new JButton(cancelText);
-        if (cancelListener != null) {
-            cancelButton.addActionListener(cancelListener);
-        }
+        final JButton cancelButton = new JButton(cancelText);
+        cancelButton.addActionListener(cancelListener);
+        
         String resetText = UIManager.getString("ColorChooser.resetText");
         JButton resetButton = new JButton(resetText);
         int resetMnemonic = UIManager.getInt("ColorChooser.resetMnemonic");
@@ -145,11 +141,13 @@
         cancelButton.addActionListener(disposeListener);
         
         buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
+        buttonsPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 5));
         buttonsPanel.add(Box.createHorizontalGlue());
         buttonsPanel.add(okButton);
+        buttonsPanel.add(Box.createHorizontalStrut(6));
         buttonsPanel.add(cancelButton);
+        buttonsPanel.add(Box.createHorizontalStrut(6));
         buttonsPanel.add(resetButton);
-        buttonsPanel.add(Box.createHorizontalGlue());
         
         result.add(buttonsPanel, BorderLayout.SOUTH);
         result.getRootPane().setDefaultButton(okButton);
@@ -160,7 +158,7 @@
         SwingUtilities.replaceUIInputMap(chooserPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, map);
         chooserPane.getActionMap().put("cancelAction", new AbstractAction() {
             public void actionPerformed(ActionEvent e) {
-                result.dispose();
+                cancelButton.doClick(0);
             }
         });
         

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComboBox.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComboBox.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComboBox.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComboBox.java Wed Sep  6 09:06:15 2006
@@ -150,7 +150,6 @@
     }
 
     private static final String UI_CLASS_ID = "ComboBoxUI";
-    private static final String LIGHTWEIGHT_POPUP_ENABLED_PROPERTY_CHANGED = "lightWeightPopupEnabled";
     private static final String MAXIMUM_ROW_COUNT_PROPERTY_CHANGED = "maximumRowCount";
     private static final String PROTOTYPE_DISPLAY_VALUE_PROPERTY_CHANGED = "prototypeDisplayValue";
 
@@ -223,7 +222,7 @@
     public void setLightWeightPopupEnabled(final boolean isEnabled) {
         if (lightWeightPopupEnabled != isEnabled) {
             lightWeightPopupEnabled = isEnabled;
-            firePropertyChange(LIGHTWEIGHT_POPUP_ENABLED_PROPERTY_CHANGED, !isEnabled, isEnabled);
+            firePropertyChange(StringConstants.LIGHTWEIGHT_POPUP_ENABLED_PROPERTY_CHANGED, !isEnabled, isEnabled);
         }
     }
 
@@ -289,11 +288,11 @@
     public void setSelectedItem(final Object element) {
         selectedItemReminder = dataModel.getSelectedItem();
 
-        if (selectedItemReminder == null || !selectedItemReminder.equals(element)) {
-            if (isEditable || getIndex(element) != -1) {
-                if (element != getSelectedItem() || element != null && !element.equals(getSelectedItem())) {
-                    dataModel.setSelectedItem(element);
-                }
+        if (isEditable || getIndex(element) != -1 || element == null) {
+            if (element != getSelectedItem() || element != null && !element.equals(getSelectedItem())) {
+                dataModel.setSelectedItem(element);
+            } else if (isEditable && element != null && !element.equals(getEditor().getItem())) {
+                getEditor().setItem(element);
             }
         }
     }
@@ -472,6 +471,7 @@
     public void showPopup() {
         setPopupVisible(true);
     }
+
     public void hidePopup() {
         setPopupVisible(false);
     }
@@ -530,6 +530,7 @@
 
     public void actionPerformed(final ActionEvent e) {
         setSelectedItem(editor.getItem());
+        getUI().setPopupVisible(this, false);
     }
 
     public void contentsChanged(final ListDataEvent e) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComponent.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComponent.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComponent.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JComponent.java Wed Sep  6 09:06:15 2006
@@ -19,6 +19,7 @@
  */
 package javax.swing;
 
+import java.applet.Applet;
 import java.awt.AWTEvent;
 import java.awt.Component;
 import java.awt.Container;
@@ -627,8 +628,7 @@
 
     public Container getTopLevelAncestor() {
         for(Container parent = getParent(); parent != null; parent = parent.getParent()) {
-            // TODO: Code should be uncommented when JApplet is supported
-            if(parent instanceof Window /*|| parent instanceof Applet*/) {
+            if(parent instanceof Window || parent instanceof Applet) {
                 return parent;
             }
         }
@@ -650,7 +650,7 @@
     }
 
     public final void setInputMap(final int condition, final InputMap map) {
-        if (condition == WHEN_IN_FOCUSED_WINDOW && !(map instanceof ComponentInputMap)) {
+        if (condition == WHEN_IN_FOCUSED_WINDOW && !(map instanceof ComponentInputMap) && map != null) {
             throw new IllegalArgumentException("For WHEN_IN_FOCUSED_WINDOW condition " +
                                                "ComponentInputMap has to be provided");
         }
@@ -1163,6 +1163,7 @@
     }
 
     public void revalidate() {
+        invalidate();
         RepaintManager.currentManager(this).addInvalidComponent(this);
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JLayeredPane.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JLayeredPane.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JLayeredPane.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JLayeredPane.java Wed Sep  6 09:06:15 2006
@@ -253,13 +253,14 @@
      * @param position the position to set
      */
     public void setPosition(final Component c, final int position) {
+        int layer = getLayer(c);
         int index = getIndexOf(c);
         if (index == -1) {
             // do nothing if c is not in the container
             return;
         }
 
-        setLayer(c, getLayer(c), position);
+        setLayer(c, layer, position);
     }
 
     /**
@@ -306,6 +307,10 @@
      * @return layer of component c
      */
     public int getLayer(final Component c) {
+        if (c == null) {
+            return -1;
+        }
+
         Object layer = getComponentToLayer().get(c);
         if (layer != null) {
             return ((Integer)layer).intValue();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JList.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JList.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JList.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JList.java Wed Sep  6 09:06:15 2006
@@ -61,6 +61,7 @@
 import javax.swing.text.Position;
 
 import org.apache.harmony.x.swing.StringConstants;
+import org.apache.harmony.x.swing.Utilities;
 
 
 public class JList extends JComponent implements Scrollable, Accessible {
@@ -741,44 +742,16 @@
     }
 
     public int getNextMatch(final String prefix, final int startIndex, final Position.Bias bias) {
-        if (prefix == null) {
-            throw new IllegalArgumentException("Prefix must be not null");
-        }
-
-        if (startIndex < 0 || startIndex >= model.getSize()) {
-            throw new IllegalArgumentException("Incorrect start index");
-        }
-
-        String ucPrefix = prefix.toUpperCase();
-        if (Position.Bias.Forward == bias) {
-            for (int i = startIndex; i < model.getSize(); i++) {
-                String elementAsString = model.getElementAt(i).toString().toUpperCase();
-                if (elementAsString.startsWith(ucPrefix)) {
-                    return i;
-                }
-            }
-            for (int i = 0; i < startIndex; i++) {
-                String elementAsString = model.getElementAt(i).toString().toUpperCase();
-                if (elementAsString.startsWith(ucPrefix)) {
-                    return i;
-                }
+        return Utilities.getNextMatch(new Utilities.ListModelAccessor() {
+            public Object getElementAt(final int index) {
+                return model.getElementAt(index);
             }
-        } else if (Position.Bias.Backward == bias) {
-            for (int i = startIndex; i >= 0; i--) {
-                String elementAsString = model.getElementAt(i).toString().toUpperCase();
-                if (elementAsString.startsWith(ucPrefix)) {
-                    return i;
-                }
-            }
-            for (int i = model.getSize() - 1; i > startIndex; i--) {
-                String elementAsString = model.getElementAt(i).toString().toUpperCase();
-                if (elementAsString.startsWith(ucPrefix)) {
-                    return i;
-                }
-            }
-        }
 
-        return -1;
+            public int getSize() {
+                return model.getSize();
+            }
+            
+        }, prefix, startIndex, bias);
     }
 
     public Rectangle getCellBounds(final int index0, final int index1) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JOptionPane.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JOptionPane.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JOptionPane.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JOptionPane.java Wed Sep  6 09:06:15 2006
@@ -206,6 +206,7 @@
         pane.setWantsInput(true);
 
         JDialog dialog = pane.createDialog(parentComponent, title);
+        setDialogDecorations(dialog, messageType);
         dialog.setVisible(true);
 
         return pane.getInputValue();
@@ -224,6 +225,7 @@
             final String title, final int messageType, final Icon icon) throws HeadlessException {
         JOptionPane pane = new JOptionPane(message, messageType, DEFAULT_OPTION, icon);
         JDialog dialog = pane.createDialog(parentComponent, title);
+        setDialogDecorations(dialog, messageType);
         dialog.setVisible(true);
     }
 
@@ -249,6 +251,7 @@
             final Icon icon) throws HeadlessException {
         JOptionPane pane = new JOptionPane(message, messageType, optionType, icon);
         JDialog dialog = pane.createDialog(parentComponent, title);
+        setDialogDecorations(dialog, messageType);
         dialog.setVisible(true);
 
         return getResultedIndex(pane);
@@ -278,6 +281,7 @@
             final Object initialValue) throws HeadlessException {
         JOptionPane pane = new JOptionPane(message, messageType, optionType, icon, options, initialValue);
         JDialog dialog = pane.createDialog(parentComponent, title);
+        setDialogDecorations(dialog, messageType);
         dialog.setVisible(true);
 
         return getResultedIndex(pane);
@@ -297,6 +301,7 @@
             final Icon icon) {
         JOptionPane pane = new JOptionPane(message, messageType, DEFAULT_OPTION, icon);
         JDialog dialog = pane.createDialog(parentComponent, title);
+        setDialogDecorations(dialog, messageType);
         JInternalFrame internalFrame = pane.createInternalFrame(parentComponent, title);
         showInternalFrameAndWaitTillClosed(internalFrame, pane, parentComponent);
     }
@@ -324,6 +329,7 @@
             final int messageType, final Icon icon) {
         JOptionPane pane = new JOptionPane(message, messageType, optionType, icon);
         JDialog dialog = pane.createDialog(parentComponent, title);
+        setDialogDecorations(dialog, messageType);
         JInternalFrame internalFrame = pane.createInternalFrame(parentComponent, title);
         showInternalFrameAndWaitTillClosed(internalFrame, pane, parentComponent);
 
@@ -336,6 +342,7 @@
             final Object[] options, final Object initialValue) {
         JOptionPane pane = new JOptionPane(message, messageType, optionType, icon, options, initialValue);
         JDialog dialog = pane.createDialog(parentComponent, title);
+        setDialogDecorations(dialog, messageType);
         JInternalFrame internalFrame = pane.createInternalFrame(parentComponent, title);
         showInternalFrameAndWaitTillClosed(internalFrame, pane, parentComponent);
 
@@ -364,6 +371,7 @@
             pane.setInitialSelectionValue(initialSelectionValue);
         }
         JDialog dialog = pane.createDialog(parentComponent, title);
+        setDialogDecorations(dialog, messageType);
         JInternalFrame internalFrame = pane.createInternalFrame(parentComponent, title);
         showInternalFrameAndWaitTillClosed(internalFrame, pane, parentComponent);
 
@@ -394,6 +402,7 @@
         }
 
         JInternalFrame frame = new JInternalFrame(title);
+        frame.putClientProperty("JInternalFrame.optionDialog", Boolean.TRUE);
         parent.add(frame);
         frame.add(this);
         frame.pack();
@@ -604,5 +613,23 @@
 
         return -1;
     }
-
+    
+    private static int messageTypeToRootPaneDecoration(final int messageType) {
+        switch (messageType) {
+        case ERROR_MESSAGE:
+            return JRootPane.ERROR_DIALOG;
+        case INFORMATION_MESSAGE:
+            return JRootPane.INFORMATION_DIALOG;
+        case QUESTION_MESSAGE:
+            return JRootPane.QUESTION_DIALOG;
+        case WARNING_MESSAGE:
+            return JRootPane.WARNING_DIALOG;
+        default:
+            return JRootPane.PLAIN_DIALOG;
+        }
+    }
+    
+    private static void setDialogDecorations(final JDialog dialog, final int messageType) {
+        dialog.getRootPane().setWindowDecorationStyle(messageTypeToRootPaneDecoration(messageType));
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JPopupMenu.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JPopupMenu.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JPopupMenu.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JPopupMenu.java Wed Sep  6 09:06:15 2006
@@ -463,10 +463,8 @@
             } else {
                 newPath = Utilities.addToPath(oldPath, this);
             }
-        } else {
-            newPath = Utilities.removeFromPath(oldPath, this);
+            manager.setSelectedPath(newPath);
         }
-        manager.setSelectedPath(newPath);
     }
 
     private void endMouseGrab() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTabbedPane.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTabbedPane.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTabbedPane.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTabbedPane.java Wed Sep  6 09:06:15 2006
@@ -26,6 +26,7 @@
 import java.awt.Point;
 import java.awt.Rectangle;
 
+import java.awt.event.InputEvent;
 import java.awt.event.MouseEvent;
 
 import java.io.Serializable;
@@ -42,6 +43,8 @@
 import javax.swing.plaf.TabbedPaneUI;
 import javax.swing.plaf.UIResource;
 
+import org.apache.harmony.x.swing.StringConstants;
+
 public class JTabbedPane extends JComponent
     implements Serializable, Accessible, SwingConstants {
 
@@ -493,6 +496,16 @@
     }
 
     public void setMnemonicAt(final int tabIndex, final int mnemonic) {
+        int oldValue = getMnemonicAt(tabIndex);
+        if (oldValue == mnemonic) {
+            return;
+        }
+
+        InputMap inputMap = getInputMap(WHEN_IN_FOCUSED_WINDOW, true);
+        inputMap.remove(KeyStroke.getKeyStroke(oldValue, InputEvent.ALT_DOWN_MASK));
+        inputMap.put(KeyStroke.getKeyStroke(mnemonic, InputEvent.ALT_DOWN_MASK),
+                     StringConstants.MNEMONIC_ACTION);
+
         getTabAt(tabIndex).setMnemonic(mnemonic);
         repaint();
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTable.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTable.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTable.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JTable.java Wed Sep  6 09:06:15 2006
@@ -76,7 +76,6 @@
 import javax.swing.table.TableModel;
 
 import org.apache.harmony.x.swing.StringConstants;
-import org.apache.harmony.x.swing.Utilities;
 
 
 public class JTable extends JComponent implements TableModelListener, Scrollable, TableColumnModelListener, ListSelectionListener, CellEditorListener, Accessible {
@@ -658,6 +657,8 @@
     private boolean dragEnabled;
     private Vector rowHeights = new Vector();
     private boolean surrendersFocusOnKeystroke;
+    private boolean wasConsumed;
+
 
     private static final String HEADER_PROPERTY = "tableHeader";
     private static final String ROW_HEIGHT_PROPERTY = "rowHeight";
@@ -694,8 +695,8 @@
 
     public JTable(final TableModel model, final TableColumnModel columnModel, final ListSelectionModel selectionModel) {
         setColumnModel(columnModel != null ? columnModel : createDefaultColumnModel());
-        setSelectionModel(selectionModel != null ? selectionModel : createDefaultSelectionModel());
         setModel(model != null ? model : createDefaultDataModel());
+        setSelectionModel(selectionModel != null ? selectionModel : createDefaultSelectionModel());
 
         initializeLocalVars();
 
@@ -970,8 +971,19 @@
 
 
     public void selectAll() {
-        getSelectionModel().setSelectionInterval(0, getRowCount() - 1);
-        getColumnModel().getSelectionModel().setSelectionInterval(0, getColumnCount() - 1);
+        int rowLead = getSelectionModel().getLeadSelectionIndex();
+        int rowAnchor = getSelectionModel().getAnchorSelectionIndex();
+        int columnLead = getColumnModel().getSelectionModel().getLeadSelectionIndex();
+        int columnAnchor = getColumnModel().getSelectionModel().getAnchorSelectionIndex();
+
+        getSelectionModel().setValueIsAdjusting(true);
+        getColumnModel().getSelectionModel().setValueIsAdjusting(true);
+        setRowSelectionInterval(0, getRowCount() - 1);
+        getSelectionModel().addSelectionInterval(rowAnchor, rowLead);
+        setColumnSelectionInterval(0, getColumnCount() - 1);
+        getColumnModel().getSelectionModel().addSelectionInterval(columnAnchor, columnLead);
+        getSelectionModel().setValueIsAdjusting(false);
+        getColumnModel().getSelectionModel().setValueIsAdjusting(false);
     }
 
     public void clearSelection() {
@@ -1048,18 +1060,18 @@
 
     public void changeSelection(final int row, final int column, final boolean toggle, final boolean extend) {
         if (!toggle && !extend) {
-            getSelectionModel().setSelectionInterval(row, row);
-            getColumnModel().getSelectionModel().setSelectionInterval(column, column);
+            setRowSelectionInterval(row, row);
+            setColumnSelectionInterval(column, column);
         } else if (!toggle && extend) {
-            getSelectionModel().setSelectionInterval(getSelectionModel().getAnchorSelectionIndex(), row);
-            getColumnModel().getSelectionModel().setSelectionInterval(getColumnModel().getSelectionModel().getAnchorSelectionIndex(), column);
+            setRowSelectionInterval(getSelectionModel().getAnchorSelectionIndex(), row);
+            setColumnSelectionInterval(getColumnModel().getSelectionModel().getAnchorSelectionIndex(), column);
         } else if (toggle && !extend) {
             if (isCellSelected(row, column)) {
-                getSelectionModel().removeSelectionInterval(row, row);
-                getColumnModel().getSelectionModel().removeSelectionInterval(column, column);
+                removeRowSelectionInterval(row, row);
+                removeColumnSelectionInterval(column, column);
             } else {
-                getSelectionModel().addSelectionInterval(row, row);
-                getColumnModel().getSelectionModel().addSelectionInterval(column, column);
+                addRowSelectionInterval(row, row);
+                addColumnSelectionInterval(column, column);
             }
         } else {
             getSelectionModel().setAnchorSelectionIndex(row);
@@ -1387,7 +1399,7 @@
         columnModel = model;
         JTableHeader header = getTableHeader();
         if (header != null) {
-            columnModel.addColumnModelListener(getTableHeader());
+            columnModel.addColumnModelListener(header);
         }
         columnModel.addColumnModelListener(this);
     }
@@ -1408,6 +1420,7 @@
 
         selectionModel = model;
         selectionModel.addListSelectionListener(this);
+        alignSelectionModelToRows();
 
         firePropertyChange(StringConstants.SELECTION_MODEL_PROPERTY, oldValue, model);
     }
@@ -1426,8 +1439,12 @@
             }
         }
 
-        updateSelectionModel(getSelectionModel(), e);
-        updateColumnSelectionModel(getColumnModel().getSelectionModel(), e);
+        if (getSelectionModel() != null) {
+            updateSelectionModel(getSelectionModel(), e);
+        }
+        if (getColumnModel().getSelectionModel() != null) {
+            updateColumnSelectionModel(getColumnModel().getSelectionModel(), e);
+        }
 
         revalidate();
         repaint();
@@ -1669,11 +1686,22 @@
     }
 
     protected void configureEnclosingScrollPane() {
-        setColumnHeader(getTableHeader());
+        JScrollPane enclosingScrollPane = getEnclosingScrollPane();
+        if (enclosingScrollPane == null) {
+            return;
+        }
+        enclosingScrollPane.setColumnHeaderView(getTableHeader());
+        enclosingScrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
+
     }
 
     protected void unconfigureEnclosingScrollPane() {
-        setColumnHeader(null);
+        JScrollPane enclosingScrollPane = getEnclosingScrollPane();
+        if (enclosingScrollPane == null) {
+            return;
+        }
+        enclosingScrollPane.setColumnHeaderView(null);
+        enclosingScrollPane.setBorder(null);
     }
 
     protected void createDefaultRenderers() {
@@ -1719,18 +1747,28 @@
     protected void processKeyEvent(final KeyEvent event) {
         super.processKeyEvent(event);
         if (event.isConsumed()) {
+            wasConsumed = true;
+        }
+
+        if (event.getID() == KeyEvent.KEY_RELEASED) {
+            wasConsumed = false;
+            return;
+        }
+        if (wasConsumed) {
             return;
         }
 
         if (event.getKeyCode() == KeyEvent.VK_SHIFT
             || event.getKeyCode() == KeyEvent.VK_ALT
-            || event.getKeyCode() == KeyEvent.VK_CONTROL) {
-
-            return;
-        }
+            || event.getKeyCode() == KeyEvent.VK_ALT_GRAPH
+            || event.getKeyCode() == KeyEvent.VK_CONTROL
+            || event.getKeyCode() == KeyEvent.VK_PRINTSCREEN
+            || event.getKeyCode() == KeyEvent.VK_CAPS_LOCK
+            || event.getKeyCode() == KeyEvent.VK_NUM_LOCK
+            || event.getKeyCode() == KeyEvent.VK_SCROLL_LOCK
+            || event.isAltDown()
+            || event.isControlDown()) {
 
-        KeyStroke pressStroke = getPressedKeyStroke(event);
-        if (pressStroke == null || getActionForKeyStroke(pressStroke) != null) {
             return;
         }
 
@@ -1754,25 +1792,16 @@
         }
     }
 
-
-    private KeyStroke getPressedKeyStroke(final KeyEvent e) {
-        if (e.getID() == KeyEvent.KEY_PRESSED) {
-            return KeyStroke.getKeyStrokeForEvent(e);
-        } else if (e.getID() == KeyEvent.KEY_RELEASED) {
-            return KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers(), false);
-        } else {
-            return KeyStroke.getKeyStroke(Utilities.keyCharToKeyCode(e.getKeyChar()), e.getModifiers(), false);
-        }
-    }
-
-    private void setColumnHeader(final Component c) {
+    private JScrollPane getEnclosingScrollPane() {
         if (getParent() instanceof JViewport
             && ((JViewport)getParent()).getView() == this) {
 
             if (getParent().getParent() instanceof JScrollPane) {
-                ((JScrollPane)getParent().getParent()).setColumnHeaderView(c);
+                return (JScrollPane)getParent().getParent();
             }
         }
+
+        return null;
     }
 
     private Object getClosestClass(final Class columnClass, final Hashtable classes) {
@@ -1829,9 +1858,11 @@
     private void updateSelectionModel(final ListSelectionModel model, final TableModelEvent e) {
         if (e.getType() == TableModelEvent.INSERT) {
             model.insertIndexInterval(e.getFirstRow(), e.getLastRow() - e.getFirstRow() + 1, true);
+            alignSelectionModelToRows();
         }
         if (e.getType() == TableModelEvent.DELETE) {
             model.removeIndexInterval(e.getFirstRow(), e.getLastRow());
+            alignSelectionModelToRows();
         }
 
         if (e.getType() == TableModelEvent.UPDATE
@@ -1925,7 +1956,7 @@
         if (resizable.getElementsCount() == 0) {
             return;
         }
-        
+
         long minColsWidth = 0;
         long maxColsWidth = 0;
         long colsWidth = 0;
@@ -1987,7 +2018,7 @@
                 result = i;
             }
         }
-        
+
         widths[result]--;
     }
 
@@ -1999,10 +2030,23 @@
                 result = i;
             }
         }
-        
+
         widths[result]++;
     }
 
+    private void alignSelectionModelToRows() {
+        if (getRowCount() == 0) {
+            if (selectionModel.getAnchorSelectionIndex() >= 0) {
+                selectionModel.setValueIsAdjusting(true);
+                selectionModel.setAnchorSelectionIndex(-1);
+                selectionModel.setLeadSelectionIndex(-1);
+                selectionModel.setValueIsAdjusting(false);
+            }
+        } else if (selectionModel.getLeadSelectionIndex() < 0) {
+            selectionModel.removeSelectionInterval(0, 0);
+        }
+     }
+
     private interface ResizableElements {
         int getElementsCount();
         TableColumn getElement(int i);
@@ -2118,9 +2162,14 @@
                 final boolean hasFocus,
                 final int row, final int column) {
 
+            
             JLabel result = (JLabel)super.getTableCellRendererComponent(table, null, isSelected, hasFocus, row, column);
             if (value != null) {
-                result.setIcon(new ImageIcon(value.toString()));
+                if (value instanceof Icon) {
+                    result.setIcon((Icon)value);
+                } else {
+                    result.setIcon(new ImageIcon(value.toString()));
+                }
                 result.setHorizontalAlignment(SwingConstants.CENTER);
                 result.setVerticalAlignment(SwingConstants.CENTER);
             } else {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/MenuSelectionManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/MenuSelectionManager.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/MenuSelectionManager.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/MenuSelectionManager.java Wed Sep  6 09:06:15 2006
@@ -87,7 +87,7 @@
             }
         }
         if (selectedPath != null) {
-            for (int j = diffStart; j < selectedPath.length; j++) {
+            for (int j = selectedPath.length - 1; j >= diffStart; j--) {
                 selectedPath[j].menuSelectionChanged(false);
             }
         }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/RepaintManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/RepaintManager.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/RepaintManager.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/RepaintManager.java Wed Sep  6 09:06:15 2006
@@ -91,8 +91,14 @@
         instance = repaintManager;
     }
 
+    /**
+     * Method doesn't perform component invalidation. It just adds component
+     * validation root to the list of roots waiting for validation and schedules
+     * it.
+     */
     public void addInvalidComponent(final JComponent invalidComponent) {
-        invalidComponent.invalidate();
+        // implementation is done according to the black-box testing and contradict to the
+        // spec: component is not marked as invalid (needed layout)
         final Component root = getValidationRoot(invalidComponent);
         if (root != null && !invalidRoots.contains(root) && !root.isValid() && root.isShowing()) {
             invalidRoots.add(root);
@@ -100,22 +106,22 @@
         }
     }
 
+    public void removeInvalidComponent(final JComponent component) {
+        invalidRoots.remove(component);
+    }
+
     public void validateInvalidComponents() {
         while(!invalidRoots.isEmpty()) {
-            List processingRoots = new ArrayList(invalidRoots);
-            invalidRoots.clear();
+            List processingRoots;
+            synchronized(invalidRoots) {
+                processingRoots = new ArrayList(invalidRoots);
+                invalidRoots.clear();
+            }
             for (Iterator it = processingRoots.iterator(); it.hasNext(); ) {
                 Component c = (Component)it.next();
                 c.validate();
             }
         }
-    }
-
-    /**
-     * It is impossile to avoid validation for the previously invalidated component since
-     * the entire hierarchy (up to the validation root) was invalidated and scheduled for validation.
-     */
-    public void removeInvalidComponent(final JComponent component) {
     }
 
     public void addDirtyRegion(final JComponent c, final int x, final int y, final int w, final int h) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/ScrollPaneLayout.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/ScrollPaneLayout.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/ScrollPaneLayout.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/ScrollPaneLayout.java Wed Sep  6 09:06:15 2006
@@ -362,11 +362,7 @@
             Insets viewportBorderInsets = pane.getViewportBorder().getBorderInsets(viewport);
             viewportWidth -= viewportBorderInsets.left + viewportBorderInsets.right;
             viewportHeight -= viewportBorderInsets.top + viewportBorderInsets.bottom;
-            if (leftToRight) {
-                viewportX += viewportBorderInsets.left;
-            } else {
-                viewportX += viewportBorderInsets.left;
-            }
+            viewportX += viewportBorderInsets.left;
             viewportY += viewportBorderInsets.top;
         }
         viewportWidth = viewportWidth > 0 ? viewportWidth : 0;

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SizeSequence.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SizeSequence.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SizeSequence.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SizeSequence.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,221 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Dennis Ushakov
+ * @version $Revision$
+ */
+package javax.swing;
+
+public class SizeSequence {    
+    private int[] tree;   
+    private int sizesCount;
+    
+    public SizeSequence() {
+        this(new int[0]);
+    }
+    
+    public SizeSequence(final int numEntries) {
+        this(numEntries, 0);
+    }
+    
+    public SizeSequence(final int numEntries, final int value) {
+        int[] sizes = new int[numEntries];
+        for (int i = 0; i < numEntries; i++) {
+            sizes[i] = value;
+        }
+        setSizes(sizes);
+    }
+    
+    public SizeSequence(final int[] sizes) {
+        setSizes(sizes);
+    }
+    
+    public void setSizes(final int[] sizes) {
+        if (sizes.length == 0) {
+            tree = new int[0];
+            sizesCount = 0; 
+            return;
+        }
+        int upper = 1;
+        while (upper - 1 < sizes.length) {
+            upper <<= 1; 
+        }
+        tree = new int[upper - 1];        
+        sizesCount = sizes.length;
+        setSizesImpl(sizes, 0, upper - 1, 0);
+}
+    
+    public int[] getSizes() {
+        if (sizesCount == 0) {
+            return new int[0];
+        }
+        int[] allSizes = new int[tree.length];
+        getSizesImpl(allSizes, 0, tree.length - 1);        
+        int[] result = new int[sizesCount];
+        System.arraycopy(allSizes, 0, result, 0, sizesCount);
+        return result;
+    }    
+    
+    public int getPosition(final int index) {
+        if (index < 0 || sizesCount == 0) {
+            return 0;
+        }
+        if (index >= sizesCount) {
+            return tree[(tree.length - 1) / 2];
+        }
+        int position = 0;
+        int left = 0;
+        int right = tree.length - 1;
+        int cur = (left + right) / 2;
+      
+        do {
+            if (cur > index) {
+                right = cur - 1;
+            } else if (cur < index) {
+                position += tree[cur];
+                position -= (right + cur + 1) / 2 == cur ? 0 : tree[(right + cur + 1) / 2];
+                left = cur + 1;
+            }
+            cur = (left + right) / 2;
+        } while(cur != index);
+        position += (cur + left) / 2 == cur ? 0 : tree[(cur + left) / 2];
+        return position;
+    }
+    
+    public int getIndex(final int position) {                
+        if (position < 0 || sizesCount == 0) {
+            return 0;
+        }
+        if (position >= tree[(tree.length - 1) / 2]) {
+            return sizesCount;
+        }
+        
+        int pos = position;
+        int left = 0;
+        int right = tree.length - 1;
+        int cur = (left + right) / 2;
+        
+        while (left != right) {
+            if (pos - tree[(cur + left) / 2] < 0) {
+                right = cur - 1;
+            } else {
+                pos -= tree[(cur + left) / 2];
+                int size = tree[cur];                
+                size -= (right + cur + 1) / 2 == cur ? 0 : tree[(right + cur + 1) / 2];
+                size -= (cur + left) / 2 == cur ? 0 : tree[(cur + left) / 2];
+                if (pos < size) {
+                    return cur < sizesCount ? cur : sizesCount;
+                } else {
+                    pos -= size;
+                    left = cur + 1;
+                }
+            }
+            cur = (left + right) / 2;
+        }
+        return cur < sizesCount ? cur : sizesCount; 
+    }
+    
+    public int getSize(final int index) {
+        if (!isValidIndex(index)) {
+            return 0;
+        }        
+        int result = tree[index];
+        int left = 0;
+        int right = tree.length - 1;
+        int cur = (left + right) / 2;
+        while (cur != index) {
+            if (cur < index) {
+                left = cur + 1; 
+            } 
+            if (cur > index) {
+                right = cur - 1;
+            }                
+            cur = (left + right) / 2;
+        }        
+        result -= (right + cur + 1) / 2 == cur ? 0 : tree[(right + cur + 1) / 2];
+        result -= (cur + left) / 2 == cur ? 0 : tree[(cur + left) / 2];
+        return result;
+    }
+    
+    public void setSize(final int index, final int size) {
+        if (!isValidIndex(index)) {
+            return;
+        }
+        int delta = size - getSize(index); 
+        int left = 0;
+        int right = tree.length - 1;
+        int cur = (left + right) / 2;
+        tree[cur] += delta;
+        while (cur != index) {
+            if (cur < index) {
+                left = cur + 1; 
+            } 
+            if (cur > index) {
+                right = cur - 1;
+            }                
+            cur = (left + right) / 2;
+            tree[cur] += delta;
+        }
+    }
+    
+    public void insertEntries(final int start, final int length, final int value) {
+        int[] newSizes = new int[sizesCount + length];
+        int[] sizes = getSizes();
+        System.arraycopy(sizes, 0, newSizes, 0, start);
+        for (int i = start; i < start + length; i++) {
+            newSizes[i] = value;
+        }
+        System.arraycopy(sizes, start, newSizes, start + length, sizes.length - start);        
+        setSizes(newSizes);
+    }
+    
+    public void removeEntries(final int start, final int length) {
+        int[] newSizes = new int[sizesCount - length];
+        int[] sizes = getSizes();
+        System.arraycopy(sizes, 0, newSizes, 0, start);
+        System.arraycopy(sizes, start + length, newSizes, start, sizes.length - start - length);
+        setSizes(newSizes);
+    }
+    
+    private boolean isValidIndex(final int index) {
+        return (index >= 0 && index < sizesCount);
+    }    
+    
+    private int setSizesImpl(final int[] sizes, final int left, final int right, final int depth) {
+        int cur = (right + left) / 2;
+        int size = (cur < sizes.length) ? sizes[cur] : 0;
+        if ((right - left) / 2 > 0) {
+            tree[cur] = size + setSizesImpl(sizes, left, cur - 1, depth + 1) + setSizesImpl(sizes, cur + 1, right, depth + 1);
+        } else if ((right - left) / 2 == 0) {            
+            tree[cur] = size;
+        } else {
+            return 0;
+        }
+        return tree[cur];
+    }
+    
+    private int getSizesImpl(final int[] sizes, final int left, final int right) {        
+        int cur = (right + left) / 2;        
+        int length = tree[cur];
+        if ((right - left) / 2 > 0) {
+            sizes[cur] = length - getSizesImpl(sizes, left, cur - 1) - getSizesImpl(sizes, cur + 1, right);
+        } else if ((right - left) / 2 == 0) {            
+            sizes[cur] = length;
+        }
+        return (right - left) / 2 < 0 ? 0 : length;
+    }        
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SortingFocusTraversalPolicy.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SortingFocusTraversalPolicy.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SortingFocusTraversalPolicy.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SortingFocusTraversalPolicy.java Wed Sep  6 09:06:15 2006
@@ -43,7 +43,32 @@
                                      .getDefaultComponent(innerCycleRoot);
             } else {
                 int nextIndex = (currentComponentIndex + 1) % availableComponents.size();
-                return (Component)availableComponents.get(nextIndex);
+                Component result = (Component)availableComponents.get(nextIndex);
+
+                if (focusCycleRoot.isFocusCycleRoot()) {
+                    Container policyProviderForCurrentComponent = getPolicyProvider(currentComponent);
+                    if (currentComponent == focusCycleRoot || policyProviderForCurrentComponent == focusCycleRoot) {
+                        if (result instanceof Container
+                            && ((Container)result).isFocusTraversalPolicyProvider()
+                            && !accept(result)) {
+
+                            Container policyProvider = (Container)result;
+
+                            return policyProvider.getFocusTraversalPolicy().getDefaultComponent(policyProvider);
+                        }
+
+                        return result;
+                    } else {
+                        Component resultFromProvider = policyProviderForCurrentComponent.getFocusTraversalPolicy().getComponentAfter(policyProviderForCurrentComponent, currentComponent);
+                        if (resultFromProvider != policyProviderForCurrentComponent.getFocusTraversalPolicy().getDefaultComponent(policyProviderForCurrentComponent)) {
+                            return resultFromProvider;
+                        } else {
+                            return focusCycleRoot.getFocusTraversalPolicy().getComponentAfter(focusCycleRoot, policyProviderForCurrentComponent);
+                        }
+                    }
+                } else {
+                    return result;
+                }
             }
         }
     };
@@ -51,7 +76,32 @@
     private final NextComponentFinder beforeComponentFinder = new NextComponentFinder() {
         public Component findNextComponent(final List availableComponents, final int currentComponentIndex) {
             int nextIndex = (currentComponentIndex + availableComponents.size() - 1) % availableComponents.size();
-            return (Component)availableComponents.get(nextIndex);
+            Component result = (Component)availableComponents.get(nextIndex);
+
+            if (focusCycleRoot.isFocusCycleRoot()) {
+                Container policyProviderForCurrentComponent = getPolicyProvider(currentComponent);
+                if (currentComponent == focusCycleRoot || policyProviderForCurrentComponent == focusCycleRoot) {
+                    if (result instanceof Container
+                        && ((Container)result).isFocusTraversalPolicyProvider()
+                        && !accept(result)) {
+
+                        Container policyProvider = (Container)result;
+
+                        return policyProvider.getFocusTraversalPolicy().getLastComponent(policyProvider);
+                    }
+
+                    return result;
+                } else {
+                    Component resultFromProvider = policyProviderForCurrentComponent.getFocusTraversalPolicy().getComponentBefore(policyProviderForCurrentComponent, currentComponent);
+                    if (resultFromProvider != policyProviderForCurrentComponent.getFocusTraversalPolicy().getLastComponent(policyProviderForCurrentComponent)) {
+                        return resultFromProvider;
+                    } else {
+                        return focusCycleRoot.getFocusTraversalPolicy().getComponentBefore(focusCycleRoot, policyProviderForCurrentComponent);
+                    }
+                }
+            } else {
+                return result;
+            }
         }
     };
 
@@ -161,11 +211,15 @@
         Component[] components = container.getComponents();
         for (int i = 0; i < components.length; i++) {
             Component component = components[i];
-            if (accept(component)) {
+            if (accept(component)
+                || ((component instanceof Container)
+                    && ((Container)component).isFocusTraversalPolicyProvider()
+                    && ((Container)component).getComponentCount() > 0)) {
+
                 result.add(component);
             }
 
-            if (component.isDisplayable() && component.isVisible() && component instanceof Container && !((Container)component).isFocusCycleRoot()) {
+            if (component.isDisplayable() && component.isVisible() && component instanceof Container && !isPolicyRoot((Container)component)) {
                 collectAllAcceptableComponents((Container)component, result);
             }
         }
@@ -175,7 +229,7 @@
 
     private Component getComponentBeforeOrAfter(final NextComponentFinder finder) {
         checkCycleRootIsNotNull(finder.focusCycleRoot);
-        if (!finder.focusCycleRoot.isFocusCycleRoot()) {
+        if (!finder.focusCycleRoot.isFocusCycleRoot() && !finder.focusCycleRoot.isFocusTraversalPolicyProvider()) {
             throw new IllegalArgumentException("Container is not a focus cycle root");
         }
 
@@ -184,7 +238,8 @@
         }
 
         if (finder.currentComponent != finder.focusCycleRoot
-            && finder.currentComponent.getFocusCycleRootAncestor() != finder.focusCycleRoot) {
+            && finder.currentComponent.getFocusCycleRootAncestor() != finder.focusCycleRoot
+            && getPolicyProvider(finder.currentComponent) != finder.focusCycleRoot) {
 
             throw new IllegalArgumentException("Component must be in a cycle root of the specified container");
         }
@@ -213,6 +268,18 @@
         if (focusCycleRoot == null) {
             throw new IllegalArgumentException("Container must be specified");
         }
+    }
+
+    private Container getPolicyProvider(final Component c) {
+        Container parent = c.getParent();
+        if (parent == null || isPolicyRoot(parent)) {
+            return parent;
+        }
+        return getPolicyProvider(parent);
+    }
+
+    private boolean isPolicyRoot(final Container c) {
+        return c.isFocusTraversalPolicyProvider() || c.isFocusCycleRoot();
     }
 
     private abstract class NextComponentFinder {



Mime
View raw message