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