Text Component Display
/*
Core SWING Advanced Programming
By Kim Topley
ISBN: 0 13 083292 8
Publisher: Prentice Hall
*/
import javax.swing.UIManager;
import javax.swing.text.*;
import javax.swing.plaf.*;
import java.io.*;
public class TextComponentDisplay {
public static void displayModel(JTextComponent comp,
PrintStream out) {
Document doc = comp.getDocument();
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).dump(out);
}
}
public static void displayViews(JTextComponent comp,
PrintStream out) {
TextUI textUI = (TextUI)comp.getUI();
View rootView = textUI.getRootView(comp);
displayView(rootView, 0, out);
}
public static void displayView(View view, int tabs,
PrintStream out) {
// Print info about this view
for (int i = 0; i < tabs; i++) {
out.print("\t");
}
out.println(view.getClass().getName());
for (int i = 0; i < tabs; i++) {
out.print("\t");
}
out.println("Start: " + view.getStartOffset() +
"; end: " + view.getEndOffset());
// Display child views, if any.
int childViews = view.getViewCount();
for (int i = 0; i < childViews ; i++) {
View childView = view.getView(i);
displayView(childView, tabs + 1, out);
}
}
}
Related examples in the same category