1 19 package org.netbeans.modules.css.actions; 20 21 import java.io.IOException ; 22 import java.text.MessageFormat ; 23 import java.util.*; 24 import java.net.*; 25 26 import org.openide.loaders.DataObject; 27 import org.openide.loaders.DataObjectNotFoundException; 28 import org.openide.text.Line; 29 import org.openide.*; 30 import org.openide.nodes.*; 31 import org.openide.cookies.*; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.URLMapper; 34 import org.openide.windows.*; 35 36 import org.xml.sax.SAXParseException ; 37 38 39 45 public class XMLDisplayer { 46 47 private final String FORMAT = "{0} [{1}] {2}"; 50 51 private InputOutput xmlIO; 52 53 54 private OutputWriter ow = null; 55 56 57 58 public XMLDisplayer() { 59 this(Util.THIS.getString("TITLE_XML_check_window")); 60 } 61 62 protected XMLDisplayer(String tab) { 63 initInputOutput(tab); 64 } 65 66 69 public void display(String msg) { 70 ow.println(msg); 71 } 72 73 76 public void display(String msg, boolean takeFocus) { 77 if (takeFocus) { 78 boolean wasFocusTaken = xmlIO.isFocusTaken(); 79 xmlIO.select(); 80 xmlIO.setFocusTaken(true); 81 ow.println(msg); 82 xmlIO.setFocusTaken(wasFocusTaken); 83 } else { 84 ow.println(msg); 85 } 86 } 87 88 91 public final void moveToFront() { 92 boolean wasFocusTaken = xmlIO.isFocusTaken(); 93 xmlIO.select(); 94 xmlIO.setFocusTaken(true); 95 ow.write("\r"); 96 xmlIO.setFocusTaken(wasFocusTaken); 97 } 98 99 100 public void display(DataObject dobj, SAXParseException sex) { 101 102 105 DataObject actualDataObject = null; 106 try { 107 FileObject[] fos = URLMapper.findFileObjects(new URL(sex.getSystemId())); 108 if (fos.length > 0) { 109 actualDataObject = DataObject.find(fos[0]); 110 } 111 } catch (MalformedURLException ex) { 112 } catch (DataObjectNotFoundException ex) { 114 } 116 117 119 String external = ""; 121 if (actualDataObject == null) { 122 external = sex.getSystemId(); 123 } 124 125 126 display ( 127 actualDataObject, sex.getMessage(), external, 128 new Integer ( sex.getLineNumber() ), 129 new Integer ( sex.getColumnNumber() ) 130 ); 131 } 132 133 134 135 protected void display(DataObject dobj, String message, String ext, Integer line, Integer col) { 136 137 138 Object [] args = new Object [] { 139 message, 140 line, 141 ext 142 }; 143 144 String text = MessageFormat.format(FORMAT, args); 145 146 try { 147 if (dobj == null) throw new IOException ("catchIt"); IOCtl ec = new IOCtl ( 149 dobj, 150 Math.max(line.intValue() - 1, 0), 151 Math.max(col.intValue() - 1, 0) 152 ); 153 ow.println(text, ec); 154 } catch (IOException catchIt) { 155 ow.println(text); } 157 158 } 159 160 163 private void initInputOutput (String name) { 164 if (ow != null) return; 165 xmlIO = IOProvider.getDefault().getIO(name, false); 166 xmlIO.setFocusTaken (false); 167 ow = xmlIO.getOut(); 168 try { 169 ow.reset(); 170 } catch (java.io.IOException ex) { 171 } 173 } 174 175 final class IOCtl implements OutputListener { 176 177 Line xline; 178 179 180 int column; 181 182 189 public IOCtl (DataObject data, int line, int column) 190 throws java.io.IOException { 191 this.column = column; 192 LineCookie cookie = (LineCookie)data.getCookie(LineCookie.class); 193 if (cookie == null) { 194 throw new java.io.FileNotFoundException (); 195 } 196 xline = cookie.getLineSet ().getOriginal (line); 197 } 198 199 public void outputLineSelected (OutputEvent ev) { 200 try { 201 xline.markError(); 202 xline.show(Line.SHOW_TRY_SHOW, column); 203 } catch (IndexOutOfBoundsException ex) { 204 } catch (ClassCastException ex) { 205 } 207 } 208 209 public void outputLineAction (OutputEvent ev) { 210 try { 211 xline.markError(); 212 xline.show(Line.SHOW_GOTO, column); 213 } catch (IndexOutOfBoundsException ex) { 214 } catch (ClassCastException ex) { 215 } 217 } 218 219 public void outputLineCleared (OutputEvent ev) { 220 try { 221 xline.unmarkError(); 222 } catch (IndexOutOfBoundsException ex) { 223 } 224 } 225 } 226 227 } 228 | Popular Tags |