create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / gui / customexpression / VariableTableModel.java
1 /**
2  * 
3  */
4 package net.sf.openrocket.gui.customexpression;
5
6 import java.awt.event.MouseAdapter;
7 import java.awt.event.MouseEvent;
8 import java.util.ArrayList;
9 import java.util.Collections;
10 import java.util.List;
11 import java.util.Set;
12 import java.util.Vector;
13
14 import javax.swing.JTable;
15 import javax.swing.table.AbstractTableModel;
16 import javax.swing.table.TableColumn;
17 import javax.swing.table.TableColumnModel;
18
19 import net.sf.openrocket.document.OpenRocketDocument;
20 import net.sf.openrocket.l10n.Translator;
21 import net.sf.openrocket.simulation.customexpression.CustomExpression;
22 import net.sf.openrocket.simulation.FlightDataType;
23 import net.sf.openrocket.startup.Application;
24
25 /**
26  * @author Richard Graham
27  *
28  */
29 public class VariableTableModel extends AbstractTableModel {
30
31         private static final Translator trans = Application.getTranslator();
32
33         private List<FlightDataType> types; // = new ArrayList<FlightDataType>();
34         private static final String[] columnNames = {trans.get("customExpression.Name"), trans.get("customExpression.Symbol"), trans.get("customExpression.Units")};
35         
36         /*
37          * Table model will be constructed with all the built in variables and any custom variables defined
38          */
39         public VariableTableModel(OpenRocketDocument doc){
40                 
41                 types = new ArrayList<FlightDataType>( doc.getFlightDataTypes() );
42                 
43                 //Collections.addAll(types, FlightDataType.ALL_TYPES);
44                 //for (CustomExpression expression : doc.getCustomExpressions()){
45                 //      types.add(expression.getType());
46                 //}
47         }
48         
49         @Override
50         public int getColumnCount() {
51                 return 3;
52         }
53
54         @Override
55         public int getRowCount() {
56                 return types.size();
57         }
58
59         @Override
60         public Object getValueAt(int row, int col) {
61                 if (col == 0)
62                         return types.get(row).getName();
63                 else if (col == 1)
64                         return types.get(row).getSymbol();
65                 else if (col == 2)
66                         return types.get(row).getUnitGroup().getSIUnit().toString();
67                 
68                 return null;
69         }
70         
71         @Override
72         public String getColumnName(int col) {
73         return columnNames[col];
74     }
75         
76         public String getSymbolAt(int row) {
77                 if (row < 0 || row > types.size()){
78                         return "";
79                 }
80                 else { 
81                         return types.get(row).getSymbol();
82                 }
83         }
84 }