-
Notifications
You must be signed in to change notification settings - Fork 2
/
WaypointsTableModel.java
143 lines (127 loc) · 4.36 KB
/
WaypointsTableModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* --------------------------------------------------------------
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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.
*
* --------------------------------------------------------------
*
* (c) 2006 by Tomo Krajina, aaa@puzz.info
*
*/
package info.puzz.trackprofiler.gui;
import info.puzz.trackprofiler.Messages;
import info.puzz.trackprofiler.TrackProfilerException;
import info.puzz.trackprofiler.appobjects.Track;
import info.puzz.trackprofiler.appobjects.Waypoint;
import info.puzz.trackprofiler.util.Message;
import info.puzz.trackprofiler.util.TrackProfilerMath;
import javax.swing.table.AbstractTableModel;
public class WaypointsTableModel extends AbstractTableModel {
public WaypointsTableModel() {
super();
if( this.getCurrentTrack() != null ) {
this.getCurrentTrack().sortWaypointsByDistance();
}
}
public int getRowCount() {
if ( this.getCurrentTrack() != null ) {
return this.getCurrentTrack().getWaypoints().size();
}
return 0;
}
public int getColumnCount() {
return 6;
}
public String getColumnName(int column) {
if( column == 0 ) {
return new Message( Messages.VISIBILITY ).toString();
}
else if( column == 1 ) {
return new Message( Messages.TITLE ).toString();
}
else if( column == 2 ) {
return new Message( Messages.DESCRIPTION ).toString();
}
else if( column == 3 ) {
return new Message( Messages.POSITION ).toString();
}
else if( column == 4 ) {
return new Message( Messages.ELEVATION ).toString();
}
return new Message( Messages.WAYPOINT_ARROW_LENGTH ).toString();
}
public Object getValueAt(int rowIndex, int columnIndex) {
Waypoint wpt = (Waypoint) this.getCurrentTrack().getWaypoints().get(rowIndex);
if (columnIndex == 0) {
return new Boolean( wpt.isVisible() );
}
else if (columnIndex == 1) {
return wpt.getTitle();
}
else if (columnIndex == 2) {
return wpt.getDescription();
}
else if (columnIndex == 3) {
return new Double( TrackProfilerMath.round(wpt.getFirstPositionOnTrack(),2) );
}
else if( columnIndex == 4 ) {
return new Double( TrackProfilerMath.round(wpt.getElevation(),2) );
}
return new Double( wpt.getArrowLength() );
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex != 3;
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
Waypoint wpt = (Waypoint) this.getCurrentTrack().getWaypoints().get(rowIndex);
if ( columnIndex == 0 ) {
boolean b = ( (Boolean) aValue ).booleanValue();
wpt.setVisible( b );
}
else if( columnIndex == 1 ) {
wpt.setTitle( (String) aValue );
}
else if( columnIndex == 2 ){
wpt.setDescription( (String) aValue );
}
else if( columnIndex == 3 ){
// wpt.setPositionOnTrack( ( (Double) aValue ).doubleValue() );
}
else if ( columnIndex == 4 ) {
wpt.setElevation( ( (Double) aValue ).doubleValue() );
}
else {
wpt.setArrowLength( ( (Integer) aValue ).intValue() );
}
try {
TrackProfilerFrame.getInstance().drawChart();
}
catch ( TrackProfilerException e ) {
e.printStackTrace();
}
this.fireTableCellUpdated( rowIndex, columnIndex );
}
public Class/*<?>*/ getColumnClass(int columnIndex) {
if (columnIndex == 0) {
return Boolean.class;
}
if( columnIndex == 1 || columnIndex == 2 ) {
return String.class;
}
if( columnIndex == 4 ) {
return Double.class;
}
return Integer.class;
}
private Track getCurrentTrack() {
return TrackProfilerFrame.getInstance().getTrack();
}
}