1 19 20 package org.netbeans.modules.xml.text.completion; 21 22 import java.awt.Color ; 23 24 import org.netbeans.modules.xml.api.model.*; 25 import javax.swing.text.JTextComponent ; 26 import javax.swing.text.Caret ; 27 28 34 class ElementResultItem extends XMLResultItem { 35 36 private final boolean startElement; 39 40 private final boolean empty; 41 42 45 public ElementResultItem(GrammarResult res){ 46 super(res.getNodeName()); 47 foreground = Color.blue; 48 startElement = true; 49 empty = res.isEmptyElement(); 50 } 51 52 55 public ElementResultItem(String name) { 56 super(name); 57 foreground = Color.blue; 58 startElement = false; 59 empty = false; 60 } 61 62 66 public String getReplacementText(int modifiers) { 67 boolean shift = (modifiers & java.awt.event.InputEvent.SHIFT_MASK) != 0; 68 69 if (shift && startElement) { 70 if (empty) { 71 return displayText + "/>"; 72 } else { 73 return displayText + ">"; 74 } 75 } else if (startElement) { 76 return displayText; 77 } else { 78 return displayText + '>'; 79 } 80 } 81 82 83 87 public boolean substituteText( JTextComponent c, int offset, int len, int modifiers ){ 88 String replacementText = getReplacementText(modifiers); 89 replaceText(c, replacementText, offset, len); 90 91 boolean shift = (modifiers & java.awt.event.InputEvent.SHIFT_MASK) != 0; 92 93 if (shift && startElement) { 94 Caret caret = c.getCaret(); int dot = caret.getDot(); 96 int rlen = replacementText.length(); 97 if (empty) { 98 caret.setDot((dot - rlen) + replacementText.indexOf('/')); 99 } 100 } 101 102 return false; 103 } 104 105 108 111 Color getPaintColor() { return Color.blue; } 112 } 113 | Popular Tags |