1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.aequo.util.prefs;
14
15 import org.abstracthorizon.aequo.util.Preferences;
16
17
18
19
20
21
22 public class RecentFileEntry {
23
24
25 public static final int MAX_RECENT = 10;
26
27
28 public String left;
29
30
31 public String right;
32
33
34 public String filters;
35
36
37
38
39 public RecentFileEntry() {
40 }
41
42
43
44
45
46
47
48 public RecentFileEntry(String left, String right, String filters) {
49 this.left = left;
50 this.right = right;
51 this.filters = filters;
52 }
53
54
55
56
57
58
59
60 public static RecentFileEntry read(Preferences prefs, int no) {
61 RecentFileEntry entry = new RecentFileEntry();
62 entry.left = prefs.getProperty("recent." + no + ".left");
63 entry.right = prefs.getProperty("recent." + no + ".right");
64 entry.filters = prefs.getProperty("recent." + no + ".filters");
65 return entry;
66 }
67
68
69
70
71
72
73
74 public static void write(Preferences prefs, RecentFileEntry entry, int no) {
75 prefs.setProperty("recent." + no + ".left", entry.left);
76 prefs.setProperty("recent." + no + ".right", entry.right);
77 prefs.setProperty("recent." + no + ".filters", entry.filters);
78 }
79
80
81
82
83
84
85
86 public static int find(Preferences prefs, RecentFileEntry entry) {
87 for (int i = 1; i <= MAX_RECENT; i++) {
88 String l = prefs.getProperty("recent." + (i - 1) + ".left");
89 String r = prefs.getProperty("recent." + (i - 1) + ".right");
90 if ((entry.left.equals(l) && entry.right.equals(r))) {
91 return (i - 1);
92 }
93 }
94 return -1;
95 }
96
97
98
99
100
101
102
103 public static boolean writeNew(Preferences prefs, RecentFileEntry entry) {
104 for (int i = 1; i <= MAX_RECENT; i++) {
105 String l = prefs.getProperty("recent." + i + ".left");
106 String r = prefs.getProperty("recent." + i + ".right");
107 if ((entry.left.equals(l) && entry.right.equals(r))) {
108 String f = entry.filters;
109 String oldF = prefs.getProperty("recent." + i + ".filters");
110 if (f == oldF) {
111 return false;
112 } else {
113 if ((f != null) && !f.equals(oldF)) {
114 prefs.setProperty("recent." + i + ".filters", f);
115 return true;
116 } else {
117 prefs.setProperty("recent." + i + ".filters", "");
118 return true;
119 }
120 }
121 }
122 }
123
124 for (int i = MAX_RECENT; i > 1; i--) {
125 String l = prefs.getProperty("recent." + (i - 1) + ".left");
126 String r = prefs.getProperty("recent." + (i - 1) + ".right");
127 String f = prefs.getProperty("recent." + (i - 1) + ".filters");
128 if ((l != null) && (r != null)) {
129 prefs.setProperty("recent." + i + ".left", l);
130 prefs.setProperty("recent." + i + ".right", r);
131 if (f != null) {
132 prefs.setProperty("recent." + i + ".filters", f);
133 } else {
134 prefs.remove("recent." + i + ".filters");
135 }
136 }
137 }
138 prefs.setProperty("recent.1.left", entry.left);
139 prefs.setProperty("recent.1.right", entry.right);
140 prefs.setProperty("recent.1.filters", entry.filters);
141 return true;
142 }
143
144 public static int getNumberOfRecent(Preferences prefs) {
145 for (int i = MAX_RECENT; i > 0; i--) {
146 String l = prefs.getProperty("recent." + i + ".left");
147 String r = prefs.getProperty("recent." + i + ".right");
148 if ((l != null) && (r != null)) {
149 return i;
150 }
151 }
152 return 0;
153 }
154 }