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 12 public class WindowMenu extends ConfigurableMenu { 13 14 int originalMenuCount; 15 MessagePanel messagePanel = null; 16 17 public WindowMenu() { 18 super(); 19 } 20 21 27 28 public void configureComponent(String 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 41 42 public void setActive(java.util.Hashtable newCommands) { 43 refreshWindows(); 44 } 45 46 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 pve) { 76 } catch (NumberFormatException nfe) { 77 } 78 } 79 } 80 } 81 82 83 } 84 | Popular Tags |