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.Dimension;
16 import java.awt.FlowLayout;
17 import java.awt.event.ActionEvent;
18 import java.lang.reflect.InvocationTargetException;
20 import javax.swing.ImageIcon;
21 import javax.swing.JButton;
22 import javax.swing.JPanel;
23 import javax.swing.JTextField;
25 import org.scilab.modules.commons.gui.FindIconHelper;
26 import org.scilab.modules.commons.gui.ScilabLAF;
27 import org.scilab.modules.gui.events.callback.CommonCallBack;
28 import org.scilab.modules.xcos.palette.view.PaletteManagerView;
29 import org.scilab.modules.xcos.utils.XcosMessages;
32 * Search Palettes Action
33 * @author Marcos CARDINOT <mcardinot@gmail.com>
35 public class SearchAction extends CommonCallBack {
37 private static final long serialVersionUID = 1L;
39 private static final String LABEL_SEARCH = XcosMessages.SEARCH;
40 private static final String ICON_SEARCH = FindIconHelper.findIcon("system-search");
42 private static JButton btnSearch;
43 private static JTextField txtSearch;
44 private static JPanel searchBar;
49 public SearchAction() {
54 * Create the search bar
57 public static JPanel createSearchBar() {
58 searchBar = new JPanel();
59 searchBar.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
61 txtSearch = new JTextField();
62 txtSearch.setPreferredSize(new Dimension(150, 22));
63 searchBar.add(txtSearch);
65 btnSearch = new JButton();
66 ScilabLAF.setDefaultProperties(btnSearch);
67 btnSearch.setIcon(new ImageIcon(ICON_SEARCH));
68 btnSearch.setToolTipText(LABEL_SEARCH);
69 btnSearch.addActionListener(getCallBack());
70 btnSearch.setFocusable(true);
71 btnSearch.setBorderPainted(false);
72 searchBar.add(btnSearch);
78 * Create a new class instance
79 * @return the instance
81 private static CommonCallBack getCallBack() {
82 CommonCallBack callback = null;
84 callback = SearchAction.class.getConstructor().newInstance();
85 } catch (IllegalArgumentException e) {
87 } catch (SecurityException e) {
89 } catch (InstantiationException e) {
91 } catch (IllegalAccessException e) {
93 } catch (InvocationTargetException e) {
95 } catch (NoSuchMethodException e) {
103 * @param e ActionEvent
105 public void actionPerformed(ActionEvent e) {
106 if (!txtSearch.getText().isEmpty()) {
107 PaletteManagerView.get().getSearchManager().search(txtSearch.getText());
112 public void callBack() {