1 19 20 package org.openharmonise.him.displaycomponents.table; 21 22 import java.awt.Component ; 23 import java.awt.Container ; 24 import java.awt.Dimension ; 25 import java.awt.LayoutManager ; 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import javax.swing.JScrollPane ; 32 import javax.swing.JSplitPane ; 33 34 43 public class TableLayout implements LayoutManager { 44 45 48 private int m_nContainerSizeX = 400; 49 50 53 private int m_nContainerSizeY = 400; 54 55 58 private Dimension m_parentSize = null; 59 60 63 private int m_nDividerLoc = -1; 64 65 68 private TableView m_table = null; 69 70 71 76 public TableLayout(TableView table) { 77 super(); 78 this.m_table = table; 79 } 80 81 84 public void removeLayoutComponent(Component arg0) { 85 } 87 88 91 public void layoutContainer(Container container) { 92 Component parent = container.getParent().getParent().getParent(); 93 if( parent instanceof JSplitPane ) { 94 Dimension dim = parent.getSize(); 95 int nDividerLoc = ((JSplitPane )parent).getDividerLocation(); 96 97 if(this.m_parentSize==null) { 98 99 } 100 if(this.m_nDividerLoc!=nDividerLoc) { 101 102 } 103 if(this.m_parentSize!=null && this.m_parentSize.getHeight()!=dim.getHeight()) { 104 105 } 106 if(this.m_parentSize!=null && this.m_parentSize.getWidth()!=dim.getWidth()) { 107 108 } 109 110 if( this.m_parentSize==null || this.m_nDividerLoc!=nDividerLoc || this.m_parentSize.getHeight()!=dim.getHeight() || this.m_parentSize.getWidth()!=dim.getWidth() ) { 111 this.reflowContainer(container); 112 this.m_parentSize=dim; 113 this.m_nDividerLoc = nDividerLoc; 114 } else { 115 this.resizeContainer(container); 116 } 117 } 118 } 119 120 126 public void reflowContainer(Container container) { 127 128 List colRowMap = new ArrayList (); 129 130 Component parent = container.getParent(); 131 if( parent instanceof JScrollPane ) { 132 parent = parent.getParent(); 133 } 134 135 this.m_nContainerSizeX = parent.getWidth(); 136 this.m_nContainerSizeY = parent.getHeight(); 137 138 int nCurrentX = 0; 139 int nCurrentY = 0; 140 141 List order = this.m_table.getOrderedList(); 142 Iterator itor = order.iterator(); 143 List col = new ArrayList (); 144 while (itor.hasNext()) { 145 String sPath = (String ) itor.next(); 146 Component comp = this.m_table.getEntry(sPath); 147 comp.setSize(comp.getPreferredSize()); 148 int nHeight = comp.getPreferredSize().height; 149 if( nCurrentY + nHeight < this.m_nContainerSizeY ) { 150 comp.setLocation(nCurrentX, nCurrentY); 151 nCurrentY = nCurrentY + nHeight; 152 col.add(((TableEntry)comp).getPath()); 153 } else { 154 colRowMap.add(col); 155 col = new ArrayList (); 156 col.add(((TableEntry)comp).getPath()); 157 int nWidth = comp.getPreferredSize().width; 158 nCurrentY = 0; 159 nCurrentX = nCurrentX + nWidth; 160 comp.setLocation(nCurrentX, nCurrentY); 161 nCurrentY = nCurrentY + nHeight; 162 } 163 } 164 if(col.size()>0) { 165 colRowMap.add(col); 166 } 167 168 nCurrentX = nCurrentX + 200; 169 170 this.m_nContainerSizeX = nCurrentX; 171 this.m_nContainerSizeY = nCurrentY; 172 173 container.repaint(); 174 this.m_table.setColRowMap(colRowMap); 175 } 176 177 184 public void reflowColumn(Container container, Component component) { 185 int nCompX = component.getLocation().x; 186 int nCurrentY = 0; 187 188 List order = this.m_table.getOrderedList(); 189 Iterator itor = order.iterator(); 190 while (itor.hasNext()) { 191 String sPath = (String ) itor.next(); 192 Component comp = this.m_table.getEntry(sPath); 193 comp.setSize(comp.getPreferredSize()); 194 if(comp.getLocation().x==nCompX) { 195 comp.setLocation(nCompX, nCurrentY); 196 197 nCurrentY = nCurrentY + comp.getHeight(); 198 } 199 } 200 201 this.m_nContainerSizeY = nCurrentY; 202 container.repaint(); 203 } 204 205 210 public void resizeContainer(Container container) { 211 int nCurrentX = 0; 212 int nCurrentY = 0; 213 214 Component [] comps = container.getComponents(); 215 for(int i=0; i<comps.length; i++) { 216 Component comp = comps[i]; 217 if(comp instanceof TableEntry) { 218 comp.setSize(comp.getPreferredSize()); 219 int nPosX = comp.getLocation().x; 220 int nPosY = comp.getLocation().y; 221 int nHeight = comp.getPreferredSize().height; 222 int nWidth = comp.getPreferredSize().width; 223 224 if(nPosX + nWidth > nCurrentX) { 225 nCurrentX = nPosX + nWidth; 226 } 227 if(nPosY + nHeight > nCurrentY) { 228 nCurrentY = nPosY + nHeight; 229 } 230 } 231 } 232 233 nCurrentX = nCurrentX + 200; 234 235 this.m_nContainerSizeX = nCurrentX; 236 this.m_nContainerSizeY = nCurrentY; 237 238 container.repaint(); 239 } 240 241 244 public void addLayoutComponent(String arg0, Component arg1) { 245 } 247 248 251 public Dimension minimumLayoutSize(Container arg0) { 252 return this.getContainerSize(); 253 } 254 255 258 public Dimension preferredLayoutSize(Container arg0) { 259 this.layoutContainer(arg0); 260 return this.getContainerSize(); 261 } 262 263 268 private Dimension getContainerSize() { 269 return new Dimension (this.m_nContainerSizeX, this.m_nContainerSizeY); 270 } 271 272 } | Popular Tags |