1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.xulux.guilayer.swing.layouts;
17
18 import java.awt.Component;
19 import java.awt.Container;
20 import java.awt.Dimension;
21 import java.awt.FlowLayout;
22 import java.awt.LayoutManager;
23 import java.util.List;
24
25 import javax.swing.JComponent;
26
27 import org.xulux.api.gui.IWidget;
28 import org.xulux.gui.ContainerWidget;
29
30
31
32
33
34
35
36 public class SwingFlowLayout extends SwingLayoutAbstract implements
37 LayoutManager {
38
39 boolean widgetsRefreshed = false;
40
41 protected FlowLayout layout;
42
43 public SwingFlowLayout() {
44 }
45
46
47
48
49
50 public void addWidget(IWidget widget) {
51 }
52
53
54
55
56
57 public void removeWidget(IWidget widget) {
58
59 }
60
61
62
63
64 public void destroy() {
65
66 }
67
68
69
70
71 public void addLayoutComponent(String name, Component comp) {
72 }
73
74
75
76
77 public void removeLayoutComponent(Component comp) {
78 layout.removeLayoutComponent(comp);
79 }
80
81
82
83
84 public Dimension preferredLayoutSize(Container parent) {
85 if (!widgetsRefreshed) {
86 setWidgetsPreferredSize();
87 }
88 return layout.preferredLayoutSize(parent);
89 }
90
91
92
93
94 public void setWidgetsPreferredSize() {
95 if (widgetsRefreshed) {
96 return;
97 }
98 System.err.println("PARENt WIDGET : "+ getParent());
99 System.err.println("CHILDWIDGETS : " + getParent().getChildWidgets());
100
101 List list = getParent().getChildWidgets();
102 if (list != null && list.size() > 0) {
103 for (int j = 0; j < list.size(); j++) {
104 IWidget w = (IWidget) list.get(j);
105 if (w instanceof ContainerWidget) {
106 List childList = w.getChildWidgets();
107 if (childList == null) {
108 continue;
109 }
110 for (int i = 0; i < childList.size(); i++) {
111 IWidget w2 = (IWidget) childList.get(i);
112 Dimension dim = w2.getRectangle().getRectangle().getSize();
113 ((JComponent) w2.getNativeWidget()).setPreferredSize(dim);
114 }
115 } else if (w.getNativeWidget() instanceof JComponent) {
116 ((JComponent) w.getNativeWidget()).setPreferredSize(w.getRectangle()
117 .getRectangle().getSize());
118 }
119 }
120 }
121 widgetsRefreshed = true;
122 }
123
124
125
126
127 public Dimension minimumLayoutSize(Container parent) {
128 if (!widgetsRefreshed) {
129 setWidgetsPreferredSize();
130 }
131 return layout.minimumLayoutSize(parent);
132 }
133
134
135
136
137 public void layoutContainer(Container target) {
138 if (!widgetsRefreshed) {
139 setWidgetsPreferredSize();
140 }
141 layout.layoutContainer(target);
142 }
143
144
145
146
147
148
149 public void setParent(IWidget widget) {
150 super.setParent(widget);
151 if (layout == null) {
152 String alignment = getParent().getProperty("layout-alignment");
153
154 int align = FlowLayout.LEFT;
155 if ("right".equalsIgnoreCase(alignment)) {
156 align = FlowLayout.RIGHT;
157 } else if ("center".equalsIgnoreCase(alignment)) {
158 align = FlowLayout.CENTER;
159 }
160 layout = new FlowLayout(align,0,0);
161 }
162 }
163 }