📄 tablemodel.java
字号:
package net.aetherial.gis.surface.editTrackPoint;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import net.aetherial.gis.surface.ItemValue;
import java.text.DecimalFormat;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2004</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class TableModel extends AbstractTableModel{
private boolean dataEdit = false;
//private String[] columnNames = {"序号","经度","纬度","高度","时间","删除"};//same as before...
//private Object[][] data = {{"1","117.9999","34.8984","2","2005.1.31",new Boolean(true)},{"2","117.43499","35.5484","6","2005.1.31",new Boolean(true)}};//same as before...
private String[] columnNames = {"里程","经度","纬度","高度"};//same as before...
private Object[][] data = {{"1","117.9999","34.8984","2"},{"2","117.43499","35.5484","6"}};//same as before...
public TableModel() {
}
public TableModel(int tracks) {
Node node = ItemValue.getTracksByPos(tracks);
this.setData(node);
}
public TableModel(Node tracks) {
this.setData(tracks);
}
public void setDataEdited(){
this.dataEdit = true;
}
public boolean getDataEdit(){
return this.dataEdit;
}
public void setData(Node node){
NodeList nl = ItemValue.getTracksPoint(node);
int row = nl.getLength();
int column = 6;
data = new Object[row][column];
java.text.DecimalFormat format = new DecimalFormat("#.###");
double temp = 0;
for(int i = 0;i<row;i++){
if (i == 0) {
data[i][0] = format.format(temp);
}else{
temp = temp + this.getDis(nl.item(i),nl.item(i-1));
data[i][0] = format.format(temp);
}
data[i][1] = ItemValue.getTracksPointX(nl.item(i));
data[i][2] = ItemValue.getTracksPointY(nl.item(i));
data[i][3] = ItemValue.getTracksPointZ(nl.item(i));
data[i][4] = ItemValue.getTracksPointTime(nl.item(i));
data[i][5] = new Boolean(false);
}
}
private double getDis(Node thisPoint,Node lastPoint){
if (thisPoint == null || lastPoint == null) {
return 0;
}else{
return ItemValue.calculateDistanceBetween2Nodes1(thisPoint,
lastPoint) / 1000;
}
}
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
/*
* Don't need to implement this method unless your table's
* editable.
*/
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
//
// if (col < 2) {
// return false;
// } else {
// return true;
// }
return false;
}
/*
* Don't need to implement this method unless your table's
* data can change.
*/
public void setValueAt(Object value, int row, int col) {
data[row][col] = value;
fireTableCellUpdated(row, col);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -