~ubuntu-branches/ubuntu/natty/jabref/natty

« back to all changes in this revision

Viewing changes to src/java/net/sf/jabref/external/TransferableFileLinkSelection.java

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2010-04-27 16:49:34 UTC
  • mfrom: (2.1.8 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100427164934-ozu2dvinslmo3444
Tags: 2.6+ds-2
debian/control: add "Recommends: xdg-utils"; thanks to Vincent Fourmond
for the bug report (closes: #579346). Change xpdf to xpdf-reader in
Suggests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package net.sf.jabref.external;
 
2
 
 
3
import net.sf.jabref.BibtexEntry;
 
4
import net.sf.jabref.GUIGlobals;
 
5
import net.sf.jabref.Util;
 
6
import net.sf.jabref.BasePanel;
 
7
import net.sf.jabref.gui.FileListTableModel;
 
8
 
 
9
import java.awt.datatransfer.StringSelection;
 
10
import java.awt.datatransfer.Transferable;
 
11
import java.awt.datatransfer.DataFlavor;
 
12
import java.awt.datatransfer.UnsupportedFlavorException;
 
13
import java.io.File;
 
14
import java.io.IOException;
 
15
import java.net.MalformedURLException;
 
16
import java.util.List;
 
17
import java.util.ArrayList;
 
18
 
 
19
/**
 
20
 * 
 
21
 */
 
22
public class TransferableFileLinkSelection implements Transferable {
 
23
 
 
24
    List<File> fileList = new ArrayList<File>();
 
25
 
 
26
    public TransferableFileLinkSelection(BasePanel panel, BibtexEntry[] selection) {
 
27
        String s = selection[0].getField(GUIGlobals.FILE_FIELD);
 
28
        FileListTableModel tm = new FileListTableModel();
 
29
        if (s != null)
 
30
            tm.setContent(s);
 
31
        if (tm.getRowCount() > 0) {
 
32
            // Find the default directory for this field type, if any:
 
33
            String dir = panel.metaData().getFileDirectory(GUIGlobals.FILE_FIELD);
 
34
            // Include the standard "file" directory:
 
35
            String fileDir = panel.metaData().getFileDirectory(GUIGlobals.FILE_FIELD);
 
36
            // Include the directory of the bib file:
 
37
            String[] dirs;
 
38
            if (panel.metaData().getFile() != null) {
 
39
                String databaseDir = panel.metaData().getFile().getParent();
 
40
                dirs = new String[] { dir, fileDir, databaseDir };
 
41
            }
 
42
            else
 
43
                dirs = new String[] { dir, fileDir };
 
44
            File expLink = Util.expandFilename(tm.getEntry(0).getLink(), dirs);
 
45
            fileList.add(expLink);
 
46
 
 
47
        }
 
48
 
 
49
    }
 
50
 
 
51
    public DataFlavor[] getTransferDataFlavors() {
 
52
        return new DataFlavor[] {DataFlavor.javaFileListFlavor};//, DataFlavor.stringFlavor};
 
53
    }
 
54
 
 
55
    public boolean isDataFlavorSupported(DataFlavor dataFlavor) {
 
56
        System.out.println("Query: "+dataFlavor.getHumanPresentableName()+" , "+
 
57
            dataFlavor.getDefaultRepresentationClass()+" , "+dataFlavor.getMimeType());
 
58
        return dataFlavor.equals(DataFlavor.javaFileListFlavor)
 
59
                || dataFlavor.equals(DataFlavor.stringFlavor);
 
60
    }
 
61
 
 
62
    public Object getTransferData(DataFlavor dataFlavor) throws UnsupportedFlavorException, IOException {
 
63
        //if (dataFlavor.equals(DataFlavor.javaFileListFlavor))
 
64
            return fileList;
 
65
        //else
 
66
        //    return "test";
 
67
    }
 
68
    /*
 
69
    private StringSelection ss;
 
70
 
 
71
    public TransferableFileLinkSelection(BasePanel panel, BibtexEntry[] selection) {
 
72
        String s = selection[0].getField(GUIGlobals.FILE_FIELD);
 
73
        FileListTableModel tm = new FileListTableModel();
 
74
        if (s != null)
 
75
            tm.setContent(s);
 
76
        if (tm.getRowCount() > 0) {
 
77
            // Find the default directory for this field type, if any:
 
78
            String dir = panel.metaData().getFileDirectory(GUIGlobals.FILE_FIELD);
 
79
            // Include the standard "file" directory:
 
80
            String fileDir = panel.metaData().getFileDirectory(GUIGlobals.FILE_FIELD);
 
81
            // Include the directory of the bib file:
 
82
            String[] dirs;
 
83
            if (panel.metaData().getFile() != null) {
 
84
                String databaseDir = panel.metaData().getFile().getParent();
 
85
                dirs = new String[] { dir, fileDir, databaseDir };
 
86
            }
 
87
            else
 
88
                dirs = new String[] { dir, fileDir };
 
89
            System.out.println(tm.getEntry(0).getLink());
 
90
            for (int i = 0; i < dirs.length; i++) {
 
91
                String dir1 = dirs[i];
 
92
                System.out.println("dir:"+dir1);
 
93
            }
 
94
            File expLink = Util.expandFilename(tm.getEntry(0).getLink(), dirs);
 
95
            try { 
 
96
                System.out.println(expLink.toURI().toURL().toString());
 
97
                ss = new StringSelection(expLink.toURI().toURL().toString());
 
98
                
 
99
            } catch (MalformedURLException ex) {
 
100
                ss = new StringSelection("");
 
101
            }
 
102
        }
 
103
        else
 
104
            ss = new StringSelection("");
 
105
 
 
106
    }
 
107
 
 
108
    public Transferable getTransferable() {
 
109
        return ss;
 
110
    } */
 
111
}