View Javadoc

1   
2   package org.catacomb.druid.gui.edit;
3   
4   import java.awt.BorderLayout;
5   import java.awt.Color;
6   import java.awt.GridLayout;
7   
8   import org.catacomb.druid.event.TextActor;
9   import org.catacomb.druid.swing.DBorderLayout;
10  import org.catacomb.druid.swing.DButton;
11  import org.catacomb.druid.swing.DPanel;
12  import org.catacomb.druid.swing.DTextArea;
13  import org.catacomb.interlish.content.StringValue;
14  import org.catacomb.interlish.structure.Ablable;
15  import org.catacomb.interlish.structure.TextArea;
16  import org.catacomb.interlish.structure.Value;
17  import org.catacomb.interlish.structure.ValueWatcher;
18  import org.catacomb.report.E;
19  
20  
21  public class DruExpandingTextArea extends DruGCPanel
22      implements TextActor, Ablable, TextArea, ValueWatcher {
23      static final long serialVersionUID = 1001;
24  
25  
26      DTextArea dTextArea;
27  
28      DPanel rtPanel;
29      DPanel rbPanel;
30  
31      DButton upButton;
32      DButton downButton;
33  
34  
35      StringValue stringValue;
36  
37      boolean collapsed;
38  
39      boolean autoResize = false;
40  
41  
42      public DruExpandingTextArea(String mn, int width, int height) {
43          super();
44  
45          setBorderLayout(0, 0);
46  
47          setActionMethod(mn);
48  
49          dTextArea = new DTextArea(width, height, DTextArea.SCROLLABLE);
50  
51          addDComponent(dTextArea, DBorderLayout.CENTER);
52  
53  
54          rtPanel = new DPanel();
55          rtPanel.setLayout(new BorderLayout());
56          rbPanel = new DPanel();
57          rbPanel.setLayout(new GridLayout(2, 1, 2, 2));
58          rtPanel.add(rbPanel, DBorderLayout.NORTH);
59  
60  
61          upButton = new DButton("");
62          upButton.setActionCommand("remove");
63          upButton.setIconSource("up-hat.gif");
64          upButton.setPadding(2, 2, 2, 2);
65  
66          downButton = new DButton("");
67          downButton.setActionCommand("add");
68          downButton.setIconSource("down-hat.gif");
69          downButton.setPadding(2, 2, 2, 2);
70          rbPanel.add(upButton);
71          rbPanel.add(downButton);
72  
73          addDComponent(rtPanel, DBorderLayout.WEST);
74  
75  
76          ExpandingTextAreaController etac =  new ExpandingTextAreaController(dTextArea);
77  
78          //   DruActionRelay relay = new DruActionRelay(etac);
79  
80          upButton.setLabelActor(etac);
81          downButton.setLabelActor(etac);
82  
83  
84          //      dTextArea.setLabelActor(this);
85          dTextArea.setTextActor(this);
86  
87          setLineBorder(0xc0c0c0);
88          collapsed = false;
89      }
90  
91  
92      public void collapse() {
93          if (!collapsed) {
94              removeDComponent(dTextArea);
95              removeDComponent(rtPanel);
96  
97              collapsed = true;
98          }
99  
100     }
101 
102     public void uncollapse() {
103         if (collapsed) {
104             addDComponent(dTextArea, DBorderLayout.CENTER);
105             addDComponent(rtPanel, DBorderLayout.WEST);
106             collapsed = false;
107         }
108     }
109 
110 
111     public void valueChangedBy(Value pv, Object src) {
112         if (src == this) {
113 
114         } else {
115             if (stringValue == pv) {
116                 if (stringValue == null) {
117                     dTextArea.setText("");
118                     dTextArea.setEnabled(false);
119                 } else {
120                     dTextArea.setText(stringValue.getString());
121                     if (autoResize) {
122                         dTextArea.resizeUpToText();
123                     }
124                     if (src.equals("HIGHLIGHT")) {  // ADHOC
125                         dTextArea.highlightLine(stringValue.getHighlight());
126                     } else {
127                         dTextArea.clearHighlight();
128                     }
129 
130                 }
131             } else {
132                 E.error("value changed by called with mismatched value");
133             }
134         }
135     }
136 
137 
138     public void setStringValue(StringValue sv) {
139         if (stringValue != null) {
140             stringValue.removeValueWatcher(this);
141         }
142         stringValue = sv;
143         if (stringValue == null) {
144             dTextArea.setEnabled(false);
145         } else {
146             dTextArea.setText(stringValue.getString());
147             stringValue.addValueWatcher(this);
148             if (autoResize) {
149                 dTextArea.resizeUpToText();
150             }
151         }
152     }
153 
154 
155     public void textChanged(String s) {
156         stringValue.reportableSetString(dTextArea.getText(), this);
157         // valueChange(dTextArea.getText()); // ever called?
158 
159         // could cause too much line counting?
160         if (autoResize) {
161 
162             //  E.info("auto resizing text are ");
163 
164             dTextArea.resizeUpToText();
165         }
166     }
167 
168     public void textEntered(String s) {
169         E.info("text entered");
170     }
171 
172     public void textEdited(String s) {
173         // E.info("text edited");
174     }
175 
176 
177 
178     public void setBg(Color c) {
179         rtPanel.setBg(c);
180         rbPanel.setBg(c);
181         upButton.setBg(c);
182         downButton.setBg(c);
183         //      dTextArea.setBg(Color.white);
184         super.setBg(c);
185     }
186 
187     public void setTextBg(int icol) {
188         Color c = new Color(icol);
189         dTextArea.setBg(c);
190     }
191 
192     public void setLineBorder(int icol) {
193         dTextArea.setLineBorder(icol);
194     }
195 
196     public void able(boolean b) {
197         dTextArea.setEnabled(b);
198     }
199 
200 
201     public void setEditable(boolean b) {
202         dTextArea.setEditable(b);
203         dTextArea.setEnabled(b);
204     }
205 
206 
207     public void setAntialiased() {
208         dTextArea.setAntialiased();
209     }
210 
211     public void setPadding(int padding) {
212         dTextArea.setPadding(padding);
213 
214     }
215 
216     public void setFontSize(int fs) {
217         dTextArea.setFontSize(fs);
218     }
219 
220 
221     public void setAutoResize(boolean b) {
222         autoResize = b;
223 
224     }
225 
226 
227     public void focusGained() {
228         // TODO Auto-generated method stub
229 
230     }
231 
232 
233     public void focusLost() {
234         // TODO Auto-generated method stub
235 
236     }
237 
238 
239 
240 }