package jp.co.nri.rid.search;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;
import javax.swing.table.TableColumn;

/**
 * 検索結果表示テーブルの、カラム幅の変更を監視し、保持するクラス
 *
 * @author t3-nishimura@nri.co.jp
 */
class SPColumnModelListener implements TableColumnModelListener {
    /** SCCS ID */
    private static final String SCCSID = "@(#)SPColumnModelListener.java";

    /** RCS ID */
    private static final String RCSID =
	"$Id: SPColumnModelListener.java,v 1.7 2003-06-26 16:09:39+09 nsmr Exp $";

    public void columnAdded(TableColumnModelEvent e) {
    }
    public void columnRemoved(TableColumnModelEvent e) {
    }
    public void columnSelectionChanged(ListSelectionEvent e) {
    }
    public void columnMoved(TableColumnModelEvent e) {
    }
    public void columnMarginChanged(ChangeEvent e) {
        /* イベントの発生元が SPTableColumnModel 以外ならば無視 */
        Object o = e.getSource();
        if (!(o instanceof SPTableColumnModel)) {
            return;
        }

        SPTableColumnModel columnModel = (SPTableColumnModel)o;
        int[] adjustedWidths = columnModel.getAdjustedWidths();

        if (adjustedWidths == null) {
            adjustedWidths = new int[columnModel.getColumnCount()];
        }

        for (int i = 0; i < adjustedWidths.length; i++) {
            TableColumn tableColumn = columnModel.getColumn(i);
            int index = tableColumn.getModelIndex();
            adjustedWidths[index] = tableColumn.getWidth();
        }
        columnModel.setAdjustedWidths(adjustedWidths);

    }
} /* class SPColumnModelListener */
