diff options
Diffstat (limited to 'gnu/java')
19 files changed, 1867 insertions, 138 deletions
diff --git a/gnu/java/awt/peer/gtk/CairoGraphics2D.java b/gnu/java/awt/peer/gtk/CairoGraphics2D.java index 7f55747c6..ce3041d73 100644 --- a/gnu/java/awt/peer/gtk/CairoGraphics2D.java +++ b/gnu/java/awt/peer/gtk/CairoGraphics2D.java @@ -985,10 +985,6 @@ public abstract class CairoGraphics2D extends Graphics2D if (sm != null) sm.checkPermission(new AWTPermission("readDisplayPixels")); - // FIXME: implement general Composite support - //throw new java.lang.UnsupportedOperationException(); - // this is in progress! yay! - //compCtx = comp.createContext(getNativeCM(), getNativeCM(), hints); compCtx = comp.createContext(getBufferCM(), getNativeCM(), hints); } } @@ -1000,18 +996,17 @@ public abstract class CairoGraphics2D extends Graphics2D * * @return ColorModel the ColorModel of native data in this peer */ - /* protected abstract ColorModel getNativeCM(); */ - protected ColorModel getNativeCM() - { - // This stub should be removed and the method made abstract once I'm done - // implementing custom composites across all the peers... but we need it - // for now, so that the build doesn't break. - return null; - } + protected abstract ColorModel getNativeCM(); - // This may be overridden by some subclasses + /** + * Returns the Color Model describing the buffer that this peer uses + * for custom composites. + * + * @return ColorModel the ColorModel of the composite buffer in this peer. + */ protected ColorModel getBufferCM() { + // This may be overridden by some subclasses return getNativeCM(); } diff --git a/gnu/java/awt/peer/gtk/ComponentGraphics.java b/gnu/java/awt/peer/gtk/ComponentGraphics.java index d9d173118..c8ec2c95e 100644 --- a/gnu/java/awt/peer/gtk/ComponentGraphics.java +++ b/gnu/java/awt/peer/gtk/ComponentGraphics.java @@ -38,22 +38,31 @@ exception statement from your version. */ package gnu.java.awt.peer.gtk; +import gnu.classpath.Pointer; + +import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.Image; +import java.awt.Point; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Toolkit; import java.awt.font.GlyphVector; import java.awt.geom.AffineTransform; +import java.awt.geom.Line2D; +import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; import java.awt.image.ImageObserver; import java.awt.image.ImageProducer; +import java.awt.image.Raster; import java.awt.image.RenderedImage; -import gnu.classpath.Pointer; +import java.awt.image.WritableRaster; +import java.util.Hashtable; /** * ComponentGraphics - context for drawing directly to a component, @@ -67,6 +76,7 @@ public class ComponentGraphics extends CairoGraphics2D private GtkComponentPeer component; protected long cairo_t; + private BufferedImage buffer, componentBuffer; private static ThreadLocal hasLock = new ThreadLocal(); private static Integer ONE = Integer.valueOf(1); @@ -227,7 +237,20 @@ public class ComponentGraphics extends CairoGraphics2D lock(); try { - super.draw(s); + if (comp == null || comp instanceof AlphaComposite) + super.draw(s); + + else + { + createBuffer(); + + Graphics2D g2d = (Graphics2D)buffer.getGraphics(); + g2d.setStroke(this.getStroke()); + g2d.setColor(this.getColor()); + g2d.draw(s); + + drawComposite(s.getBounds2D(), null); + } } finally { @@ -240,7 +263,20 @@ public class ComponentGraphics extends CairoGraphics2D lock(); try { - super.fill(s); + if (comp == null || comp instanceof AlphaComposite) + super.fill(s); + + else + { + createBuffer(); + + Graphics2D g2d = (Graphics2D)buffer.getGraphics(); + g2d.setPaint(this.getPaint()); + g2d.setColor(this.getColor()); + g2d.fill(s); + + drawComposite(s.getBounds2D(), null); + } } finally { @@ -253,7 +289,19 @@ public class ComponentGraphics extends CairoGraphics2D lock(); try { - super.drawRenderedImage(image, xform); + if (comp == null || comp instanceof AlphaComposite) + super.drawRenderedImage(image, xform); + + else + { + createBuffer(); + + Graphics2D g2d = (Graphics2D)buffer.getGraphics(); + g2d.setRenderingHints(this.getRenderingHints()); + g2d.drawRenderedImage(image, xform); + + drawComposite(buffer.getRaster().getBounds(), null); + } } finally { @@ -268,7 +316,44 @@ public class ComponentGraphics extends CairoGraphics2D lock(); try { - rv = super.drawImage(img, xform, bgcolor, obs); + if (comp == null || comp instanceof AlphaComposite) + rv = super.drawImage(img, xform, bgcolor, obs); + + else + { + // Get buffered image of source + if( !(img instanceof BufferedImage) ) + { + ImageProducer source = img.getSource(); + if (source == null) + return false; + img = Toolkit.getDefaultToolkit().createImage(source); + } + BufferedImage bImg = (BufferedImage) img; + + // Find translated bounds + Point2D origin = new Point2D.Double(bImg.getMinX(), bImg.getMinY()); + Point2D pt = new Point2D.Double(bImg.getWidth() + bImg.getMinX(), + bImg.getHeight() + bImg.getMinY()); + if (xform != null) + { + origin = xform.transform(origin, origin); + pt = xform.transform(pt, pt); + } + + // Create buffer and draw image + createBuffer(); + + Graphics2D g2d = (Graphics2D)buffer.getGraphics(); + g2d.setRenderingHints(this.getRenderingHints()); + g2d.drawImage(img, xform, obs); + + // Perform compositing + rv = drawComposite(new Rectangle2D.Double(origin.getX(), + origin.getY(), + pt.getX(), pt.getY()), + obs); + } } finally { @@ -282,7 +367,23 @@ public class ComponentGraphics extends CairoGraphics2D lock(); try { - super.drawGlyphVector(gv, x, y); + if (comp == null || comp instanceof AlphaComposite) + super.drawGlyphVector(gv, x, y); + + else + { + createBuffer(); + + Graphics2D g2d = (Graphics2D)buffer.getGraphics(); + g2d.setPaint(this.getPaint()); + g2d.setStroke(this.getStroke()); + g2d.drawGlyphVector(gv, x, y); + + Rectangle2D bounds = gv.getLogicalBounds(); + bounds = new Rectangle2D.Double(x + bounds.getX(), y + bounds.getY(), + bounds.getWidth(), bounds.getHeight()); + drawComposite(bounds, null); + } } finally { @@ -384,7 +485,11 @@ public class ComponentGraphics extends CairoGraphics2D lock(); try { - super.drawLine(x1, y1, x2, y2); + if (comp == null || comp instanceof AlphaComposite) + super.drawLine(x1, y1, x2, y2); + + else + draw(new Line2D.Double(x1, y1, x2, y2)); } finally { @@ -397,7 +502,11 @@ public class ComponentGraphics extends CairoGraphics2D lock(); try { - super.drawRect(x, y, width, height); + if (comp == null || comp instanceof AlphaComposite) + super.drawRect(x, y, width, height); + + else + draw(new Rectangle2D.Double(x, y, width, height)); } finally { @@ -410,7 +519,11 @@ public class ComponentGraphics extends CairoGraphics2D lock(); try { - super.fillRect(x, y, width, height); + if (comp == null || comp instanceof AlphaComposite) + super.fillRect(x, y, width, height); + + else + fill(new Rectangle2D.Double(x, y, width, height)); } finally { @@ -431,5 +544,99 @@ public class ComponentGraphics extends CairoGraphics2D } } + + private boolean drawComposite(Rectangle2D bounds, ImageObserver observer) + { + // Clip source to visible areas that need updating + Rectangle2D clip = this.getClipBounds(); + Rectangle2D.intersect(bounds, clip, bounds); + clip = new Rectangle(buffer.getMinX(), buffer.getMinY(), + buffer.getWidth(), buffer.getHeight()); + Rectangle2D.intersect(bounds, clip, bounds); + + BufferedImage buffer2 = buffer; + if (!bounds.equals(buffer2.getRaster().getBounds())) + buffer2 = buffer2.getSubimage((int)bounds.getX(), (int)bounds.getY(), + (int)bounds.getWidth(), + (int)bounds.getHeight()); + + // Get destination clip to bounds + double[] points = new double[] {bounds.getX(), bounds.getY(), + bounds.getMaxX(), bounds.getMaxY()}; + transform.transform(points, 0, points, 0, 2); + + Rectangle2D deviceBounds = new Rectangle2D.Double(points[0], points[1], + points[2] - points[0], + points[3] - points[1]); + + Rectangle2D.intersect(deviceBounds, this.getClipInDevSpace(), deviceBounds); + + // Get current image on the component + unlock(); + GtkImage img = grab(component); + Graphics gr = componentBuffer.createGraphics(); + gr.drawImage(img, 0, 0, null); + gr.dispose(); + lock(); + + BufferedImage cBuffer = componentBuffer; + if (!deviceBounds.equals(cBuffer.getRaster().getBounds())) + cBuffer = cBuffer.getSubimage((int)deviceBounds.getX(), + (int)deviceBounds.getY(), + (int)deviceBounds.getWidth(), + (int)deviceBounds.getHeight()); + + // Perform actual composite operation + compCtx.compose(buffer2.getRaster(), cBuffer.getRaster(), + cBuffer.getRaster()); + + // This MUST call directly into the "action" method in CairoGraphics2D, + // not one of the wrappers, to ensure that the composite isn't processed + // more than once! + boolean rv = super.drawImage(cBuffer, + AffineTransform.getTranslateInstance(bounds.getX(), + bounds.getY()), + null, null); + return rv; + } + + private void createBuffer() + { + if (buffer == null) + { + WritableRaster rst; + rst = Raster.createWritableRaster(GtkVolatileImage.createGdkSampleModel(component.awtComponent.getWidth(), + component.awtComponent.getHeight()), + new Point(0,0)); + + buffer = new BufferedImage(GtkVolatileImage.gdkColorModel, rst, + GtkVolatileImage.gdkColorModel.isAlphaPremultiplied(), + new Hashtable()); + } + else + { + Graphics2D g2d = ((Graphics2D)buffer.getGraphics()); + + g2d.setBackground(new Color(0,0,0,0)); + g2d.clearRect(0, 0, buffer.getWidth(), buffer.getHeight()); + } + + if (componentBuffer == null) + { + WritableRaster rst; + rst = Raster.createWritableRaster(GtkVolatileImage.createGdkSampleModel(component.awtComponent.getWidth(), + component.awtComponent.getHeight()), + new Point(0,0)); + + componentBuffer = new BufferedImage(GtkVolatileImage.gdkColorModel, rst, + GtkVolatileImage.gdkColorModel.isAlphaPremultiplied(), + new Hashtable()); + } + } + + protected ColorModel getNativeCM() + { + return GtkVolatileImage.gdkColorModel; + } } diff --git a/gnu/java/awt/peer/gtk/GtkImageConsumer.java b/gnu/java/awt/peer/gtk/GtkImageConsumer.java index f1a74b8cc..53e97bb1a 100644 --- a/gnu/java/awt/peer/gtk/GtkImageConsumer.java +++ b/gnu/java/awt/peer/gtk/GtkImageConsumer.java @@ -42,6 +42,7 @@ import java.awt.image.ColorModel; import java.awt.image.ImageConsumer; import java.awt.image.ImageProducer; import java.awt.image.MemoryImageSource; +import java.nio.ByteOrder; import java.util.Hashtable; /** @@ -103,7 +104,7 @@ public class GtkImageConsumer implements ImageConsumer scansize); } - public synchronized void setPixels (int x, int y, int width, int height, + public synchronized void setPixels (int x, int y, int width, int height, ColorModel cm, int[] pixels, int offset, int scansize) { @@ -117,18 +118,34 @@ public class GtkImageConsumer implements ImageConsumer width); else { - for (int i = 0; i < height; i++) - for (int j = 0; j < width; j++) - { - // get in AARRGGBB and convert to AABBGGRR - int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]); - byte b = (byte)(pix & 0xFF); - byte r = (byte)(((pix & 0x00FF0000) >> 16) & 0xFF); - pix &= 0xFF00FF00; - pix |= ((b & 0xFF) << 16); - pix |= (r & 0xFF); - pixelCache[(y + i) * this.width + x + j] = pix; - } + if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) + { + for (int i = 0; i < height; i++) + for (int j = 0; j < width; j++) + { + // get in RRGGBBAA and convert to AARRGGBB + int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]); + int a = ((pix & 0xFF000000) >> 24) & 0xFF; + int rgb = (pix & 0x00FFFFFF) << 8; + pix = rgb | a; + pixelCache[(y + i) * this.width + x + j] = pix; + } + } + else + { + for (int i = 0; i < height; i++) + for (int j = 0; j < width; j++) + { + // get in AARRGGBB and convert to AABBGGRR + int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]); + byte b = (byte)(pix & 0xFF); + byte r = (byte)(((pix & 0x00FF0000) >> 16) & 0xFF); + pix &= 0xFF00FF00; + pix |= ((b & 0xFF) << 16); + pix |= (r & 0xFF); + pixelCache[(y + i) * this.width + x + j] = pix; + } + } } } diff --git a/gnu/java/awt/peer/gtk/VolatileImageGraphics.java b/gnu/java/awt/peer/gtk/VolatileImageGraphics.java index 3a9f9d693..62dbb45d8 100644 --- a/gnu/java/awt/peer/gtk/VolatileImageGraphics.java +++ b/gnu/java/awt/peer/gtk/VolatileImageGraphics.java @@ -40,6 +40,7 @@ package gnu.java.awt.peer.gtk; import java.awt.AlphaComposite; import java.awt.Color; +import java.awt.Composite; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; @@ -269,10 +270,13 @@ public class VolatileImageGraphics extends ComponentGraphics // This MUST call directly into the "action" method in CairoGraphics2D, // not one of the wrappers, to ensure that the composite isn't processed // more than once! + Composite oldComp = comp; // so that ComponentGraphics doesn't + comp = null; // process the composite again boolean rv = super.drawImage(buffer2, AffineTransform.getTranslateInstance(bounds.getX(), bounds.getY()), null, null); + comp = oldComp; return rv; } diff --git a/gnu/java/awt/peer/headless/HeadlessGraphicsEnvironment.java b/gnu/java/awt/peer/headless/HeadlessGraphicsEnvironment.java new file mode 100644 index 000000000..77ec4bf00 --- /dev/null +++ b/gnu/java/awt/peer/headless/HeadlessGraphicsEnvironment.java @@ -0,0 +1,88 @@ +/* HeadlessGraphicsEnvironment.java -- A graphics environment for headless mode + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.awt.peer.headless; + +import gnu.java.awt.java2d.RasterGraphics; + +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.HeadlessException; +import java.awt.image.BufferedImage; +import java.util.Locale; + +public class HeadlessGraphicsEnvironment + extends GraphicsEnvironment +{ + + public Graphics2D createGraphics(BufferedImage image) + { + return new RasterGraphics(image.getRaster(), image.getColorModel()); + } + + public Font[] getAllFonts() + { + // FIXME: Implement. + return null; + } + + public String[] getAvailableFontFamilyNames() + { + // FIXME: Implement. + return null; + } + + public String[] getAvailableFontFamilyNames(Locale l) + { + // FIXME: Implement. + return null; + } + + public GraphicsDevice getDefaultScreenDevice() + { + throw new HeadlessException(); + } + + public GraphicsDevice[] getScreenDevices() + { + throw new HeadlessException(); + } + +} diff --git a/gnu/java/awt/peer/headless/HeadlessToolkit.java b/gnu/java/awt/peer/headless/HeadlessToolkit.java new file mode 100644 index 000000000..96798c9e9 --- /dev/null +++ b/gnu/java/awt/peer/headless/HeadlessToolkit.java @@ -0,0 +1,371 @@ +/* HeadlessToolkit.java -- A toolkit for headless mode + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.java.awt.peer.headless; + +import gnu.java.awt.ClasspathToolkit; +import gnu.java.awt.EmbeddedWindow; +import gnu.java.awt.peer.ClasspathFontPeer; +import gnu.java.awt.peer.EmbeddedWindowPeer; + +import java.awt.AWTException; +import java.awt.Button; +import java.awt.Canvas; +import java.awt.Checkbox; +import java.awt.CheckboxMenuItem; +import java.awt.Choice; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.FileDialog; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Frame; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.HeadlessException; +import java.awt.Image; +import java.awt.Label; +import java.awt.List; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.Panel; +import java.awt.PopupMenu; +import java.awt.PrintJob; +import java.awt.ScrollPane; +import java.awt.Scrollbar; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.Window; +import java.awt.datatransfer.Clipboard; +import java.awt.dnd.DragGestureEvent; +import java.awt.dnd.peer.DragSourceContextPeer; +import java.awt.im.InputMethodHighlight; +import java.awt.image.ColorModel; +import java.awt.image.ImageObserver; +import java.awt.image.ImageProducer; +import java.awt.peer.ButtonPeer; +import java.awt.peer.CanvasPeer; +import java.awt.peer.CheckboxMenuItemPeer; +import java.awt.peer.CheckboxPeer; +import java.awt.peer.ChoicePeer; +import java.awt.peer.DialogPeer; +import java.awt.peer.FileDialogPeer; +import java.awt.peer.FontPeer; +import java.awt.peer.FramePeer; +import java.awt.peer.LabelPeer; +import java.awt.peer.ListPeer; +import java.awt.peer.MenuBarPeer; +import java.awt.peer.MenuItemPeer; +import java.awt.peer.MenuPeer; +import java.awt.peer.PanelPeer; +import java.awt.peer.PopupMenuPeer; +import java.awt.peer.RobotPeer; +import java.awt.peer.ScrollPanePeer; +import java.awt.peer.ScrollbarPeer; +import java.awt.peer.TextAreaPeer; +import java.awt.peer.TextFieldPeer; +import java.awt.peer.WindowPeer; +import java.io.InputStream; +import java.net.URL; +import java.util.Map; +import java.util.Properties; + +public class HeadlessToolkit + extends ClasspathToolkit +{ + + /** + * The graphics environment for headless graphics. + */ + private HeadlessGraphicsEnvironment graphicsEnv; + + public void beep() + { + // TODO Auto-generated method stub + + } + + public int checkImage(Image image, int width, int height, + ImageObserver observer) + { + // TODO Auto-generated method stub + return 0; + } + + protected ButtonPeer createButton(Button target) + { + throw new HeadlessException(); + } + + protected CanvasPeer createCanvas(Canvas target) + { + throw new HeadlessException(); + } + + protected CheckboxPeer createCheckbox(Checkbox target) + { + throw new HeadlessException(); + } + + protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) + { + throw new HeadlessException(); + } + + protected ChoicePeer createChoice(Choice target) + { + throw new HeadlessException(); + } + + protected DialogPeer createDialog(Dialog target) + { + throw new HeadlessException(); + } + + public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent e) + { + throw new HeadlessException(); + } + + protected FileDialogPeer createFileDialog(FileDialog target) + { + throw new HeadlessException(); + } + + protected FramePeer createFrame(Frame target) + { + throw new HeadlessException(); + } + + public Image createImage(String filename) + { + // FIXME: Implement. + return null; + } + + public Image createImage(URL url) + { + // FIXME: Implement. + return null; + } + + public Image createImage(ImageProducer producer) + { + // FIXME: Implement. + return null; + } + + public Image createImage(byte[] data, int offset, int len) + { + // TODO Auto-generated method stub + return null; + } + + protected LabelPeer createLabel(Label target) + { + throw new HeadlessException(); + } + + protected ListPeer createList(List target) + { + throw new HeadlessException(); + } + + protected MenuPeer createMenu(Menu target) + { + throw new HeadlessException(); + } + + protected MenuBarPeer createMenuBar(MenuBar target) + { + throw new HeadlessException(); + } + + protected MenuItemPeer createMenuItem(MenuItem target) + { + throw new HeadlessException(); + } + + protected PanelPeer createPanel(Panel target) + { + throw new HeadlessException(); + } + + protected PopupMenuPeer createPopupMenu(PopupMenu target) + { + throw new HeadlessException(); + } + + protected ScrollPanePeer createScrollPane(ScrollPane target) + { + throw new HeadlessException(); + } + + protected ScrollbarPeer createScrollbar(Scrollbar target) + { + throw new HeadlessException(); + } + + protected TextAreaPeer createTextArea(TextArea target) + { + throw new HeadlessException(); + } + + protected TextFieldPeer createTextField(TextField target) + { + throw new HeadlessException(); + } + + protected WindowPeer createWindow(Window target) + { + throw new HeadlessException(); + } + + public ColorModel getColorModel() + { + // TODO Auto-generated method stub + return null; + } + + public String[] getFontList() + { + // TODO Auto-generated method stub + return null; + } + + public FontMetrics getFontMetrics(Font name) + { + // TODO Auto-generated method stub + return null; + } + + protected FontPeer getFontPeer(String name, int style) + { + // TODO Auto-generated method stub + return null; + } + + public Image getImage(String name) + { + // TODO Auto-generated method stub + return null; + } + + public Image getImage(URL url) + { + // TODO Auto-generated method stub + return null; + } + + public PrintJob getPrintJob(Frame frame, String title, Properties props) + { + // TODO Auto-generated method stub + return null; + } + + public int getScreenResolution() + { + throw new HeadlessException(); + } + + public Dimension getScreenSize() + { + throw new HeadlessException(); + } + + public Clipboard getSystemClipboard() + { + throw new HeadlessException(); + } + + protected EventQueue getSystemEventQueueImpl() + { + throw new HeadlessException(); + } + + public Map mapInputMethodHighlight(InputMethodHighlight highlight) + { + // TODO Auto-generated method stub + return null; + } + + public boolean prepareImage(Image image, int width, int height, + ImageObserver observer) + { + // TODO Auto-generated method stub + return false; + } + + public void sync() + { + // TODO Auto-generated method stub + + } + + public EmbeddedWindowPeer createEmbeddedWindow(EmbeddedWindow w) + { + throw new HeadlessException(); + } + + public Font createFont(int format, InputStream stream) + { + // TODO Auto-generated method stub + return null; + } + + public RobotPeer createRobot(GraphicsDevice screen) throws AWTException + { + throw new HeadlessException(); + } + + public ClasspathFontPeer getClasspathFontPeer(String name, Map attrs) + { + // TODO Auto-generated method stub + return null; + } + + public GraphicsEnvironment getLocalGraphicsEnvironment() + { + if (graphicsEnv == null) + graphicsEnv = new HeadlessGraphicsEnvironment(); + return graphicsEnv; + } + +} diff --git a/gnu/java/awt/peer/swing/SwingButtonPeer.java b/gnu/java/awt/peer/swing/SwingButtonPeer.java index 2357fcbfb..531d6f2db 100644 --- a/gnu/java/awt/peer/swing/SwingButtonPeer.java +++ b/gnu/java/awt/peer/swing/SwingButtonPeer.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.java.awt.peer.swing; import java.awt.Button; +import java.awt.Container; import java.awt.Graphics; import java.awt.Image; import java.awt.Point; @@ -69,6 +70,13 @@ public class SwingButtonPeer extends JButton implements SwingComponent { + Button button; + + SwingButton(Button button) + { + this.button = button; + } + /** * Overridden so that this method returns the correct value even without a * peer. @@ -90,8 +98,8 @@ public class SwingButtonPeer public boolean isShowing() { boolean retVal = false; - if (SwingButtonPeer.this.awtComponent != null) - retVal = SwingButtonPeer.this.awtComponent.isShowing(); + if (button != null) + retVal = button.isShowing(); return retVal; } @@ -168,6 +176,14 @@ public class SwingButtonPeer ev.setSource(this); processKeyEvent(ev); } + + public Container getParent() + { + Container par = null; + if (button != null) + par = button.getParent(); + return par; + } } /** @@ -205,7 +221,7 @@ public class SwingButtonPeer */ public SwingButtonPeer(Button theButton) { - SwingButton button = new SwingButton(); + SwingButton button = new SwingButton(theButton); button.setText(theButton.getLabel()); button.addActionListener(new SwingButtonListener()); init(theButton, button); diff --git a/gnu/java/awt/peer/swing/SwingComponent.java b/gnu/java/awt/peer/swing/SwingComponent.java index a51b758ad..04ca7294f 100644 --- a/gnu/java/awt/peer/swing/SwingComponent.java +++ b/gnu/java/awt/peer/swing/SwingComponent.java @@ -62,7 +62,7 @@ public interface SwingComponent /** * Handles a mouse event. This is usually forwarded to - * {@link java.awt.Component#processMouseMotionEvent(MouseEvent)} of the swing + * {@link Component#processMouseMotionEvent(MouseEvent)} of the swing * component. * * @param ev the mouse event @@ -71,7 +71,7 @@ public interface SwingComponent /** * Handles a mouse motion event. This is usually forwarded to - * {@link java.awt.Component#processMouseEvent(MouseEvent)} of the swing + * {@link Component#processMouseEvent(MouseEvent)} of the swing * component. * * @param ev the mouse motion event @@ -80,7 +80,7 @@ public interface SwingComponent /** * Handles a key event. This is usually forwarded to - * {@link java.awt.Component#processKeyEvent(KeyEvent)} of the swing + * {@link Component#processKeyEvent(KeyEvent)} of the swing * component. * * @param ev the key event diff --git a/gnu/java/awt/peer/swing/SwingComponentPeer.java b/gnu/java/awt/peer/swing/SwingComponentPeer.java index 96ccc00b8..7e1ad86a0 100644 --- a/gnu/java/awt/peer/swing/SwingComponentPeer.java +++ b/gnu/java/awt/peer/swing/SwingComponentPeer.java @@ -42,6 +42,7 @@ import java.awt.AWTException; import java.awt.BufferCapabilities; import java.awt.Color; import java.awt.Component; +import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; @@ -62,6 +63,13 @@ import java.awt.image.ImageProducer; import java.awt.image.VolatileImage; import java.awt.peer.ComponentPeer; import java.awt.peer.ContainerPeer; +import java.awt.peer.LightweightPeer; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import javax.swing.JComponent; +import javax.swing.RepaintManager; /** * The base class for Swing based component peers. This provides the basic @@ -75,7 +83,7 @@ import java.awt.peer.ContainerPeer; * This class also provides the necesary hooks into the Swing painting and * event handling system. In order to achieve this, it traps paint, mouse and * key events in {@link #handleEvent(AWTEvent)} and calls some special methods - * ({@link #peerPaint(Graphics)}, {@link #handleKeyEvent(KeyEvent)}, + * ({@link #peerPaint(Graphics,boolean)}, {@link #handleKeyEvent(KeyEvent)}, * {@link #handleMouseEvent(MouseEvent)} and * {@link #handleMouseMotionEvent(MouseEvent)}) that call the corresponding * Swing methods. @@ -97,14 +105,30 @@ public class SwingComponentPeer protected SwingComponent swingComponent; /** + * The font that is set for this peer. + */ + protected Font peerFont; + + /** + * The repaint requests that will be handled next. The events queued + * up here are in the exact same order as they appear in + * {@link #coalescePaintEvent(PaintEvent)}, that is in event queue order. + * This is used for coalescing paint events. + * + * @see #coalescePaintEvent(PaintEvent) + */ + protected List currentPaintEvents; + + /** * Creates a SwingComponentPeer instance. Subclasses are expected to call - * this constructor and thereafter call - * {@link #init(Component,SwingComponent)} - * in order to setup the AWT and Swing components properly. + * this constructor and thereafter call {@link #init(Component, + * SwingComponent)}in order to setup the AWT and Swing components properly. */ protected SwingComponentPeer() { - // Nothing to do here. + // Initialize paint event queue. + currentPaintEvents = new LinkedList(); + } /** @@ -118,6 +142,38 @@ public class SwingComponentPeer { awtComponent = awtComp; swingComponent = swingComp; + if (swingComponent != null) + { + JComponent c = swingComponent.getJComponent(); + if (c != null) + { + c.addNotify(); + RepaintManager.currentManager(c).setDoubleBufferingEnabled(false); + System.setProperty("gnu.awt.swing.doublebuffering", "true"); + } + } + + // Register this heavyweight component with the nearest heavyweight + // container, so we get peerPaint() triggered by that container. + if (! (this instanceof LightweightPeer)) + { + Component comp = awtComponent; + Container parent = comp.getParent(); + while (parent != null && + ! (parent.getPeer() instanceof SwingContainerPeer)) + { + comp = parent; + parent = comp.getParent(); + } + + // At this point we have the ancestor with a SwingContainerPeer + // (or null peer). + if (parent != null && parent.getPeer() instanceof SwingContainerPeer) + { + SwingContainerPeer p = (SwingContainerPeer) parent.getPeer(); + p.addHeavyweightDescendent(awtComponent); + } + } } /** @@ -185,6 +241,28 @@ public class SwingComponentPeer */ public void dispose() { + // Unregister this heavyweight component from the nearest heavyweight + // container. + if (! (this instanceof LightweightPeer)) + { + Component comp = awtComponent; + Container parent = comp.getParent(); + while (parent != null && + ! (parent.getPeer() instanceof SwingContainerPeer)) + { + comp = parent; + parent = comp.getParent(); + } + + // At this point we have the ancestor with a SwingContainerPeer + // (or null peer). + if (parent != null && parent.getPeer() instanceof SwingContainerPeer) + { + SwingContainerPeer p = (SwingContainerPeer) parent.getPeer(); + p.removeHeavyweightDescendent(awtComponent); + } + } + awtComponent = null; swingComponent = null; } @@ -244,8 +322,7 @@ public class SwingComponentPeer public Graphics getGraphics() { Component parent = awtComponent.getParent(); - ComponentPeer parentPeer = parent.getPeer(); - Graphics g = parentPeer.getGraphics(); + Graphics g = parent.getGraphics(); g.translate(awtComponent.getX(), awtComponent.getY()); g.setClip(0, 0, awtComponent.getWidth(), awtComponent.getHeight()); return g; @@ -331,23 +408,30 @@ public class SwingComponentPeer { case PaintEvent.UPDATE: case PaintEvent.PAINT: - // This only will work when the component is showing. - if (awtComponent.isShowing()) + // Need to synchronize to avoid threading problems on the + // paint event list. + // We must synchronize on the tree lock first to avoid deadlock, + // because Container.paint() will grab it anyway. + synchronized (awtComponent.getTreeLock()) { - Graphics g = getGraphics(); - Rectangle clip = ((PaintEvent)e).getUpdateRect(); - g.clipRect(clip.x, clip.y, clip.width, clip.height); - //if (this instanceof LightweightPeer) - // { - if (e.getID() == PaintEvent.UPDATE) - awtComponent.update(g); - else - awtComponent.paint(g); - // } - // We paint the 'heavyweights' at last, so that they appear on top of - // everything else. - peerPaint(g); - g.dispose(); + synchronized (currentPaintEvents) + { + if (currentPaintEvents.contains(e)) + { + Graphics g = awtComponent.getGraphics(); + try + { + Rectangle clip = ((PaintEvent) e).getUpdateRect(); + g.clipRect(clip.x, clip.y, clip.width, clip.height); + peerPaint(g, e.getID() == PaintEvent.UPDATE); + } + finally + { + g.dispose(); + } + currentPaintEvents.remove(e); + } + } } break; case MouseEvent.MOUSE_PRESSED: @@ -451,9 +535,15 @@ public class SwingComponentPeer return retVal; } + /** + * Paints the component. This is triggered by + * {@link Component#paintAll(Graphics)}. + * + * @param graphics the graphics to paint with + */ public void paint(Graphics graphics) { - // FIXME: I don't know what this method is supposed to do. + peerPaint(graphics, false); } /** @@ -634,6 +724,7 @@ public class SwingComponentPeer */ public void setFont(Font font) { + peerFont = font; if (swingComponent != null) swingComponent.getJComponent().setFont(font); } @@ -741,7 +832,36 @@ public class SwingComponentPeer */ public void coalescePaintEvent(PaintEvent e) { - // Nothing to do here yet. + synchronized (currentPaintEvents) + { + Rectangle newRect = e.getUpdateRect(); + boolean coalesced = false; + for (Iterator i = currentPaintEvents.iterator(); i.hasNext() && ! coalesced;) + { + PaintEvent e2 = (PaintEvent) i.next(); + if (e.getID() == e2.getID()) + { + Rectangle oldRect = e2.getUpdateRect(); + if (oldRect.contains(newRect)) + { + // Merge newRect into oldRect. We have to discard the old request + // so that the events are still in the correct order. + i.remove(); + newRect.setBounds(oldRect); + coalesced = true; + } + else if (newRect.contains(oldRect)) + { + // Merge oldRect into newRect. We have to discard the old request + // so that the events are still in the correct order. + i.remove(); + coalesced = true; + } + } + // TODO: Maybe do something more clever here. + } + currentPaintEvents.add(e); + } } /** @@ -947,9 +1067,33 @@ public class SwingComponentPeer * paint() on the Swing component. * * @param g the graphics context to use for painting + * @param update wether we need to call update or paint on the AWT component + */ + protected void peerPaint(Graphics g, boolean update) + { + peerPaintComponent(g); + + Graphics userGraphics = g.create(); + try{ + if (update) + awtComponent.update(userGraphics); + else + awtComponent.paint(userGraphics); + } finally { + userGraphics.dispose(); + } + + } + + /** + * Paints the actual 'heavyweight' swing component, if there is one + * associated to this peer. + * + * @param g the graphics to paint the component with */ - protected void peerPaint(Graphics g) + protected void peerPaintComponent(Graphics g) { + // Paint the actual Swing component if this peer has one. if (swingComponent != null) swingComponent.getJComponent().paint(g); } diff --git a/gnu/java/awt/peer/swing/SwingContainerPeer.java b/gnu/java/awt/peer/swing/SwingContainerPeer.java index f433e1b5c..c78b644a7 100644 --- a/gnu/java/awt/peer/swing/SwingContainerPeer.java +++ b/gnu/java/awt/peer/swing/SwingContainerPeer.java @@ -37,14 +37,20 @@ exception statement from your version. */ package gnu.java.awt.peer.swing; +import gnu.classpath.SystemProperties; + import java.awt.Component; import java.awt.Container; import java.awt.Graphics; +import java.awt.Image; import java.awt.Insets; -import java.awt.Shape; +import java.awt.Rectangle; +import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.peer.ComponentPeer; import java.awt.peer.ContainerPeer; +import java.util.Iterator; +import java.util.LinkedList; /** * A peer for Container to be used with the Swing based AWT peers. @@ -57,13 +63,53 @@ public class SwingContainerPeer { /** + * Stores all heavyweight descendents of the container. This is used + * in {@link #peerPaintChildren(Graphics)}. + */ + private LinkedList heavyweightDescendents; + + /** + * The backbuffer used for painting UPDATE events. + */ + private Image backbuffer; + + /** * Creates a new SwingContainerPeer. * * @param awtCont */ - public SwingContainerPeer(Component awtCont) + public SwingContainerPeer(Container awtCont) + { + heavyweightDescendents = new LinkedList(); + } + + /** + * Registers a heavyweight descendent. This is then painted by + * {@link #peerPaintChildren(Graphics)}. + * + * @param comp the descendent to register + * + * @see #peerPaintChildren(Graphics) + * @see #removeHeavyweightDescendent(Component) + */ + synchronized void addHeavyweightDescendent(Component comp) + { + heavyweightDescendents.add(comp); + focusOwner = null; + } + + /** + * Unregisters a heavyweight descendent. + * + * @param comp the descendent to unregister + * + * @see #peerPaintChildren(Graphics) + * @see #addHeavyweightDescendent(Component) + */ + synchronized void removeHeavyweightDescendent(Component comp) { - init(awtCont, null); + heavyweightDescendents.remove(comp); + focusOwner = null; } /** @@ -92,12 +138,7 @@ public class SwingContainerPeer */ public Insets getInsets() { - Insets retVal; - if (swingComponent != null) - retVal = swingComponent.getJComponent().getInsets(); - else - retVal = new Insets(0, 0, 0, 0); - return retVal; + return insets(); } /** @@ -171,38 +212,83 @@ public class SwingContainerPeer } /** - * Triggers painting of a component. This calls peerPaint on all the child - * components of this container. - * - * @param g the graphics context to paint to + * Performs the super behaviour (call peerPaintComponent() and + * awtComponent.paint()), and forwards the paint request to the heavyweight + * descendents of the container. */ - protected void peerPaint(Graphics g) + protected void peerPaint(Graphics g, boolean update) { - Container c = (Container) awtComponent; - Component[] children = c.getComponents(); - for (int i = children.length - 1; i >= 0; --i) + if (isDoubleBuffering()) { - Component child = children[i]; - ComponentPeer peer = child.getPeer(); - boolean translated = false; - boolean clipped = false; - Shape oldClip = g.getClip(); + int width = awtComponent.getWidth(); + int height = awtComponent.getHeight(); + if (backbuffer == null + || backbuffer.getWidth(awtComponent) < width + || backbuffer.getHeight(awtComponent) < height) + backbuffer = awtComponent.createImage(width, height); + Graphics g2 = backbuffer.getGraphics(); + Rectangle clip = g.getClipRect(); try - { - g.translate(child.getX(), child.getY()); - translated = true; - g.setClip(0, 0, child.getWidth(), child.getHeight()); - clipped = true; - if (peer instanceof SwingComponentPeer) - ((SwingComponentPeer) peer).peerPaint(g); - } + { + g2.setClip(clip); + super.peerPaint(g2, update); + peerPaintChildren(g2); + } finally - { - if (translated) - g.translate(- child.getX(), - child.getY()); - if (clipped) - g.setClip(oldClip); - } + { + g2.dispose(); + } + g.drawImage(backbuffer, 0, 0, awtComponent); + } + else + { + super.peerPaint(g, update); + peerPaintChildren(g); + } + } + + /** + * Determines if we should do double buffering or not. + * + * @return if we should do double buffering or not + */ + private boolean isDoubleBuffering() + { + Object prop = + SystemProperties.getProperty("gnu.awt.swing.doublebuffering", "false"); + return prop.equals("true"); + } + + /** + * Paints any heavyweight child components. + * + * @param g the graphics to use for painting + */ + protected synchronized void peerPaintChildren(Graphics g) + { + // TODO: Is this the right painting order? + for (Iterator i = heavyweightDescendents.iterator(); i.hasNext();) + { + Component child = (Component) i.next(); + ComponentPeer peer = child.getPeer(); + + if (peer instanceof SwingComponentPeer && child.isVisible()) + { + // TODO: The translation here doesn't work for deeper + // nested children. Fix this! + Graphics g2 = g.create(child.getX(), child.getY(), + child.getWidth(), child.getHeight()); + try + { + // update() is only called for the topmost component if + // necessary, all other components only get paint() called. + ((SwingComponentPeer) peer).peerPaint(g2, false); + } + finally + { + g2.dispose(); + } + } } } @@ -214,17 +300,13 @@ public class SwingContainerPeer protected void handleMouseEvent(MouseEvent ev) { Component comp = awtComponent.getComponentAt(ev.getPoint()); - if(comp == null) - comp = awtComponent; - if (comp != null) + if(comp == null) comp = awtComponent; + ComponentPeer peer = comp.getPeer(); + if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer) { - ComponentPeer peer = comp.getPeer(); - if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer) - { - ev.translatePoint(comp.getX(), comp.getY()); - ev.setSource(comp); - ((SwingComponentPeer) peer).handleMouseEvent(ev); - } + ev.translatePoint(comp.getX(), comp.getY()); + ev.setSource(comp); + ((SwingComponentPeer) peer).handleMouseEvent(ev); } } @@ -246,4 +328,39 @@ public class SwingContainerPeer } } } + + /** + * Handles key events on the component. This is usually forwarded to the + * SwingComponent's processKeyEvent() method. + * + * @param e the key event + */ + protected void handleKeyEvent(KeyEvent e) + { + Component owner = getFocusOwner(); + if(owner != null) + owner.dispatchEvent(e); + else + super.handleKeyEvent(e); + } + + private Component focusOwner = null; + + private Component getFocusOwner() + { + if(focusOwner == null) + { + for(Iterator iter=heavyweightDescendents.iterator(); iter.hasNext();) + { + Component child = (Component) iter.next(); + if(child.isFocusable()) + { + focusOwner = child; + break; + } + } + } + return focusOwner; + } + } diff --git a/gnu/java/awt/peer/swing/SwingFramePeer.java b/gnu/java/awt/peer/swing/SwingFramePeer.java index 0d5a02d78..56c7417cd 100644 --- a/gnu/java/awt/peer/swing/SwingFramePeer.java +++ b/gnu/java/awt/peer/swing/SwingFramePeer.java @@ -43,6 +43,7 @@ import java.awt.Insets; import java.awt.MenuBar; import java.awt.Point; import java.awt.event.MouseEvent; +import java.awt.peer.ComponentPeer; import java.awt.peer.FramePeer; /** @@ -53,9 +54,9 @@ import java.awt.peer.FramePeer; * As a minimum, a subclass must implement all the remaining abstract methods * as well as the following methods: * <ul> - * <li>{@link java.awt.peer.ComponentPeer#getLocationOnScreen()}</li> - * <li>{@link java.awt.peer.ComponentPeer#getGraphics()}</li> - * <li>{@link java.awt.peer.ComponentPeer#createImage(int, int)}</li> + * <li>{@link ComponentPeer#getLocationOnScreen()}</li> + * <li>{@link ComponentPeer#getGraphics()}</li> + * <li>{@link ComponentPeer#createImage(int, int)}</li> * </ul> * * @author Roman Kennke (kennke@aicas.com) @@ -97,9 +98,9 @@ public abstract class SwingFramePeer * * @param g the graphics context to use for painting */ - protected void peerPaint(Graphics g) + protected void peerPaintComponent(Graphics g) { - super.peerPaint(g); + super.peerPaintComponent(g); if (menuBar != null) menuBar.peerPaint(g); } diff --git a/gnu/java/awt/peer/swing/SwingLabelPeer.java b/gnu/java/awt/peer/swing/SwingLabelPeer.java index dd86fff2d..349c5a0ab 100644 --- a/gnu/java/awt/peer/swing/SwingLabelPeer.java +++ b/gnu/java/awt/peer/swing/SwingLabelPeer.java @@ -37,6 +37,8 @@ exception statement from your version. */ package gnu.java.awt.peer.swing; +import java.awt.Container; +import java.awt.Graphics; import java.awt.Image; import java.awt.Label; import java.awt.Point; @@ -67,7 +69,14 @@ public class SwingLabelPeer extends JLabel implements SwingComponent { - + Label label; + + + SwingLabel(Label label) + { + this.label = label; + } + /** * Returns this label. * @@ -131,8 +140,8 @@ public class SwingLabelPeer public boolean isShowing() { boolean retVal = false; - if (SwingLabelPeer.this.awtComponent != null) - retVal = SwingLabelPeer.this.awtComponent.isShowing(); + if (label != null) + retVal = label.isShowing(); return retVal; } @@ -149,7 +158,19 @@ public class SwingLabelPeer { return SwingLabelPeer.this.createImage(w, h); } - + + public Graphics getGraphics() + { + return SwingLabelPeer.this.getGraphics(); + } + + public Container getParent() + { + Container par = null; + if (label != null) + par = label.getParent(); + return par; + } } /** @@ -160,11 +181,11 @@ public class SwingLabelPeer public SwingLabelPeer(Label label) { super(); - SwingLabel swingLabel = new SwingLabel(); + SwingLabel swingLabel = new SwingLabel(label); swingLabel.setText(label.getText()); - swingLabel.setHorizontalAlignment(label.getAlignment()); swingLabel.setOpaque(true); init(label, swingLabel); + setAlignment(label.getAlignment()); } /** @@ -190,7 +211,20 @@ public class SwingLabelPeer */ public void setAlignment(int alignment) { - ((JLabel) swingComponent.getJComponent()).setHorizontalAlignment(alignment); + JLabel swingLabel = (JLabel) swingComponent.getJComponent(); + switch (alignment) + { + case Label.RIGHT: + swingLabel.setHorizontalAlignment(JLabel.RIGHT); + break; + case Label.CENTER: + swingLabel.setHorizontalAlignment(JLabel.CENTER); + break; + case Label.LEFT: + default: + swingLabel.setHorizontalAlignment(JLabel.LEFT); + break; + } } } diff --git a/gnu/java/awt/peer/swing/SwingListPeer.java b/gnu/java/awt/peer/swing/SwingListPeer.java new file mode 100644 index 000000000..aca207048 --- /dev/null +++ b/gnu/java/awt/peer/swing/SwingListPeer.java @@ -0,0 +1,352 @@ +/* SwingListPeer.java -- A Swing based peer for AWT lists + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.swing; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.List; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.peer.ListPeer; + +import javax.swing.DefaultListModel; +import javax.swing.JComponent; +import javax.swing.JList; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; + +public class SwingListPeer + extends SwingComponentPeer + implements ListPeer +{ + + /** + * A spezialized Swing scroller used to hold the list. + * + * @author Roman Kennke (kennke@aicas.com) + */ + private class SwingList + extends JScrollPane + implements SwingComponent + { + + SwingList(Component comp) + { + super(comp, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + } + + /** + * Returns this label. + * + * @return <code>this</code> + */ + public JComponent getJComponent() + { + return this; + } + + /** + * Handles mouse events by forwarding it to + * <code>processMouseEvent()</code>. + * + * @param ev the mouse event + */ + public void handleMouseEvent(MouseEvent ev) + { + ev.setSource(this); + dispatchEvent(ev); + } + + /** + * Force lightweight mouse dispatching. + */ + public boolean isLightweight() + { + return false; + } + + /** + * Handles mouse motion events by forwarding it to + * <code>processMouseMotionEvent()</code>. + * + * @param ev the mouse motion event + */ + public void handleMouseMotionEvent(MouseEvent ev) + { + processMouseMotionEvent(ev); + } + + /** + * Handles key events by forwarding it to <code>processKeyEvent()</code>. + * + * @param ev the mouse event + */ + public void handleKeyEvent(KeyEvent ev) + { + processKeyEvent(ev); + } + + /** + * Overridden so that this method returns the correct value even without a + * peer. + * + * @return the screen location of the button + */ + public Point getLocationOnScreen() + { + return SwingListPeer.this.getLocationOnScreen(); + } + + /** + * Overridden so that the isShowing method returns the correct value for the + * swing button, even if it has no peer on its own. + * + * @return <code>true</code> if the button is currently showing, + * <code>false</code> otherwise + */ + public boolean isShowing() + { + boolean retVal = false; + if (SwingListPeer.this.awtComponent != null) + retVal = SwingListPeer.this.awtComponent.isShowing(); + return retVal; + } + + /** + * Overridden, so that the Swing button can create an Image without its + * own peer. + * + * @param w the width of the image + * @param h the height of the image + * + * @return an image + */ + public Image createImage(int w, int h) + { + return SwingListPeer.this.createImage(w, h); + } + + public Graphics getGraphics() + { + return SwingListPeer.this.getGraphics(); + } + + public Container getParent() + { + Container par = null; + if (SwingListPeer.this.awtComponent != null) + par = SwingListPeer.this.awtComponent.getParent(); + return par; + } + } + + /** + * The actual Swing JList. + */ + private JList jList; + + private DefaultListModel listModel; + + public SwingListPeer(List list) + { + super(); + listModel = new DefaultListModel(); + jList = new JList(listModel); + SwingList swingList = new SwingList(jList); + init(list, swingList); + + // Pull over the items from the list. + String[] items = list.getItems(); + for (int i = 0 ; i < items.length; i++) + addItem(items[i], i); + } + + public void add(String item, int index) + { + if (listModel != null) + listModel.add(index, item); + } + + public void addItem(String item, int index) + { + if (listModel != null) + listModel.add(index, item); + } + + public void clear() + { + if (listModel != null) + listModel.clear(); + } + + public void delItems(int startIndex, int endIndex) + { + if (listModel != null) + listModel.removeRange(startIndex, endIndex); + } + + public void deselect(int index) + { + if (jList != null) + { + jList.getSelectionModel().removeSelectionInterval(index, index); + } + } + + public Dimension getMinimumSize(int s) + { + Dimension d = null; + if (jList != null) + { + d = jList.getComponent(s).getMinimumSize(); + } + return d; + } + + public Dimension getPreferredSize(int s) + { + Dimension d = null; + if (jList != null) + { + d = jList.getComponent(s).getPreferredSize(); + } + return d; + } + + public int[] getSelectedIndexes() + { + int[] sel = null; + if (jList != null) + { + sel = jList.getSelectedIndices(); + } + return sel; + } + + public void makeVisible(int index) + { + if (jList != null) + { + Component comp = jList.getComponent(index); + jList.scrollRectToVisible(comp.getBounds()); + } + } + + public Dimension minimumSize(int s) + { + Dimension d = null; + if (jList != null) + { + d = jList.getComponent(s).getMinimumSize(); + } + return d; + } + + public Dimension preferredSize(int s) + { + Dimension d = null; + if (jList != null) + { + d = jList.getComponent(s).getPreferredSize(); + } + return d; + } + + public void removeAll() + { + if (jList != null) + { + jList.removeAll(); + } + } + + public void select(int index) + { + if (jList != null) + { + jList.setSelectedIndex(index); + } + } + + public void setMultipleMode(boolean multi) + { + if (jList != null) + { + jList.setSelectionMode(multi + ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION + : ListSelectionModel.SINGLE_SELECTION); + } + } + + public void setMultipleSelections(boolean multi) + { + if (jList != null) + { + jList.setSelectionMode(multi + ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION + : ListSelectionModel.SINGLE_SELECTION); + } + } + + public void reshape(int x, int y, int width, int height) + { + if (swingComponent != null) + { + swingComponent.getJComponent().setBounds(x, y, width, height); + swingComponent.getJComponent().validate(); + } + } + + protected void peerPaint(Graphics g, boolean update) + { + super.peerPaint(g, update); + jList.doLayout(); + jList.list(); + + Rectangle r = getBounds(); + g.setColor(Color.RED); + g.drawRect(r.x, r.y, r.width, r.height); + } +} diff --git a/gnu/java/awt/peer/swing/SwingMenuBarPeer.java b/gnu/java/awt/peer/swing/SwingMenuBarPeer.java index 0033efb02..bd9dcd77a 100644 --- a/gnu/java/awt/peer/swing/SwingMenuBarPeer.java +++ b/gnu/java/awt/peer/swing/SwingMenuBarPeer.java @@ -174,7 +174,7 @@ public class SwingMenuBarPeer /** * Adds a help menu to the menu bar. * - * @param menu the menu to add + * @param m the menu to add */ public void addHelpMenu(Menu menu) { diff --git a/gnu/java/awt/peer/swing/SwingPanelPeer.java b/gnu/java/awt/peer/swing/SwingPanelPeer.java index 0a0f20fe8..3cea62ac4 100644 --- a/gnu/java/awt/peer/swing/SwingPanelPeer.java +++ b/gnu/java/awt/peer/swing/SwingPanelPeer.java @@ -39,7 +39,6 @@ exception statement from your version. */ package gnu.java.awt.peer.swing; import java.awt.Panel; -import java.awt.peer.LightweightPeer; import java.awt.peer.PanelPeer; /** @@ -51,7 +50,7 @@ import java.awt.peer.PanelPeer; // necessary, but might be good for more consistend Look. public class SwingPanelPeer extends SwingContainerPeer - implements PanelPeer, LightweightPeer + implements PanelPeer { /** @@ -63,5 +62,6 @@ public class SwingPanelPeer public SwingPanelPeer(Panel panel) { super(panel); + init(panel, null); } } diff --git a/gnu/java/awt/peer/swing/SwingTextAreaPeer.java b/gnu/java/awt/peer/swing/SwingTextAreaPeer.java new file mode 100644 index 000000000..04ac01141 --- /dev/null +++ b/gnu/java/awt/peer/swing/SwingTextAreaPeer.java @@ -0,0 +1,317 @@ +/* SwingTextAreaPeer.java -- A Swing based peer for AWT textareas + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.swing; + +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.TextArea; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.im.InputMethodRequests; +import java.awt.peer.TextAreaPeer; + +import javax.swing.JComponent; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.text.BadLocationException; + +public class SwingTextAreaPeer + extends SwingComponentPeer + implements TextAreaPeer +{ + + /** + * A spezialized Swing scroller used to hold the textarea. + * + * @author Roman Kennke (kennke@aicas.com) + */ + private class SwingTextArea + extends JScrollPane + implements SwingComponent + { + + SwingTextArea(Component comp) + { + super(comp, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + } + + /** + * Returns this label. + * + * @return <code>this</code> + */ + public JComponent getJComponent() + { + return this; + } + + /** + * Handles mouse events by forwarding it to + * <code>processMouseEvent()</code>. + * + * @param ev the mouse event + */ + public void handleMouseEvent(MouseEvent ev) + { + ev.setSource(this); + dispatchEvent(ev); + } + + /** + * Force lightweight mouse dispatching. + */ + public boolean isLightweight() + { + return false; + } + + /** + * Handles mouse motion events by forwarding it to + * <code>processMouseMotionEvent()</code>. + * + * @param ev the mouse motion event + */ + public void handleMouseMotionEvent(MouseEvent ev) + { + processMouseMotionEvent(ev); + } + + /** + * Handles key events by forwarding it to <code>processKeyEvent()</code>. + * + * @param ev the mouse event + */ + public void handleKeyEvent(KeyEvent ev) + { + processKeyEvent(ev); + } + + /** + * Overridden so that this method returns the correct value even without a + * peer. + * + * @return the screen location of the button + */ + public Point getLocationOnScreen() + { + return SwingTextAreaPeer.this.getLocationOnScreen(); + } + + /** + * Overridden so that the isShowing method returns the correct value for the + * swing button, even if it has no peer on its own. + * + * @return <code>true</code> if the button is currently showing, + * <code>false</code> otherwise + */ + public boolean isShowing() + { + boolean retVal = false; + if (SwingTextAreaPeer.this.awtComponent != null) + retVal = SwingTextAreaPeer.this.awtComponent.isShowing(); + return retVal; + } + + /** + * Overridden, so that the Swing button can create an Image without its + * own peer. + * + * @param w the width of the image + * @param h the height of the image + * + * @return an image + */ + public Image createImage(int w, int h) + { + return SwingTextAreaPeer.this.createImage(w, h); + } + + public Graphics getGraphics() + { + return SwingTextAreaPeer.this.getGraphics(); + } + + public Container getParent() + { + Container par = null; + if (SwingTextAreaPeer.this.awtComponent != null) + par = SwingTextAreaPeer.this.awtComponent.getParent(); + return par; + } + } + + /** + * The actual JTextArea. + */ + private JTextArea jTextArea; + + public SwingTextAreaPeer(TextArea textArea) + { + super(); + System.err.println("new SwingTextAreaPeer"); + jTextArea = new JTextArea(); + SwingTextArea swingArea = new SwingTextArea(jTextArea); + init(textArea, swingArea); + + // Pull over the text from the text area. + setText(textArea.getText()); + } + + public Dimension getMinimumSize(int rows, int cols) + { + // TODO Auto-generated method stub + return null; + } + + public Dimension getPreferredSize(int rows, int cols) + { + // TODO Auto-generated method stub + return null; + } + + public void insert(String text, int pos) + { + jTextArea.insert(text, pos); + } + + public void insertText(String text, int pos) + { + jTextArea.insert(text, pos); + } + + public Dimension minimumSize(int rows, int cols) + { + // TODO Auto-generated method stub + return null; + } + + public Dimension preferredSize(int rows, int cols) + { + // TODO Auto-generated method stub + return null; + } + + public void replaceRange(String text, int start, int end) + { + jTextArea.replaceRange(text, start, end); + } + + public void replaceText(String text, int start, int end) + { + jTextArea.replaceRange(text, start, end); + } + + public long filterEvents(long filter) + { + // TODO Auto-generated method stub + return 0; + } + + public int getCaretPosition() + { + return jTextArea.getCaretPosition(); + } + + public Rectangle getCharacterBounds(int pos) + { + Rectangle r; + try + { + return jTextArea.modelToView(pos); + } + catch (BadLocationException ex) + { + r = null; + } + return r; + } + + public int getIndexAtPoint(int x, int y) + { + return jTextArea.viewToModel(new Point(x, y)); + } + + public InputMethodRequests getInputMethodRequests() + { + // TODO Auto-generated method stub + return null; + } + + public int getSelectionEnd() + { + return jTextArea.getSelectionEnd(); + } + + public int getSelectionStart() + { + return jTextArea.getSelectionStart(); + } + + public String getText() + { + return jTextArea.getText(); + } + + public void select(int start, int end) + { + jTextArea.select(start, end); + } + + public void setCaretPosition(int pos) + { + jTextArea.setCaretPosition(pos); + } + + public void setEditable(boolean editable) + { + jTextArea.setEditable(editable); + } + + public void setText(String text) + { + System.err.println("setText: " + text); + jTextArea.setText(text); + } + +} diff --git a/gnu/java/awt/peer/swing/SwingTextFieldPeer.java b/gnu/java/awt/peer/swing/SwingTextFieldPeer.java index 0c3b4e726..d7d574a0b 100644 --- a/gnu/java/awt/peer/swing/SwingTextFieldPeer.java +++ b/gnu/java/awt/peer/swing/SwingTextFieldPeer.java @@ -36,7 +36,10 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package gnu.java.awt.peer.swing; +import java.awt.Component; +import java.awt.Container; import java.awt.Dimension; +import java.awt.Graphics; import java.awt.Image; import java.awt.Point; import java.awt.Rectangle; @@ -69,6 +72,13 @@ public class SwingTextFieldPeer implements SwingComponent { + TextField textField; + + SwingTextField(TextField textField) + { + this.textField = textField; + } + /** * Overridden to provide normal behaviour even without a real peer * attached. @@ -90,8 +100,8 @@ public class SwingTextFieldPeer public boolean isShowing() { boolean retVal = false; - if (SwingTextFieldPeer.this.awtComponent != null) - retVal = SwingTextFieldPeer.this.awtComponent.isShowing(); + if (textField != null) + retVal = textField.isShowing(); return retVal; } @@ -151,7 +161,19 @@ public class SwingTextFieldPeer ev.setSource(this); processKeyEvent(ev); } - + + public Container getParent() + { + Container par = null; + if (textField != null) + par = textField.getParent(); + return par; + } + + public Graphics getGraphics() + { + return SwingTextFieldPeer.this.getGraphics(); + } } /** @@ -162,7 +184,7 @@ public class SwingTextFieldPeer */ public SwingTextFieldPeer(TextField textField) { - SwingTextField swingTextField = new SwingTextField(); + SwingTextField swingTextField = new SwingTextField(textField); swingTextField.setText(textField.getText()); init(textField, swingTextField); } @@ -283,7 +305,7 @@ public class SwingTextFieldPeer * @param startPos the start index of the selection * @param endPos the start index of the selection */ - public void select(int startPos, int endPos) + public void select(int start_pos, int endPos) { // TODO: Must be implemented. } diff --git a/gnu/java/awt/peer/swing/SwingWindowPeer.java b/gnu/java/awt/peer/swing/SwingWindowPeer.java index 43a509b95..531552d90 100644 --- a/gnu/java/awt/peer/swing/SwingWindowPeer.java +++ b/gnu/java/awt/peer/swing/SwingWindowPeer.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.java.awt.peer.swing; import java.awt.Window; +import java.awt.peer.ComponentPeer; import java.awt.peer.WindowPeer; /** @@ -48,9 +49,9 @@ import java.awt.peer.WindowPeer; * As a minimum, a subclass must implement all the remaining abstract methods * as well as the following methods: * <ul> - * <li>{@link java.awt.peer.ComponentPeer#getLocationOnScreen()}</li> - * <li>{@link java.awt.peer.ComponentPeer#getGraphics()}</li> - * <li>{@link java.awt.peer.ComponentPeer#createImage(int, int)}</li> + * <li>{@link ComponentPeer#getLocationOnScreen()}</li> + * <li>{@link ComponentPeer#getGraphics()}</li> + * <li>{@link ComponentPeer#createImage(int, int)}</li> * </ul> * * @author Roman Kennke (kennke@aicas.com) @@ -68,5 +69,6 @@ public abstract class SwingWindowPeer public SwingWindowPeer(Window window) { super(window); + init(window, null); } } diff --git a/gnu/java/net/protocol/jar/Handler.java b/gnu/java/net/protocol/jar/Handler.java index 316d8cb02..7c09766a5 100644 --- a/gnu/java/net/protocol/jar/Handler.java +++ b/gnu/java/net/protocol/jar/Handler.java @@ -1,5 +1,5 @@ /* gnu.java.net.protocol.jar.Handler - jar protocol handler for java.net - Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2003, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,6 +45,9 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.StringTokenizer; /** * @author Kresten Krab Thorup (krab@gnu.org) @@ -114,7 +117,7 @@ public class Handler extends URLStreamHandler file = file.substring(0, idx + 1) + url_string; } - setURL (url, "jar", url.getHost(), url.getPort(), file, null); + setURL (url, "jar", url.getHost(), url.getPort(), flat(file), null); return; } @@ -149,6 +152,45 @@ public class Handler extends URLStreamHandler } /** + * Makes the given jar url string 'flat' by removing any . and .. from + * jar file path because ZipFile entries can only handle flat paths. + * Inside jar files '/' is always the path separator. + */ + private static String flat(String url_string) + { + int jar_stop = url_string.indexOf("!/"); + String jar_path = url_string.substring(jar_stop + 1, url_string.length()); + + if (jar_path.indexOf("/.") < 0) + return url_string; + + ArrayList tokens = new ArrayList(); + StringTokenizer st = new StringTokenizer(jar_path, "/"); + while (st.hasMoreTokens()) + { + String token = st.nextToken(); + if (token.equals(".")) + continue; + else if (token.equals("..")) + { + if (! tokens.isEmpty()) + tokens.remove(tokens.size() - 1); + } + else + tokens.add(token); + } + + StringBuffer path = new StringBuffer(url_string.length()); + path.append(url_string.substring(0, jar_stop + 1)); + + Iterator it = tokens.iterator(); + while (it.hasNext()) + path.append('/').append(it.next()); + + return path.toString(); + } + + /** * This method converts a Jar URL object into a String. * * @param url The URL object to convert |