profligacy 0.2-jruby → 0.3-jruby

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. data/Rakefile +6 -4
  2. data/doc/rdoc/classes/Proc.src/M000001.html +4 -4
  3. data/doc/rdoc/classes/Proc.src/M000002.html +4 -4
  4. data/doc/rdoc/classes/Profligacy/LELGroupLayout.html +296 -0
  5. data/doc/rdoc/classes/Profligacy/LELGroupLayout.src/M000014.html +28 -0
  6. data/doc/rdoc/classes/Profligacy/LELGroupLayout.src/M000015.html +18 -0
  7. data/doc/rdoc/classes/Profligacy/LELGroupLayout.src/M000016.html +19 -0
  8. data/doc/rdoc/classes/Profligacy/LELGroupLayout.src/M000017.html +23 -0
  9. data/doc/rdoc/classes/Profligacy/LELGroupLayout.src/M000018.html +27 -0
  10. data/doc/rdoc/classes/Profligacy/LELGroupLayout.src/M000019.html +19 -0
  11. data/doc/rdoc/classes/Profligacy/LELGroupLayout.src/M000020.html +23 -0
  12. data/doc/rdoc/classes/Profligacy/LELGroupLayout.src/M000021.html +18 -0
  13. data/doc/rdoc/classes/Profligacy/LELGroupLayout.src/M000022.html +18 -0
  14. data/doc/rdoc/classes/Profligacy/LELGroupLayout.src/M000023.html +18 -0
  15. data/doc/rdoc/classes/Profligacy/LELGroupLayout.src/M000024.html +21 -0
  16. data/doc/rdoc/classes/Profligacy/LELNameScanner.html +189 -0
  17. data/doc/rdoc/classes/Profligacy/LELNameScanner.src/M000025.html +18 -0
  18. data/doc/rdoc/classes/Profligacy/LELNameScanner.src/M000026.html +18 -0
  19. data/doc/rdoc/classes/Profligacy/LELNameScanner.src/M000027.html +18 -0
  20. data/doc/rdoc/classes/Profligacy/Swing/Build.html +30 -0
  21. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000003.html +3 -6
  22. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000004.html +4 -4
  23. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000005.html +25 -31
  24. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000006.html +4 -4
  25. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000007.html +8 -8
  26. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000008.html +21 -0
  27. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000009.html +24 -0
  28. data/doc/rdoc/classes/Profligacy/Swing/LEL.html +169 -0
  29. data/doc/rdoc/classes/Profligacy/Swing/LEL.src/M000010.html +33 -0
  30. data/doc/rdoc/classes/Profligacy/Swing/LEL.src/M000011.html +36 -0
  31. data/doc/rdoc/classes/Profligacy/Swing/RunnableProc.html +10 -10
  32. data/doc/rdoc/classes/Profligacy/Swing/RunnableProc.src/{M000008.html → M000012.html} +0 -0
  33. data/doc/rdoc/classes/Profligacy/Swing/RunnableProc.src/{M000009.html → M000013.html} +0 -0
  34. data/doc/rdoc/classes/Profligacy/Swing.html +5 -0
  35. data/doc/rdoc/classes/Profligacy.html +6 -0
  36. data/doc/rdoc/created.rid +1 -1
  37. data/doc/rdoc/files/lib/profligacy/lel_rb.html +101 -0
  38. data/doc/rdoc/files/lib/profligacy/swing_rb.html +1 -1
  39. data/doc/rdoc/fr_class_index.html +3 -0
  40. data/doc/rdoc/fr_file_index.html +1 -0
  41. data/doc/rdoc/fr_method_index.html +20 -2
  42. data/examples/layout_test.rb +25 -0
  43. data/examples/swing8_lel.rb +63 -0
  44. data/lib/profligacy/LELParser$LELEventListener.class +0 -0
  45. data/lib/profligacy/LELParser.class +0 -0
  46. data/lib/profligacy/LELParser.java +342 -0
  47. data/lib/profligacy/LELParser.rl +84 -0
  48. data/lib/profligacy/lel.rb +199 -0
  49. data/lib/profligacy/swing.rb +18 -11
  50. metadata +38 -6
@@ -0,0 +1,342 @@
1
+ // line 1 "lib/profligacy/LELParser.rl"
2
+ package profligacy;
3
+
4
+ import java.io.IOException;
5
+ import javax.swing.*;
6
+
7
+ public class LELParser {
8
+
9
+ public interface LELEventListener {
10
+ public void col();
11
+ public void ltab();
12
+ public void valign(String dir);
13
+ public void id(String name);
14
+ public void row();
15
+ public void align(String dir);
16
+ public void setwidth(int width);
17
+ public void setheight(int height);
18
+ public void finished(boolean error);
19
+ public void expand();
20
+ }
21
+
22
+ // line 49 "lib/profligacy/LELParser.rl"
23
+
24
+
25
+
26
+ // line 27 "lib/profligacy/LELParser.java"
27
+ private static void init__LayoutExpressionLanguage_actions_0( byte[] r )
28
+ {
29
+ r[0]=0; r[1]=1; r[2]=2; r[3]=1; r[4]=3; r[5]=1; r[6]=6; r[7]=1;
30
+ r[8]=9; r[9]=1; r[10]=10; r[11]=1; r[12]=11; r[13]=2; r[14]=0; r[15]=7;
31
+ r[16]=2; r[17]=0; r[18]=8; r[19]=2; r[20]=4; r[21]=1; r[22]=2; r[23]=4;
32
+ r[24]=5;
33
+ }
34
+
35
+ private static byte[] create__LayoutExpressionLanguage_actions( )
36
+ {
37
+ byte[] r = new byte[25];
38
+ init__LayoutExpressionLanguage_actions_0( r );
39
+ return r;
40
+ }
41
+
42
+ private static final byte _LayoutExpressionLanguage_actions[] = create__LayoutExpressionLanguage_actions();
43
+
44
+
45
+ private static void init__LayoutExpressionLanguage_key_offsets_0( byte[] r )
46
+ {
47
+ r[0]=0; r[1]=0; r[2]=4; r[3]=15; r[4]=17; r[5]=21; r[6]=23; r[7]=26;
48
+ r[8]=35;
49
+ }
50
+
51
+ private static byte[] create__LayoutExpressionLanguage_key_offsets( )
52
+ {
53
+ byte[] r = new byte[9];
54
+ init__LayoutExpressionLanguage_key_offsets_0( r );
55
+ return r;
56
+ }
57
+
58
+ private static final byte _LayoutExpressionLanguage_key_offsets[] = create__LayoutExpressionLanguage_key_offsets();
59
+
60
+
61
+ private static void init__LayoutExpressionLanguage_trans_keys_0( char[] r )
62
+ {
63
+ r[0]=32; r[1]=91; r[2]=9; r[3]=13; r[4]=40; r[5]=42; r[6]=46; r[7]=60;
64
+ r[8]=62; r[9]=94; r[10]=95; r[11]=65; r[12]=90; r[13]=97; r[14]=122; r[15]=48;
65
+ r[16]=57; r[17]=41; r[18]=44; r[19]=48; r[20]=57; r[21]=48; r[22]=57; r[23]=41;
66
+ r[24]=48; r[25]=57; r[26]=93; r[27]=95; r[28]=124; r[29]=48; r[30]=57; r[31]=65;
67
+ r[32]=90; r[33]=97; r[34]=122; r[35]=32; r[36]=91; r[37]=9; r[38]=13; r[39]=0;
68
+ }
69
+
70
+ private static char[] create__LayoutExpressionLanguage_trans_keys( )
71
+ {
72
+ char[] r = new char[40];
73
+ init__LayoutExpressionLanguage_trans_keys_0( r );
74
+ return r;
75
+ }
76
+
77
+ private static final char _LayoutExpressionLanguage_trans_keys[] = create__LayoutExpressionLanguage_trans_keys();
78
+
79
+
80
+ private static void init__LayoutExpressionLanguage_single_lengths_0( byte[] r )
81
+ {
82
+ r[0]=0; r[1]=2; r[2]=7; r[3]=0; r[4]=2; r[5]=0; r[6]=1; r[7]=3;
83
+ r[8]=2;
84
+ }
85
+
86
+ private static byte[] create__LayoutExpressionLanguage_single_lengths( )
87
+ {
88
+ byte[] r = new byte[9];
89
+ init__LayoutExpressionLanguage_single_lengths_0( r );
90
+ return r;
91
+ }
92
+
93
+ private static final byte _LayoutExpressionLanguage_single_lengths[] = create__LayoutExpressionLanguage_single_lengths();
94
+
95
+
96
+ private static void init__LayoutExpressionLanguage_range_lengths_0( byte[] r )
97
+ {
98
+ r[0]=0; r[1]=1; r[2]=2; r[3]=1; r[4]=1; r[5]=1; r[6]=1; r[7]=3;
99
+ r[8]=1;
100
+ }
101
+
102
+ private static byte[] create__LayoutExpressionLanguage_range_lengths( )
103
+ {
104
+ byte[] r = new byte[9];
105
+ init__LayoutExpressionLanguage_range_lengths_0( r );
106
+ return r;
107
+ }
108
+
109
+ private static final byte _LayoutExpressionLanguage_range_lengths[] = create__LayoutExpressionLanguage_range_lengths();
110
+
111
+
112
+ private static void init__LayoutExpressionLanguage_index_offsets_0( byte[] r )
113
+ {
114
+ r[0]=0; r[1]=0; r[2]=4; r[3]=14; r[4]=16; r[5]=20; r[6]=22; r[7]=25;
115
+ r[8]=32;
116
+ }
117
+
118
+ private static byte[] create__LayoutExpressionLanguage_index_offsets( )
119
+ {
120
+ byte[] r = new byte[9];
121
+ init__LayoutExpressionLanguage_index_offsets_0( r );
122
+ return r;
123
+ }
124
+
125
+ private static final byte _LayoutExpressionLanguage_index_offsets[] = create__LayoutExpressionLanguage_index_offsets();
126
+
127
+
128
+ private static void init__LayoutExpressionLanguage_trans_targs_wi_0( byte[] r )
129
+ {
130
+ r[0]=1; r[1]=2; r[2]=1; r[3]=0; r[4]=3; r[5]=2; r[6]=2; r[7]=2;
131
+ r[8]=2; r[9]=2; r[10]=7; r[11]=7; r[12]=7; r[13]=0; r[14]=4; r[15]=0;
132
+ r[16]=2; r[17]=5; r[18]=4; r[19]=0; r[20]=6; r[21]=0; r[22]=2; r[23]=6;
133
+ r[24]=0; r[25]=8; r[26]=7; r[27]=2; r[28]=7; r[29]=7; r[30]=7; r[31]=0;
134
+ r[32]=8; r[33]=2; r[34]=8; r[35]=0; r[36]=0;
135
+ }
136
+
137
+ private static byte[] create__LayoutExpressionLanguage_trans_targs_wi( )
138
+ {
139
+ byte[] r = new byte[37];
140
+ init__LayoutExpressionLanguage_trans_targs_wi_0( r );
141
+ return r;
142
+ }
143
+
144
+ private static final byte _LayoutExpressionLanguage_trans_targs_wi[] = create__LayoutExpressionLanguage_trans_targs_wi();
145
+
146
+
147
+ private static void init__LayoutExpressionLanguage_trans_actions_wi_0( byte[] r )
148
+ {
149
+ r[0]=0; r[1]=1; r[2]=0; r[3]=0; r[4]=0; r[5]=7; r[6]=3; r[7]=5;
150
+ r[8]=5; r[9]=3; r[10]=11; r[11]=11; r[12]=11; r[13]=0; r[14]=9; r[15]=0;
151
+ r[16]=13; r[17]=13; r[18]=0; r[19]=0; r[20]=9; r[21]=0; r[22]=16; r[23]=0;
152
+ r[24]=0; r[25]=22; r[26]=0; r[27]=19; r[28]=0; r[29]=0; r[30]=0; r[31]=0;
153
+ r[32]=0; r[33]=1; r[34]=0; r[35]=0; r[36]=0;
154
+ }
155
+
156
+ private static byte[] create__LayoutExpressionLanguage_trans_actions_wi( )
157
+ {
158
+ byte[] r = new byte[37];
159
+ init__LayoutExpressionLanguage_trans_actions_wi_0( r );
160
+ return r;
161
+ }
162
+
163
+ private static final byte _LayoutExpressionLanguage_trans_actions_wi[] = create__LayoutExpressionLanguage_trans_actions_wi();
164
+
165
+
166
+ static final int LayoutExpressionLanguage_start = 1;
167
+ static final int LayoutExpressionLanguage_error = 0;
168
+
169
+ static final int LayoutExpressionLanguage_en_main = 1;
170
+
171
+ // line 52 "lib/profligacy/LELParser.rl"
172
+
173
+ public int cs, p = 0, pe = 0;
174
+
175
+ public boolean scan(String input, LELEventListener listener) {
176
+ int tk_start = 0;
177
+ p = 0;
178
+ String tk = null;
179
+
180
+
181
+ // line 182 "lib/profligacy/LELParser.java"
182
+ {
183
+ cs = LayoutExpressionLanguage_start;
184
+ }
185
+ // line 61 "lib/profligacy/LELParser.rl"
186
+
187
+ pe = input.length();
188
+ char data[] = input.toCharArray();
189
+
190
+
191
+ // line 192 "lib/profligacy/LELParser.java"
192
+ {
193
+ int _klen;
194
+ int _trans;
195
+ int _acts;
196
+ int _nacts;
197
+ int _keys;
198
+
199
+ if ( p != pe ) {
200
+ if ( cs != 0 ) {
201
+ _resume: while ( true ) {
202
+ _again: do {
203
+ _match: do {
204
+ _keys = _LayoutExpressionLanguage_key_offsets[cs];
205
+ _trans = _LayoutExpressionLanguage_index_offsets[cs];
206
+ _klen = _LayoutExpressionLanguage_single_lengths[cs];
207
+ if ( _klen > 0 ) {
208
+ int _lower = _keys;
209
+ int _mid;
210
+ int _upper = _keys + _klen - 1;
211
+ while (true) {
212
+ if ( _upper < _lower )
213
+ break;
214
+
215
+ _mid = _lower + ((_upper-_lower) >> 1);
216
+ if ( data[p] < _LayoutExpressionLanguage_trans_keys[_mid] )
217
+ _upper = _mid - 1;
218
+ else if ( data[p] > _LayoutExpressionLanguage_trans_keys[_mid] )
219
+ _lower = _mid + 1;
220
+ else {
221
+ _trans += (_mid - _keys);
222
+ break _match;
223
+ }
224
+ }
225
+ _keys += _klen;
226
+ _trans += _klen;
227
+ }
228
+
229
+ _klen = _LayoutExpressionLanguage_range_lengths[cs];
230
+ if ( _klen > 0 ) {
231
+ int _lower = _keys;
232
+ int _mid;
233
+ int _upper = _keys + (_klen<<1) - 2;
234
+ while (true) {
235
+ if ( _upper < _lower )
236
+ break;
237
+
238
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
239
+ if ( data[p] < _LayoutExpressionLanguage_trans_keys[_mid] )
240
+ _upper = _mid - 2;
241
+ else if ( data[p] > _LayoutExpressionLanguage_trans_keys[_mid+1] )
242
+ _lower = _mid + 2;
243
+ else {
244
+ _trans += ((_mid - _keys)>>1);
245
+ break _match;
246
+ }
247
+ }
248
+ _trans += _klen;
249
+ }
250
+ } while (false);
251
+
252
+ cs = _LayoutExpressionLanguage_trans_targs_wi[_trans];
253
+
254
+ if ( _LayoutExpressionLanguage_trans_actions_wi[_trans] == 0 )
255
+ break _again;
256
+
257
+ _acts = _LayoutExpressionLanguage_trans_actions_wi[_trans];
258
+ _nacts = (int) _LayoutExpressionLanguage_actions[_acts++];
259
+ while ( _nacts-- > 0 )
260
+ {
261
+ switch ( _LayoutExpressionLanguage_actions[_acts++] )
262
+ {
263
+ case 0:
264
+ // line 25 "lib/profligacy/LELParser.rl"
265
+ { tk = input.substring(tk_start, p); }
266
+ break;
267
+ case 1:
268
+ // line 26 "lib/profligacy/LELParser.rl"
269
+ { listener.col(); }
270
+ break;
271
+ case 2:
272
+ // line 27 "lib/profligacy/LELParser.rl"
273
+ { listener.ltab(); }
274
+ break;
275
+ case 3:
276
+ // line 28 "lib/profligacy/LELParser.rl"
277
+ { listener.valign(input.substring(p,p+1)); }
278
+ break;
279
+ case 4:
280
+ // line 29 "lib/profligacy/LELParser.rl"
281
+ { listener.id(input.substring(tk_start, p)); }
282
+ break;
283
+ case 5:
284
+ // line 30 "lib/profligacy/LELParser.rl"
285
+ { listener.row(); }
286
+ break;
287
+ case 6:
288
+ // line 31 "lib/profligacy/LELParser.rl"
289
+ { listener.align(input.substring(p, p+1)); }
290
+ break;
291
+ case 7:
292
+ // line 32 "lib/profligacy/LELParser.rl"
293
+ { listener.setwidth(Integer.parseInt(tk)); }
294
+ break;
295
+ case 8:
296
+ // line 33 "lib/profligacy/LELParser.rl"
297
+ { listener.setheight(Integer.parseInt(tk)); }
298
+ break;
299
+ case 9:
300
+ // line 34 "lib/profligacy/LELParser.rl"
301
+ { listener.expand(); }
302
+ break;
303
+ case 10:
304
+ // line 42 "lib/profligacy/LELParser.rl"
305
+ { tk_start = p; }
306
+ break;
307
+ case 11:
308
+ // line 45 "lib/profligacy/LELParser.rl"
309
+ {tk_start = p;}
310
+ break;
311
+ // line 312 "lib/profligacy/LELParser.java"
312
+ }
313
+ }
314
+
315
+ } while (false);
316
+ if ( cs == 0 )
317
+ break _resume;
318
+ if ( ++p == pe )
319
+ break _resume;
320
+ }
321
+ } }
322
+ }
323
+ // line 66 "lib/profligacy/LELParser.rl"
324
+
325
+
326
+ listener.finished(isInErrorState());
327
+
328
+ if(isInErrorState()) {
329
+ return false;
330
+ } else {
331
+ return true;
332
+ }
333
+ }
334
+
335
+ public boolean isInErrorState() {
336
+ return cs == LayoutExpressionLanguage_error;
337
+ }
338
+
339
+ public int getPosition() {
340
+ return p;
341
+ }
342
+ }
@@ -0,0 +1,84 @@
1
+ package profligacy;
2
+
3
+ import java.io.IOException;
4
+ import javax.swing.*;
5
+
6
+ public class LELParser {
7
+
8
+ public interface LELEventListener {
9
+ public void col();
10
+ public void ltab();
11
+ public void valign(String dir);
12
+ public void id(String name);
13
+ public void row();
14
+ public void align(String dir);
15
+ public void setwidth(int width);
16
+ public void setheight(int height);
17
+ public void finished(boolean error);
18
+ public void expand();
19
+ }
20
+
21
+ %%{
22
+ machine LayoutExpressionLanguage;
23
+ alphtype char;
24
+
25
+ action token { tk = input.substring(tk_start, fpc); }
26
+ action col { listener.col(); }
27
+ action ltab { listener.ltab(); }
28
+ action valign { listener.valign(input.substring(fpc,fpc+1)); }
29
+ action id { listener.id(input.substring(tk_start, fpc)); }
30
+ action row { listener.row(); }
31
+ action align { listener.align(input.substring(fpc, fpc+1)); }
32
+ action setwidth { listener.setwidth(Integer.parseInt(tk)); }
33
+ action setheight { listener.setheight(Integer.parseInt(tk)); }
34
+ action expand { listener.expand(); }
35
+
36
+ col = "|" $col;
37
+ ltab = "[" $ltab;
38
+ rtab = "]" $row;
39
+ valign = ("^" | ".") $valign;
40
+ expand = "*" $expand;
41
+ halign = ("<" | ">") $align;
42
+ number = digit+ >{ tk_start = fpc; } %token;
43
+ setw = ("(" number %setwidth ("," number %setheight)? ")") ;
44
+ modifiers = (expand | valign | halign | setw);
45
+ id = modifiers* ((alpha | '_')+ :>> (alnum | '_')*) >{tk_start = fpc;} %id;
46
+ row = space* ltab id (col id)* rtab space*;
47
+
48
+ main := row+;
49
+ }%%
50
+
51
+ %% write data nofinal;
52
+
53
+ public int cs, p = 0, pe = 0;
54
+
55
+ public boolean scan(String input, LELEventListener listener) {
56
+ int tk_start = 0;
57
+ p = 0;
58
+ String tk = null;
59
+
60
+ %% write init;
61
+
62
+ pe = input.length();
63
+ char data[] = input.toCharArray();
64
+
65
+ %% write exec;
66
+
67
+
68
+ listener.finished(isInErrorState());
69
+
70
+ if(isInErrorState()) {
71
+ return false;
72
+ } else {
73
+ return true;
74
+ }
75
+ }
76
+
77
+ public boolean isInErrorState() {
78
+ return cs == LayoutExpressionLanguage_error;
79
+ }
80
+
81
+ public int getPosition() {
82
+ return p;
83
+ }
84
+ }
@@ -0,0 +1,199 @@
1
+
2
+ module Profligacy
3
+ include_package 'profligacy'
4
+
5
+ class LELNameScanner
6
+ include Profligacy::LELParser::LELEventListener
7
+ attr_reader :children
8
+
9
+ def initialize
10
+ @children = []
11
+ end
12
+
13
+ def id(name)
14
+ @children << name.to_sym
15
+ end
16
+
17
+ def method_missing(symb, *args)
18
+ #ignored
19
+ end
20
+ end
21
+
22
+ class LELGroupLayout
23
+ include Profligacy::LELParser::LELEventListener
24
+
25
+ include_class 'javax.swing.GroupLayout'
26
+ include_class 'javax.swing.JPanel'
27
+ include_class 'java.lang.Short'
28
+
29
+ def initialize(layout, components)
30
+ @layout = layout
31
+ @hgroup = @layout.createSequentialGroup
32
+ @vgroup = @layout.createSequentialGroup
33
+ @vertical = nil
34
+ @horizontals = []
35
+ @components = components
36
+
37
+ alignments_reset
38
+ widths_reset
39
+ heights_reset
40
+ horizontals_reset
41
+ end
42
+
43
+ def col
44
+ horizontals_push; alignments_reset ; widths_reset
45
+ end
46
+
47
+ def ltab
48
+ horizontals_reset
49
+ @vertical = @layout.createParallelGroup
50
+ end
51
+
52
+ def valign(dir)
53
+ case dir
54
+ when "^" then @valign = GroupLayout::Alignment::LEADING
55
+ when "." then @valign = GroupLayout::Alignment::TRAILING
56
+ else
57
+ raise "Invalid Vertical Alignment: #{dir}"
58
+ end
59
+ end
60
+
61
+ def id(name)
62
+ h = horizontals_cur
63
+ component = @components[name]
64
+
65
+ if component
66
+ # add it in
67
+ @vertical.addComponent(component, @valign, GroupLayout::DEFAULT_SIZE, @height, @max)
68
+ h.addComponent(component, @halign, GroupLayout::DEFAULT_SIZE, @width, @max)
69
+ elsif name != "_"
70
+ raise "Cell named '#{name}' does not have a component set during build."
71
+ end
72
+ end
73
+
74
+ def row
75
+ @vgroup.addGroup(@vertical);
76
+ alignments_reset ; widths_reset ; heights_reset
77
+ end
78
+
79
+ def align(direction)
80
+ case direction
81
+ when "<" then @halign = GroupLayout::Alignment::LEADING
82
+ when ">" then @halign = GroupLayout::Alignment::TRAILING
83
+ else
84
+ raise "Invalid Horizontal Alignment: #{direction}"
85
+ end
86
+ end
87
+
88
+ def setwidth(width)
89
+ @width = width
90
+ end
91
+
92
+ def setheight(height)
93
+ @height = height
94
+ end
95
+
96
+ def expand
97
+ @max = Short::MAX_VALUE
98
+ end
99
+
100
+ def finished(error)
101
+ if !error
102
+ @layout.setHorizontalGroup(@hgroup);
103
+ @layout.setVerticalGroup(@vgroup);
104
+ end
105
+ end
106
+
107
+ private
108
+
109
+ def alignments_reset
110
+ @valign = GroupLayout::Alignment::CENTER
111
+ @halign = GroupLayout::Alignment::CENTER
112
+ end
113
+
114
+ def widths_reset
115
+ @width = GroupLayout::DEFAULT_SIZE
116
+ @max = GroupLayout::DEFAULT_SIZE
117
+ end
118
+
119
+ def heights_reset
120
+ @height = GroupLayout::DEFAULT_SIZE
121
+ end
122
+
123
+ def horizontals_reset
124
+ @htop = 0
125
+ end
126
+
127
+ def horizontals_push
128
+ @htop += 1
129
+ end
130
+
131
+ def horizontals_cur
132
+ if !@horizontals[@htop]
133
+ @horizontals[@htop] = @layout.createParallelGroup(@valign)
134
+ @hgroup.addGroup(@horizontals[@htop])
135
+ end
136
+
137
+ @horizontals[@htop]
138
+ end
139
+
140
+ end
141
+
142
+
143
+ module Swing
144
+ class LEL < Build
145
+ include_class 'javax.swing.GroupLayout'
146
+ attr_reader :prefs
147
+
148
+ def initialize(type, expr)
149
+
150
+ @expr = expr
151
+ @container_class = type
152
+ @parser = LELParser.new
153
+ names = LELNameScanner.new
154
+ @prefs = {
155
+ :auto_create_gaps => true,
156
+ :auto_create_container_gaps => true,
157
+ :honors_visibility => true,
158
+ :pack => true,
159
+ :visible => true,
160
+ :args => []
161
+ }
162
+ parse(names)
163
+ setup_children_and_interactions(names.children)
164
+ yield @contents, @interactions
165
+ end
166
+
167
+ def build(prefs={})
168
+ prefs = @prefs.merge prefs
169
+
170
+ @container = @container_class.new(*(prefs[:args]))
171
+ pane = @container.respond_to?(:content_pane) ? @container.content_pane : @container
172
+ layout = GroupLayout.new pane
173
+ @container.layout = layout
174
+ layout.auto_create_gaps = prefs[:auto_create_gaps]
175
+ layout.auto_create_container_gaps = prefs[:auto_create_container_gaps]
176
+ layout.honors_visibility = prefs[:honors_visibility]
177
+
178
+ parse(LELGroupLayout.new(layout, @contents))
179
+
180
+ @children.each {|child|
181
+ configure_interactions_for(child,@contents[child]) if @contents[child]
182
+ }
183
+
184
+ @container.pack if (prefs[:pack] && @container.respond_to?(:pack))
185
+ @container.visible = prefs[:visible] if @container.respond_to? :visible
186
+ @container
187
+ end
188
+
189
+ private
190
+
191
+ def parse(listener)
192
+ if !@parser.scan(@expr, listener)
193
+ raise "LEL parsing error at #{@parser.position} from: '#{@expr[@parser.position-1 .. @parser.position + 30]}' ..."
194
+ end
195
+ end
196
+ end
197
+
198
+ end
199
+ end
@@ -65,10 +65,7 @@ module Profligacy
65
65
 
66
66
  def initialize(*children)
67
67
  @container_class = children.shift
68
- @children = children
69
- @klass = Struct.new *@children
70
- @contents = @klass.new
71
- @interactions = @klass.new
68
+ setup_children_and_interactions(children)
72
69
  yield @contents, @interactions
73
70
  end
74
71
 
@@ -89,13 +86,7 @@ module Profligacy
89
86
  component = @contents[child]
90
87
  each_or_one(component) {|c| @container.add(c) }
91
88
 
92
- actions = @interactions[child]
93
- # now we tack on the callback
94
- actions.each { |type, callback|
95
- each_or_one(component) do |c|
96
- c.send("add_#{type}_listener", callback.to_proc.to_listener(type))
97
- end
98
- } if actions
89
+ configure_interactions_for child, component
99
90
  end
100
91
  }
101
92
 
@@ -123,6 +114,22 @@ module Profligacy
123
114
  end
124
115
  end
125
116
 
117
+ def setup_children_and_interactions(children)
118
+ @children = children
119
+ @klass = Struct.new *@children
120
+ @contents = @klass.new
121
+ @interactions = @klass.new
122
+ end
123
+
124
+ def configure_interactions_for(child,component)
125
+ actions = @interactions[child]
126
+ # now we tack on the callback
127
+ actions.each { |type, callback|
128
+ each_or_one(component) do |c|
129
+ c.send("add_#{type}_listener", callback.to_proc.to_listener(type))
130
+ end
131
+ } if actions
132
+ end
126
133
  end
127
134
  end
128
135
  end