File Source: DMDircDesktopPane.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.components.desktopPane.DMDircDesktopPane$1__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.addons.ui_swing.components.desktopPane;
24
25 import com.dmdirc.FrameContainer;
26 import com.dmdirc.addons.ui_swing.MainFrame;
27 import com.dmdirc.interfaces.SelectionListener;
28 import com.dmdirc.logger.ErrorLevel;
29 import com.dmdirc.logger.Logger;
30 import com.dmdirc.ui.WindowManager;
31 import com.dmdirc.ui.interfaces.FrameManager;
32 import com.dmdirc.ui.interfaces.Window;
33 import com.dmdirc.addons.ui_swing.UIUtilities;
34 import com.dmdirc.addons.ui_swing.components.TreeScroller;
35 import com.dmdirc.addons.ui_swing.components.frames.InputTextFrame;
36 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
37 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewModel;
38 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewNode;
39 import com.dmdirc.util.ReturnableThread;
40
41 import java.awt.Color;
42 import java.beans.PropertyChangeEvent;
43 import java.beans.PropertyChangeListener;
44 import java.util.Arrays;
45 import java.util.HashMap;
46 import java.util.Map;
47 import java.util.Stack;
48 import java.util.concurrent.atomic.AtomicBoolean;
49
50 import javax.swing.BorderFactory;
51 import javax.swing.JComponent;
52 import javax.swing.JDesktopPane;
53 import javax.swing.JInternalFrame;
54 import javax.swing.plaf.DesktopPaneUI;
55 import javax.swing.tree.DefaultTreeSelectionModel;
56 import javax.swing.tree.TreeNode;
57 import javax.swing.tree.TreePath;
58 import javax.swing.tree.TreeSelectionModel;
59
60 /**
61 * DMDirc Extentions to JDesktopPane.
62 */
/*
P/P * Method: TreeSelectionModel access$700(DMDircDesktopPane)
*
* Preconditions:
* x0 != null
*
* Postconditions:
* return_value == x0.selectionModel
* init'ed(return_value)
*/
63 public class DMDircDesktopPane extends JDesktopPane implements FrameManager,
64 SelectionListener, PropertyChangeListener {
65
66 /** Logger to use. */
/*
P/P * Method: com.dmdirc.addons.ui_swing.components.desktopPane.DMDircDesktopPane__static_init
*
* Postconditions:
* init'ed(LOGGER)
*/
67 private static final java.util.logging.Logger LOGGER =
68 java.util.logging.Logger.getLogger(DMDircDesktopPane.class.getName());
69 /**
70 * A version number for this class. It should be changed whenever the class
71 * structure is changed (or anything else that would prevent serialized
72 * objects being unserialized with the new class).
73 */
74 private static final long serialVersionUID = 1;
75 /** The current number of pixels to displace new frames in the X
76 * direction. */
77 private int xOffset;
78 /** The current number of pixels to displace new frames in the Y
79 * direction. */
80 private int yOffset;
81 /** The number of pixels each new internal frame is offset by. */
82 private static final int FRAME_OPENING_OFFSET = 30;
83 /** Node storage, used for adding and deleting nodes correctly. */
84 private final Map<FrameContainer, TreeViewNode> nodes;
85 /** Data model. */
86 private final TreeViewModel model;
87 /** Selected model. */
88 private final TreeSelectionModel selectionModel;
89 /** Tree Scroller. */
90 private final TreeScroller treeScroller;
91 /** Selected window. */
92 private Window selectedWindow;
93 /** Maximised state. */
94 private boolean maximised;
95 /** Changing maximisation. */
96 private AtomicBoolean changing = new AtomicBoolean(false);
97 /** Main Frame. */
98 private MainFrame mainFrame;
99
100 /**
101 * Initialises the DMDirc desktop pane.
102 *
103 * @param mainFrame Main frame
104 */
105 public DMDircDesktopPane(final MainFrame mainFrame) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.desktopPane.DMDircDesktopPane(MainFrame)
*
* Postconditions:
* this.changing == &new AtomicBoolean(DMDircDesktopPane#1)
* this.mainFrame == mainFrame
* init'ed(this.mainFrame)
* this.model == &new TreeViewModel(DMDircDesktopPane#5)
* this.treeScroller.model == &new TreeViewModel(DMDircDesktopPane#5)
* this.nodes == &new HashMap(DMDircDesktopPane#4)
* this.selectionModel == &new DefaultTreeSelectionModel(DMDircDesktopPane#7)
* this.treeScroller.selectionModel == &new DefaultTreeSelectionModel(DMDircDesktopPane#7)
* this.treeScroller == &new DMDircDesktopPane$1(DMDircDesktopPane#8)
* new AtomicBoolean(DMDircDesktopPane#1) num objects == 1
* ...
*/
106 super();
107
108 this.mainFrame = mainFrame;
109 setBackground(new Color(238, 238, 238));
110 setBorder(BorderFactory.createEtchedBorder());
111 setUI(new ProxyDesktopPaneUI(getUI(), this));
112
113 nodes = new HashMap<FrameContainer, TreeViewNode>();
114 model = new TreeViewModel(new TreeViewNode(null, null));
115 selectionModel = new DefaultTreeSelectionModel();
/*
P/P * Method: void com.dmdirc.addons.ui_swing.components.desktopPane.DMDircDesktopPane$1(DMDircDesktopPane, DefaultTreeModel, TreeSelectionModel, bool)
*
* Preconditions:
* x0 != null
*
* Postconditions:
* this.model == x0
* this.model != null
* init'ed(this.rootNode)
* this.rootVisible == x2
* init'ed(this.rootVisible)
* this.selectionModel == x1
* init'ed(this.selectionModel)
*/
116 treeScroller = new TreeScroller(model, selectionModel, false) {
117
118 /** {@inheritDoc} */
119 @Override
120 protected void setPath(final TreePath path) {
/*
P/P * Method: void setPath(TreePath)
*
* Preconditions:
* path != null
* this.selectionModel != null
*
* Presumptions:
* com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewNode:getFrameContainer(...)@122 != null
* javax.swing.tree.TreePath:getLastPathComponent(...)@122 != null
*/
121 super.setPath(path);
122 ((TreeViewNode) path.getLastPathComponent()).getFrameContainer().
123 activateFrame();
124 }
125 };
126
127 WindowManager.addFrameManager(this);
128 }
129
130 /** {@inheritDoc} */
131 @Override
132 public void setUI(final DesktopPaneUI ui) {
/*
P/P * Method: void setUI(DesktopPaneUI)
*/
133 if (ui instanceof ProxyDesktopPaneUI) {
134 super.setUI(ui);
135 } else {
136 super.setUI(new ProxyDesktopPaneUI(ui, this));
137 }
138 }
139
140 /**
141 * Add a specified component at the specified index.
142 *
143 * @param comp Component to add
144 * @param index Index for insertion
145 */
146 public void add(final JComponent comp, final int index) {
/*
P/P * Method: void add(JComponent, int)
*/
147 UIUtilities.invokeLater(new Runnable() {
148
149 /** {@inheritDoc} */
150 @Override
151 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* this.val$comp != null
* (soft) this.xOffset <= 4_294_967_265
* (soft) this.yOffset <= 4_294_967_265
*
* Postconditions:
* this.xOffset == One-of{old this.xOffset, 0} + 30
* this.yOffset == One-of{old this.yOffset, 0} + 30
*/
152 addImpl(comp, null, index);
153
154 // Make sure it'll fit with our offsets
155 if (comp.getWidth() + xOffset > getWidth()) {
156 xOffset = 0;
157 }
158 if (comp.getHeight() + yOffset > getHeight()) {
159 yOffset = 0;
160 }
161
162 // Position the frame
163 comp.setLocation(xOffset, yOffset);
164
165 // Increase the offsets
166 xOffset += FRAME_OPENING_OFFSET;
167 yOffset += FRAME_OPENING_OFFSET;
168 }
169 });
170 }
171
172 /**
173 * Returns the select window.
174 *
175 * @return Selected window, or null.
176 */
177 public Window getSelectedWindow() {
/*
P/P * Method: Window getSelectedWindow()
*
* Postconditions:
* init'ed(return_value)
*/
178 return UIUtilities.invokeAndWait(new ReturnableThread<Window>() {
179
180 /** {@inheritDoc} */
181 @Override
182 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* init'ed(this.selectedWindow)
*/
183 setObject(selectedWindow);
184 }
185 });
186 }
187
188 /** {@inheritDoc} */
189 @Override
190 public void setParent(final JComponent parent) {
191 //Ignore
/*
P/P * Method: void setParent(JComponent)
*/
192 }
193
194 /** {@inheritDoc} */
195 @Override
196 public boolean canPositionVertically() {
/*
P/P * Method: bool canPositionVertically()
*
* Postconditions:
* return_value == 1
*/
197 return true;
198 }
199
200 /** {@inheritDoc} */
201 @Override
202 public boolean canPositionHorizontally() {
/*
P/P * Method: bool canPositionHorizontally()
*
* Postconditions:
* return_value == 1
*/
203 return true;
204 }
205
206 /** {@inheritDoc} */
207 @Override
208 public void addWindow(final FrameContainer window) {
/*
P/P * Method: void addWindow(FrameContainer)
*
* Preconditions:
* this.model != null
*/
209 addWindow(model.getRootNode(), window);
210 }
211
212 @Override
213 public void addWindow(final FrameContainer parent,
214 final FrameContainer window) {
/*
P/P * Method: void addWindow(FrameContainer, FrameContainer)
*/
215 UIUtilities.invokeAndWait(new Runnable() {
216
217 /** {@inheritDoc} */
218 @Override
219 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* this.nodes != null
*/
220 synchronized (nodes) {
221 addWindow(nodes.get(parent), window);
222 }
223 }
224 });
225 }
226
227 /** {@inheritDoc} */
228 @Override
229 public void delWindow(final FrameContainer parent,
230 final FrameContainer window) {
/*
P/P * Method: void delWindow(FrameContainer, FrameContainer)
*/
231 delWindow(window);
232 }
233
234 /** {@inheritDoc} */
235 @Override
236 public void delWindow(final FrameContainer window) {
/*
P/P * Method: void delWindow(FrameContainer)
*/
237 UIUtilities.invokeAndWait(new Runnable() {
238
239 /** {@inheritDoc} */
240 @Override
241 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* (soft) this.mainFrame != null
* (soft) init'ed(this.mainFrame.showVersion)
* (soft) this.model != null
* (soft) this.val$window != null
*
* Presumptions:
* com.dmdirc.FrameContainer:getFrame(...)@256 != null
* com.dmdirc.addons.ui_swing.components.desktopPane.DMDircDesktopPane:getAllFrames(...)@258 != null
* init'ed(com.dmdirc.logger.ErrorLevel.MEDIUM)
* java.util.Map:get(...)@245 != null
*
* Test Vectors:
* this.nodes: Addr_Set{null}, Inverse{null}
* com.dmdirc.addons.ui_swing.components.desktopPane.DMDircDesktopPane:getAllFrames(...).length@258: {1..+Inf}, {0}
* com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewNode:getLevel(...)@246: {-231..-1, 1..232-1}, {0}
* java.util.Map:get(...)@242: Inverse{null}, Addr_Set{null}
*/
242 if (nodes == null || nodes.get(window) == null) {
243 return;
244 }
245 final TreeViewNode node = nodes.get(window);
246 if (node.getLevel() == 0) {
247 Logger.appError(ErrorLevel.MEDIUM,
248 "delServer triggered for root node" +
249 node.toString(),
250 new IllegalArgumentException());
251 } else {
252 model.removeNodeFromParent(nodes.get(window));
253 }
254 nodes.remove(window);
255 window.removeSelectionListener(DMDircDesktopPane.this);
256 ((TextFrame) window.getFrame()).removePropertyChangeListener(
257 DMDircDesktopPane.this);
258 if (getAllFrames().length == 0) {
259 mainFrame.setTitle(null);
260 }
261 }
262 });
263 }
264
265 /**
266 * Adds a window to the frame container.
267 *
268 * @param parent Parent node
269 * @param window Window to add
270 */
271 public void addWindow(final TreeViewNode parent,
272 final FrameContainer window) {
/*
P/P * Method: void addWindow(TreeViewNode, FrameContainer)
*/
273 UIUtilities.invokeAndWait(new Runnable() {
274
275 /** {@inheritDoc} */
276 @Override
277 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* this.model != null
* this.nodes != null
* this.val$window != null
*
* Presumptions:
* com.dmdirc.FrameContainer:getFrame(...)@285 != null
*/
278 final TreeViewNode node = new TreeViewNode(null, window);
279 synchronized (nodes) {
280 nodes.put(window, node);
281 }
282 node.setUserObject(window);
283 model.insertNodeInto(node, parent);
284 window.addSelectionListener(DMDircDesktopPane.this);
285 ((TextFrame) window.getFrame()).addPropertyChangeListener(
286 DMDircDesktopPane.this);
287 }
288 });
289 }
290
291 /** Scrolls up. */
292 public void scrollUp() {
/*
P/P * Method: void scrollUp()
*
* Preconditions:
* this.treeScroller != null
* (soft) this.treeScroller.model != null
* (soft) this.treeScroller.selectionModel != null
*/
293 treeScroller.changeFocus(true);
294 }
295
296 /** Scrolls down. */
297 public void scrollDown() {
/*
P/P * Method: void scrollDown()
*
* Preconditions:
* this.treeScroller != null
* (soft) this.treeScroller.model != null
* (soft) this.treeScroller.selectionModel != null
*/
298 treeScroller.changeFocus(false);
299 }
300
301 /** {@inheritDoc} */
302 @Override
303 public void selectionChanged(final Window window) {
/*
P/P * Method: void selectionChanged(Window)
*/
304 UIUtilities.invokeLater(new Runnable() {
305
306 /** {@inheritDoc} */
307 @Override
308 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* this.mainFrame != null
* init'ed(this.mainFrame.showVersion)
* this.model != null
* this.nodes != null
* this.val$window != null
* (soft) this.selectionModel != null
* (soft) init'ed(this.val$window.inputField)
*
* Postconditions:
* this.selectedWindow == this.val$window
*
* Test Vectors:
* com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewModel:getPathToRoot(...)@310: Addr_Set{null}, Inverse{null}
* path.length@310: {0}, {1..+Inf}
*/
309 selectedWindow = window;
310 final TreeNode[] path =
311 model.getPathToRoot(nodes.get(window.getContainer()));
312 if (path != null && path.length > 0) {
313 selectionModel.setSelectionPath(new TreePath(path));
314 }
315 if (window instanceof InputTextFrame) {
316 ((InputTextFrame) window).requestInputFieldFocus();
317 }
318 mainFrame.setTitle(window.getTitle());
319 }
320 });
321 }
322
323 /** {@inheritDoc} */
324 @Override
325 public void propertyChange(final PropertyChangeEvent evt) {
/*
P/P * Method: void propertyChange(PropertyChangeEvent)
*
* Preconditions:
* evt != null
* (soft) init'ed(this.maximised)
* (soft) this.changing != null
* (soft) this.mainFrame != null
* (soft) init'ed(this.mainFrame.showVersion)
* (soft) init'ed(this.selectedWindow)
*
* Presumptions:
* java.beans.PropertyChangeEvent:getNewValue(...)@330 != null
* java.beans.PropertyChangeEvent:getSource(...)@327 != null
* java.beans.PropertyChangeEvent:getSource(...)@330 != null
*
* Postconditions:
* init'ed(this.maximised)
*
* Test Vectors:
* java.lang.String:equals(...)@326: {0}, {1}
* java.lang.String:equals(...)@329: {0}, {1}
*/
326 if ("title".equals(evt.getPropertyName())) {
327 handleTitleEvent((Window) evt.getSource(),
328 ((Window) evt.getSource()).getTitle());
329 } else if ("maximum".equals(evt.getPropertyName())) {
330 handleMaximiseEvent((Boolean) evt.getNewValue(),
331 ((Window) evt.getSource()).getTitle());
332 }
333 }
334
335 private void handleTitleEvent(final Window window, final String title) {
/*
P/P * Method: void handleTitleEvent(Window, String)
*
* Preconditions:
* init'ed(this.maximised)
* (soft) this.mainFrame != null
* (soft) init'ed(this.mainFrame.showVersion)
* (soft) init'ed(this.selectedWindow)
*
* Test Vectors:
* this.maximised: {0}, {1}
* window == this.selectedWindow: {0}, {1}
*/
336 if (maximised && (window == selectedWindow)) {
337 mainFrame.setTitle(title);
338 } else if (!maximised) {
339 mainFrame.setTitle(null);
340 }
341 }
342
343 private void handleMaximiseEvent(final boolean isMaximised,
344 final String title) {
/*
P/P * Method: void handleMaximiseEvent(bool, String)
*
* Preconditions:
* this.changing != null
* (soft) this.mainFrame != null
* (soft) init'ed(this.mainFrame.showVersion)
* (soft) init'ed(this.selectedWindow)
*
* Presumptions:
* java.util.Stack:pop(...)@355 != null
*
* Postconditions:
* possibly_updated(this.maximised)
*
* Test Vectors:
* isMaximised: {0}, {1}
* this.selectedWindow: Addr_Set{null}, Inverse{null}
* java.util.Stack:empty(...)@354: {1}, {0}
* java.util.concurrent.atomic.AtomicBoolean:get(...)@345: {0}, {1}
* javax.swing.JInternalFrame:isMaximum(...)@357: {1}, {0}
* javax.swing.JInternalFrame:isMaximum(...)@361: {0}, {1}
*/
345 if (changing.get()) {
346 return;
347 }
348 changing.set(true);
349 maximised = isMaximised;
350 if (!UIUtilities.isWindowsUI()) {
351 Stack<JInternalFrame> stack = new Stack<JInternalFrame>();
352 stack.addAll(Arrays.asList(getAllFrames()));
353
354 while (!stack.empty()) {
355 JInternalFrame frame = stack.pop();
356 if (isMaximised) {
357 if (!frame.isMaximum()) {
358 ((Window) frame).maximise();
359 }
360 } else {
361 if (frame.isMaximum()) {
362 ((Window) frame).restore();
363 }
364 }
365 }
366 if (selectedWindow != null) {
367 selectedWindow.activateFrame();
368 }
369 }
370 if (!isMaximised) {
371 mainFrame.setTitle(title);
372 } else {
373 mainFrame.setTitle(null);
374 }
375 changing.set(false);
376 }
377 }
SofCheck Inspector Build Version : 2.17854
| DMDircDesktopPane.java |
2009-Jun-25 01:54:24 |
| DMDircDesktopPane.class |
2009-Sep-02 17:04:17 |
| DMDircDesktopPane$1.class |
2009-Sep-02 17:04:17 |
| DMDircDesktopPane$2.class |
2009-Sep-02 17:04:17 |
| DMDircDesktopPane$3.class |
2009-Sep-02 17:04:17 |
| DMDircDesktopPane$4.class |
2009-Sep-02 17:04:17 |
| DMDircDesktopPane$5.class |
2009-Sep-02 17:04:17 |
| DMDircDesktopPane$6.class |
2009-Sep-02 17:04:17 |
| DMDircDesktopPane$7.class |
2009-Sep-02 17:04:17 |