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.bridge.menuitem.SwingScilabMenuItem;
24 import org.scilab.modules.gui.events.callback.CommonCallBack;
25 import org.scilab.modules.gui.menuitem.MenuItem;
26 import org.scilab.modules.gui.menuitem.ScilabMenuItem;
27 import org.scilab.modules.xcos.palette.view.PaletteManagerView;
28 import org.scilab.modules.xcos.utils.XcosMessages;
31 * Navigation menu management.
32 * Actions 'next' and 'previous' of the palette browser.
33 * @author Marcos CARDINOT <mcardinot@gmail.com>
35 public class NavigationAction extends CommonCallBack {
37 private static final long serialVersionUID = 1L;
39 private static final String ICON_NEXT = FindIconHelper.findIcon("go-next");
40 private static final String ICON_PREV = FindIconHelper.findIcon("go-previous");
42 private static JButton btnNEXT;
43 private static JButton btnPREV;
44 private static MenuItem miNEXT;
45 private static MenuItem miPREV;
50 public NavigationAction() {
55 * Create the button 'next'
58 public static JButton createButtonNext() {
59 btnNEXT = new JButton();
60 ScilabLAF.setDefaultProperties(btnNEXT);
61 btnNEXT.setName(XcosMessages.NEXT);
62 btnNEXT.setIcon(new ImageIcon(ICON_NEXT));
63 btnNEXT.setToolTipText(XcosMessages.NEXT);
64 btnNEXT.addActionListener(getCallBack());
65 btnNEXT.setFocusable(true);
66 setEnabledNext(false);
71 * Create the button 'previous'
74 public static JButton createButtonPrev() {
75 btnPREV = new JButton();
76 ScilabLAF.setDefaultProperties(btnPREV);
77 btnPREV.setName(XcosMessages.PREVIOUS);
78 btnPREV.setIcon(new ImageIcon(ICON_PREV));
79 btnPREV.setToolTipText(XcosMessages.PREVIOUS);
80 btnPREV.addActionListener(getCallBack());
81 btnPREV.setFocusable(true);
82 setEnabledPrev(false);
87 * Creates a menu item associated with the 'next' action
88 * @return the menuitem
90 public static MenuItem createMenuNext() {
91 miNEXT = ScilabMenuItem.createMenuItem();
92 miNEXT.setText(XcosMessages.NEXT);
93 miNEXT.setMnemonic('N');
94 miNEXT.setCallback(getCallBack());
95 ((SwingScilabMenuItem) miNEXT.getAsSimpleMenuItem()).setIcon(new ImageIcon(ICON_NEXT));
100 * Creates a menu item associated with the 'previous' action
101 * @return the menuitem
103 public static MenuItem createMenuPrev() {
104 miPREV = ScilabMenuItem.createMenuItem();
105 miPREV.setText(XcosMessages.PREVIOUS);
106 miPREV.setMnemonic('P');
107 miPREV.setCallback(getCallBack());
108 ((SwingScilabMenuItem) miPREV.getAsSimpleMenuItem()).setIcon(new ImageIcon(ICON_PREV));
113 * Create a new class instance
114 * @return the instance
116 private static CommonCallBack getCallBack() {
117 CommonCallBack callback = null;
119 callback = NavigationAction.class.getConstructor().newInstance();
120 } catch (IllegalArgumentException e) {
122 } catch (SecurityException e) {
124 } catch (InstantiationException e) {
126 } catch (IllegalAccessException e) {
128 } catch (InvocationTargetException e) {
130 } catch (NoSuchMethodException e) {
138 * @param e ActionEvent
140 public void actionPerformed(ActionEvent e) {
141 String cmd = e.getActionCommand();
143 cmd = ((JButton) e.getSource()).getName();
146 if (cmd.equals(XcosMessages.NEXT)) {
147 PaletteManagerView.get().getPanel().goNext();
148 } else if (cmd.equals(XcosMessages.PREVIOUS)) {
149 PaletteManagerView.get().getPanel().goPrevious();
154 * setEnabled property of the button 'next'
155 * @param enabled enabled
157 public static void setEnabledNext(boolean enabled) {
158 btnNEXT.setEnabled(enabled);
159 miNEXT.setEnabled(enabled);
163 * setEnabled property of the button 'previous'
164 * @param enabled enabled
166 public static void setEnabledPrev(boolean enabled) {
167 btnPREV.setEnabled(enabled);
168 miPREV.setEnabled(enabled);
172 public void callBack() {