1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
|
/* *************************************************************************
IT Mill Toolkit
Development of Browser User Interfaces Made Easy
Copyright (C) 2000-2006 IT Mill Ltd
*************************************************************************
This product is distributed under commercial license that can be found
from the product package on license.pdf. Use of this product might
require purchasing a commercial license from IT Mill Ltd. For guidelines
on usage, see licensing-guidelines.html
*************************************************************************
For more information, contact:
IT Mill Ltd phone: +358 2 4802 7180
Ruukinkatu 2-4 fax: +358 2 4802 7181
20540, Turku email: info@itmill.com
Finland company www: www.itmill.com
Primary source for information and releases: www.itmill.com
********************************************************************** */
package com.itmill.toolkit.ui;
import java.net.URL;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import com.itmill.toolkit.Application;
import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget;
import com.itmill.toolkit.terminal.Resource;
/**
* <p>
* An application frame window component. This component implements a window
* that contains a hierarchical set of frames. Each frame can contain a
* web-page, window or a set of frames that divides the space horizontally or
* vertically.
* </p>
*
* <p>
* A <code>FrameWindow</code> can't contain any components directly (as it
* contains only a set of frames) and thus the container interface methods do
* nothing.
* </p>
*
* @author IT Mill Ltd.
* @version
* @VERSION@
* @deprecated
* @since 3.0
*/
public class FrameWindow extends Window {
private Frameset frameset = new Frameset();
/**
* Constructs a new frame window.
*/
public FrameWindow() {
}
/**
* Constructs a new frame window.
*
* @param caption
* th etitle of the window.
*/
public FrameWindow(String caption) {
super(caption);
}
/**
* Gets the window's UIDL tag.
*
* @return the window's UIDL tag as <code>String</code>.
*/
public String getTag() {
return "framewindow";
}
/**
* Gets the main frameset of the window. This set contains all the top-level
* frames of the window. New contents are added by adding frames to this
* frameset.
*
* @return the top-level frame set of this frame window.
*/
public Frameset getFrameset() {
return frameset;
}
/**
* Paints the window contents.
*
* @param target
* the paint target event.
* @throws PaintException
* if the paint operation fails.
*
* @see com.itmill.toolkit.ui.AbstractComponent#paintContent(PaintTarget)
*/
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
// Paint frameset
getFrameset().paint(target);
}
/**
* An individual frame that contains either a window or the contents of the
* url set to frame.
*
* <p>
* The frames can be only created to framesets using the
* <code>newFrame</code> method of the frameset.
* </p>
*/
public class Frame {
/**
* URL of the frame contents.
*/
private URL url;
/**
* Name of the frame.
*/
private String name;
/**
* Window connected to frame or null.
*/
private Window window;
/**
* Window connected to frame or null.
*/
private Resource resource;
/**
* String representation of the width.
*/
private String width = "*";
/**
* Parent frameset.
*/
protected Frameset parentFrameset;
/**
* Gets the URL of the frame.
*
* @return the URl.
*/
public URL getURL() {
return window == null ? url : window.getURL();
}
/**
* Gets the parent frameset.
*
* @return the parent frameset.
*/
public Frameset getParentFrameset() {
return parentFrameset;
}
/**
* Gets the Name of the frame.
*
* @return the Name.
*/
public String getName() {
return window == null ? name : window.getName();
}
/**
* Gets the Window connected to frame.
*
* @return the window.
*/
public Window getWindow() {
return window;
}
/**
* Gets the Resource connected to frame.
*
* @return the resource.
*/
public Resource getResource() {
return resource;
}
/**
* Sets the Absolute width/height of the frame in pixels.
*
* @param widthInPixel
* the width in Pixel.
*/
public void setAbsoluteSize(int widthInPixels) {
width = String.valueOf(widthInPixels);
requestRepaint();
}
/**
* Sets the frame size to be freely specified by the terminal.
*/
public void setFreeSize() {
width = "*";
requestRepaint();
}
/**
* Sets the frame width/height as a percentage of the containing
* frameset size.
*
* @param widthInPercents
* the frame width in percent.
*/
public void setRelativeSize(int widthInPercents) {
if (widthInPercents < 0 || widthInPercents > 100)
throw new IllegalArgumentException("Relative width must "
+ "be between 0% and 100%");
width = String.valueOf(widthInPercents) + "%";
requestRepaint();
}
/**
* Paints the frame.
*
* @param target
* the paint target.
* @throws PaintException
* if the paint operation fails.
*/
private void paint(PaintTarget target) throws PaintException {
target.startTag("frame");
if (getResource() != null)
target.addAttribute("src", getResource());
else
target.addAttribute("src", getURL().toString());
target.addAttribute("name", getName());
target.endTag("frame");
}
}
/**
* Vertical or horizontal set of frames.
*/
public class Frameset extends Frame {
/**
* List of frames ordered from left to right or from top to bottom.
*/
private LinkedList frames = new LinkedList();
/**
* <code>true</code> if the frames are on top of each other. If
* <code>false</code> the frames are side by side.
*/
private boolean vertical = false;
/**
* Gets the list of frames.
*
* @return the unmodifiable list of frames.
*/
public List getFrames() {
return Collections.unmodifiableList(frames);
}
/**
* Creates the new frame containing a window.
*
* <p>
* The new frame will be in the end of the frames list.
* </p>
*
* @param window
* the window connected to the frame.
* @return the new Frame.
*/
public Frame newFrame(Window window) {
return newFrame(window, size());
}
/**
* Creates the new frame containing a window.
*
* <p>
* The new frame will be put before the frame identified by the given
* index. The indexes of the frame previously in the given position and
* all the positions after it are incremented by one.
* </p>
*
* @param window
* the window connected to the frame.
* @param index
* the given index.
*/
public Frame newFrame(Window window, int index) {
Frame f = new Frame();
f.window = window;
f.parentFrameset = this;
frames.add(index, f);
if (getApplication() != null)
getApplication().addWindow(window);
requestRepaint();
return f;
}
/**
* Creates the new frame containing a url.
*
* <p>
* The new frame will be put in the end of the frames list.
* </p>
*
* @param url
* the URL of the frame contents.
* @param name
* the Name of the frame.
* @return the new frame.
*/
public Frame newFrame(URL url, String name) {
return newFrame(url, name, size());
}
/**
* Creates the new frame containing a resource.
*
* <p>
* The new frame will be put in the end of the frames list.
* </p>
*
* @param resource
* the resource.
* @param name
* the Name of the frame.
* @return the new frame.
*/
public Frame newFrame(Resource resource, String name) {
return newFrame(resource, name, size());
}
/**
* Creates the new frame containing a url.
*
* <p>
* The new frame will be put before the frame identified by the given
* index. The indexes of the frame previously in the given position and
* all the positions after it are incremented by one.
* </p>
*
* @param url
* the URL of the frame contents.
* @param name
* the Name of the frame.
* @param index
* the given index.
* @return the new frame.
*/
public Frame newFrame(URL url, String name, int index) {
Frame f = new Frame();
f.url = url;
f.name = name;
f.parentFrameset = this;
frames.add(index, f);
requestRepaint();
return f;
}
/**
* Creates the new frame containing a resource.
*
* <p>
* The new frame will be put before the frame identified by the given
* index. The indexes of the frame previously in the given position and
* all the positions after it are incremented by one.
* </p>
*
* @param resource
* the resource.
* @param name
* the Name of the frame.
* @param index
* the given index.
* @return the new frame.
*/
public Frame newFrame(Resource resource, String name, int index) {
Frame f = new Frame();
f.resource = resource;
f.name = name;
f.parentFrameset = this;
frames.add(index, f);
requestRepaint();
return f;
}
/**
* Creates the new frameset.
*
* <p>
* The new frame will be put before the frame identified by the given
* index. The indexes of the frame previously in the given position and
* all the positions after it are incremented by one.
* </p>
*
* @param isVertical
* is the frames are on top of each other.
* @param index
* the given index.
* @return the new frameset.
*/
public Frameset newFrameset(boolean isVertical, int index) {
Frameset f = new Frameset();
f.setVertical(isVertical);
f.parentFrameset = this;
frames.add(index, f);
requestRepaint();
return f;
}
/**
* Removes the frame from this frameset.
*
* @param frame
* the frame to remove.
*/
public void removeFrame(Frame frame) {
frames.remove(frame);
frame.parentFrameset = null;
requestRepaint();
}
/**
* Removes all frames from this frameset.
*/
public void removeAllFrames() {
for (Iterator i = frames.iterator(); i.hasNext();)
((Frame) i.next()).parentFrameset = null;
frames.clear();
requestRepaint();
}
/**
* Number of frames in this frameset.
*
* @return the size.
*/
public int size() {
return frames.size();
}
/**
* Sets the framaset to be vertical.
*
* <p>
* By setting this true, the frames will be ordered on top of each other
* from top to bottom. Setting this false, the frames will be ordered
* side by side from left to right.
* </p>
*
* @param isVertical
* is the frames are on top of each other.
*/
public void setVertical(boolean isVertical) {
this.vertical = isVertical;
requestRepaint();
}
/**
* Checks if the frameset is vertical.
*
* <p>
* If this is true, the frames will be ordered on top of each other from
* top to bottom, otherwise the frames will be ordered side by side from
* left to right.
* </p>
*
* @return <code>true</code> if the frameset is Vertical, otherwise
* <code>false</code>.
*/
public boolean isVertical() {
return vertical;
}
/**
* Gets the frame by name.
*
* @param name
* the Name of the frame.
* @return the Frame having the given name or null if the frame is not
* found.
*/
public Frame getFrame(String name) {
if (name == null)
return null;
for (Iterator i = frames.iterator(); i.hasNext();) {
Frame f = (Frame) i.next();
if (name.equals(f.getName()))
return f;
}
return null;
}
/**
* Gets the frame by index.
*
* @param index
* the given index.
* @return the Frame having the given index or null if the frame is not
* found
*/
public Frame getFrame(int index) {
if (index >= 0 && index < frames.size())
return (Frame) frames.get(index);
return null;
}
/**
* Paints the frameset.
*
* @param target
* the Paint Target.
* @throws PaintException
* if the Paint operation fails.
*/
private void paint(PaintTarget target) throws PaintException {
target.startTag("frameset");
if (!frames.isEmpty()) {
StringBuffer widths = null;
for (Iterator i = frames.iterator(); i.hasNext();) {
Frame f = (Frame) i.next();
if (widths == null)
widths = new StringBuffer();
else
widths.append(',');
widths.append(f.width);
}
if (vertical)
target.addAttribute("rows", widths.toString());
else
target.addAttribute("cols", widths.toString());
for (Iterator i = frames.iterator(); i.hasNext();) {
Frame f = (Frame) i.next();
if (Frameset.class.isAssignableFrom(f.getClass()))
((Frameset) f).paint(target);
else
f.paint(target);
}
}
target.endTag("frameset");
}
/**
* Sets the application for all the frames in this frameset.
*
* @param fromApplication
* @param toApplication
*/
private void setApplication(Application fromApplication,
Application toApplication) {
for (Iterator i = frames.iterator(); i.hasNext();) {
Frame f = (Frame) i.next();
if (f instanceof Frameset)
((Frameset) f).setApplication(fromApplication,
toApplication);
else if (f.window != null) {
if (toApplication == null) {
fromApplication.removeWindow(f.window);
} else
toApplication.addWindow(f.window);
}
}
}
}
/**
* Setting the application for frame window also sets the application for
* all the frames.
*
* @see com.itmill.toolkit.ui.Window#setApplication(Application)
*/
public void setApplication(Application application) {
Application fromApplication = getApplication();
super.setApplication(application);
Frameset fs = getFrameset();
if (fs != null)
fs.setApplication(fromApplication, application);
}
/**
* Frame windows does not support scrolling.
*
* @return <code>true</code> if it is scrollable,otherwise
* <code>false</code>.
*/
public boolean isScrollable() {
return false;
}
/**
* Enables or disables scrolling.
*
* @see com.itmill.toolkit.terminal.Scrollable#setScrollable(boolean)
*/
public void setScrollable(boolean isScrollingEnabled) {
}
/**
* Sets the scroll X offset.
*
* @see com.itmill.toolkit.terminal.Scrollable#setScrollOffsetX(int)
*/
public void setScrollOffsetX(int pixelsScrolledLeft) {
}
/**
* Gets the scroll Y offset.
*
* @see com.itmill.toolkit.terminal.Scrollable#setScrollOffsetY(int)
*/
public void setScrollOffsetY(int pixelsScrolledDown) {
}
/**
* Frame window does not support adding components directly.
*
* <p>
* To add component to frame window, normal window must be first created and
* then attached to frame window as a frame.
* </p>
*
* @param c
* the component to be added.
* @see com.itmill.toolkit.ui.ComponentContainer#addComponent(Component)
*
*/
public void addComponent(Component c) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
}
|