⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preferencestore.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *      * @param out     *            the print stream     */    public void list(PrintStream out) {        properties.list(out);    }    /**     * Prints the contents of this preference store to the given print writer.     *      * @param out     *            the print writer     */    public void list(PrintWriter out) {        properties.list(out);    }    /**     * Loads this preference store from the file established in the constructor     * <code>PreferenceStore(java.lang.String)</code> (or by     * <code>setFileName</code>). Default preference values are not affected.     *      * @exception java.io.IOException     *                if there is a problem loading this store     */    public void load() throws IOException {        if (filename == null) {			throw new IOException("File name not specified");//$NON-NLS-1$		}        FileInputStream in = new FileInputStream(filename);        load(in);        in.close();    }    /**     * Loads this preference store from the given input stream. Default     * preference values are not affected.     *      * @param in     *            the input stream     * @exception java.io.IOException     *                if there is a problem loading this store     */    public void load(InputStream in) throws IOException {        properties.load(in);        dirty = false;    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public boolean needsSaving() {        return dirty;    }    /**     * Returns an enumeration of all preferences known to this store which have     * current values other than their default value.     *      * @return an array of preference names     */    public String[] preferenceNames() {        ArrayList list = new ArrayList();        Enumeration it = properties.propertyNames();        while (it.hasMoreElements()) {            list.add(it.nextElement());        }        return (String[]) list.toArray(new String[list.size()]);    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void putValue(String name, String value) {        String oldValue = getString(name);        if (oldValue == null || !oldValue.equals(value)) {            setValue(properties, name, value);            dirty = true;        }    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void removePropertyChangeListener(IPropertyChangeListener listener) {        removeListenerObject(listener);    }    /**     * Saves the non-default-valued preferences known to this preference store     * to the file from which they were originally loaded.     *      * @exception java.io.IOException     *                if there is a problem saving this store     */    public void save() throws IOException {        if (filename == null) {			throw new IOException("File name not specified");//$NON-NLS-1$		}        FileOutputStream out = null;        try {            out = new FileOutputStream(filename);            save(out, null);        } finally {            if (out != null) {				out.close();			}        }    }    /**     * Saves this preference store to the given output stream. The given string     * is inserted as header information.     *      * @param out     *            the output stream     * @param header     *            the header     * @exception java.io.IOException     *                if there is a problem saving this store     */    public void save(OutputStream out, String header) throws IOException {        properties.store(out, header);        dirty = false;    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setDefault(String name, double value) {        setValue(defaultProperties, name, value);    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setDefault(String name, float value) {        setValue(defaultProperties, name, value);    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setDefault(String name, int value) {        setValue(defaultProperties, name, value);    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setDefault(String name, long value) {        setValue(defaultProperties, name, value);    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setDefault(String name, String value) {        setValue(defaultProperties, name, value);    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setDefault(String name, boolean value) {        setValue(defaultProperties, name, value);    }    /**     * Sets the name of the file used when loading and storing this preference     * store.     * <p>     * Afterward, the methods <code>load()</code> and <code>save()</code>     * can be used to load and store this preference store.     * </p>     *      * @param name the file name     * @see #load()     * @see #save()     */    public void setFilename(String name) {        filename = name;    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setToDefault(String name) {        Object oldValue = properties.get(name);        properties.remove(name);        dirty = true;        Object newValue = null;        if (defaultProperties != null) {			newValue = defaultProperties.get(name);		}        firePropertyChangeEvent(name, oldValue, newValue);    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setValue(String name, double value) {        double oldValue = getDouble(name);        if (oldValue != value) {            setValue(properties, name, value);            dirty = true;            firePropertyChangeEvent(name, new Double(oldValue), new Double(                    value));        }    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setValue(String name, float value) {        float oldValue = getFloat(name);        if (oldValue != value) {            setValue(properties, name, value);            dirty = true;            firePropertyChangeEvent(name, new Float(oldValue), new Float(value));        }    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setValue(String name, int value) {        int oldValue = getInt(name);        if (oldValue != value) {            setValue(properties, name, value);            dirty = true;            firePropertyChangeEvent(name, new Integer(oldValue), new Integer(                    value));        }    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setValue(String name, long value) {        long oldValue = getLong(name);        if (oldValue != value) {            setValue(properties, name, value);            dirty = true;            firePropertyChangeEvent(name, new Long(oldValue), new Long(value));        }    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setValue(String name, String value) {        String oldValue = getString(name);        if (oldValue == null || !oldValue.equals(value)) {            setValue(properties, name, value);            dirty = true;            firePropertyChangeEvent(name, oldValue, value);        }    }    /*     * (non-Javadoc) Method declared on IPreferenceStore.     */    public void setValue(String name, boolean value) {        boolean oldValue = getBoolean(name);        if (oldValue != value) {            setValue(properties, name, value);            dirty = true;            firePropertyChangeEvent(name, new Boolean(oldValue), new Boolean(                    value));        }    }    /**     * Helper method: sets value for a given name.     * @param p     * @param name     * @param value     */    private void setValue(Properties p, String name, double value) {        Assert.isTrue(p != null);        p.put(name, Double.toString(value));    }    /**     * Helper method: sets value for a given name.     * @param p     * @param name     * @param value     */    private void setValue(Properties p, String name, float value) {        Assert.isTrue(p != null);        p.put(name, Float.toString(value));    }    /**     * Helper method: sets value for a given name.     * @param p     * @param name     * @param value     */    private void setValue(Properties p, String name, int value) {        Assert.isTrue(p != null);        p.put(name, Integer.toString(value));    }    /**     * Helper method: sets the value for a given name.     * @param p     * @param name     * @param value     */    private void setValue(Properties p, String name, long value) {        Assert.isTrue(p != null);        p.put(name, Long.toString(value));    }    /**     * Helper method: sets the value for a given name.     * @param p     * @param name     * @param value     */    private void setValue(Properties p, String name, String value) {        Assert.isTrue(p != null && value != null);        p.put(name, value);    }    /**     * Helper method: sets the value for a given name.     * @param p     * @param name     * @param value     */    private void setValue(Properties p, String name, boolean value) {        Assert.isTrue(p != null);        p.put(name, value == true ? IPreferenceStore.TRUE                : IPreferenceStore.FALSE);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -