1 package org.catacomb.druid.swing;
2
3
4 import org.catacomb.druid.event.LabelActor;
5 import org.catacomb.report.E;
6
7 import java.awt.BorderLayout;
8 import java.awt.FlowLayout;
9 import java.util.ArrayList;
10 import java.util.StringTokenizer;
11
12
13
14
15
16
17
18
19
20
21 public class DPlainTextEditor extends DFrame implements LabelActor {
22
23 static final long serialVersionUID = 1001;
24
25 DTextArea ta;
26 String context = "";
27 String[] target;
28
29 LabelActor lact;
30
31
32 public DPlainTextEditor() {
33 super("string array editor");
34 E.deprecate();
35 DPanel pp = new DPanel();
36 pp.setLayout(new BorderLayout(14, 14));
37
38 ta = new DTextArea(12, 40, DTextArea.SCROLLABLE);
39
40
41 ta.setColumns(22);
42 ta.setRows(20);
43
44 ta.setEditable(true);
45
46 pp.add("Center", ta);
47
48 DPanel pbot = new DPanel();
49 pbot.setLayout(new FlowLayout(FlowLayout.CENTER));
50
51 DButton[] cbs = { (new DButton("apply")), (new DButton("cancel")) };
52 for (int i = 0; i < cbs.length; i++) {
53 pbot.add(cbs[i]);
54 cbs[i].setLabelActor(this);
55 }
56 pp.add("South", pbot);
57
58 getContentPane().add("Center", pp);
59 pack();
60 }
61
62
63 public void setLabelActor(LabelActor la) {
64 lact = la;
65 }
66
67
68 public void setContext(String s) {
69 context = s;
70 }
71
72
73 public String[] getStringArray() {
74 String s = ta.getText();
75 StringTokenizer st = new StringTokenizer(s, "\n");
76 ArrayList<String> v = new ArrayList<String>();
77 while (st.hasMoreTokens()) {
78 String tok = st.nextToken().trim();
79 if (tok.length() > 0) {
80 v.add(tok);
81 }
82 }
83 int n = v.size();
84 String[] sa = new String[n];
85 for (int i = 0; i < v.size(); i++) {
86 sa[i] = v.get(i);
87 }
88 return sa;
89 }
90
91
92
93 public void labelAction(String sarg, boolean selected) {
94
95 if (sarg.equals("OK")) {
96 if (lact != null) {
97 lact.labelAction("OK", true);
98 }
99 setVisible(false);
100
101 } else if (sarg.equals("cancel")) {
102 setVisible(false);
103
104 }
105 }
106
107
108 public void setTarget(String[] sa) {
109 target = sa;
110 showContent();
111 }
112
113
114
115 public void showContent() {
116 String[] sa = target;
117
118 if (sa == null) {
119 ta.setText("");
120
121 } else {
122 StringBuffer sb = new StringBuffer();
123 for (int i = 0; i < sa.length; i++) {
124 sb.append(sa[i]);
125 sb.append("\n");
126 }
127
128 ta.setText(sb.toString());
129 }
130 ta.setVisible(true);
131 setVisible(true);
132 }
133
134 public void setText(String s) {
135
136 }
137
138
139 public String getText() {
140 return ("ERROR text editor missing code");
141 }
142
143 }