Path: blob/master/src/java.desktop/share/classes/sun/awt/NullComponentPeer.java
41152 views
/*1* Copyright (c) 2000, 2020, 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.AWTException;28import java.awt.BufferCapabilities;29import java.awt.Color;30import java.awt.Component;31import java.awt.Cursor;32import java.awt.Dimension;33import java.awt.Event;34import java.awt.Font;35import java.awt.FontMetrics;36import java.awt.Graphics;37import java.awt.GraphicsConfiguration;38import java.awt.Image;39import java.awt.Insets;40import java.awt.Point;41import java.awt.Rectangle;42import java.awt.event.FocusEvent.Cause;43import java.awt.event.PaintEvent;44import java.awt.image.ColorModel;45import java.awt.image.VolatileImage;46import java.awt.peer.CanvasPeer;47import java.awt.peer.ComponentPeer;48import java.awt.peer.ContainerPeer;49import java.awt.peer.LightweightPeer;50import java.awt.peer.PanelPeer;5152import sun.java2d.pipe.Region;5354/**55* Implements the LightweightPeer interface for use in lightweight components56* that have no native window associated with them. This gets created by57* default in Component so that Component and Container can be directly58* extended to create useful components written entirely in java. These59* components must be hosted somewhere higher up in the component tree by a60* native container (such as a Frame).61*62* This implementation provides no useful semantics and serves only as a63* marker. One could provide alternative implementations in java that do64* something useful for some of the other peer interfaces to minimize the65* native code.66*67* This was renamed from java.awt.LightweightPeer (a horrible and confusing68* name) and moved from java.awt.Toolkit into sun.awt as a public class in69* its own file.70*71* @author Timothy Prinzing72* @author Michael Martak73*/74public class NullComponentPeer implements LightweightPeer,75CanvasPeer, PanelPeer {7677public boolean isObscured() {78return false;79}8081public boolean canDetermineObscurity() {82return false;83}8485public boolean isFocusable() {86return false;87}8889public void setVisible(boolean b) {90}9192public void show() {93}9495public void hide() {96}9798public void setEnabled(boolean b) {99}100101public void enable() {102}103104public void disable() {105}106107public void paint(Graphics g) {108}109110public void repaint(long tm, int x, int y, int width, int height) {111}112113public void print(Graphics g) {114}115116public void setBounds(int x, int y, int width, int height, int op) {117}118119public void reshape(int x, int y, int width, int height) {120}121122public void coalescePaintEvent(PaintEvent e) {123}124125@SuppressWarnings("deprecation")126public boolean handleEvent(Event e) {127return false;128}129130public void handleEvent(java.awt.AWTEvent arg0) {131}132133public Dimension getPreferredSize() {134return new Dimension(1,1);135}136137public Dimension getMinimumSize() {138return new Dimension(1,1);139}140141public ColorModel getColorModel() {142return null;143}144145public Graphics getGraphics() {146return null;147}148149public GraphicsConfiguration getGraphicsConfiguration() {150return null;151}152153public FontMetrics getFontMetrics(Font font) {154return null;155}156157public void dispose() {158// no native code159}160161public void setForeground(Color c) {162}163164public void setBackground(Color c) {165}166167public void setFont(Font f) {168}169170public void updateCursorImmediately() {171}172173public void setCursor(Cursor cursor) {174}175176public boolean requestFocus177(Component lightweightChild, boolean temporary,178boolean focusedWindowChangeAllowed, long time, Cause cause) {179return false;180}181182public Image createImage(int width, int height) {183return null;184}185186public Dimension preferredSize() {187return getPreferredSize();188}189190public Dimension minimumSize() {191return getMinimumSize();192}193194public Point getLocationOnScreen() {195return new Point(0,0);196}197198public Insets getInsets() {199return insets();200}201202public void beginValidate() {203}204205public void endValidate() {206}207208public Insets insets() {209return new Insets(0, 0, 0, 0);210}211212public boolean isPaintPending() {213return false;214}215216public boolean handlesWheelScrolling() {217return false;218}219220public VolatileImage createVolatileImage(int width, int height) {221return null;222}223224public void beginLayout() {225}226227public void endLayout() {228}229230public void createBuffers(int numBuffers, BufferCapabilities caps)231throws AWTException {232throw new AWTException(233"Page-flipping is not allowed on a lightweight component");234}235public Image getBackBuffer() {236throw new IllegalStateException(237"Page-flipping is not allowed on a lightweight component");238}239public void flip(int x1, int y1, int x2, int y2,240BufferCapabilities.FlipContents flipAction)241{242throw new IllegalStateException(243"Page-flipping is not allowed on a lightweight component");244}245public void destroyBuffers() {246}247248/**249* @see java.awt.peer.ComponentPeer#isReparentSupported250*/251public boolean isReparentSupported() {252return false;253}254255/**256* @see java.awt.peer.ComponentPeer#reparent257*/258public void reparent(ContainerPeer newNativeParent) {259throw new UnsupportedOperationException();260}261262public void layout() {263}264265public Rectangle getBounds() {266return new Rectangle(0, 0, 0, 0);267}268269270/**271* Applies the shape to the native component window.272* @since 1.7273*/274public void applyShape(Region shape) {275}276277/**278* Lowers this component at the bottom of the above HW peer. If the above parameter279* is null then the method places this component at the top of the Z-order.280*/281public void setZOrder(ComponentPeer above) {282}283284public boolean updateGraphicsData(GraphicsConfiguration gc) {285return false;286}287288public GraphicsConfiguration getAppropriateGraphicsConfiguration(289GraphicsConfiguration gc)290{291return gc;292}293}294295296