diff options
| author | Anthony Towns <aj@erisian.com.au> | 2010-11-21 10:45:15 +1000 |
|---|---|---|
| committer | Anthony Towns <aj@erisian.com.au> | 2010-11-21 10:45:15 +1000 |
| commit | 2a7dc3ba36bac81640a9498e0d0caf1470b57c19 (patch) | |
| tree | 49e5687e40aa4a37a5479d831a0cb18ad6c14362 /ao-tools/altosui/AltosFlightInfoTableModel.java | |
| parent | e5b1adae9b23b98a6321986f5cd67c9d3166b87f (diff) | |
| parent | ece2c86e2641b2cd613791293526c492b1606aa1 (diff) | |
Merge branch 'buttonbox' into sitemap
Conflicts:
ao-tools/altosui/AltosFlightUI.java
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]; + } } |
