| Method from net.sourceforge.jbird.jbedit.HTMLCaretTracker Detail: |
public void actionPerformed(ActionEvent e) {
}
|
public void attachTo(JEditorPane jep) {
detach();
if (jep != null) {
pane = jep;
pane.addCaretListener(this);
}
}
|
public void caretUpdate(CaretEvent e) {
int loc = e.getDot();
HTMLDocument doc = getHTMLDocument(pane);
Element[] change = getElementsAt(doc, loc);
boolean changed = false;
if (current != null &&
change.length == current.length) {
int i = 0;
int max = change.length;
while (i < max && changed == false) {
if (change[i] != current[i]) {
changed = true;
}
i++;
}
} else {
changed = true;
}
if (changed) {
current = change;
notifyListeners();
if (trace) {
dump();
}
}
}
|
public void detach() {
if (pane != null) {
pane.removeCaretListener(this);
pane = null;
}
}
|
public void dump() {
int max = current.length;
int i;
System.out.println(name + " - cursor location");
for (i = 0; i < max; i++) {
if (current[i].isLeaf()) {
dumpRun((HTMLDocument.RunElement)current[i]);
} else {
dumpBranch(
(HTMLDocument.BranchElement)current[i]);
}
}
}
|
protected void dumpAttribs(BranchElement elem) {
AttributeSet as = elem.getAttributes();
Enumeration enum = elem.getAttributeNames();
System.out.println("\t\tAttribute names");
while (enum.hasMoreElements()) {
Object aname = enum.nextElement();
Object attrib = as.getAttribute(aname);
System.out.println("\t\t" + aname +
"\t" + attrib);
}
}
|
protected void dumpBranch(BranchElement elem) {
String rname = elem.getName();
int offset = elem.getStartOffset();
int leng = elem.getEndOffset() - offset;
System.out.println("\tBranchElement name = " +
rname + " offset = " + offset +
" length = " + leng);
System.out.println("\t\tAllowsChildren = " +
elem.getAllowsChildren() +
" ElementCount = " + elem.getElementCount());
try {
String data;
if (leng > 0) {
data = elem.getDocument()
.getText(offset, leng);
if (leng == 1) {
int type = Character.getType(
data.charAt(0));
if (type == Character.CONTROL) {
System.out.println
("\tCharacter.CONTROL");
} else {
System.out.println("\tcharacter = "
+ data);
}
} else {
if (leng < 30) {
System.out.println("\t" + data);
} else {
System.out.println("\t" +
data.substring(0,30)
+ " ...");
}
}
}
}
catch (Exception e) {
System.out.println("\texception = " +
e.getMessage());
}
dumpAttribs(elem);
}
|
protected void dumpRun(HTMLDocument.RunElement elem) {
String rname = elem.getName();
int offset = elem.getStartOffset();
int leng = elem.getEndOffset() - offset;
System.out.println("\tRunElement name = " +
rname + " offset = " + offset +
" length = " + leng);
System.out.println("\t\tAllowsChildren = " +
elem.getAllowsChildren() +
" ElementCount = " + elem.getElementCount());
try {
String data;
if (leng > 0) {
data = elem.getDocument()
.getText(offset, leng);
if (leng == 1) {
int type = Character.getType(
data.charAt(0));
if (type == Character.CONTROL) {
System.out.println
("\tCharacter.CONTROL");
} else {
System.out.println("\tcharacter = "
+ data);
}
} else {
if (leng < 30) {
System.out.println("\t" + data);
} else {
System.out.println("\t" +
data.substring(0,30)
+ " ...");
}
}
}
}
catch (Exception e) {
System.out.println("\texception = " +
e.getMessage());
}
}
|
protected void notifyListeners() {
}
|