1 /* 2 * Copyright (c) 1996, 2007, 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 package sun.awt.windows; 26 27 abstract class WObjectPeer { 28 29 static { 30 initIDs(); 31 } 32 33 long pData; // The Windows handle for the native widget. 34 Object target; // The associated AWT object. 35 36 private volatile boolean disposed; 37 38 // set from JNI if any errors in creating the peer occur 39 protected Error createError = null; 40 41 public static WObjectPeer getPeerForTarget(Object t) { 42 WObjectPeer peer = (WObjectPeer) WToolkit.targetToPeer(t); 43 return peer; 44 } 45 46 public long getData() { 47 return pData; 48 } 49 50 public Object getTarget() { 51 return target; 52 } 53 54 /* 55 * Subclasses should override disposeImpl() instead of dispose(). Client 56 * code should always invoke dispose(), never disposeImpl(). 57 */ 58 abstract protected void disposeImpl(); 59 public final void dispose() { 60 boolean call_disposeImpl = false; 61 62 synchronized (this) { 63 if (!disposed) { 64 disposed = call_disposeImpl = true; 65 } 66 } 67 68 if (call_disposeImpl) { 69 disposeImpl(); 70 } 71 } 72 protected final boolean isDisposed() { 73 return disposed; 74 } 75 76 /** 77 * Initialize JNI field and method IDs 78 */ 79 private static native void initIDs(); 80 }