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 / BasicInternalFrameTitlePane.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  8.2 KB  |  277 lines

  1. package javax.swing.plaf.basic;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.LayoutManager;
  10. import java.awt.Toolkit;
  11. import java.beans.PropertyChangeListener;
  12. import javax.swing.AbstractButton;
  13. import javax.swing.Action;
  14. import javax.swing.ActionMap;
  15. import javax.swing.Icon;
  16. import javax.swing.JButton;
  17. import javax.swing.JComponent;
  18. import javax.swing.JInternalFrame;
  19. import javax.swing.JMenu;
  20. import javax.swing.JMenuBar;
  21. import javax.swing.JMenuItem;
  22. import javax.swing.JSeparator;
  23. import javax.swing.SwingUtilities;
  24. import javax.swing.UIManager;
  25. import javax.swing.event.InternalFrameEvent;
  26. import javax.swing.plaf.ActionMapUIResource;
  27.  
  28. public class BasicInternalFrameTitlePane extends JComponent {
  29.    protected JMenuBar menuBar;
  30.    protected JButton iconButton;
  31.    protected JButton maxButton;
  32.    protected JButton closeButton;
  33.    protected JMenu windowMenu;
  34.    protected JInternalFrame frame;
  35.    protected Color selectedTitleColor;
  36.    protected Color selectedTextColor;
  37.    protected Color notSelectedTitleColor;
  38.    protected Color notSelectedTextColor;
  39.    protected Icon maxIcon;
  40.    protected Icon minIcon;
  41.    protected Icon iconIcon;
  42.    protected Icon closeIcon;
  43.    protected PropertyChangeListener propertyChangeListener;
  44.    protected Action closeAction;
  45.    protected Action maximizeAction;
  46.    protected Action iconifyAction;
  47.    protected Action restoreAction;
  48.    protected Action moveAction;
  49.    protected Action sizeAction;
  50.    protected static final String CLOSE_CMD = "Close";
  51.    protected static final String ICONIFY_CMD = "Minimize";
  52.    protected static final String RESTORE_CMD = "Restore";
  53.    protected static final String MAXIMIZE_CMD = "Maximize";
  54.    protected static final String MOVE_CMD = "Move";
  55.    protected static final String SIZE_CMD = "Size";
  56.    // $FF: synthetic field
  57.    static Class class$javax$swing$JInternalFrame;
  58.  
  59.    public BasicInternalFrameTitlePane(JInternalFrame var1) {
  60.       this.frame = var1;
  61.       this.installTitlePane();
  62.    }
  63.  
  64.    protected void installTitlePane() {
  65.       this.installDefaults();
  66.       this.createActions();
  67.       this.enableActions();
  68.       this.createActionMap();
  69.       ((Container)this).setLayout(this.createLayout());
  70.       this.assembleSystemMenu();
  71.       this.createButtons();
  72.       this.addSubComponents();
  73.    }
  74.  
  75.    protected void addSubComponents() {
  76.       ((Container)this).add(this.menuBar);
  77.       ((Container)this).add(this.iconButton);
  78.       ((Container)this).add(this.maxButton);
  79.       ((Container)this).add(this.closeButton);
  80.    }
  81.  
  82.    protected void createActions() {
  83.       this.maximizeAction = new MaximizeAction(this);
  84.       this.iconifyAction = new IconifyAction(this);
  85.       this.closeAction = new CloseAction(this);
  86.       this.restoreAction = new RestoreAction(this);
  87.       this.moveAction = new MoveAction(this);
  88.       this.sizeAction = new SizeAction(this);
  89.    }
  90.  
  91.    ActionMap createActionMap() {
  92.       ActionMapUIResource var1 = new ActionMapUIResource();
  93.       ((ActionMap)var1).put("showSystemMenu", new ShowSystemMenuAction(this, true));
  94.       ((ActionMap)var1).put("hideSystemMenu", new ShowSystemMenuAction(this, false));
  95.       return var1;
  96.    }
  97.  
  98.    protected void installListeners() {
  99.       if (this.propertyChangeListener == null) {
  100.          this.propertyChangeListener = this.createPropertyChangeListener();
  101.       }
  102.  
  103.       this.frame.addPropertyChangeListener(this.propertyChangeListener);
  104.    }
  105.  
  106.    protected void uninstallListeners() {
  107.       this.frame.removePropertyChangeListener(this.propertyChangeListener);
  108.    }
  109.  
  110.    protected void installDefaults() {
  111.       this.maxIcon = UIManager.getIcon("InternalFrame.maximizeIcon");
  112.       this.minIcon = UIManager.getIcon("InternalFrame.minimizeIcon");
  113.       this.iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon");
  114.       this.closeIcon = UIManager.getIcon("InternalFrame.closeIcon");
  115.       this.selectedTitleColor = UIManager.getColor("InternalFrame.activeTitleBackground");
  116.       this.selectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground");
  117.       this.notSelectedTitleColor = UIManager.getColor("InternalFrame.inactiveTitleBackground");
  118.       this.notSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground");
  119.    }
  120.  
  121.    protected void uninstallDefaults() {
  122.    }
  123.  
  124.    public void addNotify() {
  125.       super.addNotify();
  126.       this.installListeners();
  127.       this.addSystemMenuItems(this.windowMenu);
  128.       this.enableActions();
  129.    }
  130.  
  131.    public void removeNotify() {
  132.       super.removeNotify();
  133.       if (this.windowMenu != null) {
  134.          this.windowMenu.removeAll();
  135.       }
  136.  
  137.       this.uninstallDefaults();
  138.       this.uninstallListeners();
  139.    }
  140.  
  141.    protected void createButtons() {
  142.       this.iconButton = new NoFocusButton(this);
  143.       this.iconButton.addActionListener(this.iconifyAction);
  144.       this.maxButton = new NoFocusButton(this);
  145.       this.maxButton.addActionListener(this.maximizeAction);
  146.       this.closeButton = new NoFocusButton(this);
  147.       this.closeButton.addActionListener(this.closeAction);
  148.       this.setButtonIcons();
  149.    }
  150.  
  151.    protected void setButtonIcons() {
  152.       if (this.frame.isIcon()) {
  153.          this.iconButton.setIcon(this.minIcon);
  154.          this.maxButton.setIcon(this.maxIcon);
  155.       } else if (this.frame.isMaximum()) {
  156.          this.iconButton.setIcon(this.iconIcon);
  157.          this.maxButton.setIcon(this.minIcon);
  158.       } else {
  159.          this.iconButton.setIcon(this.iconIcon);
  160.          this.maxButton.setIcon(this.maxIcon);
  161.       }
  162.  
  163.       this.closeButton.setIcon(this.closeIcon);
  164.    }
  165.  
  166.    protected void assembleSystemMenu() {
  167.       this.menuBar = this.createSystemMenuBar();
  168.       this.windowMenu = this.createSystemMenu();
  169.       this.menuBar.add(this.windowMenu);
  170.       this.enableActions();
  171.    }
  172.  
  173.    protected void addSystemMenuItems(JMenu var1) {
  174.       JMenuItem var2 = var1.add(this.restoreAction);
  175.       ((AbstractButton)var2).setMnemonic('R');
  176.       var2 = var1.add(this.moveAction);
  177.       ((AbstractButton)var2).setMnemonic('M');
  178.       var2 = var1.add(this.sizeAction);
  179.       ((AbstractButton)var2).setMnemonic('S');
  180.       var2 = var1.add(this.iconifyAction);
  181.       ((AbstractButton)var2).setMnemonic('n');
  182.       var2 = var1.add(this.maximizeAction);
  183.       ((AbstractButton)var2).setMnemonic('x');
  184.       var1.add(new JSeparator());
  185.       var2 = var1.add(this.closeAction);
  186.       ((AbstractButton)var2).setMnemonic('C');
  187.    }
  188.  
  189.    protected JMenu createSystemMenu() {
  190.       return new JMenu("    ");
  191.    }
  192.  
  193.    protected JMenuBar createSystemMenuBar() {
  194.       this.menuBar = new SystemMenuBar(this);
  195.       this.menuBar.setBorderPainted(false);
  196.       return this.menuBar;
  197.    }
  198.  
  199.    protected void showSystemMenu() {
  200.       this.windowMenu.doClick();
  201.    }
  202.  
  203.    public void paintComponent(Graphics var1) {
  204.       boolean var2 = this.frame.isSelected();
  205.       if (var2) {
  206.          var1.setColor(this.selectedTitleColor);
  207.       } else {
  208.          var1.setColor(this.notSelectedTitleColor);
  209.       }
  210.  
  211.       var1.fillRect(0, 0, ((JComponent)this).getWidth(), ((JComponent)this).getHeight());
  212.       if (this.frame.getTitle() != null) {
  213.          Font var3 = var1.getFont();
  214.          var1.setFont(UIManager.getFont("InternalFrame.titleFont"));
  215.          if (var2) {
  216.             var1.setColor(this.selectedTextColor);
  217.          } else {
  218.             var1.setColor(this.notSelectedTextColor);
  219.          }
  220.  
  221.          FontMetrics var4 = var1.getFontMetrics();
  222.          int var5 = var4.getHeight() - var4.getLeading();
  223.          int var6 = (18 - var5) / 2 + var4.getAscent() + var4.getLeading();
  224.          String var8 = this.frame.getTitle();
  225.          int var7;
  226.          if (BasicGraphicsUtils.isLeftToRight(this.frame)) {
  227.             var7 = this.menuBar.getX() + this.menuBar.getWidth() + 2;
  228.          } else {
  229.             var7 = this.menuBar.getX() - 2 - SwingUtilities.computeStringWidth(var4, var8);
  230.          }
  231.  
  232.          var1.drawString(var8, var7, var6);
  233.          var1.setFont(var3);
  234.       }
  235.  
  236.    }
  237.  
  238.    protected void postClosingEvent(JInternalFrame var1) {
  239.       InternalFrameEvent var2 = new InternalFrameEvent(var1, 25550);
  240.       if ((class$javax$swing$JInternalFrame == null ? (class$javax$swing$JInternalFrame = class$("javax.swing.JInternalFrame")) : class$javax$swing$JInternalFrame).getClassLoader() == null) {
  241.          try {
  242.             Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(var2);
  243.             return;
  244.          } catch (SecurityException var4) {
  245.          }
  246.       }
  247.  
  248.       ((Component)var1).dispatchEvent(var2);
  249.    }
  250.  
  251.    protected void enableActions() {
  252.       this.restoreAction.setEnabled(this.frame.isMaximum() || this.frame.isIcon());
  253.       this.maximizeAction.setEnabled(this.frame.isMaximizable() && !this.frame.isMaximum());
  254.       this.iconifyAction.setEnabled(this.frame.isIconifiable() && !this.frame.isIcon());
  255.       this.closeAction.setEnabled(this.frame.isClosable());
  256.       this.sizeAction.setEnabled(false);
  257.       this.moveAction.setEnabled(false);
  258.    }
  259.  
  260.    protected PropertyChangeListener createPropertyChangeListener() {
  261.       return new PropertyChangeHandler(this);
  262.    }
  263.  
  264.    protected LayoutManager createLayout() {
  265.       return new TitlePaneLayout(this);
  266.    }
  267.  
  268.    // $FF: synthetic method
  269.    static Class class$(String var0) {
  270.       try {
  271.          return Class.forName(var0);
  272.       } catch (ClassNotFoundException var2) {
  273.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  274.       }
  275.    }
  276. }
  277.