1 4 package org.wings; 5 6 import java.util.HashMap ; 7 import java.util.Iterator ; 8 import java.util.Map ; 9 10 14 public class SScrollPaneLayout 15 extends SAbstractLayoutManager 16 { 17 public static final String VIEWPORT = "Viewport"; 18 public static final String NORTH = SBorderLayout.NORTH; 19 public static final String WEST = SBorderLayout.WEST; 20 public static final String EAST = SBorderLayout.EAST; 21 public static final String 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 components = new HashMap (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 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 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 constraint = null; 73 Iterator iterator = components.entrySet().iterator(); 74 while (iterator.hasNext()) { 75 Map.Entry entry = (Map.Entry ) iterator.next(); 76 if (c.equals(entry.getValue())) { 77 constraint = (String ) 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 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 getComponents() { 107 return components; 108 } 109 } 110 | Popular Tags |