1 19 package org.netbeans.modules.java.guards; 20 21 import java.beans.PropertyChangeListener ; 22 import java.beans.VetoableChangeListener ; 23 import java.io.ByteArrayInputStream ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 import java.util.Date ; 28 import javax.swing.text.BadLocationException ; 29 import javax.swing.text.EditorKit ; 30 import javax.swing.text.StyledDocument ; 31 import org.netbeans.spi.editor.guards.GuardedEditorSupport; 32 import org.openide.text.CloneableEditorSupport; 33 import org.openide.windows.CloneableOpenSupport; 34 35 38 final class Editor implements GuardedEditorSupport { 39 40 CloneableEditorSupport support = new EditorSupport(); 41 InputStream is = null; 42 StyledDocument doc = null; 43 44 47 public void setStringContent(String txt) { 48 is = new ByteArrayInputStream (txt.getBytes()); 49 } 50 51 public StyledDocument getDocument() { 52 return doc; 53 } 54 55 class EditorSupport extends CloneableEditorSupport { 56 57 EditorSupport() { 58 super(new CESEnv()); 59 } 60 61 protected String messageSave() { 62 throw new UnsupportedOperationException (); 63 } 64 65 protected String messageName() { 66 return ""; 67 } 68 69 protected String messageToolTip() { 70 throw new UnsupportedOperationException (); 71 } 72 73 protected String messageOpening() { 74 throw new UnsupportedOperationException (); 75 } 76 77 protected String messageOpened() { 78 throw new UnsupportedOperationException (); 79 } 80 81 protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit) 82 throws IOException , BadLocationException { 83 Editor.this.doc = doc; 84 kit.read(stream, doc, 0); 85 } 86 87 } 88 89 class CESEnv implements CloneableEditorSupport.Env { 90 public InputStream inputStream() throws IOException { 91 return Editor.this.is; 92 } 93 94 public OutputStream outputStream() throws IOException { 95 throw new UnsupportedOperationException (); 96 } 97 98 public Date getTime() { 99 throw new UnsupportedOperationException (); 100 } 101 102 public String getMimeType() { 103 return "text/x-java"; 104 } 105 106 public void addPropertyChangeListener(PropertyChangeListener l) { 107 } 108 109 public void removePropertyChangeListener(PropertyChangeListener l) { 110 } 111 112 public void addVetoableChangeListener(VetoableChangeListener l) { 113 } 114 115 public void removeVetoableChangeListener(VetoableChangeListener l) { 116 } 117 118 public boolean isValid() { 119 return true; 120 } 121 122 public boolean isModified() { 123 throw new UnsupportedOperationException (); 124 } 125 126 public void markModified() throws IOException { 127 throw new UnsupportedOperationException (); 128 } 129 130 public void unmarkModified() { 131 throw new UnsupportedOperationException (); 132 } 133 134 public CloneableOpenSupport findCloneableOpenSupport() { 135 return Editor.this.support; 136 } 137 138 } 139 140 } | Popular Tags |