Back to index

wims  3.65+svn20090927
Public Member Functions | Public Attributes | Package Functions | Package Attributes | Private Member Functions | Private Attributes
SharpTools.TableOp Class Reference

This contain certain higher level operations on the spreadsheet table such as sorting. More...

Inheritance diagram for SharpTools.TableOp:
Inheritance graph
[legend]
Collaboration diagram for SharpTools.TableOp:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void insert (boolean byRow)
void remove (boolean byRow)
void sort (boolean byRow)
void setColumnWidth ()
void setFirstColumnWidth ()
int getColumnWidth ()
void actionPerformed (ActionEvent e)
 This method is activated on the Keystrokes we are listening to in this implementation.

Public Attributes

SharpOptionPane sharpoptionpane

Package Functions

 TableOp (SharpTools sharp)

Package Attributes

final ImageIcon colwidthIcon = new ImageIcon(getClass().getResource("/images/colwidth.gif"))

Private Member Functions

void init (SharpTools sharp)
 init method.
boolean unsafeDeletion ()
void tooMuchDeletion ()

Private Attributes

SharpTools sharp
JTable table
SharpTableModel tableModel
History history
JToolBar toolBar

Detailed Description

This contain certain higher level operations on the spreadsheet table such as sorting.

Author:
Ricky Chin
Version:
Revision:
1.40

Definition at line 21 of file TableOp.java.


Constructor & Destructor Documentation

SharpTools.TableOp.TableOp ( SharpTools  sharp) [inline, package]

Definition at line 35 of file TableOp.java.

                              {
       init(sharp);
       sharp.checkFindNextState();
       
       // Identifying the Insert/Delete KeyStroke user can modify this
       // to some other Key combination.

       KeyStroke insertrow = KeyStroke.getKeyStroke
           (KeyEvent.VK_INSERT,
            ActionEvent.CTRL_MASK,
            false);

       KeyStroke insertcolumn = KeyStroke.getKeyStroke
           (KeyEvent.VK_INSERT,
            ActionEvent.CTRL_MASK|ActionEvent.SHIFT_MASK,
            false);

       KeyStroke deleterow = KeyStroke.getKeyStroke
           (KeyEvent.VK_DELETE,
            ActionEvent.CTRL_MASK,
            false);

       KeyStroke deletecolumn = KeyStroke.getKeyStroke
           (KeyEvent.VK_DELETE,
            ActionEvent.CTRL_MASK|ActionEvent.SHIFT_MASK,
            false);

       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Insert_Row"),insertrow,
                                 JComponent.WHEN_FOCUSED);

       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Insert_Column"),insertcolumn,
                                 JComponent.WHEN_FOCUSED);

       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Delete_Row"),deleterow,
                                 JComponent.WHEN_FOCUSED);

       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Delete_Column"),deletecolumn,
                                 JComponent.WHEN_FOCUSED);
       
    }

Here is the call graph for this function:


Member Function Documentation

void SharpTools.TableOp.actionPerformed ( ActionEvent  e) [inline]

This method is activated on the Keystrokes we are listening to in this implementation.

Here it listens for keystroke ActionCommands.

Without this listener, when we press certain keys the individual cell will be activated into editing mode in addition to the effect of the key accelerators we defined with menu items. With this key listener, we avoid this side effect.

Definition at line 333 of file TableOp.java.

                                               {

       if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Insert_Row"))==0) {
           insert(true);
       }
       else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Insert_Column"))==0) {
           insert(false);
       }      
       else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Delete_Row"))==0) {
           remove(true);
       }      
       else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Delete_Column"))==0) {
           remove(false);
       }             
    }

Here is the call graph for this function:

Definition at line 298 of file TableOp.java.

                               {
       int width=0;
       return width;
    }
void SharpTools.TableOp.init ( SharpTools  sharp) [inline, private]

init method.

Parameters:
sharpthe GUI object

Definition at line 81 of file TableOp.java.

Here is the caller graph for this function:

void SharpTools.TableOp.insert ( boolean  byRow) [inline]

Definition at line 91 of file TableOp.java.

                                      {
        //checks if anything is selected
       int insertNum = table.getSelectedRowCount();
        if (insertNum != 0) {
           
            if (byRow) {
              int row = table.getSelectedRow();
              CellRange range =
                  new CellRange(new CellPoint(row, SharpTools.baseCol),
                              new CellPoint(row+insertNum-1,
                                          tableModel.getColumnCount()-1));
              history.add(tableModel, range, History.INSERTROW);
               tableModel.insertRow(range);
            }
           else {
              insertNum = table.getSelectedColumnCount();
              int column = table.getSelectedColumn();
              CellRange range =
                  new CellRange(new CellPoint(SharpTools.baseRow, column),
                              new CellPoint(tableModel.getRowCount()-1,
                                          column+insertNum-1));

              history.add(tableModel, range, History.INSERTCOLUMN);
               tableModel.insertColumn(range);
                
            }
        }else { 
           sharp.noCellsSelected("Insert");
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.TableOp.remove ( boolean  byRow) [inline]

Definition at line 122 of file TableOp.java.

                                      {
       int removeNum = table.getSelectedRowCount();
       
        //checks if anything is selected
       
        if (removeNum != 0) {

            if (byRow) {

              if (removeNum == table.getRowCount()-1) {
                  tooMuchDeletion();
                  return;
              }
              
              int row = table.getSelectedRow();
              CellRange range =
                  new CellRange(new CellPoint(row, SharpTools.baseCol),
                              new CellPoint(row+removeNum-1,
                                          tableModel.getColumnCount()-1));

              if (tableModel.isDeletionSafe(range, true) || unsafeDeletion()) {
                  history.add(tableModel, range, History.REMOVEROW);
                  Debug.println(range);
                  tableModel.removeRow(range);
                    Debug.println("Delete row range "+range);
              }
            }
           else {
              int column = table.getSelectedColumn();

              removeNum = table.getSelectedColumnCount();

              if (removeNum == table.getColumnCount()-1) {
                  tooMuchDeletion();
                  return;
              }
              
              CellRange range =
                  new CellRange(new CellPoint(SharpTools.baseRow, column),
                              new CellPoint(tableModel.getRowCount()-1,
                                          column+removeNum-1));
                Debug.println("Delete column range "+range);
              if (tableModel.isDeletionSafe(range, false) || unsafeDeletion()) {
                  history.add(tableModel, range, History.REMOVECOLUMN);
                  Debug.println(range);
                  tableModel.removeColumn(range);
              }
            }        
              
        }else { 
           sharp.noCellsSelected(SharpTools.translation.getProperty("Remove"));
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 246 of file TableOp.java.

                                 {
       int width;
       if(!SharpTools.inapplet){
           width = SharpTools.getConfig().getInt("COLUMNWIDTH");
       }
       else
       {
           width = MainApplet.COLUMNWIDTH;
       }
        String inValue = JOptionPane.showInputDialog(SharpTools.translation.getProperty("Default_width")+"\n"+SharpTools.translation.getProperty("rem1")+":");
       //System.out.println("ingetiept:"+inValue);
       if (inValue != null) {
           try {
              int newwidth = Integer.parseInt(inValue,10);
              if (newwidth != width && newwidth>=0) {
                  if(!SharpTools.inapplet){
                     SharpTools.getConfig().setInt("COLUMNWIDTH", newwidth);
                  }
                  sharp.setColumnWidth(newwidth);
              }
           }
           catch (Exception e) {
           }
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 272 of file TableOp.java.

                                      {
       int width;
       if(!SharpTools.inapplet){
           width = SharpTools.getConfig().getInt("FIRSTCOLUMNWIDTH");
       }
       else
       {
           width = MainApplet.FIRSTCOLUMNWIDTH;
       }
        String inValue = JOptionPane.showInputDialog(SharpTools.translation.getProperty("Default_width")+"\n"+SharpTools.translation.getProperty("rem2")+":");
       //System.out.println("ingetiept:"+inValue);
       if (inValue != null) {
           try {
              int newwidth = Integer.parseInt(inValue,10);
              if (newwidth != width && newwidth>=0) {
                  if(!SharpTools.inapplet){
                     SharpTools.getConfig().setInt("FIRSTCOLUMNWIDTH", newwidth);
                  }
                  sharp.setBaseColumnWidth(newwidth);
              }
           }
           catch (Exception e) {
           }
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.TableOp.sort ( boolean  byRow) [inline]

Definition at line 176 of file TableOp.java.

                                    {
       //checks if anything is selected   
       if (table.getSelectedRowCount() != 0) { 
           CellRange range = new CellRange
              (table.getSelectedRows(), table.getSelectedColumns());
             

           //gets parameters for combo box in dialog
           Vector primary = new Vector();
           Vector secondary = new Vector();
            secondary.add("None");
           if (byRow) {
              for(int i = range.getStartRow(); i <= range.getEndRow(); i++) {
                  primary.add(SharpTools.translation.getProperty("Row")+" "+ Node.translateRow(i));
                  secondary.add(SharpTools.translation.getProperty("Row")+" "+ Node.translateRow(i));
              }
           }else {
              for(int i = range.getStartCol(); i <= range.getEndCol(); i++) {
                  primary.add(SharpTools.translation.getProperty("Column")+" "+ Node.translateColumn(i));
                  secondary.add(SharpTools.translation.getProperty("Column")+" "+ Node.translateColumn(i));
              }
           }

           //create and show the sort dialog
           SortDialog sortDialog = new SortDialog(sharp, primary, secondary);
           sortDialog.pack();
           sortDialog.setLocationRelativeTo(sharp);
           sortDialog.setVisible(true);
       
           
           Debug.println("Here we go " + sortDialog.getCriteriaA() + ": And : " + sortDialog.getCriteriaB());
           Debug.println(sortDialog.firstAscending() + " : " + sortDialog.secondAscending());
           int first = sortDialog.getCriteriaA();
           //check to see if there is sorting criteria
           if (first >= 0) {
                history.add(tableModel, range);    
              //translate first to col/row number
              if (byRow) {
                  first += range.getStartRow();
              }else {
                  first += range.getStartCol();
              }

              int second = sortDialog.getCriteriaB();
              //check to see if there is second sorting criteria
              if (second > 0) {
                  //translate second to col/row number
                  if (byRow) {
                     //takes into account "none" choice
                     second += range.getStartRow() - 1;
                  }else {
                     second += range.getStartCol() -  1;
                  }

                  tableModel.sort(range, first, second, byRow, 
                                sortDialog.firstAscending(),
                                sortDialog.secondAscending());
              }else {
                  //sort according to first only
                  tableModel.sort(range, first, first, byRow,
                                sortDialog.firstAscending(),
                                sortDialog.secondAscending());
              }
           }
       } else {
            sharp.noCellsSelected(SharpTools.translation.getProperty("Sort"));
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.TableOp.tooMuchDeletion ( ) [inline, private]

Definition at line 317 of file TableOp.java.

                                   {
        sharpoptionpane.showMessageDialog
           (sharp, SharpTools.translation.getProperty("rem5"),SharpTools.translation.getProperty("Delete"),
            JOptionPane.ERROR_MESSAGE);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 303 of file TableOp.java.

                                     {
        int choice = sharpoptionpane.showOptionDialog(
              sharp,
              SharpTools.translation.getProperty("rem4") +"\n"+SharpTools.translation.getProperty("rem3")+"\n\n",
              SharpTools.translation.getProperty("Delete"),
              JOptionPane.YES_NO_OPTION,
               JOptionPane.WARNING_MESSAGE,
               null, 
              1
           );

       return choice == JOptionPane.YES_OPTION;
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

final ImageIcon SharpTools.TableOp.colwidthIcon = new ImageIcon(getClass().getResource("/images/colwidth.gif")) [package]

Definition at line 30 of file TableOp.java.

Definition at line 28 of file TableOp.java.

Definition at line 24 of file TableOp.java.

Definition at line 25 of file TableOp.java.

JTable SharpTools.TableOp.table [private]

Definition at line 26 of file TableOp.java.

Definition at line 27 of file TableOp.java.

JToolBar SharpTools.TableOp.toolBar [private]

Definition at line 29 of file TableOp.java.


The documentation for this class was generated from the following file: