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 import java.awt.Cursor;
  30 
  31 /**
  32  * The interface by means of which the {@link JLightweightFrame} class
  33  * communicates to its client application.
  34  * <p>
  35  * The client application implements this interface so it can response
  36  * to requests and process notifications from {@code JLightweightFrame}.
  37  * An implementation of this interface is associated with a {@code
  38  * JLightweightFrame} instance via the {@link JLightweightFrame#setContent}
  39  * method.
  40  *
  41  * A hierarchy of components contained in the {@code JComponent} instance
  42  * returned by the {@link #getComponent} method should not contain any
  43  * heavyweight components, otherwise {@code JLightweightFrame} may fail
  44  * to paint it.
  45  *
  46  * @author Artem Ananiev
  47  * @author Anton Tarasov
  48  * @author Jim Graham
  49  */
  50 public interface LightweightContent {
  51 
  52     /**
  53      * The client application overrides this method to return the {@code
  54      * JComponent} instance which the {@code JLightweightFrame} container
  55      * will paint as its lightweight content. A hierarchy of components
  56      * contained in this component should not contain any heavyweight objects.
  57      *
  58      * @return the component to paint
  59      */
  60     public JComponent getComponent();
  61 
  62     /**
  63      * {@code JLightweightFrame} calls this method to notify the client
  64      * application that it acquires the paint lock. The client application
  65      * should implement the locking mechanism in order to synchronize access
  66      * to the content image data, shared between {@code JLightweightFrame}
  67      * and the client application.
  68      *
  69      * @see #paintUnlock
  70      */
  71     public void paintLock();
  72 
  73     /**
  74      * {@code JLightweightFrame} calls this method to notify the client
  75      * application that it releases the paint lock. The client application
  76      * should implement the locking mechanism in order to synchronize access
  77      * to the content image data, shared between {@code JLightweightFrame}
  78      * and the client application.
  79      *
  80      * @see #paintLock
  81      */
  82     public void paintUnlock();
  83 
  84     /**
  85      * {@code JLightweightFrame} calls this method to notify the client
  86      * application that a new data buffer has been set as a content pixel
  87      * buffer. Typically this occurs when a buffer of a larger size is
  88      * created in response to a content resize event. The method reports
  89      * a reference to the pixel data buffer, the content image bounds
  90      * within the buffer and the line stride of the buffer. These values
  91      * have the following correlation.
  92      * <p>
  93      * The {@code width} and {@code height} matches the size of the content
  94      * (the component returned from the {@link #getComponent} method). The
  95      * {@code x} and {@code y} is the origin of the content, {@code (0, 0)}
  96      * in the coordinate space of the content, appearing at
  97      * {@code data[y * linestride + x]} in the buffer. All indices
  98      * {@code data[(y + j) * linestride + (x + i)]} where
  99      * {@code (0 <= i < width)} and {@code (0 <= j < height)} will represent
 100      * valid pixel data, {@code (i, j)} in the coordinate space of the content.
 101      *
 102      * @param data the content pixel data buffer of INT_ARGB_PRE type
 103      * @param x the x coordinate of the image
 104      * @param y the y coordinate of the image
 105      * @param width the width of the image
 106      * @param height the height of the image
 107      * @param linestride the line stride of the pixel buffer
 108      * @param scale the scale factor of the pixel buffer
 109      */
 110     default public void imageBufferReset(int[] data,
 111                                  int x, int y,
 112                                  int width, int height,
 113                                  int linestride,
 114                                  int scale)
 115     {
 116         imageBufferReset(data, x, y, width, height, linestride);
 117     }
 118 
 119     /**
 120      * The default implementation for #imageBufferReset uses a hard-coded value
 121      * of 1 for the scale factor. Both the old and the new methods provide
 122      * default implementations in order to allow a client application to run
 123      * with any JDK version without breaking backward compatibility.
 124      */
 125     default public void imageBufferReset(int[] data,
 126                                  int x, int y,
 127                                  int width, int height,
 128                                  int linestride)
 129     {
 130         imageBufferReset(data, x, y, width, height, linestride, 1);
 131     }
 132 
 133     /**
 134      * {@code JLightweightFrame} calls this method to notify the client
 135      * application that the content image bounds have been changed within the
 136      * image's pixel buffer.
 137      *
 138      * @param x the x coordinate of the image
 139      * @param y the y coordinate of the image
 140      * @param width the width of the image
 141      * @param height the height of the image
 142      *
 143      * @see #imageBufferReset
 144      */
 145     public void imageReshaped(int x, int y, int width, int height);
 146 
 147     /**
 148      * {@code JLightweightFrame} calls this method to notify the client
 149      * application that a part of the content image, or the whole image has
 150      * been updated. The method reports bounds of the rectangular dirty region.
 151      * The {@code dirtyX} and {@code dirtyY} is the origin of the dirty
 152      * rectangle, which is relative to the origin of the content, appearing
 153      * at {@code data[(y + dirtyY] * linestride + (x + dirtyX)]} in the pixel
 154      * buffer (see {@link #imageBufferReset}). All indices
 155      * {@code data[(y + dirtyY + j) * linestride + (x + dirtyX + i)]} where
 156      * {@code (0 <= i < dirtyWidth)} and {@code (0 <= j < dirtyHeight)}
 157      * will represent valid pixel data, {@code (i, j)} in the coordinate space
 158      * of the dirty rectangle.
 159      *
 160      * @param dirtyX the x coordinate of the dirty rectangle,
 161      *        relative to the image origin
 162      * @param dirtyY the y coordinate of the dirty rectangle,
 163      *        relative to the image origin
 164      * @param dirtyWidth the width of the dirty rectangle
 165      * @param dirtyHeight the height of the dirty rectangle
 166      *
 167      * @see #imageBufferReset
 168      * @see #imageReshaped
 169      */
 170     public void imageUpdated(int dirtyX, int dirtyY,
 171                              int dirtyWidth, int dirtyHeight);
 172 
 173     /**
 174      * {@code JLightweightFrame} calls this method to notify the client
 175      * application that the frame has grabbed focus.
 176      */
 177     public void focusGrabbed();
 178 
 179     /**
 180      * {@code JLightweightFrame} calls this method to notify the client
 181      * application that the frame has ungrabbed focus.
 182      */
 183     public void focusUngrabbed();
 184 
 185     /**
 186      * {@code JLightweightFrame} calls this method to notify the client
 187      * application that the content preferred size has changed.
 188      */
 189     public void preferredSizeChanged(int width, int height);
 190 
 191     /**
 192      * {@code JLightweightFrame} calls this method to notify the client
 193      * application that the content maximum size has changed.
 194      */
 195     public void maximumSizeChanged(int width, int height);
 196 
 197     /**
 198      * {@code JLightweightFrame} calls this method to notify the client
 199      * application that the content minimum size has changed.
 200      */
 201     public void minimumSizeChanged(int width, int height);
 202 
 203     /**
 204      * {@code JLightweightFrame} calls this method to notify the client
 205      * application that in needs to set a cursor
 206      * @param cursor a cursor to set
 207      */
 208     default public void setCursor(Cursor cursor) { }
 209 }