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.DataEditorView;
044: import org.netbeans.modules.vmd.api.io.DataObjectContext;
045: import org.netbeans.modules.vmd.api.io.javame.DeviceListener;
046: import org.netbeans.modules.vmd.api.io.javame.MidpProjectPropertiesSupport;
047: import org.openide.awt.UndoRedo;
048: import org.openide.util.HelpCtx;
049: import org.openide.util.NbBundle;
050:
051: import javax.swing.*;
052: import java.io.IOException;
053: import java.util.Collection;
054: import java.util.Collections;
055:
056: /**
057: * @author David Kaspar
058: */
059: // TODO - reload screen designer only when it is visible
060: public class ScreenEditorView implements DataEditorView, DeviceListener {
061:
062: private static final long serialVersionUID = -1;
063:
064: public static final String SCREEN_EDITOR_VIEW_DISPLAY_NAME = NbBundle
065: .getMessage(ScreenEditorView.class, "TITLE_ScreenView"); // NOI18N
066:
067: private DataObjectContext context;
068: private transient ScreenViewController controller;
069:
070: public ScreenEditorView(DataObjectContext context) {
071: this .context = context;
072: init();
073: }
074:
075: private void init() {
076: controller = new ScreenViewController(context);
077: }
078:
079: public DataObjectContext getContext() {
080: return context;
081: }
082:
083: public Kind getKind() {
084: return Kind.MODEL;
085: }
086:
087: public boolean canShowSideWindows() {
088: return true;
089: }
090:
091: public Collection<String> getTags() {
092: return Collections.emptySet();
093: }
094:
095: public String preferredID() {
096: return ScreenViewController.SCREEN_ID;
097: }
098:
099: public String getDisplayName() {
100: return SCREEN_EDITOR_VIEW_DISPLAY_NAME;
101: }
102:
103: public HelpCtx getHelpCtx() {
104: return new HelpCtx(ScreenEditorView.class);
105: }
106:
107: public JComponent getVisualRepresentation() {
108: return controller.getVisualRepresentation();
109: }
110:
111: public JComponent getToolbarRepresentation() {
112: return controller.getToolbarRepresentation();
113: }
114:
115: public UndoRedo getUndoRedo() {
116: return null;
117: }
118:
119: public void componentOpened() {
120: }
121:
122: public void componentClosed() {
123: }
124:
125: public void componentShowing() {
126: MidpProjectPropertiesSupport.addDeviceListener(context, this );
127: deviceChanged();
128: }
129:
130: public void componentHidden() {
131: MidpProjectPropertiesSupport.removeDeviceChangedListener(
132: context, this );
133: }
134:
135: public void componentActivated() {
136: }
137:
138: public void componentDeactivated() {
139: }
140:
141: public int getOpenPriority() {
142: return getOrder();
143: }
144:
145: public int getEditPriority() {
146: return -getOrder();
147: }
148:
149: public int getOrder() {
150: return 1000;
151: }
152:
153: public void deviceChanged() {
154: controller.setScreenSize(MidpProjectPropertiesSupport
155: .getDeviceScreenSizeFromProject(context));
156: }
157:
158: private void writeObject(java.io.ObjectOutputStream out)
159: throws IOException {
160: out.writeObject(context);
161: }
162:
163: private void readObject(java.io.ObjectInputStream in)
164: throws IOException, ClassNotFoundException {
165: Object object = in.readObject();
166: if (!(object instanceof DataObjectContext))
167: throw new ClassNotFoundException(
168: "DataObjectContext expected but not found"); // NOI18N
169: context = (DataObjectContext) object;
170: init();
171: }
172:
173: }
|