2
* $Id: JXFindBar.java,v 1.11 2007/09/14 08:12:38 kleopatra Exp $
4
* Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5
* Santa Clara, California 95054, U.S.A. All rights reserved.
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
package org.jdesktop.swingx;
23
import java.awt.Color;
24
import java.awt.FlowLayout;
26
import javax.swing.JButton;
27
import javax.swing.JLabel;
28
import javax.swing.KeyStroke;
29
import javax.swing.SwingConstants;
32
* A simple low-intrusion default widget for incremental search.
34
* Actions registered (in addition to super):
36
* <li> {@link JXDialog#CLOSE_ACTION_COMMAND} - an action bound to this
37
* component's cancel method. The method itself is an empty implementation:
38
* Subclassing clients can override the method, all clients can register a
44
* <li> ESCAPE - calls action registered for
45
* {@link JXDialog#CLOSE_ACTION_COMMAND}
48
* This implementation uses textfield coloring as not-found visualization.
51
* PENDING: the coloring needs to be read from the UIManager instead of
55
* PENDING: the state transition of found/non-found coloring needs clean-up -
56
* there are spurious problems when re-using the same instance (as SearchFactory
59
* @author Jeanette Winzenburg
62
public class JXFindBar extends JXFindPanel {
64
protected Color previousBackgroundColor;
66
protected Color previousForegroundColor;
68
// PENDING: need to read from UIManager
69
protected Color notFoundBackgroundColor = Color.decode("#FF6666");
71
protected Color notFoundForegroundColor = Color.white;
73
protected JButton findNext;
75
protected JButton findPrevious;
81
public JXFindBar(Searchable searchable) {
83
getPatternModel().setIncremental(true);
84
getPatternModel().setWrapping(true);
88
public void setSearchable(Searchable searchable) {
89
super.setSearchable(searchable);
94
* here: set textfield colors to not-found colors.
97
protected void showNotFoundMessage() {
98
//JW: quick hack around #487-swingx - NPE in setSearchable
99
if (searchField == null) return;
100
searchField.setForeground(notFoundForegroundColor);
101
searchField.setBackground(notFoundBackgroundColor);
105
* here: set textfield colors to normal.
108
protected void showFoundMessage() {
109
//JW: quick hack around #487-swingx - NPE in setSearchable
110
if (searchField == null) return;
111
searchField.setBackground(previousBackgroundColor);
112
searchField.setForeground(previousForegroundColor);
116
public void addNotify() {
118
if (previousBackgroundColor == null) {
119
previousBackgroundColor = searchField.getBackground();
120
previousForegroundColor = searchField.getForeground();
122
searchField.setBackground(previousBackgroundColor);
123
searchField.setForeground(previousForegroundColor);
127
// --------------------------- action call back
129
* Action callback method for bound action JXDialog.CLOSE_ACTION_COMMAND.
131
* Here: does nothing. Subclasses can override to define custom "closing"
132
* behaviour. Alternatively, any client can register a custom action with
137
public void cancel() {
140
// -------------------- init
143
protected void initExecutables() {
144
getActionMap().put(JXDialog.CLOSE_ACTION_COMMAND,
145
createBoundAction(JXDialog.CLOSE_ACTION_COMMAND, "cancel"));
146
super.initExecutables();
150
protected void bind() {
153
.addActionListener(getAction(JXDialog.EXECUTE_ACTION_COMMAND));
154
findNext.setAction(getAction(FIND_NEXT_ACTION_COMMAND));
155
findPrevious.setAction(getAction(FIND_PREVIOUS_ACTION_COMMAND));
156
KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE");
157
getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(stroke,
158
JXDialog.CLOSE_ACTION_COMMAND);
162
protected void build() {
163
setLayout(new FlowLayout(SwingConstants.LEADING));
165
add(new JLabel(":"));
166
add(new JLabel(" "));
173
protected void initComponents() {
174
super.initComponents();
175
findNext = new JButton();
176
findPrevious = new JButton();