KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > guards > Editor


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 package org.netbeans.modules.java.guards;
20
21 import java.beans.PropertyChangeListener JavaDoc;
22 import java.beans.VetoableChangeListener JavaDoc;
23 import java.io.ByteArrayInputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.OutputStream JavaDoc;
27 import java.util.Date JavaDoc;
28 import javax.swing.text.BadLocationException JavaDoc;
29 import javax.swing.text.EditorKit JavaDoc;
30 import javax.swing.text.StyledDocument JavaDoc;
31 import org.netbeans.spi.editor.guards.GuardedEditorSupport;
32 import org.openide.text.CloneableEditorSupport;
33 import org.openide.windows.CloneableOpenSupport;
34
35 /**
36  * minimal impl of an editor support
37  */

38 final class Editor implements GuardedEditorSupport {
39     
40     CloneableEditorSupport support = new EditorSupport();
41     InputStream JavaDoc is = null;
42     StyledDocument JavaDoc doc = null;
43     
44     /**
45      * here you can pass document content
46      */

47     public void setStringContent(String JavaDoc txt) {
48         is = new ByteArrayInputStream JavaDoc(txt.getBytes());
49     }
50     
51     public StyledDocument JavaDoc getDocument() {
52         return doc;
53     }
54     
55     class EditorSupport extends CloneableEditorSupport {
56         
57         EditorSupport() {
58             super(new CESEnv());
59         }
60         
61         protected String JavaDoc messageSave() {
62             throw new UnsupportedOperationException JavaDoc();
63         }
64         
65         protected String JavaDoc messageName() {
66             return "";
67         }
68         
69         protected String JavaDoc messageToolTip() {
70             throw new UnsupportedOperationException JavaDoc();
71         }
72         
73         protected String JavaDoc messageOpening() {
74             throw new UnsupportedOperationException JavaDoc();
75         }
76         
77         protected String JavaDoc messageOpened() {
78             throw new UnsupportedOperationException JavaDoc();
79         }
80         
81         protected void loadFromStreamToKit(StyledDocument JavaDoc doc, InputStream JavaDoc stream, EditorKit JavaDoc kit)
82         throws IOException JavaDoc, BadLocationException JavaDoc {
83             Editor.this.doc = doc;
84             kit.read(stream, doc, 0);
85         }
86         
87     }
88     
89     class CESEnv implements CloneableEditorSupport.Env {
90         public InputStream JavaDoc inputStream() throws IOException JavaDoc {
91             return Editor.this.is;
92         }
93         
94         public OutputStream JavaDoc outputStream() throws IOException JavaDoc {
95             throw new UnsupportedOperationException JavaDoc();
96         }
97         
98         public Date JavaDoc getTime() {
99             throw new UnsupportedOperationException JavaDoc();
100         }
101         
102         public String JavaDoc getMimeType() {
103             return "text/x-java";
104         }
105         
106         public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
107         }
108         
109         public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
110         }
111         
112         public void addVetoableChangeListener(VetoableChangeListener JavaDoc l) {
113         }
114         
115         public void removeVetoableChangeListener(VetoableChangeListener JavaDoc l) {
116         }
117         
118         public boolean isValid() {
119             return true;
120         }
121         
122         public boolean isModified() {
123             throw new UnsupportedOperationException JavaDoc();
124         }
125         
126         public void markModified() throws IOException JavaDoc {
127             throw new UnsupportedOperationException JavaDoc();
128         }
129         
130         public void unmarkModified() {
131             throw new UnsupportedOperationException JavaDoc();
132         }
133         
134         public CloneableOpenSupport findCloneableOpenSupport() {
135             return Editor.this.support;
136         }
137         
138     }
139     
140 }
Popular Tags