001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.vmd.game;
043:
044: import java.awt.BorderLayout;
045: import java.awt.GridBagLayout;
046: import java.util.Collection;
047: import javax.swing.JComponent;
048: import javax.swing.JLabel;
049: import javax.swing.JPanel;
050: import javax.swing.JScrollPane;
051: import org.netbeans.modules.vmd.api.model.DesignComponent;
052: import org.netbeans.modules.vmd.api.model.DesignDocument;
053: import org.netbeans.modules.vmd.api.model.common.ActiveDocumentSupport;
054: import org.netbeans.modules.vmd.game.model.Editable;
055: import org.netbeans.modules.vmd.game.model.EditorManagerListener;
056: import org.netbeans.modules.vmd.game.model.GlobalRepository;
057: import org.netbeans.spi.navigator.NavigatorPanel;
058: import org.openide.util.Lookup;
059: import org.openide.util.NbBundle;
060:
061: /**
062: *
063: * @author Karel Herink
064: */
065: public class GameBuilderNavigator extends JPanel implements
066: NavigatorPanel, EditorManagerListener {
067:
068: private final static boolean DEBUG = false;
069:
070: private GlobalRepository gameDesign;
071: private ADSL listener;
072:
073: public GameBuilderNavigator() {
074: this .setNavigator(null);
075: this .listener = new ADSL();
076: }
077:
078: public String getDisplayName() {
079: return NbBundle.getMessage(GameBuilderNavigator.class,
080: "GameBuilderNavigator.DisplayName");
081: }
082:
083: public String getDisplayHint() {
084: return NbBundle.getMessage(GameBuilderNavigator.class,
085: "GameBuilderNavigator.DisplayHint");
086: }
087:
088: public JComponent getComponent() {
089: return this ;
090: }
091:
092: public void panelActivated(Lookup context) {
093: if (DEBUG)
094: System.out.println("panelActivated()"); // NOI18N
095: ActiveDocumentSupport.getDefault().addActiveDocumentListener(
096: this .listener);
097:
098: final JComponent[] navigator = { null };
099: final DesignDocument doc = ActiveDocumentSupport.getDefault()
100: .getActiveDocument();
101: if (DEBUG)
102: System.out.println("\tActive document: " + doc); // NOI18N
103: if (doc == null)
104: return;
105: doc.getTransactionManager().readAccess(new Runnable() {
106: public void run() {
107: GameAccessController controller = doc
108: .getListenerManager().getAccessController(
109: GameAccessController.class);
110: if (controller == null)
111: return;
112: GameBuilderNavigator.this .gameDesign = controller
113: .getGameDesign();
114: if (DEBUG)
115: System.out.println("\t\t gameDesign = "
116: + controller.getGameDesign()); // NOI18N
117: GameBuilderNavigator.this .gameDesign.getMainView()
118: .addEditorManagerListener(
119: GameBuilderNavigator.this );
120: Editable editable = GameBuilderNavigator.this .gameDesign
121: .getMainView().getCurrentEditable();
122: if (editable == null) {
123: return;
124: }
125: navigator[0] = editable.getNavigator();
126: }
127: });
128: this .setNavigator(navigator[0]);
129: }
130:
131: public void panelDeactivated() {
132: ActiveDocumentSupport.getDefault()
133: .removeActiveDocumentListener(this .listener);
134: }
135:
136: public Lookup getLookup() {
137: return null;
138: }
139:
140: private void setNavigator(JComponent navigator) {
141: if (DEBUG)
142: System.out.println("setNavigator: " + navigator); // NOI18N
143: this .removeAll();
144: if (navigator != null) {
145: this .setLayout(new BorderLayout());
146: this .add(new JScrollPane(navigator), BorderLayout.CENTER);
147: } else {
148: this .setLayout(new GridBagLayout());
149: this .add(new JLabel(NbBundle.getMessage(
150: GameBuilderNavigator.class,
151: "GameBuilderNavigator.no_structure_lbl")));
152: }
153: this .validate();
154: this .repaint();
155: }
156:
157: public void editing(Editable editable) {
158: if (DEBUG)
159: System.out.println("\tediting: " + editable); // NOI18N
160: this .setNavigator(editable.getNavigator());
161: }
162:
163: private class ADSL implements ActiveDocumentSupport.Listener {
164: public void activeDocumentChanged(
165: DesignDocument deactivatedDocument,
166: final DesignDocument activatedDocument) {
167: if (DEBUG)
168: System.out.println("activeDocumentChanged: "
169: + activatedDocument); // NOI18N
170: if (deactivatedDocument == activatedDocument)
171: return;
172: if (activatedDocument == null) {
173: setNavigator(null);
174: return;
175: }
176: final JComponent[] navigator = { null };
177: activatedDocument.getTransactionManager().readAccess(
178: new Runnable() {
179: public void run() {
180: GameAccessController controller = activatedDocument
181: .getListenerManager()
182: .getAccessController(
183: GameAccessController.class);
184: GameBuilderNavigator.this .gameDesign = controller
185: .getGameDesign();
186: GameBuilderNavigator.this .gameDesign
187: .getMainView()
188: .addEditorManagerListener(
189: GameBuilderNavigator.this );
190: Editable editable = GameBuilderNavigator.this .gameDesign
191: .getMainView().getCurrentEditable();
192: if (editable == null)
193: return;
194: navigator[0] = editable.getNavigator();
195: }
196: });
197: GameBuilderNavigator.this .setNavigator(navigator[0]);
198:
199: }
200:
201: public void activeComponentsChanged(
202: Collection<DesignComponent> activeComponents) {
203: }
204: }
205:
206: }
|