1 /*
   2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.swing;
  27 
  28 import javax.swing.JComponent;
  29 
  30 /**
  31  * The interface by means of which the {@link JLightweightFrame} class communicates to its
  32  * client application.
  33  * <p>
  34  * The client application implements this interface so it can response to requests and process
  35  * notifications from {@code JLightweightFrame}. An implementation of this interface is associated
  36  * with a {@code JLightweightFrame} instance via the {@link JLightweightFrame#setContent} method.
  37  * 
  38  * A hierarchy of components contained in the {@code JComponent} instance returned by the
  39  * {@link #getComponent} method should not contain any heavyweight components, otherwise
  40  * {@code JLightweightFrame} may fail to paint it.
  41  * 
  42  * @author Artem Ananiev
  43  * @author Anton Tarasov
  44  * @author Jim Graham
  45  */
  46 public interface LightweightContent {
  47 
  48     /**
  49      * The client application overrides this method to return the {@code JComponent} instance
  50      * which the {@code JLightweightFrame} container will paint as its lightweight content.
  51      * A hierarchy of components contained in this component should not contain any heavyweight
  52      * objects.
  53      * 
  54      * @return the component to paint
  55      */
  56     public JComponent getComponent();
  57 
  58     /**
  59      * {@code JLightweightFrame} calls this method to notify the client application that it
  60      * acquires the paint lock. The client application should implement the locking mechanism
  61      * in order to synchronize access to the content image data, shared between {@code JLightweightFrame}
  62      * and the client application.
  63      * 
  64      * @see #paintUnlock
  65      */
  66     public void paintLock();
  67 
  68     /**
  69      * {@code JLightweightFrame} calls this method to notify the client application that it
  70      * releases the paint lock. The client application should implement the locking mechanism
  71      * in order to synchronize access to the content image data, shared between {@code JLightweightFrame}
  72      * and the client application.
  73      * 
  74      * @see #paintLock
  75      */
  76     public void paintUnlock();
  77     
  78     /**
  79      * {@code JLightweightFrame} calls this method to notify the client application that a new data buffer
  80      * has been set as a content pixel buffer. Typically this occurs when a buffer of a larger size is
  81      * created in response to a content resize event. The method reports a reference to the pixel data buffer,
  82      * the content image bounds within the buffer and the line stride of the buffer. These values have the
  83      * following correlation.
  84      * <p>
  85      * The {@code width} and {@code height} matches the size of the content (the component returned from the
  86      * {@link #getComponent} method). The {@code x} and {@code y} is the origin of the content, {@code (0, 0)}
  87      * in the coordinate space of the content, appearing at {@code data[y * linestride + x]} in the buffer.
  88      * All indices {@code data[(y + j) * linestride + (x + i)]} where {@code (0 <= i < width)} and {@code (0 <= j < height)}
  89      * will represent valid pixel data, {@code (i, j)} in the coordinate space of the content.
  90      * 
  91      * @param data the content pixel data buffer of INT_ARGB_PRE type
  92      * @param x the x coordinate of the image
  93      * @param y the y coordinate of the image
  94      * @param width the width of the image
  95      * @param height the height of the image
  96      * @param linestride the line stride of the pixel buffer
  97      */
  98     public void imageBufferReset(int[] data, int x, int y, int width, int height, int linestride);
  99     
 100     /**
 101      * {@code JLightweightFrame} calls this method to notify the client application that the content image
 102      * bounds have been changed within the image's pixel buffer.
 103      * 
 104      * @param x the x coordinate of the image
 105      * @param y the y coordinate of the image
 106      * @param width the width of the image
 107      * @param height the height of the image
 108      * 
 109      * @see #imageBufferReset
 110      */
 111     public void imageReshaped(int x, int y, int width, int height);
 112     
 113     /**
 114      * {@code JLightweightFrame} calls this method to notify the client application that a part of
 115      * the content image, or the whole image has been updated. The method reports bounds of the
 116      * rectangular dirty region. The {@code dirtyX} and {@code dirtyY} is the origin of the dirty
 117      * rectangle, which is relative to the origin of the content, appearing at
 118      * {@code data[(y + dirtyY] * linestride + (x + dirtyX)]} in the pixel buffer
 119      * (see {@link #imageBufferReset}). All indices {@code data[(y + dirtyY + j) * linestride +
 120      * (x + dirtyX + i)]} where {@code (0 <= i < dirtyWidth)} and {@code (0 <= j < dirtyHeight)}
 121      * will represent valid pixel data, {@code (i, j)} in the coordinate space of the dirty rectangle.
 122      * 
 123      * @param dirtyX the x coordinate of the dirty rectangle, relative to the image origin
 124      * @param dirtyY the y coordinate of the dirty rectangle, relative to the image origin
 125      * @param dirtyWidth the width of the dirty rectangle
 126      * @param dirtyHeight the height of the dirty rectangle
 127      * 
 128      * @see #imageBufferReset
 129      * @see #imageReshaped
 130      */
 131     public void imageUpdated(int dirtyX, int dirtyY, int dirtyWidth, int dirtyHeight);
 132     
 133     /**
 134      * {@code JLightweightFrame} calls this method to notify the client application that the frame
 135      * has grabbed focus.
 136      */
 137     public void focusGrabbed();
 138     
 139     /**
 140      * {@code JLightweightFrame} calls this method to notify the client application that the frame
 141      * has ungrabbed focus.
 142      */
 143     public void focusUngrabbed();
 144 }