1 | package org.expeditee.setting;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.LinkedList;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import org.expeditee.gui.FrameIO;
|
---|
9 | import org.expeditee.gui.FrameUtils;
|
---|
10 | import org.expeditee.items.Text;
|
---|
11 |
|
---|
12 | public class DirectoryListSetting extends ListSetting<String> {
|
---|
13 |
|
---|
14 | /*
|
---|
15 | public DirectoryListSetting(String tooltip, String name, List<String> value) {
|
---|
16 | super(tooltip, name, value);
|
---|
17 | }*/
|
---|
18 |
|
---|
19 | public DirectoryListSetting(String tooltip, String name) {
|
---|
20 | super(tooltip, name, new LinkedList<String>());
|
---|
21 | }
|
---|
22 |
|
---|
23 | @Override
|
---|
24 | public boolean setSetting(Text text) {
|
---|
25 | _value.addAll(FrameUtils.getDirs(text));
|
---|
26 | return true;
|
---|
27 | }
|
---|
28 |
|
---|
29 | public List<String> getAbsoluteDirs() {
|
---|
30 | String parent_folder = FrameIO.PARENT_FOLDER;
|
---|
31 | boolean need_file_sep_replace = (!File.separator.equals("/"));
|
---|
32 |
|
---|
33 | List<String> value_absolute_dir = new ArrayList<String>();
|
---|
34 |
|
---|
35 | for (String rel : _value) {
|
---|
36 | if (need_file_sep_replace) {
|
---|
37 | rel = rel.replace("/",File.separator);
|
---|
38 | }
|
---|
39 |
|
---|
40 | String abs = null;
|
---|
41 | File rel_file = new File(rel);
|
---|
42 | if (rel_file.isAbsolute()) {
|
---|
43 | // The directory being stored somehow wasn't relative to expeditee.home
|
---|
44 | // => use it 'as is'
|
---|
45 | abs = rel;
|
---|
46 | }
|
---|
47 | else {
|
---|
48 | abs = parent_folder + rel;
|
---|
49 |
|
---|
50 | }
|
---|
51 | value_absolute_dir.add(abs);
|
---|
52 | }
|
---|
53 |
|
---|
54 | return value_absolute_dir;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void addAbsoluteDir(String absolute_dir) {
|
---|
58 | boolean need_file_sep_replace = (!File.separator.equals("/"));
|
---|
59 |
|
---|
60 | String rel = null;
|
---|
61 | if (absolute_dir.startsWith(FrameIO.PARENT_FOLDER)) {
|
---|
62 | // only remove parent_folder if it matches
|
---|
63 | rel = absolute_dir.substring(FrameIO.PARENT_FOLDER.length());
|
---|
64 | }
|
---|
65 | else {
|
---|
66 | rel = absolute_dir;
|
---|
67 | }
|
---|
68 |
|
---|
69 | if (need_file_sep_replace) {
|
---|
70 | rel = rel.replace(File.separator,"/");
|
---|
71 | }
|
---|
72 |
|
---|
73 | _value.add(rel);
|
---|
74 | }
|
---|
75 | }
|
---|