Java Code Examples for javax.swing.plaf.TextUI#getRootView()
The following examples show how to use
javax.swing.plaf.TextUI#getRootView() .
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: Utilities.java From netbeans with Apache License 2.0 | 5 votes |
/** * Get first view in the hierarchy that is an instance of the given class. * It allows to skip various wrapper-views around the doc-view that holds * the child views for the lines. * * @param component component from which the root view is fetched. * @param rootViewClass class of the view to return. * @return view being instance of the requested class or null if there * is not one. */ public static View getRootView(JTextComponent component, Class rootViewClass) { View view = null; TextUI textUI = component.getUI(); if (textUI != null) { view = textUI.getRootView(component); while (view != null && !rootViewClass.isInstance(view) && view.getViewCount() == 1 // must be wrapper view ) { view = view.getView(0); // get the only child } } return view; }
Example 2
Source File: DocumentView.java From netbeans with Apache License 2.0 | 5 votes |
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 3
Source File: ActionFactory.java From netbeans with Apache License 2.0 | 4 votes |
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 4
Source File: DocumentationComponent.java From consulo with Apache License 2.0 | 4 votes |
private int definitionPreferredWidth() { TextUI ui = myEditorPane.getUI(); View view = ui.getRootView(myEditorPane); View definition = findDefinition(view); return definition != null ? (int)definition.getPreferredSpan(View.X_AXIS) : -1; }