jdk/src/java.desktop/share/classes/javax/swing/text/GlyphPainter1.java
author serb
Mon, 06 Mar 2017 22:52:45 +0300
changeset 44155 1bf93336ea45
parent 41807 f9eb6cb54fed
child 44655 06871a50a4b5
permissions -rw-r--r--
8158209: Editing in TableView breaks the layout, when the document is I18n Reviewed-by: serb, alexsch Contributed-by: Abossolo Foh Guy <guy.abossolo.foh@scientificware.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * A class to perform rendering of the glyphs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This can be implemented to be stateless, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * to hold some information as a cache to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * facilitate faster rendering and model/view
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * translation.  At a minimum, the GlyphPainter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * allows a View implementation to perform its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * duties independent of a particular version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * of JVM and selection of capabilities (i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * shaping for i18n, etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * This implementation is intended for operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * under the JDK1.1 API of the Java Platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Since the JDK is backward compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * JDK1.1 API, this class will also function on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Java 2.  The JDK introduces improved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * API for rendering text however, so the GlyphPainter2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * is recommended for the DK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see GlyphView
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
class GlyphPainter1 extends GlyphView.GlyphPainter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Determine the span the glyphs given a start location
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * (for tab expansion).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public float getSpan(GlyphView v, int p0, int p1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                         TabExpander e, float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        sync(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        Segment text = v.getText(p0, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        int[] justificationData = getJustificationData(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        int width = Utilities.getTabbedTextWidth(v, text, metrics, (int) x, e, p0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                                 justificationData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        SegmentCache.releaseSharedSegment(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public float getHeight(GlyphView v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        sync(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        return metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Fetches the ascent above the baseline for the glyphs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * corresponding to the given range in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public float getAscent(GlyphView v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        sync(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return metrics.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Fetches the descent below the baseline for the glyphs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * corresponding to the given range in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public float getDescent(GlyphView v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        sync(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return metrics.getDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Paints the glyphs representing the given range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        sync(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        Segment text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        TabExpander expander = v.getTabExpander();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // determine the x coordinate to render the glyphs
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 28231
diff changeset
   101
        float x = alloc.x;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        int p = v.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        int[] justificationData = getJustificationData(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (p != p0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            text = v.getText(p, p0);
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 28231
diff changeset
   106
            float width = Utilities.getTabbedTextWidth(v, text, metrics, x,
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 28231
diff changeset
   107
                                                       expander, p,
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 28231
diff changeset
   108
                                                       justificationData);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            x += width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            SegmentCache.releaseSharedSegment(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        // determine the y coordinate to render the glyphs
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 28231
diff changeset
   114
        float y = alloc.y + metrics.getHeight() - metrics.getDescent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // render the glyphs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        text = v.getText(p0, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        g.setFont(metrics.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        Utilities.drawTabbedText(v, text, x, y, g, expander,p0,
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 28231
diff changeset
   121
                                 justificationData, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        SegmentCache.releaseSharedSegment(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public Shape modelToView(GlyphView v, int pos, Position.Bias bias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                             Shape a) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        sync(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        int p0 = v.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        int p1 = v.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        TabExpander expander = v.getTabExpander();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        Segment text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if(pos == p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            // The caller of this is left to right and borders a right to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            // left view, return our end location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            return new Rectangle(alloc.x + alloc.width, alloc.y, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                 metrics.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if ((pos >= p0) && (pos <= p1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            // determine range to the left of the position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            text = v.getText(p0, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            int[] justificationData = getJustificationData(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            int width = Utilities.getTabbedTextWidth(v, text, metrics, alloc.x, expander, p0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                                     justificationData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            SegmentCache.releaseSharedSegment(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            return new Rectangle(alloc.x + width, alloc.y, 0, metrics.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        throw new BadLocationException("modelToView - can't convert", p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Provides a mapping from the view coordinate space to the logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * coordinate space of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param v the view containing the view coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param x the X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param y the Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param biasReturn always returns <code>Position.Bias.Forward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *   as the zero-th element of this array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @return the location within the model that best represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *  given point in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see View#viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public int viewToModel(GlyphView v, float x, float y, Shape a,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                           Position.Bias[] biasReturn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        sync(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        int p0 = v.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        int p1 = v.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        TabExpander expander = v.getTabExpander();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        Segment text = v.getText(p0, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        int[] justificationData = getJustificationData(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        int offs = Utilities.getTabbedTextOffset(v, text, metrics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                                 alloc.x, (int) x, expander, p0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                                 justificationData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        SegmentCache.releaseSharedSegment(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        int retValue = p0 + offs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if(retValue == p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            // No need to return backward bias as GlyphPainter1 is used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            // ltr text only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            retValue--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        biasReturn[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Determines the best location (in the model) to break
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * the given view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * This method attempts to break on a whitespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * location.  If a whitespace location can't be found, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * nearest character location is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param v the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param p0 the location in the model where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *  fragment should start its representation >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param pos the graphic location along the axis that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *  broken view would occupy >= 0; this may be useful for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *  things like tab calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param len specifies the distance into the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *  where a potential break is desired >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @return the model location desired for a break
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @see View#breakView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public int getBoundedPosition(GlyphView v, int p0, float x, float len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        sync(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        TabExpander expander = v.getTabExpander();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        Segment s = v.getText(p0, v.getEndOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        int[] justificationData = getJustificationData(v);
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 28231
diff changeset
   214
        int index = Utilities.getTabbedTextOffset(v, s, metrics, x, (x+len),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                                  expander, p0, false,
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 28231
diff changeset
   216
                                                  justificationData, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        SegmentCache.releaseSharedSegment(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        int p1 = p0 + index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return p1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   222
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    void sync(GlyphView v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        Font f = v.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if ((metrics == null) || (! f.equals(metrics.getFont()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            // fetch a new FontMetrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            Container c = v.getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            metrics = (c != null) ? c.getFontMetrics(f) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                Toolkit.getDefaultToolkit().getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @return justificationData from the ParagraphRow this GlyphView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * is in or {@code null} if no justification is needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    private int[] getJustificationData(GlyphView v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        View parent = v.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        int [] ret = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (parent instanceof ParagraphView.Row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            ParagraphView.Row row = ((ParagraphView.Row) parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            ret = row.justificationData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    // --- variables ---------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    FontMetrics metrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
}