All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.meteoinfo.table.DataTableModel Maven / Gradle / Ivy

/* Copyright 2012 Yaqiang Wang,
 * [email protected]
 * 
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 * 
 * This library 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 Lesser
 * General Public License for more details.
 */
package org.meteoinfo.table;

import org.meteoinfo.ndarray.DataType;
import javax.swing.table.AbstractTableModel;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 *
 * @author yaqiang
 */
public class DataTableModel extends AbstractTableModel {

    // 
    private DataTable _dataTable;
    // 
    // 
    /**
     * Constructor
     * @param dataTable Data table
     */
    public DataTableModel(DataTable dataTable){
        _dataTable = dataTable;        
    }
    // 
    // 
    // 
    //     
    @Override
    public int getRowCount() {
        return _dataTable.getRowCount();
    }

    @Override
    public int getColumnCount() {
        return _dataTable.getColumnCount();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        if (_dataTable.getColumns().get(columnIndex).getDataType() == DataType.DATE){
            DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            return format.format((LocalDateTime)_dataTable.getValue(rowIndex, columnIndex));
        } else 
            return _dataTable.getValue(rowIndex, columnIndex);
    }    
    
    @Override
    public void setValueAt(Object value, int row, int column){
        _dataTable.setValue(row, column, value);
    }
    
    @Override
    public String getColumnName(int columnIndex){
        return _dataTable.getColumns().get(columnIndex).getColumnName();
    }
    
    @Override
    public boolean isCellEditable(int row, int column){
        return false;
    }
    
    public void addColumn(DataColumn col){
        this._dataTable.addColumn(col);
    }
    // 
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy