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.awt; 27 28 import java.awt.Container; 29 import java.awt.Frame; 30 import java.awt.Graphics; 31 import java.awt.Image; 32 import java.awt.MenuBar; 33 import java.awt.MenuComponent; 34 import java.awt.Toolkit; 35 import java.awt.peer.FramePeer; 36 37 /** 38 * The class provides basic functionality for a lightweight frame 39 * implementation. A subclass is expected to provide painting to an 40 * offscreen image and access to it. Thus it can be used for lightweight 41 * embedding. 42 * 43 * @author Artem Ananiev 44 * @author Anton Tarasov 45 */ 46 @SuppressWarnings("serial") 47 public abstract class LightweightFrame extends Frame { 48 49 /** 50 * Constructs a new, initially invisible {@code LightweightFrame} 51 * instance. 52 */ 53 public LightweightFrame() { 54 setUndecorated(true); 55 setResizable(true); 56 setEnabled(true); 57 } 58 59 /** 60 * Blocks introspection of a parent window by this child. 61 * 62 * @return null 63 */ 64 @Override public final Container getParent() { return null; } 65 66 @Override public Graphics getGraphics() { return null; } 67 68 @Override public final boolean isResizable() { return true; } 69 70 // Block modification of any frame attributes, since they aren't 71 // applicable for a lightweight frame. 72 73 @Override public final void setTitle(String title) {} 74 @Override public final void setIconImage(Image image) {} 75 @Override public final void setIconImages(java.util.List<? extends Image> icons) {} 76 @Override public final void setMenuBar(MenuBar mb) {} 77 @Override public final void setResizable(boolean resizable) {} 78 @Override public final void remove(MenuComponent m) {} 79 @Override public final void toFront() {} 80 @Override public final void toBack() {} 81 82 @Override public void addNotify() { 83 synchronized (getTreeLock()) { 84 if (getPeer() == null) { 85 SunToolkit stk = (SunToolkit)Toolkit.getDefaultToolkit(); 86 try { 87 setPeer(stk.createLightweightFrame(this)); 88 } catch (Exception e) { 89 throw new RuntimeException(e); 90 } 91 } 92 super.addNotify(); 93 } 94 } 95 96 private void setPeer(final FramePeer p) { 97 AWTAccessor.getComponentAccessor().setPeer(this, p); 98 } 99 100 /** 101 * Requests the peer to emulate activation or deactivation of the 102 * frame. Peers should override this method if they are to implement 103 * this functionality. 104 * 105 * @param activate if <code>true</code>, activates the frame; 106 * otherwise, deactivates the frame 107 */ 108 public void emulateActivation(boolean activate) { 109 ((FramePeer)getPeer()).emulateActivation(activate); 110 } 111 112 /** 113 * Delegates the focus grab action to the client (embedding) application. 114 * The method is called by the AWT grab machinery. 115 * 116 * @see SunToolkit#grab(java.awt.Window) 117 */ 118 public abstract void grabFocus(); 119 120 /** 121 * Delegates the focus ungrab action to the client (embedding) application. 122 * The method is called by the AWT grab machinery. 123 * 124 * @see SunToolkit#ungrab(java.awt.Window) 125 */ 126 public abstract void ungrabFocus(); 127 128 /** 129 * Returns the scale factor set with the {@link #setScaleFactor} method. 130 * The default value is 1. 131 * 132 * @return the scale factor 133 */ 134 public abstract int getScaleFactor(); 135 136 /** 137 * Sets the scale factor which defines the HiDPI resolution 138 * of the offscreen buffer the frame is painted to. 139 * 140 * @param scale the factor 141 */ 142 public abstract void setScaleFactor(int scale); 143 }