KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > WindowMenu


1 package net.suberic.pooka.gui;
2 import net.suberic.util.gui.*;
3 import net.suberic.pooka.Pooka;
4 import javax.swing.*;
5 import java.awt.event.*;
6 import net.suberic.util.*;
7
8 /**
9  * This is a specialized Menu which shows the currently open windows in
10  * the FolderPanel.
11  */

12 public class WindowMenu extends ConfigurableMenu {
13
14     int originalMenuCount;
15     MessagePanel messagePanel = null;
16     
17     public WindowMenu() {
18     super();
19     }
20
21     /**
22      * Overrides ConfigurableMenu.configureComponent().
23      *
24      * Actually just calls ConfigurableMenu.configureComponent() and then
25      * sets that number of menuItems as the original values.
26      */

27
28     public void configureComponent(String JavaDoc key, VariableBundle vars) {
29     super.configureComponent(key, vars);
30     
31     originalMenuCount = this.getMenuComponentCount();
32     if (Pooka.getMainPanel().getContentPanel() instanceof MessagePanel)
33         messagePanel = (MessagePanel) Pooka.getMainPanel().getContentPanel();
34     }
35
36     /**
37      * Overrides ConfigurableMenu.setActive(Hashtable);
38      *
39      * calls refreshWindows().
40      */

41
42     public void setActive(java.util.Hashtable JavaDoc newCommands) {
43     refreshWindows();
44     }
45
46     /**
47      * This method actually does all of the interesting work for this
48      * component.
49      */

50     public void refreshWindows() {
51     if (messagePanel != null) {
52         for (int k = this.getMenuComponentCount(); k > originalMenuCount; k--)
53         this.remove(k-1);
54         
55         JInternalFrame[] allFrames = messagePanel.getAllFrames();
56         for(int j = 0; j < allFrames.length; j++) {
57         JMenuItem mi = new JMenuItem(allFrames[j].getTitle());
58         mi.addActionListener(new ActivateWindowAction());
59         mi.setActionCommand(String.valueOf(messagePanel.getIndexOf(allFrames[j])));
60         this.add(mi);
61         }
62     }
63     }
64
65     class ActivateWindowAction extends AbstractAction {
66     
67     ActivateWindowAction() {
68         super("activate-window");
69     }
70
71         public void actionPerformed(ActionEvent e) {
72         if (messagePanel != null) {
73         try {
74             ((JInternalFrame)(messagePanel.getComponent(Integer.parseInt(e.getActionCommand())))).setSelected(true);
75         } catch (java.beans.PropertyVetoException JavaDoc pve) {
76         } catch (NumberFormatException JavaDoc nfe) {
77         }
78         }
79     }
80     }
81     
82
83 }
84
Popular Tags