1 package com.explosion.utilities.preferences.editandrender.table;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.awt.Component;
24 import java.io.File;
25
26 import javax.swing.JTable;
27 import javax.swing.table.DefaultTableCellRenderer;
28 import javax.swing.table.TableCellRenderer;
29
30 import com.explosion.utilities.GeneralConstants;
31 import com.explosion.utilities.preferences.Preference;
32
33 public class FilePreferenceRenderer extends DefaultTableCellRenderer
34 implements
35 TableCellRenderer {
36
37 public FilePreferenceRenderer() {
38 super();
39
40 }
41
42 public Component getTableCellRendererComponent(JTable table,
43 Object preference, boolean isSelected, boolean hasFocus, int row,
44 int column) {
45
46 Object renderableValue = null;
47 if (preference instanceof Preference) {
48 Preference pref = (Preference) preference;
49 if (renderableValue == null && pref.getDefaultValue() != null)
50 renderableValue = pref.getDefaultValue();
51 } else
52 renderableValue = preference;
53
54 if (renderableValue == null)
55 setText("");
56 else {
57 if (((File) renderableValue).getName().indexOf(
58 GeneralConstants.DEFAULT_FILE) >= 0) {
59 setText("Click here to select file/directory...");
60 } else {
61 setText(renderableValue.toString());
62 }
63 }
64
65 return this;
66 }
67 }