blob: 9d7d119b0268457c0cd8820479e3462a07daa899 (
plain)
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
|
package com.itmill.toolkit.ui;
import java.util.Iterator;
import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget;
import com.itmill.toolkit.terminal.Sizeable;
/**
* TODO finish documentation
*
* our layouts (except custom layout of course) don't currently work at all with
* relative widths. This layout tries to cope with this issue.
*
* basically this is ordered layout which has Sizeable interface 100 % height &
* width by default
*
* all contained components may also have Sizeable interfaces sizes
*
* can be used to build flexible layout where some component gets all the space
* other components don't use. Or just provide expanded container.
*
*/
public class ExpandLayout extends OrderedLayout {
private Component expanded;
public ExpandLayout() {
setSizeFull();
}
public ExpandLayout(int orientation) {
this();
setOrientation(orientation);
}
/**
* @param c
* Component which container will be maximized
*/
public void expand(Component c) {
expanded = c;
requestRepaint();
}
public String getTag() {
return "expandlayout";
}
public void paintContent(PaintTarget target) throws PaintException {
// Add margin info. Defaults to false.
target.addAttribute("margins", margins.getBitMask());
// Add spacing attribute (omitted if false)
if (isSpacingEnabled()) {
target.addAttribute("spacing", true);
}
// Size
if (getHeight() >= 0) {
target.addAttribute("height", "" + getHeight()
+ Sizeable.UNIT_SYMBOLS[getHeightUnits()]);
}
if (getWidth() >= 0) {
target.addAttribute("width", "" + getWidth()
+ Sizeable.UNIT_SYMBOLS[getWidthUnits()]);
}
// Adds the attributes: orientation
// note that the default values (b/vertival) are omitted
if (getOrientation() == ORIENTATION_HORIZONTAL) {
target.addAttribute("orientation", "horizontal");
}
String[] alignmentsArray = new String[components.size()];
// Adds all items in all the locations
int index = 0;
for (Iterator i = getComponentIterator(); i.hasNext();) {
Component c = (Component) i.next();
if (c != null) {
target.startTag("cc");
if (c == expanded) {
target.addAttribute("expanded", true);
}
c.paint(target);
target.endTag("cc");
}
alignmentsArray[index++] = String.valueOf(getComponentAlignment(c));
}
// Add child component alignment info to layout tag
target.addAttribute("alignments", alignmentsArray);
}
public void addComponent(Component c, int index) {
if (expanded == null) {
expanded = c;
}
super.addComponent(c, index);
}
public void addComponent(Component c) {
if (expanded == null) {
expanded = c;
}
super.addComponent(c);
}
public void addComponentAsFirst(Component c) {
if (expanded == null) {
expanded = c;
}
super.addComponentAsFirst(c);
}
public void removeComponent(Component c) {
super.removeComponent(c);
if (c == expanded && getComponentIterator().hasNext()) {
expanded = (Component) getComponentIterator().next();
} else {
expanded = null;
}
}
public void replaceComponent(Component oldComponent, Component newComponent) {
super.replaceComponent(oldComponent, newComponent);
if (oldComponent == expanded) {
expanded = newComponent;
}
}
}
|