/** * Copyright 1999-2009 The Pegadi Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.pegadi.sources; import javax.swing.table.AbstractTableModel; import java.util.ResourceBundle; public class SourceTableModel extends AbstractTableModel { java.util.List<Source> sources; String[] columns = {"Name", "Position", "Email"}; ResourceBundle strings; public SourceTableModel(java.util.List<Source> sources) { this.sources=sources; strings = ResourceBundle.getBundle("org.pegadi.sources.SourceTableModelStrings"); columns[0] = strings.getString("column.name"); columns[1] = strings.getString("column.position"); columns[2] = strings.getString("column.email"); } public int getRowCount() { return sources.size(); } public int getColumnCount() { return 3; } public Object getValueAt(int row, int col) { Source s = sources.get(row); switch(col) { case 0: return s.getName(); case 1: return s.getPosition(); case 2: return s.getEmail(); } return null; } public String getColumnName(int col) { return columns[col]; } public void setSources(java.util.List<Source> sources) { this.sources=sources; fireTableDataChanged(); } public Source getSource(int row) { return sources.get(row); } }