home *** CD-ROM | disk | FTP | other *** search
- package sun.awt.windows;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.image.ColorModel;
- import java.awt.image.ImageObserver;
- import java.awt.image.ImageProducer;
- import java.awt.peer.ComponentPeer;
- import sun.awt.ScreenUpdater;
- import sun.awt.UpdateClient;
-
- public abstract class WComponentPeer implements ComponentPeer, UpdateClient {
- private int updateX1;
- private int updateY1;
- private int updateX2;
- private int updateY2;
- Component target;
- int pNativeWidget;
- int pWinMsg;
-
- WComponentPeer(Component target) {
- this.target = target;
- Container parent = target.getParent();
- this.create((WComponentPeer)(parent != null ? ((Component)parent).getPeer() : null));
- this.initialize();
- }
-
- protected void finalize() {
- if (this.pNativeWidget != 0) {
- this.dispose();
- }
-
- }
-
- abstract void create(WComponentPeer var1);
-
- public native void dispose();
-
- public native void show();
-
- public native void hide();
-
- public native void enable();
-
- public native void disable();
-
- public native void setForeground(Color var1);
-
- public native void setBackground(Color var1);
-
- public native void setFont(Font var1);
-
- public native void requestFocus();
-
- public native void nextFocus();
-
- public native void reshape(int var1, int var2, int var3, int var4);
-
- public native boolean handleEvent(Event var1);
-
- public Dimension minimumSize() {
- return this.target.size();
- }
-
- public Dimension preferredSize() {
- return this.minimumSize();
- }
-
- public ColorModel getColorModel() {
- return WToolkit.getStaticColorModel();
- }
-
- public Toolkit getToolkit() {
- return Toolkit.getDefaultToolkit();
- }
-
- public Graphics getGraphics() {
- Graphics g = new WGraphics(this);
- g.setColor(this.target.getForeground());
- g.setFont(this.target.getFont());
- return g;
- }
-
- public FontMetrics getFontMetrics(Font font) {
- return WFontMetrics.getFontMetrics(font);
- }
-
- public void repaint(long tm, int x, int y, int width, int height) {
- this.addRepaintArea(x, y, width, height);
- ScreenUpdater.updater.notify(this, tm);
- }
-
- public void paint(Graphics g) {
- g.setColor(this.target.getForeground());
- g.setFont(this.target.getFont());
- this.target.paint(g);
- }
-
- public void update(Graphics g) {
- g.setColor(this.target.getForeground());
- g.setFont(this.target.getFont());
- this.target.update(g);
- }
-
- public void print(Graphics g) {
- Dimension d = this.target.size();
- g.setColor(this.target.getForeground());
- g.setFont(this.target.getFont());
- g.drawRect(0, 0, d.width - 1, d.height - 1);
- this.target.print(g);
- }
-
- public Image createImage(ImageProducer producer) {
- return new WImage(producer);
- }
-
- public Image createImage(int width, int height) {
- return new WImage(width, height);
- }
-
- public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
- return WToolkit.prepareScrImage(img, w, h, o);
- }
-
- public int checkImage(Image img, int w, int h, ImageObserver o) {
- return WToolkit.checkScrImage(img, w, h, o);
- }
-
- public int updatePriority() {
- return 5;
- }
-
- public void updateClient(Object arg) {
- synchronized(this){}
-
- int x1;
- int y1;
- int x2;
- int y2;
- try {
- x1 = this.updateX1;
- y1 = this.updateY1;
- x2 = this.updateX2;
- y2 = this.updateY2;
- this.updateX1 = this.updateX2;
- } catch (Throwable var8) {
- throw var8;
- }
-
- if (x1 != x2) {
- this.widget_repaint(x1, y1, x2 - x1, y2 - y1);
- }
-
- }
-
- protected native void widget_repaint(int var1, int var2, int var3, int var4);
-
- void initialize() {
- if (this.target.isVisible()) {
- this.show();
- } else {
- this.hide();
- }
-
- Color c;
- if ((c = this.target.getForeground()) != null) {
- this.setForeground(c);
- }
-
- if ((c = this.target.getBackground()) != null) {
- this.setBackground(c);
- }
-
- Font f;
- if ((f = this.target.getFont()) != null) {
- this.setFont(f);
- }
-
- if (!this.target.isEnabled()) {
- this.disable();
- }
-
- Rectangle r = this.target.bounds();
- this.reshape(r.x, r.y, r.width, r.height);
- }
-
- private synchronized void addRepaintArea(int x, int y, int w, int h) {
- if (this.updateX1 == this.updateX2) {
- this.updateX1 = x;
- this.updateY1 = y;
- this.updateX2 = x + w;
- this.updateY2 = y + h;
- } else {
- if (x < this.updateX1) {
- this.updateX1 = x;
- }
-
- if (y < this.updateY1) {
- this.updateY1 = y;
- }
-
- if (x + w > this.updateX2) {
- this.updateX2 = x + w;
- }
-
- if (y + h > this.updateY2) {
- this.updateY2 = y + h;
- }
-
- }
- }
-
- public String toString() {
- return this.getClass().getName() + "[" + this.target + "]";
- }
-
- private native Event setData(int var1, Event var2);
-
- protected void handleQuit(long when) {
- Event e = new Event(this.target, 201, (Object)null);
- this.target.postEvent(e);
- }
-
- protected void handleMoved(long when, int data, int x, int y) {
- }
-
- protected void handleResize(long when, int u1, int width, int height, int u4, int u5) {
- }
-
- protected void handleGotFocus(long when, int data, int u2, int u3, int u4, int u5) {
- Event e = this.setData(data, new Event(this.target, 1004, (Object)null));
- this.target.postEvent(e);
- }
-
- protected void handleLostFocus(long when, int data, int u2, int u3, int u4, int u5) {
- Event e = this.setData(data, new Event(this.target, 1005, (Object)null));
- this.target.postEvent(e);
- }
-
- protected void handleActionKey(long when, int data, int x, int y, int key, int flags) {
- Event e = this.setData(data, new Event(this.target, when, 403, x, y, key, flags));
- this.target.postEvent(e);
- }
-
- protected void handleActionKeyRelease(long when, int data, int x, int y, int key, int flags) {
- Event e = this.setData(data, new Event(this.target, when, 404, x, y, key, flags));
- this.target.postEvent(e);
- }
-
- protected void handleKeyPress(long when, int data, int x, int y, int key, int flags) {
- Event e = this.setData(data, new Event(this.target, when, 401, x, y, key, flags));
- this.target.postEvent(e);
- }
-
- protected void handleKeyRelease(long when, int data, int x, int y, int key, int flags) {
- Event e = this.setData(data, new Event(this.target, when, 402, x, y, key, flags));
- this.target.postEvent(e);
- }
-
- protected void handleMouseEnter(long when, int data, int x, int y) {
- Event e = new Event(this.target, when, 504, x, y, 0, 0, (Object)null);
- this.target.postEvent(e);
- }
-
- protected void handleMouseExit(long when, int data, int x, int y) {
- Event e = new Event(this.target, when, 505, x, y, 0, 0, (Object)null);
- this.target.postEvent(e);
- }
-
- protected void handleMouseDown(long when, int data, int x, int y, int clickCount, int flags) {
- Event e = this.setData(data, new Event(this.target, when, 501, x, y, 0, flags, (Object)null));
- e.clickCount = clickCount;
- this.target.postEvent(e);
- }
-
- protected void handleMouseUp(long when, int data, int x, int y, int u4, int flags) {
- Event e = this.setData(data, new Event(this.target, when, 502, x, y, 0, flags, (Object)null));
- this.target.postEvent(e);
- }
-
- protected void handleMouseMoved(long when, int data, int x, int y, int flags) {
- Event e = this.setData(data, new Event(this.target, when, 503, x, y, 0, flags, (Object)null));
- this.target.postEvent(e);
- }
-
- protected void handleMouseDrag(long when, int data, int x, int y, int flags) {
- Event e = this.setData(data, new Event(this.target, when, 506, x, y, 0, flags, (Object)null));
- this.target.postEvent(e);
- }
-
- protected void handleExpose(long when, int data, int x, int y, int w, int h) {
- Graphics g = this.getGraphics();
-
- try {
- g.clipRect(x, y, w, h);
- this.paint(g);
- } finally {
- g.dispose();
- }
-
- }
-
- protected void handleRepaint(long when, int data, int x, int y, int w, int h) {
- Graphics g = this.getGraphics();
-
- try {
- g.clipRect(x, y, w, h);
- this.update(g);
- } finally {
- g.dispose();
- }
-
- }
- }
-