1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.internal.ui.text;
14 import org.eclipse.core.runtime.Preferences;
16 import org.eclipse.jface.preference.IPreferenceStore;
17 import org.eclipse.jface.util.IPropertyChangeListener;
18 import org.eclipse.jface.util.ListenerList;
19 import org.eclipse.jface.util.PropertyChangeEvent;
22 * Adapts {@link org.eclipse.core.runtime.Preferences} to
23 * {@link org.eclipse.jface.preference.IPreferenceStore}
27 public class PreferencesAdapter implements IPreferenceStore {
30 * Property change listener. Listens for events of type
31 * {@link org.eclipse.core.runtime.Preferences.PropertyChangeEvent} and fires
32 * a {@link org.eclipse.jface.util.PropertyChangeEvent} on the
33 * adapter with arguments from the received event.
35 private class PropertyChangeListener implements Preferences.IPropertyChangeListener {
38 * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
40 public void propertyChange(Preferences.PropertyChangeEvent event) {
41 firePropertyChangeEvent(event.getProperty(), event.getOldValue(), event.getNewValue());
45 /** Listeners on the adapter */
46 private ListenerList fListeners= new ListenerList();
48 /** Listener on the adapted Preferences */
49 private PropertyChangeListener fListener= new PropertyChangeListener();
51 /** Adapted Preferences */
52 private Preferences fPreferences;
54 /** True iff no events should be forwarded */
55 private boolean fSilent;
58 * Initialize with empty Preferences.
60 public PreferencesAdapter() {
61 this(new Preferences());
64 * Initialize with the given Preferences.
66 * @param preferences The preferences to wrap.
68 public PreferencesAdapter(Preferences preferences) {
69 fPreferences= preferences;
75 public void addPropertyChangeListener(IPropertyChangeListener listener) {
76 if (fListeners.size() == 0)
77 fPreferences.addPropertyChangeListener(fListener);
78 fListeners.add(listener);
84 public void removePropertyChangeListener(IPropertyChangeListener listener) {
85 fListeners.remove(listener);
86 if (fListeners.size() == 0)
87 fPreferences.removePropertyChangeListener(fListener);
93 public boolean contains(String name) {
94 return fPreferences.contains(name);
100 public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
102 PropertyChangeEvent event= new PropertyChangeEvent(this, name, oldValue, newValue);
103 Object[] listeners= fListeners.getListeners();
104 for (int i= 0; i < listeners.length; i++)
105 ((IPropertyChangeListener) listeners[i]).propertyChange(event);
112 public boolean getBoolean(String name) {
113 return fPreferences.getBoolean(name);
119 public boolean getDefaultBoolean(String name) {
120 return fPreferences.getDefaultBoolean(name);
126 public double getDefaultDouble(String name) {
127 return fPreferences.getDefaultDouble(name);
133 public float getDefaultFloat(String name) {
134 return fPreferences.getDefaultFloat(name);
140 public int getDefaultInt(String name) {
141 return fPreferences.getDefaultInt(name);
147 public long getDefaultLong(String name) {
148 return fPreferences.getDefaultLong(name);
154 public String getDefaultString(String name) {
155 return fPreferences.getDefaultString(name);
161 public double getDouble(String name) {
162 return fPreferences.getDouble(name);
168 public float getFloat(String name) {
169 return fPreferences.getFloat(name);
175 public int getInt(String name) {
176 return fPreferences.getInt(name);
182 public long getLong(String name) {
183 return fPreferences.getLong(name);
189 public String getString(String name) {
190 return fPreferences.getString(name);
196 public boolean isDefault(String name) {
197 return fPreferences.isDefault(name);
203 public boolean needsSaving() {
204 return fPreferences.needsSaving();
210 public void putValue(String name, String value) {
213 fPreferences.setValue(name, value);
222 public void setDefault(String name, double value) {
223 fPreferences.setDefault(name, value);
229 public void setDefault(String name, float value) {
230 fPreferences.setDefault(name, value);
236 public void setDefault(String name, int value) {
237 fPreferences.setDefault(name, value);
243 public void setDefault(String name, long value) {
244 fPreferences.setDefault(name, value);
250 public void setDefault(String name, String defaultObject) {
251 fPreferences.setDefault(name, defaultObject);
257 public void setDefault(String name, boolean value) {
258 fPreferences.setDefault(name, value);
264 public void setToDefault(String name) {
265 fPreferences.setToDefault(name);
271 public void setValue(String name, double value) {
272 fPreferences.setValue(name, value);
278 public void setValue(String name, float value) {
279 fPreferences.setValue(name, value);
285 public void setValue(String name, int value) {
286 fPreferences.setValue(name, value);
292 public void setValue(String name, long value) {
293 fPreferences.setValue(name, value);
299 public void setValue(String name, String value) {
300 fPreferences.setValue(name, value);
306 public void setValue(String name, boolean value) {
307 fPreferences.setValue(name, value);