/*
Copyright (C) 2011 Jason von Nieda <jason@vonnieda.org>
This file is part of OpenPnP.
OpenPnP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenPnP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenPnP. If not, see <http://www.gnu.org/licenses/>.
For more information about OpenPnP visit http://openpnp.org
*/
package org.openpnp.gui.tablemodel;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import org.openpnp.model.Board;
import org.openpnp.model.Configuration;
public class BoardsTableModel extends AbstractTableModel implements PropertyChangeListener {
private String[] columnNames = new String[] { "Board", "Path" };
private final Configuration configuration;
private List<Board> boards;
public BoardsTableModel(Configuration configuration) {
this.configuration = configuration;
boards = configuration.getBoards();
configuration.addPropertyChangeListener("boards", this);
}
@Override
public String getColumnName(int column) {
return columnNames[column];
}
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return boards.size();
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex == 1) {
return false;
}
return true;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
try {
Board board = boards.get(rowIndex);
if (columnIndex == 0) {
board.setName(aValue.toString());
}
}
catch (Exception e) {
// TODO: dialog, bad input
}
}
public Object getValueAt(int row, int col) {
Board board = boards.get(row);
switch (col) {
case 0:
return board.getName();
case 1:
return board.getFile().getPath();
default:
return null;
}
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
boards = configuration.getBoards();
fireTableDataChanged();
}
}