View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  package org.xnap.gui.component;
20  
21  import javax.swing.text.JTextComponent;
22  
23  import org.apache.log4j.Logger;
24  import org.xnap.i18n.I18n;
25  import org.xnap.util.*;
26  
27  public class CompletionModeFactory 
28  {
29  	//--- Constant(s) ---
30  
31  	public static final String DEFAULT_COMPLETION = I18n.marktr("Default");
32  
33  	public static final String AUTOMATIC_COMPLETION = I18n.marktr("Automatic");
34  
35  	public static final String SHORT_AUTOMATIC_COMPLETION 
36  		= I18n.marktr("Short Automatic");
37  
38  	public static final String AUTOMATIC_DROPDOWN_COMPLETION 
39  		= I18n.marktr("Automatic Dropdown");
40  
41  	public static final String NO_COMPLETION = I18n.marktr("None");
42  	
43  	public static final String MANUAL_COMPLETION 
44  		= I18n.marktr("Manual");
45  	
46  	public static final String EMACS_COMPLETION 
47  		= I18n.marktr("Emacs");
48  	
49  	public static final String DROPDOWN_COMPLETION 
50  		= I18n.marktr("Dropdown List");
51  	
52  	public static final String[] DEFAULT_COMPLETION_MODES = new String[] {
53  		NO_COMPLETION, DROPDOWN_COMPLETION, AUTOMATIC_COMPLETION, 
54  		SHORT_AUTOMATIC_COMPLETION, AUTOMATIC_DROPDOWN_COMPLETION, 
55  		MANUAL_COMPLETION, EMACS_COMPLETION, 
56  	};
57  	
58  	//--- Data field(s) ---
59  
60      private static Logger logger = Logger.getLogger(CompletionModeFactory.class);
61  	
62  	//--- Constructor(s) ---
63  
64      public CompletionModeFactory()
65  	{
66  		
67  	}
68  
69      //--- Method(s) ---
70  
71  	public static CompletionMode createCompletionMode(String key,
72  													  JTextComponent c,
73  													  boolean wholeText)
74  	{
75  		if (key.equals(DEFAULT_COMPLETION)) {
76    			String def = Preferences.getInstance().getDefaultCompletionMode();
77    			// avoid infinite recursion
78    			if (def.equals(DEFAULT_COMPLETION)) {
79    				return new DropDownListCompletionMode(c, wholeText);  				
80    			}
81    			else {
82    				return createCompletionMode(def, c, wholeText);
83    			}
84    		}
85  		else if (key.equals(NO_COMPLETION)) {
86  			return new NoCompletionMode(c, wholeText);
87  		}
88  		else if (key.equals(DROPDOWN_COMPLETION)) {
89  			return new DropDownListCompletionMode(c, wholeText);
90  		}
91  		else if (key.equals(AUTOMATIC_COMPLETION)) {
92  			return new AutomaticCompletionMode(c, wholeText);
93  		}
94  		else if (key.equals(SHORT_AUTOMATIC_COMPLETION)) {
95  			return new ShortAutomaticCompletionMode(c, wholeText);
96  		}
97  		else if (key.equals(AUTOMATIC_DROPDOWN_COMPLETION)) {
98  			return new AutomaticDropDownCompletionMode(c, wholeText);
99  		}
100 		else if (key.equals(MANUAL_COMPLETION)) {
101 			return new ManualCompletionMode(c, wholeText);
102 		}
103 		else if (key.equals(EMACS_COMPLETION)) {
104 			return new EmacsCompletionMode(c, wholeText);
105 		}
106 		else {
107 			// hard coded default
108 			return new DropDownListCompletionMode(c, wholeText);
109 		}
110 	}
111 
112 }