AbstractPluginPreferences.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.xnap.util |
![]() |
![]() |
XNap 3 |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* XNap - A P2P framework and client.
*
* See the file AUTHORS for copyright information.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.xnap.util;
import java.awt.Color;
import java.awt.Font;
import java.beans.PropertyChangeListener;
import javax.swing.KeyStroke;
import org.apache.log4j.Logger;
import org.xnap.util.prefs.Validator;
/**
* This class acts as a wraper for the {@link Preferences} class. It
* is meant to be extended by plugins that need to store preferences.
*/
public abstract class AbstractPluginPreferences
implements TablePreferencesProvider {
//--- Constant(s) ---
public static final String VERSION_KEY = "props.ver";
//--- Data field(s) ---
protected static Logger logger
= Logger.getLogger(AbstractPluginPreferences.class);
protected Preferences prefs = Preferences.getInstance();
private String namespace = "";
private int version;
//--- Constructor(s) ---
/**
* Constructs an AbstractPluginPreference object. Calls the convert
* method if neccessary.
*
* @param namespace a prefix that is used for each key
* @param version the current version of the preferences
*/
public AbstractPluginPreferences(String namespace, int version)
{
if (!namespace.endsWith(".")) {
namespace += ".";
}
this.namespace = namespace;
this.version = version;
int oldVersion = getInt(VERSION_KEY);
if (oldVersion < version) {
logger.debug("converting from version " + oldVersion + " to "
+ version);
convert(oldVersion);
}
set(VERSION_KEY, version);
}
//--- Method(s) ---
public synchronized
void addPropertyChangeListener(PropertyChangeListener l)
{
prefs.addPropertyChangeListener(l);
}
public synchronized
void addPropertyChangeListener(String key, PropertyChangeListener l)
{
prefs.addPropertyChangeListener(key, l);
}
public synchronized
void addTableListener(String table, PropertyChangeListener l)
{
prefs.addTableListener(table, l);
}
public synchronized
void removePropertyChangeListener(PropertyChangeListener l) {
prefs.removePropertyChangeListener(l);
}
public synchronized
void removePropertyChangeListener(String key, PropertyChangeListener l) {
prefs.removePropertyChangeListener(key, l);
}
/**
* Convert the preferences from <code>oldVersion</code>. The
* default implementation does nothing. Sub classes should
* overwrite this method.
*/
public void convert(int oldVersion)
{
}
public String get(String key)
{
return prefs.get(namespace + key);
}
public boolean getNotShowDialog(String dialogName)
{
dialogName = StringHelper.toFirstUpper(dialogName);
return prefs.getBoolean(namespace + "notShowDialog" + dialogName);
}
public String[] getArray(String key)
{
return prefs.getArray(namespace + key);
}
public boolean getBoolean(String key)
{
return prefs.getBoolean(namespace + key);
}
public Color getColor(String key)
{
return prefs.getColor(namespace + key);
}
public Font getFont(String key)
{
return prefs.getFont(namespace + key);
}
public int getInt(String key)
{
return prefs.getInt(namespace + key);
}
public int[] getIntArray(String key)
{
return prefs.getIntArray(namespace + key);
}
public KeyStroke getKeyStroke(String key)
{
return prefs.getKeyStroke(namespace + key);
}
public long getLong(String key)
{
return prefs.getLong(namespace + key);
}
public String[] getTableColumns(String table)
{
return prefs.getTableColumns(namespace + table);
}
public int[] getTableColumnWidths(String table)
{
return prefs.getTableColumnWidths(namespace + table);
}
public boolean getTableMaintainSortOrder(String table)
{
return prefs.getTableMaintainSortOrder(namespace + table);
}
public int getTableSortedColumn(String table)
{
return prefs.getTableSortedColumn(namespace + table);
}
public void removeProperty(String key)
{
prefs.removeProperty(key);
}
/**
* Renames a property, used for conversion of property file formats.
* Ignores namespace. Does not fire change event.
*/
public void renameProperty(String oldKey, String newKey)
{
prefs.renameProperty(oldKey, newKey);
}
public void set(String key, String newValue)
{
prefs.set(namespace + key, newValue);
}
public void set(String key, String[] newValue)
{
prefs.set(namespace + key, newValue);
}
public void set(String key, boolean newValue)
{
prefs.set(namespace + key, newValue);
}
public void set(String key, Color newValue)
{
prefs.set(namespace + key, newValue);
}
public void set(String key, Font newValue)
{
prefs.set(namespace + key, newValue);
}
public void set(String key, int newValue)
{
prefs.set(namespace + key, newValue);
}
public void set(String key, int[] newValue)
{
prefs.set(namespace + key, newValue);
}
public void set(String key, KeyStroke newValue)
{
prefs.set(namespace + key, newValue);
}
public void set(String key, long newValue)
{
prefs.set(namespace + key, newValue);
}
public void setDefault(String key, String value, Validator validator)
{
prefs.setDefault(namespace + key, value, validator);
}
public void setDefault(String key, String value)
{
prefs.setDefault(namespace + key, value);
}
public void setNotShowDialog(String dialogName, boolean newValue)
{
dialogName = StringHelper.toFirstUpper(dialogName);
prefs.set(namespace + "notShowDialog" + dialogName, newValue);
}
public void setTableColumns(String table, String[] columns)
{
prefs.setTableColumns(namespace + table, columns);
}
public void setTableColumnWidths(String table, int[] widths)
{
prefs.setTableColumnWidths(namespace + table, widths);
}
public void setTableMaintainSortOrder(String table, boolean enable)
{
prefs.setTableMaintainSortOrder(namespace + table, enable);
}
public void setTableSortedColumn(String table, int column)
{
prefs.setTableSortedColumn(namespace + table, column);
}
}
The table below shows all metrics for AbstractPluginPreferences.java.




