KickJava   Java API By Example, From Geeks To Geeks.

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


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.FileInputStream JavaDoc;
27 import java.io.FileOutputStream JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.OutputStream JavaDoc;
31 import java.io.StringBufferInputStream JavaDoc;
32 import java.util.Date JavaDoc;
33
34 import org.openide.text.CloneableEditorSupport;
35 import org.openide.text.CloneableEditor;
36 import org.openide.text.Line;
37 import org.openide.windows.CloneableOpenSupport;
38 import org.openide.windows.CloneableTopComponent;
39
40
41 /**
42  * Empty implementstion of <code>CloneableEditorSupport</code>.
43  * Helper test class. Is used by regression test TextTest to reproduce
44  * deadlock from bug #10449.
45  *
46  * @author Marek Slama, Yarda Tulach
47  */

48 public class EmptyCESHidden extends CloneableEditorSupport {
49
50     private Line.Set pls;
51
52     public EmptyCESHidden(CloneableEditorSupport.Env env) {
53         super (env);
54         pls = getLineSet();
55     }
56         
57     /** A method to create a new component. Must be overridden in subclasses.
58      * @return the cloneable top component for this support
59     */

60     protected CloneableTopComponent createCloneableTopComponent() {
61         // initializes the document if not initialized
62
prepareDocument ();
63         
64         Thread JavaDoc tstThread = new Thread JavaDoc
65         (new Runnable JavaDoc() {
66             public void run() {
67                 synchronized (new java.awt.Panel JavaDoc().getTreeLock()) {
68                 System.out.println(System.currentTimeMillis() + " Thread runs");
69                 pls.getOriginal(0);
70                 System.out.println(System.currentTimeMillis() + " Thread finish");
71                 }
72             }
73         },"Test"
74         );
75         
76         tstThread.start();
77
78         System.out.println(System.currentTimeMillis() + " Main sleeping");
79         try {
80             Thread.sleep(500);
81         } catch (InterruptedException JavaDoc e) {
82         }
83         System.out.println(System.currentTimeMillis() + " Main wakeuped");
84         
85         CloneableEditor ed = createCloneableEditor ();
86         initializeCloneableEditor (ed);
87         return ed;
88     }
89     
90     /** Message to display when an object is being opened.
91      * @return the message or null if nothing should be displayed
92     */

93     protected String JavaDoc messageOpening() {
94         return "Test Opening";
95     }
96     
97     /** Message to display when an object has been opened.
98      * @return the message or null if nothing should be displayed
99     */

100     protected String JavaDoc messageOpened() {
101         return "Test Opened";
102     }
103     
104     /** Constructs message that should be used to name the editor component.
105      *
106      * @return name of the editor
107  */

108     protected String JavaDoc messageName() {
109         return "Test Name";
110     }
111     
112     /** Constructs message that should be displayed when the data object
113      * is modified and is being closed.
114      *
115      * @return text to show to the user
116  */

117     protected String JavaDoc messageSave() {
118         return "Test Save";
119     }
120     
121     /** Text to use as tooltip for component.
122      *
123      * @return text to show to the user
124  */

125     protected String JavaDoc messageToolTip() {
126         return "Test Tool Tip";
127     }
128     
129     public static class Env implements CloneableEditorSupport.Env {
130         
131         private StringBufferInputStream JavaDoc input;
132         private FileOutputStream JavaDoc outFile;
133         private CloneableOpenSupport tstInst;
134         
135         public void setInstance(CloneableOpenSupport tst) {
136             tstInst = tst;
137         }
138         
139         /** Support for marking the environement modified.
140          * @exception IOException if the environment cannot be marked modified
141          * (for example when the file is readonly), when such exception
142          * is the support should discard all previous changes
143  */

144         public void markModified() throws java.io.IOException JavaDoc {
145         }
146         
147         /** Reverse method that can be called to make the environment
148          * unmodified.
149  */

150         public void unmarkModified() {
151         }
152         
153         /** Removes property listener.
154  */

155         public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
156         }
157         
158         /** Test whether the object is modified or not.
159          * @return true if the object is modified
160  */

161         public boolean isModified() {
162             return false;
163         }
164         
165         /** Removes veto listener.
166          */

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

176         public boolean isValid() {
177             return true;
178         }
179         
180         /** Adds veto listener.
181         */

182         public void addVetoableChangeListener(VetoableChangeListener JavaDoc l) {
183         }
184         
185         /** Adds property listener.
186         */

187         public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
188         }
189         
190         /** Method that allows environment to find its
191          * cloneable open support.
192          */

193         public CloneableOpenSupport findCloneableOpenSupport() {
194             return tstInst;
195         }
196         
197         /** The time when the data has been modified
198          */

199         public Date JavaDoc getTime() {
200             return null;
201         }
202         
203         /** Obtains the output stream.
204          * @exception IOException if an I/O error occures
205          */

206         public OutputStream JavaDoc outputStream() throws IOException JavaDoc {
207             if (outFile == null) {
208                 outFile = new FileOutputStream JavaDoc("outFile");
209             }
210             return outFile;
211         }
212         
213         /** Mime type of the document.
214          * @return the mime type to use for the document
215          */

216         public String JavaDoc getMimeType() {
217             return "text/plain";
218         }
219         
220         /** Obtains the input stream.
221          * @exception IOException if an I/O error occures
222          */

223         public InputStream JavaDoc inputStream() throws IOException JavaDoc {
224             if (input == null) {
225                 input = new StringBufferInputStream JavaDoc("Test text");
226             }
227             return input;
228         }
229         
230     }
231 }
232
Popular Tags