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