Java Code Examples for javax.swing.text.GlyphView#getTabExpander()

The following examples show how to use javax.swing.text.GlyphView#getTabExpander() . 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: GlyphVectorPainter.java    From PolyGlot with 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 2
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 5 votes vote down vote up
/**
 * Provides a mapping from the view coordinate space to the logical
 * coordinate space of the model.
 *
 * @param v the view containing the view coordinates
 * @param x the X coordinate
 * @param y the Y coordinate
 * @param a the allocated region to render into
 * @param biasReturn always returns <code>Position.Bias.Forward</code>
 *   as the zero-th element of this array
 * @return the location within the model that best represents the
 *  given point in the view
 * @see View#viewToModel
 */
@Override
public int viewToModel(GlyphView v, float x, float y, Shape a,
                       Position.Bias[] biasReturn) {
    int ret;
    
    try {
        if (a != null) {
            sync(v);
            Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();
            int p0 = v.getStartOffset();
            int p1 = v.getEndOffset();
            TabExpander expander = v.getTabExpander();
            String docText = v.getDocument().getText(p0, p1-p0);
            int offs = getTabbedTextOffset(v, docText, alloc.x, (int) x, expander, p0, true, null);
            int retValue = p0 + offs;
            if(retValue == p1) {
                // No need to return backward bias as GlyphPainter1 is used for
                // ltr text only.
                retValue--;
            }
            biasReturn[0] = Position.Bias.Forward;
            ret = retValue;
        } else {
            ret = -1;
        }
    } catch (BadLocationException e) {
        //e.printStackTrace();
        ret = -1;
        IOHandler.writeErrorLog(e, "EXTERNAL CODE");
    }
    return ret;
}
 
Example 3
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 4 votes vote down vote up
/**
 * Paints the glyphs representing the given range.
 */
@Override
public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1) {
    try {
        sync(v);

        if (a != null ) {
            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            String localText;
            TabExpander expander = v.getTabExpander();
            Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();

            // determine the x coordinate to render the glyphs
            int x = alloc.x;
            int p = v.getStartOffset();
            if (p != p0) {
                localText = v.getDocument().getText(p, p0-p);
                float width = getTabbedTextWidth(v, localText, x, expander, p, null);
                x += width;
            }

            // determine the y coordinate to render the glyphs
            int y = alloc.y + Math.round(lm.getHeight() - lm.getDescent());

            // render the glyphs
            localText = v.getDocument().getText(p0, p1-p0);
            g.setFont(font);

            if( p0 > v.getStartOffset() || p1 < v.getEndOffset() ) {
                Shape s = v.modelToView(p0, Position.Bias.Forward,
                                        p1, Position.Bias.Backward, a);
                Shape savedClip = g.getClip();
                ((Graphics2D)g).clip(s);
                x=v.modelToView(v.getStartOffset(), a, Position.Bias.Forward).getBounds().x;
                drawTabbedText(v, localText, x, y, g, expander,p0, null);
                g.setClip(savedClip);
            }
            else {
                drawTabbedText(v, localText, x, y, g, expander,p0, null);                
            }
        }

    } catch (BadLocationException e) {
        //e.printStackTrace();
        IOHandler.writeErrorLog(e, "EXTERNAL CODE");
    }
}