source: trunk/src/gcc/libjava/gnu/awt/xlib/XGraphics.java@ 2

Last change on this file since 2 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.8 KB
Line 
1/* Copyright (C) 2000 Free Software Foundation
2
3 This file is part of libgcj.
4
5This software is copyrighted work licensed under the terms of the
6Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7details. */
8
9package gnu.awt.xlib;
10
11import java.awt.*;
12import java.awt.image.WritableRaster;
13import java.awt.image.Raster;
14import java.awt.image.DataBuffer;
15import java.awt.image.ColorModel;
16import java.awt.image.ImageObserver;
17import java.awt.image.BufferedImage;
18import gnu.gcj.xlib.GC;
19import gnu.gcj.xlib.XImage;
20import gnu.gcj.xlib.Drawable;
21import gnu.gcj.xlib.Window;
22import gnu.gcj.xlib.Drawable;
23import gnu.gcj.xlib.Visual;
24import gnu.awt.j2d.DirectRasterGraphics;
25import gnu.awt.j2d.MappedRaster;
26
27public class XGraphics implements Cloneable, DirectRasterGraphics
28{
29 static class XRaster extends MappedRaster
30 {
31 XImage ximage;
32
33 public XRaster(WritableRaster raster, XImage ximage, ColorModel cm)
34 {
35 super(raster, cm);
36 this.ximage = ximage;
37 }
38 }
39
40 GC context;
41 XGraphicsConfiguration config;
42 Rectangle clipBounds;
43
44 XFontMetrics metrics;
45
46
47 public Object clone()
48 {
49 XGraphics gfxCopy = (XGraphics) super.clone();
50 gfxCopy.context = context.create();
51
52 return gfxCopy;
53 }
54
55 public void dispose()
56 {
57 GC lContext = context;
58 context = null;
59 config = null;
60 clipBounds = null;
61
62 if (lContext != null)
63 {
64 lContext.dispose();
65 }
66 }
67
68 public XGraphics(Drawable drawable, XGraphicsConfiguration config)
69 {
70 context = new GC(drawable);
71 this.config = config;
72 }
73
74 public void setColor(Color color)
75 {
76 context.setForeground(config.getPixel(color));
77 }
78
79 public void setPaintMode()
80 {
81 throw new UnsupportedOperationException("not implemented");
82 }
83
84 public void setXORMode(Color c1)
85 {
86 throw new UnsupportedOperationException("not implemented");
87 }
88
89 public void setFont(Font font)
90 {
91 if ((metrics != null) && font.equals(metrics.getFont())) return;
92
93 metrics = config.getXFontMetrics(font);
94 context.setFont(metrics.xfont);
95 }
96
97 public FontMetrics getFontMetrics(Font font)
98 {
99 if ((metrics != null) && font.equals(metrics.getFont()))
100 return metrics;
101
102 return config.getXFontMetrics(font);
103 }
104
105 public void setClip(int x, int y, int width, int height)
106 {
107 Rectangle[] rects = { new Rectangle(x, y, width, height) };
108 context.setClipRectangles(rects);
109 }
110
111 public void setClip(Shape clip)
112 {
113 /* TODO: create a special RectangleUnion shape that can be
114 used to draw advantage of the GCs ability to set multiple
115 rectangles.
116 */
117
118 /* FIXME: creating all these objects is wasteful and can be
119 costly in the long run, since this code is run at every
120 expose. */
121 Rectangle newClipBounds = clip.getBounds();
122
123 if ((clipBounds != null) && !clipBounds.contains(newClipBounds))
124 {
125 System.err.println("warning: old clip ("+ clipBounds +") does " +
126 "not fully contain new clip (" +
127 newClipBounds + ")");
128 }
129 clipBounds = newClipBounds;
130 Rectangle[] rects = { clipBounds };
131 context.setClipRectangles(rects);
132 }