- Timestamp:
- 07/12/13 23:41:06 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/gui/table/TableModel.java
r99 r100 6 6 import java.util.List; 7 7 8 import javax.swing.JCheckBox; 9 import javax.swing.JComponent; 10 import javax.swing.JTable; 11 import javax.swing.UIManager; 8 12 import javax.swing.event.TableModelEvent; 9 13 import javax.swing.event.TableModelListener; 10 14 11 import org.apache.log4j.Logger; 15 import org.apache.logging.log4j.Logger; 16 import org.apache.logging.log4j.LogManager; 12 17 13 import com.framsticks.params.Access Interface;18 import com.framsticks.params.Access; 14 19 import com.framsticks.params.ListAccess; 20 import com.framsticks.params.Param; 15 21 import com.framsticks.params.PrimitiveParam; 16 import com.framsticks. util.UnsupportedOperationException;22 import com.framsticks.params.types.ProcedureParam; 17 23 import com.framsticks.util.lang.Casting; 18 24 19 25 public class TableModel implements javax.swing.table.TableModel { 20 private static final Logger log =21 Logger.getLogger(TableModel.class);22 26 27 private static final Logger log = LogManager.getLogger(TableModel.class); 23 28 24 29 protected List<TableModelListener> listeners = new LinkedList<>(); 25 30 protected ListAccess access; 26 protected AccessInterface elementAccess; 27 protected final List<PrimitiveParam<?>> columnParams = new ArrayList<>(); 31 protected Access elementAccess; 32 protected final List<Column> columns = new ArrayList<>(); 33 protected final ListPanel listPanel; 34 protected JTable table; 35 36 /** 37 * @param listPanel 38 */ 39 public TableModel(ListPanel listPanel) { 40 this.listPanel = listPanel; 41 } 42 43 /** 44 * @return the listPanel 45 */ 46 public ListPanel getListPanel() { 47 return listPanel; 48 } 49 50 public JTable getTable() { 51 return listPanel.getTable(); 52 } 28 53 29 54 protected void refreshAll() { … … 31 56 l.tableChanged(new TableModelEvent(this)); 32 57 } 58 } 33 59 60 /** 61 * @param table the table to set 62 */ 63 public void setupTable() { 64 getTable().setDefaultRenderer(ProcedureParam.class, new ProcedureRenderer()); 65 getTable().setDefaultEditor(ProcedureParam.class, new ProcedureEditor(new JCheckBox())); 34 66 } 35 67 … … 38 70 39 71 this.elementAccess = this.access.getElementAccess().cloneAccess(); 40 log.debug("attached " +access);72 log.debug("attached {}", access); 41 73 refreshAll(); 42 74 } … … 49 81 @Override 50 82 public Class<?> getColumnClass(int columnIndex) { 51 // log.debug("returning column type " +columnParams.get(columnIndex).getStorageType());52 return column Params.get(columnIndex).getStorageType();83 // log.debug("returning column type {}", columnParams.get(columnIndex).getStorageType()); 84 return columns.get(columnIndex).getColumnClass(); 53 85 } 54 86 55 87 @Override 56 88 public int getColumnCount() { 57 // log.debug("returning column count " +columnParams.size());58 return column Params.size();89 // log.debug("returning column count {}", columnParams.size()); 90 return columns.size(); 59 91 } 60 92 61 93 @Override 62 94 public String getColumnName(int columnIndex) { 63 return column Params.get(columnIndex).getName();95 return columns.get(columnIndex).getParam().getName(); 64 96 } 65 97 66 98 @Override 67 99 public int getRowCount() { 68 // log.debug("returning row count " +access.getParamCount());69 return access .getParamCount();100 // log.debug("returning row count {}", access.getParamCount()); 101 return access == null ? 0 : access.getParamCount(); 70 102 } 71 103 72 104 @Override 73 105 public Object getValueAt(int rowIndex, int columnIndex) { 74 assert (rowIndex < access.getParamCount() && columnIndex < column Params.size());106 assert (rowIndex < access.getParamCount() && columnIndex < columns.size()); 75 107 76 return elementAccess.select(access.get(rowIndex, Object.class)).get(columnParams.get(columnIndex), Object.class);108 return columns.get(columnIndex).getValueAt(rowIndex); 77 109 } 78 110 79 111 @Override 80 112 public boolean isCellEditable(int rowIndex, int columnIndex) { 81 return false;113 return columns.get(columnIndex).isEditable(); 82 114 } 83 115 … … 87 119 } 88 120 121 89 122 @Override 90 123 public void setValueAt(Object value, int rowIndex, int columnIndex) { 91 throw new UnsupportedOperationException().msg("setting value in table"); 92 124 assert (rowIndex < access.getParamCount() && columnIndex < columns.size()); 125 // Object object = getObjectAt(rowIndex, columnIndex); 126 // if (object == null) { 127 // return; 128 // } 129 columns.get(columnIndex).setValueAt(rowIndex, value); 93 130 } 94 131 95 public void addColumn(PrimitiveParam<?> columnParam) { 96 log.debug("added " + columnParam); 97 columnParams.add(columnParam); 132 public void addColumn(Column column) { 133 log.debug("added {}", column); 134 columns.add(column); 135 } 136 137 /** 138 * @return the access 139 */ 140 public ListAccess getAccess() { 141 return access; 142 } 143 144 /** 145 * @return the elementAccess 146 */ 147 public Access getElementAccess() { 148 return elementAccess; 98 149 } 99 150 … … 101 152 * @return the columnParams 102 153 */ 103 public List<PrimitiveParam<?>> getColumnParams() { 104 return Collections.unmodifiableList(columnParams); 154 public List<Column> getColumns() { 155 return Collections.unmodifiableList(columns); 156 } 157 158 159 public boolean addColumnIfSupported(Param param) { 160 if (param instanceof PrimitiveParam) { 161 addColumn(new PrimitiveColumn((PrimitiveParam<?>) param, this)); 162 return true; 163 } 164 if (param instanceof ProcedureParam) { 165 if (((ProcedureParam) param).getArgumentsType().size() == 0) { 166 addColumn(new ProcedureColumn((ProcedureParam) param, this)); 167 return true; 168 } 169 return false; 170 } 171 return false; 172 } 173 174 public static void transferCellAppeariance(JTable table, JComponent component, boolean isSelected) { 175 if (isSelected) { 176 component.setForeground(table.getSelectionForeground()); 177 component.setBackground(table.getSelectionBackground()); 178 } else { 179 component.setForeground(table.getForeground()); 180 component.setBackground(UIManager.getColor("Button.background")); 181 } 182 105 183 } 106 184
Note: See TracChangeset
for help on using the changeset viewer.