/*
* Copyright (C) 2011-2014 GeoForge Project
*
* This program 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 3 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.geoforge.guillc.panel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.logging.Logger;
import javax.swing.JTable;
import javax.swing.JViewport;
import javax.swing.ListSelectionModel;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import org.geoforge.guillc.scrollpane.GfrScr;
import org.geoforge.guillc.table.GfrTblAbs;
import org.geoforge.guillc.table.GfrTblEdit;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
* Should be refactored => remove "Sng"
*/
public class GfrPnlGrpSngTbl extends GfrPnlGrpAbs implements TableModelListener
{
final static public int INT_DEFAULT_HEIGHT = 150;
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrPnlGrpSngTbl.class.getName());
static
{
GfrPnlGrpSngTbl._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// ---
//-- beg private fields
private GfrScr _scrList_;
private GfrTblAbs _tblContent_ = null;
private TableModel _tml_ = null;
//-- end private fields
//-- beg public methods
public Object getValueAt(int row, int column)
{
return this._tblContent_.getValueAt(row, column);
}
public int getRowCount()
{
return this._tblContent_.getRowCount();
}
public int getColumnCount()
{
return this._tblContent_.getColumnCount();
}
public JTable getTable()
{
return this._tblContent_;
}
public TableColumnModel getColumnModel()
{
return this._tblContent_.getColumnModel();
}
public void setDefaultRenderer(Class<?> columnClass, TableCellRenderer renderer)
{
this._tblContent_.setDefaultRenderer(columnClass, renderer);
}
public ListSelectionModel getSelectionModel()
{
return this._tblContent_.getSelectionModel();
}
public GfrPnlGrpSngTbl(
String strWhat,
TableModel tml)
{
this(
strWhat,
GfrPnlGrpSngTbl.INT_DEFAULT_HEIGHT,
tml);
}
public GfrPnlGrpSngTbl(
String strWhat,
int sizeVertical,
TableModel tml)
{
super(
strWhat,
sizeVertical);
this._tblContent_ = new GfrTblEdit();
this._scrList_ = new GfrScr(this._tblContent_);
this._tblContent_.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
this._tml_ = tml;
if(this._tml_ != null)
this._tml_.addTableModelListener((TableModelListener) this);
}
public void setHeightTableHeader(final int intHeight)
{
JViewport vwp = new JViewport()
{
@Override
public Dimension getPreferredSize()
{
int intWidth = super.getPreferredSize().width;
Dimension dim = new Dimension(intWidth, intHeight);
return dim;
}
};
this._scrList_.setColumnHeader(vwp);
}
@Override
public boolean init()
{
if (!super.init())
return false;
if (!this._tblContent_.init())
return false;
if (!this._scrList_.init())
return false;
if (this._tml_ != null)
if (!((IGfrHandlerLifeCycleObject) this._tml_).init())
return false;
this.setMandatoryIcon(false);
if (this._tml_ != null)
this._tblContent_.setModel(this._tml_);
this._scrList_.setPreferredSize(
new Dimension(this.getWidthContent(), this.getHeightComponent()));
this._pnlContent.add(this._scrList_, BorderLayout.CENTER);
return true;
}
public void setTableModel(TableModel tml)
{
this._tblContent_.setModel(tml);
}
@Override
public void destroy()
{
super.destroy();
if (this._tblContent_ != null)
{
this._tblContent_.destroy();
this._tblContent_ = null;
}
if (this._scrList_ != null)
{
this._scrList_.destroy();
this._scrList_ = null;
}
}
@Override
public void tableChanged(TableModelEvent e)
{
int intType = e.getType();
if (intType != TableModelEvent.INSERT
&& intType != TableModelEvent.DELETE
&& intType != TableModelEvent.UPDATE)
{
GfrPnlGrpSngTbl._LOGGER_.warning("Uncaught type=" + intType);
}
super.firePanelUpdate();
}
//-- end public
}