1
1
/*
2
- * Copyright (c) 2008, 2024 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2008, 2025 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
37
37
import com .sun .hotspot .igv .settings .Settings ;
38
38
import com .sun .hotspot .igv .util .LookupHistory ;
39
39
import com .sun .hotspot .igv .view .EditorTopComponent ;
40
+ import com .sun .hotspot .igv .view .PlaceholderTopComponent ;
40
41
import java .awt .BorderLayout ;
41
42
import java .awt .Dimension ;
43
+ import java .awt .HeadlessException ;
44
+ import java .awt .datatransfer .DataFlavor ;
45
+ import java .awt .datatransfer .UnsupportedFlavorException ;
46
+ import java .awt .dnd .DnDConstants ;
47
+ import java .awt .dnd .DropTarget ;
48
+ import java .awt .dnd .DropTargetDragEvent ;
49
+ import java .awt .dnd .DropTargetDropEvent ;
50
+ import java .awt .dnd .DropTargetEvent ;
51
+ import java .awt .dnd .DropTargetListener ;
42
52
import java .io .*;
43
53
import java .nio .channels .FileChannel ;
44
54
import java .nio .file .*;
@@ -92,6 +102,9 @@ public final class OutlineTopComponent extends TopComponent implements ExplorerM
92
102
private GraphNode [] selectedGraphs = new GraphNode [0 ];
93
103
private Path documentPath = null ;
94
104
105
+ private final DropTargetListener fileDropListener = new FileDropListener ();
106
+ private final PlaceholderTopComponent editorPlaceholder = new PlaceholderTopComponent (fileDropListener );
107
+
95
108
private OutlineTopComponent () {
96
109
initComponents ();
97
110
@@ -100,6 +113,17 @@ private OutlineTopComponent() {
100
113
initListView ();
101
114
initToolbar ();
102
115
server .startServer ();
116
+
117
+ showEditorPlaceholder ();
118
+
119
+ WindowManager .getDefault ().invokeWhenUIReady (() -> {
120
+ new DropTarget (WindowManager .getDefault ().getMainWindow (), fileDropListener );
121
+ });
122
+ }
123
+
124
+ private void showEditorPlaceholder () {
125
+ editorPlaceholder .open ();
126
+ editorPlaceholder .requestActive ();
103
127
}
104
128
105
129
public static GraphDocument getDocument () {
@@ -236,6 +260,11 @@ private void documentChanged() {
236
260
saveAction .setEnabled (enableButton );
237
261
saveAsAction .setEnabled (enableButton );
238
262
removeAllAction .setEnabled (enableButton );
263
+ if (document .getElements ().isEmpty ()) {
264
+ showEditorPlaceholder ();
265
+ } else {
266
+ editorPlaceholder .close ();
267
+ }
239
268
}
240
269
241
270
@ Override
@@ -372,15 +401,20 @@ public void openFile() {
372
401
JFileChooser fc = new JFileChooser (Settings .get ().get (Settings .DIRECTORY , Settings .DIRECTORY_DEFAULT ));
373
402
fc .setFileFilter (graphFileFilter );
374
403
if (fc .showOpenDialog (null ) == JFileChooser .APPROVE_OPTION ) {
375
- clearWorkspace ();
376
- String path = fc .getSelectedFile ().getAbsolutePath ();
377
- Settings .get ().put (Settings .DIRECTORY , path );
378
- setDocumentPath (path );
379
- try {
380
- loadGraphDocument (path , true );
381
- } catch (IOException e ) {
382
- throw new RuntimeException (e );
383
- }
404
+ handleOpen (fc .getSelectedFile ());
405
+ }
406
+ }
407
+
408
+ private void handleOpen (File file ) {
409
+ clearWorkspace ();
410
+ editorPlaceholder .close ();
411
+ String path = file .getAbsolutePath ();
412
+ Settings .get ().put (Settings .DIRECTORY , path );
413
+ setDocumentPath (path );
414
+ try {
415
+ loadGraphDocument (path , true );
416
+ } catch (IOException e ) {
417
+ throw new RuntimeException (e );
384
418
}
385
419
}
386
420
@@ -590,6 +624,65 @@ public void setState(String state) {
590
624
handle .finish ();
591
625
}
592
626
627
+ private class FileDropListener implements DropTargetListener {
628
+ @ Override
629
+ public void dragEnter (DropTargetDragEvent dtde ) {
630
+ if (dtde .isDataFlavorSupported (DataFlavor .javaFileListFlavor )) {
631
+ dtde .acceptDrag (DnDConstants .ACTION_COPY );
632
+ } else {
633
+ dtde .rejectDrag ();
634
+ }
635
+ }
636
+
637
+ @ Override
638
+ public void dragOver (DropTargetDragEvent dtde ) {
639
+ dragEnter (dtde );
640
+ }
641
+
642
+ @ Override
643
+ public void dropActionChanged (DropTargetDragEvent dtde ) {}
644
+
645
+ @ Override
646
+ public void dragExit (DropTargetEvent dte ) {}
647
+
648
+ @ Override
649
+ public void drop (DropTargetDropEvent dtde ) {
650
+ try {
651
+ if (dtde .isDataFlavorSupported (DataFlavor .javaFileListFlavor )) {
652
+ dtde .acceptDrop (DnDConstants .ACTION_COPY );
653
+
654
+ List <File > droppedFiles = (List <File >) dtde .getTransferable ()
655
+ .getTransferData (DataFlavor .javaFileListFlavor );
656
+
657
+ if (droppedFiles .isEmpty ()) return ;
658
+ if (droppedFiles .size () > 1 ) {
659
+ JOptionPane .showMessageDialog (null ,
660
+ "Please only drag and drop one file as only one file can be open at a time." ,
661
+ "Multiple Files Dropped" , JOptionPane .WARNING_MESSAGE );
662
+ return ;
663
+ }
664
+
665
+ File file = droppedFiles .get (0 );
666
+
667
+ if (file .getName ().endsWith (".xml" ) || file .getName ().endsWith (".igv" )) {
668
+ handleOpen (file );
669
+ } else {
670
+ JOptionPane .showMessageDialog (null ,
671
+ "Unsupported file type: " + file .getName (),
672
+ "Unsupported File" , JOptionPane .WARNING_MESSAGE );
673
+ }
674
+
675
+ dtde .dropComplete (true );
676
+ } else {
677
+ dtde .rejectDrop ();
678
+ }
679
+ } catch (HeadlessException | UnsupportedFlavorException | IOException ex ) {
680
+ ex .printStackTrace ();
681
+ dtde .dropComplete (false );
682
+ }
683
+ }
684
+ }
685
+
593
686
/** This method is called from within the constructor to
594
687
* initialize the form.
595
688
* WARNING: Do NOT modify this code. The content of this method is
0 commit comments