Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/awt/LightweightFrame.java
38827 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.awt;2627import java.awt.Component;28import java.awt.Container;29import java.awt.Frame;30import java.awt.Graphics;31import java.awt.Image;32import java.awt.MenuBar;33import java.awt.MenuComponent;34import java.awt.Rectangle;35import java.awt.Toolkit;36import java.awt.dnd.DragGestureEvent;37import java.awt.dnd.DragGestureListener;38import java.awt.dnd.DragGestureRecognizer;39import java.awt.dnd.DragSource;40import java.awt.dnd.DropTarget;41import java.awt.dnd.InvalidDnDOperationException;42import java.awt.dnd.peer.DragSourceContextPeer;43import java.awt.peer.FramePeer;4445/**46* The class provides basic functionality for a lightweight frame47* implementation. A subclass is expected to provide painting to an48* offscreen image and access to it. Thus it can be used for lightweight49* embedding.50*51* @author Artem Ananiev52* @author Anton Tarasov53*/54@SuppressWarnings("serial")55public abstract class LightweightFrame extends Frame {5657/**58* Constructs a new, initially invisible {@code LightweightFrame}59* instance.60*/61public LightweightFrame() {62setUndecorated(true);63setResizable(true);64setEnabled(true);65}6667/**68* Blocks introspection of a parent window by this child.69*70* @return null71*/72@Override public final Container getParent() { return null; }7374@Override public Graphics getGraphics() { return null; }7576@Override public final boolean isResizable() { return true; }7778// Block modification of any frame attributes, since they aren't79// applicable for a lightweight frame.8081@Override public final void setTitle(String title) {}82@Override public final void setIconImage(Image image) {}83@Override public final void setIconImages(java.util.List<? extends Image> icons) {}84@Override public final void setMenuBar(MenuBar mb) {}85@Override public final void setResizable(boolean resizable) {}86@Override public final void remove(MenuComponent m) {}87@Override public final void toFront() {}88@Override public final void toBack() {}8990@Override public void addNotify() {91synchronized (getTreeLock()) {92if (getPeer() == null) {93SunToolkit stk = (SunToolkit)Toolkit.getDefaultToolkit();94try {95setPeer(stk.createLightweightFrame(this));96} catch (Exception e) {97throw new RuntimeException(e);98}99}100super.addNotify();101}102}103104private void setPeer(final FramePeer p) {105AWTAccessor.getComponentAccessor().setPeer(this, p);106}107108/**109* Requests the peer to emulate activation or deactivation of the110* frame. Peers should override this method if they are to implement111* this functionality.112*113* @param activate if <code>true</code>, activates the frame;114* otherwise, deactivates the frame115*/116public void emulateActivation(boolean activate) {117((FramePeer)getPeer()).emulateActivation(activate);118}119120/**121* Delegates the focus grab action to the client (embedding) application.122* The method is called by the AWT grab machinery.123*124* @see SunToolkit#grab(java.awt.Window)125*/126public abstract void grabFocus();127128/**129* Delegates the focus ungrab action to the client (embedding) application.130* The method is called by the AWT grab machinery.131*132* @see SunToolkit#ungrab(java.awt.Window)133*/134public abstract void ungrabFocus();135136/**137* Returns the scale factor of this frame. The default value is 1.138*139* @return the scale factor140* @see #notifyDisplayChanged(int)141*/142public abstract int getScaleFactor();143144/**145* Called when display of the hosted frame is changed.146*147* @param scaleFactor the scale factor148*/149public abstract void notifyDisplayChanged(int scaleFactor);150151/**152* Host window absolute bounds.153*/154private int hostX, hostY, hostW, hostH;155156/**157* Returns the absolute bounds of the host (embedding) window.158*159* @return the host window bounds160*/161public Rectangle getHostBounds() {162if (hostX == 0 && hostY == 0 && hostW == 0 && hostH == 0) {163// The client app is probably unaware of the setHostBounds.164// A safe fall-back:165return getBounds();166}167return new Rectangle(hostX, hostY, hostW, hostH);168}169170/**171* Sets the absolute bounds of the host (embedding) window.172*/173public void setHostBounds(int x, int y, int w, int h) {174hostX = x;175hostY = y;176hostW = w;177hostH = h;178}179180/**181* Create a drag gesture recognizer for the lightweight frame.182*/183public abstract <T extends DragGestureRecognizer> T createDragGestureRecognizer(184Class<T> abstractRecognizerClass,185DragSource ds, Component c, int srcActions,186DragGestureListener dgl);187188/**189* Create a drag source context peer for the lightweight frame.190*/191public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException;192193/**194* Adds a drop target to the lightweight frame.195*/196public abstract void addDropTarget(DropTarget dt);197198/**199* Removes a drop target from the lightweight frame.200*/201public abstract void removeDropTarget(DropTarget dt);202}203204205