| 1 19 20 package edu.umd.cs.findbugs.gui2; 21 22 import java.awt.BorderLayout ; 23 import java.awt.event.ItemEvent ; 24 import java.awt.event.ItemListener ; 25 import java.awt.event.KeyEvent ; 26 import java.io.ByteArrayInputStream ; 27 import java.io.ByteArrayOutputStream ; 28 import java.io.IOException ; 29 import java.io.ObjectInputStream ; 30 import java.io.ObjectOutputStream ; 31 import java.util.ArrayList ; 32 import java.util.HashMap ; 33 import java.util.Map ; 34 35 import javax.swing.JCheckBoxMenuItem ; 36 import javax.swing.JMenu ; 37 38 import net.infonode.docking.DockingWindow; 39 import net.infonode.docking.DockingWindowAdapter; 40 import net.infonode.docking.DockingWindowListener; 41 import net.infonode.docking.RootWindow; 42 import net.infonode.docking.SplitWindow; 43 import net.infonode.docking.TabWindow; 44 import net.infonode.docking.View; 45 import net.infonode.docking.theme.DockingWindowsTheme; 46 import net.infonode.docking.theme.ShapedGradientDockingTheme; 47 import net.infonode.docking.title.DockingWindowTitleProvider; 48 import net.infonode.docking.util.DockingUtil; 49 import net.infonode.docking.util.ViewMap; 50 51 54 public class DockLayout implements FindBugsLayoutManager { 55 private static class DockParentListener extends DockingWindowAdapter 56 { 57 @Override  58 public void windowClosed(DockingWindow window) 59 { 60 ArrayList <DockingWindow> children = new ArrayList <DockingWindow>(); 62 for (int i = 0; i < window.getChildWindowCount(); i++) 63 children.add(window.getChildWindow(i)); 64 for (DockingWindow i : children) 65 i.close(); 66 } 67 } 68 private class ViewMenuItem extends JCheckBoxMenuItem implements ItemListener  69 { 70 private View view; 71 72 public ViewMenuItem(View view, String title) 73 { 74 super(title, true); 75 addItemListener(this); 76 this.view = view; 77 } 79 80 public void itemStateChanged(ItemEvent evt) 82 { 83 if (evt.getStateChange() == ItemEvent.SELECTED) 84 DockingUtil.addWindow(view, rootWindow); 85 if (evt.getStateChange() == ItemEvent.DESELECTED) 86 view.close(); 87 } 88 89 } 106 private View commentsView = null; 107 final MainFrame frame; 108 private RootWindow rootWindow; 109 private View sourceView = null; 110 private View summaryView = null; 111 private TabWindow tabs = null; 112 113 private View topView = null; 114 private Map <View, ViewMenuItem> viewMenuItems = null; 115 118 public DockLayout(MainFrame frame) { 119 this.frame = frame; 120 } 121 124 public JMenu createWindowMenu() { 125 126 viewMenuItems = new HashMap <View, ViewMenuItem>(); 127 viewMenuItems.put(summaryView, new ViewMenuItem(summaryView, "Bug summary")); 128 viewMenuItems.put(commentsView, new ViewMenuItem(commentsView, "Comments")); 129 viewMenuItems.put(sourceView, new ViewMenuItem(sourceView, "Source code")); 130 131 JMenu windowMenu = new JMenu ("Window"); 132 windowMenu.setMnemonic(KeyEvent.VK_W); 133 windowMenu.add(viewMenuItems.get(summaryView)); 134 windowMenu.add(viewMenuItems.get(commentsView)); 135 windowMenu.add(viewMenuItems.get(sourceView)); 136 return windowMenu; 137 } 138 139 142 public void initialize() { 143 ViewMap viewMap = new ViewMap(); 144 topView = new View(L10N.getLocalString("view.bugs", "Bugs"), null, frame.bugListPanel()); 145 topView.getWindowProperties().setCloseEnabled(false); 146 viewMap.addView(0, topView); 147 summaryView = new View(L10N.getLocalString("view.bug_summary", "Bug Summary"), null, frame.summaryTab()); 148 viewMap.addView(1, summaryView); 149 commentsView = new View(L10N.getLocalString("view.comments", "Comments"), null, frame.commentsPanel()); 150 viewMap.addView(2, commentsView); 151 sourceView = new View(L10N.getLocalString("view.source", "Source"), null, frame.createSourceCodePanel()); 152 viewMap.addView(3, sourceView); 153 154 rootWindow = DockingUtil.createRootWindow(viewMap, true); 155 156 tabs = new TabWindow(new DockingWindow[]{summaryView, commentsView, sourceView}); 157 tabs.addListener(new DockParentListener()); 158 tabs.setSelectedTab(0); 159 161 rootWindow.setWindow(new SplitWindow(false, 0.4f, topView, tabs)); 162 163 DockingWindowsTheme theme = new ShapedGradientDockingTheme(); 164 rootWindow.getRootWindowProperties().addSuperObject(theme.getRootWindowProperties()); 165 166 try 167 { 168 rootWindow.read(new ObjectInputStream (new ByteArrayInputStream (GUISaveState.getInstance().getDockingLayout())), true); 169 } 170 catch (IOException e) {} 171 172 DockingWindowListener listener = new DockingWindowAdapter() 173 { 174 @Override  175 public void windowAdded(DockingWindow addedToWindow, DockingWindow addedWindow) 176 { 177 viewMenuItems.get(addedWindow).setSelected(true); 178 179 addedToWindow.addListener(new DockParentListener()); 180 } 181 182 @Override  183 public void windowClosed(DockingWindow window) 184 { 185 viewMenuItems.get(window).setSelected(false); 186 } 187 }; 188 189 summaryView.addListener(listener); 190 commentsView.addListener(listener); 191 sourceView.addListener(listener); 192 193 frame.setLayout(new BorderLayout ()); 194 frame.add(rootWindow, BorderLayout.CENTER); 195 frame.add(frame.statusBar(), BorderLayout.SOUTH); 196 } 197 198 201 public void makeCommentsVisible() { 202 commentsView.makeVisible(); 203 204 } 205 206 209 public void makeSourceVisible() { 210 sourceView.makeVisible(); 211 212 } 213 214 217 public void saveState() { 218 try 219 { 220 ByteArrayOutputStream dockingLayout = new ByteArrayOutputStream (); 222 ObjectOutputStream out = new ObjectOutputStream (dockingLayout); 223 rootWindow.write(out, true); 224 out.close(); 225 GUISaveState.getInstance().setDockingLayout(dockingLayout.toByteArray()); 226 } 227 catch (IOException e) {} 228 229 } 230 231 234 public void setSourceTitle(final String title) { 235 sourceView.getWindowProperties().setTitleProvider(new DockingWindowTitleProvider(){ 236 public String getTitle(DockingWindow arg0) { 237 return title; 238 } 239 }); 240 } 241 242 243 } 244 | Popular Tags |