Path: blob/master/src/java.desktop/share/classes/sun/awt/LightweightFrame.java
41152 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.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@SuppressWarnings("deprecation")91@Override public void addNotify() {92synchronized (getTreeLock()) {93if (!isDisplayable()) {94SunToolkit stk = (SunToolkit)Toolkit.getDefaultToolkit();95try {96setPeer(stk.createLightweightFrame(this));97} catch (Exception e) {98throw new RuntimeException(e);99}100}101super.addNotify();102}103}104105private void setPeer(final FramePeer p) {106AWTAccessor.getComponentAccessor().setPeer(this, p);107}108109/**110* Requests the peer to emulate activation or deactivation of the111* frame. Peers should override this method if they are to implement112* this functionality.113*114* @param activate if {@code true}, activates the frame;115* otherwise, deactivates the frame116*/117public void emulateActivation(boolean activate) {118final FramePeer peer = AWTAccessor.getComponentAccessor().getPeer(this);119peer.emulateActivation(activate);120}121122/**123* Delegates the focus grab action to the client (embedding) application.124* The method is called by the AWT grab machinery.125*126* @see SunToolkit#grab(java.awt.Window)127*/128public abstract void grabFocus();129130/**131* Delegates the focus ungrab action to the client (embedding) application.132* The method is called by the AWT grab machinery.133*134* @see SunToolkit#ungrab(java.awt.Window)135*/136public abstract void ungrabFocus();137138/**139* Returns the scale factor of this frame. The default value is 1.140*141* @return the scale factor142* @see #notifyDisplayChanged(int)143* @Depricated replaced by {@link #getScaleFactorX()} and144* {@link #getScaleFactorY}145*/146@Deprecated(since = "9")147public abstract int getScaleFactor();148149/**150* Returns the scale factor of this frame along x coordinate. The default151* value is 1.152*153* @return the x coordinate scale factor154* @see #notifyDisplayChanged(double, double)155* @since 9156*/157public abstract double getScaleFactorX();158159/**160* Returns the scale factor of this frame along y coordinate. The default161* value is 1.162*163* @return the y coordinate scale factor164* @see #notifyDisplayChanged(double, double)165* @since 9166*/167public abstract double getScaleFactorY();168169/**170* Called when display of the hosted frame is changed.171*172* @param scaleFactor the scale factor173* @Depricated replaced by {@link #notifyDisplayChanged(double, double)}174*/175@Deprecated(since = "9")176public abstract void notifyDisplayChanged(int scaleFactor);177178/**179* Called when display of the hosted frame is changed.180*181* @param scaleFactorX the scale factor182* @param scaleFactorY the scale factor183* @since 9184*/185public abstract void notifyDisplayChanged(double scaleFactorX,186double scaleFactorY);187188/**189* Host window absolute bounds.190*/191private int hostX, hostY, hostW, hostH;192193/**194* Returns the absolute bounds of the host (embedding) window.195*196* @return the host window bounds197*/198public Rectangle getHostBounds() {199if (hostX == 0 && hostY == 0 && hostW == 0 && hostH == 0) {200// The client app is probably unaware of the setHostBounds.201// A safe fall-back:202return getBounds();203}204return new Rectangle(hostX, hostY, hostW, hostH);205}206207/**208* Sets the absolute bounds of the host (embedding) window.209*/210public void setHostBounds(int x, int y, int w, int h) {211hostX = x;212hostY = y;213hostW = w;214hostH = h;215}216217/**218* Create a drag gesture recognizer for the lightweight frame.219*/220public abstract <T extends DragGestureRecognizer> T createDragGestureRecognizer(221Class<T> abstractRecognizerClass,222DragSource ds, Component c, int srcActions,223DragGestureListener dgl);224225/**226* Create a drag source context peer for the lightweight frame.227*/228public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException;229230/**231* Adds a drop target to the lightweight frame.232*/233public abstract void addDropTarget(DropTarget dt);234235/**236* Removes a drop target from the lightweight frame.237*/238public abstract void removeDropTarget(DropTarget dt);239240}241242243