KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > view > DefaultView


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.windows.view;
21
22
23 import java.awt.Dimension JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.logging.Logger JavaDoc;
26
27 import javax.swing.*;
28 import java.awt.*;
29 import java.util.Arrays JavaDoc;
30 import java.util.HashSet JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Set JavaDoc;
33 import javax.swing.SwingUtilities JavaDoc;
34
35 import org.openide.awt.ToolbarPool; // Why is this in open API?
36
import org.openide.util.WeakSet;
37 import org.openide.windows.TopComponent;
38
39 import org.netbeans.core.windows.Constants;
40 import org.netbeans.core.windows.Debug;
41 import org.netbeans.core.windows.ModeImpl;
42 import org.netbeans.core.windows.model.ModelElement;
43 import org.netbeans.core.windows.view.dnd.WindowDnDManager;
44 import org.netbeans.core.windows.WindowManagerImpl;
45 import org.netbeans.core.windows.WindowSystemSnapshot;
46 import org.netbeans.core.windows.view.ui.slides.SlideOperation;
47
48 /**
49  * Class which handles view requests, i.e. updates GUI accordingly (ViewHierarchy)
50  * and also handles changes to GUI made by user, informs controller handler.
51  *
52  * @author Peter Zavadsky
53  */

54 class DefaultView implements View, Controller, WindowDnDManager.ViewAccessor {
55     
56     
57     private final ViewHierarchy hierarchy = new ViewHierarchy(this, new WindowDnDManager(this));
58     
59     private final ControllerHandler controllerHandler;
60     
61     private final Set JavaDoc<TopComponent> showingTopComponents = new WeakSet<TopComponent>(10);
62
63     /** Debugging flag. */
64     private static final boolean DEBUG = Debug.isLoggable(DefaultView.class);
65     
66     public DefaultView(ControllerHandler controllerHandler) {
67         this.controllerHandler = controllerHandler;
68     }
69     
70
71     // XXX
72
public boolean isDragInProgress() {
73         return hierarchy.isDragInProgress();
74     }
75     
76     // XXX
77
public Frame getMainWindow() {
78         return hierarchy.getMainWindow();
79     }
80     
81     public Component getEditorAreaComponent() {
82         return hierarchy.getEditorAreaComponent();
83     }
84     
85     public String JavaDoc guessSlideSide (TopComponent comp) {
86         String JavaDoc toReturn = Constants.LEFT;
87         if (hierarchy.getMaximizedModeView() != null) {
88             //issue #58562
89
toReturn = (String JavaDoc)comp.getClientProperty("lastSlideSide");
90             if (toReturn == null) {
91                 //TODO? now how does one figure on startup with maximazed mode where the editor is?
92
toReturn = Constants.LEFT;
93             }
94         } else {
95             Rectangle editorb = hierarchy.getPureEditorAreaBounds();
96             Point leftTop = new Point(0, 0);
97             SwingUtilities.convertPointToScreen(leftTop, comp);
98             if (editorb.x > leftTop.x) {
99                 toReturn = Constants.LEFT;
100             }
101             if ((editorb.x + editorb.width) < leftTop.x) {
102                 toReturn = Constants.RIGHT;
103             }
104             if ((editorb.y + editorb.height) < leftTop.y) {
105                 toReturn = Constants.BOTTOM;
106             }
107             comp.putClientProperty("lastSlideSide", toReturn);
108         }
109         return toReturn;
110     }
111     
112     public void changeGUI(ViewEvent[] viewEvents, WindowSystemSnapshot snapshot) {
113
114         // Change to view understandable-convenient structure.
115
WindowSystemAccessor wsa = ViewHelper.createWindowSystemAccessor(snapshot);
116         
117         if(DEBUG) {
118             debugLog("CHANGEGUI()"); // NOI18N
119
debugLog("Structure=" + wsa); // NOI18N
120
debugLog(""); // NOI18N
121
}
122
123         // Update view hierarchy from accessors info
124
if(wsa != null) { // wsa == null during hiding.
125
hierarchy.updateViewHierarchy(wsa.getModeStructureAccessor());
126         }
127
128         // Update showing TopComponents.
129
Set JavaDoc<TopComponent> oldShowing = new HashSet JavaDoc<TopComponent>(showingTopComponents);
130         Set JavaDoc<TopComponent> newShowing = hierarchy.getShowingTopComponents();
131         showingTopComponents.clear();
132         showingTopComponents.addAll(newShowing);
133         
134         Set JavaDoc<TopComponent> toShow = new HashSet JavaDoc<TopComponent>(newShowing);
135         toShow.removeAll(oldShowing);
136         for(TopComponent tc: toShow) {
137             WindowManagerImpl.getInstance().componentShowing(tc);
138         }
139         if(DEBUG) {
140             debugLog("ChangeGUI: Checking view events...") ; // NOI18N
141
}
142         
143         // PENDING Find main event first.
144
for(int i = 0; i < viewEvents.length; i++) {
145             ViewEvent viewEvent = viewEvents[i];
146             int changeType = viewEvent.getType();
147             if(DEBUG) {
148                 debugLog("ViewEvent=" + viewEvent) ; // NOI18N
149
}
150             
151             if(changeType == CHANGE_VISIBILITY_CHANGED) {
152                 if(DEBUG) {
153                     debugLog("Winsys visibility changed, visible=" + viewEvent.getNewValue()) ; // NOI18N
154
}
155                 
156                 windowSystemVisibilityChanged(((Boolean JavaDoc)viewEvent.getNewValue()).booleanValue(), wsa);
157                 // PENDING this should be processed separatelly, there is nothing to coallesce.
158

159                 return;
160             }
161         }
162         
163         // Process all event types.
164
for(int i = 0; i < viewEvents.length; i++) {
165             ViewEvent viewEvent = viewEvents[i];
166             int changeType = viewEvent.getType();
167             
168             // The other types.
169
if(changeType == CHANGE_MAIN_WINDOW_BOUNDS_JOINED_CHANGED) {
170                 if(DEBUG) {
171                     debugLog("Main window bounds joined changed"); // NOI18N
172
}
173
174                 if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_JOINED) {
175                     Rectangle bounds = (Rectangle)viewEvent.getNewValue();
176                     if(bounds != null) {
177                         hierarchy.getMainWindow().setBounds(bounds);
178                     }
179                 }
180             } else if(changeType == CHANGE_MAIN_WINDOW_BOUNDS_SEPARATED_CHANGED) {
181                 if(DEBUG) {
182                     debugLog("Main window bounds separated changed"); // NOI18N
183
}
184
185                 if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_SEPARATED) {
186                     Rectangle bounds = (Rectangle)viewEvent.getNewValue();
187                     if(bounds != null) {
188                         hierarchy.getMainWindow().setBounds(bounds);
189                     }
190                 }
191             } else if(changeType == CHANGE_MAIN_WINDOW_FRAME_STATE_JOINED_CHANGED) {
192                 if(DEBUG) {
193                     debugLog("Main window frame state joined changed"); // NOI18N
194
}
195
196                 if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_JOINED) {
197                     hierarchy.getMainWindow().setExtendedState(wsa.getMainWindowFrameStateJoined());
198                 }
199             } else if(changeType == CHANGE_MAIN_WINDOW_FRAME_STATE_SEPARATED_CHANGED) {
200                 if(DEBUG) {
201                     debugLog("Main window frame state separated changed"); // NOI18N
202
}
203
204                 if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_SEPARATED) {
205                     hierarchy.getMainWindow().setExtendedState(wsa.getMainWindowFrameStateSeparated());
206                 }
207             } else if(changeType == CHANGE_EDITOR_AREA_STATE_CHANGED) {
208                 if(DEBUG) {
209                     debugLog("Editor area state changed"); // NOI18N
210
}
211                 //#45832 updating the main windo bounds goes first. need to have the correct bounds when updating desktop.
212
hierarchy.updateMainWindowBounds(wsa);
213                 hierarchy.updateDesktop(wsa);
214                 hierarchy.setSeparateModesVisible(true);
215             } else if(changeType == CHANGE_EDITOR_AREA_FRAME_STATE_CHANGED) {
216                 if(DEBUG) {
217                     debugLog("Editor area frame state changed"); // NOI18N
218
}
219                 hierarchy.updateEditorAreaFrameState(wsa.getEditorAreaFrameState());
220             } else if(changeType == CHANGE_EDITOR_AREA_BOUNDS_CHANGED) {
221                 if(DEBUG) {
222                     debugLog("Editor area bounds changed"); // NOI18N
223
}
224
225                 hierarchy.updateEditorAreaBounds((Rectangle)viewEvent.getNewValue());
226             } else if(changeType == CHANGE_EDITOR_AREA_CONSTRAINTS_CHANGED) {
227                 if(DEBUG) {
228                     debugLog("Editor area constraints changed"); // NOI18N
229
}
230
231                 hierarchy.updateDesktop(wsa);
232             } else if(changeType == CHANGE_ACTIVE_MODE_CHANGED) {
233                 if(DEBUG) {
234                     debugLog("Active mode changed, mode=" + viewEvent.getNewValue()); // NOI18N
235
}
236                 hierarchy.updateDesktop(wsa);
237                 hierarchy.activateMode(wsa.getActiveModeAccessor());
238             } else if(changeType == CHANGE_TOOLBAR_CONFIGURATION_CHANGED) {
239                 if(DEBUG) {
240                     debugLog("Toolbar config name changed"); // NOI18N
241
}
242
243                 ToolbarPool.getDefault().setConfiguration(wsa.getToolbarConfigurationName());
244             } else if(changeType == CHANGE_MAXIMIZED_MODE_CHANGED) {
245                 if(DEBUG) {
246                     debugLog("Maximized mode changed"); // NOI18N
247
}
248
249                 hierarchy.setMaximizedModeView(hierarchy.getModeViewForAccessor(wsa.getMaximizedModeAccessor()));
250                 hierarchy.updateDesktop(wsa);
251                 hierarchy.activateMode(wsa.getActiveModeAccessor());
252             } else if(changeType == CHANGE_MODE_ADDED) {
253                 if(DEBUG) {
254                     debugLog("Mode added"); // NOI18N
255
}
256
257                 hierarchy.updateDesktop(wsa);
258             } else if(changeType == CHANGE_MODE_REMOVED) {
259                 if(DEBUG) {
260                     debugLog("Mode removed"); // NOI18N
261
}
262
263                 hierarchy.updateDesktop(wsa);
264                 hierarchy.activateMode(wsa.getActiveModeAccessor());
265             } else if(changeType == CHANGE_MODE_CONSTRAINTS_CHANGED) {
266                 if(DEBUG) {
267                     debugLog("Mode constraints changed"); // NOI18N
268
}
269
270                 hierarchy.updateDesktop(wsa);
271             } else if(changeType == CHANGE_MODE_BOUNDS_CHANGED) {
272                 if(DEBUG) {
273                     debugLog("Mode bounds changed"); // NOI18N
274
}
275
276                 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String JavaDoc)viewEvent.getSource())); // XXX
277
if(modeView != null) {
278                     modeView.getComponent().setBounds((Rectangle)viewEvent.getNewValue());
279                 }
280             } else if(changeType == CHANGE_MODE_FRAME_STATE_CHANGED) {
281                 if(DEBUG) {
282                     debugLog("Mode state changed"); // NOI18N
283
}
284
285                 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String JavaDoc)viewEvent.getSource())); // XXX
286
if(modeView != null) {
287                     modeView.setFrameState(((Integer JavaDoc)viewEvent.getNewValue()).intValue());
288                     modeView.updateFrameState();
289                 }
290             } else if(changeType == CHANGE_MODE_SELECTED_TOPCOMPONENT_CHANGED) {
291                 if(DEBUG) {
292                     debugLog("Selected topcomponent changed, tc=" + viewEvent.getNewValue()); // NOI18N
293
}
294
295                 // XXX PENDING see TopComponent.requestFocus (it's wrongly overriden).
296
hierarchy.updateDesktop(wsa);
297 // // XXX if the selection is changed in the active mode reactivate it.
298
// ModeAccessor ma = wsa.getActiveModeAccessor();
299
// if(ma == wsa.getActiveModeAccessor()) {
300
hierarchy.activateMode(wsa.getActiveModeAccessor());
301 // }
302
} else if(changeType == CHANGE_MODE_TOPCOMPONENT_ADDED) {
303                 if(DEBUG) {
304                     debugLog("TopComponent added"); // NOI18N
305
}
306
307                 hierarchy.updateDesktop(wsa);
308                 hierarchy.setSeparateModesVisible(true);
309                 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String JavaDoc)viewEvent.getSource())); // XXX
310
if (modeView != null) {
311                     // #39755 - seems to require to call the updateframestate() in order to have a closed mode to show in the last framestate.
312
// not 100% sure this is the correct location for the call, for editorarea the relevant change resides in ViewHierarchy.updateDesktop,
313
// prefer not to call hierarchy.updateframestates() because it's only needed for the currently opened mode..
314
modeView.updateFrameState();
315                 }
316             } else if(changeType == CHANGE_MODE_TOPCOMPONENT_REMOVED) {
317                 if(DEBUG) {
318                     debugLog("TopComponent removed"); // NOI18N
319
}
320
321                 hierarchy.setMaximizedModeView(hierarchy.getModeViewForAccessor(wsa.getMaximizedModeAccessor()));
322                 hierarchy.updateDesktop(wsa);
323                 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String JavaDoc)viewEvent.getSource())); // XXX
324
if(modeView != null) {
325                     modeView.removeTopComponent((TopComponent)viewEvent.getNewValue());
326                 }
327                 hierarchy.activateMode(wsa.getActiveModeAccessor());
328             } else if(changeType == CHANGE_TOPCOMPONENT_DISPLAY_NAME_CHANGED) {
329                 if(DEBUG) {
330                     debugLog("TopComponent display name changed, tc=" + viewEvent.getNewValue()); // NOI18N
331
}
332
333                 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String JavaDoc)viewEvent.getSource())); // XXX
334
if(modeView != null) { // PENDING investigate
335
modeView.updateName((TopComponent)viewEvent.getNewValue());
336                 }
337             } else if(changeType == CHANGE_TOPCOMPONENT_DISPLAY_NAME_ANNOTATION_CHANGED) {
338                 if(DEBUG) {
339                     debugLog("TopComponent display name annotation changed, tc=" + viewEvent.getNewValue()); // NOI18N
340
}
341
342                 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String JavaDoc)viewEvent.getSource())); // XXX
343
if(modeView != null) { // PENDING investigate
344
modeView.updateName((TopComponent)viewEvent.getNewValue());
345                 }
346             } else if(changeType == CHANGE_TOPCOMPONENT_TOOLTIP_CHANGED) {
347                 if(DEBUG) {
348                     debugLog("TopComponent tooltip changed, tc=" + viewEvent.getNewValue()); // NOI18N
349
}
350
351                 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String JavaDoc)viewEvent.getSource())); // XXX
352
if(modeView != null) { // PENDING investigate
353
modeView.updateToolTip((TopComponent)viewEvent.getNewValue());
354                 }
355             } else if(changeType == CHANGE_TOPCOMPONENT_ICON_CHANGED) {
356                 if(DEBUG) {
357                     debugLog("TopComponent icon changed"); // NOI18N
358
}
359
360                 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String JavaDoc)viewEvent.getSource())); // XXX
361
if(modeView != null) { // PENDING investigate
362
modeView.updateIcon((TopComponent)viewEvent.getNewValue());
363                 }
364             } else if(changeType == CHANGE_TOPCOMPONENT_ATTACHED) {
365                 if(DEBUG) {
366                     debugLog("TopComponent attached"); // NOI18N
367
}
368
369                 hierarchy.updateDesktop(wsa);
370                 hierarchy.activateMode(wsa.getActiveModeAccessor());
371             } else if(changeType == CHANGE_TOPCOMPONENT_ARRAY_ADDED) {
372                 if(DEBUG) {
373                     debugLog("TopComponent array added:" // NOI18N
374
+ Arrays.asList((TopComponent[])viewEvent.getNewValue()));
375                 }
376                 hierarchy.updateDesktop(wsa);
377 // hierarchy.activateMode(wsa.getActiveModeAccessor());
378
} else if(changeType == CHANGE_TOPCOMPONENT_ARRAY_REMOVED) {
379                 if(DEBUG) {
380                     debugLog("TopComponent array removed:" // NOI18N
381
+ Arrays.asList((TopComponent[])viewEvent.getNewValue()));
382                 }
383
384                 hierarchy.updateDesktop(wsa);
385                 hierarchy.activateMode(wsa.getActiveModeAccessor());
386             } else if(changeType == CHANGE_TOPCOMPONENT_ACTIVATED) {
387                 if(DEBUG) {
388                     debugLog("TopComponent activated, tc=" + viewEvent.getNewValue()); // NOI18N
389
}
390                 
391                 hierarchy.updateDesktop(wsa);
392                 hierarchy.activateMode(wsa.getActiveModeAccessor());
393             } else if(changeType == CHANGE_MODE_CLOSED) {
394                 if(DEBUG) {
395                     debugLog("Mode closed, mode=" + viewEvent.getSource()); // NOI18N
396
}
397                 
398                 hierarchy.updateDesktop();
399             } else if(changeType == CHANGE_DND_PERFORMED) {
400                 if(DEBUG) {
401                     debugLog("DnD performed"); // NOI18N
402
}
403
404                 hierarchy.setMaximizedModeView(hierarchy.getModeViewForAccessor(wsa.getMaximizedModeAccessor()));
405                 hierarchy.updateDesktop();
406                 hierarchy.activateMode(wsa.getActiveModeAccessor());
407             } else if(changeType == CHANGE_UI_UPDATE) {
408                 if(DEBUG) {
409                     debugLog("UI update"); // NOI18N
410
}
411
412                 hierarchy.updateUI();
413             } else if(changeType == CHANGE_TOPCOMPONENT_AUTO_HIDE_ENABLED ||
414                       changeType == CHANGE_TOPCOMPONENT_AUTO_HIDE_DISABLED) {
415                 if(DEBUG) {
416                     debugLog("Top Component Auto Hide changed"); // NOI18N
417
}
418                 hierarchy.setMaximizedModeView(hierarchy.getModeViewForAccessor(wsa.getMaximizedModeAccessor()));
419                 hierarchy.updateDesktop(wsa);
420                 hierarchy.activateMode(wsa.getActiveModeAccessor());
421             } else if (changeType == View.TOPCOMPONENT_REQUEST_ATTENTION) {
422                 if (DEBUG) {
423                     debugLog("Top component request attention");
424                 }
425                 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String JavaDoc)viewEvent.getSource())); // XXX
426
if (modeView != null) {
427                    TopComponent tc = (TopComponent) viewEvent.getNewValue();
428                    if (tc == null) {
429                        throw new NullPointerException JavaDoc ("Top component is null for attention request"); //NOI18N
430
}
431                    modeView.requestAttention (tc);
432                 } else {
433                     Logger.getLogger(DefaultView.class.getName()).fine(
434                         "Could not find mode " + viewEvent.getSource());
435                 }
436             } else if (changeType == View.TOPCOMPONENT_CANCEL_REQUEST_ATTENTION) {
437                 if (DEBUG) {
438                     debugLog("Top component cancel request attention"); //NOI18N
439
}
440                 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String JavaDoc)viewEvent.getSource())); // XXX
441
if (modeView != null) {
442                    TopComponent tc = (TopComponent) viewEvent.getNewValue();
443                    if (tc == null) {
444                        throw new NullPointerException JavaDoc ("Top component is null for attention cancellation request"); //NOI18N
445
}
446                    modeView.cancelRequestAttention (tc);
447                 } else {
448                     Logger.getLogger(DefaultView.class.getName()).fine(
449                         "Could not find mode " + viewEvent.getSource());
450                 }
451             } else if (changeType == View.CHANGE_MAXIMIZE_TOPCOMPONENT_SLIDE_IN) {
452                 if (DEBUG) {
453                     debugLog("Slided-in top component toggle maximize"); //NOI18N
454
}
455                 TopComponent tc = (TopComponent)viewEvent.getSource();
456                 String JavaDoc side = (String JavaDoc)viewEvent.getNewValue();
457                 hierarchy.performSlideToggleMaximize( tc, side );
458             }
459         }
460         
461         Set JavaDoc<TopComponent> toHide = new HashSet JavaDoc<TopComponent>(oldShowing);
462         toHide.removeAll(newShowing);
463         for(TopComponent tc: toHide) {
464             WindowManagerImpl.getInstance().componentHidden(tc);
465         }
466     }
467     
468     /** Whether the window system should show or hide its GUI. */
469     private void windowSystemVisibilityChanged(boolean visible, WindowSystemAccessor wsa) {
470         if(visible) {
471             showWindowSystem(wsa);
472         } else {
473             hideWindowSystem();
474         }
475     }
476     
477
478     //////////////////////////////////////////////////////////
479
private void showWindowSystem(final WindowSystemAccessor wsa) {
480         long start = System.currentTimeMillis();
481         if(DEBUG) {
482             debugLog("ShowWindowSystem--"); // NOI18N
483
}
484 // java.awt.Toolkit.getDefaultToolkit().addAWTEventListener(new java.awt.event.AWTEventListener() {
485
// public void eventDispatched(java.awt.event.AWTEvent event) {
486
//// debugLog("" + event.getID() + " " + event.getSource().getClass() + event.toString());
487
// Debug.log(org.netbeans.core.windows.Constants.class, event.toString());
488
// Debug.log(org.netbeans.core.windows.Constants.class, "keyboard focus=" + java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
489
// }
490
// }, AWTEvent.FOCUS_EVENT_MASK);
491

492         hierarchy.getMainWindow().initializeComponents();
493         // Init toolbar.
494
ToolbarPool.getDefault().setConfiguration(wsa.getToolbarConfigurationName());
495         
496         if(DEBUG) {
497             debugLog(wsa.getModeStructureAccessor().toString());
498         }
499         // Prepare main window (pack and set bounds).
500
hierarchy.getMainWindow().prepareWindow();
501
502         if(DEBUG) {
503             debugLog("Init view 4="+(System.currentTimeMillis() - start) + " ms"); // NOI18N
504
}
505
506
507         if(DEBUG) {
508             debugLog("Init view 2="+(System.currentTimeMillis() - start) + " ms"); // NOI18N
509
}
510         
511         hierarchy.setSplitModesVisible(true);
512
513         if(DEBUG) {
514             debugLog("Init view 3="+(System.currentTimeMillis() - start) + " ms"); // NOI18N
515
}
516         
517         // Shows main window
518
hierarchy.getMainWindow().setVisible(true);
519         
520         if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_JOINED) {
521             hierarchy.getMainWindow().setExtendedState(wsa.getMainWindowFrameStateJoined());
522         } else {
523             hierarchy.getMainWindow().setExtendedState(wsa.getMainWindowFrameStateSeparated());
524         }
525         
526         hierarchy.setMaximizedModeView(hierarchy.getModeViewForAccessor(wsa.getMaximizedModeAccessor()));
527
528         // Init desktop.
529
hierarchy.updateDesktop(wsa);
530         
531         // Show separate modes.
532
hierarchy.setSeparateModesVisible(true);
533
534         hierarchy.updateEditorAreaFrameState(wsa.getEditorAreaFrameState());
535         
536         // Updates frame states of separate modes.
537
hierarchy.updateFrameStates();
538         
539         // XXX PENDING
540
if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_JOINED) {
541             // Ignore when main window is maximized.
542
if(hierarchy.getMainWindow().getExtendedState() != Frame.MAXIMIZED_BOTH) {
543                 if (DEBUG) {
544                     debugLog("do updateMainWindowBoundsSeparatedHelp");
545                 }
546                 updateMainWindowBoundsSeparatedHelp();
547                 updateEditorAreaBoundsHelp();
548 // updateSeparateBoundsForView(hierarchy.getSplitRootElement());
549
}
550         }
551         
552         // setting activate mode had to be done in Swing.invokeLater() because of split recalculations. (#40501)
553
// since the JSplitPane.resetToPrefferedSizes() rewrite, it's no longer necessary
554
// also should fix
555
hierarchy.activateMode(wsa.getActiveModeAccessor());
556
557         //#39238 in maximazed mode swing posts a lot of stuff to Awt thread using SwingUtilities.invokeLater
558
// for that reason the installation of window listeners and the update of splits kicked in too early when
559
// the window was not maximazed yet -> resulted in wrong calculation of splits and also bad reactions from the listeners
560
// which considered the automated change to maximazed mode to be issued by the user.
561
SwingUtilities.invokeLater(new Runnable JavaDoc() {
562             public void run() {
563                 if (DEBUG) {
564                     debugLog("Installing main window listeners.");
565                 }
566                 hierarchy.installMainWindowListeners();
567             }
568         });
569         
570         if(DEBUG) {
571             debugLog("Init view 5="+(System.currentTimeMillis() - start) + " ms"); // NOI18N
572
}
573     }
574     
575     private void hideWindowSystem() {
576         hierarchy.uninstallMainWindowListeners();
577         
578         hierarchy.setSeparateModesVisible(false);
579         hierarchy.getMainWindow().setVisible(false);
580         // Release all.
581
hierarchy.releaseAll();
582     }
583     
584     ////////////////////////////////////////////////////
585
// Controller >>
586
public void userActivatedModeView(ModeView modeView) {
587         if(DEBUG) {
588             debugLog("User activated mode view, mode=" + modeView); // NOI18N
589
}
590         
591         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
592         ModeImpl mode = getModeForModeAccessor(modeAccessor);
593         controllerHandler.userActivatedMode(mode);
594     }
595     
596     public void userActivatedModeWindow(ModeView modeView) {
597         if(DEBUG) {
598             debugLog("User activated mode window, mode=" + modeView); // NOI18N
599
}
600         
601         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
602         ModeImpl mode = getModeForModeAccessor(modeAccessor);
603         controllerHandler.userActivatedModeWindow(mode);
604     }
605     
606     public void userActivatedEditorWindow() {
607         if(DEBUG) {
608             debugLog("User activated editor window"); // NOI18N
609
}
610         
611         controllerHandler.userActivatedEditorWindow();
612     }
613     
614     public void userSelectedTab(ModeView modeView, TopComponent selected) {
615         if(DEBUG) {
616             debugLog("User selected tab, tc=" + WindowManagerImpl.getInstance().getTopComponentDisplayName(selected)); // NOI18N
617
}
618
619         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
620         ModeImpl mode = getModeForModeAccessor(modeAccessor);
621         controllerHandler.userActivatedTopComponent(mode, selected);
622     }
623     
624     public void userClosingMode(ModeView modeView) {
625         if(DEBUG) {
626             debugLog("User closing mode="+modeView); // NOI18N
627
}
628
629         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
630         ModeImpl mode = getModeForModeAccessor(modeAccessor);
631         controllerHandler.userClosedMode(mode);
632     }
633     
634     private void removeModeViewFromHierarchy(ModeView modeView) {
635         hierarchy.removeModeView(modeView);
636         hierarchy.updateDesktop();
637     }
638     
639     public void userResizedMainWindow(Rectangle bounds) {
640         if(DEBUG) {
641             debugLog("User resized main window"); // NOI18N
642
}
643
644         // Ignore when main window is maximized.
645
if(hierarchy.getMainWindow().getExtendedState() != Frame.MAXIMIZED_BOTH) {
646             controllerHandler.userResizedMainWindow(bounds);
647         }
648
649         // Ignore when main window is maximized.
650
if(hierarchy.getMainWindow().getExtendedState() != Frame.MAXIMIZED_BOTH) {
651             // XXX PENDING
652
updateMainWindowBoundsSeparatedHelp();
653             updateEditorAreaBoundsHelp();
654             updateSeparateBoundsForView(hierarchy.getSplitRootElement());
655         }
656     }
657     
658     public void userMovedMainWindow(Rectangle bounds) {
659         if(DEBUG) {
660             debugLog("User moved main window"); // NOI18N
661
}
662
663         // Ignore when main window is maximized.
664
if (hierarchy.getMainWindow().getExtendedState() != Frame.MAXIMIZED_BOTH) {
665             controllerHandler.userResizedMainWindow(bounds);
666         }
667     }
668     
669     public void userResizedEditorArea(Rectangle bounds) {
670         if(DEBUG) {
671             debugLog("User resized editor area"); // NOI18N
672
}
673
674         controllerHandler.userResizedEditorArea(bounds);
675     }
676     
677     public void userResizedModeBounds(ModeView modeView, Rectangle bounds) {
678         if(DEBUG) {
679             debugLog("User resized mode"); // NOI18N
680
}
681
682         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
683         // XXX PENDING #39083 Investigate how it could happen.
684
if(modeAccessor != null) {
685             ModeImpl mode = getModeForModeAccessor(modeAccessor);
686             controllerHandler.userResizedModeBounds(mode, bounds);
687         }
688     }
689     
690     public void userMovedSplit(SplitView splitView, ViewElement[] childrenViews, double[] splitWeights) {
691         if(DEBUG) {
692             debugLog("User moved split"); // NOI18N
693
// Debug.dumpStack(DefaultView.class);
694
}
695
696         SplitAccessor splitAccessor = (SplitAccessor)hierarchy.getAccessorForView(splitView);
697         ElementAccessor[] childrenAccessors = new ElementAccessor[childrenViews.length];
698         for( int i=0; i<childrenViews.length; i++ ) {
699             childrenAccessors[i] = hierarchy.getAccessorForView( childrenViews[i] );
700         }
701         ViewHelper.setSplitWeights(splitAccessor, childrenAccessors, splitWeights, controllerHandler);
702         
703         // XXX PENDING
704
// updateSeparateBoundsForView(splitView);
705
}
706     
707     public void userClosedTopComponent(ModeView modeView, TopComponent tc) {
708         if(DEBUG) {
709             debugLog("User closed topComponent=" + tc); // NOI18N
710
}
711
712         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
713         ModeImpl mode = getModeForModeAccessor(modeAccessor);
714         controllerHandler.userClosedTopComponent(mode, tc);
715     }
716     
717     public void userChangedFrameStateMainWindow(int frameState) {
718         if(DEBUG) {
719             debugLog("User changed frame state main window"); // NOI18N
720
}
721         
722         controllerHandler.userChangedFrameStateMainWindow(frameState);
723     }
724     
725     public void userChangedFrameStateEditorArea(int frameState) {
726         if(DEBUG) {
727             debugLog("User changed frame state editor area"); // NOI18N
728
}
729         controllerHandler.userChangedFrameStateEditorArea(frameState);
730     }
731     
732     public void userChangedFrameStateMode(ModeView modeView, int frameState) {
733         if(DEBUG) {
734             debugLog("User changed frame state mode"); // NOI18N
735
}
736
737         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
738         ModeImpl mode = getModeForModeAccessor(modeAccessor);
739         controllerHandler.userChangedFrameStateMode(mode, frameState);
740     }
741     
742     // DnD
743
public void userDroppedTopComponents(ModeView modeView, TopComponent[] tcs) {
744         if(tcs.length == 0) {
745             return;
746         }
747         
748         if(DEBUG) {
749             debugLog("User dropped TopComponent's"); // NOI18N
750
}
751
752         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
753         ModeImpl mode = getModeForModeAccessor(modeAccessor);
754         controllerHandler.userDroppedTopComponents(mode, tcs);
755     }
756     
757     public void userDroppedTopComponents(ModeView modeView, TopComponent[] tcs, int index) {
758         if(tcs.length == 0) {
759             return;
760         }
761         
762         if(DEBUG) {
763             debugLog("User dropped TopComponent's to index=" + index); // NOI18N
764
}
765         
766         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
767         ModeImpl mode = getModeForModeAccessor(modeAccessor);
768         
769         // #37127 Refine the index if the TC is moving inside the mode.
770
int position = Arrays.asList(modeAccessor.getOpenedTopComponents()).indexOf(tcs[0]);
771         if(position > -1 && position <= index) {
772             index--;
773         }
774                 
775         controllerHandler.userDroppedTopComponents(mode, tcs, index);
776     }
777     
778     public void userDroppedTopComponents(ModeView modeView, TopComponent[] tcs, String JavaDoc side) {
779         if(tcs.length == 0) {
780             return;
781         }
782         
783         if(DEBUG) {
784             debugLog("User dropped TopComponent's to side=" + side); // NOI18N
785
}
786         
787         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
788         ModeImpl mode = getModeForModeAccessor(modeAccessor);
789         controllerHandler.userDroppedTopComponents(mode, tcs, side);
790     }
791
792     public void userDroppedTopComponentsIntoEmptyEditor(TopComponent[] tcs) {
793         if(tcs.length == 0) {
794             return;
795         }
796
797         if(DEBUG) {
798             debugLog("User dropped TopComponent's into empty editor"); // NOI18N
799
}
800         
801         controllerHandler.userDroppedTopComponentsIntoEmptyEditor(tcs);
802     }
803     
804     public void userDroppedTopComponentsAround(TopComponent[] tcs, String JavaDoc side) {
805         if(tcs.length == 0) {
806             return;
807         }
808
809         if(DEBUG) {
810             debugLog("User dropped TopComponent's around, side=" + side); // NOI18N
811
}
812         
813         controllerHandler.userDroppedTopComponentsAround(tcs, side);
814     }
815     
816     public void userDroppedTopComponentsAroundEditor(TopComponent[] tcs, String JavaDoc side, int modeKind) {
817         if(tcs.length == 0) {
818             return;
819         }
820
821         if(DEBUG) {
822             debugLog("User dropped TopComponent's around editor, side=" + side); // NOI18N
823
}
824         
825         controllerHandler.userDroppedTopComponentsAroundEditor(tcs, side, modeKind);
826     }
827     
828     public void userDroppedTopComponentsIntoFreeArea(TopComponent[] tcs, Rectangle bounds, int draggedKind) {
829         if(tcs.length == 0) {
830             return;
831         }
832         
833         if(DEBUG) {
834             debugLog("User dropped TopComponent's into free area, bounds=" + bounds); // NOI18N
835
}
836         
837         controllerHandler.userDroppedTopComponentsIntoFreeArea(tcs, bounds, draggedKind);
838     }
839
840     // Sliding
841

842     public void userDisabledAutoHide(ModeView modeView, TopComponent tc) {
843         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
844         ModeImpl mode = getModeForModeAccessor(modeAccessor);
845         controllerHandler.userDisabledAutoHide(tc, mode);
846     }
847
848     public void userEnabledAutoHide(ModeView modeView, TopComponent tc) {
849         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
850         ModeImpl mode = getModeForModeAccessor(modeAccessor);
851         String JavaDoc side = guessSlideSide(tc);
852         controllerHandler.userEnabledAutoHide(tc, mode, side);
853     }
854     
855     public void userTriggeredSlideIn(ModeView modeView, SlideOperation operation) {
856         hierarchy.performSlideIn(operation);
857     }
858     
859     public void userTriggeredSlideOut(ModeView modeView, SlideOperation operation) {
860         hierarchy.performSlideOut(operation);
861         // restore focus if needed
862
if (operation.requestsActivation()) {
863             ModeView lastNonSlidingActive = hierarchy.getLastNonSlidingActiveModeView();
864             ModeImpl mode = null;
865             if (lastNonSlidingActive != null) {
866                 mode = getModeForModeAccessor((ModeAccessor)hierarchy.getAccessorForView(lastNonSlidingActive));
867             }
868             if (mode != null) {
869                 controllerHandler.userActivatedMode(mode);
870             } else {
871                 // no appropriate mode exists - select editor as last resort
872
controllerHandler.userActivatedEditorWindow();
873             }
874         }
875     }
876     
877     public void userTriggeredSlideIntoDesktop(ModeView modeView, SlideOperation operation) {
878         hierarchy.performSlideIntoDesktop(operation);
879     }
880     
881     public void userTriggeredSlideIntoEdge(ModeView modeView, SlideOperation operation) {
882         hierarchy.performSlideIntoEdge(operation);
883     }
884     
885     public void userResizedSlidingWindow(ModeView modeView, SlideOperation operation) {
886         ((SlidingView)modeView).setSlideBounds(modeView.getSelectedTopComponent().getBounds());
887         hierarchy.performSlideResize(operation);
888         ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView);
889         ModeImpl mode = getModeForModeAccessor(modeAccessor);
890         controllerHandler.userResizedSlidingMode(mode, operation.getFinishBounds());
891     }
892     
893     
894     private static ModeImpl getModeForModeAccessor(ModeAccessor accessor) {
895         return accessor == null ? null : accessor.getMode();
896     }
897     
898     private static ModelElement getModelElementForAccessor(ElementAccessor accessor) {
899         return accessor == null ? null : accessor.getOriginator();
900     }
901     // Controller <<
902
////////////////////////////////////////////////////
903

904     // XXX
905
private void updateMainWindowBoundsSeparatedHelp() {
906         controllerHandler.userResizedMainWindowBoundsSeparatedHelp(
907                 hierarchy.getMainWindow().getPureMainWindowBounds());
908     }
909     
910     // XXX
911
private void updateEditorAreaBoundsHelp() {
912         Rectangle bounds = hierarchy.getPureEditorAreaBounds();
913         controllerHandler.userResizedEditorAreaBoundsHelp(bounds);
914     }
915     
916     // XXX PENDING This is just for the cases split modes doesn't have a separated
917
// opposite ones, so they keep the bounds for them. Revise.
918
void updateSeparateBoundsForView(ViewElement view) {
919         if (view.getComponent() instanceof JComponent) {
920             // when updating the views after resizing the split, do
921
// set the preffered size accordingly to prevent jumping splits
922
// in SplitView.updateAwtHierarchy()
923
// is basically a workaround, the problem should be fixed by reimplementing the
924
// splits without using the JSplitPane
925
// #45186 for more details
926
JComponent comp = (JComponent)view.getComponent();
927             Dimension JavaDoc dim = new Dimension JavaDoc(comp.getSize());
928             comp.setPreferredSize(dim);
929             comp.putClientProperty("lastAvailableSpace", dim); //NOI18N
930
}
931         if(view instanceof ModeView) {
932             ModeView mv = (ModeView)view;
933             ModeAccessor ma = (ModeAccessor)hierarchy.getAccessorForView(mv);
934             if(ma != null) {
935                 Component comp = mv.getComponent();
936                 Rectangle bounds = comp.getBounds();
937                 Point point = new Point(0, 0);
938                 SwingUtilities.convertPointToScreen(point, comp);
939                 bounds.setLocation(point);
940                 
941                 ModeImpl mode = getModeForModeAccessor(ma);
942                 // XXX ControllerHandler
943
controllerHandler.userResizedModeBoundsSeparatedHelp(mode, bounds);
944             }
945         } else if(view instanceof SplitView) {
946             SplitView sv = (SplitView)view;
947             List JavaDoc children = sv.getChildren();
948             for( Iterator JavaDoc i=children.iterator(); i.hasNext(); ) {
949                 ViewElement child = (ViewElement)i.next();
950                 updateSeparateBoundsForView( child );
951             }
952         } else if(view instanceof EditorView) {
953             updateEditorAreaBoundsHelp();
954             // Editor area content isn't needed to remember.
955
}
956     }
957
958     ///////////////
959
// ViewAccessor
960
public Set JavaDoc<Component> getModeComponents() {
961         return hierarchy.getModeComponents();
962     }
963     
964     public Set JavaDoc<Component> getSeparateModeFrames() {
965         return hierarchy.getSeparateModeFrames();
966     }
967     
968     public Controller getController() {
969         return this;
970     }
971     
972     public Component getSlidingModeComponent(String JavaDoc side) {
973         return hierarchy.getSlidingModeComponent(side);
974     }
975     // ViewAccessor
976
///////////////
977

978     
979     private static void debugLog(String JavaDoc message) {
980         Debug.log(DefaultView.class, message);
981     }
982
983     
984 }
985
986
Popular Tags