1 /*
2 Copyright 2002-2006 Martin van den Bemt
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
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 * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
30 * @version $Id: SwingGridBagLayout.java,v 1.1 2004/05/24 18:12:34 mvdb Exp $
31 */
32 public class SwingGridBagLayout extends SwingLayoutAbstract implements LayoutManager2 {
33
34 protected GridBagLayout layout;
35 /**
36 * We reuse the instance of gbc, since it is cloned when
37 * passed as a parameter to the gridbaglayout
38 */
39 protected GridBagConstraints c = new GridBagConstraints();
40
41 /**
42 *
43 */
44 public SwingGridBagLayout() {
45 layout = new GridBagLayout();
46 }
47
48 /**
49 * @see org.xulux.api.gui.IXuluxLayout#addWidget(org.xulux.api.gui.IWidget)
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 * @see org.xulux.api.gui.IXuluxLayout#removeWidget(org.xulux.api.gui.IWidget)
65 */
66 public void removeWidget(IWidget widget) {
67 }
68
69 /**
70 * @see org.xulux.api.gui.IXuluxLayout#destroy()
71 */
72 public void destroy() {
73 c = null;
74 layout = null;
75 }
76
77 /**
78 * @see java.awt.LayoutManager2#addLayoutComponent(java.awt.Component, java.lang.Object)
79 */
80 public void addLayoutComponent(Component comp, Object constraints) {
81 addWidget((IWidget) constraints);
82 }
83
84 /**
85 * @see java.awt.LayoutManager2#maximumLayoutSize(java.awt.Container)
86 */
87 public Dimension maximumLayoutSize(Container target) {
88 return layout.maximumLayoutSize(target);
89 }
90
91 /**
92 * @see java.awt.LayoutManager2#getLayoutAlignmentX(java.awt.Container)
93 */
94 public float getLayoutAlignmentX(Container target) {
95 return layout.getLayoutAlignmentX(target);
96 }
97
98 /**
99 * @see java.awt.LayoutManager2#getLayoutAlignmentY(java.awt.Container)
100 */
101 public float getLayoutAlignmentY(Container target) {
102 return layout.getLayoutAlignmentY(target);
103 }
104
105 /**
106 * @see java.awt.LayoutManager2#invalidateLayout(java.awt.Container)
107 */
108 public void invalidateLayout(Container target) {
109
110 }
111
112 /**
113 * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
114 */
115 public void addLayoutComponent(String name, Component comp) {
116 layout.addLayoutComponent(name, comp);
117 }
118
119 /**
120 * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
121 */
122 public void removeLayoutComponent(Component comp) {
123 layout.removeLayoutComponent(comp);
124 }
125
126 /**
127 * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
128 */
129 public Dimension preferredLayoutSize(Container parent) {
130 return layout.preferredLayoutSize(parent);
131 }
132
133 /**
134 * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
135 */
136 public Dimension minimumLayoutSize(Container parent) {
137 return layout.minimumLayoutSize(parent);
138 }
139
140 /**
141 * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
142 */
143 public void layoutContainer(Container parent) {
144 layout.layoutContainer(parent);
145 }
146
147 }