jdk/src/share/classes/sun/swing/JLightweightFrame.java
author ant
Wed, 15 May 2013 16:49:34 +0400
changeset 17415 62b97a10da72
parent 16706 4b243017cd27
child 19026 96141cb8d7eb
permissions -rw-r--r--
8014227: JLightweightFrame needs another synchronization policy Reviewed-by: art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     1
/*
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     4
 *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    10
 *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    15
 * accompanied this code).
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    16
 *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    20
 *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    23
 * questions.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    24
 */
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    25
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    26
package sun.swing;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    27
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    28
import java.awt.BorderLayout;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    29
import java.awt.Color;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    30
import java.awt.Component;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    31
import java.awt.Container;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    32
import java.awt.EventQueue;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    33
import java.awt.Graphics;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    34
import java.awt.Graphics2D;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    35
import java.awt.Rectangle;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    36
import java.awt.image.BufferedImage;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    37
import java.awt.image.DataBufferInt;
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    38
import java.security.AccessController;
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    39
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    40
import javax.swing.JLayeredPane;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    41
import javax.swing.JPanel;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    42
import javax.swing.JRootPane;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    43
import javax.swing.LayoutFocusTraversalPolicy;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    44
import javax.swing.RootPaneContainer;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    45
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    46
import sun.awt.LightweightFrame;
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    47
import sun.security.action.GetPropertyAction;
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    48
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    49
/**
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    50
 * The frame serves as a lightweight container which paints its content
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    51
 * to an offscreen image and provides access to the image's data via the
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    52
 * {@link LightweightContent} interface. Note, that it may not be shown
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    53
 * as a standalone toplevel frame. Its purpose is to provide functionality
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    54
 * for lightweight embedding.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    55
 *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    56
 * @author Artem Ananiev
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    57
 * @author Anton Tarasov
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    58
 */
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    59
public final class JLightweightFrame extends LightweightFrame implements RootPaneContainer {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    60
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    61
    private final JRootPane rootPane = new JRootPane();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    62
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    63
    private LightweightContent content;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    64
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    65
    private Component component;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    66
    private JPanel contentPane;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    67
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    68
    private BufferedImage bbImage;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    69
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    70
    /**
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    71
     * {@code copyBufferEnabled}, true by default, defines the following strategy.
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    72
     * A duplicating (copy) buffer is created for the original pixel buffer.
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    73
     * The copy buffer is synchronized with the original buffer every time the
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    74
     * latter changes. {@code JLightweightFrame} passes the copy buffer array
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    75
     * to the {@link LightweightContent#imageBufferReset} method. The code spot
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    76
     * which synchronizes two buffers becomes the only critical section guarded
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    77
     * by the lock (managed with the {@link LightweightContent#paintLock()},
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    78
     * {@link LightweightContent#paintUnlock()} methods).
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    79
     */
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    80
    private boolean copyBufferEnabled;
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    81
    private int[] copyBuffer;
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    82
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    83
    /**
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    84
     * Constructs a new, initially invisible {@code JLightweightFrame}
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    85
     * instance.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    86
     */
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    87
    public JLightweightFrame() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    88
        super();
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    89
        copyBufferEnabled = "true".equals(AccessController.
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    90
            doPrivileged(new GetPropertyAction("jlf.copyBufferEnabled", "true")));
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
    91
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    92
        add(rootPane, BorderLayout.CENTER);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    93
        setFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
16706
4b243017cd27 8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents: 15983
diff changeset
    94
        if (getGraphicsConfiguration().isTranslucencyCapable()) {
4b243017cd27 8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents: 15983
diff changeset
    95
            setBackground(new Color(0, 0, 0, 0));
4b243017cd27 8010375: sun.swing.JLightweightFrame should be implemented for XToolkit
ant
parents: 15983
diff changeset
    96
        }
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    97
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    98
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
    99
    /**
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   100
     * Sets the {@link LightweightContent} instance for this frame.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   101
     * The {@code JComponent} object returned by the
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   102
     * {@link LightweightContent#getComponent()} method is immediately
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   103
     * added to the frame's content pane.
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   104
     *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   105
     * @param content the {@link LightweightContent} instance
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   106
     */
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   107
    public void setContent(LightweightContent content) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   108
        this.content = content;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   109
        this.component = content.getComponent();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   110
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   111
        initInterior();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   112
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   113
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   114
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   115
    public Graphics getGraphics() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   116
        if (bbImage == null) return null;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   117
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   118
        Graphics2D g = bbImage.createGraphics();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   119
        g.setBackground(getBackground());
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   120
        g.setColor(getForeground());
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   121
        g.setFont(getFont());
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   122
        return g;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   123
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   124
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   125
    /**
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   126
     * {@inheritDoc}
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   127
     *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   128
     * @see LightweightContent#focusGrabbed()
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   129
     */
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   130
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   131
    public void grabFocus() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   132
        if (content != null) content.focusGrabbed();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   133
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   134
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   135
    /**
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   136
     * {@inheritDoc}
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   137
     *
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   138
     * @see LightweightContent#focusUngrabbed()
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   139
     */
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   140
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   141
    public void ungrabFocus() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   142
        if (content != null) content.focusUngrabbed();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   143
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   144
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   145
    private void syncCopyBuffer(boolean reset, int x, int y, int w, int h) {
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   146
        content.paintLock();
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   147
        try {
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   148
            int[] srcBuffer = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData();
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   149
            if (reset) {
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   150
                copyBuffer = new int[srcBuffer.length];
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   151
            }
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   152
            int linestride = bbImage.getWidth();
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   153
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   154
            for (int i=0; i<h; i++) {
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   155
                int from = (y + i) * linestride + x;
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   156
                System.arraycopy(srcBuffer, from, copyBuffer, from, w);
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   157
            }
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   158
        } finally {
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   159
            content.paintUnlock();
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   160
        }
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   161
    }
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   162
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   163
    private void initInterior() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   164
        contentPane = new JPanel() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   165
            @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   166
            public void paint(Graphics g) {
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   167
                if (!copyBufferEnabled) {
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   168
                    content.paintLock();
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   169
                }
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   170
                try {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   171
                    super.paint(g);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   172
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   173
                    final Rectangle clip = g.getClipBounds() != null ?
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   174
                            g.getClipBounds() :
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   175
                            new Rectangle(0, 0, contentPane.getWidth(), contentPane.getHeight());
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   176
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   177
                    clip.x = Math.max(0, clip.x);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   178
                    clip.y = Math.max(0, clip.y);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   179
                    clip.width = Math.min(contentPane.getWidth(), clip.width);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   180
                    clip.height = Math.min(contentPane.getHeight(), clip.height);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   181
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   182
                    EventQueue.invokeLater(new Runnable() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   183
                        @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   184
                        public void run() {
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   185
                            if (copyBufferEnabled) {
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   186
                                syncCopyBuffer(false, clip.x, clip.y, clip.width, clip.height);
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   187
                            }
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   188
                            content.imageUpdated(clip.x, clip.y, clip.width, clip.height);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   189
                        }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   190
                    });
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   191
                } finally {
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   192
                    if (!copyBufferEnabled) {
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   193
                        content.paintUnlock();
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   194
                    }
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   195
                }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   196
            }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   197
            @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   198
            protected boolean isPaintingOrigin() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   199
                return true;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   200
            }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   201
        };
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   202
        contentPane.setLayout(new BorderLayout());
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   203
        contentPane.add(component);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   204
        setContentPane(contentPane);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   205
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   206
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   207
    @SuppressWarnings("deprecation")
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   208
    @Override public void reshape(int x, int y, int width, int height) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   209
        super.reshape(x, y, width, height);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   210
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   211
        if (width == 0 || height == 0) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   212
            return;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   213
        }
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   214
        if (!copyBufferEnabled) {
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   215
            content.paintLock();
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   216
        }
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   217
        try {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   218
            if ((bbImage == null) || (width != bbImage.getWidth()) || (height != bbImage.getHeight())) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   219
                boolean createBB = true;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   220
                int newW = width;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   221
                int newH = height;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   222
                if (bbImage != null) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   223
                    int oldW = bbImage.getWidth();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   224
                    int oldH = bbImage.getHeight();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   225
                    if ((oldW >= newW) && (oldH >= newH)) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   226
                        createBB = false;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   227
                    } else {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   228
                        if (oldW >= newW) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   229
                            newW = oldW;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   230
                        } else {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   231
                            newW = Math.max((int)(oldW * 1.2), width);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   232
                        }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   233
                        if (oldH >= newH) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   234
                            newH = oldH;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   235
                        } else {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   236
                            newH = Math.max((int)(oldH * 1.2), height);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   237
                        }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   238
                    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   239
                }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   240
                if (createBB) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   241
                    BufferedImage oldBB = bbImage;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   242
                    bbImage = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB_PRE);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   243
                    if (oldBB != null) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   244
                        Graphics g = bbImage.getGraphics();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   245
                        try {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   246
                            g.drawImage(oldBB, 0, 0, newW, newH, null);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   247
                        } finally {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   248
                            g.dispose();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   249
                            oldBB.flush();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   250
                        }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   251
                    }
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   252
                    int[] pixels = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData();
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   253
                    if (copyBufferEnabled) {
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   254
                        syncCopyBuffer(true, 0, 0, width, height);
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   255
                        pixels = copyBuffer;
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   256
                    }
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   257
                    content.imageBufferReset(pixels, 0, 0, width, height, bbImage.getWidth());
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   258
                    return;
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   259
                }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   260
            }
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   261
            content.imageReshaped(0, 0, width, height);
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   262
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   263
        } finally {
17415
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   264
            if (!copyBufferEnabled) {
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   265
                content.paintUnlock();
62b97a10da72 8014227: JLightweightFrame needs another synchronization policy
ant
parents: 16706
diff changeset
   266
            }
15983
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   267
        }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   268
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   269
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   270
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   271
    public JRootPane getRootPane() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   272
        return rootPane;
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   273
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   274
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   275
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   276
    public void setContentPane(Container contentPane) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   277
        getRootPane().setContentPane(contentPane);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   278
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   279
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   280
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   281
    public Container getContentPane() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   282
        return getRootPane().getContentPane();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   283
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   284
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   285
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   286
    public void setLayeredPane(JLayeredPane layeredPane) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   287
        getRootPane().setLayeredPane(layeredPane);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   288
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   289
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   290
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   291
    public JLayeredPane getLayeredPane() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   292
        return getRootPane().getLayeredPane();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   293
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   294
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   295
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   296
    public void setGlassPane(Component glassPane) {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   297
        getRootPane().setGlassPane(glassPane);
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   298
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   299
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   300
    @Override
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   301
    public Component getGlassPane() {
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   302
        return getRootPane().getGlassPane();
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   303
    }
26a673dec5b2 8006406: lightweight embedding in other Java UI toolkits
ant
parents:
diff changeset
   304
}