Last change
on this file since 6972 was
6972,
checked in by mlg, 14 years ago
|
New feature : research
Add a research functionnality : it's juste a field on the bottom right of the main frame. To make a research, the user have to type text in that field and press enter. It opens a new tab. A new tab is opened for each research. The tab contains the query string.
|
File size:
853 bytes
|
Line | |
---|
1 | package fr.mael.jiwigo.ui.field; |
---|
2 | |
---|
3 | import java.awt.Color; |
---|
4 | import java.awt.event.FocusEvent; |
---|
5 | import java.awt.event.FocusListener; |
---|
6 | |
---|
7 | import javax.swing.JTextField; |
---|
8 | |
---|
9 | public class HintTextField extends JTextField implements FocusListener { |
---|
10 | |
---|
11 | private final String hint; |
---|
12 | |
---|
13 | public HintTextField(final String hint) { |
---|
14 | super(hint); |
---|
15 | this.hint = hint; |
---|
16 | setForeground(Color.GRAY); |
---|
17 | super.addFocusListener(this); |
---|
18 | } |
---|
19 | |
---|
20 | @Override |
---|
21 | public void focusGained(FocusEvent e) { |
---|
22 | if (this.getText().isEmpty()) { |
---|
23 | setForeground(Color.BLACK); |
---|
24 | super.setText(""); |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | @Override |
---|
29 | public void focusLost(FocusEvent e) { |
---|
30 | if (this.getText().isEmpty()) { |
---|
31 | super.setText(hint); |
---|
32 | setForeground(Color.GRAY); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | @Override |
---|
37 | public String getText() { |
---|
38 | String typed = super.getText(); |
---|
39 | return typed.equals(hint) ? "" : typed; |
---|
40 | } |
---|
41 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.