* maybe finally fixed DnD on Linux ...

This commit is contained in:
Reinhard Pointner 2009-06-30 12:29:02 +00:00
parent ed40d4099e
commit 6766e1bb95
2 changed files with 11 additions and 18 deletions

View File

@ -32,7 +32,7 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
private final List<Object> model; private final List<Object> model;
public NamesListTransferablePolicy(List<Object> model) { public NamesListTransferablePolicy(List<Object> model) {
this.model = model; this.model = model;
} }
@ -78,10 +78,10 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
protected void load(String string) { protected void load(String string) {
List<String> values = new ArrayList<String>(); List<String> values = new ArrayList<String>();
Scanner scanner = new Scanner(string).useDelimiter(LINE_SEPARATOR); Scanner scanner = new Scanner(string);
while (scanner.hasNext()) { while (scanner.hasNextLine()) {
String line = scanner.next(); String line = scanner.nextLine();
if (line.trim().length() > 0) { if (line.trim().length() > 0) {
values.add(line); values.add(line);
@ -116,10 +116,10 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
protected void loadListFiles(List<File> files, List<Object> values) throws FileNotFoundException { protected void loadListFiles(List<File> files, List<Object> values) throws FileNotFoundException {
for (File file : files) { for (File file : files) {
// don't use new Scanner(File) because of BUG 6368019 (http://bugs.sun.com/view_bug.do?bug_id=6368019) // don't use new Scanner(File) because of BUG 6368019 (http://bugs.sun.com/view_bug.do?bug_id=6368019)
Scanner scanner = new Scanner(new FileInputStream(file), "UTF-8").useDelimiter(LINE_SEPARATOR); Scanner scanner = new Scanner(new FileInputStream(file), "UTF-8");
while (scanner.hasNext()) { while (scanner.hasNextLine()) {
String line = scanner.next(); String line = scanner.nextLine();
if (line.trim().length() > 0) { if (line.trim().length() > 0) {
values.add(line); values.add(line);

View File

@ -14,17 +14,10 @@ import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Pattern;
public abstract class FileTransferablePolicy extends TransferablePolicy { public abstract class FileTransferablePolicy extends TransferablePolicy {
/**
* Pattern that will match Windows (\r\n), Unix (\n) and Mac (\r) line separators.
*/
public static final Pattern LINE_SEPARATOR = Pattern.compile("\r\n|[\r\n]");
@Override @Override
public boolean accept(Transferable tr) throws Exception { public boolean accept(Transferable tr) throws Exception {
List<File> files = getFilesFromTransferable(tr); List<File> files = getFilesFromTransferable(tr);
@ -43,14 +36,14 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
return (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); return (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
} else if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) { } else if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) {
// file URI list flavor // file URI list flavor
String transferData = (String) tr.getTransferData(FileTransferable.uriListFlavor); Readable transferData = (Readable) tr.getTransferData(FileTransferable.uriListFlavor);
Scanner scanner = new Scanner(transferData).useDelimiter(LINE_SEPARATOR); Scanner scanner = new Scanner(transferData);
List<File> files = new ArrayList<File>(); List<File> files = new ArrayList<File>();
while (scanner.hasNext()) { while (scanner.hasNextLine()) {
String uri = scanner.next(); String uri = scanner.nextLine();
if (uri.startsWith("#")) { if (uri.startsWith("#")) {
// the line is a comment (as per RFC 2483) // the line is a comment (as per RFC 2483)