View Javadoc
1 //{{{imports 2 package net.sf.plb4jedit.filelocator; 3 import java.util.Vector; 4 5 import javax.swing.table.AbstractTableModel; 6 //}}} 7 8 /*** 9 * A table model that provides editing of map configurations 10 * 11 * @created 03.05.2002 12 * @author Bernhard Krickl 13 * 14 * V.0.01 $Log: MapTableModel.java,v $ 15 * V.0.01 Revision 1.1 2003/11/04 17:40:31 skopp 16 * V.0.01 checked in subprojects + sources 17 * V.0.01 18 * V.0.01 Revision 1.1 2002/05/08 15:02:31 krickl 19 * V.0.01 A table model that provides editing of map configurations 20 * V.0.01 21 */ 22 public class MapTableModel extends AbstractTableModel { 23 24 Vector mapConfigs; 25 26 public MapTableModel(Vector newMapConfigs) { 27 setMapConfigs(newMapConfigs); 28 } 29 30 public int getColumnCount() { 31 return 3; 32 } 33 34 /*** 35 * returns the number of currently available MapConfigs plus one 36 * to produce an empty line. The empty line is necessary to be able 37 * to insert new lines. 38 */ 39 public int getRowCount() { 40 return (mapConfigs.size() + 1); // available configs plus one empty line 41 } 42 43 public Class getColumnClass(int col) { 44 return String.class; 45 } 46 47 public Object getValueAt(int row, int col) { 48 Object value; 49 Vector mapConfigs = getMapConfigs(); 50 if (row < mapConfigs.size()) { 51 MapConfig mapConfig = (MapConfig)mapConfigs.elementAt(row); 52 switch (col) { 53 case 0: 54 value = mapConfig.getName(); 55 break; 56 case 1: 57 value = mapConfig.getDirectory(); 58 break; 59 case 2: 60 value = mapConfig.getExtension(); 61 break; 62 default: 63 value = ""; 64 break; 65 } 66 } 67 else { 68 return ""; // e.g. called for the empty line 69 } 70 return value; 71 } 72 73 public boolean isCellEditable(int row, int col) { 74 return true; 75 } 76 77 /*** 78 * set the value at the specified cell. 79 * empty values delete the row. 80 * setting values in non-existent rows inserts one row after the 81 * current last row. 82 */ 83 public void setValueAt(Object valueObj, int row, int col) { 84 String value = valueObj.toString(); 85 Vector mapConfigs = getMapConfigs(); 86 if (row < mapConfigs.size()) { 87 if (value.compareTo("") != 0) { 88 updateRow(value, row, col); 89 } 90 else { 91 deleteRow(row); 92 } 93 } 94 else { 95 row = mapConfigs.size(); 96 insertRow(value, row, col); 97 } 98 } 99 100 public String getColumnName(int index) { 101 String columnName; 102 switch (index) { 103 case 0: 104 columnName = "Map Name"; 105 break; 106 case 1: 107 columnName = "Directory"; 108 break; 109 case 2: 110 columnName = "Extension"; 111 break; 112 default: 113 columnName = "NO SUCH COLUMN"; 114 break; 115 } 116 return columnName; 117 } 118 119 /* 120 * private 121 */ 122 123 private void updateRow(String value, int row, int col) { 124 updateCell(value, row, col); 125 fireTableRowsUpdated(row,row); 126 } 127 128 private void deleteRow(int row) { 129 mapConfigs.removeElementAt(row); 130 fireTableRowsDeleted(row,row); 131 } 132 133 private void insertRow(String value, int row, int col) { 134 MapConfig mapConfig = new MapConfig(); 135 mapConfigs.insertElementAt(mapConfig, row); 136 updateCell(value, row, col); 137 fireTableRowsInserted(row, row); 138 } 139 140 private void updateCell(String value, int row, int col) { 141 MapConfig mapConfig = (MapConfig)mapConfigs.elementAt(row); 142 switch (col) { 143 case 0: 144 mapConfig.setName(value); 145 break; 146 case 1: 147 mapConfig.setDirectory(value); 148 break; 149 case 2: 150 mapConfig.setExtension(value); 151 break; 152 } 153 } 154 155 private void setMapConfigs(Vector newMapConfigs) { 156 this.mapConfigs = newMapConfigs; 157 } 158 159 private Vector getMapConfigs() { 160 return this.mapConfigs; 161 } 162 } 163

This page was automatically generated by Maven