View Javadoc

1   /*
2    *  XNap Commons
3    *
4    *  Copyright (C) 2005  Felix Berger
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or (at your option) any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package org.xnap.commons.settings;
21  
22  import java.beans.PropertyChangeEvent;
23  import java.beans.PropertyChangeListener;
24  import org.xnap.commons.gui.completion.GlobalDefaultCompletionMode;
25  
26  
27  /***
28   * A setting that store the default completion mode. When the setting changes
29   * the {@link GlobalDefaultCompletionMode} is updated accordingly.
30   * 
31   * <p>This class should only be instaciated once.
32   * 
33   * <p><b>Note:</b> When a {@link org.xnap.commons.settings.SettingResource} is 
34   * loaded a {@link java.beans.PropertyChangeEvent} is not triggered, therefore
35   * {@link #updateMode()} needs to be invoked once after the settings have been
36   * loaded.
37   * 
38   * @author Steffen Pingel
39   */
40  public class DefaultCompletionModeSetting extends StringSetting 
41  {
42  
43  	/***
44  	 * Creates a CompletionModeSetting for all instances of 
45  	 * {@link GlobalDefaultCompletionMode}.
46  	 * @param key the settings key for the properties file 
47  	 * @param className the mode which is initially set for the completion
48  	 * object
49  	 * 
50  	 * @throws NullPointerException if <code>className</code> is null
51  	 */
52  	public DefaultCompletionModeSetting(SettingResource backend, String key, 
53  			String className)
54  		
55  	{
56  		super(backend, key, className);
57  
58  		if (className == null) {
59  			throw new NullPointerException("className must not be null");
60  		}
61  		
62  		updateMode();
63  		
64  		addPropertyChangeListener(new PropertyChangeListener() {
65  			public void propertyChange(PropertyChangeEvent event)
66  			{
67  				updateMode();
68  			}			
69  		});
70  	}
71  
72  	/***
73  	 * Updates the global default completion mode.
74  	 * 
75  	 * @see GlobalDefaultCompletionMode#setCompletionMode(String)
76  	 */
77  	public void updateMode()
78  	{
79  		GlobalDefaultCompletionMode.setCompletionMode(getValue());
80  	}
81  	
82  }