home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / plaf / basic / BasicInternalFrameUI.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  10.6 KB  |  413 lines

  1. package javax.swing.plaf.basic;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Dimension;
  7. import java.awt.IllegalComponentStateException;
  8. import java.awt.LayoutManager;
  9. import java.awt.Rectangle;
  10. import java.awt.event.ComponentListener;
  11. import java.beans.PropertyChangeListener;
  12. import javax.swing.ActionMap;
  13. import javax.swing.DefaultDesktopManager;
  14. import javax.swing.DesktopManager;
  15. import javax.swing.Icon;
  16. import javax.swing.InputMap;
  17. import javax.swing.JComponent;
  18. import javax.swing.JInternalFrame;
  19. import javax.swing.KeyStroke;
  20. import javax.swing.LookAndFeel;
  21. import javax.swing.SwingUtilities;
  22. import javax.swing.UIManager;
  23. import javax.swing.event.InternalFrameListener;
  24. import javax.swing.event.MouseInputAdapter;
  25. import javax.swing.event.MouseInputListener;
  26. import javax.swing.plaf.ActionMapUIResource;
  27. import javax.swing.plaf.ComponentUI;
  28. import javax.swing.plaf.InternalFrameUI;
  29. import javax.swing.plaf.UIResource;
  30.  
  31. public class BasicInternalFrameUI extends InternalFrameUI {
  32.    protected JInternalFrame frame;
  33.    protected MouseInputAdapter borderListener;
  34.    protected PropertyChangeListener propertyChangeListener;
  35.    protected LayoutManager internalFrameLayout;
  36.    protected ComponentListener componentListener;
  37.    protected MouseInputListener glassPaneDispatcher;
  38.    protected JComponent northPane;
  39.    protected JComponent southPane;
  40.    protected JComponent westPane;
  41.    protected JComponent eastPane;
  42.    protected BasicInternalFrameTitlePane titlePane;
  43.    private static DesktopManager sharedDesktopManager;
  44.    private boolean componentListenerAdded = false;
  45.    private Rectangle parentBounds = null;
  46.    protected KeyStroke openMenuKey;
  47.    private boolean keyBindingRegistered = false;
  48.    private boolean keyBindingActive = false;
  49.    private InternalFrameListener internalFrameListener = null;
  50.  
  51.    public static ComponentUI createUI(JComponent var0) {
  52.       return new BasicInternalFrameUI((JInternalFrame)var0);
  53.    }
  54.  
  55.    public BasicInternalFrameUI(JInternalFrame var1) {
  56.    }
  57.  
  58.    public void installUI(JComponent var1) {
  59.       this.frame = (JInternalFrame)var1;
  60.       this.frame.add(this.frame.getRootPane(), "Center");
  61.       this.installDefaults();
  62.       this.installComponents();
  63.       this.installListeners();
  64.       this.installKeyboardActions();
  65.       this.setNorthPane(this.createNorthPane(this.frame));
  66.       this.setSouthPane(this.createSouthPane(this.frame));
  67.       this.setEastPane(this.createEastPane(this.frame));
  68.       this.setWestPane(this.createWestPane(this.frame));
  69.       this.frame.setOpaque(true);
  70.       int var2 = (this.getNorthPane() != null ? this.getNorthPane().getMinimumSize().height : 0) + this.frame.getInsets().top + this.frame.getInsets().bottom;
  71.       this.frame.setMinimumSize(new Dimension(120, var2));
  72.    }
  73.  
  74.    public void uninstallUI(JComponent var1) {
  75.       if (var1 != this.frame) {
  76.          throw new IllegalComponentStateException(this + " was asked to deinstall() " + var1 + " when it only knows about " + this.frame + ".");
  77.       } else {
  78.          this.uninstallDefaults();
  79.          this.uninstallComponents();
  80.          this.frame.setCursor(Cursor.getPredefinedCursor(0));
  81.          this.setNorthPane((JComponent)null);
  82.          this.setSouthPane((JComponent)null);
  83.          this.setEastPane((JComponent)null);
  84.          this.setWestPane((JComponent)null);
  85.          this.uninstallListeners();
  86.          this.uninstallKeyboardActions();
  87.          this.frame.remove(this.frame.getRootPane());
  88.          this.frame = null;
  89.       }
  90.    }
  91.  
  92.    protected void installDefaults() {
  93.       Icon var1 = this.frame.getFrameIcon();
  94.       if (var1 == null || var1 instanceof UIResource) {
  95.          this.frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon"));
  96.       }
  97.  
  98.       JComponent var2 = (JComponent)this.frame.getContentPane();
  99.       if (var2 != null) {
  100.          Color var3 = ((Component)var2).getBackground();
  101.          if (var3 instanceof UIResource) {
  102.             var2.setBackground((Color)null);
  103.          }
  104.       }
  105.  
  106.       LookAndFeel.installBorder(this.frame, "InternalFrame.border");
  107.    }
  108.  
  109.    protected void installKeyboardActions() {
  110.       if (this.internalFrameListener == null) {
  111.          this.createInternalFrameListener();
  112.       }
  113.  
  114.       this.frame.addInternalFrameListener(this.internalFrameListener);
  115.    }
  116.  
  117.    protected void installComponents() {
  118.    }
  119.  
  120.    protected void installListeners() {
  121.       this.borderListener = this.createBorderListener(this.frame);
  122.       this.propertyChangeListener = this.createPropertyChangeListener();
  123.       this.frame.addPropertyChangeListener(this.propertyChangeListener);
  124.       this.frame.setLayout(this.internalFrameLayout = this.createLayoutManager());
  125.       this.installMouseHandlers(this.frame);
  126.       this.glassPaneDispatcher = this.createGlassPaneDispatcher();
  127.       this.frame.getGlassPane().addMouseListener(this.glassPaneDispatcher);
  128.       this.frame.getGlassPane().addMouseMotionListener(this.glassPaneDispatcher);
  129.       this.componentListener = this.createComponentListener();
  130.       if (this.frame.getParent() != null && !this.componentListenerAdded) {
  131.          this.frame.getParent().addComponentListener(this.componentListener);
  132.          this.componentListenerAdded = true;
  133.          this.parentBounds = this.frame.getParent().getBounds();
  134.       }
  135.  
  136.    }
  137.  
  138.    InputMap getInputMap(int var1) {
  139.       return var1 == 2 ? this.createInputMap(var1) : null;
  140.    }
  141.  
  142.    InputMap createInputMap(int var1) {
  143.       if (var1 == 2) {
  144.          Object[] var2 = UIManager.get("InternalFrame.windowBindings");
  145.          if (var2 != null) {
  146.             return LookAndFeel.makeComponentInputMap(this.frame, var2);
  147.          }
  148.       }
  149.  
  150.       return null;
  151.    }
  152.  
  153.    ActionMap getActionMap() {
  154.       return this.createActionMap();
  155.    }
  156.  
  157.    ActionMap createActionMap() {
  158.       ActionMapUIResource var1 = new ActionMapUIResource();
  159.       ((ActionMap)var1).put("showSystemMenu", new 1(this));
  160.       return var1;
  161.    }
  162.  
  163.    protected void uninstallDefaults() {
  164.       Icon var1 = this.frame.getFrameIcon();
  165.       if (var1 instanceof UIResource) {
  166.          this.frame.setFrameIcon((Icon)null);
  167.       }
  168.  
  169.       LookAndFeel.uninstallBorder(this.frame);
  170.    }
  171.  
  172.    protected void uninstallComponents() {
  173.    }
  174.  
  175.    protected void uninstallListeners() {
  176.       this.deinstallMouseHandlers(this.frame);
  177.       this.frame.removePropertyChangeListener(this.propertyChangeListener);
  178.       this.frame.setLayout((LayoutManager)null);
  179.       this.internalFrameLayout = null;
  180.       this.propertyChangeListener = null;
  181.       this.frame.getGlassPane().removeMouseListener(this.glassPaneDispatcher);
  182.       this.frame.getGlassPane().removeMouseMotionListener(this.glassPaneDispatcher);
  183.       if (this.frame.getParent() != null && this.componentListenerAdded) {
  184.          this.frame.getParent().removeComponentListener(this.componentListener);
  185.          this.componentListenerAdded = false;
  186.       }
  187.  
  188.       this.glassPaneDispatcher = null;
  189.       this.componentListener = null;
  190.       this.borderListener = null;
  191.    }
  192.  
  193.    protected void uninstallKeyboardActions() {
  194.       if (this.internalFrameListener != null) {
  195.          this.frame.removeInternalFrameListener(this.internalFrameListener);
  196.       }
  197.  
  198.       if (this.isKeyBindingRegistered()) {
  199.          SwingUtilities.replaceUIInputMap(this.frame, 2, (InputMap)null);
  200.          SwingUtilities.replaceUIActionMap(this.frame, (ActionMap)null);
  201.       }
  202.  
  203.    }
  204.  
  205.    protected LayoutManager createLayoutManager() {
  206.       return new InternalFrameLayout(this);
  207.    }
  208.  
  209.    protected PropertyChangeListener createPropertyChangeListener() {
  210.       return new InternalFramePropertyChangeListener(this);
  211.    }
  212.  
  213.    public Dimension getPreferredSize(JComponent var1) {
  214.       return this.frame == var1 ? this.frame.getLayout().preferredLayoutSize(var1) : new Dimension(100, 100);
  215.    }
  216.  
  217.    public Dimension getMinimumSize(JComponent var1) {
  218.       return this.frame == var1 ? this.frame.getLayout().minimumLayoutSize(var1) : new Dimension(0, 0);
  219.    }
  220.  
  221.    public Dimension getMaximumSize(JComponent var1) {
  222.       return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
  223.    }
  224.  
  225.    protected void replacePane(JComponent var1, JComponent var2) {
  226.       if (var1 != null) {
  227.          this.deinstallMouseHandlers(var1);
  228.          this.frame.remove(var1);
  229.       }
  230.  
  231.       if (var2 != null) {
  232.          this.frame.add(var2);
  233.          this.installMouseHandlers(var2);
  234.       }
  235.  
  236.    }
  237.  
  238.    protected void deinstallMouseHandlers(JComponent var1) {
  239.       ((Component)var1).removeMouseListener(this.borderListener);
  240.       ((Component)var1).removeMouseMotionListener(this.borderListener);
  241.    }
  242.  
  243.    protected void installMouseHandlers(JComponent var1) {
  244.       ((Component)var1).addMouseListener(this.borderListener);
  245.       ((Component)var1).addMouseMotionListener(this.borderListener);
  246.    }
  247.  
  248.    protected JComponent createNorthPane(JInternalFrame var1) {
  249.       this.titlePane = new BasicInternalFrameTitlePane(var1);
  250.       return this.titlePane;
  251.    }
  252.  
  253.    protected JComponent createSouthPane(JInternalFrame var1) {
  254.       return null;
  255.    }
  256.  
  257.    protected JComponent createWestPane(JInternalFrame var1) {
  258.       return null;
  259.    }
  260.  
  261.    protected JComponent createEastPane(JInternalFrame var1) {
  262.       return null;
  263.    }
  264.  
  265.    protected MouseInputAdapter createBorderListener(JInternalFrame var1) {
  266.       return new BorderListener(this);
  267.    }
  268.  
  269.    private InternalFrameListener getInternalFrameListener() {
  270.       return this.internalFrameListener;
  271.    }
  272.  
  273.    protected void createInternalFrameListener() {
  274.       this.internalFrameListener = new BasicInternalFrameListener(this);
  275.    }
  276.  
  277.    protected final boolean isKeyBindingRegistered() {
  278.       return this.keyBindingRegistered;
  279.    }
  280.  
  281.    protected final void setKeyBindingRegistered(boolean var1) {
  282.       this.keyBindingRegistered = var1;
  283.    }
  284.  
  285.    public final boolean isKeyBindingActive() {
  286.       return this.keyBindingActive;
  287.    }
  288.  
  289.    protected final void setKeyBindingActive(boolean var1) {
  290.       this.keyBindingActive = var1;
  291.    }
  292.  
  293.    protected void setupMenuOpenKey() {
  294.       InputMap var1 = this.getInputMap(2);
  295.       SwingUtilities.replaceUIInputMap(this.frame, 2, var1);
  296.       ActionMap var2 = this.getActionMap();
  297.       SwingUtilities.replaceUIActionMap(this.frame, var2);
  298.    }
  299.  
  300.    protected void setupMenuCloseKey() {
  301.    }
  302.  
  303.    public JComponent getNorthPane() {
  304.       return this.northPane;
  305.    }
  306.  
  307.    public void setNorthPane(JComponent var1) {
  308.       this.replacePane(this.northPane, var1);
  309.       this.northPane = var1;
  310.    }
  311.  
  312.    public JComponent getSouthPane() {
  313.       return this.southPane;
  314.    }
  315.  
  316.    public void setSouthPane(JComponent var1) {
  317.       this.southPane = var1;
  318.    }
  319.  
  320.    public JComponent getWestPane() {
  321.       return this.westPane;
  322.    }
  323.  
  324.    public void setWestPane(JComponent var1) {
  325.       this.westPane = var1;
  326.    }
  327.  
  328.    public JComponent getEastPane() {
  329.       return this.eastPane;
  330.    }
  331.  
  332.    public void setEastPane(JComponent var1) {
  333.       this.eastPane = var1;
  334.    }
  335.  
  336.    protected DesktopManager getDesktopManager() {
  337.       if (this.frame.getDesktopPane() != null && this.frame.getDesktopPane().getDesktopManager() != null) {
  338.          return this.frame.getDesktopPane().getDesktopManager();
  339.       } else {
  340.          if (sharedDesktopManager == null) {
  341.             sharedDesktopManager = this.createDesktopManager();
  342.          }
  343.  
  344.          return sharedDesktopManager;
  345.       }
  346.    }
  347.  
  348.    protected DesktopManager createDesktopManager() {
  349.       return new DefaultDesktopManager();
  350.    }
  351.  
  352.    protected void closeFrame(JInternalFrame var1) {
  353.       this.getDesktopManager().closeFrame(var1);
  354.    }
  355.  
  356.    protected void maximizeFrame(JInternalFrame var1) {
  357.       this.getDesktopManager().maximizeFrame(var1);
  358.    }
  359.  
  360.    protected void minimizeFrame(JInternalFrame var1) {
  361.       this.getDesktopManager().minimizeFrame(var1);
  362.    }
  363.  
  364.    protected void iconifyFrame(JInternalFrame var1) {
  365.       this.getDesktopManager().iconifyFrame(var1);
  366.    }
  367.  
  368.    protected void deiconifyFrame(JInternalFrame var1) {
  369.       this.getDesktopManager().deiconifyFrame(var1);
  370.    }
  371.  
  372.    protected void activateFrame(JInternalFrame var1) {
  373.       this.getDesktopManager().activateFrame(var1);
  374.    }
  375.  
  376.    protected void deactivateFrame(JInternalFrame var1) {
  377.       this.getDesktopManager().deactivateFrame(var1);
  378.    }
  379.  
  380.    protected ComponentListener createComponentListener() {
  381.       return new ComponentHandler(this);
  382.    }
  383.  
  384.    protected MouseInputListener createGlassPaneDispatcher() {
  385.       return new GlassPaneDispatcher(this);
  386.    }
  387.  
  388.    // $FF: synthetic method
  389.    static boolean access$000(BasicInternalFrameUI var0) {
  390.       return var0.componentListenerAdded;
  391.    }
  392.  
  393.    // $FF: synthetic method
  394.    static boolean access$002(BasicInternalFrameUI var0, boolean var1) {
  395.       return var0.componentListenerAdded = var1;
  396.    }
  397.  
  398.    // $FF: synthetic method
  399.    static Rectangle access$102(BasicInternalFrameUI var0, Rectangle var1) {
  400.       return var0.parentBounds = var1;
  401.    }
  402.  
  403.    // $FF: synthetic method
  404.    static Rectangle access$100(BasicInternalFrameUI var0) {
  405.       return var0.parentBounds;
  406.    }
  407.  
  408.    // $FF: synthetic method
  409.    static InternalFrameListener access$200(BasicInternalFrameUI var0) {
  410.       return var0.internalFrameListener;
  411.    }
  412. }
  413.