1 package org.columba.core.gui.globalactions; 2 3 import java.awt.event.ActionEvent ; 4 import java.util.Iterator ; 5 6 import javax.swing.AbstractAction ; 7 import javax.swing.JMenuItem ; 8 9 import org.columba.api.gui.frame.IDock; 10 import org.columba.api.gui.frame.IDockable; 11 import org.columba.api.gui.frame.IFrameMediator; 12 import org.columba.api.gui.frame.event.FrameEvent; 13 import org.columba.core.gui.frame.DefaultFrameController; 14 import org.columba.core.gui.frame.FrameMediatorAdapter; 15 import org.columba.core.gui.menu.IMenu; 16 import org.flexdock.docking.Dockable; 17 import org.flexdock.docking.DockingManager; 18 19 26 public class ShowHideViewSubmenu extends IMenu { 27 28 public ShowHideViewSubmenu(IFrameMediator controller) { 29 super(controller, "Show/Hide View", 30 ((DefaultFrameController) controller).getViewItem().get("id")); 31 32 controller.addListener(new MyListener()); 34 35 if ( getMenuComponentCount() == 0) setEnabled(false); 36 else setEnabled(true); 37 } 38 39 class DisplayAction extends AbstractAction { 40 String id; 41 42 DisplayAction(String id, String name) { 43 this.id = id; 44 45 putValue(AbstractAction.NAME, name); 46 } 47 48 public void actionPerformed(ActionEvent e) { 49 Dockable dockable = DockingManager.getDockable(id); 50 DockingManager.display(dockable); 51 } 52 } 53 54 57 public void actionPerformed(ActionEvent arg0) { 58 59 } 60 61 67 class MyListener extends FrameMediatorAdapter { 68 69 MyListener() { 70 71 } 72 73 76 @Override 77 public void switchedComponent(FrameEvent event) { 78 IFrameMediator mediator = getFrameMediator(); 79 80 if (mediator instanceof IDock) { 82 Iterator <IDockable> it = ((IDock) mediator) 83 .getDockableIterator(); 84 while (it.hasNext()) { 85 IDockable dockable = it.next(); 86 87 DisplayAction action = new DisplayAction(dockable.getId(), 88 dockable.resolveName()); 89 add(new JMenuItem (action)); 90 } 91 } 92 93 if ( getMenuComponentCount() == 0) setEnabled(false); 94 else setEnabled(true); 95 } 96 } 97 98 } 99 | Popular Tags |