1 package org.sape.carbon.services.console; 2 3 import java.awt.event.ActionEvent ; 4 import java.awt.event.ActionListener ; 5 import java.beans.PropertyVetoException ; 6 7 import javax.swing.JCheckBoxMenuItem ; 8 import javax.swing.JInternalFrame ; 9 import javax.swing.JMenu ; 10 import javax.swing.JMenuItem ; 11 import javax.swing.event.MenuEvent ; 12 import javax.swing.event.MenuListener ; 13 14 22 public class WindowMenu extends JMenu { 23 private MDIDesktopPane desktop; 24 25 private JMenuItem cascade=new JMenuItem ("Cascade"); 26 private JMenuItem tile=new JMenuItem ("Tile"); 27 28 public WindowMenu(MDIDesktopPane desktop) { 29 this.desktop=desktop; 30 setText("Window"); 31 cascade.addActionListener(new ActionListener () { 32 public void actionPerformed(ActionEvent ae) { 33 WindowMenu.this.desktop.cascadeFrames(); 34 } 35 }); 36 tile.addActionListener(new ActionListener () { 37 public void actionPerformed(ActionEvent ae) { 38 WindowMenu.this.desktop.tileFrames(); 39 } 40 }); 41 addMenuListener(new MenuListener () { 42 public void menuCanceled (MenuEvent e) {} 43 44 public void menuDeselected (MenuEvent e) { 45 removeAll(); 46 } 47 48 public void menuSelected (MenuEvent e) { 49 buildChildMenus(); 50 } 51 }); 52 } 53 54 55 private void buildChildMenus() { 56 int i; 57 ChildMenuItem menu; 58 JInternalFrame [] array = desktop.getAllFrames(); 59 60 add(cascade); 61 add(tile); 62 if (array.length > 0) addSeparator(); 63 cascade.setEnabled(array.length > 0); 64 tile.setEnabled(array.length > 0); 65 66 for (i = 0; i < array.length; i++) { 67 menu = new ChildMenuItem(array[i]); 68 menu.setState(i == 0); 69 menu.addActionListener(new ActionListener () { 70 public void actionPerformed(ActionEvent ae) { 71 JInternalFrame frame = ((ChildMenuItem)ae.getSource()).getFrame(); 72 frame.moveToFront(); 73 try { 74 frame.setSelected(true); 75 } catch (PropertyVetoException e) { 76 e.printStackTrace(); 77 } 78 } 79 }); 80 menu.setIcon(array[i].getFrameIcon()); 81 add(menu); 82 } 83 } 84 85 87 class ChildMenuItem extends JCheckBoxMenuItem { 88 private JInternalFrame frame; 89 90 public ChildMenuItem(JInternalFrame frame) { 91 super(frame.getTitle()); 92 this.frame=frame; 93 } 94 95 public JInternalFrame getFrame() { 96 return frame; 97 } 98 } 99 } 100 | Popular Tags |