Java Code Examples for javax.swing.text.GlyphView

The following examples show how to use javax.swing.text.GlyphView. These examples are extracted from open source projects. 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 Project: SmartIM   Source File: WrapHTMLFactory.java    License: Apache License 2.0 6 votes vote down vote up
public View breakView(int axis, int p0, float pos, float len) {
    if (axis == View.X_AXIS) {
        checkPainter();
        int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
        try {
            // if the view contains line break char break the view
            int index = getDocument().getText(p0, p1 - p0).indexOf(WrapHTMLFactory.SEPARATOR);
            if (index >= 0) {
                GlyphView v = (GlyphView)createFragment(p0, p0 + index + 1);
                return v;
            }
        } catch (BadLocationException ex) {
            // should never happen
        }

    }
    return super.breakView(axis, p0, pos, len);
}
 
Example 2
Source Project: PolyGlot   Source File: GlyphVectorPainter.java    License: MIT License 6 votes vote down vote up
private void checkKerning(GlyphView v) {
    Object testKVal = v.getElement().getAttributes().getAttribute(KEY_KERNING);
    if (testKVal != null) {
        float kValue;
        
        if (testKVal instanceof Double) {
            kValue = ((Double)testKVal).floatValue();
        } else if (testKVal instanceof Float) {
            kValue = (Float)testKVal;
        } else {
            kValue = (float)testKVal;
        }
        
        for (int i=glyphVector.getNumGlyphs()-1; i>=0; i--) {
            Point2D p=glyphVector.getGlyphPosition(i);
            p.setLocation(p.getX() + i * kValue, p.getY());
            glyphVector.setGlyphPosition(i, p);
        }
    }
}
 
Example 3
Source Project: PolyGlot   Source File: GlyphVectorPainter.java    License: MIT License 6 votes vote down vote up
/**
 * Determine the span the glyphs given a start location
 * (for tab expansion).
 * @param exp
 * @return 
 */
@Override
public float getSpan(GlyphView v, int p0, int p1,
                     TabExpander exp, float x) {
    try {
        sync(v);
        String docText = v.getDocument().getText(p0,p1-p0);
        float width = getTabbedTextWidth(v, docText, x, exp, p0, null);
        return width;
    } catch (BadLocationException e) {
        //e.printStackTrace();
        IOHandler.writeErrorLog(e, "EXTERNAL CODE");
    }

    return 0;
}
 
Example 4
Source Project: PolyGlot   Source File: GlyphVectorPainter.java    License: MIT License 6 votes vote down vote up
/**
 * Determines the best location (in the model) to break
 * the given view.
 * This method attempts to break on a whitespace
 * location.  If a whitespace location can't be found, the
 * nearest character location is returned.
 *
 * @param v the view
 * @param p0 the location in the model where the
 *  fragment should start its representation >= 0
 * @param x the graphic location along the axis that the
 *  broken view would occupy >= 0; this may be useful for
 *  things like tab calculations
 * @param len specifies the distance into the view
 *  where a potential break is desired >= 0
 * @return the model location desired for a break
 * @see View#breakView
 */
@Override
public int getBoundedPosition(GlyphView v, int p0, float x, float len) {
    int ret;
    
    try {
        sync(v);
        TabExpander expander = v.getTabExpander();
        String s = v.getDocument().getText(p0, v.getEndOffset()-p0);
        int index = getTabbedTextOffset(v,s, (int)x, (int)(x+len), expander, p0, false, null);
        int p1 = p0 + index;
        ret = p1;
    } catch (BadLocationException e) {
        //e.printStackTrace();
        ret = -1;
        IOHandler.writeErrorLog(e, "EXTERNAL CODE");
    }

    return ret;
}
 
Example 5
Source Project: dragonwell8_jdk   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 6
Source Project: dragonwell8_jdk   Source File: bug8014863.java    License: 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 Project: TencentKona-8   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 8
Source Project: TencentKona-8   Source File: bug8014863.java    License: 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 Project: jdk8u60   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 10
Source Project: jdk8u60   Source File: bug8014863.java    License: 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 Project: openjdk-jdk8u   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 12
Source Project: openjdk-jdk8u   Source File: bug8014863.java    License: 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 13
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 14
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 15
Source Project: openjdk-jdk9   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 16
Source Project: openjdk-jdk9   Source File: bug8014863.java    License: 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 Project: jdk8u-jdk   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 18
Source Project: jdk8u-jdk   Source File: bug8014863.java    License: 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 19
Source Project: hottub   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 20
Source Project: hottub   Source File: bug8014863.java    License: 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 21
Source Project: openjdk-8-source   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 22
Source Project: openjdk-8-source   Source File: bug8014863.java    License: 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 23
Source Project: openjdk-8   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 24
Source Project: openjdk-8   Source File: bug8014863.java    License: 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 25
Source Project: jdk8u_jdk   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 26
Source Project: jdk8u_jdk   Source File: bug8014863.java    License: 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 27
Source Project: jdk8u-jdk   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 28
Source Project: jdk8u-jdk   Source File: bug8014863.java    License: 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 29
Source Project: jdk8u-dev-jdk   Source File: bug6857057.java    License: GNU General Public License v2.0 5 votes vote down vote up
bug6857057() {
    Element elem = new StubBranchElement(" G L Y P H V");
    GlyphView view = new GlyphView(elem);
    float pos = elem.getStartOffset();
    float len = elem.getEndOffset() - pos;
    int res = view.getBreakWeight(View.X_AXIS, pos, len);
    if (res != View.ExcellentBreakWeight) {
        throw new RuntimeException("breakWeight != ExcellentBreakWeight");
    }
}
 
Example 30
Source Project: jdk8u-dev-jdk   Source File: bug8014863.java    License: 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);
        }
    }
}