001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings;
014:
015: import java.util.HashMap;
016: import java.util.Iterator;
017: import java.util.Map;
018:
019: /**
020: * Swing-like border layout.
021: * <p/>
022: * You can add up to 5 components to a
023: * container with this layout at the following positions:
024: * <code>NORTH</code>, <code>SOUTH</code>, <code>EAST</code>,
025: * <code>WEST</code> and <code>CENTER</code>.
026: *
027: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
028: */
029: public class SBorderLayout extends SAbstractLayoutManager {
030:
031: public static final String NORTH = "North";
032: public static final String SOUTH = "South";
033: public static final String EAST = "East";
034: public static final String WEST = "West";
035: public static final String CENTER = "Center";
036:
037: protected Map components = new HashMap(5);
038:
039: /**
040: * The horizontal gap (in pixels) specifiying the space
041: * between columns. They can be changed at any time.
042: * This should be a non-negative integer.
043: */
044: protected int hgap = 0;
045:
046: /**
047: * The vertical gap (in pixels) which specifiying the space
048: * between rows. They can be changed at any time.
049: * This should be a non negative integer.
050: */
051: protected int vgap = 0;
052:
053: /**
054: * creates a new border layout
055: */
056: public SBorderLayout() {
057: this (0, 0);
058: }
059:
060: /**
061: * creates a new border layout
062: */
063: public SBorderLayout(int hgap, int vgap) {
064: setHgap(hgap);
065: setVgap(vgap);
066: // like swing
067: setPreferredSize(SDimension.FULLWIDTH);
068: }
069:
070: public void addComponent(SComponent c, Object constraint, int index) {
071: if (constraint == null)
072: constraint = CENTER;
073:
074: components.put(constraint, c);
075: }
076:
077: /**
078: * Removes the component from the layout manager
079: * @param c the component to be removed
080: */
081: public void removeComponent(SComponent c) {
082: if (c == null)
083: return;
084:
085: Iterator iterator = components.entrySet().iterator();
086: while (iterator.hasNext()) {
087: Map.Entry entry = (Map.Entry) iterator.next();
088: if (c.equals(entry.getValue())) {
089: iterator.remove();
090: break;
091: }
092: }
093: }
094:
095: /**
096: * Returns a map of all components.
097: * @return the components contained by the layout
098: */
099: public Map getComponents() {
100: return components;
101: }
102:
103: /**
104: * Gets the horizontal gap between components in pixel. Rendered half as margin left and margin right
105: * Some PLAFs might ignore this property.
106: *
107: * @return the horizontal gap between components
108: */
109: public int getHgap() {
110: return hgap;
111: }
112:
113: /**
114: * Sets the horizontal gap between components to the specified value in pixe. Rendered half as margin left and margin right
115: * Some PLAFs might ignore this property.
116: *
117: * @param hgap the horizontal gap between components
118: */
119: public void setHgap(int hgap) {
120: this .hgap = hgap;
121: }
122:
123: /**
124: * Gets the vertical gap between components in pixel. Rendered half as margin top and margin bottom
125: * Some PLAFs might ignore this property.
126: *
127: * @return the vertical gap between components
128: */
129: public int getVgap() {
130: return vgap;
131: }
132:
133: /**
134: * Sets the vertical gap between components to the specified value in pixel.
135: * Rendered half as margin top and margin bottom. Some PLAFs might ignore this property.
136: *
137: * @param vgap the vertical gap between components
138: */
139: public void setVgap(int vgap) {
140: this.vgap = vgap;
141: }
142: }
|