source: java/main/src/main/java/com/framsticks/gui/controls/TextControl.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 1018 bytes
Line 
1package com.framsticks.gui.controls;
2
3import javax.swing.event.DocumentEvent;
4import javax.swing.event.DocumentListener;
5import javax.swing.text.JTextComponent;
6
7import com.framsticks.params.PrimitiveParam;
8
9@SuppressWarnings("serial")
10public abstract class TextControl extends ValueControl {
11
12        public TextControl(PrimitiveParam<?> valueParam) {
13                super(valueParam);
14        }
15
16        protected void addDefaultDocumentListener(JTextComponent text) {
17                text.getDocument().addDocumentListener(createDocumentListener(new Runnable() {
18                        @Override
19                        public void run() {
20                                notifyOfChange();
21                        }
22                }));
23        }
24
25        protected static DocumentListener createDocumentListener(final Runnable runnable) {
26                return new DocumentListener() {
27                        @Override
28                        public void insertUpdate(DocumentEvent documentEvent) {
29                                runnable.run();
30                        }
31
32                        @Override
33                        public void removeUpdate(DocumentEvent documentEvent) {
34                                runnable.run();
35                        }
36
37                        @Override
38                        public void changedUpdate(DocumentEvent documentEvent) {
39                                runnable.run();
40                        }
41                };
42        }
43
44
45
46}
Note: See TracBrowser for help on using the repository browser.