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

  1. package java.awt;
  2.  
  3. import java.awt.image.ColorModel;
  4. import java.awt.image.ImageObserver;
  5. import java.awt.image.ImageProducer;
  6. import java.awt.peer.ComponentPeer;
  7. import java.io.PrintStream;
  8.  
  9. public abstract class Component implements ImageObserver {
  10.    ComponentPeer peer;
  11.    Container parent;
  12.    // $FF: renamed from: x int
  13.    int field_0;
  14.    // $FF: renamed from: y int
  15.    int field_1;
  16.    int width;
  17.    int height;
  18.    Color foreground;
  19.    Color background;
  20.    Font font;
  21.    boolean visible = true;
  22.    boolean enabled = true;
  23.    boolean valid = false;
  24.  
  25.    Component() {
  26.    }
  27.  
  28.    public Container getParent() {
  29.       return this.parent;
  30.    }
  31.  
  32.    public ComponentPeer getPeer() {
  33.       return this.peer;
  34.    }
  35.  
  36.    public Toolkit getToolkit() {
  37.       ComponentPeer peer = this.peer;
  38.       if (peer != null) {
  39.          return peer.getToolkit();
  40.       } else {
  41.          Container parent = this.parent;
  42.          return parent != null ? ((Component)parent).getToolkit() : Toolkit.getDefaultToolkit();
  43.       }
  44.    }
  45.  
  46.    public boolean isValid() {
  47.       return this.peer != null && this.valid;
  48.    }
  49.  
  50.    public boolean isVisible() {
  51.       return this.visible;
  52.    }
  53.  
  54.    public boolean isShowing() {
  55.       if (this.visible && this.peer != null) {
  56.          Container parent = this.parent;
  57.          return parent == null || ((Component)parent).isShowing();
  58.       } else {
  59.          return false;
  60.       }
  61.    }
  62.  
  63.    public boolean isEnabled() {
  64.       return this.enabled;
  65.    }
  66.  
  67.    public Point location() {
  68.       return new Point(this.field_0, this.field_1);
  69.    }
  70.  
  71.    public Dimension size() {
  72.       return new Dimension(this.width, this.height);
  73.    }
  74.  
  75.    public Rectangle bounds() {
  76.       return new Rectangle(this.field_0, this.field_1, this.width, this.height);
  77.    }
  78.  
  79.    public synchronized void enable() {
  80.       if (!this.enabled) {
  81.          this.enabled = true;
  82.          if (this.peer != null) {
  83.             this.peer.enable();
  84.          }
  85.       }
  86.  
  87.    }
  88.  
  89.    public void enable(boolean cond) {
  90.       if (cond) {
  91.          this.enable();
  92.       } else {
  93.          this.disable();
  94.       }
  95.    }
  96.  
  97.    public synchronized void disable() {
  98.       if (this.enabled) {
  99.          this.enabled = false;
  100.          if (this.peer != null) {
  101.             this.peer.disable();
  102.          }
  103.       }
  104.  
  105.    }
  106.  
  107.    public synchronized void show() {
  108.       if (!this.visible) {
  109.          this.visible = true;
  110.          if (this.peer != null) {
  111.             this.peer.show();
  112.             if (this.parent != null) {
  113.                this.parent.invalidate();
  114.             }
  115.          }
  116.       }
  117.  
  118.    }
  119.  
  120.    public void show(boolean cond) {
  121.       if (cond) {
  122.          this.show();
  123.       } else {
  124.          this.hide();
  125.       }
  126.    }
  127.  
  128.    public synchronized void hide() {
  129.       if (this.visible) {
  130.          this.visible = false;
  131.          if (this.peer != null) {
  132.             this.peer.hide();
  133.             if (this.parent != null) {
  134.                this.parent.invalidate();
  135.             }
  136.          }
  137.       }
  138.  
  139.    }
  140.  
  141.    public Color getForeground() {
  142.       Color foreground = this.foreground;
  143.       if (foreground != null) {
  144.          return foreground;
  145.       } else {
  146.          Container parent = this.parent;
  147.          return parent != null ? ((Component)parent).getForeground() : null;
  148.       }
  149.    }
  150.  
  151.    public synchronized void setForeground(Color c) {
  152.       this.foreground = c;
  153.       if (this.peer != null) {
  154.          c = this.getForeground();
  155.          if (c != null) {
  156.             this.peer.setForeground(c);
  157.          }
  158.       }
  159.  
  160.    }
  161.  
  162.    public Color getBackground() {
  163.       Color background = this.background;
  164.       if (background != null) {
  165.          return background;
  166.       } else {
  167.          Container parent = this.parent;
  168.          return parent != null ? ((Component)parent).getBackground() : null;
  169.       }
  170.    }
  171.  
  172.    public synchronized void setBackground(Color c) {
  173.       this.background = c;
  174.       if (this.peer != null) {
  175.          c = this.getBackground();
  176.          if (c != null) {
  177.             this.peer.setBackground(c);
  178.          }
  179.       }
  180.  
  181.    }
  182.  
  183.    public Font getFont() {
  184.       Font font = this.font;
  185.       if (font != null) {
  186.          return font;
  187.       } else {
  188.          Container parent = this.parent;
  189.          return parent != null ? ((Component)parent).getFont() : null;
  190.       }
  191.    }
  192.  
  193.    public synchronized void setFont(Font f) {
  194.       this.font = f;
  195.       if (this.peer != null) {
  196.          f = this.getFont();
  197.          if (f != null) {
  198.             this.peer.setFont(f);
  199.          }
  200.       }
  201.  
  202.    }
  203.  
  204.    public synchronized ColorModel getColorModel() {
  205.       return this.peer == null ? this.getToolkit().getColorModel() : this.peer.getColorModel();
  206.    }
  207.  
  208.    public void move(int x, int y) {
  209.       this.reshape(x, y, this.width, this.height);
  210.    }
  211.  
  212.    public void resize(int width, int height) {
  213.       this.reshape(this.field_0, this.field_1, width, height);
  214.    }
  215.  
  216.    public void resize(Dimension d) {
  217.       this.reshape(this.field_0, this.field_1, d.width, d.height);
  218.    }
  219.  
  220.    public synchronized void reshape(int x, int y, int width, int height) {
  221.       boolean resized = this.width != width || this.height != height;
  222.       if (resized || this.field_0 != x || this.field_1 != y) {
  223.          this.field_0 = x;
  224.          this.field_1 = y;
  225.          this.width = width;
  226.          this.height = height;
  227.          if (this.peer != null) {
  228.             this.peer.reshape(x, y, width, height);
  229.             if (resized) {
  230.                this.invalidate();
  231.             }
  232.  
  233.             if (this.parent != null) {
  234.                this.parent.invalidate();
  235.             }
  236.          }
  237.       }
  238.  
  239.    }
  240.  
  241.    public Dimension preferredSize() {
  242.       ComponentPeer peer = this.peer;
  243.       return peer != null ? peer.preferredSize() : this.minimumSize();
  244.    }
  245.  
  246.    public Dimension minimumSize() {
  247.       ComponentPeer peer = this.peer;
  248.       return peer != null ? peer.minimumSize() : this.size();
  249.    }
  250.  
  251.    public void layout() {
  252.    }
  253.  
  254.    public void validate() {
  255.       while(!this.valid && this.peer != null) {
  256.          this.valid = true;
  257.          this.layout();
  258.       }
  259.  
  260.    }
  261.  
  262.    public void invalidate() {
  263.       this.valid = false;
  264.    }
  265.  
  266.    public Graphics getGraphics() {
  267.       ComponentPeer peer = this.peer;
  268.       return peer != null ? peer.getGraphics() : null;
  269.    }
  270.  
  271.    public FontMetrics getFontMetrics(Font font) {
  272.       ComponentPeer peer = this.peer;
  273.       return peer != null ? peer.getFontMetrics(font) : this.getToolkit().getFontMetrics(font);
  274.    }
  275.  
  276.    public void paint(Graphics g) {
  277.    }
  278.  
  279.    public void update(Graphics g) {
  280.       g.setColor(this.getBackground());
  281.       g.fillRect(0, 0, this.width, this.height);
  282.       g.setColor(this.getForeground());
  283.       this.paint(g);
  284.    }
  285.  
  286.    public void paintAll(Graphics g) {
  287.       ComponentPeer peer = this.peer;
  288.       if (this.visible && peer != null) {
  289.          this.validate();
  290.          peer.paint(g);
  291.       }
  292.  
  293.    }
  294.  
  295.    public void repaint() {
  296.       this.repaint(0L, 0, 0, this.width, this.height);
  297.    }
  298.  
  299.    public void repaint(long tm) {
  300.       this.repaint(tm, 0, 0, this.width, this.height);
  301.    }
  302.  
  303.    public void repaint(int x, int y, int width, int height) {
  304.       this.repaint(0L, x, y, width, height);
  305.    }
  306.  
  307.    public void repaint(long tm, int x, int y, int width, int height) {
  308.       ComponentPeer peer = this.peer;
  309.       if (peer != null && width > 0 && height > 0) {
  310.          peer.repaint(tm, x, y, width, height);
  311.       }
  312.  
  313.    }
  314.  
  315.    public void print(Graphics g) {
  316.       this.paint(g);
  317.    }
  318.  
  319.    public void printAll(Graphics g) {
  320.       ComponentPeer peer = this.peer;
  321.       if (this.visible && peer != null) {
  322.          this.validate();
  323.          peer.print(g);
  324.       }
  325.  
  326.    }
  327.  
  328.    public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h) {
  329.       int rate = -1;
  330.       if ((flags & 48) != 0) {
  331.          rate = 0;
  332.       } else if ((flags & 8) != 0) {
  333.          String isInc = System.getProperty("awt.image.incrementaldraw");
  334.          if (isInc == null || isInc.equals("true")) {
  335.             String incRate = System.getProperty("awt.image.redrawrate");
  336.  
  337.             try {
  338.                rate = incRate != null ? Integer.parseInt(incRate) : 100;
  339.                if (rate < 0) {
  340.                   rate = 0;
  341.                }
  342.             } catch (Exception var10) {
  343.                rate = 100;
  344.             }
  345.          }
  346.       }
  347.  
  348.       if (rate >= 0) {
  349.          this.repaint((long)rate, 0, 0, this.width, this.height);
  350.       }
  351.  
  352.       return (flags & 160) == 0;
  353.    }
  354.  
  355.    public Image createImage(ImageProducer producer) {
  356.       ComponentPeer peer = this.peer;
  357.       return peer != null ? peer.createImage(producer) : this.getToolkit().createImage(producer);
  358.    }
  359.  
  360.    public Image createImage(int width, int height) {
  361.       ComponentPeer peer = this.peer;
  362.       return peer != null ? peer.createImage(width, height) : null;
  363.    }
  364.  
  365.    public boolean prepareImage(Image image, ImageObserver observer) {
  366.       return this.prepareImage(image, -1, -1, observer);
  367.    }
  368.  
  369.    public boolean prepareImage(Image image, int width, int height, ImageObserver observer) {
  370.       ComponentPeer peer = this.peer;
  371.       return peer != null ? peer.prepareImage(image, width, height, observer) : this.getToolkit().prepareImage(image, width, height, observer);
  372.    }
  373.  
  374.    public int checkImage(Image image, ImageObserver observer) {
  375.       return this.checkImage(image, -1, -1, observer);
  376.    }
  377.  
  378.    public int checkImage(Image image, int width, int height, ImageObserver observer) {
  379.       ComponentPeer peer = this.peer;
  380.       return peer != null ? peer.checkImage(image, width, height, observer) : this.getToolkit().checkImage(image, width, height, observer);
  381.    }
  382.  
  383.    public synchronized boolean inside(int x, int y) {
  384.       return x >= 0 && x - this.field_0 < this.width && y >= 0 && y - this.field_1 < this.height;
  385.    }
  386.  
  387.    public Component locate(int x, int y) {
  388.       return this.inside(x, y) ? this : null;
  389.    }
  390.  
  391.    public void deliverEvent(Event e) {
  392.       this.postEvent(e);
  393.    }
  394.  
  395.    public boolean postEvent(Event e) {
  396.       ComponentPeer peer = this.peer;
  397.       if (this.handleEvent(e)) {
  398.          return true;
  399.       } else {
  400.          Component parent = this.parent;
  401.          if (parent != null) {
  402.             e.translate(this.field_0, this.field_1);
  403.             if (parent.postEvent(e)) {
  404.                return true;
  405.             }
  406.          }
  407.  
  408.          return peer != null ? peer.handleEvent(e) : false;
  409.       }
  410.    }
  411.  
  412.    public boolean handleEvent(Event evt) {
  413.       switch (evt.id) {
  414.          case 403:
  415.          case 401:
  416.             return this.keyDown(evt, evt.key);
  417.          case 504:
  418.             return this.mouseEnter(evt, evt.x, evt.y);
  419.          case 402:
  420.          case 404:
  421.             return this.keyUp(evt, evt.key);
  422.          case 503:
  423.             return this.mouseMove(evt, evt.x, evt.y);
  424.          case 502:
  425.             return this.mouseUp(evt, evt.x, evt.y);
  426.          case 501:
  427.             return this.mouseDown(evt, evt.x, evt.y);
  428.          case 1005:
  429.             return this.lostFocus(evt, evt.arg);
  430.          case 1004:
  431.             return this.gotFocus(evt, evt.arg);
  432.          case 1001:
  433.             return this.action(evt, evt.arg);
  434.          case 506:
  435.             return this.mouseDrag(evt, evt.x, evt.y);
  436.          case 505:
  437.             return this.mouseExit(evt, evt.x, evt.y);
  438.          default:
  439.             return false;
  440.       }
  441.    }
  442.  
  443.    public boolean mouseDown(Event evt, int x, int y) {
  444.       return false;
  445.    }
  446.  
  447.    public boolean mouseDrag(Event evt, int x, int y) {
  448.       return false;
  449.    }
  450.  
  451.    public boolean mouseUp(Event evt, int x, int y) {
  452.       return false;
  453.    }
  454.  
  455.    public boolean mouseMove(Event evt, int x, int y) {
  456.       return false;
  457.    }
  458.  
  459.    public boolean mouseEnter(Event evt, int x, int y) {
  460.       return false;
  461.    }
  462.  
  463.    public boolean mouseExit(Event evt, int x, int y) {
  464.       return false;
  465.    }
  466.  
  467.    public boolean keyDown(Event evt, int key) {
  468.       return false;
  469.    }
  470.  
  471.    public boolean keyUp(Event evt, int key) {
  472.       return false;
  473.    }
  474.  
  475.    public boolean action(Event evt, Object what) {
  476.       return false;
  477.    }
  478.  
  479.    public void addNotify() {
  480.       this.valid = false;
  481.    }
  482.  
  483.    public synchronized void removeNotify() {
  484.       if (this.peer != null) {
  485.          this.peer.dispose();
  486.          this.peer = null;
  487.       }
  488.  
  489.    }
  490.  
  491.    public boolean gotFocus(Event evt, Object what) {
  492.       return false;
  493.    }
  494.  
  495.    public boolean lostFocus(Event evt, Object what) {
  496.       return false;
  497.    }
  498.  
  499.    public void requestFocus() {
  500.       ComponentPeer peer = this.peer;
  501.       if (peer != null) {
  502.          peer.requestFocus();
  503.       }
  504.  
  505.    }
  506.  
  507.    public void nextFocus() {
  508.       ComponentPeer peer = this.peer;
  509.       if (peer != null) {
  510.          peer.nextFocus();
  511.       }
  512.  
  513.    }
  514.  
  515.    protected String paramString() {
  516.       String str = this.field_0 + "," + this.field_1 + "," + this.width + "x" + this.height;
  517.       if (!this.valid) {
  518.          str = str + ",invalid";
  519.       }
  520.  
  521.       if (!this.visible) {
  522.          str = str + ",hidden";
  523.       }
  524.  
  525.       if (!this.enabled) {
  526.          str = str + ",disabled";
  527.       }
  528.  
  529.       return str;
  530.    }
  531.  
  532.    public String toString() {
  533.       return this.getClass().getName() + "[" + this.paramString() + "]";
  534.    }
  535.  
  536.    public void list() {
  537.       this.list(System.out, 0);
  538.    }
  539.  
  540.    public void list(PrintStream out) {
  541.       this.list(out, 0);
  542.    }
  543.  
  544.    public void list(PrintStream out, int indent) {
  545.       for(int i = 0; i < indent; ++i) {
  546.          out.print("  ");
  547.       }
  548.  
  549.       out.println(this);
  550.    }
  551. }
  552.