javax.swing.text.View#getParent ( )源码实例Demo

下面列出了javax.swing.text.View#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: ViewUtilitiesImpl.java
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);
    }
}
 
源代码2 项目: Bytecoder   文件: ImageView.java
/**
 * 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;
}
 
源代码3 项目: jdk8u_jdk   文件: ImageView.java
/**
 * 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;
}
 
源代码4 项目: SwingBox   文件: ElementBoxView.java
@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;
}
 
源代码5 项目: netbeans   文件: DocumentView.java
static DocumentView get(View view) {
    while (view != null && !(view instanceof DocumentView)) {
        view = view.getParent();
    }
    return (DocumentView) view;
}
 
源代码6 项目: PolyGlot   文件: GlyphVectorPainter.java
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;
}
 
源代码7 项目: PolyGlot   文件: GlyphVectorPainter.java
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;
}
 
源代码8 项目: netbeans   文件: LockView.java
/**
 * 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;
}