2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2015 - Marcos CARDINOT
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13 package org.scilab.modules.xcos.palette.actions;
15 import java.awt.event.ActionEvent;
16 import java.lang.reflect.InvocationTargetException;
18 import javax.swing.ImageIcon;
19 import javax.swing.JButton;
21 import org.scilab.modules.commons.gui.FindIconHelper;
22 import org.scilab.modules.commons.gui.ScilabLAF;
23 import org.scilab.modules.gui.events.callback.CommonCallBack;
24 import org.scilab.modules.xcos.palette.view.PaletteManagerView;
25 import org.scilab.modules.xcos.utils.XcosMessages;
28 * Navigation menu management.
29 * Actions 'next' and 'previous' of the palette browser.
30 * @author Marcos CARDINOT <mcardinot@gmail.com>
32 public class NavigationAction extends CommonCallBack {
34 private static final long serialVersionUID = 1L;
36 private static final String LABEL_NEXT = XcosMessages.NEXT;
37 private static final String LABEL_PREV = XcosMessages.PREVIOUS;
38 private static final String ICON_NEXT = FindIconHelper.findIcon("go-next");
39 private static final String ICON_PREV = FindIconHelper.findIcon("go-previous");
41 private static JButton btnNEXT;
42 private static JButton btnPREV;
47 public NavigationAction() {
52 * Create the button 'next'
55 public static JButton createButtonNext() {
56 btnNEXT = new JButton();
57 ScilabLAF.setDefaultProperties(btnNEXT);
58 btnNEXT.setIcon(new ImageIcon(ICON_NEXT));
59 btnNEXT.setToolTipText(LABEL_NEXT);
60 btnNEXT.addActionListener(getCallBack());
61 btnNEXT.setFocusable(true);
62 setEnabledNext(false);
67 * Create the button 'previous'
70 public static JButton createButtonPrev() {
71 btnPREV = new JButton();
72 ScilabLAF.setDefaultProperties(btnPREV);
73 btnPREV.setIcon(new ImageIcon(ICON_PREV));
74 btnPREV.setToolTipText(LABEL_PREV);
75 btnPREV.addActionListener(getCallBack());
76 btnPREV.setFocusable(true);
77 setEnabledPrev(false);
82 * Create a new class instance
83 * @return the instance
85 private static CommonCallBack getCallBack() {
86 CommonCallBack callback = null;
88 callback = NavigationAction.class.getConstructor().newInstance();
89 } catch (IllegalArgumentException e) {
91 } catch (SecurityException e) {
93 } catch (InstantiationException e) {
95 } catch (IllegalAccessException e) {
97 } catch (InvocationTargetException e) {
99 } catch (NoSuchMethodException e) {
107 * @param e ActionEvent
109 public void actionPerformed(ActionEvent e) {
110 Object src = e.getSource();
111 if (btnNEXT != null && src.equals(btnNEXT)) {
112 PaletteManagerView.get().getPanel().goNext();
113 } else if (btnPREV != null && src.equals(btnPREV)) {
114 PaletteManagerView.get().getPanel().goPrevious();
119 * setEnabled property of the button 'next'
120 * @param enabled enabled
122 public static void setEnabledNext(boolean enabled) {
123 btnNEXT.setEnabled(enabled);
127 * setEnabled property of the button 'previous'
128 * @param enabled enabled
130 public static void setEnabledPrev(boolean enabled) {
131 btnPREV.setEnabled(enabled);
135 public void callBack() {