home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / S992TT (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  6.6 KB  |  287 lines

  1. package com.sun.java.swing;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.Rectangle;
  7. import java.beans.PropertyVetoException;
  8. import java.io.Serializable;
  9.  
  10. public class DefaultDesktopManager implements DesktopManager, Serializable {
  11.    static final String PREVIOUS_BOUNDS_PROPERTY = "previousBounds";
  12.    static final String HAS_BEEN_ICONIFIED_PROPERTY = "wasIconOnce";
  13.  
  14.    public void activateFrame(JInternalFrame f) {
  15.       Container p = ((Component)f).getParent();
  16.       if (p == null) {
  17.          p = f.getDesktopIcon().getParent();
  18.          if (p == null) {
  19.             return;
  20.          }
  21.       }
  22.  
  23.       Component[] c;
  24.       if (p instanceof JLayeredPane) {
  25.          JLayeredPane var10000 = (JLayeredPane)p;
  26.          JLayeredPane var10001 = (JLayeredPane)p;
  27.          c = var10000.getComponentsInLayer(JLayeredPane.getLayer(f));
  28.       } else {
  29.          c = p.getComponents();
  30.       }
  31.  
  32.       int count = c.length;
  33.  
  34.       for(int i = 0; i < count; ++i) {
  35.          if (c[i] != f && c[i] instanceof JInternalFrame) {
  36.             JInternalFrame w = (JInternalFrame)c[i];
  37.             if (w.isSelected()) {
  38.                try {
  39.                   w.setSelected(false);
  40.                } catch (PropertyVetoException var7) {
  41.                }
  42.             }
  43.          } else if (c[i] instanceof JInternalFrame.JDesktopIcon && c[i] != f.getDesktopIcon()) {
  44.             JInternalFrame w = ((JInternalFrame.JDesktopIcon)c[i]).getInternalFrame();
  45.             if (w.isSelected()) {
  46.                try {
  47.                   w.setSelected(false);
  48.                } catch (PropertyVetoException var8) {
  49.                }
  50.             }
  51.          }
  52.       }
  53.  
  54.       f.moveToFront();
  55.    }
  56.  
  57.    public void beginDraggingFrame(JComponent f) {
  58.    }
  59.  
  60.    public void beginResizingFrame(JComponent f, int direction) {
  61.    }
  62.  
  63.    public void closeFrame(JInternalFrame f) {
  64.       if (((Component)f).getParent() != null) {
  65.          Container c = ((Component)f).getParent();
  66.          c.remove(f);
  67.          ((Component)c).repaint(((JComponent)f).getX(), ((JComponent)f).getY(), ((JComponent)f).getWidth(), ((JComponent)f).getHeight());
  68.       }
  69.  
  70.       this.removeIconFor(f);
  71.       if (this.getPreviousBounds(f) != null) {
  72.          this.setPreviousBounds(f, (Rectangle)null);
  73.       }
  74.  
  75.       if (this.wasIcon(f)) {
  76.          this.setWasIcon(f, (Boolean)null);
  77.       }
  78.  
  79.    }
  80.  
  81.    public void deactivateFrame(JInternalFrame f) {
  82.    }
  83.  
  84.    public void deiconifyFrame(JInternalFrame f) {
  85.       JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
  86.       if (((Component)desktopIcon).getParent() != null) {
  87.          ((Component)desktopIcon).getParent().add(f);
  88.          this.removeIconFor(f);
  89.  
  90.          try {
  91.             f.setSelected(true);
  92.          } catch (PropertyVetoException var3) {
  93.          }
  94.       }
  95.  
  96.    }
  97.  
  98.    public void dragFrame(JComponent f, int newX, int newY) {
  99.       this.setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
  100.    }
  101.  
  102.    public void endDraggingFrame(JComponent f) {
  103.    }
  104.  
  105.    public void endResizingFrame(JComponent f) {
  106.    }
  107.  
  108.    protected Rectangle getBoundsForIconOf(JInternalFrame f) {
  109.       Rectangle p = ((Component)f).getParent().getBounds();
  110.       Dimension prefSize = f.getDesktopIcon().getPreferredSize();
  111.       int w2 = prefSize.width;
  112.       int h2 = prefSize.height;
  113.       int x2 = 0;
  114.       int y2 = p.height - h2;
  115.       if (((Component)f).getParent() == null && f.getDesktopIcon().getParent() == null) {
  116.          return new Rectangle(x2, y2, w2, h2);
  117.       } else {
  118.          Container lp = ((Component)f).getParent();
  119.          if (lp == null) {
  120.             lp = f.getDesktopIcon().getParent();
  121.          }
  122.  
  123.          int pos = lp.getComponentCount();
  124.          lp.getComponents();
  125.          int x3 = 0;
  126.          int y3 = p.height;
  127.  
  128.          for(int i = pos - 1; i >= 0; --i) {
  129.             JInternalFrame next = null;
  130.             if (lp.getComponent(i) instanceof JInternalFrame) {
  131.                next = (JInternalFrame)lp.getComponent(i);
  132.             } else if (lp.getComponent(i) instanceof JInternalFrame.JDesktopIcon) {
  133.                next = ((JInternalFrame.JDesktopIcon)lp.getComponent(i)).getInternalFrame();
  134.             }
  135.  
  136.             if (next != null && next != f && this.wasIcon(next)) {
  137.                Rectangle b = next.getDesktopIcon().getBounds();
  138.                if (b.y < y3) {
  139.                   y3 = b.y;
  140.                   x3 = b.x + b.width;
  141.                } else if (b.y == y3 && b.x + b.width > x3) {
  142.                   x3 = b.x + b.width;
  143.                }
  144.             }
  145.          }
  146.  
  147.          if (y3 != p.height) {
  148.             y2 = y3;
  149.          }
  150.  
  151.          if (x3 + w2 > p.width) {
  152.             y2 -= h2;
  153.             x2 = 0;
  154.          } else {
  155.             x2 = x3;
  156.          }
  157.  
  158.          return new Rectangle(x2, y2, w2, h2);
  159.       }
  160.    }
  161.  
  162.    protected Rectangle getPreviousBounds(JInternalFrame f) {
  163.       return (Rectangle)((JComponent)f).getClientProperty("previousBounds");
  164.    }
  165.  
  166.    public void iconifyFrame(JInternalFrame f) {
  167.       JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
  168.       if (!this.wasIcon(f)) {
  169.          Rectangle r = this.getBoundsForIconOf(f);
  170.          ((Component)desktopIcon).setBounds(r.x, r.y, r.width, r.height);
  171.          this.setWasIcon(f, Boolean.TRUE);
  172.       }
  173.  
  174.       Container c = ((Component)f).getParent();
  175.       c.remove(f);
  176.       c.add(desktopIcon);
  177.       ((Component)c).repaint(((JComponent)f).getX(), ((JComponent)f).getY(), ((JComponent)f).getWidth(), ((JComponent)f).getHeight());
  178.  
  179.       try {
  180.          f.setSelected(false);
  181.       } catch (PropertyVetoException var5) {
  182.       }
  183.  
  184.    }
  185.  
  186.    public void maximizeFrame(JInternalFrame f) {
  187.       Rectangle p;
  188.       if (!f.isIcon()) {
  189.          this.setPreviousBounds(f, ((Component)f).getBounds());
  190.          p = ((Component)f).getParent().getBounds();
  191.       } else {
  192.          Container c = f.getDesktopIcon().getParent();
  193.          if (c == null) {
  194.             return;
  195.          }
  196.  
  197.          p = ((Component)c).getBounds();
  198.  
  199.          try {
  200.             f.setIcon(false);
  201.          } catch (PropertyVetoException var5) {
  202.          }
  203.       }
  204.  
  205.       this.setBoundsForFrame(f, 0, 0, p.width, p.height);
  206.  
  207.       try {
  208.          f.setSelected(true);
  209.       } catch (PropertyVetoException var4) {
  210.       }
  211.  
  212.       this.removeIconFor(f);
  213.    }
  214.  
  215.    public void minimizeFrame(JInternalFrame f) {
  216.       if (this.getPreviousBounds(f) != null) {
  217.          Rectangle r = this.getPreviousBounds(f);
  218.          this.setPreviousBounds(f, (Rectangle)null);
  219.  
  220.          try {
  221.             f.setSelected(true);
  222.          } catch (PropertyVetoException var4) {
  223.          }
  224.  
  225.          if (f.isIcon()) {
  226.             try {
  227.                f.setIcon(false);
  228.             } catch (PropertyVetoException var3) {
  229.             }
  230.          }
  231.  
  232.          this.setBoundsForFrame(f, r.x, r.y, r.width, r.height);
  233.       }
  234.  
  235.       this.removeIconFor(f);
  236.    }
  237.  
  238.    public void openFrame(JInternalFrame f) {
  239.       if (f.getDesktopIcon().getParent() != null) {
  240.          f.getDesktopIcon().getParent().add(f);
  241.          this.removeIconFor(f);
  242.       }
  243.  
  244.    }
  245.  
  246.    protected void removeIconFor(JInternalFrame f) {
  247.       JInternalFrame.JDesktopIcon di = f.getDesktopIcon();
  248.       Container c = ((Component)di).getParent();
  249.       if (c != null) {
  250.          c.remove(di);
  251.          ((Component)c).repaint(((JComponent)di).getX(), ((JComponent)di).getY(), ((JComponent)di).getWidth(), ((JComponent)di).getHeight());
  252.       }
  253.  
  254.    }
  255.  
  256.    public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
  257.       this.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
  258.    }
  259.  
  260.    public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
  261.       boolean didResize = f.getWidth() != newWidth || f.getHeight() != newHeight;
  262.       ((Component)f).setBounds(newX, newY, newWidth, newHeight);
  263.       if (didResize) {
  264.          ((Container)f).validate();
  265.       }
  266.  
  267.    }
  268.  
  269.    protected void setPreviousBounds(JInternalFrame f, Rectangle r) {
  270.       if (r != null) {
  271.          ((JComponent)f).putClientProperty("previousBounds", r);
  272.       }
  273.  
  274.    }
  275.  
  276.    protected void setWasIcon(JInternalFrame f, Boolean value) {
  277.       if (value != null) {
  278.          ((JComponent)f).putClientProperty("wasIconOnce", value);
  279.       }
  280.  
  281.    }
  282.  
  283.    protected boolean wasIcon(JInternalFrame f) {
  284.       return ((JComponent)f).getClientProperty("wasIconOnce") == Boolean.TRUE;
  285.    }
  286. }
  287.