]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/participant/SVGTransfer.java
Option to copy diagram selection to clipboard as SVG graphics
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / participant / SVGTransfer.java
diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/SVGTransfer.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/SVGTransfer.java
new file mode 100644 (file)
index 0000000..539e22e
--- /dev/null
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.diagram.participant;
+
+import java.nio.charset.StandardCharsets;
+
+import org.eclipse.swt.dnd.ByteArrayTransfer;
+
+public class SVGTransfer extends ByteArrayTransfer {
+    private static SVGTransfer instance = new SVGTransfer();
+    private static final String TYPE_NAME = "image/svg+xml";
+    private static final int TYPE_ID = registerType(TYPE_NAME);
+
+    public static byte[] formatContent(String svg) {
+        return svg.getBytes(StandardCharsets.UTF_8);
+    }
+
+    public static SVGTransfer getInstance () {
+        return instance;
+    }
+
+    @Override
+    protected int[] getTypeIds(){
+        return new int[] {TYPE_ID};
+    }
+
+    @Override
+    protected String[] getTypeNames(){
+        return new String[] {TYPE_NAME};
+    }
+}
\ No newline at end of file