Java Code Examples for javax.swing.text.View#getParent()
The following examples show how to use
javax.swing.text.View#getParent() .
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: ViewUtilitiesImpl.java From netbeans with Apache License 2.0 | 5 votes |
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 2
Source File: ImageView.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Returns the view to use for alternate text. This may be null. */ private View getAltView() { View view; synchronized(this) { view = altView; } if (view != null && view.getParent() == null) { view.setParent(getParent()); } return view; }
Example 3
Source File: ImageView.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns the view to use for alternate text. This may be null. */ private View getAltView() { View view; synchronized(this) { view = altView; } if (view != null && view.getParent() == null) { view.setParent(getParent()); } return view; }
Example 4
Source File: ElementBoxView.java From SwingBox with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected View getViewAtPoint(int x, int y, Rectangle alloc) { View retv = null; int retorder = -1; Vector<View> leaves = new Vector<View>(); findLeaves(this, leaves); for (View leaf : leaves) { View v = leaf; if (v instanceof CSSBoxView) { Box b = getBox(v); if (locateBox(b, x, y) != null) { while (v.getParent() != null && v.getParent() != this) v = v.getParent(); //System.out.println("Candidate: " + v + " (leaf: " + leaf + ")"); int o = ((CSSBoxView) v).getDrawingOrder(); if (retv == null || o >= retorder) //next box is drawn after the current one { retv = v; retorder = order; alloc.setBounds(getCompleteBoxAllocation(b)); } } } } //System.out.println("At " + x + ":" + y + " found " + retv); return retv; }
Example 5
Source File: DocumentView.java From netbeans with Apache License 2.0 | 4 votes |
static DocumentView get(View view) { while (view != null && !(view instanceof DocumentView)) { view = view.getParent(); } return (DocumentView) view; }
Example 6
Source File: GlyphVectorPainter.java From PolyGlot with MIT License | 4 votes |
float getTabbedTextWidth(View view, String txtStr, float x, TabExpander e, int startOffset, int[] justificationData) { float nextX = x; char[] txt = txtStr.toCharArray(); int txtOffset = 0; int n = txtStr.length(); int charCount = 0; int spaceAddon = 0; int spaceAddonLeftoverEnd = -1; int startJustifiableContent = 0; int endJustifiableContent = 0; if (justificationData != null) { int offset = - startOffset + txtOffset; View parent; if (view != null && (parent = view.getParent()) != null) { offset += parent.getStartOffset(); } spaceAddon =justificationData[0]; spaceAddonLeftoverEnd =justificationData[1] + offset; startJustifiableContent =justificationData[2] + offset; endJustifiableContent =justificationData[3] + offset; } for (int i = txtOffset; i < n; i++) { if (txt[i] == '\t' || ((spaceAddon != 0 || i <= spaceAddonLeftoverEnd) && (txt[i] == ' ') && startJustifiableContent <= i && i <= endJustifiableContent )) { // doesn't account for complex glyphs/constructed diacratics in windows. Skipping diacratic mark is an approximate solution. if (glyphVector.getNumGlyphs() >= i) { nextX += (glyphVector.getGlyphPosition(i).getX() - glyphVector.getGlyphPosition(i-charCount).getX()); } charCount = 0; if (txt[i] == '\t') { if (e != null) { nextX = e.nextTabStop(nextX, startOffset + i - txtOffset); } else { if (spaceVector.getNumGlyphs() >= 1) { nextX += (spaceVector.getGlyphPosition(1).getX()); } } } else if (txt[i] == ' ') { if (spaceVector.getNumGlyphs() >= 1) { nextX += (spaceVector.getGlyphPosition(1).getX()) + spaceAddon; } if (i <= spaceAddonLeftoverEnd) { nextX++; } } } else if(txt[i] == '\n') { // doesn't account for complex glyphs/constructed diacratics in windows. Skipping diacratic mark is an approximate solution. if (glyphVector.getNumGlyphs() >= i) { // Ignore newlines, they take up space and we shouldn't be counting them. nextX += (glyphVector.getGlyphPosition(i).getX() - glyphVector.getGlyphPosition(i-charCount).getX()); } charCount = 0; } else { charCount++; } } // doesn't account for complex glyphs/constructed diacratics in windows. Skipping diacratic mark is an approximate solution. if (glyphVector.getNumGlyphs() >= n) { nextX += (glyphVector.getGlyphPosition(n).getX() - glyphVector.getGlyphPosition(n - charCount).getX()); } return nextX - x; }
Example 7
Source File: GlyphVectorPainter.java From PolyGlot with MIT License | 4 votes |
int getTabbedTextOffset(View view, String s, int x0, int x, TabExpander e, int startOffset, boolean round, int[] justificationData) { if (x0 >= x) { // x before x0, return. return 0; } float currX = x0; float nextX = currX; // s may be a shared String, so it is copied prior to calling // the tab expander char[] txt = s.toCharArray(); int txtOffset = 0; int txtCount = s.length(); int spaceAddon = 0 ; int spaceAddonLeftoverEnd = -1; int startJustifiableContent = 0 ; int endJustifiableContent = 0; if (justificationData != null) { int offset = - startOffset + txtOffset; View parent; if (view != null && (parent = view.getParent()) != null) { offset += parent.getStartOffset(); } spaceAddon =justificationData[0]; spaceAddonLeftoverEnd =justificationData[1] + offset; startJustifiableContent =justificationData[2] + offset; endJustifiableContent =justificationData[3] + offset; } int n = s.length(); for (int i = 0; i < n; i++) { if (txt[i] == '\t' || ((spaceAddon != 0 || i <= spaceAddonLeftoverEnd) && (txt[i] == ' ') && startJustifiableContent <= i && i <= endJustifiableContent )){ if (txt[i] == '\t') { if (e != null) { nextX = (int) e.nextTabStop(nextX, startOffset + i - txtOffset); } else { nextX += (spaceVector.getGlyphPosition(1).getX()); } } else if (txt[i] == ' ') { nextX += (spaceVector.getGlyphPosition(1).getX())+spaceAddon; if (i <= spaceAddonLeftoverEnd) { nextX++; } } } else { // doesn't account for complex glyphs/constructed diacratics in windows. Skipping diacratic mark is an approximate solution. if (glyphVector.getNumGlyphs() >= i + 1) { nextX += (glyphVector.getGlyphPosition(i+1).getX() - glyphVector.getGlyphPosition(i).getX()); } } if ((x >= currX) && (x < nextX)) { // found the hit position... return the appropriate side if (!round || (x - currX) < (nextX - x)) { return i - txtOffset; } else { return i + 1 - txtOffset; } } currX = nextX; } // didn't find, return end offset return txtCount; }
Example 8
Source File: LockView.java From netbeans with Apache License 2.0 | 3 votes |
/** * Find the <code>LockView</code> instance in a view hierarchy * by traversing it up to the root view. * * @param view view in the view hierarchy. <code>null</code> is accepted too. * @return valid instance of <code>LockView</code> or null * if there is no <code>LockView</code> instance present * in the view hierarchy of the view is no longer * part of the view hierarchy. */ public static LockView get(View view) { while (view != null && !(view instanceof LockView)) { view = view.getParent(); } return (LockView)view; }