1 19 20 package org.netbeans.modules.tasklist.javaparser; 21 22 import javax.swing.text.*; 23 import javax.swing.event.*; 24 import java.awt.*; 25 import java.awt.event.*; 26 import javax.swing.*; 27 import org.openide.ErrorManager; 28 import org.openide.explorer.view.*; 29 import org.openide.nodes.*; 30 import org.netbeans.modules.java.*; 31 32 import org.openide.loaders.DataObject; 33 import org.openide.text.Line; 34 35 import org.netbeans.editor.ext.java.*; 36 import org.netbeans.modules.editor.java.*; 37 38 import org.netbeans.modules.tasklist.core.ConfPanel; 39 import org.netbeans.modules.tasklist.core.TLUtils; 40 import org.netbeans.modules.tasklist.client.Suggestion; 41 import org.netbeans.modules.tasklist.client.SuggestionPerformer; 42 43 44 56 class CastPerformer implements SuggestionPerformer { 57 58 private int column; 59 private Line line; 60 private DataObject dobj; 61 private Document doc; 62 private String reqType; 63 private String reqClass; 64 private String beforeDesc; 65 66 CastPerformer(int column, Line line, DataObject dobj, 67 Document doc, 68 String reqType, 69 String reqClass, 70 String beforeDesc) { 71 this.column = column; 72 this.line = line; 73 this.dobj = dobj; 74 this.doc = doc; 75 this.reqType = reqType; 76 this.reqClass = reqClass; 77 this.beforeDesc = beforeDesc; 78 } 79 80 public boolean hasConfirmation() { 81 return true; 82 } 83 84 public Object getConfirmation(Suggestion s) { 85 String filename = 86 dobj.getPrimaryFile().getNameExt(); 87 StringBuffer sb = new StringBuffer (200); 88 Line l = line; 89 String text = l.getText(); 90 91 sb.append("<html>"); TLUtils.appendSurroundingLine(sb, l, -1); 94 TLUtils.appendHTMLString(sb, text.substring(0, column)); 95 sb.append("<b>("); sb.append(reqClass); 97 sb.append(")</b>"); TLUtils.appendHTMLString(sb, text.substring(column)); 99 TLUtils.appendSurroundingLine(sb, l, +1); 101 sb.append("</html>"); String beforeContents = sb.toString(); 103 int lineno = line.getLineNumber(); 104 return new ConfPanel(beforeDesc, beforeContents, null, 105 null, filename, lineno, null); 106 } 107 108 public void perform(Suggestion s) { 109 if (!(doc instanceof StyledDocument)) { 110 return; 111 } 112 113 int lineno = line.getLineNumber(); 114 StyledDocument sdoc = (StyledDocument)doc; 115 116 Element e = sdoc.getParagraphElement(0).getParentElement(); 117 if (e == null) { 118 e = sdoc.getDefaultRootElement(); 120 } 121 Element elm = e.getElement(lineno); 122 if (elm == null) { 123 return; 124 } 125 int offset = elm.getStartOffset(); 126 127 try { 128 int pos = offset + column; 129 sdoc.insertString(pos, "(" + reqClass + ")", null); 130 131 } catch (BadLocationException ex) { 139 ErrorManager.getDefault().notify(ErrorManager.WARNING, ex); 140 } 141 } 142 } 143 144 | Popular Tags |