1 7 package org.jdesktop.swing.util; 8 9 import java.beans.PropertyChangeEvent ; 10 import java.beans.PropertyChangeListener ; 11 12 import java.io.IOException ; 13 import java.net.URL ; 14 import java.util.HashMap ; 15 16 import org.jdesktop.swing.data.MetaData; 17 import org.jdesktop.swing.data.DefaultTableModelExt; 18 import org.jdesktop.swing.data.TableModelExtTextLoader; 19 20 25 public class TestSupport { 26 27 public static DefaultTableModelExt createTabularDataModel(MetaData[] metaData, int rowCount) { 28 DefaultTableModelExt tabularData = new DefaultTableModelExt(metaData.length); 29 for (int i = 0; i < metaData.length; i++) { 30 tabularData.setColumnMetaData(i, metaData[i]); 31 } 32 for (int i = 0; i < rowCount; i++) { 33 tabularData.addRow(new Object [metaData.length]); 34 35 } 36 return tabularData; 37 } 38 39 40 public static DefaultTableModelExt loadTabularCSVData(URL dataURL, boolean firstRowHeader) { 41 DefaultTableModelExt data = new DefaultTableModelExt(dataURL); 42 data.getColumnCount(); 43 TableModelExtTextLoader loader = (TableModelExtTextLoader) data.getLoader(); 44 loader.setColumnDelimiter(","); 45 loader.setFirstRowHeader(firstRowHeader); 46 try { 47 data.startLoading(); 48 } catch (IOException e) { 49 e.printStackTrace(); 51 } 52 int row = 0; 53 while (data.isLoading()) { 54 } 56 return data; 57 } 58 59 64 public static class PropertyChangeTracker implements PropertyChangeListener { 65 private HashMap changedProperties = new HashMap (); 66 67 public void propertyChange(PropertyChangeEvent e) { 68 changedProperties.put(e.getPropertyName(), e); 69 } 70 71 77 public boolean gotPropertyChangeEvent(String propertyName) { 78 return changedProperties.containsKey(propertyName); 79 } 80 81 86 public Object getNewPropertyValue(String propertyName) { 87 PropertyChangeEvent e = (PropertyChangeEvent ) 88 changedProperties.get(propertyName); 89 return e.getNewValue(); 90 } 91 92 97 public Object getOldPropertyValue(String propertyName) { 98 PropertyChangeEvent e = (PropertyChangeEvent ) 99 changedProperties.get(propertyName); 100 return e.getOldValue(); 101 } 102 103 public boolean hasPropertyChangeEvents() { 104 return !changedProperties.isEmpty(); 105 } 106 107 110 public void clear() { 111 changedProperties.clear(); 112 } 113 } 114 } | Popular Tags |