/* * 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.util.ArrayList; import java.util.List; import javax.swing.table.AbstractTableModel; import org.openpnp.ConfigurationListener; import org.openpnp.model.Configuration; import org.openpnp.spi.Head; public class HeadsTableModel extends AbstractTableModel { final private Configuration configuration; private String[] columnNames = new String[] {"Name", "Type"}; private List<Head> heads; public HeadsTableModel(Configuration configuration) { this.configuration = configuration; Configuration.get().addListener(new ConfigurationListener.Adapter() { public void configurationComplete(Configuration configuration) throws Exception { heads = new ArrayList<>(configuration.getMachine().getHeads()); fireTableDataChanged(); } }); } @Override public String getColumnName(int column) { return columnNames[column]; } public int getColumnCount() { return columnNames.length; } public int getRowCount() { return (heads == null) ? 0 : heads.size(); } public Head getHead(int index) { return heads.get(index); } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } public Object getValueAt(int row, int col) { Head head = heads.get(row); switch (col) { case 0: return head.getName(); case 1: return head.getClass().getSimpleName(); default: return null; } } }