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.BorderLayout;
19 import java.awt.Component;
20 import java.awt.Container;
21 import java.awt.Dimension;
22 import java.awt.LayoutManager2;
23
24 import org.xulux.api.gui.IWidget;
25 import org.xulux.utils.StringUtils;
26
27
28
29
30
31
32
33 public class SwingBorderLayout extends SwingLayoutAbstract implements LayoutManager2 {
34
35
36 protected BorderLayout layout;
37
38
39 public SwingBorderLayout() {
40 }
41
42
43
44
45 public void addWidget(IWidget widget) {
46 createLayout();
47 String constraint = widget.getProperty("layout-constraint");
48 constraint = StringUtils.capitalize(constraint);
49 if (constraint == null) {
50 constraint = BorderLayout.CENTER;
51 }
52 layout.addLayoutComponent((Component) widget.getNativeWidget(), constraint);
53 }
54
55
56
57
58 public void removeWidget(IWidget widget) {
59 }
60
61
62
63
64 public void destroy() {
65
66 }
67
68
69
70 public void addLayoutComponent(Component comp, Object constraints) {
71 if (constraints == null || !(constraints instanceof IWidget)) {
72
73 createLayout();
74 if (constraints != null) {
75 addLayoutComponent(comp, constraints);
76 } else {
77 layout.addLayoutComponent(comp, BorderLayout.CENTER);
78 }
79 } else {
80 addWidget((IWidget) constraints);
81 }
82 }
83
84
85
86 public Dimension maximumLayoutSize(Container target) {
87 return layout.maximumLayoutSize(target);
88 }
89
90
91
92 public float getLayoutAlignmentX(Container target) {
93 return layout.getLayoutAlignmentX(target);
94 }
95
96
97
98 public float getLayoutAlignmentY(Container target) {
99 return layout.getLayoutAlignmentY(target);
100 }
101
102
103
104 public void invalidateLayout(Container target) {
105 if (layout != null) {
106 layout.invalidateLayout(target);
107 }
108 }
109
110
111
112 public void addLayoutComponent(String name, Component comp) {
113 System.out.println("layoutComponent called : " + name);
114 }
115
116
117
118 public void removeLayoutComponent(Component comp) {
119 layout.removeLayoutComponent(comp);
120 }
121
122
123
124 public Dimension preferredLayoutSize(Container parent) {
125 createLayout();
126 return layout.preferredLayoutSize(parent);
127 }
128
129
130
131 public Dimension minimumLayoutSize(Container parent) {
132 return layout.minimumLayoutSize(parent);
133 }
134
135
136
137 public void layoutContainer(Container parent) {
138 createLayout();
139 layout.layoutContainer(parent);
140 }
141
142 protected void createLayout() {
143 if (layout == null) {
144 layout = new BorderLayout();
145 }
146 }
147
148 }