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.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 * The border layout. This is a wrapper around the swing border layout
29 *
30 * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
31 * @version $Id: SwingBorderLayout.java,v 1.4 2005/01/12 18:39:31 mvdb Exp $
32 */
33 public class SwingBorderLayout extends SwingLayoutAbstract implements LayoutManager2 {
34
35
36 protected BorderLayout layout;
37
38
39 public SwingBorderLayout() {
40 }
41
42 /**
43 * @see org.xulux.api.gui.IXuluxLayout#addWidget(org.xulux.api.gui.IWidget)
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 * @see org.xulux.api.gui.IXuluxLayout#removeWidget(org.xulux.api.gui.IWidget)
57 */
58 public void removeWidget(IWidget widget) {
59 }
60
61 /**
62 * @see org.xulux.gui.IXuluxLayout#destroy()
63 */
64 public void destroy() {
65
66 }
67 /**
68 * @see java.awt.LayoutManager2#addLayoutComponent(java.awt.Component, java.lang.Object)
69 */
70 public void addLayoutComponent(Component comp, Object constraints) {
71 if (constraints == null || !(constraints instanceof IWidget)) {
72 // assume a native widget..
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 * @see java.awt.LayoutManager2#maximumLayoutSize(java.awt.Container)
85 */
86 public Dimension maximumLayoutSize(Container target) {
87 return layout.maximumLayoutSize(target);
88 }
89 /**
90 * @see java.awt.LayoutManager2#getLayoutAlignmentX(java.awt.Container)
91 */
92 public float getLayoutAlignmentX(Container target) {
93 return layout.getLayoutAlignmentX(target);
94 }
95 /**
96 * @see java.awt.LayoutManager2#getLayoutAlignmentY(java.awt.Container)
97 */
98 public float getLayoutAlignmentY(Container target) {
99 return layout.getLayoutAlignmentY(target);
100 }
101 /**
102 * @see java.awt.LayoutManager2#invalidateLayout(java.awt.Container)
103 */
104 public void invalidateLayout(Container target) {
105 if (layout != null) {
106 layout.invalidateLayout(target);
107 }
108 }
109 /**
110 * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
111 */
112 public void addLayoutComponent(String name, Component comp) {
113 System.out.println("layoutComponent called : " + name);
114 }
115 /**
116 * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
117 */
118 public void removeLayoutComponent(Component comp) {
119 layout.removeLayoutComponent(comp);
120 }
121 /**
122 * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
123 */
124 public Dimension preferredLayoutSize(Container parent) {
125 createLayout();
126 return layout.preferredLayoutSize(parent);
127 }
128 /**
129 * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
130 */
131 public Dimension minimumLayoutSize(Container parent) {
132 return layout.minimumLayoutSize(parent);
133 }
134 /**
135 * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
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 }