1 | // Copyright 2004-2007 Jean-Francois Poilpret |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package net.sourceforge.hiveboard.drawing; |
16 | |
17 | import java.awt.BorderLayout; |
18 | |
19 | import javax.swing.JScrollPane; |
20 | import javax.swing.JTextArea; |
21 | import javax.swing.text.Document; |
22 | |
23 | import org.jdesktop.application.Action; |
24 | |
25 | import net.sourceforge.hivegui.component.TextListener; |
26 | import net.sourceforge.hivegui.dialog.AbstractDialogPanel; |
27 | |
28 | public class TextToolPanel extends AbstractDialogPanel |
29 | { |
30 | static private final String NAME = "text-tool"; |
31 | |
32 | public TextToolPanel() |
33 | { |
34 | super(NAME); |
35 | setLayout(new BorderLayout()); |
36 | |
37 | // Initialize widgets |
38 | _field.setName(NAME + "-input"); |
39 | JScrollPane scroller = new JScrollPane( _field, |
40 | JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, |
41 | JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); |
42 | add(scroller, BorderLayout.CENTER); |
43 | |
44 | _field.getDocument().addDocumentListener(new TextListener() |
45 | { |
46 | @Override protected void contentUpdated() |
47 | { |
48 | setAcceptEnabled( _field.getText() != null |
49 | && _field.getText().length() != 0); |
50 | } |
51 | }); |
52 | } |
53 | |
54 | public Document getFieldDocument() |
55 | { |
56 | return _field.getDocument(); |
57 | } |
58 | |
59 | @Override public void reset() |
60 | { |
61 | setAcceptEnabled(false); |
62 | _field.setText(""); |
63 | _field.requestFocus(); |
64 | } |
65 | |
66 | @Action(enabledProperty = "acceptEnabled") |
67 | public void accept() |
68 | { |
69 | _parent.close(false); |
70 | } |
71 | |
72 | final private JTextArea _field = new JTextArea(5, 40); |
73 | } |