Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/swing/LightweightContent.java
38829 views
/*1* Copyright (c) 2013, 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*/120default public void imageBufferReset(int[] data,121int x, int y,122int width, int height,123int linestride,124int scale)125{126imageBufferReset(data, x, y, width, height, linestride);127}128129/**130* The default implementation for #imageBufferReset uses a hard-coded value131* of 1 for the scale factor. Both the old and the new methods provide132* default implementations in order to allow a client application to run133* with any JDK version without breaking backward compatibility.134*/135default public void imageBufferReset(int[] data,136int x, int y,137int width, int height,138int linestride)139{140imageBufferReset(data, x, y, width, height, linestride, 1);141}142143/**144* {@code JLightweightFrame} calls this method to notify the client145* application that the content image bounds have been changed within the146* image's pixel buffer.147*148* @param x the x coordinate of the image149* @param y the y coordinate of the image150* @param width the width of the image151* @param height the height of the image152*153* @see #imageBufferReset154*/155public void imageReshaped(int x, int y, int width, int height);156157/**158* {@code JLightweightFrame} calls this method to notify the client159* application that a part of the content image, or the whole image has160* been updated. The method reports bounds of the rectangular dirty region.161* The {@code dirtyX} and {@code dirtyY} is the origin of the dirty162* rectangle, which is relative to the origin of the content, appearing163* at {@code data[(y + dirtyY] * linestride + (x + dirtyX)]} in the pixel164* buffer (see {@link #imageBufferReset}). All indices165* {@code data[(y + dirtyY + j) * linestride + (x + dirtyX + i)]} where166* {@code (0 <= i < dirtyWidth)} and {@code (0 <= j < dirtyHeight)}167* will represent valid pixel data, {@code (i, j)} in the coordinate space168* of the dirty rectangle.169*170* @param dirtyX the x coordinate of the dirty rectangle,171* relative to the image origin172* @param dirtyY the y coordinate of the dirty rectangle,173* relative to the image origin174* @param dirtyWidth the width of the dirty rectangle175* @param dirtyHeight the height of the dirty rectangle176*177* @see #imageBufferReset178* @see #imageReshaped179*/180public void imageUpdated(int dirtyX, int dirtyY,181int dirtyWidth, int dirtyHeight);182183/**184* {@code JLightweightFrame} calls this method to notify the client185* application that the frame has grabbed focus.186*/187public void focusGrabbed();188189/**190* {@code JLightweightFrame} calls this method to notify the client191* application that the frame has ungrabbed focus.192*/193public void focusUngrabbed();194195/**196* {@code JLightweightFrame} calls this method to notify the client197* application that the content preferred size has changed.198*/199public void preferredSizeChanged(int width, int height);200201/**202* {@code JLightweightFrame} calls this method to notify the client203* application that the content maximum size has changed.204*/205public void maximumSizeChanged(int width, int height);206207/**208* {@code JLightweightFrame} calls this method to notify the client209* application that the content minimum size has changed.210*/211public void minimumSizeChanged(int width, int height);212213/**214* {@code JLightweightFrame} calls this method to notify the client215* application that in needs to set a cursor216* @param cursor a cursor to set217*/218default public void setCursor(Cursor cursor) { }219220/**221* Create a drag gesture recognizer for the lightweight frame.222*/223default public <T extends DragGestureRecognizer> T createDragGestureRecognizer(224Class<T> abstractRecognizerClass,225DragSource ds, Component c, int srcActions,226DragGestureListener dgl)227{228return null;229}230231/**232* Create a drag source context peer for the lightweight frame.233*/234default public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException235{236return null;237}238239/**240* Adds a drop target to the lightweight frame.241*/242default public void addDropTarget(DropTarget dt) {}243244/**245* Removes a drop target from the lightweight frame.246*/247default public void removeDropTarget(DropTarget dt) {}248}249250251