KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > WindowManagerImpl


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;
21
22 import java.awt.*;
23 import java.beans.*;
24 import java.net.URL JavaDoc;
25 import java.util.*;
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import javax.swing.*;
29 import org.netbeans.core.windows.actions.ActionUtils;
30 import org.netbeans.core.windows.persistence.PersistenceManager;
31 import org.openide.nodes.Node;
32 import org.openide.util.*;
33 import org.openide.windows.*;
34
35 /**
36  * This class extends WindowManager to provide all window system functionality.
37  *
38  * This class is final only for performance reasons. Can be freely
39  * unfinaled if desired.
40  *
41  * @author Peter Zavadsky
42  */

43 public final class WindowManagerImpl extends WindowManager implements Workspace {
44 // XXX Implements Workspace for backward compatibility of old API only,
45
// there are no workspaces any more.
46

47     // XXX PENDING additional, not-yet officialy supported properties.
48
/** Name of property change fired when active mode changed. */
49     public static final String JavaDoc PROP_ACTIVE_MODE = "activeMode"; // NOI8N
50
/** Name of property change fired when maximized mode changed. */
51     public static final String JavaDoc PROP_MAXIMIZED_MODE = "maximizedMode"; // NOI18N
52
/** Name of property change fired when editor area state changed. */
53     public static final String JavaDoc PROP_EDITOR_AREA_STATE = "editorAreaState"; // NOI18N
54

55     /** Init lock. */
56     private static final Object JavaDoc LOCK_INIT = new Object JavaDoc();
57     
58     /** The only instance of the window manager implementation in the system */
59     private static WindowManagerImpl defaultInstance;
60
61     /** Central unit of window system. */
62     private final Central central = new Central();
63     
64     /** properties support */
65     private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
66     
67     // PENDING
68
/** Manages list of recently activated <code>TopCompoennt</code>s. */
69     private final RecentViewList recentViewList = new RecentViewList(this);
70
71     /** Only for hack 40237, to not call componentShowing twice */
72     private TopComponent persistenceShowingTC;
73     
74     
75     /** exclusive invocation of runnables */
76     private Exclusive exclusive = new Exclusive();
77     /** Default constructor. Don't use directly, use getDefault()
78      * instead.
79      */

80     public WindowManagerImpl() {
81         synchronized(LOCK_INIT) {
82             // a static object to synchronize on
83
if(defaultInstance != null) {
84                 throw new IllegalStateException JavaDoc("Instance already exists"); // NOI18N
85
}
86             defaultInstance = this;
87         }
88     }
89     
90     /** Singleton accessor, returns instance of window manager implementation */
91     public static WindowManagerImpl getInstance() {
92         if (defaultInstance != null) {
93             // Save a bunch of time accessing global lookup, acc. to profiler.
94
return defaultInstance;
95         }
96         return (WindowManagerImpl)Lookup.getDefault().lookup(WindowManager.class);
97     }
98     
99     public void topComponentRequestAttention(TopComponent tc) {
100         ModeImpl mode = (ModeImpl) findMode(tc);
101         
102         central.topComponentRequestAttention(mode, tc);
103     }
104
105     public void topComponentCancelRequestAttention(TopComponent tc) {
106         ModeImpl mode = (ModeImpl) findMode(tc);
107         
108         central.topComponentCancelRequestAttention(mode, tc);
109     }
110
111     /////////////////////////
112
// API impelementation >>
113
/////////////////////////
114

115     // PENDING revise this method, it is dangerous to expose the GUI.
116
/** Provides access to the MainWindow of the IDE.
117      * Implements <code>WindowManager</code> abstract method.
118      * @return the MainWindow */

119     public Frame getMainWindow() {
120         assertEventDispatchThreadWeak();
121         
122         return central.getMainWindow();
123     }
124     
125     /** Called after a current LookAndFeel change to update the IDE's UI
126      * Implements <code>WindowManager</code> abstract method. */

127     public void updateUI() {
128         assertEventDispatchThreadWeak();
129         
130         central.updateUI();
131     }
132     
133     /** Creates a component manager for given top component.
134      * Implements <code>WindowManager</code> abstract method.
135      * @param c the component
136      * @return the manager that handles opening, closing and selecting a component
137      * @deprecated Don't use this. */

138     protected synchronized WindowManager.Component createTopComponentManager(TopComponent c) {
139         assertEventDispatchThreadWeak();
140         
141         return null;
142     }
143     
144     /** Creates new workspace with given name and display name.
145      * Implements <code>WindowManager</code> abstract method.
146      * @return fake implementation of only workspace
147      * @deprecated Doesn't have a sense now. Workspaces aren't supported anymore. */

148     public Workspace createWorkspace(String JavaDoc name, String JavaDoc displayName) {
149         assertEventDispatchThreadWeak();
150         
151         // get back fake workspace.
152
return this;
153     }
154
155     /** Finds workspace given its name.
156      * @return fake implementation of only workspace
157      * @deprecated Doesn't have a sense now. Workspaces aren't supported anymore. */

158     public Workspace findWorkspace(String JavaDoc name) {
159         assertEventDispatchThreadWeak();
160         
161         // PENDING what to return?
162
return this;
163     }
164     
165     /** List of all currenty available workspaces.
166      * Implements <code>WindowManager</code> abstract method.
167      * @return array with only one (fake) workspace impl
168      * @deprecated Doesn't have a sense now. Workspaces aren't supported anymore. */

169     public Workspace[] getWorkspaces() {
170         assertEventDispatchThreadWeak();
171         
172         return new Workspace[] {this};
173     }
174
175     /** Sets new workspaces.
176      * Implements <code>WindowManager</code> abstract method.
177      * @param workspaces array of new workspaces
178      * @deprecated Doesn't have a sense now. Workspaces aren't supported anymore. */

179     public void setWorkspaces(Workspace[] workspaces) {
180         assertEventDispatchThreadWeak();
181     }
182
183     /** Gets current workspace. Can be changed by calling Workspace.activate ()
184      * Implements <code>WindowManager</code> abstract method.
185      * @return fake implementation of only workspace
186      * @deprecated Doesn't have a sense now. Workspaces aren't supported anymore. */

187     public Workspace getCurrentWorkspace() {
188         assertEventDispatchThreadWeak();
189         
190         // Gets back this as a fake workspace.
191
return this;
192     }
193
194     /** Finds TopComponentGroup of given name. */
195     public TopComponentGroup findTopComponentGroup(String JavaDoc name) {
196         assertEventDispatchThread();
197         
198         for(Iterator it = getTopComponentGroups().iterator(); it.hasNext(); ) {
199             TopComponentGroupImpl group = (TopComponentGroupImpl)it.next();
200             if(group.getName().equals(name)) {
201                 return group;
202             }
203         }
204         
205         return null;
206     }
207     
208     /** Returns <code>TopComponent</code> for given unique ID.
209      * @param tcID unique <code>TopComponent</code> ID
210      * @return <code>TopComponent</code> instance corresponding to unique ID
211      */

212     public TopComponent findTopComponent(String JavaDoc tcID) {
213         assertEventDispatchThreadWeak();
214         
215         return getTopComponentForID(tcID);
216     }
217     
218     /** Adds listener.
219     * Implements <code>WindowManager</code> abstract method. */

220     public void addPropertyChangeListener(PropertyChangeListener l) {
221         changeSupport.addPropertyChangeListener(l);
222     }
223     
224     /** Removes listener.
225      * Implements <code>WindowManager</code> abstract method. */

226     public void removePropertyChangeListener(PropertyChangeListener l) {
227         changeSupport.removePropertyChangeListener(l);
228     }
229
230     ////////////////////////
231
// API implementation <<
232
////////////////////////
233

234 // /** Activates <code>TopComponent</code>, if it is opened. */
235
// private boolean activateTopComponent(TopComponent tc) {
236
// if(tc != null) {
237
// // Find whether the component is in mode.
238
// ModeImpl mode = (ModeImpl)findMode(tc);
239
// if(mode != null) {
240
// // Actually activates the TopComponent.
241
// central.activateModeTopComponent(mode, tc);
242
// } else {
243
// // TopComponent not in mode yet.
244
// return false;
245
// }
246
// }
247
//
248
// return true;
249
// }
250

251 // /** Selects <code>TopComponent</code>, if it is opened. */
252
// protected void selectTopComponentImpl(TopComponent tc) {
253
// if(tc != null) {
254
// // Find whether the component is in mode.
255
// ModeImpl mode = (ModeImpl)findMode(tc);
256
// if(mode != null) {
257
// // Actually select the TopComponent.
258
// central.setModeSelectedTopComponent(mode, tc);
259
// }
260
// }
261
// }
262

263
264     // XXX For backward compatibility (Workspace class), this is the only (fake) workspace.
265
// There are not supported workspaces any more.
266
///////////////////////////////////////
267
// Start of Workspace implementation>>
268
///////////////////////////////////////
269

270     /** Gets the programmatic unique name of this workspace.
271      * Implements <code>Workspace</code> interface method.
272      * @return the programmatic name of only workspace impl
273      * @deprecated Doesn't have a sense now. Workspaces aren't supported anymore. */

274     public String JavaDoc getName () {
275         return "FakeWorkspace"; // NOI18N
276
}
277     
278     /** Gets human-presentable name of the workspace.
279      * Implements <code>Workspace</code> interface method.
280      * @return the diplay name of the workspace
281      * @deprecated Doesn't have a sense now. Workspaces aren't supported anymore. */

282     public String JavaDoc getDisplayName () {
283         return NbBundle.getMessage(WindowManagerImpl.class, "LBL_FakeWorkspace");
284     }
285
286     /** Gets <code>Set</code> of all <code>Mode</code>'s.
287      * Implements <code>Workspace</code> interface method. */

288     public Set<? extends Mode> getModes () {
289         return central.getModes();
290     }
291     
292     /** Get bounds.
293      * Implements <code>Workspace</code> interface method. */

294     public Rectangle getBounds () {
295         if(getEditorAreaState() == Constants.EDITOR_AREA_JOINED) {
296             return getMainWindowBoundsJoined();
297         } else {
298             return getMainWindowBoundsSeparated();
299         }
300     }
301
302     /** Activates this workspace to be current one.
303      * @deprecated Doesn't have a sense now. Workspaces aren't supported anymore. */

304     public void activate () {
305     }
306     
307     /** Creates new <code>Mode</code>.
308      * Implements <code>Workspace</code> interface method.
309      * @param name a unique programmatic name of the mode
310      * @param displayName <em>ignored</em> doesn't have a sense now
311      * @param icon <em>ignored</em> doesn't have a sense now
312      * @return the new mode */

313     public Mode createMode(String JavaDoc name, String JavaDoc displayName, URL JavaDoc icon) {
314         if(getEditorAreaState() == Constants.EDITOR_AREA_JOINED) {
315             return new WrapMode (createMode(name, Constants.MODE_KIND_EDITOR, Constants.MODE_STATE_JOINED, false, null));
316         } else {
317             // #36945 In 'separate' ui mode create new mode.
318
return createMode(name, Constants.MODE_KIND_VIEW, Constants.MODE_STATE_SEPARATED, false,
319                 new SplitConstraint[] { new SplitConstraint(Constants.HORIZONTAL, 1, 0.2)});
320         }
321     }
322     private static class WrapMode implements Mode {
323         private Mode wrap;
324         
325         public WrapMode (Mode wrap) {
326             this.wrap = wrap;
327         }
328         
329         public void addPropertyChangeListener (PropertyChangeListener list) {
330             wrap.addPropertyChangeListener (list);
331         }
332         
333         public boolean canDock (TopComponent tc) {
334             return wrap.canDock (tc);
335         }
336         
337         public boolean dockInto (TopComponent c) {
338             if (c.getClientProperty (Constants.TOPCOMPONENT_ALLOW_DOCK_ANYWHERE) == null) {
339                 c.putClientProperty (Constants.TOPCOMPONENT_ALLOW_DOCK_ANYWHERE, Boolean.TRUE);
340             }
341             return wrap.dockInto (c);
342         }
343         
344         public Rectangle getBounds () {
345             return wrap.getBounds ();
346         }
347         
348         public String JavaDoc getDisplayName () {
349             return wrap.getDisplayName ();
350         }
351         
352         public Image getIcon () {
353             return wrap.getIcon ();
354         }
355         
356         public String JavaDoc getName () {
357             return wrap.getName ();
358         }
359         
360         public TopComponent getSelectedTopComponent () {
361             return wrap.getSelectedTopComponent ();
362         }
363         
364         public TopComponent[] getTopComponents () {
365             return wrap.getTopComponents ();
366         }
367         
368         public Workspace getWorkspace () {
369             return wrap.getWorkspace ();
370         }
371         
372         public void removePropertyChangeListener (PropertyChangeListener list) {
373             wrap.removePropertyChangeListener (list);
374         }
375         
376         public void setBounds (Rectangle s) {
377             wrap.setBounds (s);
378         }
379     } // end of WrapMode
380

381     /** Finds mode by specified name.
382      * Implements <code>Workspace</code> interface method.
383      * @param name the name of the mode to search for
384      * @return the mode with that name, or <code>null</code> */

385     public Mode findMode(String JavaDoc name) {
386         return findModeImpl(name);
387     }
388     
389     /** Finds mode the component is in.
390      * Implements <code>Workspace</code> interface method.
391      * @param c component to find mode for
392      * @return the mode or <code>null</code> if the component is not in any mode */

393     public Mode findMode(TopComponent tc) {
394         if(tc == null) {
395             // Log something?
396
return null;
397         }
398         
399         for(Iterator it = getModes().iterator(); it.hasNext(); ) {
400             ModeImpl mode = (ModeImpl)it.next();
401             
402             if(mode.containsTopComponent(tc)) {
403                 return mode;
404             }
405         }
406
407         return null;
408     }
409     
410     /** Clears this workspace and removes this workspace from window manager.
411      * Implements <code>Workspace</code> interface method.
412      * @deprecated Doesn't have a sense now. Workspaces aren't supported anymore. */

413     public void remove () {
414     }
415     ////////////////////////////////////
416
// End of Workspace implementation<<
417
////////////////////////////////////
418

419     //////////////////////////////
420
// TopComponentGroup>>
421
public void addTopComponentGroup(TopComponentGroupImpl tcGroup) {
422         central.addTopComponentGroup(tcGroup);
423     }
424     
425     public void removeTopComponentGroup(TopComponentGroupImpl tcGroup) {
426         central.removeTopComponentGroup(tcGroup);
427     }
428     
429     public Set<TopComponentGroupImpl> getTopComponentGroups() {
430         return central.getTopComponentGroups();
431     }
432     // TopComponentGroup<<
433
//////////////////////////////
434

435     
436     /// Copy from older WorkspaceImpl>>
437

438     ////////////////////////////////////////////////////////
439
// PENDING some of the next methods could make inner API
440
/** Creates new mode.
441      * @param name a unique programmatic name of the mode
442      * @param permanent true if mode has to remain in model even it is emptied */

443     public ModeImpl createMode(String JavaDoc name, int kind, int state, boolean permanent, SplitConstraint[] constraints) {
444         // It gets existing mode with the same name.
445
ModeImpl mode = (ModeImpl)findMode(name);
446         if(mode != null) {
447             return mode;
448         }
449         
450         // XXX PENDING When no constraints are specified, default (editor or view) mode is returned.
451
if(constraints == null && kind != Constants.MODE_KIND_SLIDING) {
452             if(kind == Constants.MODE_KIND_EDITOR) {
453                 return getDefaultEditorMode();
454             } else {
455                 return getDefaultViewMode();
456             }
457         }
458
459         mode = createModeImpl(name, kind, state, permanent);
460         addMode(mode, constraints);
461         return mode;
462     }
463     
464     public ModeImpl createSlidingMode(String JavaDoc name, boolean permanent, String JavaDoc side, Map<String JavaDoc,Integer JavaDoc> slideInSizes) {
465         // It gets existing mode with the same name.
466
ModeImpl mode = (ModeImpl)findMode(name);
467         if(mode != null) {
468             return mode;
469         }
470         
471         mode = createModeImpl(name, Constants.MODE_KIND_SLIDING, permanent);
472         central.addSlidingMode(mode, null, side, slideInSizes);
473         return mode;
474     }
475     
476     
477     /*private*/ ModeImpl createModeImpl(String JavaDoc name, int kind, boolean permanent) {
478         int state = getEditorAreaState() == Constants.EDITOR_AREA_JOINED
479                                                 ? Constants.MODE_STATE_JOINED
480                                                 : Constants.MODE_STATE_SEPARATED;
481         return createModeImpl(name, kind, state, permanent);
482     }
483     
484     /** */
485     /*private*/ ModeImpl createModeImpl(String JavaDoc name, int kind, int state, boolean permanent) {
486         if(name == null) {
487             name = ModeImpl.getUnusedModeName();
488         }
489         ModeImpl toReturn = ModeImpl.createModeImpl(name, state, kind, permanent);
490         return toReturn;
491     }
492
493     // XXX
494
/** Gets default mode. */
495     /*private*/ ModeImpl getDefaultEditorMode() {
496         ModeImpl mode = findModeImpl("editor"); // NOI18N
497
if(mode == null) {
498             Logger.getLogger(WindowManagerImpl.class.getName()).log(Level.INFO, null,
499                               new java.lang.IllegalStateException JavaDoc("Creating default editor mode. It shouldn\'t happen this way")); // NOI18N
500
// PENDING should be defined in winsys layer?
501
ModeImpl newMode = createModeImpl("editor", Constants.MODE_KIND_EDITOR, true); // NOI18N
502
addMode(newMode, new SplitConstraint[0]);
503             return newMode;
504         } else {
505             return mode;
506         }
507     }
508     
509     // XXX
510
/** Gets default view mode. */
511     ModeImpl getDefaultViewMode() {
512         ModeImpl mode = findModeImpl("explorer"); // NOI18N
513
if(mode == null) {
514             Logger.getLogger(WindowManagerImpl.class.getName()).log(Level.INFO, null,
515                               new java.lang.IllegalStateException JavaDoc("Creating default view mode. It shouldn\'t happen this way")); // NOI18N
516
// PENDING should be defined in winsys layer?
517
ModeImpl newMode = createModeImpl("explorer", Constants.MODE_KIND_VIEW, true); // NOI18N
518
addMode(newMode, new SplitConstraint[] {
519                 new SplitConstraint(Constants.VERTICAL, 0, 0.7D),
520                 new SplitConstraint(Constants.HORIZONTAL, 0, 0.25D)
521             });
522             return newMode;
523         } else {
524             return mode;
525         }
526     }
527     
528     /** Gets default sliding view mode. */
529     ModeImpl getDefaultSlidingMode() {
530         ModeImpl mode = findModeImpl("sliding"); // NOI18N
531
if(mode == null) {
532             Logger.getLogger(WindowManagerImpl.class.getName()).log(Level.INFO, null,
533                               new java.lang.IllegalStateException JavaDoc("Creating default sliding mode. It shouldn\'t happen this way")); // NOI18N
534
// PENDING should be defined in winsys layer?
535
ModeImpl newMode = createModeImpl("sliding", Constants.MODE_KIND_SLIDING, true); // NOI18N
536
addMode(newMode, new SplitConstraint[] {
537                 new SplitConstraint(Constants.VERTICAL, 0, 0.7D),
538                 new SplitConstraint(Constants.HORIZONTAL, 0, 0.25D)
539             });
540             return newMode;
541         } else {
542             return mode;
543         }
544     }
545     
546     private ModeImpl findModeImpl(String JavaDoc name) {
547         if(name == null) {
548             // PENDING log something?
549
return null;
550         }
551         
552         for(Iterator it = getModes().iterator(); it.hasNext(); ) {
553             ModeImpl mode = (ModeImpl)it.next();
554             if (name.equals(mode.getName())) {
555                 return mode;
556             }
557         }
558         
559         return null;
560     }
561     
562     // XXX PENDING see WindowManager
563
public TopComponent getSelectedTopComponent(Mode mode) {
564         return central.getModeSelectedTopComponent((ModeImpl)mode);
565     }
566     
567     public Rectangle getMainWindowBoundsJoined() {
568         return central.getMainWindowBoundsJoined();
569     }
570     
571     public void setMainWindowBoundsJoined(Rectangle bounds) {
572         central.setMainWindowBoundsJoined(bounds);
573     }
574     
575     public Rectangle getMainWindowBoundsSeparated() {
576         return central.getMainWindowBoundsSeparated();
577     }
578     
579     public void setMainWindowBoundsSeparated(Rectangle bounds) {
580         central.setMainWindowBoundsSeparated(bounds);
581     }
582     
583     public int getMainWindowFrameStateJoined() {
584         return central.getMainWindowFrameStateJoined();
585     }
586     
587     public void setMainWindowFrameStateJoined(int frameState) {
588         central.setMainWindowFrameStateJoined(frameState);
589     }
590     
591     public int getMainWindowFrameStateSeparated() {
592         return central.getMainWindowFrameStateSeparated();
593     }
594     
595     public void setMainWindowFrameStateSeparated(int frameState) {
596         central.setMainWindowFrameStateSeparated(frameState);
597     }
598     
599     
600     /** Gets active mode.
601      * @return active mode */

602     public ModeImpl getActiveMode () {
603         return central.getActiveMode();
604     }
605     
606     /** Sets active mode.
607      * @param current active mode */

608     public void setActiveMode(ModeImpl activeMode) {
609         central.setActiveMode(activeMode);
610     }
611     
612     public void setEditorAreaBounds(Rectangle editorAreaBounds) {
613         central.setEditorAreaBounds(editorAreaBounds);
614     }
615     
616     public Rectangle getEditorAreaBounds() {
617         return central.getEditorAreaBounds();
618     }
619
620     /** Sets editor area constraints. */
621     public void setEditorAreaConstraints(SplitConstraint[] editorAreaConstraints) {
622         central.setEditorAreaConstraints(editorAreaConstraints);
623     }
624     
625     public java.awt.Component JavaDoc getEditorAreaComponent() {
626         return central.getEditorAreaComponent();
627     }
628     
629     /** Gets editor area constraints. */
630     public SplitConstraint[] getEditorAreaConstraints() {
631         return central.getEditorAreaConstraints();
632     }
633     
634     /** Sets editor area state. */
635     public void setEditorAreaState(int editorAreaState) {
636         setEditorAreaStateImpl(editorAreaState);
637     }
638     
639     // XXX
640
void setEditorAreaStateImpl(int editorAreaState) {
641         central.setEditorAreaState(editorAreaState);
642     }
643     
644     public int getEditorAreaState() {
645         return central.getEditorAreaState();
646     }
647     
648     public void setEditorAreaFrameState(int editorAreaFrameState) {
649         central.setEditorAreaFrameState(editorAreaFrameState);
650     }
651     
652     public int getEditorAreaFrameState() {
653         return central.getEditorAreaFrameState();
654     }
655     
656     /**
657      * Sets new maximized mode or cancels the current one.
658      * @param newMaximizedMode Mode to set as the maximized one or null to cancel the current one.
659      */

660     public void switchMaximizedMode(ModeImpl newMaximizedMode) {
661         central.switchMaximizedMode(newMaximizedMode);
662     }
663     
664     /** Sets editor mode that is currenlty maximized (used when the window system loads) */
665     public void setEditorMaximizedMode(ModeImpl editorMaximizedMode) {
666         central.setEditorMaximizedMode(editorMaximizedMode);
667     }
668     
669     /** Sets view mode that is currenlty maximized (used when the window system loads) */
670     public void setViewMaximizedMode(ModeImpl viewMaximizedMode) {
671         central.setViewMaximizedMode(viewMaximizedMode);
672     }
673     
674     /** Gets mode that is currently maximized. */
675     public ModeImpl getCurrentMaximizedMode() {
676         return central.getCurrentMaximizedMode();
677     }
678     
679     /** Gets editor maximized mode. */
680     public ModeImpl getEditorMaximizedMode() {
681         return central.getEditorMaximizedMode();
682     }
683     
684     /** Gets view maximized mode. */
685     public ModeImpl getViewMaximizedMode() {
686         return central.getViewMaximizedMode();
687     }
688     
689     /** Sets constraints, delegates from ModeImpl. */
690     public void setModeConstraints(ModeImpl mode, SplitConstraint[] modeConstraints) {
691         central.setModeConstraints(mode, modeConstraints);
692     }
693     
694     /** Gets constraints, delegates from ModeImpl. */
695     public SplitConstraint[] getModeConstraints(ModeImpl mode) {
696         return central.getModeConstraints(mode);
697     }
698
699     /** Adds mode. */
700     private void addMode(ModeImpl mode, SplitConstraint[] modeConstraints) {
701         if (mode.getKind() == Constants.MODE_KIND_SLIDING) {
702             // TODO.. where to get the side..
703
central.addSlidingMode(mode, null, Constants.LEFT, null);
704         } else {
705             central.addMode(mode, modeConstraints);
706         }
707     }
708     
709     /** Removes mode. */
710     public void removeMode(ModeImpl mode) {
711         if (mode.getKind() == Constants.MODE_KIND_SLIDING) {
712             
713         } else {
714             central.removeMode(mode);
715         }
716     }
717
718     /** Sets toolbar configuration name. */
719     public void setToolbarConfigName(String JavaDoc toolbarConfigName) {
720         central.setToolbarConfigName(toolbarConfigName);
721     }
722
723     /** Gets toolbar configuration name.
724      * @return toolbar configuration name */

725     public String JavaDoc getToolbarConfigName () {
726         return central.getToolbarConfigName();
727     }
728
729     // Copy from older WorkspaceImpl<<
730

731    
732
733     /** Sets visible or invisible window system GUI. */
734     public void setVisible(boolean visible) {
735         SwingUtilities.invokeLater(exclusive);
736         central.setVisible(visible);
737     }
738     
739     /** Indicates whether windows system shows GUI. */
740     public boolean isVisible() {
741         return central.isVisible();
742     }
743     
744     /** Attaches TopComponent to one side of mode, it removes it from original one. */
745     public void attachTopComponentToSide(TopComponent tc, ModeImpl attachMode, String JavaDoc side) {
746         central.attachTopComponentsToSide(new TopComponent[] {tc}, attachMode, side);
747     }
748     // Utility method <<
749

750     boolean isTopComponentPersistentWhenClosed(TopComponent tc) {
751         // XXX
752
return PersistenceHandler.getDefault().isTopComponentPersistentWhenClosed(tc);
753     }
754     
755     // XXX
756
public TopComponent getTopComponentForID(String JavaDoc tcID) {
757         return PersistenceHandler.getDefault().getTopComponentForID(tcID);
758     }
759     
760     public boolean isTopComponentAllowedToMoveAnywhere(TopComponent tc) {
761         if(Boolean.TRUE.equals(tc.getClientProperty(Constants.TOPCOMPONENT_ALLOW_DOCK_ANYWHERE))) {
762             return true;
763         }
764         
765         return false;
766     }
767     
768     // XXX
769
public ModeImpl findModeForOpenedID(String JavaDoc tcID) {
770         if(tcID == null) {
771             return null;
772         }
773         
774         for(Iterator it = getModes().iterator(); it.hasNext(); ) {
775             ModeImpl mode = (ModeImpl)it.next();
776             
777             if(mode.getOpenedTopComponentsIDs().contains(tcID)) {
778                 return mode;
779             }
780         }
781         
782         return null;
783     }
784     
785     // XXX
786
public ModeImpl findModeForClosedID(String JavaDoc tcID) {
787         if(tcID == null) {
788             return null;
789         }
790         
791         for(Iterator it = getModes().iterator(); it.hasNext(); ) {
792             ModeImpl mode = (ModeImpl)it.next();
793             
794             if(mode.getClosedTopComponentsIDs().contains(tcID)) {
795                 return mode;
796             }
797         }
798         
799         return null;
800     }
801     
802     private static final boolean NAME_HACK = Boolean.getBoolean("nb.tabnames.html"); //NOI18N
803

804     /** Helper method to retrieve some form of display name of TopComponent.
805      * First tries TopComponent's getHtmlDisplayName, if is it null then continues
806      * with getDisplayName and getName in this order.
807      *
808      * @param tc TopComponent to retrieve display name from. May be null.
809      * @return TopComponent's display name or null if no display name available
810      * or null TopComponent is given
811      */

812     public String JavaDoc getTopComponentDisplayName(TopComponent tc) {
813         if(tc == null) {
814             return null;
815         }
816         String JavaDoc displayName = tc.getHtmlDisplayName();
817         if (displayName == null) {
818             displayName = tc.getDisplayName();
819         }
820         if (displayName == null) {
821             displayName = tc.getName();
822         }
823         if (NAME_HACK && displayName != null) {
824             //THIS IS FOR DEMO PURPOSES ONLY! A PROPER API IS NEEDED
825
//(TopComponent.getHtmlDisplayName()), OR
826
//HTML SHOULD BE PRE-SUPPLIED
827
if (displayName.endsWith("*")) {
828                 
829                 if (displayName.startsWith("<html>")) {
830                     displayName = displayName.substring(6);
831                 }
832                 
833                 displayName = "<html><b>" +
834                     displayName.substring(0, displayName.length()-2);
835                 
836             } else {
837                 
838                 int i = displayName.indexOf ("[r/o]");
839                 if (i > 0) {
840                     
841                     if (displayName.startsWith("<html>")) {
842                         displayName = displayName.substring(6);
843                         i -= 6;
844                     }
845
846                     int roLength = "[r/o]".length();
847                     String JavaDoc nuName = "<html><font color='#555555'><i>" + //NOI18N
848
displayName.substring (0, i-1);
849                     if (i + roLength < displayName.length()) {
850                         nuName += displayName.substring(i + roLength);
851                     }
852                     displayName = nuName;
853                 }
854             }
855         }
856         return displayName;
857     }
858     
859     // PENDING for ModeImpl only.
860
Central getCentral() {
861         return central;
862     }
863
864     // XXX
865
public boolean isDragInProgress() {
866         return central.isDragInProgress();
867     }
868     
869     /** Analyzes bounds of given top component and finds appropriate side
870      * of desktop for sliding for given top component.
871      *
872      * @param tc top component to find side for sliding for
873      * @return side where top component should live in sliding state
874      * @see Constants.LEFT
875      */

876     public String JavaDoc guessSlideSide(TopComponent tc) {
877         return central.guessSlideSide(tc);
878     }
879
880     /**
881      * {@inheritDoc}
882      */

883     public boolean isDocked (TopComponent comp) {
884         return central.isDocked(comp);
885     }
886
887     /** Takes given top component out of the main window and puts it in
888      * new separate floating window.
889      *
890      * @param tc TopComponent to make floating
891      * @param modeKind kind of mode where TopComponent currently lives (before undock)
892      *
893      * @throws IllegalStateException when given top component is already floating
894      */

895     public void userUndockedTopComponent(TopComponent tc, int modeKind) {
896         if (!isDocked(tc)) {
897             throw new IllegalStateException JavaDoc("TopComponent is already in floating state: " + tc);
898         }
899
900         central.userUndockedTopComponent(tc, modeKind);
901     }
902
903     /** Puts given top component back into main window.
904      *
905      * @param tc TopComponent to put back into main window
906      * @param modeKind kind of mode where TopComponent currently lives (before dock)
907      *
908      * @throws IllegalStateException when given top component is already inside main window
909      */

910     public void userDockedTopComponent(TopComponent tc, int modeKind) {
911         if (isDocked(tc)) {
912             throw new IllegalStateException JavaDoc("TopComponent is already inside main window: " + tc);
913         }
914
915         central.userDockedTopComponent(tc, modeKind);
916     }
917
918     // PENDING>>
919
public void setRecentViewList(TopComponent[] tcs) {
920         recentViewList.setTopComponents(tcs);
921     }
922     
923     public TopComponent[] getRecentViewList() {
924         return recentViewList.getTopComponents();
925     }
926     // PENDING<<
927

928     void doFirePropertyChange(final String JavaDoc propName,
929     final Object JavaDoc oldValue, final Object JavaDoc newValue) {
930         // PENDING When #37529 finished, then uncomment the next row and move the
931
// checks of AWT thread away.
932
// WindowManagerImpl.assertEventDispatchThread();
933
if(SwingUtilities.isEventDispatchThread()) {
934             changeSupport.firePropertyChange(propName, oldValue, newValue);
935         } else {
936             SwingUtilities.invokeLater(new Runnable JavaDoc() {
937                 public void run() {
938                     changeSupport.firePropertyChange(propName, oldValue, newValue);
939                 }
940             });
941         }
942     }
943
944     // PENDING used in persistence only, revise how to restrict its usage only there.
945
/** Gets persistence observer. */
946     public org.netbeans.core.windows.persistence.PersistenceObserver getPersistenceObserver() {
947         return PersistenceHandler.getDefault();
948     }
949
950     
951     /////////////////////////
952
// Notifications>>
953
public void notifyTopComponentOpened(TopComponent tc) {
954         // Inform component instance.
955
componentOpenNotify(tc);
956         // then let others know that top component was opened...
957
notifyRegistryTopComponentOpened(tc);
958     }
959     
960     public void notifyTopComponentClosed(TopComponent tc) {
961         // Inform component instance.
962
componentCloseNotify(tc);
963         // let others know that top component was closed...
964
notifyRegistryTopComponentClosed(tc);
965     }
966     // Notifications<<
967
/////////////////////////
968

969     /////////////////////////////
970
// Registry notifications
971
static void notifyRegistryTopComponentActivated(final TopComponent tc) {
972         ((RegistryImpl)getDefault().getRegistry()).topComponentActivated(tc);
973
974         
975         // #37457 It is needed to ensure the activation calls are in AWT thread.
976
if(SwingUtilities.isEventDispatchThread()) {
977             WindowManagerImpl.getInstance().activateComponent(tc);
978         } else {
979             SwingUtilities.invokeLater(new Runnable JavaDoc() {
980                 public void run() {
981                     WindowManagerImpl.getInstance().activateComponent(tc);
982                 }
983             });
984         }
985     }
986     
987     private static void notifyRegistryTopComponentOpened(TopComponent tc) {
988         ((RegistryImpl)getDefault().getRegistry()).topComponentOpened(tc);
989     }
990     
991     private static void notifyRegistryTopComponentClosed(TopComponent tc) {
992         ((RegistryImpl)getDefault().getRegistry()).topComponentClosed(tc);
993     }
994     
995     private static void notifyRegistrySelectedNodesChanged(TopComponent tc, Node[] nodes) {
996         ((RegistryImpl)getDefault().getRegistry()).selectedNodesChanged(tc, nodes);
997     }
998     // Registry notifications
999
/////////////////////////////
1000

1001    /** Overrides superclass method, to enhance access modifier. */
1002    public void componentShowing(TopComponent tc) {
1003        if((tc != null) && (tc != persistenceShowingTC)) {
1004            super.componentShowing(tc);
1005        }
1006    }
1007    
1008    /** XXX - Hack for 40237, should be changed to fix real reason of 37188
1009     * timing of activate events */

1010    void specialPersistenceCompShow(TopComponent tc) {
1011        componentShowing(tc);
1012        persistenceShowingTC = tc;
1013    }
1014    
1015    /** Overrides superclass method, to enhance access modifier. */
1016    public void componentHidden(TopComponent tc) {
1017        if(tc != null) {
1018            super.componentHidden(tc);
1019            if (tc == persistenceShowingTC) {
1020                persistenceShowingTC = null;
1021            }
1022        }
1023    }
1024
1025    
1026    // Manipulating methods (overriding the superclass dummy ones) >>
1027
protected void topComponentOpen(TopComponent tc) {
1028        assertEventDispatchThreadWeak();
1029        
1030        if (tc == null) {
1031            throw new IllegalArgumentException JavaDoc ("Cannot open a null " +
1032                "TopComponent"); //NOI18N
1033
}
1034        
1035        
1036        ModeImpl mode = getMode(tc);
1037        
1038        if(mode == null) {
1039            mode = getDefaultEditorMode();
1040            if (tc.getClientProperty (Constants.TOPCOMPONENT_ALLOW_DOCK_ANYWHERE) == null) {
1041                tc.putClientProperty (Constants.TOPCOMPONENT_ALLOW_DOCK_ANYWHERE, Boolean.TRUE);
1042            }
1043        }
1044        boolean alreadyOpened = mode.getOpenedTopComponents().contains( tc );
1045
1046        // XXX PENDING If necessary, unmaximize the state, but exclude sliding modes
1047
// Consider to put it in addOpenedTopComponent, to do it in one step.
1048
ModeImpl maximizedMode = getCurrentMaximizedMode();
1049        if(maximizedMode != null && mode != maximizedMode
1050           && mode.getKind() != Constants.MODE_KIND_SLIDING
1051           && central.isViewMaximized() ) {
1052            switchMaximizedMode(null);
1053        }
1054
1055        mode.addOpenedTopComponent(tc);
1056        
1057        if( central.isEditorMaximized()
1058                && !alreadyOpened
1059                && mode.getState() != Constants.MODE_STATE_SEPARATED ) {
1060            //the editor is maximized so the newly opened TopComponent should slide out
1061
String JavaDoc tcID = findTopComponentID( tc );
1062            if( !isTopComponentDockedInMaximizedMode( tcID ) && mode.getKind() != Constants.MODE_KIND_SLIDING ) {
1063                //slide the TopComponent to edgebar and slide it out
1064
central.slide( tc, mode, central.getSlideSideForMode( mode ) );
1065
1066                topComponentRequestActive( tc );
1067            }
1068        }
1069    }
1070    
1071    protected void topComponentClose(TopComponent tc) {
1072        assertEventDispatchThreadWeak();
1073        
1074        boolean opened = topComponentIsOpened(tc);
1075        if(!opened) {
1076            return;
1077        }
1078
1079        ModeImpl mode = getModeForOpenedTopComponent(tc);
1080        if(mode != null) {
1081            mode.close(tc);
1082        }
1083    }
1084    
1085    protected void topComponentRequestActive(TopComponent tc) {
1086        assertEventDispatchThreadWeak();
1087        
1088        ModeImpl mode = getModeForOpenedTopComponent(tc);
1089        if(mode != null) {
1090            central.activateModeTopComponent(mode, tc);
1091        }
1092    }
1093    
1094    protected void topComponentRequestVisible(TopComponent tc) {
1095        assertEventDispatchThreadWeak();
1096        
1097        ModeImpl mode = getModeForOpenedTopComponent(tc);
1098        if(mode != null) {
1099            central.setModeSelectedTopComponent(mode, tc);
1100        }
1101    }
1102
1103    protected void topComponentDisplayNameChanged(TopComponent tc, String JavaDoc displayName) {
1104        assertEventDispatchThreadWeak();
1105        
1106        ModeImpl mode = getModeForOpenedTopComponent(tc);
1107        if(mode != null) {
1108            central.topComponentDisplayNameChanged(mode, tc);
1109        }
1110    }
1111    
1112    protected void topComponentHtmlDisplayNameChanged(TopComponent tc, String JavaDoc htmlDisplayName) {
1113        // do the same thing as for display name, we can because string param is ignored
1114
topComponentDisplayNameChanged(tc, null);
1115    }
1116    
1117    protected void topComponentToolTipChanged(TopComponent tc, String JavaDoc toolTip) {
1118        assertEventDispatchThreadWeak();
1119        
1120        ModeImpl mode = getModeForOpenedTopComponent(tc);
1121        if(mode != null) {
1122            central.topComponentToolTipChanged(mode, tc);
1123        }
1124    }
1125    
1126    protected void topComponentIconChanged(TopComponent tc, Image icon) {
1127        assertEventDispatchThreadWeak();
1128        
1129        ModeImpl mode = getModeForOpenedTopComponent(tc);
1130        if(mode != null) {
1131            central.topComponentIconChanged(mode, tc);
1132        }
1133    }
1134
1135    protected void topComponentActivatedNodesChanged(TopComponent tc, Node[] activatedNodes) {
1136        assertEventDispatchThreadWeak();
1137        
1138        notifyRegistrySelectedNodesChanged(tc, activatedNodes);
1139    }
1140    
1141    protected boolean topComponentIsOpened(TopComponent tc) {
1142        assertEventDispatchThreadWeak();
1143        
1144        return getModeForOpenedTopComponent(tc) != null;
1145    }
1146    
1147    protected Action[] topComponentDefaultActions(TopComponent tc) {
1148        assertEventDispatchThreadWeak();
1149        
1150        return ActionUtils.createDefaultPopupActions(tc);
1151    }
1152    
1153    protected String JavaDoc topComponentID (TopComponent tc, String JavaDoc preferredID) {
1154        assertEventDispatchThreadWeak();
1155        
1156        if (preferredID == null) {
1157            Logger.getLogger(WindowManagerImpl.class.getName()).log(Level.WARNING, null,
1158                              new java.lang.IllegalStateException JavaDoc("Assertion failed. " +
1159                                                                  tc.getClass().getName() +
1160                                                                  ".preferredID method shouldn\'t be overriden to return null. " +
1161                                                                  "Please change your impl to return non-null string.")); // NOI18N
1162
}
1163        
1164        return PersistenceManager.getDefault().getGlobalTopComponentID(tc, preferredID);
1165    }
1166
1167    @Override JavaDoc
1168    public void invokeWhenUIReady(Runnable JavaDoc run) {
1169        exclusive.register(run);
1170    }
1171    
1172    @Override JavaDoc
1173    public boolean isEditorTopComponent( TopComponent tc ) {
1174        for( Iterator it = getModes().iterator(); it.hasNext(); ) {
1175            ModeImpl mode = (ModeImpl)it.next();
1176            
1177            if( mode.containsTopComponent( tc ) ) {
1178                return isEditorMode( mode );
1179            }
1180        }
1181
1182        //unknown TopComponent
1183
return false;
1184    }
1185    
1186    @Override JavaDoc
1187    public boolean isEditorMode( Mode mode ) {
1188        ModeImpl modeImpl = findModeImpl( mode.getName() );
1189        return null != modeImpl && modeImpl.getKind() == Constants.MODE_KIND_EDITOR;
1190    }
1191
1192    /** Handles exclusive invocation of Runnables.
1193     */

1194    private static final class Exclusive implements Runnable JavaDoc {
1195        /** lists of runnables to run */
1196        private ArrayList<Runnable JavaDoc> arr = new ArrayList<Runnable JavaDoc>();
1197
1198        /** Registers given runnable and ensures that it is run when UI
1199         * of the system is ready.
1200         */

1201        public synchronized void register(Runnable JavaDoc r) {
1202            arr.add(r);
1203            SwingUtilities.invokeLater(this);
1204        }
1205
1206        public void run() {
1207            if (!WindowManagerImpl.getInstance().isVisible()) {
1208                return;
1209            }
1210            
1211            ArrayList<Runnable JavaDoc> arrCopy = null;
1212            synchronized (this) {
1213                if (arr.isEmpty()) {
1214                    return;
1215                }
1216                
1217                arrCopy = arr;
1218                arr = new ArrayList<Runnable JavaDoc>();
1219            }
1220
1221            for (Runnable JavaDoc r : arrCopy) {
1222                try {
1223                    r.run();
1224                } catch (RuntimeException JavaDoc ex) {
1225                    Logger.getLogger(WindowManagerImpl.class.getName()).log(
1226                            Level.WARNING, null, ex);
1227                }
1228            }
1229        }
1230    } // end of Exclusive class
1231

1232    public void resetModel() {
1233        central.resetModel();
1234        RegistryImpl rimpl = (RegistryImpl)componentRegistry();
1235        rimpl.clear();
1236    }
1237    
1238    // Manipulating methods (overriding the superclass dummy ones) <<
1239

1240    /** Helper only. */
1241    private ModeImpl getMode(TopComponent tc) {
1242        return (ModeImpl)findMode(tc);
1243    }
1244
1245    // #37561
1246
/** Helper only */
1247    private ModeImpl getModeForOpenedTopComponent(TopComponent tc) {
1248        if(tc == null) {
1249            // Log something?
1250
return null;
1251        }
1252        
1253        for(Iterator it = getModes().iterator(); it.hasNext(); ) {
1254            ModeImpl mode = (ModeImpl)it.next();
1255            
1256            if(mode.getOpenedTopComponents().contains(tc)) {
1257                return mode;
1258            }
1259        }
1260        
1261        return null;
1262    }
1263    
1264    /**
1265     * @return The mode where the given TopComponent had been before it was moved to sliding or separate mode.
1266     */

1267    public ModeImpl getPreviousModeForTopComponent(String JavaDoc tcID, ModeImpl slidingMode) {
1268        return getCentral().getModeTopComponentPreviousMode(tcID, slidingMode);
1269    }
1270    
1271    /**
1272     * @return The position (tab index) of the given TopComponent before it was moved to sliding or separate mode.
1273     */

1274    public int getPreviousIndexForTopComponent(String JavaDoc tcID, ModeImpl slidingMode) {
1275        return getCentral().getModeTopComponentPreviousIndex(tcID, slidingMode);
1276    
1277    }
1278    
1279    /**
1280     * Remember the mode and position where the given TopComponent was before moving into sliding or separate mode.
1281     *
1282     * @param tcID TopComponent's id
1283     * @param currentSlidingMode The mode where the TopComponent is at the moment.
1284     * @param prevMode The mode where the TopComponent had been before it was moved to the sliding mode.
1285     * @param prevIndex Tab index of the TopComponent before it was moved to the new mode.
1286     */

1287    public void setPreviousModeForTopComponent(String JavaDoc tcID, ModeImpl slidingMode, ModeImpl prevMode, int prevIndex) {
1288        getCentral().setModeTopComponentPreviousMode(tcID, slidingMode, prevMode, prevIndex);
1289    }
1290    
1291    /**
1292     * Set the state of the TopComponent when the editor is maximized.
1293     *
1294     * @param tcID TopComponent id
1295     * @param docked True if the TopComponent should stay docked in maximized editor mode,
1296     * false if it should slide out when the editor is maximized.
1297     */

1298    public void setTopComponentDockedInMaximizedMode( String JavaDoc tcID, boolean docked ) {
1299        getCentral().setTopComponentDockedInMaximizedMode( tcID, docked );
1300    }
1301    
1302    /**
1303     * Get the state of the TopComponent when the editor is maximized.
1304     *
1305     * @param tcID TopComponent id.
1306     * @return True if the TopComponent should stay docked in maximized editor mode,
1307     * false if it should slide out when the editor is maximized.
1308     */

1309    public boolean isTopComponentDockedInMaximizedMode( String JavaDoc tcID ) {
1310        return getCentral().isTopComponentDockedInMaximizedMode( tcID );
1311    }
1312    
1313    /**
1314     * Set the state of the TopComponent when no mode is maximized.
1315     *
1316     * @param tcID TopComponent id
1317     * @param slided True if the TopComponent is slided in the default mode,
1318     * false if it is docked.
1319     */

1320    public void setTopComponentSlidedInDefaultMode( String JavaDoc tcID, boolean slided ) {
1321        getCentral().setTopComponentSlidedInDefaultMode( tcID, slided );
1322    }
1323    
1324    /**
1325     * Get the state of the TopComponent when no mode is maximized.
1326     *
1327     * @param tcID TopComponent id.
1328     * @return True if the TopComponent is slided in the default mode,
1329     * false if it is docked.
1330     */

1331    public boolean isTopComponentSlidedInDefaultMode( String JavaDoc tcID ) {
1332        return getCentral().isTopComponentSlidedInDefaultMode( tcID );
1333    }
1334    
1335    /**
1336     * Get the state of the TopComponent when it is slided-in.
1337     *
1338     * @param tcID TopComponent id.
1339     * @return true if the TopComponent is maximized when slided-in.
1340     */

1341    public boolean isTopComponentMaximizedWhenSlidedIn( String JavaDoc tcID ) {
1342        return getCentral().isTopComponentMaximizedWhenSlidedIn( tcID );
1343    }
1344    
1345    /**
1346     * Set the state of the TopComponent when it is slided-in.
1347     *
1348     * @param tcID TopComponent id.
1349     * @param maximized true if the TopComponent is maximized when slided-in.
1350     */

1351    public void setTopComponentMaximizedWhenSlidedIn( String JavaDoc tcID, boolean maximized ) {
1352        getCentral().setTopComponentMaximizedWhenSlidedIn( tcID, maximized );
1353    }
1354    
1355    public void userToggledTopComponentSlideInMaximize( String JavaDoc tcID ) {
1356        getCentral().userToggledTopComponentSlideInMaximize( tcID );
1357    }
1358
1359    /** Finds out if given Window is used as separate floating window or not.
1360     *
1361     * @return true if Window is separate floating window, false if window
1362     * is used for other purposes such as independent dialog/window, main window etc.
1363     */

1364    public static boolean isSeparateWindow (Window w) {
1365        // work only in Swing environment
1366
if (!(w instanceof RootPaneContainer)) {
1367            return false;
1368        }
1369        // #85089 - getRootPane may return null in some edge situations
1370
JRootPane rp = ((RootPaneContainer) w).getRootPane();
1371        if (rp == null) {
1372            return false;
1373        }
1374        return rp.getClientProperty(Constants.SEPARATE_WINDOW_PROPERTY) != null;
1375    }
1376
1377    private static final String JavaDoc ASSERTION_ERROR_MESSAGE = "WindowsAPI is required to be called from AWT thread only, see " // NOI18N
1378
+ "http://core.netbeans.org/proposals/threading/"; // NOI18N
1379

1380    static void assertEventDispatchThread() {
1381        assert SwingUtilities.isEventDispatchThread() : ASSERTION_ERROR_MESSAGE;
1382    }
1383
1384    // PENDING Just temporary until all 'bad' calls are really put into AWT thread.
1385
static void assertEventDispatchThreadWeak() {
1386        if(!SwingUtilities.isEventDispatchThread()) {
1387            Logger.getLogger(WindowManagerImpl.class.getName()).log(Level.WARNING, null,
1388                              new java.lang.IllegalStateException JavaDoc("Assertion failed. " +
1389                                                                  ASSERTION_ERROR_MESSAGE)); // NOI18N
1390
}
1391    }
1392
1393    /**
1394     * @return An array of TopComponents that are opened in editor modes (i.e. editor windows).
1395     */

1396    public TopComponent[] getEditorTopComponents() {
1397        ArrayList<TopComponent> editors = new ArrayList<TopComponent>();
1398        Set<? extends Mode> modes = getModes();
1399        for(Mode mode: modes) {
1400            ModeImpl modeImpl = findModeImpl( mode.getName() ); // XXX probably useless
1401
if( modeImpl.getKind() == Constants.MODE_KIND_EDITOR ) {
1402                editors.addAll( modeImpl.getOpenedTopComponents() );
1403            }
1404        }
1405        return editors.toArray( new TopComponent[editors.size()] );
1406    }
1407
1408    /**
1409     * @return TopComponent that is selected in an arbitrary editor-type mode
1410     * or null if editor mode(s) is empty.
1411     */

1412    public TopComponent getArbitrarySelectedEditorTopComponent() {
1413        Set modes = getModes();
1414        for( Iterator i=modes.iterator(); i.hasNext(); ) {
1415            Mode mode = (Mode)i.next();
1416            ModeImpl modeImpl = findModeImpl( mode.getName() );
1417            if( modeImpl.getKind() == Constants.MODE_KIND_EDITOR ) {
1418                return mode.getSelectedTopComponent();
1419            }
1420        }
1421        return null;
1422    }
1423
1424    /**
1425     * Send componentHidden() event to all selected TopComponents in editor modes.
1426     */

1427    public void deselectEditorTopComponents() {
1428        Set modes = getModes();
1429        for( Iterator i=modes.iterator(); i.hasNext(); ) {
1430            Mode mode = (Mode)i.next();
1431            ModeImpl modeImpl = findModeImpl( mode.getName() );
1432            if( modeImpl.getKind() == Constants.MODE_KIND_EDITOR ) {
1433                //not a pretty hack - add an empty TopComponent into the mode
1434
//and make it the selected one so that componentHidden() gets called
1435
//on the previously selected TopComponent
1436
TopComponent dummy = new DummyTopComponent();
1437                modeImpl.addOpenedTopComponent( dummy );
1438                modeImpl.setSelectedTopComponent( dummy );
1439            }
1440        }
1441    }
1442
1443    /**
1444     * Calls close() on all TopComponents that are opened in noneditor-type modes.
1445     *
1446     */

1447    public void closeNonEditorViews() {
1448        Set modes = getModes();
1449        for( Iterator i=modes.iterator(); i.hasNext(); ) {
1450            Mode mode = (Mode)i.next();
1451            ModeImpl modeImpl = findModeImpl( mode.getName() );
1452            if( null != modeImpl && modeImpl.getKind() != Constants.MODE_KIND_EDITOR ) {
1453                java.util.List JavaDoc tcs = modeImpl.getOpenedTopComponents();
1454                for( Iterator j=tcs.iterator(); j.hasNext(); ) {
1455                    TopComponent tc = (TopComponent)j.next();
1456                    tc.close();
1457                }
1458            }
1459        }
1460    }
1461    
1462    /**
1463     * An empty TopComponent needed for deselectEditorTopComponents()
1464     */

1465    private static class DummyTopComponent extends TopComponent {
1466        protected String JavaDoc preferredID() {
1467            return "temp";
1468        }
1469
1470        public int getPersistenceType() {
1471            return PERSISTENCE_NEVER;
1472        }
1473    }
1474}
1475
1476
Popular Tags