From: argius Date: Thu, 27 Nov 2014 13:03:25 +0000 (+0900) Subject: [#34645] add a feature which pastes abs-paths via DnD to ConsoleTextArea X-Git-Tag: v4.2.0-beta1~5^2 X-Git-Url: http://git.osdn.net/view?p=stew%2FStew4.git;a=commitdiff_plain;h=6457823e4839f3d5b627f02f7ad58428967245a8 [#34645] add a feature which pastes abs-paths via DnD to ConsoleTextArea --- diff --git a/src/net/argius/stew/ui/window/ConsoleTextArea.java b/src/net/argius/stew/ui/window/ConsoleTextArea.java index 0ac57eb..22899b4 100644 --- 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; import static net.argius.stew.ui.window.AnyActionKey.breakCommand; import static net.argius.stew.ui.window.AnyActionKey.execute; import static net.argius.stew.ui.window.ConsoleTextArea.ActionKey.*; - +import java.awt.datatransfer.*; +import java.awt.dnd.*; import java.awt.event.*; +import java.io.*; import java.util.*; - import javax.swing.*; import javax.swing.text.*; import javax.swing.text.Highlighter.Highlight; import javax.swing.text.Highlighter.HighlightPainter; import javax.swing.undo.*; - import net.argius.stew.*; import net.argius.stew.text.*; @@ -50,6 +50,30 @@ final class ConsoleTextArea extends JTextArea implements AnyActionListener, Text aa.bindSelf(breakCommand, getKeyStroke(VK_B, ALT_DOWN_MASK)); aa.bindSelf(addNewLine, getKeyStroke(VK_ENTER, shortcutKey)); aa.bindSelf(jumpToHomePosition, getKeyStroke(VK_HOME, 0)); + // [Events] + class DropTargetAdapterImpl extends DropTargetAdapter { + @Override + public void drop(DropTargetDropEvent dtde) { + Transferable t = dtde.getTransferable(); + if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { + dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); + try { + StringBuilder buffer = new StringBuilder(); + @SuppressWarnings("unchecked") + List fileList = (List)t.getTransferData(DataFlavor.javaFileListFlavor); + for (File file : fileList) { + buffer.append(file.getAbsolutePath()).append(" "); + } + append(buffer.toString()); + } catch (UnsupportedFlavorException ex) { + throw new RuntimeException(ex); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + } + } + setDropTarget(new DropTarget(this, new DropTargetAdapterImpl())); } private final class ConsoleTextAreaDocumentFilter extends DocumentFilter { @@ -252,7 +276,7 @@ final class ConsoleTextArea extends JTextArea implements AnyActionListener, Text removeHighlights(); } } - + @Override public void reset() { removeHighlights();