192 text.setFont(text.getFont().deriveFont(Font.PLAIN));
193 text.setForeground(table.getForeground());
194 text.setText(String.valueOf(o));
195 }
196 }
197 }
198
199 // Interview.Observer
200 public void currentQuestionChanged(Question q) {
201 }
202
203 public void pathUpdated() {
204 updateContent();
205 }
206
207 private void updateContent() {
208 setEnv(params.getEnv());
209 }
210 };
211
212 private class EnvEntryComparator implements Comparator {
213 EnvEntryComparator(int sortMode, String[] inherits) {
214 this.sortMode = sortMode;
215 this.inherits = inherits;
216 }
217
218 public int compare(Object o1, Object o2) {
219 TestEnvironment.Element e1 = (TestEnvironment.Element)o1;
220 TestEnvironment.Element e2 = (TestEnvironment.Element)o2;
221 // the following should be a switch statement, but JDK
222 // 1.1.7 can't compile it: doesn't recognize KEY etc as
223 // constants.
224 if (sortMode == KEY)
225 // key should always be unique, so should be enough to sort on that
226 return (e1.getKey().compareTo(e2.getKey()));
227 else if (sortMode == VALUE) {
228 // value probably unique, but if not, sort on key as well
229 int c = (e1.getValue().compareTo(e2.getValue()));
230 return (c != 0 ? c : e1.getKey().compareTo(e2.getKey()));
231 }
232 else if (sortMode == DEFINED_IN_ENV) {
233 // defined_in probably not unique, so sort on key as well
234 int i1 = getInheritsIndex(e1.getDefinedInEnv());
235 int i2 = getInheritsIndex(e2.getDefinedInEnv());
236 return (i1 < i2 ? -1 :
237 i1 > i2 ? +1 : e1.getKey().compareTo(e2.getKey()));
238 }
239 else if (sortMode == DEFINED_IN_FILE) {
240 // defined_in probably not unique, so sort on key as well
259 }
260
261 private class ElementsTableModel extends AbstractTableModel {
262 ElementsTableModel() {
263 if (headings == null) {
264 headings = new String[4];
265 headings[KEY] = uif.getI18NString("env.head.key");
266 headings[VALUE] = uif.getI18NString("env.head.value");
267 headings[DEFINED_IN_FILE] = uif.getI18NString("env.head.defInFile");
268 headings[DEFINED_IN_ENV] = uif.getI18NString("env.head.defInEnv");
269 }
270 }
271
272 public synchronized void setEnvironment(TestEnvironment env) {
273 int oldRowCount = getRowCount();
274 currEnv = env;
275
276 if (currEnv == null)
277 elems = null;
278 else {
279 Collection e = currEnv.elements();
280 elems = (TestEnvironment.Element[]) (e.toArray(new TestEnvironment.Element[e.size()]));
281 Arrays.sort(elems, new EnvEntryComparator(KEY, currEnv.getInherits()));
282 }
283 int newRowCount = getRowCount();
284
285 int commonRowCount = Math.min(oldRowCount, newRowCount);
286
287 if (commonRowCount > 0) {
288 // the rows in common have changed
289 fireTableRowsUpdated(0, commonRowCount - 1);
290 }
291
292 if (newRowCount > oldRowCount) {
293 // the new table is bigger: so rows have been added
294 fireTableRowsInserted(commonRowCount, newRowCount - 1);
295 }
296 else if (newRowCount < oldRowCount) {
297 // the new table is smaller, so rows have been removed
298 fireTableRowsDeleted(commonRowCount, oldRowCount - 1);
299 }
300 }
306 }
307 }
308
309 private void update() {
310 }
311
312 public synchronized int getRowCount() {
313 return (elems == null ? 0 : elems.length);
314 }
315
316 public int getColumnCount() {
317 // might be nice to make this more dynamic ...
318 // have "defined in env" and "defined in file" be dynamic, specified on View menu
319 return 4; // key, value, defined_in_env, defined_in_file
320 }
321
322 public String getColumnName(int columnIndex) {
323 return headings[columnIndex];
324 }
325
326 public Class getColumnClass(int columnIndex) {
327 return String.class;
328 }
329
330 public synchronized Object getValueAt(int rowIndex, int columnIndex) {
331 if (rowIndex < 0 || rowIndex >= getRowCount()
332 || columnIndex < 0 || columnIndex >= getColumnCount())
333 throw new IllegalArgumentException();
334
335 TestEnvironment.Element e = elems[rowIndex];
336 switch (columnIndex) {
337 case KEY:
338 return e.getKey();
339 case DEFINED_IN_ENV:
340 return e.getDefinedInEnv();
341 case DEFINED_IN_FILE:
342 return e.getDefinedInFile();
343 case VALUE:
344 return e.getValue();
345 default:
346 throw new Error();
|
192 text.setFont(text.getFont().deriveFont(Font.PLAIN));
193 text.setForeground(table.getForeground());
194 text.setText(String.valueOf(o));
195 }
196 }
197 }
198
199 // Interview.Observer
200 public void currentQuestionChanged(Question q) {
201 }
202
203 public void pathUpdated() {
204 updateContent();
205 }
206
207 private void updateContent() {
208 setEnv(params.getEnv());
209 }
210 };
211
212 private class EnvEntryComparator implements Comparator<TestEnvironment.Element> {
213 EnvEntryComparator(int sortMode, String[] inherits) {
214 this.sortMode = sortMode;
215 this.inherits = inherits;
216 }
217
218 public int compare(TestEnvironment.Element e1, TestEnvironment.Element e2) {
219 // the following should be a switch statement, but JDK
220 // 1.1.7 can't compile it: doesn't recognize KEY etc as
221 // constants.
222 if (sortMode == KEY)
223 // key should always be unique, so should be enough to sort on that
224 return (e1.getKey().compareTo(e2.getKey()));
225 else if (sortMode == VALUE) {
226 // value probably unique, but if not, sort on key as well
227 int c = (e1.getValue().compareTo(e2.getValue()));
228 return (c != 0 ? c : e1.getKey().compareTo(e2.getKey()));
229 }
230 else if (sortMode == DEFINED_IN_ENV) {
231 // defined_in probably not unique, so sort on key as well
232 int i1 = getInheritsIndex(e1.getDefinedInEnv());
233 int i2 = getInheritsIndex(e2.getDefinedInEnv());
234 return (i1 < i2 ? -1 :
235 i1 > i2 ? +1 : e1.getKey().compareTo(e2.getKey()));
236 }
237 else if (sortMode == DEFINED_IN_FILE) {
238 // defined_in probably not unique, so sort on key as well
257 }
258
259 private class ElementsTableModel extends AbstractTableModel {
260 ElementsTableModel() {
261 if (headings == null) {
262 headings = new String[4];
263 headings[KEY] = uif.getI18NString("env.head.key");
264 headings[VALUE] = uif.getI18NString("env.head.value");
265 headings[DEFINED_IN_FILE] = uif.getI18NString("env.head.defInFile");
266 headings[DEFINED_IN_ENV] = uif.getI18NString("env.head.defInEnv");
267 }
268 }
269
270 public synchronized void setEnvironment(TestEnvironment env) {
271 int oldRowCount = getRowCount();
272 currEnv = env;
273
274 if (currEnv == null)
275 elems = null;
276 else {
277 Collection<TestEnvironment.Element> e = currEnv.elements();
278 elems = e.toArray(new TestEnvironment.Element[e.size()]);
279 Arrays.sort(elems, new EnvEntryComparator(KEY, currEnv.getInherits()));
280 }
281 int newRowCount = getRowCount();
282
283 int commonRowCount = Math.min(oldRowCount, newRowCount);
284
285 if (commonRowCount > 0) {
286 // the rows in common have changed
287 fireTableRowsUpdated(0, commonRowCount - 1);
288 }
289
290 if (newRowCount > oldRowCount) {
291 // the new table is bigger: so rows have been added
292 fireTableRowsInserted(commonRowCount, newRowCount - 1);
293 }
294 else if (newRowCount < oldRowCount) {
295 // the new table is smaller, so rows have been removed
296 fireTableRowsDeleted(commonRowCount, oldRowCount - 1);
297 }
298 }
304 }
305 }
306
307 private void update() {
308 }
309
310 public synchronized int getRowCount() {
311 return (elems == null ? 0 : elems.length);
312 }
313
314 public int getColumnCount() {
315 // might be nice to make this more dynamic ...
316 // have "defined in env" and "defined in file" be dynamic, specified on View menu
317 return 4; // key, value, defined_in_env, defined_in_file
318 }
319
320 public String getColumnName(int columnIndex) {
321 return headings[columnIndex];
322 }
323
324 public Class<?> getColumnClass(int columnIndex) {
325 return String.class;
326 }
327
328 public synchronized Object getValueAt(int rowIndex, int columnIndex) {
329 if (rowIndex < 0 || rowIndex >= getRowCount()
330 || columnIndex < 0 || columnIndex >= getColumnCount())
331 throw new IllegalArgumentException();
332
333 TestEnvironment.Element e = elems[rowIndex];
334 switch (columnIndex) {
335 case KEY:
336 return e.getKey();
337 case DEFINED_IN_ENV:
338 return e.getDefinedInEnv();
339 case DEFINED_IN_FILE:
340 return e.getDefinedInFile();
341 case VALUE:
342 return e.getValue();
343 default:
344 throw new Error();
|