1 package edu.psu.geovista.app.spreadsheet.tools;
2
3 /*
4 * Description:
5 * Date: Mar 18, 2003
6 * Time: 2:15:21 PM
7 * @author Jin Chen
8 */
9
10 import edu.psu.geovista.app.spreadsheet.formula.Cell;
11
12 import javax.swing.*;
13 import javax.swing.table.TableColumnModel;
14 import javax.swing.table.TableColumn;
15 import java.awt.event.ActionListener;
16 import java.awt.event.ActionEvent;
17
18 import edu.psu.geovista.app.spreadsheet.table.SSTableModel;
19 import edu.psu.geovista.app.spreadsheet.table.SSTable;
20
21 /***
22 * For now just insert 1 column
23 */
24 public class AddColumn implements ActionListener{
25 int NumOfInsert=1;//Number of Column to be inserted. for now just insert one column each time
26 SSTableModel tbm;
27 SSTable tb;
28 public AddColumn(SSTable tb) {
29 this.tb=tb;
30 tbm=(SSTableModel)tb.getModel();
31 //tbm=(SSTableModel) SSTableModel.getInstance() ;
32
33 }
34
35 public void actionPerformed (ActionEvent e){
36
37 TableColumnModel tcm = tb.getColumnModel();
38 int col=tb.getSelectedColumn() ;
39 TableColumn selectedColumn;
40 int lastCol=tb.getColumnCount()-1;
41 if (col==-1){
42 selectedColumn = tcm.getColumn(lastCol);
43
44 }
45 else if(col==0){//can't insert before the first column
46 //JOptionPane.showInternalMessageDialog(tb,"Can't insert a column before the first column");
47 return;
48
49 }
50 else{//Select no column, by default select the last column
51 selectedColumn = tcm.getColumn(col);
52 }
53
54
55 for (int i=0;i<NumOfInsert;i++){
56 int newColIndex=lastCol+i+1;
57 TableColumn newCol=new TableColumn(newColIndex,selectedColumn.getWidth() );
58 tcm.addColumn(newCol);
59 tbm.addColumn(newCol.getHeaderValue()) ;
60 if (col!=-1){ //select a column
61 lastCol=tb.getColumnCount()-1;
62 this.tb.moveColumn(lastCol,col); //This a TABLE do moveColumn, NOT tablModel
63 }
64 }
65 tb.reSetColumnHeader() ;
66 //Reset Header
67 //TableColumnModel tcmd=tb.getColumnModel() ;
68 /*
69 for (int i=1;i< tcm.getColumnCount() ;i++){
70 TableColumn tbcol=tcm.getColumn(i);
71 tbcol.setHeaderValue(Cell.translateColumn(i) );
72 } */
73
74 }
75
76 }
This page was automatically generated by Maven