KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > gui2 > DockLayout


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.gui2;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.event.ItemEvent JavaDoc;
24 import java.awt.event.ItemListener JavaDoc;
25 import java.awt.event.KeyEvent JavaDoc;
26 import java.io.ByteArrayInputStream JavaDoc;
27 import java.io.ByteArrayOutputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.ObjectInputStream JavaDoc;
30 import java.io.ObjectOutputStream JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.Map JavaDoc;
34
35 import javax.swing.JCheckBoxMenuItem JavaDoc;
36 import javax.swing.JMenu JavaDoc;
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 /**
52  * @author pugh
53  */

54 public class DockLayout implements FindBugsLayoutManager {
55     private static class DockParentListener extends DockingWindowAdapter
56     {
57         @Override JavaDoc
58         public void windowClosed(DockingWindow window)
59         {
60             // Notify all children's listeners
61
ArrayList JavaDoc<DockingWindow> children = new ArrayList JavaDoc<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 JavaDoc implements ItemListener JavaDoc
69     {
70         private View view;
71         
72         public ViewMenuItem(View view, String JavaDoc title)
73         {
74             super(title, true);
75             addItemListener(this);
76             this.view = view;
77 // view.addListener(new Listener());
78
}
79
80         // Menu item has been checked or unchecked
81
public void itemStateChanged(ItemEvent JavaDoc 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 // private class Listener extends DockingWindowAdapter
90
// {
91
// @Override
92
// public void windowAdded(DockingWindow addedToWindow, DockingWindow addedWindow)
93
// {
94
// if (addedWindow.equals(view))
95
// ViewMenuItem.this.setSelected(true);
96
// }
97
//
98
// @Override
99
// public void windowRemoved(DockingWindow removedFromWindow, DockingWindow removedWindow)
100
// {
101
// if (removedWindow.equals(view))
102
// ViewMenuItem.this.setSelected(false);
103
// }
104
// }
105
}
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 JavaDoc<View, ViewMenuItem> viewMenuItems = null;
115     /**
116      * @param frame
117      */

118     public DockLayout(MainFrame frame) {
119         this.frame = frame;
120     }
121     /* (non-Javadoc)
122      * @see edu.umd.cs.findbugs.gui2.LayoutManager#createWindowMenu()
123      */

124     public JMenu JavaDoc createWindowMenu() {
125         
126         viewMenuItems = new HashMap JavaDoc<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 JavaDoc windowMenu = new JMenu JavaDoc("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     /* (non-Javadoc)
140      * @see edu.umd.cs.findbugs.gui2.LayoutManager#initialize()
141      */

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 // tabs.getWindowProperties().setCloseEnabled(false);
160

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 JavaDoc(new ByteArrayInputStream JavaDoc(GUISaveState.getInstance().getDockingLayout())), true);
169         }
170         catch (IOException JavaDoc e) {}
171         
172         DockingWindowListener listener = new DockingWindowAdapter()
173         {
174             @Override JavaDoc
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 JavaDoc
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 JavaDoc());
194         frame.add(rootWindow, BorderLayout.CENTER);
195         frame.add(frame.statusBar(), BorderLayout.SOUTH);
196     }
197
198     /* (non-Javadoc)
199      * @see edu.umd.cs.findbugs.gui2.LayoutManager#makeCommentsVisible()
200      */

201     public void makeCommentsVisible() {
202         commentsView.makeVisible();
203         
204     }
205
206     /* (non-Javadoc)
207      * @see edu.umd.cs.findbugs.gui2.LayoutManager#makeSourceVisible()
208      */

209     public void makeSourceVisible() {
210         sourceView.makeVisible();
211         
212     }
213
214     /* (non-Javadoc)
215      * @see edu.umd.cs.findbugs.gui2.LayoutManager#saveState()
216      */

217     public void saveState() {
218         try
219         {
220             // FIXME this is writing the wrong array and I don't know why
221
ByteArrayOutputStream JavaDoc dockingLayout = new ByteArrayOutputStream JavaDoc();
222             ObjectOutputStream JavaDoc out = new ObjectOutputStream JavaDoc(dockingLayout);
223             rootWindow.write(out, true);
224             out.close();
225             GUISaveState.getInstance().setDockingLayout(dockingLayout.toByteArray());
226         }
227         catch (IOException JavaDoc e) {}
228         
229     }
230
231     /* (non-Javadoc)
232      * @see edu.umd.cs.findbugs.gui2.LayoutManager#setSourceTitle(java.lang.String)
233      */

234     public void setSourceTitle(final String JavaDoc title) {
235     sourceView.getWindowProperties().setTitleProvider(new DockingWindowTitleProvider(){
236         public String JavaDoc getTitle(DockingWindow arg0) {
237             return title;
238         }
239     });
240     }
241     
242     
243 }
244
Popular Tags