KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SScrollPaneLayout


1 /*
2  * Copyright (c) 2005 Your Corporation. All Rights Reserved.
3  */

4 package org.wings;
5
6 import java.util.HashMap JavaDoc;
7 import java.util.Iterator JavaDoc;
8 import java.util.Map JavaDoc;
9
10 /**
11  * @author hengels
12  * @version $Revision: 1.3 $
13  */

14 public class SScrollPaneLayout
15         extends SAbstractLayoutManager
16 {
17     public static final String JavaDoc VIEWPORT = "Viewport";
18     public static final String JavaDoc NORTH = SBorderLayout.NORTH;
19     public static final String JavaDoc WEST = SBorderLayout.WEST;
20     public static final String JavaDoc EAST = SBorderLayout.EAST;
21     public static final String JavaDoc SOUTH = SBorderLayout.SOUTH;
22
23     private SComponent viewport;
24     private SComponent north;
25     private SComponent west;
26     private SComponent east;
27     private SComponent south;
28
29     Map JavaDoc components = new HashMap JavaDoc(5);
30     private boolean paging = true;
31
32     public boolean isPaging() {
33         return paging;
34     }
35
36     public void setPaging(boolean paging) {
37         this.paging = paging;
38     }
39
40     public void addSingletonComponent(SComponent component, Object JavaDoc constraint) {
41         if (VIEWPORT.equals(constraint)) {
42             container.remove(viewport);
43             viewport = component;
44         }
45         else if (NORTH.equals(constraint)) {
46             container.remove(north);
47             north = component;
48         }
49         else if (WEST.equals(constraint)) {
50             container.remove(west);
51             west = component;
52         }
53         else if (EAST.equals(constraint)) {
54             container.remove(east);
55             east = component;
56         }
57         else if (SOUTH.equals(constraint)) {
58             container.remove(south);
59             south = component;
60         }
61     }
62
63     public void addComponent(SComponent component, Object JavaDoc constraint, int index) {
64         addSingletonComponent(component, constraint);
65         components.put(constraint, component);
66     }
67
68     public void removeComponent(SComponent c) {
69         if (c == null)
70             return;
71
72         String JavaDoc constraint = null;
73         Iterator JavaDoc iterator = components.entrySet().iterator();
74         while (iterator.hasNext()) {
75             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iterator.next();
76             if (c.equals(entry.getValue())) {
77                 constraint = (String JavaDoc) entry.getKey();
78                 break;
79             }
80         }
81
82         if (constraint != null) {
83             components.remove(constraint);
84             removeSingletonComponent(constraint);
85         }
86     }
87
88     private void removeSingletonComponent(String JavaDoc constraint) {
89         if (VIEWPORT.equals(constraint)) {
90             viewport = null;
91         }
92         else if (NORTH.equals(constraint)) {
93             north = null;
94         }
95         else if (WEST.equals(constraint)) {
96             west = null;
97         }
98         else if (EAST.equals(constraint)) {
99             east = null;
100         }
101         else if (SOUTH.equals(constraint)) {
102             south = null;
103         }
104     }
105
106     public Map JavaDoc getComponents() {
107         return components;
108     }
109 }
110
Popular Tags