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 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
package org.argouml.ui; |
40 | |
|
41 | |
import java.awt.BorderLayout; |
42 | |
import java.util.ArrayList; |
43 | |
import java.util.Collection; |
44 | |
|
45 | |
import javax.swing.BorderFactory; |
46 | |
import javax.swing.DefaultComboBoxModel; |
47 | |
import javax.swing.JComboBox; |
48 | |
import javax.swing.JLabel; |
49 | |
import javax.swing.JPanel; |
50 | |
import javax.swing.JTextField; |
51 | |
|
52 | |
import org.argouml.application.api.Argo; |
53 | |
import org.argouml.application.api.GUISettingsTabInterface; |
54 | |
import org.argouml.configuration.Configuration; |
55 | |
import org.argouml.i18n.Translator; |
56 | |
import org.argouml.uml.ui.SaveGraphicsManager; |
57 | |
import org.argouml.util.SuffixFilter; |
58 | |
import org.tigris.swidgets.LabelledLayout; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
class SettingsTabEnvironment extends JPanel |
67 | |
implements GUISettingsTabInterface { |
68 | |
|
69 | |
private JPanel topPanel; |
70 | |
private JTextField fieldArgoExtDir; |
71 | |
private JTextField fieldJavaHome; |
72 | |
private JTextField fieldUserHome; |
73 | |
private JTextField fieldUserDir; |
74 | |
private JTextField fieldStartupDir; |
75 | |
private JComboBox fieldGraphicsFormat; |
76 | |
private JComboBox fieldGraphicsResolution; |
77 | |
private Collection<GResolution> theResolutions; |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
SettingsTabEnvironment() { |
83 | 900 | super(); |
84 | 900 | } |
85 | |
|
86 | |
private void buildPanel() { |
87 | 19 | setLayout(new BorderLayout()); |
88 | 19 | int labelGap = 10; |
89 | 19 | int componentGap = 5; |
90 | 19 | topPanel = new JPanel(new LabelledLayout(labelGap, componentGap)); |
91 | |
|
92 | 19 | JLabel label = |
93 | |
new JLabel(Translator.localize("label.default.graphics-format")); |
94 | 19 | fieldGraphicsFormat = new JComboBox(); |
95 | 19 | label.setLabelFor(fieldGraphicsFormat); |
96 | 19 | topPanel.add(label); |
97 | 19 | topPanel.add(fieldGraphicsFormat); |
98 | |
|
99 | 19 | label = |
100 | |
new JLabel( |
101 | |
Translator.localize("label.default.graphics-resolution")); |
102 | 19 | theResolutions = new ArrayList<GResolution>(); |
103 | 19 | theResolutions.add(new GResolution(1, "combobox.item.resolution-1")); |
104 | 19 | theResolutions.add(new GResolution(2, "combobox.item.resolution-2")); |
105 | 19 | theResolutions.add(new GResolution(4, "combobox.item.resolution-4")); |
106 | 19 | fieldGraphicsResolution = new JComboBox(); |
107 | 19 | label.setLabelFor(fieldGraphicsResolution); |
108 | 19 | topPanel.add(label); |
109 | 19 | topPanel.add(fieldGraphicsResolution); |
110 | |
|
111 | |
|
112 | 19 | label = new JLabel("${argo.ext.dir}"); |
113 | 19 | JTextField j2 = new JTextField(); |
114 | 19 | fieldArgoExtDir = j2; |
115 | 19 | fieldArgoExtDir.setEnabled(false); |
116 | 19 | label.setLabelFor(fieldArgoExtDir); |
117 | 19 | topPanel.add(label); |
118 | 19 | topPanel.add(fieldArgoExtDir); |
119 | |
|
120 | |
|
121 | 19 | label = new JLabel("${java.home}"); |
122 | 19 | JTextField j3 = new JTextField(); |
123 | 19 | fieldJavaHome = j3; |
124 | 19 | fieldJavaHome.setEnabled(false); |
125 | 19 | label.setLabelFor(fieldJavaHome); |
126 | 19 | topPanel.add(label); |
127 | 19 | topPanel.add(fieldJavaHome); |
128 | |
|
129 | |
|
130 | 19 | label = new JLabel("${user.home}"); |
131 | 19 | JTextField j4 = new JTextField(); |
132 | 19 | fieldUserHome = j4; |
133 | 19 | fieldUserHome.setEnabled(false); |
134 | 19 | label.setLabelFor(fieldUserHome); |
135 | 19 | topPanel.add(label); |
136 | 19 | topPanel.add(fieldUserHome); |
137 | |
|
138 | |
|
139 | 19 | label = new JLabel("${user.dir}"); |
140 | 19 | JTextField j5 = new JTextField(); |
141 | 19 | fieldUserDir = j5; |
142 | 19 | fieldUserDir.setEnabled(false); |
143 | 19 | label.setLabelFor(fieldUserDir); |
144 | 19 | topPanel.add(label); |
145 | 19 | topPanel.add(fieldUserDir); |
146 | |
|
147 | 19 | label = new JLabel(Translator.localize("label.startup-directory")); |
148 | 19 | JTextField j6 = new JTextField(); |
149 | 19 | fieldStartupDir = j6; |
150 | 19 | fieldStartupDir.setEnabled(false); |
151 | 19 | label.setLabelFor(fieldStartupDir); |
152 | 19 | topPanel.add(label); |
153 | 19 | topPanel.add(fieldStartupDir); |
154 | |
|
155 | 19 | topPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
156 | 19 | add(topPanel, BorderLayout.NORTH); |
157 | |
|
158 | 19 | JPanel bottom = new JPanel(); |
159 | 19 | bottom.add(new JLabel( |
160 | |
Translator.localize("label.graphics-export-resolution.warning"))); |
161 | 19 | add(bottom, BorderLayout.SOUTH); |
162 | 19 | } |
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
public void handleSettingsTabRefresh() { |
168 | 19 | fieldArgoExtDir.setText(System.getProperty("argo.ext.dir")); |
169 | 19 | fieldJavaHome.setText(System.getProperty("java.home")); |
170 | 19 | fieldUserHome.setText(System.getProperty("user.home")); |
171 | 19 | fieldUserDir.setText(Configuration.getString(Argo.KEY_STARTUP_DIR, |
172 | |
System.getProperty("user.dir"))); |
173 | 19 | fieldStartupDir.setText(Argo.getDirectory()); |
174 | |
|
175 | 19 | fieldGraphicsFormat.removeAllItems(); |
176 | 19 | Collection c = SaveGraphicsManager.getInstance().getSettingsList(); |
177 | 19 | fieldGraphicsFormat.setModel(new DefaultComboBoxModel(c.toArray())); |
178 | |
|
179 | 19 | fieldGraphicsResolution.removeAllItems(); |
180 | 19 | fieldGraphicsResolution.setModel(new DefaultComboBoxModel( |
181 | |
theResolutions.toArray())); |
182 | 19 | int defaultResolution = |
183 | |
Configuration.getInteger( |
184 | |
SaveGraphicsManager.KEY_GRAPHICS_RESOLUTION, 1); |
185 | 19 | for (GResolution gr : theResolutions) { |
186 | 19 | if (defaultResolution == gr.getResolution()) { |
187 | 19 | fieldGraphicsResolution.setSelectedItem(gr); |
188 | 19 | break; |
189 | |
} |
190 | |
} |
191 | 19 | } |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
public void handleSettingsTabSave() { |
197 | 0 | Configuration.setString(Argo.KEY_STARTUP_DIR, fieldUserDir.getText()); |
198 | |
|
199 | 0 | GResolution r = (GResolution) fieldGraphicsResolution.getSelectedItem(); |
200 | 0 | Configuration.setInteger(SaveGraphicsManager.KEY_GRAPHICS_RESOLUTION, |
201 | |
r.getResolution()); |
202 | |
|
203 | 0 | SaveGraphicsManager.getInstance().setDefaultFilter( |
204 | |
(SuffixFilter) fieldGraphicsFormat.getSelectedItem()); |
205 | 0 | } |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
public void handleSettingsTabCancel() { |
211 | 0 | handleSettingsTabRefresh(); |
212 | 0 | } |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
public void handleResetToDefault() { |
218 | |
|
219 | 0 | } |
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
public String getTabKey() { |
225 | 19 | return "tab.environment"; |
226 | |
} |
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
public JPanel getTabPanel() { |
232 | 19 | if (topPanel == null) { |
233 | 19 | buildPanel(); |
234 | |
} |
235 | 19 | return this; |
236 | |
} |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
private static final long serialVersionUID = 543442930918741133L; |
242 | |
} |
243 | |
|
244 | |
|
245 | |
class GResolution { |
246 | |
private int resolution; |
247 | |
private String label; |
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | 57 | GResolution(int r, String name) { |
256 | 57 | resolution = r; |
257 | 57 | label = Translator.localize(name); |
258 | 57 | } |
259 | |
|
260 | |
int getResolution() { |
261 | 19 | return resolution; |
262 | |
} |
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
public String toString() { |
268 | 57 | return label; |
269 | |
} |
270 | |
} |
271 | |
|