View Javadoc

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   * Copyright 2004 Stephen Cowx
14   * 
15   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
16   * use this file except in compliance with the License. You may obtain a copy of
17   * the License at
18   * 
19   * http://www.apache.org/licenses/LICENSE-2.0
20   * 
21   * Unless required by applicable law or agreed to in writing, software
22   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
23   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
24   * License for the specific language governing permissions and limitations under
25   * the License.
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 }