コミットメタ情報

リビジョン6457823e4839f3d5b627f02f7ad58428967245a8 (tree)
日時2014-11-27 22:03:25
作者argius <argius.net@gmai...>
コミッターargius

ログメッセージ

[#34645] add a feature which pastes abs-paths via DnD to ConsoleTextArea

変更サマリ

差分

--- a/src/net/argius/stew/ui/window/ConsoleTextArea.java
+++ b/src/net/argius/stew/ui/window/ConsoleTextArea.java
@@ -6,16 +6,16 @@ import static javax.swing.KeyStroke.getKeyStroke;
66 import static net.argius.stew.ui.window.AnyActionKey.breakCommand;
77 import static net.argius.stew.ui.window.AnyActionKey.execute;
88 import static net.argius.stew.ui.window.ConsoleTextArea.ActionKey.*;
9-
9+import java.awt.datatransfer.*;
10+import java.awt.dnd.*;
1011 import java.awt.event.*;
12+import java.io.*;
1113 import java.util.*;
12-
1314 import javax.swing.*;
1415 import javax.swing.text.*;
1516 import javax.swing.text.Highlighter.Highlight;
1617 import javax.swing.text.Highlighter.HighlightPainter;
1718 import javax.swing.undo.*;
18-
1919 import net.argius.stew.*;
2020 import net.argius.stew.text.*;
2121
@@ -50,6 +50,30 @@ final class ConsoleTextArea extends JTextArea implements AnyActionListener, Text
5050 aa.bindSelf(breakCommand, getKeyStroke(VK_B, ALT_DOWN_MASK));
5151 aa.bindSelf(addNewLine, getKeyStroke(VK_ENTER, shortcutKey));
5252 aa.bindSelf(jumpToHomePosition, getKeyStroke(VK_HOME, 0));
53+ // [Events]
54+ class DropTargetAdapterImpl extends DropTargetAdapter {
55+ @Override
56+ public void drop(DropTargetDropEvent dtde) {
57+ Transferable t = dtde.getTransferable();
58+ if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
59+ dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
60+ try {
61+ StringBuilder buffer = new StringBuilder();
62+ @SuppressWarnings("unchecked")
63+ List<File> fileList = (List<File>)t.getTransferData(DataFlavor.javaFileListFlavor);
64+ for (File file : fileList) {
65+ buffer.append(file.getAbsolutePath()).append(" ");
66+ }
67+ append(buffer.toString());
68+ } catch (UnsupportedFlavorException ex) {
69+ throw new RuntimeException(ex);
70+ } catch (IOException ex) {
71+ throw new RuntimeException(ex);
72+ }
73+ }
74+ }
75+ }
76+ setDropTarget(new DropTarget(this, new DropTargetAdapterImpl()));
5377 }
5478
5579 private final class ConsoleTextAreaDocumentFilter extends DocumentFilter {
@@ -252,7 +276,7 @@ final class ConsoleTextArea extends JTextArea implements AnyActionListener, Text
252276 removeHighlights();
253277 }
254278 }
255-
279+
256280 @Override
257281 public void reset() {
258282 removeHighlights();
旧リポジトリブラウザで表示