diff options
Diffstat (limited to 'ao-tools/altosui/AltosFlightInfoTableModel.java')
| -rw-r--r-- | ao-tools/altosui/AltosFlightInfoTableModel.java | 77 | 
1 files changed, 40 insertions, 37 deletions
| diff --git a/ao-tools/altosui/AltosFlightInfoTableModel.java b/ao-tools/altosui/AltosFlightInfoTableModel.java index 3355ff52..e23eff68 100644 --- a/ao-tools/altosui/AltosFlightInfoTableModel.java +++ b/ao-tools/altosui/AltosFlightInfoTableModel.java @@ -29,53 +29,56 @@ import java.util.prefs.*;  import java.util.concurrent.LinkedBlockingQueue;  public class AltosFlightInfoTableModel extends AbstractTableModel { -	private String[] columnNames = {"Field", "Value"}; +	final static private String[] columnNames = {"Field", "Value"}; -	class InfoLine { -		String	name; -		String	value; +	int	rows; +	int	cols; +	private String[][] data; -		public InfoLine(String n, String v) { -			name = n; -			value = v; -		} -	} - -	private ArrayList<InfoLine> rows = new ArrayList<InfoLine>(); - -	public int getColumnCount() { return columnNames.length; } -	public String getColumnName(int col) { return columnNames[col]; } - -	public int getRowCount() { return 17; } - -	int	current_row = 0; -	int	prev_num_rows = 0; +	public int getColumnCount() { return cols; } +	public int getRowCount() { return rows; } +	public String getColumnName(int col) { return columnNames[col & 1]; }  	public Object getValueAt(int row, int col) { -		if (row >= rows.size()) +		if (row >= rows || col >= cols)  			return ""; -		if (col == 0) -			return rows.get(row).name; -		else -			return rows.get(row).value; +		return data[row][col];  	} -	public void resetRow() { -		current_row = 0; +	int[]	current_row; + +	public void reset() { +		for (int i = 0; i < cols / 2; i++) +			current_row[i] = 0;  	} -	public void addRow(String name, String value) { -		if (current_row >= rows.size()) -			rows.add(current_row, new InfoLine(name, value)); -		else -			rows.set(current_row, new InfoLine(name, value)); -		current_row++; + +	public void clear() { +		reset(); +		for (int c = 0; c < cols; c++) +			for (int r = 0; r < rows; r++) +				data[r][c] = ""; +		fireTableDataChanged(); +	} + +	public void addRow(int col, String name, String value) { +		if (current_row[col] < rows) { +			data[current_row[col]][col * 2] = name; +			data[current_row[col]][col * 2 + 1] = value; +		} +		current_row[col]++;  	} +  	public void finish() { -		if (current_row > prev_num_rows) -			fireTableRowsInserted(prev_num_rows, current_row - 1); -		while (rows.size() > current_row) -			rows.remove(rows.size() - 1); -		prev_num_rows = current_row; +		for (int c = 0; c < cols / 2; c++) +			while (current_row[c] < rows) +				addRow(c, "", "");  		fireTableDataChanged();  	} + +	public AltosFlightInfoTableModel (int in_rows, int in_cols) { +		rows = in_rows; +		cols = in_cols * 2; +		data = new String[rows][cols]; +		current_row = new int[in_cols]; +	}  } | 
