Skip to content

Commit 7720ed0

Browse files
committed
DnD fixes for JTabbedPanes
1 parent 019bda3 commit 7720ed0

File tree

5 files changed

+41
-31
lines changed

5 files changed

+41
-31
lines changed

sources/net.sf.j2s.java.core/src/java/awt/Component.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5848,7 +5848,7 @@ public void addNotify() {
58485848
// relocateComponent();
58495849
// }
58505850
// }
5851-
if (秘j2sInvalidateOnAdd )
5851+
if (秘j2sInvalidateOnAdd)
58525852
invalidate();
58535853

58545854
// int npopups = (popups != null? popups.size() : 0);
@@ -5858,8 +5858,10 @@ public void addNotify() {
58585858
// popup.addNotify();
58595859
// }
58605860
//
5861-
// if (dropTarget != null) dropTarget.addNotify(peer);
5862-
//
5861+
5862+
if (dropTarget != null)
5863+
dropTarget.addNotify(peer);
5864+
58635865
peerFont = getFont();
58645866

58655867
// if (getContainer() != null && !isAddNotifyComplete) {

sources/net.sf.j2s.java.core/src/java/awt/Container.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,9 +1134,8 @@ protected void addImplCont(Component comp, Object constraints, int index) {
11341134
adjustDescendants(comp.countHierarchyMembers());
11351135

11361136
invalidateIfValid();
1137-
if (peer != null) {
1137+
if (peer != null)
11381138
comp.addNotify();
1139-
}
11401139

11411140
/* Notify the layout manager of the added component. */
11421141
if (layoutMgr != null) {

sources/net.sf.j2s.java.core/src/javax/swing/JTabbedPane.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,15 +2449,15 @@ public int indexOfTabComponent(Component tabComponent) {
24492449
}
24502450

24512451
/**
2452-
* SwingJS added - needs this??
2453-
*
2452+
* Needed in SwingJS because these really ARE components
24542453
*/
24552454
@Override
24562455
public void addNotify() {
24572456
for(int i = 0; i < getTabCount(); i++) {
24582457
Component c = getTabComponentAt(i);
24592458
if (c != null)
24602459
c.addNotify();
2460+
getComponentAt(i).addNotify();
24612461
}
24622462
}
24632463
}

sources/net.sf.j2s.java.core/src/swingjs/JSDnD.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,18 @@ public static void drop(JComponent jc, Object html5DataTransfer, String name, by
7171
public static void drop(JComponent jc, Object html5DataTransfer, Object[][] data, int x, int y) {
7272
if (html5DataTransfer == null)
7373
return;
74-
JSTransferable t = new JSTransferable(html5DataTransfer);
74+
JSTransferable t = new FileTransferable(data);
7575
DropTarget target = jc.getDropTarget();
76-
System.out.println("JSDnD[] drop for " + jc.getUIClassID() + " target " + target);
77-
Point offset;
76+
System.out.println("JSDnD[] drop for " + jc.getUIClassID() + " target " + target);
7877
if (target != null) {
79-
offset = jc.getLocationOnScreen();
80-
// if (name == null)
81-
target.drop(createDropEvent(target, t, data, x, y));
78+
target.drop(createDropEvent(target, t, data, x, y));
8279
return;
8380
}
84-
Component top = jc.getTopLevelAncestor();
85-
offset = top.getLocationOnScreen();
86-
87-
System.out.println("JSDnD drop for " + jc.getUIClassID() + " offset " + x + " " + y + " -"+ offset);
88-
89-
top.dispatchEvent(new JSDropMouseEvent(jc, MouseEvent.MOUSE_RELEASED, x
90-
//- offset.x
91-
, y
92-
//- offset.y
93-
, t, null, null));
81+
Component top = jc.getTopLevelAncestor();
82+
83+
System.out.println("JSDnD drop for " + jc.getUIClassID() + " offset " + x + " " + y);
84+
85+
top.dispatchEvent(new JSDropMouseEvent(jc, MouseEvent.MOUSE_RELEASED, x, y, t, null, null));
9486
}
9587

9688
@SuppressWarnings("serial")
@@ -109,6 +101,14 @@ public JSDropMouseEvent(Component source, int id, int x, int y, Transferable t,
109101
setBData(data);
110102
}
111103

104+
// public JSDropMouseEvent(Component source, int id, int x, int y, Transferable t, Object[][] data) {
105+
// super(source, id, System.currentTimeMillis(), 0, x, y, 0, false, NOBUTTON);
106+
// System.out.println("new JSDropMouseEvent for " + source);
107+
// this.transferable = t;
108+
// //
109+
// setBData((byte[]) (Object) data);
110+
// }
111+
//
112112
protected void copyPrivateDataInto(AWTEvent that) {
113113

114114
// in case this gets transferred.
@@ -166,7 +166,7 @@ public String paramString() {
166166

167167
static DropTargetDropEvent createDropEvent(DropTarget target, Transferable t, Object[][] data, int x, int y) {
168168
DropTargetContext context = new DropTargetContext(target);
169-
context.addNotify(new JSDropTargetContextPeer(target, t, data));
169+
context.addNotify(new JSDropTargetContextPeer(target, t, null, null));
170170
return new DropTargetDropEvent(context, new Point(x, y), DnDConstants.ACTION_MOVE, DnDConstants.ACTION_LINK | DnDConstants.ACTION_COPY_OR_MOVE);
171171
}
172172

@@ -183,11 +183,6 @@ public JSDropTargetContextPeer (DropTarget target, Transferable t, String name,
183183
transferable = (name == null ? t : new FileTransferable(name, data));
184184
}
185185

186-
public JSDropTargetContextPeer(DropTarget target, Transferable t, Object[][] data) {
187-
this.target = target;
188-
transferable = new FileTransferable(data);
189-
}
190-
191186
private Transferable transferable;
192187
private DropTarget target;
193188

@@ -257,6 +252,20 @@ public static class JSTransferable implements Transferable {
257252
public JSTransferable(Object html5DataTransfer) {
258253
dataTransfer = (HTML5DataTransfer)html5DataTransfer;
259254
mimeTypes = /** @j2sNative html5DataTransfer && html5DataTransfer.types ||*/null;
255+
if (mimeTypes != null) {
256+
if (mimeTypes.length == 0) {
257+
// Chrome ver. 77 does this
258+
mimeTypes = new String[] {"application/x-java-file-list;class=java.util.List"};
259+
260+
} else {
261+
String[] t = new String[mimeTypes.length];
262+
// check for valid mimeType syntax; make a normal String
263+
for (int i = 0; i < mimeTypes.length; i++)
264+
t[i] = (mimeTypes[i].equals("Files") ? "application/x-java-file-list;class=java.util.List"
265+
: mimeTypes[i]);
266+
mimeTypes = t;
267+
}
268+
}
260269
}
261270

262271
@Override

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSListUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,9 +842,9 @@ protected void installListeners() {
842842
// list.setTransferHandler(defaultTransferHandler);
843843
// // default TransferHandler doesn't support drop
844844
// // so we don't want drop handling
845-
// if (list.getDropTarget() instanceof UIResource) {
845+
if (list.getDropTarget() instanceof UIResource) {
846846
list.setDropTarget(null);
847-
// }
847+
}
848848
// }
849849

850850
focusListener = createFocusListener();

0 commit comments

Comments
 (0)