1 19 20 package org.openide.text; 21 22 23 import java.beans.*; 24 import java.io.*; 25 import java.util.*; 26 import javax.swing.JEditorPane ; 27 import org.netbeans.junit.NbTestCase; 28 import org.openide.util.Exceptions; 29 import org.openide.util.Lookup; 30 import org.openide.util.io.NbMarshalledObject; 31 import org.openide.windows.*; 32 33 public class CloneableEditorTest extends NbTestCase 34 implements CloneableEditorSupport.Env { 35 36 private transient CES support; 37 38 private transient String content = ""; 40 private transient boolean valid = true; 41 private transient boolean modified = false; 42 43 private transient String cannotBeModified; 44 private transient Date date = new Date (); 45 private transient List propL = new ArrayList (); 46 private transient VetoableChangeListener vetoL; 47 48 private static CloneableEditorTest RUNNING; 49 50 public CloneableEditorTest(String s) { 51 super(s); 52 } 53 54 protected void setUp () { 55 support = new CES (this, Lookup.EMPTY); 56 RUNNING = this; 57 } 58 59 protected boolean runInEQ() { 60 return true; 61 } 62 63 private Object writeReplace () { 64 return new Replace (); 65 } 66 67 public void testGetOpenedPanesWorksAfterDeserializationIssue39236 () throws Exception { 68 support.open (); 69 70 CloneableEditor ed = (CloneableEditor)support.getRef ().getAnyComponent (); 71 72 JEditorPane [] panes = support.getOpenedPanes (); 73 assertNotNull (panes); 74 assertEquals ("One is there", 1, panes.length); 75 76 NbMarshalledObject obj = new NbMarshalledObject (ed); 77 ed.close (); 78 79 panes = support.getOpenedPanes (); 80 assertNull ("No panes anymore", panes); 81 82 ed = (CloneableEditor)obj.get (); 83 84 panes = support.getOpenedPanes (); 85 assertNotNull ("One again", panes); 86 assertEquals ("One is there again", 1, panes.length); 87 } 88 89 public void testEditorPaneActionMapIsParentOfCloneableEditorActionMap() { 90 support.open(); 91 92 CloneableEditor ed = (CloneableEditor)support.getRef().getArbitraryComponent(); 93 94 assertSame(ed.getEditorPane().getActionMap(), ed.getActionMap().getParent()); 95 } 96 97 98 102 public synchronized void addPropertyChangeListener(PropertyChangeListener l) { 103 propL.add (l); 104 } 105 public synchronized void removePropertyChangeListener(PropertyChangeListener l) { 106 propL.remove (l); 107 } 108 109 public synchronized void addVetoableChangeListener(VetoableChangeListener l) { 110 assertNull ("This is the first veto listener", vetoL); 111 vetoL = l; 112 } 113 public void removeVetoableChangeListener(VetoableChangeListener l) { 114 assertEquals ("Removing the right veto one", vetoL, l); 115 vetoL = null; 116 } 117 118 public CloneableOpenSupport findCloneableOpenSupport() { 119 return RUNNING.support; 120 } 121 122 public String getMimeType() { 123 return "text/plain"; 124 } 125 126 public Date getTime() { 127 return date; 128 } 129 130 public InputStream inputStream() throws IOException { 131 return new ByteArrayInputStream (content.getBytes ()); 132 } 133 public OutputStream outputStream() throws IOException { 134 class ContentStream extends ByteArrayOutputStream { 135 public void close () throws IOException { 136 super.close (); 137 content = new String (toByteArray ()); 138 } 139 } 140 141 return new ContentStream (); 142 } 143 144 public boolean isValid() { 145 return valid; 146 } 147 148 public boolean isModified() { 149 return modified; 150 } 151 152 public void markModified() throws IOException { 153 if (cannotBeModified != null) { 154 final String notify = cannotBeModified; 155 IOException e = new IOException () { 156 public String getLocalizedMessage () { 157 return notify; 158 } 159 }; 160 Exceptions.attachLocalizedMessage(e, cannotBeModified); 161 throw e; 162 } 163 164 modified = true; 165 } 166 167 public void unmarkModified() { 168 modified = false; 169 } 170 171 172 private static final class CES extends CloneableEditorSupport { 173 public CES (Env env, Lookup l) { 174 super (env, l); 175 } 176 177 public CloneableTopComponent.Ref getRef () { 178 return allEditors; 179 } 180 181 protected String messageName() { 182 return "Name"; 183 } 184 185 protected String messageOpened() { 186 return "Opened"; 187 } 188 189 protected String messageOpening() { 190 return "Opening"; 191 } 192 193 protected String messageSave() { 194 return "Save"; 195 } 196 197 protected String messageToolTip() { 198 return "ToolTip"; 199 } 200 201 } 202 203 private static final class Replace implements Serializable { 204 public Object readResolve () { 205 return RUNNING; 206 } 207 } 208 } 209 | Popular Tags |