jdk/src/share/classes/javax/swing/text/ComponentView.java
author xdono
Mon, 15 Dec 2008 16:55:25 -0800
changeset 1639 a97859015238
parent 1287 a04aca99c77a
child 5506 202f599c92aa
permissions -rw-r--r--
6785258: Update copyright year Summary: Update copyright for files that have been modified starting July 2008 to Dec 2008 Reviewed-by: katleman, ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1639
a97859015238 6785258: Update copyright year
xdono
parents: 1287
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.PropertyChangeListener;
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
    30
import java.util.Set;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.SwingUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Component decorator that implements the view interface.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * entire element is used to represent the component.  This acts
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * as a gateway from the display-only View implementations to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * interactive lightweight components (ie it allows components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * to be embedded into the View hierarchy).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The component is placed relative to the text baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * according to the value returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>Component.getAlignmentY</code>.  For Swing components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * this value can be conveniently set using the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <code>JComponent.setAlignmentY</code>.  For example, setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * a value of <code>0.75</code> will cause 75 percent of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * component to be above the baseline, and 25 percent of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * component to be below the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * This class is implemented to do the extra work necessary to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * work properly in the presence of multiple threads (i.e. from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * asynchronous notification of model changes for example) by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * ensuring that all component access is done on the event thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * The component used is determined by the return value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * createComponent method.  The default implementation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * method is to return the component held as an attribute of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * the element (by calling StyleConstants.getComponent).  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * limitation of this behavior is that the component cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * be used by more than one text component (i.e. with a shared
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * model).  Subclasses can remove this constraint by implementing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * the createComponent to actually create a component based upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * some kind of specification contained in the attributes.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * ObjectView class in the html package is an example of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * ComponentView implementation that supports multiple component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * views of a shared model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @author Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public class ComponentView extends View  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Creates a new ComponentView object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param elem the element to decorate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public ComponentView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        super(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Create the component that is associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * this view.  This will be called when it has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * been determined that a new component is needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * This would result from a call to setParent or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * as a result of being notified that attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected Component createComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        AttributeSet attr = getElement().getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        Component comp = StyleConstants.getComponent(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Fetch the component associated with the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public final Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return createdC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // --- View methods ---------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * The real paint behavior occurs naturally from the association
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * that the component has with its parent container (the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * container hosting this view).  This is implemented to do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param g the graphics context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param a the shape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see View#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public void paint(Graphics g, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            Rectangle alloc = (a instanceof Rectangle) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                (Rectangle) a : a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            c.setBounds(alloc.x, alloc.y, alloc.width, alloc.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Determines the preferred span for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * axis.  This is implemented to return the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * returned by Component.getPreferredSize along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * axis of interest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param axis may be either View.X_AXIS or View.Y_AXIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return   the span the view would like to be rendered into >= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *           Typically the view is told to render into the span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *           that is returned, although there is no guarantee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *           The parent may choose to resize or break the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @exception IllegalArgumentException for an invalid axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public float getPreferredSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if ((axis != X_AXIS) && (axis != Y_AXIS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            throw new IllegalArgumentException("Invalid axis: " + axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            Dimension size = c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            if (axis == View.X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                return size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                return size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Determines the minimum span for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * axis.  This is implemented to return the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * returned by Component.getMinimumSize along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * axis of interest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param axis may be either View.X_AXIS or View.Y_AXIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @return   the span the view would like to be rendered into >= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *           Typically the view is told to render into the span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *           that is returned, although there is no guarantee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *           The parent may choose to resize or break the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @exception IllegalArgumentException for an invalid axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public float getMinimumSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if ((axis != X_AXIS) && (axis != Y_AXIS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            throw new IllegalArgumentException("Invalid axis: " + axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            Dimension size = c.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (axis == View.X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                return size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                return size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Determines the maximum span for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * axis.  This is implemented to return the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * returned by Component.getMaximumSize along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * axis of interest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param axis may be either View.X_AXIS or View.Y_AXIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @return   the span the view would like to be rendered into >= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *           Typically the view is told to render into the span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *           that is returned, although there is no guarantee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *           The parent may choose to resize or break the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @exception IllegalArgumentException for an invalid axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public float getMaximumSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if ((axis != X_AXIS) && (axis != Y_AXIS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            throw new IllegalArgumentException("Invalid axis: " + axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            Dimension size = c.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if (axis == View.X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                return size.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                return size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Determines the desired alignment for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * axis.  This is implemented to give the alignment of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * embedded component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param axis may be either View.X_AXIS or View.Y_AXIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return the desired alignment.  This should be a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *   between 0.0 and 1.0 where 0 indicates alignment at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *   origin and 1.0 indicates alignment to the full span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *   away from the origin.  An alignment of 0.5 would be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *   center of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public float getAlignment(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            switch (axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            case View.X_AXIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                return c.getAlignmentX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            case View.Y_AXIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                return c.getAlignmentY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return super.getAlignment(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Sets the parent for a child view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * The parent calls this on the child to tell it who its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * parent is, giving the view access to things like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * the hosting Container.  The superclass behavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * executed, followed by a call to createComponent if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * the parent view parameter is non-null and a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * has not yet been created. The embedded components parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * is then set to the value returned by <code>getContainer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * If the parent view parameter is null, this view is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * cleaned up, thus the component is removed from its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * The changing of the component hierarchy will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * touch the component lock, which is the one thing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * that is not safe from the View hierarchy.  Therefore,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * this functionality is executed immediately if on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * event thread, or is queued on the event queue if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * called from another thread (notification of change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * from an asynchronous update).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @param p the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public void setParent(View p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        super.setParent(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (SwingUtilities.isEventDispatchThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            setComponentParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            Runnable callSetComponentParent = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        if (doc instanceof AbstractDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                            ((AbstractDocument)doc).readLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        setComponentParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        Container host = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        if (host != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                            preferenceChanged(null, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                            host.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                        if (doc instanceof AbstractDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                            ((AbstractDocument)doc).readUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            SwingUtilities.invokeLater(callSetComponentParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Set the parent of the embedded component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * with assurance that it is thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    void setComponentParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        View p = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            Container parent = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    // try to build a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    Component comp = createComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    if (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                        createdC = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        c = new Invalidator(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    if (c.getParent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        // components associated with the View tree are added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        // to the hosting container with the View as a constraint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        parent.add(c, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                        parent.addPropertyChangeListener("enabled", c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                Container parent = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    // remove the component from its hosting container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    parent.remove(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    parent.removePropertyChangeListener("enabled", c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Provides a mapping from the coordinate space of the model to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * that of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @param pos the position to convert >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @return the bounding box of the given position is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @exception BadLocationException  if the given position does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *   represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @see View#modelToView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        int p0 = getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        int p1 = getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if ((pos >= p0) && (pos <= p1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            Rectangle r = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            if (pos == p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                r.x += r.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            r.width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        throw new BadLocationException(pos + " not in range " + p0 + "," + p1, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Provides a mapping from the view coordinate space to the logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * coordinate space of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @param x the X coordinate >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @param y the Y coordinate >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @return the location within the model that best represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *    the given point in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @see View#viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        Rectangle alloc = (Rectangle) a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if (x < alloc.x + (alloc.width / 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            bias[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            return getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        bias[0] = Position.Bias.Backward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    // --- member variables ------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    private Component createdC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    private Invalidator c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * This class feeds the invalidate back to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * hosting View.  This is needed to get the View
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * hierarchy to consider giving the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * a different size (i.e. layout may have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * cached between the associated view and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * container hosting this component).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    class Invalidator extends Container implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        // NOTE: When we remove this class we are going to have to some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        // how enforce setting of the focus traversal keys on the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        // so that they don't inherit them from the JEditorPane. We need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        // to do this as JEditorPane has abnormal bindings (it is a focus cycle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        // root) and the children typically don't want these bindings as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        Invalidator(Component child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            add(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            cacheChildSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         * The components invalid layout needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
         * to be propagated through the view hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
         * so the views (which position the component)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
         * can have their layout recomputed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        public void invalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            super.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            if (getParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                preferenceChanged(null, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        public void doLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            cacheChildSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        public void setBounds(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            super.setBounds(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            if (getComponentCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                getComponent(0).setSize(w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            cacheChildSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        public void validateIfNecessary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            if (!isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        private void cacheChildSizes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            if (getComponentCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                Component child = getComponent(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                min = child.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                pref = child.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                max = child.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                yalign = child.getAlignmentY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                xalign = child.getAlignmentX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                min = pref = max = new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
         * Shows or hides this component depending on the value of parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
         * <code>b</code>.
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   438
         * @param b If <code>true</code>, shows this component;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
         * otherwise, hides this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
         * @see #isVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
         * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            super.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            if (getComponentCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                getComponent(0).setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
         * Overridden to fix 4759054. Must return true so that content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
         * is painted when inside a CellRendererPane which is normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
         * invisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            validateIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            return min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            validateIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            return pref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            validateIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            return max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        public float getAlignmentX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            validateIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            return xalign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        public float getAlignmentY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            validateIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            return yalign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   484
        public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            return KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    getDefaultFocusTraversalKeys(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        public void propertyChange(PropertyChangeEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            Boolean enable = (Boolean) ev.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            if (getComponentCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                getComponent(0).setEnabled(enable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        Dimension min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        Dimension pref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        Dimension max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        float yalign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        float xalign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
}