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;
15 import org.eclipse.jface.preference.IPreferenceStore;
16 import org.eclipse.jface.util.IPropertyChangeListener;
17 import org.eclipse.jface.util.ListenerList;
18 import org.eclipse.jface.util.PropertyChangeEvent;
21 * Adapts {@link org.eclipse.core.runtime.Preferences} to
22 * {@link org.eclipse.jface.preference.IPreferenceStore}
26 public class PreferencesAdapter implements IPreferenceStore {
29 * Property change listener. Listens for events of type
30 * {@link org.eclipse.core.runtime.Preferences.PropertyChangeEvent} and
31 * fires a {@link org.eclipse.jface.util.PropertyChangeEvent} on the adapter
32 * with arguments from the received event.
34 private class PropertyChangeListener implements
35 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(),
46 /** Listeners on the adapter */
47 private ListenerList fListeners = new ListenerList();
49 /** Listener on the adapted Preferences */
50 private PropertyChangeListener fListener = new PropertyChangeListener();
52 /** Adapted Preferences */
53 private Preferences fPreferences;
55 /** True iff no events should be forwarded */
56 private boolean fSilent;
59 * Initialize with empty Preferences.
61 public PreferencesAdapter() {
62 this(new Preferences());
66 * Initialize with the given Preferences.
69 * The preferences to wrap.
71 public PreferencesAdapter(Preferences preferences) {
72 fPreferences = preferences;
78 public void addPropertyChangeListener(IPropertyChangeListener listener) {
79 if (fListeners.size() == 0)
80 fPreferences.addPropertyChangeListener(fListener);
81 fListeners.add(listener);
87 public void removePropertyChangeListener(IPropertyChangeListener listener) {
88 fListeners.remove(listener);
89 if (fListeners.size() == 0)
90 fPreferences.removePropertyChangeListener(fListener);
96 public boolean contains(String name) {
97 return fPreferences.contains(name);
103 public void firePropertyChangeEvent(String name, Object oldValue,
106 PropertyChangeEvent event = new PropertyChangeEvent(this, name,
108 Object[] listeners = fListeners.getListeners();
109 for (int i = 0; i < listeners.length; i++)
110 ((IPropertyChangeListener) listeners[i]).propertyChange(event);
117 public boolean getBoolean(String name) {
118 return fPreferences.getBoolean(name);
124 public boolean getDefaultBoolean(String name) {
125 return fPreferences.getDefaultBoolean(name);
131 public double getDefaultDouble(String name) {
132 return fPreferences.getDefaultDouble(name);
138 public float getDefaultFloat(String name) {
139 return fPreferences.getDefaultFloat(name);
145 public int getDefaultInt(String name) {
146 return fPreferences.getDefaultInt(name);
152 public long getDefaultLong(String name) {
153 return fPreferences.getDefaultLong(name);
159 public String getDefaultString(String name) {
160 return fPreferences.getDefaultString(name);
166 public double getDouble(String name) {
167 return fPreferences.getDouble(name);
173 public float getFloat(String name) {
174 return fPreferences.getFloat(name);
180 public int getInt(String name) {
181 return fPreferences.getInt(name);
187 public long getLong(String name) {
188 return fPreferences.getLong(name);
194 public String getString(String name) {
195 return fPreferences.getString(name);
201 public boolean isDefault(String name) {
202 return fPreferences.isDefault(name);
208 public boolean needsSaving() {
209 return fPreferences.needsSaving();
215 public void putValue(String name, String value) {
218 fPreferences.setValue(name, value);
227 public void setDefault(String name, double value) {
228 fPreferences.setDefault(name, value);
234 public void setDefault(String name, float value) {
235 fPreferences.setDefault(name, value);
241 public void setDefault(String name, int value) {
242 fPreferences.setDefault(name, value);
248 public void setDefault(String name, long value) {
249 fPreferences.setDefault(name, value);
255 public void setDefault(String name, String defaultObject) {
256 fPreferences.setDefault(name, defaultObject);
262 public void setDefault(String name, boolean value) {
263 fPreferences.setDefault(name, value);
269 public void setToDefault(String name) {
270 fPreferences.setToDefault(name);
276 public void setValue(String name, double value) {
277 fPreferences.setValue(name, value);
283 public void setValue(String name, float value) {
284 fPreferences.setValue(name, value);
290 public void setValue(String name, int value) {
291 fPreferences.setValue(name, value);
297 public void setValue(String name, long value) {
298 fPreferences.setValue(name, value);
304 public void setValue(String name, String value) {
305 fPreferences.setValue(name, value);
311 public void setValue(String name, boolean value) {
312 fPreferences.setValue(name, value);