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: package org.netbeans.modules.vmd.screen;
042:
043: import org.netbeans.modules.vmd.api.io.DataObjectContext;
044: import org.netbeans.modules.vmd.api.io.DesignDocumentAwareness;
045: import org.netbeans.modules.vmd.api.io.IOUtils;
046: import org.netbeans.modules.vmd.api.io.ProjectUtils;
047: import org.netbeans.modules.vmd.api.io.javame.MidpProjectPropertiesSupport;
048: import org.netbeans.modules.vmd.api.model.DesignDocument;
049:
050: import javax.swing.*;
051: import java.awt.*;
052:
053: /**
054: * @author David Kaspar
055: */
056: public class ScreenViewController implements DesignDocumentAwareness {
057:
058: public static final String SCREEN_ID = "screen"; // NOI18N
059:
060: private DesignDocument designDocument;
061:
062: private JPanel visual;
063: private JToolBar toolbar;
064:
065: private JComponent loadingPanel;
066:
067: public ScreenViewController(DataObjectContext context) {
068: loadingPanel = IOUtils.createLoadingPanel();
069:
070: visual = new JPanel();
071: visual.setLayout(new BorderLayout());
072: toolbar = new JToolBar();
073: toolbar.setFloatable(false);
074:
075: context.addDesignDocumentAwareness(this );
076: }
077:
078: public JComponent getVisualRepresentation() {
079: return visual;
080: }
081:
082: public JComponent getToolbarRepresentation() {
083: return toolbar;
084: }
085:
086: public void setDesignDocument(final DesignDocument newDesignDocument) {
087: IOUtils.runInAWTNoBlocking(new Runnable() {
088: public void run() {
089: if (designDocument != null) {
090: ScreenAccessController accessController = designDocument
091: .getListenerManager().getAccessController(
092: ScreenAccessController.class);
093: if (accessController != null)
094: accessController.hideNotify();
095: }
096: toolbar.removeAll();
097: visual.removeAll();
098:
099: designDocument = newDesignDocument;
100:
101: final ScreenAccessController accessController = designDocument != null ? designDocument
102: .getListenerManager().getAccessController(
103: ScreenAccessController.class)
104: : null;
105: if (accessController != null) {
106: accessController.showNotify();
107: final DataObjectContext context = ProjectUtils
108: .getDataObjectContextForDocument(designDocument);
109: if (context != null) {
110: designDocument.getTransactionManager()
111: .readAccess(new Runnable() {
112: public void run() {
113: accessController
114: .setScreenSize(MidpProjectPropertiesSupport
115: .getDeviceScreenSizeFromProject(context));
116: }
117: });
118: }
119: visual.add(new JScrollPane(accessController
120: .getMainPanel()), BorderLayout.CENTER);
121:
122: JToolBar.Separator separator = new JToolBar.Separator();
123: separator.setOrientation(JSeparator.VERTICAL);
124: toolbar.add(separator);
125:
126: toolbar.add(accessController.getToolBar());
127: } else {
128: visual.add(loadingPanel, BorderLayout.CENTER);
129: }
130: toolbar.validate();
131: visual.validate();
132: }
133: });
134: }
135:
136: public void setScreenSize(final Dimension deviceScreenSize) {
137: IOUtils.runInAWTNoBlocking(new Runnable() {
138: public void run() {
139: if (designDocument != null) {
140: designDocument.getTransactionManager().readAccess(
141: new Runnable() {
142: public void run() {
143: ScreenAccessController accessController = designDocument
144: .getListenerManager()
145: .getAccessController(
146: ScreenAccessController.class);
147: if (accessController != null)
148: accessController
149: .setScreenSize(deviceScreenSize);
150: }
151: });
152: }
153: }
154: });
155: }
156: }
|