jdk/src/share/classes/javax/swing/JLayer.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8372 786e091594a0
child 9050 26c2c1de1631
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8372
diff changeset
     2
 * Copyright (c) 2009, 2011, 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.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    47
 * <p/>
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.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    50
 * <p/>
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.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
    56
 * <p/>
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
 */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   151
public final class JLayer<V extends Component>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   152
        extends JComponent
6838
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   153
        implements Scrollable, PropertyChangeListener, Accessible {
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   154
    private V view;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   155
    // this field is necessary because JComponent.ui is transient
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   156
    // when layerUI is serializable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   157
    private LayerUI<? super V> layerUI;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   158
    private JPanel glassPane;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   159
    private long eventMask;
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   160
    private transient boolean isPainting;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   161
    private transient boolean isPaintingImmediately;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   162
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   163
    private static final LayerEventController eventController =
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   164
            new LayerEventController();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   165
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
     * Creates a new {@code JLayer} object with a {@code null} view component
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   168
     * and default {@link javax.swing.plaf.LayerUI}.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   169
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   170
     * @see #setView
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   171
     * @see #setUI
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   172
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   173
    public JLayer() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   174
        this(null);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   175
    }
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
     * Creates a new {@code JLayer} object
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   179
     * with default {@link javax.swing.plaf.LayerUI}.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   180
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   181
     * @param view the component to be decorated by this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   182
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   183
     * @see #setUI
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   184
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   185
    public JLayer(V view) {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   186
        this(view, new LayerUI<V>());
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   187
    }
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
     * Creates a new {@code JLayer} object with the specified view component
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   191
     * and {@link javax.swing.plaf.LayerUI} object.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   192
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   193
     * @param view the component to be decorated
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   194
     * @param ui the {@link javax.swing.plaf.LayerUI} delegate
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   195
     * to be used by this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   196
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   197
    public JLayer(V view, LayerUI<V> ui) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   198
        setGlassPane(createGlassPane());
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   199
        setView(view);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   200
        setUI(ui);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   201
    }
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
     * Returns the {@code JLayer}'s view component or {@code null}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   205
     * <br/>This is a bound property.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   206
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   207
     * @return the {@code JLayer}'s view component
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   208
     *         or {@code null} if none exists
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   209
     *
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   210
     * @see #setView(Component)
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   211
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   212
    public V getView() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   213
        return view;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   214
    }
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
     * Sets the {@code JLayer}'s view component, which can be {@code null}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   218
     * <br/>This is a bound property.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   219
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   220
     * @param view the view component for this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   221
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   222
     * @see #getView()
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   223
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   224
    public void setView(V view) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   225
        Component oldView = getView();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   226
        if (oldView != null) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   227
            super.remove(oldView);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   228
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   229
        if (view != null) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   230
            super.addImpl(view, null, getComponentCount());
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   231
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   232
        this.view = view;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   233
        firePropertyChange("view", oldView, view);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   234
        revalidate();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   235
        repaint();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   236
    }
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
     * Sets the {@link javax.swing.plaf.LayerUI} which will perform painting
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   240
     * and receive input events for this {@code JLayer}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   241
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   242
     * @param ui the {@link javax.swing.plaf.LayerUI} for this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   243
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   244
    public void setUI(LayerUI<? super V> ui) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   245
        this.layerUI = ui;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   246
        super.setUI(ui);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   247
    }
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
     * Returns the {@link javax.swing.plaf.LayerUI} for this {@code JLayer}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   251
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   252
     * @return the {@code LayerUI} for this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   253
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   254
    public LayerUI<? super V> getUI() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   255
        return layerUI;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   256
    }
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
     * Returns the {@code JLayer}'s glassPane component or {@code null}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   260
     * <br/>This is a bound property.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   261
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   262
     * @return the {@code JLayer}'s glassPane component
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   263
     *         or {@code null} if none exists
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   264
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   265
     * @see #setGlassPane(JPanel)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   266
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   267
    public JPanel getGlassPane() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   268
        return glassPane;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   269
    }
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
     * Sets the {@code JLayer}'s glassPane component, which can be {@code null}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   273
     * <br/>This is a bound property.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   274
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   275
     * @param glassPane the glassPane component of this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   276
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   277
     * @see #getGlassPane()
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   278
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   279
    public void setGlassPane(JPanel glassPane) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   280
        Component oldGlassPane = getGlassPane();
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   281
        boolean isGlassPaneVisible = false;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   282
        if (oldGlassPane != null) {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   283
            isGlassPaneVisible = oldGlassPane.isVisible();
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   284
            super.remove(oldGlassPane);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   285
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   286
        if (glassPane != null) {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   287
            AWTAccessor.getComponentAccessor().setMixingCutoutShape(glassPane,
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   288
                    new Rectangle());
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   289
            glassPane.setVisible(isGlassPaneVisible);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   290
            super.addImpl(glassPane, null, 0);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   291
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   292
        this.glassPane = glassPane;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   293
        firePropertyChange("glassPane", oldGlassPane, glassPane);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   294
        revalidate();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   295
        repaint();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   296
    }
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
     * Called by the constructor methods to create a default {@code glassPane}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   300
     * 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
   301
     * and opacity set to false.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   302
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   303
     * @return the default {@code glassPane}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   304
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   305
    public JPanel createGlassPane() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   306
        return new DefaultLayerGlassPane();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   307
    }
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
    /**
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   310
     * Sets the layout manager for this container.  This method is
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   311
     * overridden to prevent the layout manager from being set.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   312
     * <p/>Note:  If {@code mgr} is non-{@code null}, this
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   313
     * method will throw an exception as layout managers are not supported on
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   314
     * a {@code JLayer}.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   315
     *
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   316
     * @param mgr the specified layout manager
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   317
     * @exception IllegalArgumentException this method is not supported
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   318
     */
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   319
    public void setLayout(LayoutManager mgr) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   320
        if (mgr != null) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   321
            throw new IllegalArgumentException("JLayer.setLayout() not supported");
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   322
        }
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
    /**
7258
3a035d9d123a 7002176: JLayer docs build produces warnings
alexp
parents: 7250
diff changeset
   326
     * 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
   327
     * of this component from becoming complex enough to inhibit
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   328
     * subclassing of {@code LayerUI} class.  To create a {@code JLayer} with a border,
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   329
     * add it to a {@code JPanel} that has a border.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   330
     * <p/>Note:  If {@code border} is non-{@code null}, this
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   331
     * method will throw an exception as borders are not supported on
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   332
     * a {@code JLayer}.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   333
     *
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   334
     * @param border the {@code Border} to set
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   335
     * @exception IllegalArgumentException this method is not supported
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   336
     */
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   337
    public void setBorder(Border border) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   338
        if (border != null) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   339
            throw new IllegalArgumentException("JLayer.setBorder() not supported");
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   340
        }
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
    /**
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   344
     * This method is not supported by {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   345
     * and always throws {@code UnsupportedOperationException}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   346
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   347
     * @throws UnsupportedOperationException this method is not supported
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   348
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   349
     * @see #setView(Component)
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   350
     * @see #setGlassPane(JPanel)
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   351
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   352
    protected void addImpl(Component comp, Object constraints, int index) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   353
        throw new UnsupportedOperationException(
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   354
                "Adding components to JLayer is not supported, " +
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   355
                        "use setView() or setGlassPane() instead");
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   356
    }
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
     * {@inheritDoc}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   360
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   361
    public void remove(Component comp) {
3975
097245f7db08 6875716: JLayer.remove((Component)null) should behave consistently in (not) throwing NPE
alexp
parents: 3973
diff changeset
   362
        if (comp == null) {
097245f7db08 6875716: JLayer.remove((Component)null) should behave consistently in (not) throwing NPE
alexp
parents: 3973
diff changeset
   363
            super.remove(comp);
097245f7db08 6875716: JLayer.remove((Component)null) should behave consistently in (not) throwing NPE
alexp
parents: 3973
diff changeset
   364
        } else if (comp == getView()) {
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   365
            setView(null);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   366
        } else if (comp == getGlassPane()) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   367
            setGlassPane(null);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   368
        } else {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   369
            super.remove(comp);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   370
        }
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
     * {@inheritDoc}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   375
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   376
    public void removeAll() {
7250
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   377
        if (view != null) {
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   378
            setView(null);
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   379
        }
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   380
        if (glassPane != null) {
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   381
            setGlassPane(null);
b16cad13bf2c 6994419: JLayer.removeAll() behavior doesn't correspond to JLayer.remove() behavior.
alexp
parents: 7005
diff changeset
   382
        }
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   383
    }
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
    /**
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   386
     * Always returns {@code true} to cause painting to originate from {@code JLayer},
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   387
     * or one of its ancestors.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   388
     *
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   389
     * @return true
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   390
     * @see JComponent#isPaintingOrigin()
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   391
     */
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents: 6838
diff changeset
   392
    protected boolean isPaintingOrigin() {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   393
        return true;
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   394
    }
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   395
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   396
    /**
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   397
     * 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
   398
     * {@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
   399
     * if {@code LayerUI} is set.
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   400
     *
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   401
     * @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
   402
     * @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
   403
     * @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
   404
     * @param h  the height of the region to be painted
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   405
     */
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   406
    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
   407
        if (!isPaintingImmediately && getUI() != null) {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   408
            isPaintingImmediately = true;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   409
            try {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   410
                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
   411
            } finally {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   412
                isPaintingImmediately = false;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   413
            }
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   414
        } else {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   415
            super.paintImmediately(x, y, w, h);
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   416
        }
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
    /**
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   420
     * Delegates all painting to the {@link javax.swing.plaf.LayerUI} object.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   421
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   422
     * @param g the {@code Graphics} to render to
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   423
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   424
    public void paint(Graphics g) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   425
        if (!isPainting) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   426
            isPainting = true;
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   427
            try {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   428
                super.paintComponent(g);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   429
            } finally {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   430
                isPainting = false;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7668
diff changeset
   431
            }
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   432
        } else {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   433
            super.paint(g);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   434
        }
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
     * This method is empty, because all painting is done by
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   439
     * {@link #paint(Graphics)} and
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   440
     * {@link javax.swing.plaf.LayerUI#update(Graphics, JComponent)} methods
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   441
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   442
    protected void paintComponent(Graphics g) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   443
    }
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
    /**
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   446
     * The {@code JLayer} overrides the default implementation of
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   447
     * this method (in {@code JComponent}) to return {@code false}.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   448
     * This ensures
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   449
     * that the drawing machinery will call the {@code JLayer}'s
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   450
     * {@code paint}
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   451
     * implementation rather than messaging the {@code JLayer}'s
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   452
     * children directly.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   453
     *
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   454
     * @return false
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   455
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   456
    public boolean isOptimizedDrawingEnabled() {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   457
        return false;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   458
    }
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
     * {@inheritDoc}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   462
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   463
    public void propertyChange(PropertyChangeEvent evt) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   464
        if (getUI() != null) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   465
            getUI().applyPropertyChange(evt, this);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   466
        }
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
    /**
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   470
     * 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
   471
     * 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
   472
     * to be delivered to the
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   473
     * {@link LayerUI#eventDispatched(AWTEvent, JLayer)} method.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   474
     * <p/>
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   475
     * 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
   476
     * 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
   477
     * is displayable.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   478
     * <p/>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   479
     * The following example shows how to correclty use this method
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   480
     * in the {@code LayerUI} implementations:
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   481
     * <pre>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   482
     *    public void installUI(JComponent c) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   483
     *       super.installUI(c);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   484
     *       JLayer l = (JLayer) c;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   485
     *       // this LayerUI will receive only key and focus events
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   486
     *       l.setLayerEventMask(AWTEvent.KEY_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   487
     *    }
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
     *    public void uninstallUI(JComponent c) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   490
     *       super.uninstallUI(c);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   491
     *       JLayer l = (JLayer) c;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   492
     *       // JLayer must be returned to its initial state
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   493
     *       l.setLayerEventMask(0);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   494
     *    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   495
     * </pre>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   496
     *
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   497
     * 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
   498
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   499
     * @param layerEventMask the bitmask of event types to receive
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   500
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   501
     * @see #getLayerEventMask()
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   502
     * @see LayerUI#eventDispatched(AWTEvent, JLayer)
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   503
     * @see Component#isDisplayable()
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   504
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   505
    public void setLayerEventMask(long layerEventMask) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   506
        long oldEventMask = getLayerEventMask();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   507
        this.eventMask = layerEventMask;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   508
        firePropertyChange("layerEventMask", oldEventMask, layerEventMask);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   509
        if (layerEventMask != oldEventMask) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   510
            disableEvents(oldEventMask);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   511
            enableEvents(eventMask);
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   512
            if (isDisplayable()) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   513
                eventController.updateAWTEventListener(
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   514
                        oldEventMask, layerEventMask);
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   515
            }
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   516
        }
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
     * Returns the bitmap of event mask to receive by this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   521
     * and its {@code LayerUI}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   522
     * <p/>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   523
     * It means that {@link javax.swing.plaf.LayerUI#eventDispatched(AWTEvent, JLayer)} method
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   524
     * will only receive events that match the event mask.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   525
     * <p/>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   526
     * By default {@code JLayer} receives no events.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   527
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   528
     * @return the bitmask of event types to receive for this {@code JLayer}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   529
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   530
    public long getLayerEventMask() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   531
        return eventMask;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   532
    }
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
     * 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
   536
     * if {@code LayerUI} is set.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   537
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   538
    public void updateUI() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   539
        if (getUI() != null) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   540
            getUI().updateUI(this);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   541
        }
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
     * Returns the preferred size of the viewport for a view component.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   546
     * <p/>
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   547
     * If the view component of this layer implements {@link Scrollable}, this method delegates its
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   548
     * implementation to the view component.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   549
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   550
     * @return the preferred size of the viewport for a view component
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   551
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   552
     * @see Scrollable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   553
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   554
    public Dimension getPreferredScrollableViewportSize() {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   555
        if (getView() instanceof Scrollable) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   556
            return ((Scrollable)getView()).getPreferredScrollableViewportSize();
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   557
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   558
        return getPreferredSize();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   559
    }
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
     * Returns a scroll increment, which is required for components
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   563
     * that display logical rows or columns in order to completely expose
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   564
     * one block of rows or columns, depending on the value of orientation.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   565
     * <p/>
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   566
     * If the view component of this layer implements {@link Scrollable}, this method delegates its
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   567
     * implementation to the view component.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   568
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   569
     * @return the "block" increment for scrolling in the specified direction
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   570
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   571
     * @see Scrollable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   572
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   573
    public int getScrollableBlockIncrement(Rectangle visibleRect,
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   574
                                           int orientation, int direction) {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   575
        if (getView() instanceof Scrollable) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   576
            return ((Scrollable)getView()).getScrollableBlockIncrement(visibleRect,
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   577
                    orientation, direction);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   578
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   579
        return (orientation == SwingConstants.VERTICAL) ? visibleRect.height :
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   580
                visibleRect.width;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   581
    }
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
     * 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
   585
     * determine the height of the layer, unless the preferred height
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   586
     * of the layer is smaller than the height of the viewport.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   587
     * <p/>
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   588
     * If the view component of this layer implements {@link Scrollable}, this method delegates its
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   589
     * implementation to the view component.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   590
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   591
     * @return whether the layer should track the height of the viewport
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   592
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   593
     * @see Scrollable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   594
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   595
    public boolean getScrollableTracksViewportHeight() {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   596
        if (getView() instanceof Scrollable) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   597
            return ((Scrollable)getView()).getScrollableTracksViewportHeight();
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   598
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   599
        return false;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   600
    }
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
     * 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
   604
     * determine the width of the layer, unless the preferred width
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   605
     * of the layer is smaller than the width of the viewport.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   606
     * <p/>
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   607
     * If the view component of this layer implements {@link Scrollable}, this method delegates its
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   608
     * implementation to the view component.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   609
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   610
     * @return whether the layer should track the width of the viewport
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   611
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   612
     * @see Scrollable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   613
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   614
    public boolean getScrollableTracksViewportWidth() {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   615
        if (getView() instanceof Scrollable) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   616
            return ((Scrollable)getView()).getScrollableTracksViewportWidth();
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   617
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   618
        return false;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   619
    }
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
     * Returns a scroll increment, which is required for components
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   623
     * that display logical rows or columns in order to completely expose
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   624
     * one new row or column, depending on the value of orientation.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   625
     * Ideally, components should handle a partially exposed row or column
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   626
     * by returning the distance required to completely expose the item.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   627
     * <p/>
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   628
     * Scrolling containers, like {@code JScrollPane}, will use this method
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   629
     * each time the user requests a unit scroll.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   630
     * <p/>
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   631
     * If the view component of this layer implements {@link Scrollable}, this method delegates its
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   632
     * implementation to the view component.
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   633
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   634
     * @return The "unit" increment for scrolling in the specified direction.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   635
     *         This value should always be positive.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   636
     *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   637
     * @see Scrollable
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   638
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   639
    public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation,
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   640
                                          int direction) {
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   641
        if (getView() instanceof Scrollable) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   642
            return ((Scrollable) getView()).getScrollableUnitIncrement(
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   643
                    visibleRect, orientation, direction);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   644
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   645
        return 1;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   646
    }
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
    private void readObject(ObjectInputStream s)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   649
            throws IOException, ClassNotFoundException {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   650
        s.defaultReadObject();
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   651
        if (layerUI != null) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   652
            setUI(layerUI);
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   653
        }
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   654
        if (eventMask != 0) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   655
            eventController.updateAWTEventListener(0, eventMask);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   656
        }
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   657
    }
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   658
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   659
    /**
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   660
     * {@inheritDoc}
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   661
     */
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   662
    public void addNotify() {
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   663
        super.addNotify();
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   664
        eventController.updateAWTEventListener(0, eventMask);
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   665
    }
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   666
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   667
    /**
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   668
     * {@inheritDoc}
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   669
     */
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   670
    public void removeNotify() {
3748
b88af44d77a8 6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents: 3743
diff changeset
   671
        super.removeNotify();
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   672
        eventController.updateAWTEventListener(eventMask, 0);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   673
    }
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
    /**
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   676
     * Delegates its functionality to the {@link javax.swing.plaf.LayerUI#doLayout(JLayer)} method,
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   677
     * if {@code LayerUI} is set.
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   678
     */
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   679
    public void doLayout() {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   680
        if (getUI() != null) {
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   681
            getUI().doLayout(this);
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   682
        }
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
    /**
6838
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   686
     * Gets the AccessibleContext associated with this {@code JLayer}.
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   687
     *
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   688
     * @return the AccessibleContext associated with this {@code JLayer}.
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   689
     */
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   690
    public AccessibleContext getAccessibleContext() {
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   691
        if (accessibleContext == null) {
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   692
            accessibleContext = new AccessibleJComponent() {
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   693
                public AccessibleRole getAccessibleRole() {
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   694
                    return AccessibleRole.PANEL;
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   695
                }
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   696
            };
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
        return accessibleContext;
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
c101d59707f3 6986385: JLayer should implement accessible interface
alexp
parents: 6647
diff changeset
   701
    /**
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   702
     * static AWTEventListener to be shared with all AbstractLayerUIs
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   703
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   704
    private static class LayerEventController implements AWTEventListener {
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   705
        private ArrayList<Long> layerMaskList =
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   706
                new ArrayList<Long>();
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   707
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   708
        private long currentEventMask;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   709
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   710
        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
   711
                AWTEvent.COMPONENT_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   712
                        AWTEvent.CONTAINER_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   713
                        AWTEvent.FOCUS_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   714
                        AWTEvent.KEY_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   715
                        AWTEvent.MOUSE_WHEEL_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   716
                        AWTEvent.MOUSE_MOTION_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   717
                        AWTEvent.MOUSE_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   718
                        AWTEvent.INPUT_METHOD_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   719
                        AWTEvent.HIERARCHY_EVENT_MASK |
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   720
                        AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK;
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   721
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   722
        @SuppressWarnings("unchecked")
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   723
        public void eventDispatched(AWTEvent event) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   724
            Object source = event.getSource();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   725
            if (source instanceof Component) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   726
                Component component = (Component) source;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   727
                while (component != null) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   728
                    if (component instanceof JLayer) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   729
                        JLayer l = (JLayer) component;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   730
                        LayerUI ui = l.getUI();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   731
                        if (ui != null &&
6647
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   732
                                isEventEnabled(l.getLayerEventMask(), event.getID()) &&
9d119d6c36b9 6982661: Complete JLayer component
alexp
parents: 5506
diff changeset
   733
                                (!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   734
                            ui.eventDispatched(event, l);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   735
                        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   736
                    }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   737
                    component = component.getParent();
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
            }
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
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   742
        private void updateAWTEventListener(long oldEventMask, long newEventMask) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   743
            if (oldEventMask != 0) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   744
                layerMaskList.remove(oldEventMask);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   745
            }
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   746
            if (newEventMask != 0) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   747
                layerMaskList.add(newEventMask);
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   748
            }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   749
            long combinedMask = 0;
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   750
            for (Long mask : layerMaskList) {
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   751
                combinedMask |= mask;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   752
            }
5451
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   753
            // filter out all unaccepted events
82e4cf75e5b4 6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents: 3975
diff changeset
   754
            combinedMask &= ACCEPTED_EVENTS;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   755
            if (combinedMask == 0) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   756
                removeAWTEventListener();
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   757
            } else if (getCurrentEventMask() != combinedMask) {
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
                addAWTEventListener(combinedMask);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   760
            }
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   761
            currentEventMask = combinedMask;
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   762
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   763
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   764
        private long getCurrentEventMask() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   765
            return currentEventMask;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   766
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   767
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   768
        private void addAWTEventListener(final long eventMask) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   769
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   770
                public Void run() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   771
                    Toolkit.getDefaultToolkit().
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   772
                            addAWTEventListener(LayerEventController.this, eventMask);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   773
                    return null;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   774
                }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   775
            });
3743
906063616ec2 6872503: JLayer event handling should be rewritten
alexp
parents: 3737
diff changeset
   776
3508
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   777
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   778
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   779
        private void removeAWTEventListener() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   780
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   781
                public Void run() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   782
                    Toolkit.getDefaultToolkit().
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   783
                            removeAWTEventListener(LayerEventController.this);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   784
                    return null;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   785
                }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   786
            });
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
        private boolean isEventEnabled(long eventMask, int id) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   790
            return (((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   791
                    id >= ComponentEvent.COMPONENT_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   792
                    id <= ComponentEvent.COMPONENT_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   793
                    || ((eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   794
                    id >= ContainerEvent.CONTAINER_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   795
                    id <= ContainerEvent.CONTAINER_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   796
                    || ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   797
                    id >= FocusEvent.FOCUS_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   798
                    id <= FocusEvent.FOCUS_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   799
                    || ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   800
                    id >= KeyEvent.KEY_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   801
                    id <= KeyEvent.KEY_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   802
                    || ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   803
                    id == MouseEvent.MOUSE_WHEEL)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   804
                    || ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   805
                    (id == MouseEvent.MOUSE_MOVED ||
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   806
                            id == MouseEvent.MOUSE_DRAGGED))
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   807
                    || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   808
                    id != MouseEvent.MOUSE_MOVED &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   809
                    id != MouseEvent.MOUSE_DRAGGED &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   810
                    id != MouseEvent.MOUSE_WHEEL &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   811
                    id >= MouseEvent.MOUSE_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   812
                    id <= MouseEvent.MOUSE_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   813
                    || ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   814
                    id >= InputMethodEvent.INPUT_METHOD_FIRST &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   815
                    id <= InputMethodEvent.INPUT_METHOD_LAST)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   816
                    || ((eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   817
                    id == HierarchyEvent.HIERARCHY_CHANGED)
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   818
                    || ((eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 &&
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   819
                    (id == HierarchyEvent.ANCESTOR_MOVED ||
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   820
                            id == HierarchyEvent.ANCESTOR_RESIZED)));
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   821
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   822
    }
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
     * The default glassPane for the {@link javax.swing.JLayer}.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   826
     * 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
   827
     */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   828
    private static class DefaultLayerGlassPane extends JPanel {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   829
        /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   830
         * Creates a new {@link DefaultLayerGlassPane}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   831
         */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   832
        public DefaultLayerGlassPane() {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   833
            setOpaque(false);
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
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   836
        /**
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   837
         * First, implementatation of this method iterates through
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   838
         * glassPane's child components and returns {@code true}
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   839
         * if any of them is visible and contains passed x,y point.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   840
         * After that it checks if no mouseListeners is attached to this component
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   841
         * and no mouse cursor is set, then it returns {@code false},
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   842
         * otherwise calls the super implementation of this method.
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   843
         *
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   844
         * @param x the <i>x</i> coordinate of the point
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   845
         * @param y the <i>y</i> coordinate of the point
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   846
         * @return true if this component logically contains x,y
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   847
         */
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   848
        public boolean contains(int x, int y) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   849
            for (int i = 0; i < getComponentCount(); i++) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   850
                Component c = getComponent(i);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   851
                Point point = SwingUtilities.convertPoint(this, new Point(x, y), c);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   852
                if(c.isVisible() && c.contains(point)){
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   853
                    return true;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   854
                }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   855
            }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   856
            if (getMouseListeners().length == 0
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   857
                    && getMouseMotionListeners().length == 0
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   858
                    && getMouseWheelListeners().length == 0
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   859
                    && !isCursorSet()) {
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   860
                return false;
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   861
            }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   862
            return super.contains(x, y);
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   863
        }
defe8eec9251 6822696: Integrating JXLayer component to Swing library
alexp
parents:
diff changeset
   864
    }
3733
af63479b67b8 6872492: JLayer sources contain wrong header
alexp
parents: 3508
diff changeset
   865
}