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.file.FileUtil;
022import icy.gui.dialog.IdConfirmDialog;
023import icy.gui.frame.progress.ToolTipFrame;
024import icy.gui.util.LookAndFeelUtil;
025import icy.roi.ROI.ROIPainter;
026
027/**
028 * @author Stephane
029 */
030public class GeneralPreferences
031{
032    /**
033     * pref id
034     */
035    public static final String PREF_GENERAL_ID = "general";
036    public static final String TOOLTIPS_ID = "toolTips";
037    public static final String CONFIRMS_ID = "confirms";
038    public static final String ROIOVERLAY_ID = "roiOverlay";
039
040    /**
041     * id general
042     */
043    public static final String ID_SEQUENCE_PERSISTENCE = "sequencePersistence";
044    public static final String ID_SAVE_NEW_SEQUENCE = "saveNewSequence";
045    public static final String ID_VIRTUAL_MODE = "virtualMode";
046    public static final String ID_AUTO_UPDATE = "autoUpdate";
047    public static final String ID_LAST_UPDATECHECK_TIME = "lastUpdateCheckTime";
048    public static final String ID_RIBBON_MINIMIZED = "ribbonMinimized";
049    public static final String ID_DETACHED_MODE = "detached";
050    public static final String ID_ALWAYS_ON_TOP = "alwaysOnTop";
051    public static final String ID_USAGE_STATS_REPORT = "usageStatsReport";
052    public static final String ID_GUI_SKIN = "guiSkin";
053    public static final String ID_GUI_FONT_SIZE = "guiFontSize";
054    public static final String ID_STARTUP_TOOLTIP = "startupTooltip";
055    public static final String ID_LOADER_FOLDER = "loaderFolder";
056    public static final String ID_RESULT_FOLDER = "resultFolder";
057    public static final String ID_USER_LOGIN = "userLogin";
058    public static final String ID_USER_NAME = "userName";
059    public static final String ID_USER_EMAIL = "userEmail";
060    public static final String ID_HISTORY_SIZE = "historySize";
061    public static final String ID_OUTPUT_LOG_SIZE = "outputLogSize";
062    public static final String ID_OUTPUT_LOG_FILE = "outputLogFile";
063
064    /**
065     * id confirm
066     */
067    public static final String ID_CONFIRM_EXIT = "exit";
068
069    /**
070     * preferences
071     */
072    private static XMLPreferences prefGeneral;
073    private static XMLPreferences prefToolTips;
074    private static XMLPreferences prefConfirms;
075    private static XMLPreferences prefRoiOverlay;
076
077    public static void load()
078    {
079        // load preferences
080        prefGeneral = ApplicationPreferences.getPreferences().node(PREF_GENERAL_ID);
081        prefToolTips = prefGeneral.node(TOOLTIPS_ID);
082        prefConfirms = prefGeneral.node(CONFIRMS_ID);
083        prefRoiOverlay = prefGeneral.node(ROIOVERLAY_ID);
084    }
085
086    /**
087     * @deprecated Use {@link #getPreferences()} instead
088     */
089    @Deprecated
090    public static XMLPreferences getPreferencesGeneral()
091    {
092        return getPreferences();
093    }
094
095    /**
096     * @return the preferences
097     */
098    public static XMLPreferences getPreferences()
099    {
100        return prefGeneral;
101    }
102
103    /**
104     * @return the root preferences for tool tips ({@link ToolTipFrame}).
105     */
106    public static XMLPreferences getPreferencesToolTips()
107    {
108        return prefToolTips;
109    }
110
111    /**
112     * @return the root preferences for confirm dialog ({@link IdConfirmDialog}).
113     */
114    public static XMLPreferences getPreferencesConfirms()
115    {
116        return prefConfirms;
117    }
118
119    /**
120     * @return the root preferences for ROI overlay setting ({@link ROIPainter}).
121     */
122    public static XMLPreferences getPreferencesRoiOverlay()
123    {
124        return prefRoiOverlay;
125    }
126
127    public static boolean getExitConfirm()
128    {
129        return prefConfirms.getBoolean(ID_CONFIRM_EXIT, true);
130    }
131
132    public static boolean getSaveNewSequence()
133    {
134        return prefGeneral.getBoolean(ID_SAVE_NEW_SEQUENCE, false);
135    }
136
137    public static boolean getSequencePersistence()
138    {
139        return prefGeneral.getBoolean(ID_SEQUENCE_PERSISTENCE, true);
140    }
141
142    public static boolean getAutomaticUpdate()
143    {
144        return prefGeneral.getBoolean(ID_AUTO_UPDATE, true);
145    }
146
147    public static long getLastUpdateCheckTime()
148    {
149        return prefGeneral.getLong(ID_LAST_UPDATECHECK_TIME, 0);
150    }
151
152    public static boolean getRibbonMinimized()
153    {
154        return prefGeneral.getBoolean(ID_RIBBON_MINIMIZED, false);
155    }
156
157    public static boolean getMultiWindowMode()
158    {
159        return prefGeneral.getBoolean(ID_DETACHED_MODE, false);
160    }
161
162    public static boolean getAlwaysOnTop()
163    {
164        return prefGeneral.getBoolean(ID_ALWAYS_ON_TOP, false);
165    }
166
167    public static boolean getUsageStatisticsReport()
168    {
169        return prefGeneral.getBoolean(ID_USAGE_STATS_REPORT, true);
170    }
171
172    public static boolean getStatupTooltip()
173    {
174        return prefGeneral.getBoolean(ID_STARTUP_TOOLTIP, true);
175    }
176
177    public static String getLoaderFolder()
178    {
179        return prefGeneral.get(ID_LOADER_FOLDER, "");
180    }
181
182    public static String getResultFolder()
183    {
184        return prefGeneral.get(ID_RESULT_FOLDER, FileUtil.APPLICATION_DIRECTORY + FileUtil.separator + "result");
185    }
186
187    public static String getUserLogin()
188    {
189        return prefGeneral.get(ID_USER_LOGIN, "");
190    }
191
192    public static String getUserName()
193    {
194        return prefGeneral.get(ID_USER_NAME, "");
195    }
196
197    public static String getUserEmail()
198    {
199        return prefGeneral.get(ID_USER_EMAIL, "");
200    }
201
202    public static int getGuiFontSize()
203    {
204        return prefGeneral.getInt(ID_GUI_FONT_SIZE, LookAndFeelUtil.getDefaultFontSize());
205    }
206
207    public static String getGuiSkin()
208    {
209        return prefGeneral.get(ID_GUI_SKIN, LookAndFeelUtil.getDefaultSkin());
210    }
211
212    public static int getHistorySize()
213    {
214        return prefGeneral.getInt(ID_HISTORY_SIZE, 50);
215    }
216
217    public static int getOutputLogSize()
218    {
219        return prefGeneral.getInt(ID_OUTPUT_LOG_SIZE, 10000);
220    }
221
222    public static boolean getOutputLogToFile()
223    {
224        return prefGeneral.getBoolean(ID_OUTPUT_LOG_FILE, false);
225    }
226
227    public static boolean getVirtualMode()
228    {
229        return prefGeneral.getBoolean(ID_VIRTUAL_MODE, false);
230    }
231
232    public static void setExitConfirm(boolean value)
233    {
234        prefConfirms.putBoolean(ID_CONFIRM_EXIT, value);
235    }
236
237    public static void setSaveNewSequence(boolean value)
238    {
239        prefGeneral.putBoolean(ID_SAVE_NEW_SEQUENCE, value);
240    }
241
242    public static void setSequencePersistence(boolean value)
243    {
244        prefGeneral.putBoolean(ID_SEQUENCE_PERSISTENCE, value);
245    }
246
247    public static void setAutomaticUpdate(boolean value)
248    {
249        prefGeneral.putBoolean(ID_AUTO_UPDATE, value);
250    }
251
252    public static void setUsageStatisticsReport(boolean value)
253    {
254        prefGeneral.putBoolean(ID_USAGE_STATS_REPORT, value);
255    }
256
257    public static void setLastUpdateCheckTime(long time)
258    {
259        prefGeneral.putLong(ID_LAST_UPDATECHECK_TIME, time);
260    }
261
262    public static void setRibbonMinimized(boolean value)
263    {
264        prefGeneral.putBoolean(ID_RIBBON_MINIMIZED, value);
265    }
266
267    public static void setMultiWindowMode(boolean value)
268    {
269        prefGeneral.putBoolean(ID_DETACHED_MODE, value);
270    }
271
272    public static void setAlwaysOnTop(boolean value)
273    {
274        prefGeneral.putBoolean(ID_ALWAYS_ON_TOP, value);
275    }
276
277    public static void setStatupTooltip(boolean value)
278    {
279        prefGeneral.putBoolean(ID_STARTUP_TOOLTIP, value);
280    }
281
282    public static void setLoaderFolder(String value)
283    {
284        prefGeneral.put(ID_LOADER_FOLDER, value);
285    }
286
287    public static void setResultFolder(String value)
288    {
289        prefGeneral.put(ID_RESULT_FOLDER, value);
290    }
291
292    public static void setUserLogin(String value)
293    {
294        prefGeneral.put(ID_USER_LOGIN, value);
295    }
296
297    public static void setUserName(String value)
298    {
299        prefGeneral.put(ID_USER_NAME, value);
300    }
301
302    public static void setUserEmail(String value)
303    {
304        prefGeneral.put(ID_USER_EMAIL, value);
305    }
306
307    public static void setGuiFontSize(int value)
308    {
309        prefGeneral.putInt(ID_GUI_FONT_SIZE, value);
310    }
311
312    public static void setGuiSkin(String value)
313    {
314        prefGeneral.put(ID_GUI_SKIN, value);
315    }
316
317    public static void setHistorySize(int value)
318    {
319        prefGeneral.putInt(ID_HISTORY_SIZE, value);
320    }
321
322    public static void setOutputLogSize(int value)
323    {
324        prefGeneral.putInt(ID_OUTPUT_LOG_SIZE, value);
325    }
326
327    public static void setOutputLogFile(boolean value)
328    {
329        prefGeneral.putBoolean(ID_OUTPUT_LOG_FILE, value);
330    }
331
332    public static void setVirtualMode(boolean value)
333    {
334        prefGeneral.putBoolean(ID_VIRTUAL_MODE, value);
335    }
336}