KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > text > SimpleCESHidden


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
20
21 package org.openide.text;
22
23
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.beans.VetoableChangeListener JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.OutputStream JavaDoc;
29 import java.util.Date JavaDoc;
30
31 import org.openide.filesystems.FileObject;
32 import org.openide.text.CloneableEditorSupport;
33 import org.openide.windows.CloneableOpenSupport;
34
35
36 /**
37  * Empty implementstion of <code>CloneableEditorSupport</code>.
38  * Helper test class. It's used by regression test.
39  * deadlock from bug #12557.
40  *
41  * @author Peter Zavadsky
42  */

43 public class SimpleCESHidden extends CloneableEditorSupport {
44     
45     private FileObject fo;
46
47     public SimpleCESHidden(Env env) {
48         super(env);
49         
50         this.fo = env.fo;
51     }
52         
53     /** Message to display when an object is being opened.
54      * @return the message or null if nothing should be displayed
55     */

56     protected String JavaDoc messageOpening() {
57         return "Opening " + fo.getName();
58     }
59     
60     /** Message to display when an object has been opened.
61      * @return the message or null if nothing should be displayed
62      */

63     protected String JavaDoc messageOpened() {
64         return "Opened " + fo.getName();
65     }
66     
67     /** Constructs message that should be used to name the editor component.
68      *
69      * @return name of the editor
70      */

71     protected String JavaDoc messageName() {
72         return fo.getName();
73     }
74     
75     /** Constructs message that should be displayed when the data object
76      * is modified and is being closed.
77      *
78      * @return text to show to the user
79      */

80     protected String JavaDoc messageSave() {
81         return fo.getName() + "*";
82     }
83     
84     /** Text to use as tooltip for component.
85      *
86      * @return text to show to the user
87      */

88     protected String JavaDoc messageToolTip() {
89         return fo.getNameExt();
90     }
91
92     
93     /** Helper Env implementation. */
94     public static class Env extends Object JavaDoc implements CloneableEditorSupport.Env {
95             
96         /** object to serialize and be connected to*/
97         private FileObject fo;
98
99         /** Reference to support instance. */
100         private CloneableOpenSupport support;
101         
102
103         /** Constructor. Attaches itself as listener to
104         * the data object so, all property changes of the data object
105         * are also rethrown to own listeners.
106         *
107         * @param obj data object to be attached to
108         */

109         public Env (FileObject fo) {
110             this.fo = fo;
111         }
112
113
114         public void setSupport(CloneableOpenSupport support) {
115             this.support = support;
116         }
117         
118         /** Method that allows environment to find its
119          * cloneable open support.
120          * @return the support or null if the environemnt is not in valid
121          * state and the CloneableOpenSupport cannot be found for associated
122          * data object
123          */

124         public CloneableOpenSupport findCloneableOpenSupport() {
125             return support;
126         }
127         
128         /** Obtains the input stream.
129          * @exception IOException if an I/O error occures
130          */

131         public InputStream JavaDoc inputStream () throws IOException JavaDoc {
132             return fo.getInputStream();
133         }
134
135         /** Obtains the output stream.
136          * @exception IOException if an I/O error occures
137          */

138         public OutputStream JavaDoc outputStream () throws IOException JavaDoc {
139             return fo.getOutputStream(fo.lock());
140         }
141
142         /** The time when the data has been modified */
143         public Date JavaDoc getTime () {
144             return null;
145         }
146
147         /** Mime type of the document.
148         * @return the mime type to use for the document
149         */

150         public String JavaDoc getMimeType () {
151             return fo.getMIMEType();
152         }
153         
154         /** Adds property listener.
155         */

156         public void addPropertyChangeListener (PropertyChangeListener JavaDoc l) {
157         }
158         
159         /** Removes property listener.
160         */

161         public void removePropertyChangeListener (PropertyChangeListener JavaDoc l) {
162         }
163
164         /** Adds veto listener.
165         */

166         public void addVetoableChangeListener (VetoableChangeListener JavaDoc l) {
167         }
168         /** Removes veto listener.
169         */

170         public void removeVetoableChangeListener (VetoableChangeListener JavaDoc l) {
171         }
172
173         /** Test whether the support is in valid state or not.
174         * It could be invalid after deserialization when the object it
175         * referenced to does not exist anymore.
176         *
177         * @return true or false depending on its state
178         */

179         public boolean isValid () {
180             return fo.isValid();
181         }
182         
183         /** Test whether the object is modified or not.
184         * @return true if the object is modified
185         */

186         public boolean isModified () {
187             return false;
188         }
189
190         /** Support for marking the environement modified.
191         * @exception IOException if the environment cannot be marked modified
192         * (for example when the file is readonly), when such exception
193         * is the support should discard all previous changes
194         */

195         public void markModified () throws java.io.IOException JavaDoc {}
196
197         /** Reverse method that can be called to make the environment
198         * unmodified.
199         */

200         public void unmarkModified () {}
201
202     } // End of Env class.
203
}
204
Popular Tags