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