Java Code Examples for javax.swing.text.View#getView()

The following examples show how to use javax.swing.text.View#getView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Baseline.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the baseline for single line text components, like
 * <code>JTextField</code>.
 */
private static int getSingleLineTextBaseline(JTextComponent textComponent, int h) {
	View rootView = textComponent.getUI().getRootView(textComponent);
	if (rootView.getViewCount() > 0) {
		Insets insets = textComponent.getInsets();
		int height = h - insets.top - insets.bottom;
		int y = insets.top;
		View fieldView = rootView.getView(0);
		int vspan = (int) fieldView.getPreferredSpan(View.Y_AXIS);
		if (height != vspan) {
			int slop = height - vspan;
			y += slop / 2;
		}
		FontMetrics fm = textComponent.getFontMetrics(textComponent.getFont());
		y += fm.getAscent();
		return y;
	}
	return -1;
}
 
Example 2
Source File: Utilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static int viewToModel(JTextComponent tc, double x, double y, Position.Bias[] biasReturn) {
int offs = -1;
Document doc = tc.getDocument();
if (doc instanceof AbstractDocument) {
    ((AbstractDocument)doc).readLock();
}
try {
    Rectangle alloc = getVisibleEditorRect(tc);
    if (alloc != null) {
               View rootView = tc.getUI().getRootView(tc);
               View documentView = rootView.getView(0);
               if (documentView instanceof EditorView) {
                   documentView.setSize(alloc.width, alloc.height);
                   offs = ((EditorView) documentView).viewToModelChecked(x, y, alloc, biasReturn);
               } else {
                   rootView.setSize(alloc.width, alloc.height);
                   offs = rootView.viewToModel((float) x, (float) y, alloc, biasReturn);
               }
    }
} finally {
    if (doc instanceof AbstractDocument) {
	((AbstractDocument)doc).readUnlock();
    }
}
       return offs;
   }
 
Example 3
Source File: bug8014863.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example 4
Source File: bug8014863.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example 5
Source File: bug8014863.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example 6
Source File: bug8014863.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example 7
Source File: bug8014863.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example 8
Source File: bug8014863.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example 9
Source File: bug4960629.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void test() {
    View root = ((View)label.getClientProperty(BasicHTML.propertyKey))
            .getView(0);
    int n = root.getViewCount();
    View v  = root.getView(n - 1);
    AttributeSet attrs = v.getAttributes();
    StyleSheet ss = ((HTMLDocument) v.getDocument()).getStyleSheet();
    Font font = ss.getFont(attrs);
    System.out.println(font.getSize());
    passed = (font.getSize() == 12);
    if(!passed) {
        throw new RuntimeException("Test failed.");
    }
}
 
Example 10
Source File: bug8014863.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example 11
Source File: bug8014863.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example 12
Source File: DocumentView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static DocumentView get(JTextComponent component) {
    TextUI textUI = component.getUI();
    if (textUI != null) {
        View rootView = textUI.getRootView(component);
        if (rootView != null && rootView.getViewCount() > 0) {
            View view = rootView.getView(0);
            if (view instanceof DocumentView) {
                return (DocumentView)view;
            }
        }
    }
    return null;
}
 
Example 13
Source File: bug8014863.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example 14
Source File: NumberedParagraphView.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public int getPreviousLineCount0() {
    int lineCount = 0;
    View parent = this.getParent();
    int count = parent.getViewCount();
    for (int i = 0; i < count; i++) {
        if (parent.getView(i) == this) {
            break;
        } else {
            lineCount += parent.getView(i).getViewCount();
        }
    }
    return lineCount;
}
 
Example 15
Source File: ViewUtilitiesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void checkChildrenParent(View v) {
    int cnt = v.getViewCount();
    for (int i = 0; i < cnt; i++) {
        View child = v.getView(i);
        View childParent = child.getParent();
        if (childParent != v) {
            throw new IllegalStateException("child=" + child // NOI18N
                + " has parent=" + childParent // NOI18N
                + " instead of " + v // NOI18N
            );
        }
        checkChildrenParent(child);
    }
}
 
Example 16
Source File: bug8014863.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example 17
Source File: bug8014863.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void retrieveGlyphViews(View root) {
    for (int i=0; i<= root.getViewCount()-1; i++) {
        View view = root.getView(i);
        if (view instanceof GlyphView && view.isVisible()) {
            if (!glyphViews.contains(view)) {
                glyphViews.add((GlyphView)view);
            }
        } else {
            retrieveGlyphViews(view);
        }
    }
}
 
Example 18
Source File: HTMLPrintable.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
private boolean printView(final Graphics2D graphics2D,
                          final Shape allocation, final View view) {
    boolean pageExists = false;
    final Rectangle clipRectangle = new Rectangle(0, 0, (int) (pageFormat
            .getImageableWidth() / SCALE), (int) clientHeight);
    Shape childAllocation;
    View childView;

    if (view.getViewCount() > 0) {
        for (int i = 0; i < view.getViewCount(); i++) {
            childAllocation = view.getChildAllocation(i, allocation);
            if (childAllocation != null) {
                childView = view.getView(i);
                if (printView(graphics2D, childAllocation, childView)) {
                    pageExists = true;
                }
            }
        }
    } else {
        if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {

            if (allocation.getBounds().getHeight() > clipRectangle
                    .getHeight()
                    && allocation.intersects(clipRectangle)) {
                paintView(graphics2D, view, allocation);
                pageExists = true;
            } else {
                if (allocation.getBounds().getY() >= clipRectangle.getY()) {
                    if (allocation.getBounds().getMaxY() <= clipRectangle
                            .getMaxY()) {
                        paintView(graphics2D, view, allocation);
                        pageExists = true;

                    } else {
                        if (allocation.getBounds().getY() < pageEndY) {
                            pageEndY = allocation.getBounds().getY();
                        }
                    }
                }
            }
        }
    }
    return pageExists;
}
 
Example 19
Source File: ActionFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    AbstractDocument adoc = (AbstractDocument)target.getDocument();

    // Dump fold hierarchy
    FoldHierarchy hierarchy = FoldHierarchy.get(target);
    adoc.readLock();
    try {
        hierarchy.lock();
        try {
            /*DEBUG*/System.err.println("FOLD HIERARCHY DUMP:\n" + hierarchy); // NOI18N
            TokenHierarchy<?> th = TokenHierarchy.get(adoc);
            /*DEBUG*/System.err.println("TOKEN HIERARCHY DUMP:\n" + (th != null ? th : "<NULL-TH>")); // NOI18N

        } finally {
            hierarchy.unlock();
        }
    } finally {
        adoc.readUnlock();
    }

    View rootView = null;
    TextUI textUI = target.getUI();
    if (textUI != null) {
        rootView = textUI.getRootView(target); // Root view impl in BasicTextUI
        if (rootView != null && rootView.getViewCount() == 1) {
            rootView = rootView.getView(0); // Get DocumentView
        }
    }
    if (rootView != null) {
        String rootViewDump = (rootView instanceof DocumentView)
                ? ((DocumentView)rootView).toStringDetail()
                : rootView.toString();
        /*DEBUG*/System.err.println("DOCUMENT VIEW: " + System.identityHashCode(rootView) + // NOI18N
                "\n" + rootViewDump); // NOI18N
        int caretOffset = target.getCaretPosition();
        int caretViewIndex = rootView.getViewIndex(caretOffset, Position.Bias.Forward);
        /*DEBUG*/System.err.println("caretOffset=" + caretOffset + ", caretViewIndex=" + caretViewIndex); // NOI18N
        if (caretViewIndex >= 0 && caretViewIndex < rootView.getViewCount()) {
            View caretView = rootView.getView(caretViewIndex);
            /*DEBUG*/System.err.println("caretView: " + caretView); // NOI18N
        }
        /*DEBUG*/System.err.println(FixLineSyntaxState.lineInfosToString(adoc));
        // Check the hierarchy correctness
        //org.netbeans.editor.view.spi.ViewUtilities.checkViewHierarchy(rootView);
    }
    
    if (adoc instanceof BaseDocument) {
        /*DEBUG*/System.err.println("DOCUMENT:\n" + ((BaseDocument)adoc).toStringDetail()); // NOI18N
    }
}
 
Example 20
Source File: ChatPrinter.java    From Spark with Apache License 2.0 4 votes vote down vote up
private boolean printView(Graphics2D graphics2D, Shape allocation,
                              View view) {
        boolean pageExists = false;
        Rectangle clipRectangle = graphics2D.getClipBounds();
        Shape childAllocation;
        View childView;

        if (view.getViewCount() > 0) {
            for (int i = 0; i < view.getViewCount(); i++) {
                childAllocation = view.getChildAllocation(i, allocation);
                if (childAllocation != null) {
                    childView = view.getView(i);
                    if (printView(graphics2D, childAllocation, childView)) {
                        pageExists = true;
                    }
                }
            }
        }
        else {
//  I
            if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {
                pageExists = true;
//  II
                if ((allocation.getBounds().getHeight() > clipRectangle.getHeight()) &&
                        (allocation.intersects(clipRectangle))) {
                    view.paint(graphics2D, allocation);
                }
                else {
//  III
                    if (allocation.getBounds().getY() >= clipRectangle.getY()) {
                        if (allocation.getBounds().getMaxY() <= clipRectangle.getMaxY()) {
                            view.paint(graphics2D, allocation);
                        }
                        else {
//  IV
                            if (allocation.getBounds().getY() < pageEndY) {
                                pageEndY = allocation.getBounds().getY();
                            }
                        }
                    }
                }
            }
        }
        return pageExists;
    }