@@ -50,7 +50,7 @@ public class Flowduino extends Application {
50
50
protected VariablesMenu variablesMenu ;
51
51
52
52
protected Node clipboard ;
53
- protected Node nodeToMove ;
53
+ protected Node toMove ;
54
54
55
55
protected HashMap <Rectangle , Node > targetNodeMap = new HashMap <>();
56
56
protected HashMap <Rectangle , Boolean > targetFirstMap = new HashMap <>();
@@ -336,9 +336,12 @@ public void handle(DragEvent event) {
336
336
IfComponent ifComponent = new IfComponent (nodes , cases );
337
337
newComponent = ifComponent ;
338
338
} else if (db .getString ().equals ("NodeMove" )) {
339
- if (insertNodeReletiveToNode (n , nodeToMove , b )) {
340
- deleteNodeFromTree (nodeToMove );
341
- nodeToMove = null ;
339
+ Node nodeToMove = toMove ;
340
+ if (nodeToMove == null ) {
341
+ nodeToMove = loadNode (db .getFiles ().get (0 ));
342
+ }
343
+ if (nodeToMove != null && insertNodeReletiveToNode (n , nodeToMove , b ) && toMove != null ) {
344
+ deleteNodeFromTree (toMove );
342
345
}
343
346
}
344
347
if (newComponent != null ) {
@@ -601,7 +604,6 @@ public boolean saveFile() {
601
604
out .close ();
602
605
fileOut .close ();
603
606
d .setSavedSinceLastChange (true );
604
-
605
607
} catch (Exception e ) {
606
608
System .out .println ("Save failed" );
607
609
e .printStackTrace ();
@@ -712,13 +714,26 @@ public void handle(MouseEvent mouseEvent) {
712
714
/* put a string on dragboard */
713
715
ClipboardContent content = new ClipboardContent ();
714
716
content .putString ("NodeMove" );
717
+ try {
718
+ File temp = File .createTempFile ("clipboard" , ".tmp" );
719
+ saveNode (temp , n );
720
+ toMove = n ;
721
+ content .putFiles (new ArrayList <File >(){{add (temp );}});
722
+
723
+ } catch (IOException e ) {
724
+ e .printStackTrace ();
725
+ }
715
726
db .setContent (content );
716
727
717
- nodeToMove = n ;
718
-
719
728
mouseEvent .consume ();
720
729
}
721
730
});
731
+ p .setOnDragDone (new EventHandler <DragEvent >() {
732
+ @ Override
733
+ public void handle (DragEvent mouseEvent ) {
734
+ toMove = null ;
735
+ }
736
+ });
722
737
p .getStyleClass ().add (blocktype );
723
738
p .getStyleClass ().add ("block-image" );
724
739
programView .getChildren ().add (p );
@@ -751,4 +766,30 @@ public boolean insertNodeReletiveToNode(Node n, Node newNodeToInsert, boolean be
751
766
return false ;
752
767
}
753
768
}
769
+
770
+ public void saveNode (File f , Node n ) {
771
+ try {
772
+ FileOutputStream fileOut = new FileOutputStream (f .getAbsoluteFile ());
773
+ ObjectOutputStream out = new ObjectOutputStream (fileOut );
774
+ out .writeObject (n );
775
+ out .close ();
776
+ fileOut .close ();
777
+ } catch (Exception e ) {
778
+ e .printStackTrace ();
779
+ }
780
+ }
781
+
782
+ public Node loadNode (File f ) {
783
+ try {
784
+ FileInputStream fileIn = new FileInputStream (f .getAbsoluteFile ());
785
+ ObjectInputStream in = new ObjectInputStream (fileIn );
786
+ Node n = (Node )in .readObject ();
787
+ in .close ();
788
+ fileIn .close ();
789
+ return n ;
790
+ } catch (Exception e ) {
791
+ e .printStackTrace ();
792
+ }
793
+ return null ;
794
+ }
754
795
}
0 commit comments