KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SBorderLayout


1 /*
2  * $Id: SBorderLayout.java,v 1.6 2005/06/03 13:16:16 blueshift Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings;
15
16 import java.util.HashMap JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.Map JavaDoc;
19
20 /**
21  * This is a border layout. You can add up to 5 components to a
22  * container with this layout at the following positions:
23  * <code>NORTH</code>, <code>SOUTH</code>, <code>EAST</code>,
24  * <code>WEST</code> and <code>CENTER</code>.
25  *
26  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
27  * @version $Revision: 1.6 $
28  */

29 public class SBorderLayout
30         extends SAbstractLayoutManager {
31
32     public static final String JavaDoc NORTH = "North";
33     public static final String JavaDoc SOUTH = "South";
34     public static final String JavaDoc EAST = "East";
35     public static final String JavaDoc WEST = "West";
36     public static final String JavaDoc CENTER = "Center";
37
38     protected Map JavaDoc components = new HashMap JavaDoc(5);
39     protected int border = 0;
40
41     /**
42      * The horizontal gap (in pixels) specifiying the space
43      * between columns. They can be changed at any time.
44      * This should be a non-negative integer.
45      */

46     protected int hgap = 0;
47
48     /**
49      * The vertical gap (in pixels) which specifiying the space
50      * between rows. They can be changed at any time.
51      * This should be a non negative integer.
52      */

53     protected int vgap = 0;
54
55
56     /**
57      * creates a new border layout
58      */

59     public SBorderLayout() {}
60
61     /**
62      * creates a new border layout
63      */

64     public SBorderLayout(int hgap, int vgap) {
65         setHgap(hgap);
66         setVgap(vgap);
67     }
68
69
70     public void addComponent(SComponent c, Object JavaDoc constraint, int index) {
71         if (constraint == null)
72             constraint = CENTER;
73
74         components.put(constraint, c);
75     }
76
77     public void removeComponent(SComponent c) {
78         if (c == null)
79             return;
80
81         Iterator JavaDoc iterator = components.entrySet().iterator();
82         while (iterator.hasNext()) {
83             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iterator.next();
84             if (c.equals(entry.getValue())) {
85                 iterator.remove();
86                 break;
87             }
88         }
89     }
90
91     public Map JavaDoc getComponents() {
92         return components;
93     }
94
95     /**
96      * Set the thickness of the border.
97      * Default is 0, which means no border.
98      *
99      * @param pixel thickness of the border
100      */

101     public void setBorder(int pixel) {
102         border = pixel;
103     }
104
105     /**
106      * Returns the thickness of the border.
107      *
108      * @return thickness of the border
109      */

110     public int getBorder() {
111         return border;
112     }
113
114     /**
115      * Gets the horizontal gap between components in pixel. Rendered half as margin left and margin right
116      * Some PLAFs might ignore this property.
117      *
118      * @return the horizontal gap between components
119      */

120     public int getHgap() {
121         return hgap;
122     }
123
124     /**
125      * Sets the horizontal gap between components to the specified value in pixe. Rendered half as margin left and margin right
126      * Some PLAFs might ignore this property.
127      *
128      * @param hgap the horizontal gap between components
129      */

130     public void setHgap(int hgap) {
131         this.hgap = hgap;
132     }
133
134     /**
135      * Gets the vertical gap between components in pixel. Rendered half as margin top and margin bottom
136      * Some PLAFs might ignore this property.
137      *
138      * @return the vertical gap between components
139      */

140     public int getVgap() {
141         return vgap;
142     }
143
144     /**
145      * Sets the vertical gap between components to the specified value in pixel.
146      * Rendered half as margin top and margin bottom. Some PLAFs might ignore this property.
147      *
148      * @param vgap the vertical gap between components
149      */

150     public void setVgap(int vgap) {
151         this.vgap = vgap;
152     }
153 }
154
155
156
Popular Tags