jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthTextFieldUI.java
author alexsch
Fri, 15 Apr 2016 19:15:12 +0400
changeset 37698 4d798c873df0
parent 25859 3317bb8137f4
child 47140 519fd8ec4ce1
permissions -rw-r--r--
8132791: No access to SynthContext.getContext() Reviewed-by: serb, ssadetsky
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 2002, 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: 4848
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: 4848
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: 4848
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.basic.BasicTextFieldUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.event.FocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.event.FocusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
    39
 * Provides the Synth L&F UI delegate for {@link javax.swing.JTextField}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20168
diff changeset
    46
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author  Shannon Hickey
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    51
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    53
@SuppressWarnings("serial") // Same-version serialization only
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    54
public class SynthTextFieldUI extends BasicTextFieldUI implements SynthUI {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    55
    private Handler handler = new Handler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private SynthStyle style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Creates a UI for a JTextField.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param c the text field
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
    62
     * @return the UI object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return new SynthTextFieldUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private void updateStyle(JTextComponent comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        SynthContext context = getContext(comp, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        if (style != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            SynthTextFieldUI.updateStyle(comp, context, getPropertyPrefix());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                uninstallKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                installKeyboardActions();
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    static void updateStyle(JTextComponent comp, SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            String prefix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        SynthStyle style = context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Color color = comp.getCaretColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (color == null || color instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            comp.setCaretColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                (Color)style.get(context, prefix + ".caretForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        Color fg = comp.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (fg == null || fg instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            fg = style.getColorForState(context, ColorType.TEXT_FOREGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (fg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                comp.setForeground(fg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        Object ar = style.get(context, prefix + ".caretAspectRatio");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (ar instanceof Number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            comp.putClientProperty("caretAspectRatio", ar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        context.setComponentState(SELECTED | FOCUSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        Color s = comp.getSelectionColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (s == null || s instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            comp.setSelectionColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                style.getColor(context, ColorType.TEXT_BACKGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        Color sfg = comp.getSelectedTextColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (sfg == null || sfg instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            comp.setSelectedTextColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                style.getColor(context, ColorType.TEXT_FOREGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        context.setComponentState(DISABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        Color dfg = comp.getDisabledTextColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (dfg == null || dfg instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            comp.setDisabledTextColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                style.getColor(context, ColorType.TEXT_FOREGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Insets margin = comp.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (margin == null || margin instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            margin = (Insets)style.get(context, prefix + ".margin");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            if (margin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                // Some places assume margins are non-null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                margin = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            comp.setMargin(margin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        Caret caret = comp.getCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (caret instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            Object o = style.get(context, prefix + ".caretBlinkRate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (o != null && o instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                Integer rate = (Integer)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                caret.setBlinkRate(rate.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   150
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   151
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   152
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   153
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public SynthContext getContext(JComponent c) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   155
        return getContext(c, SynthLookAndFeel.getComponentState(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private SynthContext getContext(JComponent c, int state) {
25100
d527cc827d7d 8043627: NPE in SynthContext in plugin mode
malenkov
parents: 22574
diff changeset
   159
        return SynthContext.getContext(c, style, state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   162
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   163
     * Notifies this UI delegate to repaint the specified component.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   164
     * This method paints the component background, then calls
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   165
     * the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   166
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   167
     * <p>In general, this method does not need to be overridden by subclasses.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   168
     * All Look and Feel rendering code should reside in the {@code paint} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   169
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   170
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   171
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   172
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   173
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   174
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        paintBackground(context, g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   184
     * Paints the specified component.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   185
     * <p>This is routed to the {@link #paintSafely} method under
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   186
     * the guarantee that the model does not change from the view of this
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   187
     * thread while it is rendering (if the associated model is
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   188
     * derived from {@code AbstractDocument}).  This enables the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * model to potentially be updated asynchronously.
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   190
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   191
     * @param context context for the component being painted
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   192
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   193
     * @see #update(Graphics,JComponent)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        super.paint(g, getComponent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    void paintBackground(SynthContext context, Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        context.getPainter().paintTextFieldBackground(context, g, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                                c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   204
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   205
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   206
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   207
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        context.getPainter().paintTextFieldBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   213
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   214
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   215
     * Overridden to do nothing.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   216
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   217
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    protected void paintBackground(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // Overriden to do nothing, all our painting is done from update/paint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * This method gets called when a bound property is changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * on the associated JTextComponent.  This is a hook
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * which UI implementations may change to reflect how the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * UI displays bound properties of JTextComponent subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * This is implemented to do nothing (i.e. the response to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * properties in JTextComponent itself are handled prior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * to calling this method).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param evt the property change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   233
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    protected void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            updateStyle((JTextComponent)evt.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        super.propertyChange(evt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   241
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   242
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   243
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   244
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        // Installs the text cursor on the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        super.installDefaults();
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   248
        updateStyle(getComponent());
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   249
        getComponent().addFocusListener(handler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   252
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   253
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   254
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   255
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        SynthContext context = getContext(getComponent(), ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        getComponent().putClientProperty("caretAspectRatio", null);
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   260
        getComponent().removeFocusListener(handler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        super.uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   267
    private final class Handler implements FocusListener {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   268
        public void focusGained(FocusEvent e) {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   269
            getComponent().repaint();
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   270
        }
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   271
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   272
        public void focusLost(FocusEvent e) {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   273
            getComponent().repaint();
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 1639
diff changeset
   274
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
}