8042219: [macosx] LWComponentPeer should not reference classes from sun.lwawt.macosx
Reviewed-by: serb, azvegint
--- a/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java Wed May 07 19:40:30 2014 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java Wed May 07 19:47:26 2014 +0400
@@ -63,8 +63,6 @@
import javax.swing.SwingUtilities;
import javax.swing.RepaintManager;
-import sun.lwawt.macosx.CDropTarget;
-
import com.sun.java.swing.SwingUtilities3;
public abstract class LWComponentPeer<T extends Component, D extends JComponent>
@@ -137,7 +135,7 @@
private final Object dropTargetLock = new Object();
private int fNumDropTargets = 0;
- private CDropTarget fDropTarget = null;
+ private PlatformDropTarget fDropTarget = null;
private final PlatformComponent platformComponent;
@@ -1063,11 +1061,11 @@
// if it's the first (or last) one for the component. Otherwise this call is a no-op.
if (++fNumDropTargets == 1) {
// Having a non-null drop target would be an error but let's check just in case:
- if (fDropTarget != null)
- System.err.println("CComponent.addDropTarget(): current drop target is non-null.");
-
+ if (fDropTarget != null) {
+ throw new IllegalStateException("Current drop target is not null");
+ }
// Create a new drop target:
- fDropTarget = CDropTarget.createDropTarget(dt, target, this);
+ fDropTarget = LWToolkit.getLWToolkit().createDropTarget(dt, target, this);
}
}
}
--- a/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java Wed May 07 19:40:30 2014 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWToolkit.java Wed May 07 19:47:26 2014 +0400
@@ -28,6 +28,7 @@
import java.awt.*;
import java.awt.List;
import java.awt.datatransfer.*;
+import java.awt.dnd.DropTarget;
import java.awt.image.*;
import java.awt.peer.*;
import java.security.*;
@@ -440,6 +441,10 @@
protected abstract FileDialogPeer createFileDialogPeer(FileDialog target);
+ protected abstract PlatformDropTarget createDropTarget(DropTarget dropTarget,
+ Component component,
+ LWComponentPeer<?, ?> peer);
+
// ---- UTILITY METHODS ---- //
/*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/macosx/classes/sun/lwawt/PlatformDropTarget.java Wed May 07 19:47:26 2014 +0400
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.lwawt;
+
+public interface PlatformDropTarget {
+
+ /**
+ * Release native dragging destination, if any
+ */
+ void dispose();
+}
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CDropTarget.java Wed May 07 19:40:30 2014 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CDropTarget.java Wed May 07 19:47:26 2014 +0400
@@ -25,54 +25,37 @@
package sun.lwawt.macosx;
-import java.awt.Component;
-import java.awt.peer.ComponentPeer;
+import sun.lwawt.LWComponentPeer;
+import sun.lwawt.PlatformDropTarget;
+
+import java.awt.*;
import java.awt.dnd.DropTarget;
-import sun.lwawt.LWComponentPeer;
-import sun.lwawt.PlatformWindow;
-
-public final class CDropTarget {
-
- Component fComponent;
- ComponentPeer fPeer;
- DropTarget fDropTarget;
- private long fNativeDropTarget;
+final class CDropTarget implements PlatformDropTarget {
+ private long fNativeDropTarget;
- public static CDropTarget createDropTarget(DropTarget dropTarget, Component component, ComponentPeer peer) {
- return new CDropTarget(dropTarget, component, peer);
- }
-
- private CDropTarget(DropTarget dropTarget, Component component, ComponentPeer peer) {
- super();
-
- fDropTarget = dropTarget;
- fComponent = component;
- fPeer = peer;
-
- long nativePeer = CPlatformWindow.getNativeViewPtr(((LWComponentPeer) peer).getPlatformWindow());
+ CDropTarget(DropTarget dropTarget, Component component, LWComponentPeer<?, ?> peer) {
+ long nativePeer = CPlatformWindow.getNativeViewPtr(peer.getPlatformWindow());
if (nativePeer == 0L) return; // Unsupported for a window without a native view (plugin)
// Create native dragging destination:
- fNativeDropTarget = this.createNativeDropTarget(dropTarget, component, peer, nativePeer);
+ fNativeDropTarget = createNativeDropTarget(dropTarget, component, nativePeer);
if (fNativeDropTarget == 0) {
throw new IllegalStateException("CDropTarget.createNativeDropTarget() failed.");
}
}
- public DropTarget getDropTarget() {
- return fDropTarget;
- }
-
+ @Override
public void dispose() {
- // Release native dragging destination, if any:
if (fNativeDropTarget != 0) {
- this.releaseNativeDropTarget(fNativeDropTarget);
+ releaseNativeDropTarget(fNativeDropTarget);
fNativeDropTarget = 0;
}
}
- protected native long createNativeDropTarget(DropTarget dropTarget, Component component, ComponentPeer peer, long nativePeer);
+ protected native long createNativeDropTarget(DropTarget dropTarget,
+ Component component,
+ long nativePeer);
protected native void releaseNativeDropTarget(long nativeDropTarget);
}
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Wed May 07 19:40:30 2014 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Wed May 07 19:47:26 2014 +0400
@@ -701,7 +701,14 @@
return (T)dgr;
}
-// InputMethodSupport Method
+ @Override
+ protected PlatformDropTarget createDropTarget(DropTarget dropTarget,
+ Component component,
+ LWComponentPeer<?, ?> peer) {
+ return new CDropTarget(dropTarget, component, peer);
+ }
+
+ // InputMethodSupport Method
/**
* Returns the default keyboard locale of the underlying operating system
*/
--- a/jdk/src/macosx/native/sun/awt/CDropTarget.h Wed May 07 19:40:30 2014 +0400
+++ b/jdk/src/macosx/native/sun/awt/CDropTarget.h Wed May 07 19:47:26 2014 +0400
@@ -48,7 +48,7 @@
+ (CDropTarget *) currentDropTarget;
// Common methods:
-- (id)init:(jobject)dropTarget component:(jobject)jcomponent peer:(jobject)jpeer control:(id)control;
+- (id)init:(jobject)dropTarget component:(jobject)jcomponent control:(id)control;
- (void)controlModelControlValid;
- (void)removeFromView:(JNIEnv *)env;
--- a/jdk/src/macosx/native/sun/awt/CDropTarget.m Wed May 07 19:40:30 2014 +0400
+++ b/jdk/src/macosx/native/sun/awt/CDropTarget.m Wed May 07 19:47:26 2014 +0400
@@ -65,7 +65,7 @@
return sCurrentDropTarget;
}
-- (id)init:(jobject)jdropTarget component:(jobject)jcomponent peer:(jobject)jpeer control:(id)control
+- (id)init:(jobject)jdropTarget component:(jobject)jcomponent control:(id)control
{
self = [super init];
DLog2(@"[CDropTarget init]: %@\n", self);
@@ -714,13 +714,13 @@
* Signature: (Ljava/awt/dnd/DropTarget;Ljava/awt/Component;Ljava/awt/peer/ComponentPeer;J)J
*/
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CDropTarget_createNativeDropTarget
- (JNIEnv *env, jobject jthis, jobject jdroptarget, jobject jcomponent, jobject jpeer, jlong jnativepeer)
+ (JNIEnv *env, jobject jthis, jobject jdroptarget, jobject jcomponent, jlong jnativepeer)
{
CDropTarget* dropTarget = nil;
JNF_COCOA_ENTER(env);
id controlObj = (id) jlong_to_ptr(jnativepeer);
- dropTarget = [[CDropTarget alloc] init:jdroptarget component:jcomponent peer:jpeer control:controlObj];
+ dropTarget = [[CDropTarget alloc] init:jdroptarget component:jcomponent control:controlObj];
JNF_COCOA_EXIT(env);
return ptr_to_jlong(dropTarget);