*******************************************************************************/
package org.simantics.ui.dnd;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.FlavorTable;
import java.awt.datatransfer.SystemFlavorMap;
-import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.dnd.ByteArrayTransfer;
import org.eclipse.swt.dnd.TransferData;
-import sun.awt.datatransfer.DataTransferer;
-
public class LocalObjectTransfer extends ByteArrayTransfer {
// First attempt to create a UUID for the type name to make sure that
// <code>LocalSelectionTransfer</code>
public static final String TYPE_NAME = SystemFlavorMap.encodeJavaMIMEType(LocalObjectTransferable.TYPE_NAME);
- private static int getMapping() {
-
- for(Map.Entry<DataFlavor, String> entry : SystemFlavorMap.getDefaultFlavorMap().getNativesForFlavors(new DataFlavor[] { LocalObjectTransferable.FLAVOR }).entrySet()) {
- for(long l : DataTransferer.getInstance().getFormatsForFlavorAsArray(entry.getKey(), (FlavorTable)SystemFlavorMap.getDefaultFlavorMap())) {
- return (int)l;
- }
- }
-
- throw new Error("No mapping.");
-
- }
+// private static int getMapping() {
+//
+// for(Map.Entry<DataFlavor, String> entry : SystemFlavorMap.getDefaultFlavorMap().getNativesForFlavors(new DataFlavor[] { LocalObjectTransferable.FLAVOR }).entrySet()) {
+// for(long l : DataTransferer.getInstance().getFormatsForFlavorAsArray(entry.getKey(), (FlavorTable)SystemFlavorMap.getDefaultFlavorMap())) {
+// return (int)l;
+// }
+// }
+// DataFlavor[] flavors = SystemFlavorMap.getDefaultFlavorMap().getNativesForFlavors(new DataFlavor[] { LocalObjectTransferable.FLAVOR }).keySet().toArray(new DataFlavor[0]);
+// for(long l : DataTransferer.getInstance().getFormatsForFlavors(flavors, (FlavorTable)SystemFlavorMap.getDefaultFlavorMap()).keySet()) {
+// return (int)l;
+// }
+//
+// throw new Error("No mapping.");
+//
+// }
// In Linux (Ubuntu 14.04) using SystemFlavorMap to get the type id gives different result than what is received with drop data (TransferData.type)
private static final int TYPEID = registerType(TYPE_NAME);//getMapping();
import org.simantics.utils.ui.internal.awt.CleanResizeListener;
import org.simantics.utils.ui.internal.awt.EmbeddedChildFocusTraversalPolicy;
import org.simantics.utils.ui.internal.awt.SwtFocusHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*/
public abstract class SWTAWTComponent extends Composite {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SWTAWTComponent.class);
+
private static class AwtContext {
private Frame frame;
private Component swingComponent;
private void workaroundJava7FocusProblem(Frame frame) {
String ver = System.getProperty("java.version");
- if (ver.startsWith("1.7") || ver.startsWith("1.8")) {
- try {
- frame.addWindowListener(new Java7FocusFixListener(this, frame));
- } catch (SecurityException e) {
- Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
- } catch (NoSuchMethodException e) {
- Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
+ String[] split = ver.split(".");
+
+ if (split.length < 2) {
+ LOGGER.warn("Focus fix listener: unrecognized Java version: " + ver);
+ return;
+ }
+
+ try {
+ int major = Integer.parseInt(split[0]);
+ int minor = Integer.parseInt(split[1]);
+ if ((major == 1 && (minor == 7 || minor == 8)) || major >= 9) {
+ try {
+ frame.addWindowListener(new Java7FocusFixListener(this, frame));
+ } catch (SecurityException e) {
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
+ } catch (NoSuchMethodException e) {
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
+ }
}
+ } catch (NumberFormatException e) {
+ LOGGER.error("Focus fix listener: unrecognized Java version: " + ver);
}
}
private static JComponent createTable() {
/* Creating components */
int nrows = 1000, ncolumns = 10;
- Vector<Object> rows = new Vector<Object>();
+ Vector<Vector<Object>> rows = new Vector<>();
for (int i = 0; i < nrows; i++) {
- Vector<Object> row = new Vector<Object>();
+ Vector<Object> row = new Vector<>();
for (int j = 0; j < ncolumns; j++) {
row.addElement("Item " + i + "-" + j);
}