jdk/src/share/classes/javax/swing/JLayer.java
author malenkov
Wed, 30 Apr 2014 19:28:05 +0400
changeset 24544 c0133e7c7162
parent 23697 e556a715949f
child 25568 b906a74c6882
permissions -rw-r--r--
8041917: unexcepted behavior of LineBorder while using Boolean variable true Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20158
diff changeset
     2
 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
3733
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
     4
 *
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
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: 5451
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3733
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5451
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3733
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
    10
 *
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
    15
 * accompanied this code).
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
    16
 *
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5451
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5451
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5451
diff changeset
    23
 * questions.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    24
 */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    25
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    26
package javax.swing;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    27
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
    28
import sun.awt.AWTAccessor;
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
    29
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    30
import javax.swing.plaf.LayerUI;
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
    31
import javax.swing.border.Border;
6838
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
    32
import javax.accessibility.*;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    33
import java.awt.*;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    34
import java.awt.event.*;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    35
import java.beans.PropertyChangeEvent;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    36
import java.beans.PropertyChangeListener;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    37
import java.io.IOException;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    38
import java.io.ObjectInputStream;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    39
import java.util.ArrayList;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    40
import java.security.AccessController;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    41
import java.security.PrivilegedAction;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    42
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    43
/**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    44
 * {@code JLayer} is a universal decorator for Swing components
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    45
 * which enables you to implement various advanced painting effects as well as
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    46
 * receive notifications of all {@code AWTEvent}s generated within its borders.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
    47
 * <p>
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    48
 * {@code JLayer} delegates the handling of painting and input events to a
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    49
 * {@link javax.swing.plaf.LayerUI} object, which performs the actual decoration.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
    50
 * <p>
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    51
 * The custom painting implemented in the {@code LayerUI} and events notification
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    52
 * work for the JLayer itself and all its subcomponents.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    53
 * This combination enables you to enrich existing components
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    54
 * by adding new advanced functionality such as temporary locking of a hierarchy,
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    55
 * data tips for compound components, enhanced mouse scrolling etc and so on.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
    56
 * <p>
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    57
 * {@code JLayer} is a good solution if you only need to do custom painting
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    58
 * over compound component or catch input events from its subcomponents.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    59
 * <pre>
3973
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    60
 * import javax.swing.*;
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    61
 * import javax.swing.plaf.LayerUI;
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    62
 * import java.awt.*;
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    63
 *
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    64
 * public class JLayerSample {
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    65
 *
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    66
 *     private static JLayer&lt;JComponent&gt; createLayer() {
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    67
 *         // This custom layerUI will fill the layer with translucent green
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    68
 *         // and print out all mouseMotion events generated within its borders
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    69
 *         LayerUI&lt;JComponent&gt; layerUI = new LayerUI&lt;JComponent&gt;() {
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    70
 *
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    71
 *             public void paint(Graphics g, JComponent c) {
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    72
 *                 // paint the layer as is
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    73
 *                 super.paint(g, c);
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    74
 *                 // fill it with the translucent green
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    75
 *                 g.setColor(new Color(0, 128, 0, 128));
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    76
 *                 g.fillRect(0, 0, c.getWidth(), c.getHeight());
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    77
 *             }
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    78
 *
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    79
 *             public void installUI(JComponent c) {
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    80
 *                 super.installUI(c);
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    81
 *                 // enable mouse motion events for the layer's subcomponents
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    82
 *                 ((JLayer) c).setLayerEventMask(AWTEvent.MOUSE_MOTION_EVENT_MASK);
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    83
 *             }
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    84
 *
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    85
 *             public void uninstallUI(JComponent c) {
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    86
 *                 super.uninstallUI(c);
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    87
 *                 // reset the layer event mask
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    88
 *                 ((JLayer) c).setLayerEventMask(0);
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    89
 *             }
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    90
 *
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    91
 *             // overridden method which catches MouseMotion events
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    92
 *             public void eventDispatched(AWTEvent e, JLayer&lt;? extends JComponent&gt; l) {
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    93
 *                 System.out.println("AWTEvent detected: " + e);
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    94
 *             }
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    95
 *         };
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    96
 *         // create a component to be decorated with the layer
3973
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    97
 *         JPanel panel = new JPanel();
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    98
 *         panel.add(new JButton("JButton"));
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
    99
 *
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   100
 *         // create the layer for the panel using our custom layerUI
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   101
 *         return new JLayer&lt;JComponent&gt;(panel, layerUI);
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   102
 *     }
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   103
 *
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   104
 *     private static void createAndShowGUI() {
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   105
 *         final JFrame frame = new JFrame();
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   106
 *         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   107
 *
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   108
 *         // work with the layer as with any other Swing component
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   109
 *         frame.add(createLayer());
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   110
 *
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   111
 *         frame.setSize(200, 200);
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   112
 *         frame.setLocationRelativeTo(null);
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   113
 *         frame.setVisible(true);
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   114
 *     }
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   115
 *
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   116
 *     public static void main(String[] args) throws Exception {
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   117
 *         SwingUtilities.invokeAndWait(new Runnable() {
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   118
 *             public void run() {
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   119
 *                 createAndShowGUI();
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   120
 *             }
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   121
 *         });
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   122
 *     }
3bdd09958faf 6878792: Sample provided in javax.swing.JLayer class description is not usable
alexp
parents: 3748
diff changeset
   123
 * }
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   124
 * </pre>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   125
 *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   126
 * <b>Note:</b> {@code JLayer} doesn't support the following methods:
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   127
 * <ul>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   128
 * <li>{@link Container#add(java.awt.Component)}</li>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   129
 * <li>{@link Container#add(String, java.awt.Component)}</li>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   130
 * <li>{@link Container#add(java.awt.Component, int)}</li>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   131
 * <li>{@link Container#add(java.awt.Component, Object)}</li>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   132
 * <li>{@link Container#add(java.awt.Component, Object, int)}</li>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   133
 * </ul>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   134
 * using any of of them will cause {@code UnsupportedOperationException} to be thrown,
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   135
 * to add a component to {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   136
 * use {@link #setView(Component)} or {@link #setGlassPane(JPanel)}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   137
 *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   138
 * @param <V> the type of {@code JLayer}'s view component
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   139
 *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   140
 * @see #JLayer(Component)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   141
 * @see #setView(Component)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   142
 * @see #getView()
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   143
 * @see javax.swing.plaf.LayerUI
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   144
 * @see #JLayer(Component, LayerUI)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   145
 * @see #setUI(javax.swing.plaf.LayerUI)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   146
 * @see #getUI()
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   147
 * @since 1.7
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   148
 *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   149
 * @author Alexander Potochkin
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   150
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   151
@SuppressWarnings("serial") // Superclass is not serializable across versions
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   152
public final class JLayer<V extends Component>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   153
        extends JComponent
6838
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   154
        implements Scrollable, PropertyChangeListener, Accessible {
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   155
    private V view;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   156
    // this field is necessary because JComponent.ui is transient
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   157
    // when layerUI is serializable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   158
    private LayerUI<? super V> layerUI;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   159
    private JPanel glassPane;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   160
    private long eventMask;
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   161
    private transient boolean isPainting;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   162
    private transient boolean isPaintingImmediately;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   163
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   164
    private static final LayerEventController eventController =
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   165
            new LayerEventController();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   166
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   167
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   168
     * Creates a new {@code JLayer} object with a {@code null} view component
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   169
     * and default {@link javax.swing.plaf.LayerUI}.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   170
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   171
     * @see #setView
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   172
     * @see #setUI
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   173
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   174
    public JLayer() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   175
        this(null);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   176
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   177
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   178
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   179
     * Creates a new {@code JLayer} object
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   180
     * with default {@link javax.swing.plaf.LayerUI}.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   181
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   182
     * @param view the component to be decorated by this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   183
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   184
     * @see #setUI
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   185
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   186
    public JLayer(V view) {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   187
        this(view, new LayerUI<V>());
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   188
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   189
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   190
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   191
     * Creates a new {@code JLayer} object with the specified view component
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   192
     * and {@link javax.swing.plaf.LayerUI} object.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   193
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   194
     * @param view the component to be decorated
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   195
     * @param ui the {@link javax.swing.plaf.LayerUI} delegate
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   196
     * to be used by this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   197
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   198
    public JLayer(V view, LayerUI<V> ui) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   199
        setGlassPane(createGlassPane());
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   200
        setView(view);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   201
        setUI(ui);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   202
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   203
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   204
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   205
     * Returns the {@code JLayer}'s view component or {@code null}.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   206
     * <br>This is a bound property.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   207
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   208
     * @return the {@code JLayer}'s view component
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   209
     *         or {@code null} if none exists
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   210
     *
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   211
     * @see #setView(Component)
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   212
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   213
    public V getView() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   214
        return view;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   215
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   216
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   217
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   218
     * Sets the {@code JLayer}'s view component, which can be {@code null}.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   219
     * <br>This is a bound property.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   220
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   221
     * @param view the view component for this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   222
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   223
     * @see #getView()
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   224
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   225
    public void setView(V view) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   226
        Component oldView = getView();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   227
        if (oldView != null) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   228
            super.remove(oldView);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   229
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   230
        if (view != null) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   231
            super.addImpl(view, null, getComponentCount());
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   232
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   233
        this.view = view;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   234
        firePropertyChange("view", oldView, view);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   235
        revalidate();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   236
        repaint();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   237
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   238
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   239
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   240
     * Sets the {@link javax.swing.plaf.LayerUI} which will perform painting
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   241
     * and receive input events for this {@code JLayer}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   242
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   243
     * @param ui the {@link javax.swing.plaf.LayerUI} for this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   244
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   245
    public void setUI(LayerUI<? super V> ui) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   246
        this.layerUI = ui;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   247
        super.setUI(ui);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   248
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   249
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   250
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   251
     * Returns the {@link javax.swing.plaf.LayerUI} for this {@code JLayer}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   252
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   253
     * @return the {@code LayerUI} for this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   254
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   255
    public LayerUI<? super V> getUI() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   256
        return layerUI;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   257
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   258
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   259
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   260
     * Returns the {@code JLayer}'s glassPane component or {@code null}.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   261
     * <br>This is a bound property.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   262
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   263
     * @return the {@code JLayer}'s glassPane component
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   264
     *         or {@code null} if none exists
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   265
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   266
     * @see #setGlassPane(JPanel)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   267
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   268
    public JPanel getGlassPane() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   269
        return glassPane;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   270
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   271
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   272
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   273
     * Sets the {@code JLayer}'s glassPane component, which can be {@code null}.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   274
     * <br>This is a bound property.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   275
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   276
     * @param glassPane the glassPane component of this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   277
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   278
     * @see #getGlassPane()
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   279
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   280
    public void setGlassPane(JPanel glassPane) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   281
        Component oldGlassPane = getGlassPane();
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   282
        boolean isGlassPaneVisible = false;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   283
        if (oldGlassPane != null) {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   284
            isGlassPaneVisible = oldGlassPane.isVisible();
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   285
            super.remove(oldGlassPane);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   286
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   287
        if (glassPane != null) {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   288
            AWTAccessor.getComponentAccessor().setMixingCutoutShape(glassPane,
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   289
                    new Rectangle());
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   290
            glassPane.setVisible(isGlassPaneVisible);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   291
            super.addImpl(glassPane, null, 0);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   292
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   293
        this.glassPane = glassPane;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   294
        firePropertyChange("glassPane", oldGlassPane, glassPane);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   295
        revalidate();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   296
        repaint();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   297
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   298
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   299
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   300
     * Called by the constructor methods to create a default {@code glassPane}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   301
     * By default this method creates a new JPanel with visibility set to true
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   302
     * and opacity set to false.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   303
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   304
     * @return the default {@code glassPane}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   305
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   306
    public JPanel createGlassPane() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   307
        return new DefaultLayerGlassPane();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   308
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   309
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   310
    /**
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   311
     * Sets the layout manager for this container.  This method is
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   312
     * overridden to prevent the layout manager from being set.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   313
     * <p>Note:  If {@code mgr} is non-{@code null}, this
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   314
     * method will throw an exception as layout managers are not supported on
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   315
     * a {@code JLayer}.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   316
     *
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   317
     * @param mgr the specified layout manager
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   318
     * @exception IllegalArgumentException this method is not supported
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   319
     */
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   320
    public void setLayout(LayoutManager mgr) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   321
        if (mgr != null) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   322
            throw new IllegalArgumentException("JLayer.setLayout() not supported");
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   323
        }
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   324
    }
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   325
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   326
    /**
7258
3a035d9d123a 7002176: JLayer docs build produces warnings
alexp
parents: 7250
diff changeset
   327
     * A non-{@code null} border, or non-zero insets, isn't supported, to prevent the geometry
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   328
     * of this component from becoming complex enough to inhibit
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   329
     * subclassing of {@code LayerUI} class.  To create a {@code JLayer} with a border,
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   330
     * add it to a {@code JPanel} that has a border.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   331
     * <p>Note:  If {@code border} is non-{@code null}, this
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   332
     * method will throw an exception as borders are not supported on
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   333
     * a {@code JLayer}.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   334
     *
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   335
     * @param border the {@code Border} to set
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   336
     * @exception IllegalArgumentException this method is not supported
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   337
     */
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   338
    public void setBorder(Border border) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   339
        if (border != null) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   340
            throw new IllegalArgumentException("JLayer.setBorder() not supported");
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   341
        }
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   342
    }
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   343
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   344
    /**
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   345
     * This method is not supported by {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   346
     * and always throws {@code UnsupportedOperationException}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   347
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   348
     * @throws UnsupportedOperationException this method is not supported
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   349
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   350
     * @see #setView(Component)
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   351
     * @see #setGlassPane(JPanel)
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   352
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   353
    protected void addImpl(Component comp, Object constraints, int index) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   354
        throw new UnsupportedOperationException(
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   355
                "Adding components to JLayer is not supported, " +
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   356
                        "use setView() or setGlassPane() instead");
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   357
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   358
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   359
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   360
     * {@inheritDoc}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   361
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   362
    public void remove(Component comp) {
3975
097245f7db08 6875716: JLayer.remove((Component)null) should behave consistently in (not) throwing NPE
alexp
parents: 3973
diff changeset
   363
        if (comp == null) {
097245f7db08 6875716: JLayer.remove((Component)null) should behave consistently in (not) throwing NPE
alexp
parents: 3973
diff changeset
   364
            super.remove(comp);
097245f7db08 6875716: JLayer.remove((Component)null) should behave consistently in (not) throwing NPE
alexp
parents: 3973
diff changeset
   365
        } else if (comp == getView()) {
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   366
            setView(null);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   367
        } else if (comp == getGlassPane()) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   368
            setGlassPane(null);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   369
        } else {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   370
            super.remove(comp);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   371
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   372
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   373
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   374
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   375
     * {@inheritDoc}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   376
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   377
    public void removeAll() {
7250
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   378
        if (view != null) {
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   379
            setView(null);
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   380
        }
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   381
        if (glassPane != null) {
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   382
            setGlassPane(null);
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   383
        }
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   384
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   385
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   386
    /**
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   387
     * Always returns {@code true} to cause painting to originate from {@code JLayer},
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   388
     * or one of its ancestors.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   389
     *
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   390
     * @return true
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   391
     * @see JComponent#isPaintingOrigin()
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   392
     */
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents: 6838
diff changeset
   393
    protected boolean isPaintingOrigin() {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   394
        return true;
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   395
    }
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   396
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   397
    /**
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   398
     * Delegates its functionality to the
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   399
     * {@link javax.swing.plaf.LayerUI#paintImmediately(int, int, int, int, JLayer)} method,
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   400
     * if {@code LayerUI} is set.
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   401
     *
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   402
     * @param x  the x value of the region to be painted
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   403
     * @param y  the y value of the region to be painted
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   404
     * @param w  the width of the region to be painted
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   405
     * @param h  the height of the region to be painted
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   406
     */
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   407
    public void paintImmediately(int x, int y, int w, int h) {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   408
        if (!isPaintingImmediately && getUI() != null) {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   409
            isPaintingImmediately = true;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   410
            try {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   411
                getUI().paintImmediately(x, y, w, h, this);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   412
            } finally {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   413
                isPaintingImmediately = false;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   414
            }
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   415
        } else {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   416
            super.paintImmediately(x, y, w, h);
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   417
        }
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   418
    }
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   419
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   420
    /**
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   421
     * Delegates all painting to the {@link javax.swing.plaf.LayerUI} object.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   422
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   423
     * @param g the {@code Graphics} to render to
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   424
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   425
    public void paint(Graphics g) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   426
        if (!isPainting) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   427
            isPainting = true;
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   428
            try {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   429
                super.paintComponent(g);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   430
            } finally {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   431
                isPainting = false;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   432
            }
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   433
        } else {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   434
            super.paint(g);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   435
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   436
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   437
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   438
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   439
     * This method is empty, because all painting is done by
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   440
     * {@link #paint(Graphics)} and
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   441
     * {@link javax.swing.plaf.LayerUI#update(Graphics, JComponent)} methods
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   442
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   443
    protected void paintComponent(Graphics g) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   444
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   445
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   446
    /**
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   447
     * The {@code JLayer} overrides the default implementation of
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   448
     * this method (in {@code JComponent}) to return {@code false}.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   449
     * This ensures
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   450
     * that the drawing machinery will call the {@code JLayer}'s
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   451
     * {@code paint}
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   452
     * implementation rather than messaging the {@code JLayer}'s
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   453
     * children directly.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   454
     *
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   455
     * @return false
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   456
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   457
    public boolean isOptimizedDrawingEnabled() {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   458
        return false;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   459
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   460
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   461
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   462
     * {@inheritDoc}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   463
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   464
    public void propertyChange(PropertyChangeEvent evt) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   465
        if (getUI() != null) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   466
            getUI().applyPropertyChange(evt, this);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   467
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   468
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   469
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   470
    /**
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   471
     * Enables the events from JLayer and <b>all its descendants</b>
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   472
     * defined by the specified event mask parameter
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   473
     * to be delivered to the
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   474
     * {@link LayerUI#eventDispatched(AWTEvent, JLayer)} method.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   475
     * <p>
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   476
     * Events are delivered provided that {@code LayerUI} is set
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   477
     * for this {@code JLayer} and the {@code JLayer}
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   478
     * is displayable.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   479
     * <p>
8955
37ab7cd5890a 6992716: Typos in JLayer files
alexp
parents: 8372
diff changeset
   480
     * The following example shows how to correctly use this method
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   481
     * in the {@code LayerUI} implementations:
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   482
     * <pre>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   483
     *    public void installUI(JComponent c) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   484
     *       super.installUI(c);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   485
     *       JLayer l = (JLayer) c;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   486
     *       // this LayerUI will receive only key and focus events
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   487
     *       l.setLayerEventMask(AWTEvent.KEY_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   488
     *    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   489
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   490
     *    public void uninstallUI(JComponent c) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   491
     *       super.uninstallUI(c);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   492
     *       JLayer l = (JLayer) c;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   493
     *       // JLayer must be returned to its initial state
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   494
     *       l.setLayerEventMask(0);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   495
     *    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   496
     * </pre>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   497
     *
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   498
     * By default {@code JLayer} receives no events and its event mask is {@code 0}.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   499
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   500
     * @param layerEventMask the bitmask of event types to receive
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   501
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   502
     * @see #getLayerEventMask()
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   503
     * @see LayerUI#eventDispatched(AWTEvent, JLayer)
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   504
     * @see Component#isDisplayable()
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   505
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   506
    public void setLayerEventMask(long layerEventMask) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   507
        long oldEventMask = getLayerEventMask();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   508
        this.eventMask = layerEventMask;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   509
        firePropertyChange("layerEventMask", oldEventMask, layerEventMask);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   510
        if (layerEventMask != oldEventMask) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   511
            disableEvents(oldEventMask);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   512
            enableEvents(eventMask);
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   513
            if (isDisplayable()) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   514
                eventController.updateAWTEventListener(
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   515
                        oldEventMask, layerEventMask);
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   516
            }
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   517
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   518
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   519
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   520
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   521
     * Returns the bitmap of event mask to receive by this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   522
     * and its {@code LayerUI}.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   523
     * <p>
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   524
     * It means that {@link javax.swing.plaf.LayerUI#eventDispatched(AWTEvent, JLayer)} method
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   525
     * will only receive events that match the event mask.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   526
     * <p>
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   527
     * By default {@code JLayer} receives no events.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   528
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   529
     * @return the bitmask of event types to receive for this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   530
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   531
    public long getLayerEventMask() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   532
        return eventMask;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   533
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   534
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   535
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   536
     * Delegates its functionality to the {@link javax.swing.plaf.LayerUI#updateUI(JLayer)} method,
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   537
     * if {@code LayerUI} is set.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   538
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   539
    public void updateUI() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   540
        if (getUI() != null) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   541
            getUI().updateUI(this);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   542
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   543
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   544
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   545
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   546
     * Returns the preferred size of the viewport for a view component.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   547
     * <p>
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   548
     * If the view component of this layer implements {@link Scrollable}, this method delegates its
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   549
     * implementation to the view component.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   550
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   551
     * @return the preferred size of the viewport for a view component
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   552
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   553
     * @see Scrollable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   554
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   555
    public Dimension getPreferredScrollableViewportSize() {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   556
        if (getView() instanceof Scrollable) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   557
            return ((Scrollable)getView()).getPreferredScrollableViewportSize();
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   558
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   559
        return getPreferredSize();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   560
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   561
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   562
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   563
     * Returns a scroll increment, which is required for components
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   564
     * that display logical rows or columns in order to completely expose
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   565
     * one block of rows or columns, depending on the value of orientation.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   566
     * <p>
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   567
     * If the view component of this layer implements {@link Scrollable}, this method delegates its
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   568
     * implementation to the view component.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   569
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   570
     * @return the "block" increment for scrolling in the specified direction
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   571
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   572
     * @see Scrollable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   573
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   574
    public int getScrollableBlockIncrement(Rectangle visibleRect,
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   575
                                           int orientation, int direction) {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   576
        if (getView() instanceof Scrollable) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   577
            return ((Scrollable)getView()).getScrollableBlockIncrement(visibleRect,
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   578
                    orientation, direction);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   579
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   580
        return (orientation == SwingConstants.VERTICAL) ? visibleRect.height :
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   581
                visibleRect.width;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   582
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   583
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   584
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   585
     * Returns {@code false} to indicate that the height of the viewport does not
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   586
     * determine the height of the layer, unless the preferred height
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   587
     * of the layer is smaller than the height of the viewport.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   588
     * <p>
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   589
     * If the view component of this layer implements {@link Scrollable}, this method delegates its
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   590
     * implementation to the view component.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   591
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   592
     * @return whether the layer should track the height of the viewport
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   593
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   594
     * @see Scrollable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   595
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   596
    public boolean getScrollableTracksViewportHeight() {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   597
        if (getView() instanceof Scrollable) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   598
            return ((Scrollable)getView()).getScrollableTracksViewportHeight();
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   599
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   600
        return false;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   601
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   602
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   603
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   604
     * Returns {@code false} to indicate that the width of the viewport does not
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   605
     * determine the width of the layer, unless the preferred width
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   606
     * of the layer is smaller than the width of the viewport.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   607
     * <p>
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   608
     * If the view component of this layer implements {@link Scrollable}, this method delegates its
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   609
     * implementation to the view component.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   610
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   611
     * @return whether the layer should track the width of the viewport
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   612
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   613
     * @see Scrollable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   614
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   615
    public boolean getScrollableTracksViewportWidth() {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   616
        if (getView() instanceof Scrollable) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   617
            return ((Scrollable)getView()).getScrollableTracksViewportWidth();
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   618
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   619
        return false;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   620
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   621
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   622
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   623
     * Returns a scroll increment, which is required for components
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   624
     * that display logical rows or columns in order to completely expose
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   625
     * one new row or column, depending on the value of orientation.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   626
     * Ideally, components should handle a partially exposed row or column
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   627
     * by returning the distance required to completely expose the item.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   628
     * <p>
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   629
     * Scrolling containers, like {@code JScrollPane}, will use this method
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   630
     * each time the user requests a unit scroll.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 9050
diff changeset
   631
     * <p>
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   632
     * If the view component of this layer implements {@link Scrollable}, this method delegates its
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   633
     * implementation to the view component.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   634
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   635
     * @return The "unit" increment for scrolling in the specified direction.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   636
     *         This value should always be positive.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   637
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   638
     * @see Scrollable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   639
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   640
    public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation,
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   641
                                          int direction) {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   642
        if (getView() instanceof Scrollable) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   643
            return ((Scrollable) getView()).getScrollableUnitIncrement(
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   644
                    visibleRect, orientation, direction);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   645
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   646
        return 1;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   647
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   648
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   649
    private void readObject(ObjectInputStream s)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   650
            throws IOException, ClassNotFoundException {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   651
        s.defaultReadObject();
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   652
        if (layerUI != null) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   653
            setUI(layerUI);
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   654
        }
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   655
        if (eventMask != 0) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   656
            eventController.updateAWTEventListener(0, eventMask);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   657
        }
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   658
    }
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   659
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   660
    /**
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   661
     * {@inheritDoc}
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   662
     */
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   663
    public void addNotify() {
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   664
        super.addNotify();
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   665
        eventController.updateAWTEventListener(0, eventMask);
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   666
    }
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   667
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   668
    /**
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   669
     * {@inheritDoc}
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   670
     */
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   671
    public void removeNotify() {
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   672
        super.removeNotify();
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   673
        eventController.updateAWTEventListener(eventMask, 0);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   674
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   675
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   676
    /**
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   677
     * Delegates its functionality to the {@link javax.swing.plaf.LayerUI#doLayout(JLayer)} method,
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   678
     * if {@code LayerUI} is set.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   679
     */
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   680
    public void doLayout() {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   681
        if (getUI() != null) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   682
            getUI().doLayout(this);
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   683
        }
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   684
    }
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   685
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   686
    /**
6838
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   687
     * Gets the AccessibleContext associated with this {@code JLayer}.
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   688
     *
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   689
     * @return the AccessibleContext associated with this {@code JLayer}.
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   690
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   691
    @SuppressWarnings("serial") // anonymous class
6838
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   692
    public AccessibleContext getAccessibleContext() {
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   693
        if (accessibleContext == null) {
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   694
            accessibleContext = new AccessibleJComponent() {
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   695
                public AccessibleRole getAccessibleRole() {
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   696
                    return AccessibleRole.PANEL;
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   697
                }
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   698
            };
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   699
        }
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   700
        return accessibleContext;
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   701
    }
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   702
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   703
    /**
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   704
     * static AWTEventListener to be shared with all AbstractLayerUIs
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   705
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   706
    private static class LayerEventController implements AWTEventListener {
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   707
        private ArrayList<Long> layerMaskList =
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   708
                new ArrayList<Long>();
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   709
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   710
        private long currentEventMask;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   711
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   712
        private static final long ACCEPTED_EVENTS =
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   713
                AWTEvent.COMPONENT_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   714
                        AWTEvent.CONTAINER_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   715
                        AWTEvent.FOCUS_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   716
                        AWTEvent.KEY_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   717
                        AWTEvent.MOUSE_WHEEL_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   718
                        AWTEvent.MOUSE_MOTION_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   719
                        AWTEvent.MOUSE_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   720
                        AWTEvent.INPUT_METHOD_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   721
                        AWTEvent.HIERARCHY_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   722
                        AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK;
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   723
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   724
        @SuppressWarnings("unchecked")
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   725
        public void eventDispatched(AWTEvent event) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   726
            Object source = event.getSource();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   727
            if (source instanceof Component) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   728
                Component component = (Component) source;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   729
                while (component != null) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   730
                    if (component instanceof JLayer) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   731
                        JLayer l = (JLayer) component;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   732
                        LayerUI ui = l.getUI();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   733
                        if (ui != null &&
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   734
                                isEventEnabled(l.getLayerEventMask(), event.getID()) &&
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   735
                                (!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   736
                            ui.eventDispatched(event, l);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   737
                        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   738
                    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   739
                    component = component.getParent();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   740
                }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   741
            }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   742
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   743
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   744
        private void updateAWTEventListener(long oldEventMask, long newEventMask) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   745
            if (oldEventMask != 0) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   746
                layerMaskList.remove(oldEventMask);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   747
            }
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   748
            if (newEventMask != 0) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   749
                layerMaskList.add(newEventMask);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   750
            }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   751
            long combinedMask = 0;
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   752
            for (Long mask : layerMaskList) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   753
                combinedMask |= mask;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   754
            }
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   755
            // filter out all unaccepted events
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   756
            combinedMask &= ACCEPTED_EVENTS;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   757
            if (combinedMask == 0) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   758
                removeAWTEventListener();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   759
            } else if (getCurrentEventMask() != combinedMask) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   760
                removeAWTEventListener();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   761
                addAWTEventListener(combinedMask);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   762
            }
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   763
            currentEventMask = combinedMask;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   764
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   765
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   766
        private long getCurrentEventMask() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   767
            return currentEventMask;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   768
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   769
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   770
        private void addAWTEventListener(final long eventMask) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   771
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   772
                public Void run() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   773
                    Toolkit.getDefaultToolkit().
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   774
                            addAWTEventListener(LayerEventController.this, eventMask);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   775
                    return null;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   776
                }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   777
            });
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   778
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   779
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   780
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   781
        private void removeAWTEventListener() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   782
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   783
                public Void run() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   784
                    Toolkit.getDefaultToolkit().
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   785
                            removeAWTEventListener(LayerEventController.this);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   786
                    return null;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   787
                }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   788
            });
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   789
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   790
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   791
        private boolean isEventEnabled(long eventMask, int id) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   792
            return (((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   793
                    id >= ComponentEvent.COMPONENT_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   794
                    id <= ComponentEvent.COMPONENT_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   795
                    || ((eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   796
                    id >= ContainerEvent.CONTAINER_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   797
                    id <= ContainerEvent.CONTAINER_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   798
                    || ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   799
                    id >= FocusEvent.FOCUS_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   800
                    id <= FocusEvent.FOCUS_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   801
                    || ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   802
                    id >= KeyEvent.KEY_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   803
                    id <= KeyEvent.KEY_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   804
                    || ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   805
                    id == MouseEvent.MOUSE_WHEEL)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   806
                    || ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   807
                    (id == MouseEvent.MOUSE_MOVED ||
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   808
                            id == MouseEvent.MOUSE_DRAGGED))
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   809
                    || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   810
                    id != MouseEvent.MOUSE_MOVED &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   811
                    id != MouseEvent.MOUSE_DRAGGED &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   812
                    id != MouseEvent.MOUSE_WHEEL &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   813
                    id >= MouseEvent.MOUSE_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   814
                    id <= MouseEvent.MOUSE_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   815
                    || ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   816
                    id >= InputMethodEvent.INPUT_METHOD_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   817
                    id <= InputMethodEvent.INPUT_METHOD_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   818
                    || ((eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   819
                    id == HierarchyEvent.HIERARCHY_CHANGED)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   820
                    || ((eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   821
                    (id == HierarchyEvent.ANCESTOR_MOVED ||
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   822
                            id == HierarchyEvent.ANCESTOR_RESIZED)));
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   823
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   824
    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   825
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   826
    /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   827
     * The default glassPane for the {@link javax.swing.JLayer}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   828
     * It is a subclass of {@code JPanel} which is non opaque by default.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   829
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   830
    @SuppressWarnings("serial") // Superclass is not serializable across versions
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   831
    private static class DefaultLayerGlassPane extends JPanel {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   832
        /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   833
         * Creates a new {@link DefaultLayerGlassPane}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   834
         */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   835
        public DefaultLayerGlassPane() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   836
            setOpaque(false);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   837
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   838
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   839
        /**
8955
37ab7cd5890a 6992716: Typos in JLayer files
alexp
parents: 8372
diff changeset
   840
         * First, implementation of this method iterates through
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   841
         * glassPane's child components and returns {@code true}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   842
         * if any of them is visible and contains passed x,y point.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   843
         * After that it checks if no mouseListeners is attached to this component
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   844
         * and no mouse cursor is set, then it returns {@code false},
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   845
         * otherwise calls the super implementation of this method.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   846
         *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   847
         * @param x the <i>x</i> coordinate of the point
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   848
         * @param y the <i>y</i> coordinate of the point
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   849
         * @return true if this component logically contains x,y
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   850
         */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   851
        public boolean contains(int x, int y) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   852
            for (int i = 0; i < getComponentCount(); i++) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   853
                Component c = getComponent(i);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   854
                Point point = SwingUtilities.convertPoint(this, new Point(x, y), c);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   855
                if(c.isVisible() && c.contains(point)){
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   856
                    return true;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   857
                }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   858
            }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   859
            if (getMouseListeners().length == 0
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   860
                    && getMouseMotionListeners().length == 0
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   861
                    && getMouseWheelListeners().length == 0
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   862
                    && !isCursorSet()) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   863
                return false;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   864
            }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   865
            return super.contains(x, y);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   866
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   867
    }
3733
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
   868
}