home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / sun / awt / windows / WComponentPeer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  9.2 KB  |  324 lines

  1. package sun.awt.windows;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Dimension;
  7. import java.awt.Event;
  8. import java.awt.Font;
  9. import java.awt.FontMetrics;
  10. import java.awt.Graphics;
  11. import java.awt.Image;
  12. import java.awt.Rectangle;
  13. import java.awt.Toolkit;
  14. import java.awt.image.ColorModel;
  15. import java.awt.image.ImageObserver;
  16. import java.awt.image.ImageProducer;
  17. import java.awt.peer.ComponentPeer;
  18. import sun.awt.ScreenUpdater;
  19. import sun.awt.UpdateClient;
  20.  
  21. public abstract class WComponentPeer implements ComponentPeer, UpdateClient {
  22.    private int updateX1;
  23.    private int updateY1;
  24.    private int updateX2;
  25.    private int updateY2;
  26.    Component target;
  27.    int pNativeWidget;
  28.    int pWinMsg;
  29.  
  30.    WComponentPeer(Component target) {
  31.       this.target = target;
  32.       Container parent = target.getParent();
  33.       this.create((WComponentPeer)(parent != null ? ((Component)parent).getPeer() : null));
  34.       this.initialize();
  35.    }
  36.  
  37.    protected void finalize() {
  38.       if (this.pNativeWidget != 0) {
  39.          this.dispose();
  40.       }
  41.  
  42.    }
  43.  
  44.    abstract void create(WComponentPeer var1);
  45.  
  46.    public native void dispose();
  47.  
  48.    public native void show();
  49.  
  50.    public native void hide();
  51.  
  52.    public native void enable();
  53.  
  54.    public native void disable();
  55.  
  56.    public native void setForeground(Color var1);
  57.  
  58.    public native void setBackground(Color var1);
  59.  
  60.    public native void setFont(Font var1);
  61.  
  62.    public native void requestFocus();
  63.  
  64.    public native void nextFocus();
  65.  
  66.    public native void reshape(int var1, int var2, int var3, int var4);
  67.  
  68.    public native boolean handleEvent(Event var1);
  69.  
  70.    public Dimension minimumSize() {
  71.       return this.target.size();
  72.    }
  73.  
  74.    public Dimension preferredSize() {
  75.       return this.minimumSize();
  76.    }
  77.  
  78.    public ColorModel getColorModel() {
  79.       return WToolkit.getStaticColorModel();
  80.    }
  81.  
  82.    public Toolkit getToolkit() {
  83.       return Toolkit.getDefaultToolkit();
  84.    }
  85.  
  86.    public Graphics getGraphics() {
  87.       Graphics g = new WGraphics(this);
  88.       g.setColor(this.target.getForeground());
  89.       g.setFont(this.target.getFont());
  90.       return g;
  91.    }
  92.  
  93.    public FontMetrics getFontMetrics(Font font) {
  94.       return WFontMetrics.getFontMetrics(font);
  95.    }
  96.  
  97.    public void repaint(long tm, int x, int y, int width, int height) {
  98.       this.addRepaintArea(x, y, width, height);
  99.       ScreenUpdater.updater.notify(this, tm);
  100.    }
  101.  
  102.    public void paint(Graphics g) {
  103.       g.setColor(this.target.getForeground());
  104.       g.setFont(this.target.getFont());
  105.       this.target.paint(g);
  106.    }
  107.  
  108.    public void update(Graphics g) {
  109.       g.setColor(this.target.getForeground());
  110.       g.setFont(this.target.getFont());
  111.       this.target.update(g);
  112.    }
  113.  
  114.    public void print(Graphics g) {
  115.       Dimension d = this.target.size();
  116.       g.setColor(this.target.getForeground());
  117.       g.setFont(this.target.getFont());
  118.       g.drawRect(0, 0, d.width - 1, d.height - 1);
  119.       this.target.print(g);
  120.    }
  121.  
  122.    public Image createImage(ImageProducer producer) {
  123.       return new WImage(producer);
  124.    }
  125.  
  126.    public Image createImage(int width, int height) {
  127.       return new WImage(width, height);
  128.    }
  129.  
  130.    public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
  131.       return WToolkit.prepareScrImage(img, w, h, o);
  132.    }
  133.  
  134.    public int checkImage(Image img, int w, int h, ImageObserver o) {
  135.       return WToolkit.checkScrImage(img, w, h, o);
  136.    }
  137.  
  138.    public int updatePriority() {
  139.       return 5;
  140.    }
  141.  
  142.    public void updateClient(Object arg) {
  143.       synchronized(this){}
  144.  
  145.       int x1;
  146.       int y1;
  147.       int x2;
  148.       int y2;
  149.       try {
  150.          x1 = this.updateX1;
  151.          y1 = this.updateY1;
  152.          x2 = this.updateX2;
  153.          y2 = this.updateY2;
  154.          this.updateX1 = this.updateX2;
  155.       } catch (Throwable var8) {
  156.          throw var8;
  157.       }
  158.  
  159.       if (x1 != x2) {
  160.          this.widget_repaint(x1, y1, x2 - x1, y2 - y1);
  161.       }
  162.  
  163.    }
  164.  
  165.    protected native void widget_repaint(int var1, int var2, int var3, int var4);
  166.  
  167.    void initialize() {
  168.       if (this.target.isVisible()) {
  169.          this.show();
  170.       } else {
  171.          this.hide();
  172.       }
  173.  
  174.       Color c;
  175.       if ((c = this.target.getForeground()) != null) {
  176.          this.setForeground(c);
  177.       }
  178.  
  179.       if ((c = this.target.getBackground()) != null) {
  180.          this.setBackground(c);
  181.       }
  182.  
  183.       Font f;
  184.       if ((f = this.target.getFont()) != null) {
  185.          this.setFont(f);
  186.       }
  187.  
  188.       if (!this.target.isEnabled()) {
  189.          this.disable();
  190.       }
  191.  
  192.       Rectangle r = this.target.bounds();
  193.       this.reshape(r.x, r.y, r.width, r.height);
  194.    }
  195.  
  196.    private synchronized void addRepaintArea(int x, int y, int w, int h) {
  197.       if (this.updateX1 == this.updateX2) {
  198.          this.updateX1 = x;
  199.          this.updateY1 = y;
  200.          this.updateX2 = x + w;
  201.          this.updateY2 = y + h;
  202.       } else {
  203.          if (x < this.updateX1) {
  204.             this.updateX1 = x;
  205.          }
  206.  
  207.          if (y < this.updateY1) {
  208.             this.updateY1 = y;
  209.          }
  210.  
  211.          if (x + w > this.updateX2) {
  212.             this.updateX2 = x + w;
  213.          }
  214.  
  215.          if (y + h > this.updateY2) {
  216.             this.updateY2 = y + h;
  217.          }
  218.  
  219.       }
  220.    }
  221.  
  222.    public String toString() {
  223.       return this.getClass().getName() + "[" + this.target + "]";
  224.    }
  225.  
  226.    private native Event setData(int var1, Event var2);
  227.  
  228.    protected void handleQuit(long when) {
  229.       Event e = new Event(this.target, 201, (Object)null);
  230.       this.target.postEvent(e);
  231.    }
  232.  
  233.    protected void handleMoved(long when, int data, int x, int y) {
  234.    }
  235.  
  236.    protected void handleResize(long when, int u1, int width, int height, int u4, int u5) {
  237.    }
  238.  
  239.    protected void handleGotFocus(long when, int data, int u2, int u3, int u4, int u5) {
  240.       Event e = this.setData(data, new Event(this.target, 1004, (Object)null));
  241.       this.target.postEvent(e);
  242.    }
  243.  
  244.    protected void handleLostFocus(long when, int data, int u2, int u3, int u4, int u5) {
  245.       Event e = this.setData(data, new Event(this.target, 1005, (Object)null));
  246.       this.target.postEvent(e);
  247.    }
  248.  
  249.    protected void handleActionKey(long when, int data, int x, int y, int key, int flags) {
  250.       Event e = this.setData(data, new Event(this.target, when, 403, x, y, key, flags));
  251.       this.target.postEvent(e);
  252.    }
  253.  
  254.    protected void handleActionKeyRelease(long when, int data, int x, int y, int key, int flags) {
  255.       Event e = this.setData(data, new Event(this.target, when, 404, x, y, key, flags));
  256.       this.target.postEvent(e);
  257.    }
  258.  
  259.    protected void handleKeyPress(long when, int data, int x, int y, int key, int flags) {
  260.       Event e = this.setData(data, new Event(this.target, when, 401, x, y, key, flags));
  261.       this.target.postEvent(e);
  262.    }
  263.  
  264.    protected void handleKeyRelease(long when, int data, int x, int y, int key, int flags) {
  265.       Event e = this.setData(data, new Event(this.target, when, 402, x, y, key, flags));
  266.       this.target.postEvent(e);
  267.    }
  268.  
  269.    protected void handleMouseEnter(long when, int data, int x, int y) {
  270.       Event e = new Event(this.target, when, 504, x, y, 0, 0, (Object)null);
  271.       this.target.postEvent(e);
  272.    }
  273.  
  274.    protected void handleMouseExit(long when, int data, int x, int y) {
  275.       Event e = new Event(this.target, when, 505, x, y, 0, 0, (Object)null);
  276.       this.target.postEvent(e);
  277.    }
  278.  
  279.    protected void handleMouseDown(long when, int data, int x, int y, int clickCount, int flags) {
  280.       Event e = this.setData(data, new Event(this.target, when, 501, x, y, 0, flags, (Object)null));
  281.       e.clickCount = clickCount;
  282.       this.target.postEvent(e);
  283.    }
  284.  
  285.    protected void handleMouseUp(long when, int data, int x, int y, int u4, int flags) {
  286.       Event e = this.setData(data, new Event(this.target, when, 502, x, y, 0, flags, (Object)null));
  287.       this.target.postEvent(e);
  288.    }
  289.  
  290.    protected void handleMouseMoved(long when, int data, int x, int y, int flags) {
  291.       Event e = this.setData(data, new Event(this.target, when, 503, x, y, 0, flags, (Object)null));
  292.       this.target.postEvent(e);
  293.    }
  294.  
  295.    protected void handleMouseDrag(long when, int data, int x, int y, int flags) {
  296.       Event e = this.setData(data, new Event(this.target, when, 506, x, y, 0, flags, (Object)null));
  297.       this.target.postEvent(e);
  298.    }
  299.  
  300.    protected void handleExpose(long when, int data, int x, int y, int w, int h) {
  301.       Graphics g = this.getGraphics();
  302.  
  303.       try {
  304.          g.clipRect(x, y, w, h);
  305.          this.paint(g);
  306.       } finally {
  307.          g.dispose();
  308.       }
  309.  
  310.    }
  311.  
  312.    protected void handleRepaint(long when, int data, int x, int y, int w, int h) {
  313.       Graphics g = this.getGraphics();
  314.  
  315.       try {
  316.          g.clipRect(x, y, w, h);
  317.          this.update(g);
  318.       } finally {
  319.          g.dispose();
  320.       }
  321.  
  322.    }
  323. }
  324.