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;
18 import java.awt.event.ActionEvent;
19 import java.lang.reflect.InvocationTargetException;
21 import javax.swing.ImageIcon;
22 import javax.swing.JButton;
23 import javax.swing.JPanel;
24 import javax.swing.JTextField;
26 import org.scilab.modules.commons.gui.FindIconHelper;
27 import org.scilab.modules.commons.gui.ScilabLAF;
28 import org.scilab.modules.gui.events.callback.CommonCallBack;
29 import org.scilab.modules.xcos.palette.view.PaletteManagerView;
30 import org.scilab.modules.xcos.utils.XcosMessages;
33 * Search Palettes Action
34 * @author Marcos CARDINOT <mcardinot@gmail.com>
36 public class SearchAction extends CommonCallBack {
38 private static final long serialVersionUID = 1L;
40 private static final String LABEL_SEARCH = XcosMessages.SEARCH;
41 private static final String ICON_SEARCH = FindIconHelper.findIcon("system-search");
43 private static JButton btnSearch;
44 private static JTextField txtSearch;
45 private static JPanel searchBar;
50 public SearchAction() {
55 * Create the search bar
58 public static JPanel createSearchBar() {
59 searchBar = new JPanel();
60 searchBar.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
62 txtSearch = new JTextField();
63 txtSearch.setPreferredSize(new Dimension(150, 22));
64 txtSearch.setFont(new Font("SansSerif", Font.PLAIN, 10));
65 searchBar.add(txtSearch);
67 btnSearch = new JButton();
68 ScilabLAF.setDefaultProperties(btnSearch);
69 btnSearch.setIcon(new ImageIcon(ICON_SEARCH));
70 btnSearch.setToolTipText(LABEL_SEARCH);
71 btnSearch.addActionListener(getCallBack());
72 btnSearch.setFocusable(true);
73 btnSearch.setBorderPainted(false);
74 searchBar.add(btnSearch);
80 * Create a new class instance
81 * @return the instance
83 private static CommonCallBack getCallBack() {
84 CommonCallBack callback = null;
86 callback = SearchAction.class.getConstructor().newInstance();
87 } catch (IllegalArgumentException e) {
89 } catch (SecurityException e) {
91 } catch (InstantiationException e) {
93 } catch (IllegalAccessException e) {
95 } catch (InvocationTargetException e) {
97 } catch (NoSuchMethodException e) {
105 * @param e ActionEvent
107 public void actionPerformed(ActionEvent e) {
108 if (!txtSearch.getText().isEmpty()) {
109 PaletteManagerView.get().getSearchManager().search(txtSearch.getText());
114 public void callBack() {