1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package fr.ifremer.quadrige3.ui.swing.component.date;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 import java.text.DateFormat;
55 import java.util.*;
56 public final class ComponentTextDefaults {
57
58 private static ComponentTextDefaults instance;
59
60
61
62
63
64
65 public static ComponentTextDefaults getInstance() {
66 if (instance == null) {
67 instance = new ComponentTextDefaults();
68 }
69 return instance;
70 }
71
72 public enum Key {
73
74 TODAY("text.today", "general"),
75 MONTH("text.month", "general"),
76 YEAR("text.year", "general"),
77 CLEAR("text.clear", "general"),
78
79
80 JANUARY("text.january", "month", 0),
81 FEBRUARY("text.february", "month", 1),
82 MARCH("text.march", "month", 2),
83 APRIL("text.april", "month", 3),
84 MAY("text.may", "month", 4),
85 JUNE("text.june", "month", 5),
86 JULY("text.july", "month", 6),
87 AUGUST("text.august", "month", 7),
88 SEPTEMBER("text.september", "month", 8),
89 OCTOBER("text.october", "month", 9),
90 NOVEMBER("text.november", "month", 10),
91 DECEMBER("text.december", "month", 11),
92
93
94 SUN("text.sun", "dow", 0),
95 MON("text.mon", "dow", 1),
96 TUE("text.tue", "dow", 2),
97 WED("text.wed", "dow", 3),
98 THU("text.thu", "dow", 4),
99 FRI("text.fri", "dow", 5),
100 SAT("text.sat", "dow", 6);
101
102 private final String property;
103 private final String kind;
104 private Integer index;
105
106 Key(String property, String kind) {
107 this.property = property;
108 this.kind = kind;
109 }
110
111 Key(String property, String kind, Integer index) {
112 this.property = property;
113 this.kind = kind;
114 this.index = index;
115 }
116
117 public String getProperty() {
118 return property;
119 }
120
121 public String getKind() {
122 return kind;
123 }
124
125 public Integer getIndex() {
126 return index;
127 }
128
129 public static Key getMonthKey(int index) {
130 for (Key key : values()) {
131 if ("month".equals(key.getKind()) && index == key.getIndex()) {
132 return key;
133 }
134 }
135 return null;
136 }
137
138 public static Key getDowKey(int index) {
139 for (Key key : values()) {
140 if ("dow".equals(key.getKind()) && index == key.getIndex()) {
141 return key;
142 }
143 }
144 return null;
145 }
146
147 }
148
149 private final Properties texts;
150
151
152
153
154 private ComponentTextDefaults() {
155 texts = toProperties(ResourceBundle.getBundle("org.jdatepicker.i18n.Text", Locale.getDefault()));
156 }
157
158 private Properties toProperties(ResourceBundle resource) {
159 Properties result = new Properties();
160 Enumeration<String> keys = resource.getKeys();
161 while (keys.hasMoreElements()) {
162 String key = keys.nextElement();
163 result.put(key, resource.getString(key));
164 }
165 return result;
166 }
167
168
169
170
171
172
173
174
175
176
177 public String getText(Key key) {
178 String text = texts.getProperty(key.getProperty());
179 if (text == null && "month".equals(key.getKind())) {
180 Calendar c = Calendar.getInstance();
181 c.set(Calendar.MONTH, key.getIndex());
182 AbstractComponentFormat defaults = ComponentFormatDefaults.getInstance();
183 DateFormat monthFormat = defaults.getFormat(AbstractComponentFormat.Key.MONTH_SELECTOR);
184 text = monthFormat.format(c.getTime());
185 }
186 if (text == null && "dow".equals(key.getKind())) {
187 Calendar c = Calendar.getInstance();
188 c.set(Calendar.DAY_OF_WEEK, key.getIndex());
189 AbstractComponentFormat defaults = ComponentFormatDefaults.getInstance();
190 DateFormat dowFormat = defaults.getFormat(AbstractComponentFormat.Key.DOW_HEADER);
191 text = dowFormat.format(c.getTime());
192 }
193 return text;
194 }
195
196
197
198
199
200
201
202 public void setText(Key key, String value) {
203 texts.setProperty(key.getProperty(), value);
204 }
205
206 }