1 package com.explosion.utilities.preferences.editandrender.form;
2
3 import java.awt.Component;
4 import java.util.Map;
5
6 import javax.swing.JPanel;
7
8 import com.explosion.utilities.preferences.Preference;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 /***
31 * This class provides a basic platform for a component based preference Editor and Renderer
32 * @author Stephen Cowx
33 * @version
34 */
35 public class FormBasedPreferenceRendererAndEditor extends JPanel
36 {
37 private Preference preference;
38
39 public FormBasedPreferenceRendererAndEditor(Preference preference)
40 {
41 this.preference = preference;
42 }
43
44 /***
45 * @return Returns the preference.
46 */
47 public Preference getPreference() {
48 return preference;
49 }
50
51 /***
52 * @param preference The preference to set.
53 */
54 public void setPreference(Preference preference) {
55 this.preference = preference;
56 }
57
58
59 /***
60 * This method returns the correct editor to use for a particular preference type
61 * @param type
62 * @param theOwner
63 * @param preference
64 * @return
65 */
66 public static final FormBasedPreferenceRendererAndEditor getEditorForType(int type, Component theOwner, Preference preference, Map modifiers)
67 {
68 switch (type)
69 {
70 case (Preference.PROPERTY_TYPE_TEXT):
71 return new TextPreferenceEditorAndRenderer(preference);
72 case (Preference.PROPERTY_TYPE_FILE):
73 return new FilePreferenceEditorAndRenderer(preference, theOwner,Preference.PROPERTY_TYPE_FILE, preference.getLongName());
74 case (Preference.PROPERTY_TYPE_DIRECTORY):
75 return new FilePreferenceEditorAndRenderer(preference, theOwner,Preference.PROPERTY_TYPE_DIRECTORY, preference.getLongName());
76 case (Preference.PROPERTY_TYPE_COLOR):
77 return new ColorPreferenceEditorAndRenderer(preference, theOwner);
78 case (Preference.PROPERTY_TYPE_INT):
79 return new TextPreferenceEditorAndRenderer(preference);
80 case (Preference.PROPERTY_TYPE_FLOAT):
81 return new TextPreferenceEditorAndRenderer(preference);
82 case (Preference.PROPERTY_TYPE_STRING_CHOICE):
83 if (modifiers!= null && modifiers.get("DisplayAsDropDownChoice") != null)
84 return new ChoicePreferenceEditorAndRenderer(preference);
85 else
86 return new ListChoicePreferenceEditorAndRenderer(preference);
87 case (Preference.PROPERTY_TYPE_INT_CHOICE):
88 return new ChoicePreferenceEditorAndRenderer(preference);
89 case (Preference.PROPERTY_TYPE_BOOLEAN):
90 return new BooleanPreferenceEditorAndRenderer(preference);
91 case (Preference.PROPERTY_TYPE_FONT):
92 return new FontPreferenceEditorAndRenderer(preference, theOwner);
93 case (Preference.PROPERTY_TYPE_ENCRYPTED):
94 return new PasswordPreferenceEditorAndRenderer(preference);
95 case (Preference.PROPERTY_TYPE_COLLECTION):
96 return new CollectionPreferenceEditorAndRenderer(preference);
97 default:
98 return null;
99 }
100 }
101 }