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.io.javame;
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.ProjectUtils;
046: import org.openide.awt.UndoRedo;
047: import org.openide.text.CloneableEditor;
048: import org.openide.text.NbDocument;
049: import org.openide.util.HelpCtx;
050:
051: import javax.swing.*;
052: import javax.swing.text.Document;
053: import java.io.IOException;
054: import java.util.Collection;
055: import java.util.Collections;
056:
057: /**
058: * @author David Kaspar
059: */
060: public final class MESourceEditorView implements DataEditorView {
061:
062: private static final long serialVersionUID = -1;
063:
064: static final String VIEW_ID = "source"; // NOI18N
065:
066: private DataObjectContext context;
067: private transient CloneableEditor editor;
068: private transient JComponent toolbar;
069:
070: MESourceEditorView(DataObjectContext context) {
071: this .context = context;
072: init();
073: }
074:
075: private void init() {
076: MEDesignEditorSupport sup = (MEDesignEditorSupport) context
077: .getCloneableEditorSupport();
078: editor = new CloneableEditor(sup);
079: sup.initializeCloneableEditor(editor);
080: }
081:
082: public DataObjectContext getContext() {
083: return context;
084: }
085:
086: public Kind getKind() {
087: return Kind.CODE;
088: }
089:
090: public boolean canShowSideWindows() {
091: return true;
092: }
093:
094: public Collection<String> getTags() {
095: return Collections.emptySet();
096: }
097:
098: public String preferredID() {
099: return VIEW_ID;
100: }
101:
102: public String getDisplayName() {
103: return ProjectUtils.getSourceEditorViewDisplayName();
104: }
105:
106: public HelpCtx getHelpCtx() {
107: return new HelpCtx(MESourceEditorView.class);
108: }
109:
110: public JComponent getVisualRepresentation() {
111: return editor;
112: }
113:
114: public JComponent getToolbarRepresentation() {
115: if (toolbar == null) {
116: JEditorPane pane = editor.getEditorPane();
117: if (pane != null) {
118: Document doc = pane.getDocument();
119: if (doc instanceof NbDocument.CustomToolbar)
120: toolbar = ((NbDocument.CustomToolbar) doc)
121: .createToolbar(pane);
122: }
123: if (toolbar == null)
124: toolbar = new JPanel();
125: }
126: return toolbar;
127: }
128:
129: public UndoRedo getUndoRedo() {
130: return editor.getUndoRedo();
131: }
132:
133: public void componentOpened() {
134: }
135:
136: public void componentClosed() {
137: }
138:
139: public void componentShowing() {
140: }
141:
142: public void componentHidden() {
143: }
144:
145: public void componentActivated() {
146: }
147:
148: public void componentDeactivated() {
149: }
150:
151: public int getOpenPriority() {
152: return getOrder();
153: }
154:
155: public int getEditPriority() {
156: return -getOrder();
157: }
158:
159: public int getOrder() {
160: return -1000;
161: }
162:
163: private void writeObject(java.io.ObjectOutputStream out)
164: throws IOException {
165: out.writeObject(context);
166: }
167:
168: private void readObject(java.io.ObjectInputStream in)
169: throws IOException, ClassNotFoundException {
170: Object object = in.readObject();
171: if (!(object instanceof DataObjectContext))
172: throw new ClassNotFoundException(
173: "DataObjectContext expected but not found"); // NOI18N
174: context = (DataObjectContext) object;
175: init();
176: }
177:
178: }
|