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.action;
020
021import icy.gui.preferences.GUICanvasPreferencePanel;
022import icy.gui.preferences.ChatPreferencePanel;
023import icy.gui.preferences.GeneralPreferencePanel;
024import icy.gui.preferences.NetworkPreferencePanel;
025import icy.gui.preferences.PluginLocalPreferencePanel;
026import icy.gui.preferences.PluginOnlinePreferencePanel;
027import icy.gui.preferences.PluginPreferencePanel;
028import icy.gui.preferences.PluginStartupPreferencePanel;
029import icy.gui.preferences.PreferenceFrame;
030import icy.gui.preferences.RepositoryPreferencePanel;
031import icy.gui.preferences.WorkspaceLocalPreferencePanel;
032import icy.gui.preferences.WorkspaceOnlinePreferencePanel;
033import icy.gui.preferences.WorkspacePreferencePanel;
034import icy.resource.ResourceUtil;
035import icy.resource.icon.IcyIcon;
036import icy.util.ClassUtil;
037
038import java.awt.event.ActionEvent;
039import java.lang.reflect.Field;
040import java.util.ArrayList;
041import java.util.Arrays;
042import java.util.List;
043
044/**
045 * Preference actions.
046 * 
047 * @author Stephane
048 */
049public class PreferencesActions
050{
051    public static IcyAbstractAction preferencesAction = new IcyAbstractAction("Preferences  ", new IcyIcon(
052            ResourceUtil.ICON_TOOLS), "Show the preferences window", "Setup Icy preferences")
053    {
054        /**
055         * 
056         */
057        private static final long serialVersionUID = 1536708346834850905L;
058
059        @Override
060        public boolean doAction(ActionEvent e)
061        {
062            new PreferenceFrame(GeneralPreferencePanel.NODE_NAME);
063            return true;
064        }
065    };
066
067    public static IcyAbstractAction generalPreferencesAction = new IcyAbstractAction("Preferences", new IcyIcon(
068            ResourceUtil.ICON_TOOLS), "Show the general preferences window",
069            "Setup general setting as font size, automatic update, maximum memory...")
070    {
071        /**
072         * 
073         */
074        private static final long serialVersionUID = 1536708346834850905L;
075
076        @Override
077        public boolean doAction(ActionEvent e)
078        {
079            new PreferenceFrame(GeneralPreferencePanel.NODE_NAME);
080            return true;
081        }
082    };
083
084    public static IcyAbstractAction canvasPreferencesAction = new IcyAbstractAction("Canvas preferences", new IcyIcon(
085            ResourceUtil.ICON_PICTURE), "Show the canvas preferences window",
086            "Setup canvas setting as filtering, mouse wheel sensivity and reverse mouse axis...")
087    {
088        /**
089         * 
090         */
091        private static final long serialVersionUID = 5758147926869943436L;
092
093        @Override
094        public boolean doAction(ActionEvent e)
095        {
096            new PreferenceFrame(GUICanvasPreferencePanel.NODE_NAME);
097            return true;
098        }
099    };
100
101//    public static IcyAbstractAction chatPreferencesAction = new IcyAbstractAction("Chat preferences", new IcyIcon(
102//            ResourceUtil.ICON_CHAT), "Show the chat preferences window",
103//            "Setup chat setting as auto connect, real name, chat password...")
104//    {
105//        /**
106//         * 
107//         */
108//        private static final long serialVersionUID = 7557101963461320397L;
109//
110//        @Override
111//        public boolean doAction(ActionEvent e)
112//        {
113//            new PreferenceFrame(ChatPreferencePanel.NODE_NAME);
114//            return true;
115//        }
116//    };
117
118    public static IcyAbstractAction networkPreferencesAction = new IcyAbstractAction("Network preferences",
119            new IcyIcon(ResourceUtil.ICON_NETWORK), "Show the network preferences window",
120            "Setup network setting as proxy server.")
121    {
122        /**
123         * 
124         */
125        private static final long serialVersionUID = -8056321522618950702L;
126
127        @Override
128        public boolean doAction(ActionEvent e)
129        {
130            new PreferenceFrame(NetworkPreferencePanel.NODE_NAME);
131            return true;
132        }
133    };
134
135    public static IcyAbstractAction pluginPreferencesAction = new IcyAbstractAction("Plugin preferences", new IcyIcon(
136            ResourceUtil.ICON_PLUGIN), "Show the plugin preferences window",
137            "Setup plugin setting as automatic update and enable beta version.")
138    {
139        /**
140         * 
141         */
142        private static final long serialVersionUID = 1703582841917110419L;
143
144        @Override
145        public boolean doAction(ActionEvent e)
146        {
147            new PreferenceFrame(PluginPreferencePanel.NODE_NAME);
148            return true;
149        }
150    };
151
152    public static IcyAbstractAction localPluginPreferencesAction = new IcyAbstractAction("Local plugin", new IcyIcon(
153            ResourceUtil.ICON_PLUGIN), "Show the local plugin window",
154            "Browse, remove, update and show informations about installed plugin.")
155    {
156        /**
157         * 
158         */
159        private static final long serialVersionUID = -8604088116271591026L;
160
161        @Override
162        public boolean doAction(ActionEvent e)
163        {
164            new PreferenceFrame(PluginLocalPreferencePanel.NODE_NAME);
165            return true;
166        }
167    };
168
169    public static IcyAbstractAction onlinePluginPreferencesAction = new IcyAbstractAction("Online plugin", new IcyIcon(
170            ResourceUtil.ICON_PLUGIN), "Show the online plugin window", "Browse online plugins and install them.")
171    {
172        /**
173         * 
174         */
175        private static final long serialVersionUID = -4583665324845708263L;
176
177        @Override
178        public boolean doAction(ActionEvent e)
179        {
180            new PreferenceFrame(PluginOnlinePreferencePanel.NODE_NAME);
181            return true;
182        }
183    };
184
185    public static IcyAbstractAction startupPluginPreferencesAction = new IcyAbstractAction("Startup plugin",
186            new IcyIcon(ResourceUtil.ICON_PLUGIN), "Show the startup plugin window",
187            "Enable / disable startup plugins.")
188    {
189        /**
190         * 
191         */
192        private static final long serialVersionUID = 3354219389334167804L;
193
194        @Override
195        public boolean doAction(ActionEvent e)
196        {
197            new PreferenceFrame(PluginStartupPreferencePanel.NODE_NAME);
198            return true;
199        }
200    };
201
202    public static IcyAbstractAction repositoryPreferencesAction = new IcyAbstractAction("Repository preferences",
203            new IcyIcon(ResourceUtil.ICON_TOOLS), "Show the repository preferences window",
204            "Add, edit or remove repository address.")
205    {
206        /**
207         * 
208         */
209        private static final long serialVersionUID = -8186738344041266273L;
210
211        @Override
212        public boolean doAction(ActionEvent e)
213        {
214            new PreferenceFrame(RepositoryPreferencePanel.NODE_NAME);
215            return true;
216        }
217    };
218
219    public static IcyAbstractAction workspacePreferencesAction = new IcyAbstractAction("Workspace preferences",
220            new IcyIcon(ResourceUtil.ICON_TOOLS), "Show the workspace preferences window")
221    {
222        /**
223         * 
224         */
225        private static final long serialVersionUID = -7568519363461531069L;
226
227        @Override
228        public boolean doAction(ActionEvent e)
229        {
230            new PreferenceFrame(WorkspacePreferencePanel.NODE_NAME);
231            return true;
232        }
233    };
234
235    public static IcyAbstractAction localWorkspacePreferencesAction = new IcyAbstractAction("Local workspace",
236            new IcyIcon(ResourceUtil.ICON_TOOLS), "Show the local workspace window",
237            "Enable / disable or remove installed workspaces.")
238    {
239        /**
240         * 
241         */
242        private static final long serialVersionUID = 5843627734779598519L;
243
244        @Override
245        public boolean doAction(ActionEvent e)
246        {
247            new PreferenceFrame(WorkspaceLocalPreferencePanel.NODE_NAME);
248            return true;
249        }
250    };
251    public static IcyAbstractAction onlineWorkspacePreferencesAction = new IcyAbstractAction("Online workspace",
252            new IcyIcon(ResourceUtil.ICON_TOOLS), "Show the online workspace window",
253            "Browse online workspaces and install them.")
254    {
255        /**
256         * 
257         */
258        private static final long serialVersionUID = 4739347012951517215L;
259
260        @Override
261        public boolean doAction(ActionEvent e)
262        {
263            new PreferenceFrame(WorkspaceOnlinePreferencePanel.NODE_NAME);
264            return true;
265        }
266    };
267
268    /**
269     * Return all actions of this class
270     */
271    public static List<IcyAbstractAction> getAllActions()
272    {
273        final List<IcyAbstractAction> result = new ArrayList<IcyAbstractAction>();
274
275        for (Field field : PreferencesActions.class.getFields())
276        {
277            final Class<?> type = field.getType();
278
279            try
280            {
281                if (ClassUtil.isSubClass(type, IcyAbstractAction[].class))
282                    result.addAll(Arrays.asList(((IcyAbstractAction[]) field.get(null))));
283                else if (ClassUtil.isSubClass(type, IcyAbstractAction.class))
284                    result.add((IcyAbstractAction) field.get(null));
285            }
286            catch (Exception e)
287            {
288                // ignore
289            }
290        }
291
292        return result;
293    }
294}