Path: blob/master/src/java.desktop/share/classes/sun/swing/LightweightContent.java
41153 views
/*1* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.swing;2627import javax.swing.JComponent;28import java.awt.Component;29import java.awt.Cursor;30import java.awt.dnd.DragGestureEvent;31import java.awt.dnd.DragGestureListener;32import java.awt.dnd.DragGestureRecognizer;33import java.awt.dnd.DragSource;34import java.awt.dnd.DropTarget;35import java.awt.dnd.InvalidDnDOperationException;36import java.awt.dnd.peer.DragSourceContextPeer;3738/**39* The interface by means of which the {@link JLightweightFrame} class40* communicates to its client application.41* <p>42* The client application implements this interface so it can response43* to requests and process notifications from {@code JLightweightFrame}.44* An implementation of this interface is associated with a {@code45* JLightweightFrame} instance via the {@link JLightweightFrame#setContent}46* method.47*48* A hierarchy of components contained in the {@code JComponent} instance49* returned by the {@link #getComponent} method should not contain any50* heavyweight components, otherwise {@code JLightweightFrame} may fail51* to paint it.52*53* @author Artem Ananiev54* @author Anton Tarasov55* @author Jim Graham56*/57public interface LightweightContent {5859/**60* The client application overrides this method to return the {@code61* JComponent} instance which the {@code JLightweightFrame} container62* will paint as its lightweight content. A hierarchy of components63* contained in this component should not contain any heavyweight objects.64*65* @return the component to paint66*/67public JComponent getComponent();6869/**70* {@code JLightweightFrame} calls this method to notify the client71* application that it acquires the paint lock. The client application72* should implement the locking mechanism in order to synchronize access73* to the content image data, shared between {@code JLightweightFrame}74* and the client application.75*76* @see #paintUnlock77*/78public void paintLock();7980/**81* {@code JLightweightFrame} calls this method to notify the client82* application that it releases the paint lock. The client application83* should implement the locking mechanism in order to synchronize access84* to the content image data, shared between {@code JLightweightFrame}85* and the client application.86*87* @see #paintLock88*/89public void paintUnlock();9091/**92* {@code JLightweightFrame} calls this method to notify the client93* application that a new data buffer has been set as a content pixel94* buffer. Typically this occurs when a buffer of a larger size is95* created in response to a content resize event.96* <p>97* The method reports a reference to the pixel data buffer, the content98* image bounds within the buffer and the line stride of the buffer.99* These values have the following correlation.100* The {@code width} and {@code height} matches the layout size of the content101* (the component returned from the {@link #getComponent} method). The102* {@code x} and {@code y} is the origin of the content, {@code (0, 0)}103* in the layout coordinate space of the content, appearing at104* {@code data[y * scale * linestride + x * scale]} in the buffer.105* A pixel with indices {@code (i, j)}, where {@code (0 <= i < width)} and106* {@code (0 <= j < height)}, in the layout coordinate space of the content107* is represented by a {@code scale^2} square of pixels in the physical108* coordinate space of the buffer. The top-left corner of the square has the109* following physical coordinate in the buffer:110* {@code data[(y + j) * scale * linestride + (x + i) * scale]}.111*112* @param data the content pixel data buffer of INT_ARGB_PRE type113* @param x the logical x coordinate of the image114* @param y the logical y coordinate of the image115* @param width the logical width of the image116* @param height the logical height of the image117* @param linestride the line stride of the pixel buffer118* @param scale the scale factor of the pixel buffer119* @Depricated replaced by120* {@link #imageBufferReset(int[],int,int,int,int,int,double,double)}121*/122@Deprecated(since = "9")123default public void imageBufferReset(int[] data,124int x, int y,125int width, int height,126int linestride,127int scale)128{129imageBufferReset(data, x, y, width, height, linestride);130}131132/**133* {@code JLightweightFrame} calls this method to notify the client134* application that a new data buffer has been set as a content pixel135* buffer. Typically this occurs when a buffer of a larger size is136* created in response to a content resize event.137* <p>138* The method reports a reference to the pixel data buffer, the content139* image bounds within the buffer and the line stride of the buffer.140* These values have the following correlation.141* The {@code width} and {@code height} matches the layout size of the142* content (the component returned from the {@link #getComponent} method).143* The {@code x} and {@code y} is the origin of the content, {@code (0, 0)}144* in the layout coordinate space of the content, appearing at145* {@code data[y * scaleY * linestride + x * scaleX]} in the buffer.146* A pixel with indices {@code (i, j)}, where {@code (0 <= i < width)} and147* {@code (0 <= j < height)}, in the layout coordinate space of the content148* is represented by a {@code scaleX * scaleY} square of pixels in the149* physical coordinate space of the buffer. The top-left corner of the150* square has the following physical coordinate in the buffer:151* {@code data[(y + j) * scaleY * linestride + (x + i) * scaleX]}.152*153* @param data the content pixel data buffer of INT_ARGB_PRE type154* @param x the logical x coordinate of the image155* @param y the logical y coordinate of the image156* @param width the logical width of the image157* @param height the logical height of the image158* @param linestride the line stride of the pixel buffer159* @param scaleX the x coordinate scale factor of the pixel buffer160* @param scaleY the y coordinate scale factor of the pixel buffer161* @since 9162*/163@SuppressWarnings("deprecation")164default public void imageBufferReset(int[] data,165int x, int y,166int width, int height,167int linestride,168double scaleX, double scaleY)169{170imageBufferReset(data, x, y, width, height, linestride,171(int)Math.round(scaleX));172}173174/**175* The default implementation for #imageBufferReset uses a hard-coded value176* of 1 for the scale factor. Both the old and the new methods provide177* default implementations in order to allow a client application to run178* with any JDK version without breaking backward compatibility.179*/180@SuppressWarnings("deprecation")181default public void imageBufferReset(int[] data,182int x, int y,183int width, int height,184int linestride)185{186imageBufferReset(data, x, y, width, height, linestride, 1);187}188189/**190* {@code JLightweightFrame} calls this method to notify the client191* application that the content image bounds have been changed within the192* image's pixel buffer.193*194* @param x the x coordinate of the image195* @param y the y coordinate of the image196* @param width the width of the image197* @param height the height of the image198*199* @see #imageBufferReset200*/201public void imageReshaped(int x, int y, int width, int height);202203/**204* {@code JLightweightFrame} calls this method to notify the client205* application that a part of the content image, or the whole image has206* been updated. The method reports bounds of the rectangular dirty region.207* The {@code dirtyX} and {@code dirtyY} is the origin of the dirty208* rectangle, which is relative to the origin of the content, appearing209* at {@code data[(y + dirtyY] * linestride + (x + dirtyX)]} in the pixel210* buffer (see {@link #imageBufferReset}). All indices211* {@code data[(y + dirtyY + j) * linestride + (x + dirtyX + i)]} where212* {@code (0 <= i < dirtyWidth)} and {@code (0 <= j < dirtyHeight)}213* will represent valid pixel data, {@code (i, j)} in the coordinate space214* of the dirty rectangle.215*216* @param dirtyX the x coordinate of the dirty rectangle,217* relative to the image origin218* @param dirtyY the y coordinate of the dirty rectangle,219* relative to the image origin220* @param dirtyWidth the width of the dirty rectangle221* @param dirtyHeight the height of the dirty rectangle222*223* @see #imageBufferReset224* @see #imageReshaped225*/226public void imageUpdated(int dirtyX, int dirtyY,227int dirtyWidth, int dirtyHeight);228229/**230* {@code JLightweightFrame} calls this method to notify the client231* application that the frame has grabbed focus.232*/233public void focusGrabbed();234235/**236* {@code JLightweightFrame} calls this method to notify the client237* application that the frame has ungrabbed focus.238*/239public void focusUngrabbed();240241/**242* {@code JLightweightFrame} calls this method to notify the client243* application that the content preferred size has changed.244*/245public void preferredSizeChanged(int width, int height);246247/**248* {@code JLightweightFrame} calls this method to notify the client249* application that the content maximum size has changed.250*/251public void maximumSizeChanged(int width, int height);252253/**254* {@code JLightweightFrame} calls this method to notify the client255* application that the content minimum size has changed.256*/257public void minimumSizeChanged(int width, int height);258259/**260* {@code JLightweightFrame} calls this method to notify the client261* application that in needs to set a cursor262* @param cursor a cursor to set263*/264default public void setCursor(Cursor cursor) { }265266/**267* Create a drag gesture recognizer for the lightweight frame.268*/269default public <T extends DragGestureRecognizer> T createDragGestureRecognizer(270Class<T> abstractRecognizerClass,271DragSource ds, Component c, int srcActions,272DragGestureListener dgl)273{274return null;275}276277/**278* Create a drag source context peer for the lightweight frame.279*/280default public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException281{282return null;283}284285/**286* Adds a drop target to the lightweight frame.287*/288default public void addDropTarget(DropTarget dt) {}289290/**291* Removes a drop target from the lightweight frame.292*/293default public void removeDropTarget(DropTarget dt) {}294}295296297