001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets;
006:
007: import java.util.*;
008: import java.io.*;
009:
010: import com.javelin.swinglets.plaf.*;
011:
012: /**
013: * SBorderLayout is used to layout SComponents in a SContainer.
014: * <P>
015: * The SBorderLayout component is based on the java.awt.BorderLayout
016: * LayoutManager.
017: *
018: * @author Robin Sharp
019: */
020:
021: public class SBorderLayout extends SLayoutManager {
022: /**
023: * Layout the component across the top of the container.
024: */
025: public static final String NORTH = "North";
026:
027: /**
028: * Layout the component across the bottom of container.
029: */
030: public final static String SOUTH = "South";
031:
032: /**
033: * Layout the component on the left side of container.
034: */
035: public final static String EAST = "East";
036:
037: /**
038: * Layout the component on the right side of container.
039: */
040: public final static String WEST = "West";
041:
042: /**
043: * Layout the component in the middle of container.
044: */
045: public final static String CENTER = "Center";
046:
047: /**
048: * Construct a fully qualified SBorderLayout.
049: */
050: public SBorderLayout() {
051: }
052:
053: /**
054: * Construct a fully qualified SBorderLayout, 2 columns, and n rows.
055: * Set the rows and columns to 0 to let the layout manager figure
056: * out the correct number of rows or columns.
057: */
058: public SBorderLayout(int gap) {
059: setGap(gap);
060: }
061:
062: /**
063: * Returns the name of the L&F class that renders this layout.
064: */
065: public Class getUIClass() {
066: return SBorderLayout.class;
067: }
068:
069: /**
070: * Add a component, at a location.
071: * If the component is null then it is removed.
072: */
073: public void addComponent(SComponent component, Object constraint) {
074: if (constraint == null)
075: constraint = CENTER;
076:
077: if (!(constraint instanceof String)) {
078: throw new IllegalArgumentException(
079: "Constraint must be integer. "
080: + constraint.getClass());
081: }
082:
083: if (!(constraint.equals(NORTH) || constraint.equals(SOUTH)
084: || constraint.equals(EAST) || constraint.equals(WEST) || constraint
085: .equals(CENTER))) {
086: throw new IllegalArgumentException("Unknown Constraint "
087: + constraint);
088: }
089:
090: if (component == null) {
091: components.remove(constraint);
092: } else {
093: components.put(constraint, component);
094: }
095: }
096:
097: /**
098: * Get component from a contraint.
099: */
100: public SComponent getComponent(Object constraint) {
101: return (SComponent) components.get(constraint);
102: }
103:
104: /**
105: * Remove a component.
106: */
107: public void removeComponent(SComponent component) {
108: Object value = null;
109: Object key = null;
110:
111: for (Enumeration keys = components.keys(); keys
112: .hasMoreElements();) {
113: key = keys.nextElement();
114: value = components.get(key);
115:
116: if (component == value) {
117: components.remove(key);
118: return;
119: }
120: }
121: }
122:
123: /**
124: * Get the gap.
125: */
126: public int getGap() {
127: return gap;
128: }
129:
130: /**
131: * Set the gap.
132: */
133: public void setGap(int gap) {
134: if (gap < 0)
135: throw new IllegalArgumentException("gap < 0");
136: this .gap = gap;
137: }
138:
139: // PRIVATE /////////////////////////////////////////////////////////
140:
141: private Hashtable components = new Hashtable();
142: private int gap;
143:
144: }
|