001: /*
002: * Copyright (c) 2005 Your Corporation. All Rights Reserved.
003: */
004: package org.wings;
005:
006: import java.util.HashMap;
007: import java.util.Iterator;
008: import java.util.Map;
009:
010: /**
011: * Internal layout manager used by {@link SScrollPane}
012: *
013: * @author hengels
014: * @version $Revision: 2994 $
015: */
016: public class SScrollPaneLayout extends SAbstractLayoutManager {
017: public static final String VIEWPORT = "Viewport";
018: public static final String NORTH = SBorderLayout.NORTH;
019: public static final String WEST = SBorderLayout.WEST;
020: public static final String EAST = SBorderLayout.EAST;
021: public static final String SOUTH = SBorderLayout.SOUTH;
022:
023: private SComponent viewport;
024: private SComponent north;
025: private SComponent west;
026: private SComponent east;
027: private SComponent south;
028:
029: Map components = new HashMap(5);
030:
031: public SScrollPaneLayout() {
032: }
033:
034: /**
035: * @deprecated Use {@link org.wings.SScrollPane#isPaging()}
036: */
037: public boolean isPaging() {
038: return ((SScrollPane) container).getMode() == SScrollPane.MODE_SCROLLING;
039: }
040:
041: /**
042: * @deprecated Use {@link org.wings.SScrollPane#setPaging(boolean)}
043: */
044: public void setPaging(boolean paging) {
045: if (paging) {
046: ((SScrollPane) container)
047: .setMode(SScrollPane.MODE_SCROLLING);
048: } else {
049: ((SScrollPane) container)
050: .setMode(SScrollPane.MODE_COMPLETE);
051: }
052: }
053:
054: public void addSingletonComponent(SComponent component,
055: Object constraint) {
056: if (VIEWPORT.equals(constraint)) {
057: if (viewport != component) {
058: container.remove(viewport);
059: }
060: viewport = component;
061: } else if (NORTH.equals(constraint)) {
062: if (viewport != component) {
063: container.remove(north);
064: }
065: north = component;
066: } else if (WEST.equals(constraint)) {
067: if (viewport != component) {
068: container.remove(west);
069: }
070: west = component;
071: } else if (EAST.equals(constraint)) {
072: if (viewport != component) {
073: container.remove(east);
074: }
075: east = component;
076: } else if (SOUTH.equals(constraint)) {
077: if (viewport != component) {
078: container.remove(south);
079: }
080: south = component;
081: }
082: }
083:
084: public void addComponent(SComponent component, Object constraint,
085: int index) {
086: addSingletonComponent(component, constraint);
087: components.put(constraint, component);
088: }
089:
090: /**
091: * Removes the component from the layout manager
092: * @param c the component to be removed
093: */
094: public void removeComponent(SComponent c) {
095: if (c == null) {
096: return;
097: }
098:
099: String constraint = null;
100: Iterator iterator = components.entrySet().iterator();
101: while (iterator.hasNext()) {
102: Map.Entry entry = (Map.Entry) iterator.next();
103: if (c.equals(entry.getValue())) {
104: constraint = (String) entry.getKey();
105: break;
106: }
107: }
108:
109: if (constraint != null) {
110: components.remove(constraint);
111: removeSingletonComponent(constraint);
112: }
113: }
114:
115: private void removeSingletonComponent(String constraint) {
116: if (VIEWPORT.equals(constraint)) {
117: viewport = null;
118: } else if (NORTH.equals(constraint)) {
119: north = null;
120: } else if (WEST.equals(constraint)) {
121: west = null;
122: } else if (EAST.equals(constraint)) {
123: east = null;
124: } else if (SOUTH.equals(constraint)) {
125: south = null;
126: }
127: }
128:
129: /**
130: * Returns a map of all components.
131: * @return the components contained by the layout
132: */
133: public Map getComponents() {
134: return components;
135: }
136: }
|