source: src/main/java/genius/gui/panels/TextPanel.java@ 346

Last change on this file since 346 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 1.5 KB
Line 
1package genius.gui.panels;
2
3import java.awt.BorderLayout;
4
5import javax.swing.JPanel;
6import javax.swing.JTextField;
7import javax.swing.SwingUtilities;
8import javax.swing.event.DocumentEvent;
9import javax.swing.event.DocumentListener;
10
11import genius.core.listener.Listener;
12
13/**
14 * Shows a single text line input area.
15 */
16@SuppressWarnings("serial")
17public class TextPanel extends JPanel {
18 private final JTextField textfield;
19
20 public TextPanel(final TextModel model) {
21 setLayout(new BorderLayout());
22 this.textfield = new JTextField(model.getText());
23 add(textfield, BorderLayout.CENTER);
24 // not working?
25 // setMaximumSize(new Dimension(99999999, 30));
26 textfield.getDocument().addDocumentListener(new DocumentListener() {
27
28 @Override
29 public void removeUpdate(DocumentEvent e) {
30 if (!textfield.getText().isEmpty()) {
31 model.setText(textfield.getText());
32 }
33 // we ignore empty text to avoid reacting on replace procedure
34 // too early
35 }
36
37 @Override
38 public void insertUpdate(DocumentEvent e) {
39 model.setText(textfield.getText());
40 }
41
42 @Override
43 public void changedUpdate(DocumentEvent e) {
44 model.setText(textfield.getText());
45 }
46 });
47
48 model.addListener(new Listener<String>() {
49 @Override
50 public void notifyChange(final String data) {
51 SwingUtilities.invokeLater(new Runnable() {
52
53 @Override
54 public void run() {
55 textfield.setText((String) data);
56 }
57 });
58 }
59 });
60
61 }
62 public JTextField getTextField() {
63 return textfield;
64 }
65}
Note: See TracBrowser for help on using the repository browser.