package DataLoader; import java.util.*; import javax.swing.*; import javax.swing.table.*; import java.util.regex.*; import java.awt.event.*; import java.awt.Point; import java.awt.Component; //----------------------------------------------------------------------------------------------- public class VariableTable extends JTable implements MouseListener, ActionListener{ //----------------------------------------------------------------------------------------------- private static String SET_VALUE= "Set Value"; private Vector selectedCells = new Vector(); private DefaultTableModel model; //----------------------------------------------------------------------------------------------- public VariableTable(int row, int rowHeight) { super (); model = new VariableTableModel(); this.setModel(model); for (int m=0;m0) model.setColumnCount( cols-1 ); } //----------------------------------------------------------------------------------------------- public String getColumnHeader(int index) { if (index >= this.getColumnCount()) { return null; }else { TableColumn tc = ((TableColumnModel)this.getColumnModel()).getColumn(index); return (String)tc.getHeaderValue(); } } //----------------------------------------------------------------------------------------------- public void mouseClicked(MouseEvent e) {} //----------------------------------------------------------------------------------------------- public void mousePressed(MouseEvent e) {} //----------------------------------------------------------------------------------------------- public void mouseEntered(MouseEvent e) {} //----------------------------------------------------------------------------------------------- public void mouseExited(MouseEvent e) {} //----------------------------------------------------------------------------------------------- public void mouseReleased(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { Point p = e.getPoint(); int tableRow = this.rowAtPoint(p); int tableCol = this.columnAtPoint(p); if (isCellSelected(tableRow, tableCol)){ int rowIndexStart = this.getSelectedRow (); int rowIndexEnd = this.getSelectionModel().getMaxSelectionIndex(); int colIndexStart = this.getSelectedColumn(); int colIndexEnd = this.getColumnModel().getSelectionModel().getMaxSelectionIndex(); if (colIndexStart != colIndexEnd){ JOptionPane.showMessageDialog(this, "Multiple Variables Selected.\n\n"+ "Please choose only one variable "); return; } JPopupMenu menu = new JPopupMenu(); JMenuItem item= new JMenuItem("Set Value..."); item.setActionCommand(SET_VALUE); item.addActionListener(this); menu.add(item); menu.setLightWeightPopupEnabled(false); menu.show(this, e.getX(), e.getY()); } } } //----------------------------------------------------------------------------------------------- public void actionPerformed (ActionEvent e) { String command = e.getActionCommand(); if (SET_VALUE.equals(command)){ String newValue = JOptionPane.showInputDialog(this, "Set Value To: "); for (int h=0; h