List of usage examples for javax.swing.text View getEndOffset
public int getEndOffset()
From source file:TextFieldViews.java
public static void displayView(View view, int indent, Document doc, PrintStream out) { String name = view.getClass().getName(); for (int i = 0; i < indent; i++) { out.print("\t"); }//from w ww .java 2 s . c o m int start = view.getStartOffset(); int end = view.getEndOffset(); out.println(name + "; offsets [" + start + ", " + end + "]"); int viewCount = view.getViewCount(); if (viewCount == 0) { int length = Math.min(32, end - start); try { String txt = doc.getText(start, length); for (int i = 0; i < indent + 1; i++) { out.print("\t"); } out.println("[" + txt + "]"); } catch (BadLocationException e) { } } else { for (int i = 0; i < viewCount; i++) { displayView(view.getView(i), indent + 1, doc, out); } } }
From source file:ShowHTMLViews.java
public static void displayView(View view, int indent, Document doc, PrintStream out) { String name = view.getClass().getName(); for (int i = 0; i < indent; i++) { out.print(" "); }/*from w w w . j a v a 2 s .c om*/ int start = view.getStartOffset(); int end = view.getEndOffset(); out.println(name + "; offsets [" + start + ", " + end + "]"); for (int i = 0; i < indent; i++) { out.print(" "); } HTMLDocDisplay.displayAttributes(view.getAttributes(), indent, out); int viewCount = view.getViewCount(); if (viewCount == 0) { int length = Math.min(32, end - start); try { String txt = doc.getText(start, length); for (int i = 0; i < indent + 1; i++) { out.print(" "); } out.println("[" + txt + "]"); } catch (BadLocationException e) { } } else { for (int i = 0; i < viewCount; i++) { displayView(view.getView(i), indent + 1, doc, out); } } out.println(""); }
From source file:TextComponentDisplay.java
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"); }//w w w . j av a 2 s.c o m 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); } }
From source file:Main.java
@Override public Shape paintLayer(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c, View view) { g.setColor(color == null ? c.getSelectionColor() : color); Rectangle rect = null;/* w ww. j a v a 2 s .c o m*/ if (offs0 == view.getStartOffset() && offs1 == view.getEndOffset()) { if (bounds instanceof Rectangle) { rect = (Rectangle) bounds; } else { rect = bounds.getBounds(); } } else { try { Shape shape = view.modelToView(offs0, Position.Bias.Forward, offs1, Position.Bias.Backward, bounds); rect = (shape instanceof Rectangle) ? (Rectangle) shape : shape.getBounds(); } catch (BadLocationException e) { return null; } } FontMetrics fm = c.getFontMetrics(c.getFont()); int baseline = rect.y + rect.height - fm.getDescent() + 1; g.drawLine(rect.x, baseline, rect.x + rect.width, baseline); g.drawLine(rect.x, baseline + 1, rect.x + rect.width, baseline + 1); return rect; }