001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.preferences;
020
021import icy.plugin.abstract_.Plugin;
022import icy.preferences.XMLPreferences.XMLPreferencesRoot;
023
024/**
025 * Global class for Preferences.
026 * 
027 * @author Stephane
028 */
029public class IcyPreferences
030{
031    private static final String DEFAULT_NAME = "setting.xml";
032
033    // load from default setting file
034    private static final XMLPreferencesRoot root = new XMLPreferencesRoot(DEFAULT_NAME);
035
036    public static void init()
037    {
038        // load preferences
039        load();
040    }
041
042    public static void load()
043    {
044        // load root first
045        ApplicationPreferences.load();
046        // then load others
047        GeneralPreferences.load();
048        CanvasPreferences.load();
049        NetworkPreferences.load();
050        ChatPreferences.load();
051        RepositoryPreferences.load();
052        // load plugin before pluginLocal and pluginOnline
053        PluginPreferences.load();
054        PluginLocalPreferences.load();
055        PluginOnlinePreferences.load();
056        // load workspace before workspaceLocal and workspaceOnline
057        WorkspacePreferences.load();
058        WorkspaceLocalPreferences.load();
059        WorkspaceOnlinePreferences.load();
060        PluginsPreferences.load();
061    }
062
063    public static void save()
064    {
065        // save to setting file
066        root.save();
067    }
068
069    public static void clear()
070    {
071        // removing all from root node is sufficient
072        root.getPreferences().clear();
073        root.getPreferences().removeChildren();
074        root.getPreferences().clean();
075
076        // reload
077        load();
078    }
079
080    /**
081     * Get absolute root
082     */
083    public static XMLPreferences root()
084    {
085        return root.getPreferences();
086    }
087
088    /**
089     * Get application root
090     */
091    public static XMLPreferences applicationRoot()
092    {
093        return ApplicationPreferences.getPreferences();
094    }
095
096    /**
097     * @deprecated Use {@link PluginsPreferences#root(Plugin)} instead.
098     */
099    @Deprecated
100    public static XMLPreferences pluginRoot(Plugin plugin)
101    {
102        return PluginsPreferences.root(plugin);
103    }
104
105    /**
106     * @deprecated Use {@link PluginsPreferences#getPreferences()} instead.
107     */
108    @Deprecated
109    public static XMLPreferences pluginsRoot()
110    {
111        return PluginsPreferences.getPreferences();
112    }
113
114}