Back to index

wims  3.65+svn20090927
Public Member Functions | Static Public Member Functions | Protected Member Functions | Package Functions | Private Member Functions | Static Private Member Functions | Private Attributes
SharpTools.SharpTableModel Class Reference

This is the table data structure of the spreadsheet (i.e. More...

Collaboration diagram for SharpTools.SharpTableModel:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SharpTableModel (SharpTools sharp)
 Constructs a default SharpTableModel which is a table of zero columns and zeros rows.
 SharpTableModel (SharpTools sharp, int numRows, int numColumns)
 This constructor creates an empty table with numRow rows and numCol columns including the row and column label row and column.
 SharpTableModel (SharpTools sharp, Object[][] data)
 This constructor is convenience for loading objects that are already in an array.
String getColumnName (int col)
 This is used to return the column name.
Cell getCellAt (int aRow, int aColumn)
 This method gets the whole Cell object located at the these coordinates.
Object getValueAt (int aRow, int aColumn)
 This class returns the cell object at those coordinates.
void recalculate (int aRow, int aColumn)
 This is a warper method of the Formula class's evaluate method.
void recalculate (CellPoint x)
 This is the version of recalculate that takes a CellPoint object as an argument.
void setValueAt (Object aValue, int aRow, int aColumn)
 Sets the value of the cell.
void doSetValueAt (Object aValue, int aRow, int aColumn)
 This method sets the value of the cell specified with these coordinates to aValue.
void setCellAt (Object input, int aRow, int aColumn)
 This object assumes that the object passes to it is already the correct object to set the value of the cell as.
void setRange (CellRange range, Object[][] data)
 This method sets the cells given by the range to the cooresponding value in the Object array.
void setRange (CellRange range, Cell[][] data, boolean byValue)
 This is a method used to paste cells onto the table.
void clearRange (CellRange range)
 This method clears all cells in the range but leaves the reference lists alone.
CellPoint look (CellPoint begin, Object goal, boolean matchCase, boolean matchCell)
 This searches of an object starting from a cell point.
Cell[][] getRange (CellRange range)
 This method copies the cells in a range into a two-dimensional array of cells.
void addRefs (int aRow, int aColumn)
 This method should be called with a cell is set as a formula cell (although it does nothing if it is not a formula).
void removeRefs (int aRow, int aColumn)
 This method removes this formula cell from the reference lists of all cells it references.
void updateRefs (int aRow, int aColumn)
 This method updates the values of all cells that reference this one.
void recalculateAll ()
 This method recalculates all cells in the table.
void removeColumn (CellRange deletionRange)
 This method removes columns in the range.
void insertColumn (CellRange insertRange)
 This method inserts columns to the left of the range with the number of new columns equal to the number of columns in the range.
void removeRow (CellRange deletionRange)
 This method removes rows in the range.
void insertRow (CellRange insertRange)
 This method inserts rows to the left of range.
Number getNumericValueAt (int row, int col) throws ParserException
 This implements a needed class to work with the Formula class.
boolean isFormula (int aRow, int aColumn)
 Determines if a cell at these coordinates is a formula cell.
boolean isCellEditable (int row, int column)
 All Cells other than those in row 0 or column 0 are editable.
Class getColumnClass (int c)
 JTable uses this method to determine the default renderer editor for each cell.
void setModified (boolean modified)
 Sets modified state of current document.
void setPasswordModified (boolean modified)
 Sets modified state of password; can't undo.
boolean isModified ()
 Returns modified state of document.
JTable getTable ()
 Returns JTable.
void setSelection (CellRange sel)
 set table selection to the range sel
boolean isDeletionSafe (CellRange range, boolean byRow)
 check whether the deletion is safe
String toString (CellRange range, boolean byValue)
 toString is used to convert a range of cells into a string.
String to_WIMS (CellRange range, boolean byValue, boolean matrix)
String toString ()
 convert the whole table to a string.
String toWIMS (boolean matrix)
void sort (CellRange area, int primary, int second, boolean isRow, boolean ascend, boolean tiebreaker)
 This method sorts an arbitrary range in the table.
boolean isEmptyCell (int row, int col)
 Determines if a cell is empty.

Static Public Member Functions

static Object fieldParser (String input)
 This method does not recognize formula strings.
static CellPoint getSize (String input)
 From a string input determine how many rows/columns it requires for the table - it corresponds to the number of newlines and tabs.

Protected Member Functions

void fillRange (CellRange range, String s)
void fill (CellRange range, Object input)
 This method is used to implement the fills of the spreadsheet.

Package Functions

void setHistory (History h)
 This method associated the proper undo object to this SharpTableModel.
void fromString (String text, int rowOff, int colOff, CellRange range)
 fromString is used to convert a string to valus in a range of cells.

Private Member Functions

TreeSet getRefs (int row, int col)
 This method gets the set of cells that will be affects by a value change for the cpecified cell.
void getRefs (int row, int col, TreeSet set)
 This method is a helper method for getReds(int, int).
void removeColumn ()
void addColumn ()
 Helper method for insertColumn.
void addRow ()
 Adds row to end of table.
boolean isLoop (CellPoint cell)
 Starting from cell, detect potential reference loops.
boolean isLoop (CellPoint cell, TreeSet set)
 Starting from cell, detect potential reference loops.
int compareLines (int primary, boolean isRow, boolean ascending, int i, int j)
 This is a helper function that compares rows or columns.
Cell getCriteria (int interest, int i, boolean isRow)
 used to make sorting method and helper methods for sort treat row sorting the same as column sorting.
boolean rightOrder (int primary, int second, boolean isRow, int i, int j, boolean ascend, boolean order)
 Determines if cells are in the wrong order Used only as helper method for sort.
int[] internalSort (CellRange area, int primary, int second, boolean isRow, boolean ascend, boolean tiebreaker)
 Helper for sort that does the sorting.

Static Private Member Functions

static Object fieldParser (String input, CellPoint c)
 This is a static method that parses string input passed to it from somewhere else.

Private Attributes

boolean modified
 Stores modified state of document.
boolean passwordModified
 true if password has been changed
SharpTools sharp
 Stores file name of current document.
History history
 holds the history information for the table

Detailed Description

This is the table data structure of the spreadsheet (i.e.

the heart of the backend). Although this class implements the methods needed for TableModel, it also has methods for maintaining dependencies and some data manipulation.

Note: This structure only holds Cell objects! It's methods take into account the Cell object. If you modified the cell class please check the methods in this class.

Author:
Ricky Chin
Version:
Revision:
1.91

Definition at line 29 of file SharpTableModel.java.


Constructor & Destructor Documentation

Constructs a default SharpTableModel which is a table of zero columns and zeros rows.

Parameters:
sharpthe gui component to tie it to

Definition at line 48 of file SharpTableModel.java.

                                             {
        super();

       // initialize state to unmodified and file to untitled
       modified = false;
       this.sharp = sharp;
    }
SharpTools.SharpTableModel.SharpTableModel ( SharpTools  sharp,
int  numRows,
int  numColumns 
) [inline]

This constructor creates an empty table with numRow rows and numCol columns including the row and column label row and column.

The zeroth column are headers. The rows are numbered 1, 2, ... and columns are labeled A, B, ... . Thus, it really holds numRow X numCol-1 of data. The table is initialized with no cell objects. Each coordinate that will have data will have a cell object created for it later by the getCell method.

Parameters:
sharpgui object to associated with this SharpTableModel
numRowstotal number of rows including row header
numColumnstotal number of columns including column header

Definition at line 68 of file SharpTableModel.java.

                                                                          {
       
        super(numRows, numColumns+1);
        //initialize row headers
       for(int row = SharpTools.baseRow; row < numRows; row++) {
            Cell temp = new Cell(new Integer(row+1));
            super.setValueAt(temp, row, 0);
        }

        //initialize column headers
       /*
       for (int col = 1; col < numColumns; col++) {
           Cell temp = new Cell(Node.translateColumn(col));
           super.setValueAt(temp, 0, col);
       }
       */
        for(int row = SharpTools.baseRow; row < numRows; row++)
           for (int col = SharpTools.baseCol; col < numColumns+1; col++)
              // we initialize it here
              super.setValueAt(new Cell(""), row, col);

        // initialize state to unmodified and file to untitled
       modified = false;
       this.sharp = sharp;
    }
SharpTools.SharpTableModel.SharpTableModel ( SharpTools  sharp,
Object  data[][] 
) [inline]

This constructor is convenience for loading objects that are already in an array.

It fills the SharpTableModel with the objects in the array making Object[0][0] be in cell A1, etc.

Note: This constructor does not assume that objects are of the desired form. It will parse a string to see if it is a number or formula.

Parameters:
sharpgui object to associate with this SharpTableModel
datathe array of objects to place into the SharpTableModel

Definition at line 104 of file SharpTableModel.java.

                                                              {

        this(sharp, data.length + SharpTools.baseRow/*+ 1*/,
            data[0].length + SharpTools.baseCol);

        /* load the data */
        for(int i = SharpTools.baseRow; i < data.length; i++) {
            for(int j = SharpTools.baseCol; j < data[i].length; j++) {
                doSetValueAt(data[i][j], i, j);
            }
        }

        // initialize state to unmodified and file to untitled
       modified = false;
       //     file = new File("Untitled");
       this.sharp = sharp;
    }

Here is the call graph for this function:


Member Function Documentation

void SharpTools.SharpTableModel.addColumn ( ) [inline, private]

Helper method for insertColumn.

This method will not send the appropriate notification to JTable. Please use insertColumn method instead.

Definition at line 971 of file SharpTableModel.java.

                             {
        
        columnIdentifiers.addElement(null);

        /* Initialize the new column */
        Iterator it = dataVector.iterator();
        
        //Give column the appropriate label 
        if (it.hasNext()) {
            Cell temp = new Cell(Node.translateColumn(getColumnCount() - 1));
            ((Vector)it.next()).addElement(temp);
        }
        
        //initialize cells
        while (it.hasNext()) {
            ((Vector)it.next()).addElement(new Cell(""));
        }

        // Generate notification
       /*        newColumnsAdded(new TableModelEvent(this, 0, getRowCount() - 1,
                getColumnCount() - 1, TableModelEvent.INSERT));
       */
    }    

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.addRefs ( int  aRow,
int  aColumn 
) [inline]

This method should be called with a cell is set as a formula cell (although it does nothing if it is not a formula).

When a formula is entered, it may reference other cells. These cells need to be notified that if they are changed, to notify this formula cell. This method adds the cell coordinates to the reference list of each cell that the formula references.

Parameters:
aRowrow of formula cell
aColumncolumn of formula cell

Definition at line 675 of file SharpTableModel.java.

                                               {
        if (isFormula(aRow, aColumn)) {
            Formula temp = getCellAt(aRow, aColumn).getFormula();
            TreeSet list = temp.getDependency();
         
            /* use formula's dependency to find cells
             * that need to notify it if their values
             * change
             */
            Iterator it = list.iterator();
           CellPoint thisRef = new CellPoint(aRow, aColumn);
           while (it.hasNext()) {
                CellPoint update = (CellPoint)it.next();
              Cell field = getCellAt(update.getRow(), update.getCol());
              
                //test of cell found was out of bounds
              if (field != null)
                  field.addRef(thisRef);
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.addRow ( ) [inline, private]

Adds row to end of table.

Definition at line 1084 of file SharpTableModel.java.

                          {
        
        //create a new row with appropriate label
        Vector rowData = new Vector();
        rowData.add(0, new Cell(new Integer(getRowCount() + 1)));
        
        //add it to the table
        super.addRow(rowData);
        
        for(int i = 1; i < getColumnCount(); i++) {
            super.setValueAt(new Cell(""), getRowCount() - 1, i);
        }
    }

Here is the caller graph for this function:

This method clears all cells in the range but leaves the reference lists alone.

Parameters:
rangerange to clear

Definition at line 506 of file SharpTableModel.java.

                                            {           
        fill(range, null);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

int SharpTools.SharpTableModel.compareLines ( int  primary,
boolean  isRow,
boolean  ascending,
int  i,
int  j 
) [inline, private]

This is a helper function that compares rows or columns.

Parameters:
dataan array of cells
primaryfirst criteria to sort by
secondarysecond criteria to sort by (set to -1 if not specified)
isRowtrue if the criteria are rows
icolumn or row you are comparing
jcolumn or row to compare i to
Returns:
-1 if i < j, 0 if i = j, 1 if i > j

Definition at line 1620 of file SharpTableModel.java.

                                           {
 
            Cell x = getCriteria(primary, i, isRow);
            Cell y = getCriteria(primary, j, isRow);
            return x.compare(y, ascending);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.doSetValueAt ( Object  aValue,
int  aRow,
int  aColumn 
) [inline]

This method sets the value of the cell specified with these coordinates to aValue.

It does the parsing of string objects to see if they are numbers or formulas. If you do not want any parsing at all, use setCellAt.

Parameters:
aValuevalue to set cell to
aRowrow coordinate of cell
aColumncolumn coordinate of cell

Definition at line 313 of file SharpTableModel.java.

                                                                   {

       if (aValue == null)
           aValue = new String("");       
       
       if (aValue instanceof String) {

           String input = (String)aValue;
           
           /* try making it a formula */
           if (input.startsWith("=")) {
              Formula form = null;     
              
              //create formula and its value and put in a cell
              try {
                  form = new Formula(input.substring(1),
                                   aRow, aColumn);
                  setCellAt(form, aRow, aColumn);
              }
              catch (ParserException e) {
                  // no parsing
                  form = new Formula(input.substring(1), aRow, aColumn, e);
                  setCellAt(form, aRow, aColumn);
                  getCellAt(aRow, aColumn).setValue(e);
              }
              
           }else {

              //                try {
              //                Integer idata = new Integer(input);
              //                setCellAt(idata, aRow, aColumn);
              //            }
                
                /* if it begins with "=" but invalid just
                 * treat as a string
                 */
              
              //            catch (NumberFormatException e) {
                  /* try making it a number */
                  try {
                     Float data = new Float(input);
                     setCellAt(data, aRow, aColumn);
                  }
                
                  /* if it begins with "=" but invalid just
                   * treat as a string
                   */
              
                  catch (NumberFormatException e2) {
                     /* all else fails treat as string */
                     setCellAt(aValue, aRow, aColumn);
                  }
                  //        }
           }
        }else {
            /* it is an object, assume it is exactly
             * what should the cell be set to
             */
            if (aValue instanceof Formula) {
                try {
                  Formula form = (Formula)aValue;
                  setCellAt(new Formula(form, aRow, aColumn), aRow, aColumn);
                }catch (ParserException e) {
                   //           errorMessage(e.toString());
                    Formula form2 = (Formula)aValue;
                    form2 = new Formula(form2.toString(), aRow, aColumn, e);
                  setCellAt(form2, aRow, aColumn);
                  getCellAt(aRow, aColumn).setValue(e);
                }
            }else {           
                setCellAt(aValue, aRow, aColumn);
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static Object SharpTools.SharpTableModel.fieldParser ( String  input,
CellPoint  c 
) [inline, static, private]

This is a static method that parses string input passed to it from somewhere else.

It parses the input and returns the appropriate object including formula object. It is used to create appropriate objects to pass to the other methods in table model.

Parameters:
inputthe input string to parse
cthe point in table where this input to be placed
Returns:
the appropriate object after parsing

Definition at line 230 of file SharpTableModel.java.

                                                                 {
        if (input == null)
           return new String("");  
       
        int row = c.getRow();
        int col = c.getCol();
        
       /* try making it a formula */
       if (input.startsWith("=")) {
           Formula form = null;        
       
            //create formula and its value and put in a cell
           try {
               return new Formula(input.substring(1), row, col);
            }catch (ParserException e) {
              // no parsing
              return new Formula(input.substring(1), row, col, e);
           }
              
        }else {       
           /* try making it a number */
           try {
              //            try {
              //                return new Integer(input);
              //            }
              //            catch (NumberFormatException e) {
                  return new Float(input);
                  //        }
            }catch (NumberFormatException e2) {
              /* all else fails treat as string */
              return input;
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static Object SharpTools.SharpTableModel.fieldParser ( String  input) [inline, static]

This method does not recognize formula strings.

It is used for dialogue box input where there will be no formulas inputted or expected to be inputted.

Parameters:
inputinput string to parse
Returns:
appropriate object after parsing

Definition at line 271 of file SharpTableModel.java.

                                                   {
        if (input == null)
           return new String("");  
       
       /* try making it a number */
       try {
           return new Float(input);
        }catch (NumberFormatException e) {
           /* all else fails treat as string */
           return input;
        }
    }
void SharpTools.SharpTableModel.fill ( CellRange  range,
Object  input 
) [inline, protected]

This method is used to implement the fills of the spreadsheet.

It takes a range and fills the range with the object. For formula, it is equivalent to pasting the formula on every cell in the range.

Parameters:
rangerange to fill
inputobject to fill range with

Definition at line 523 of file SharpTableModel.java.

                                                       {
        
        //loop through range
        for (int i = range.getStartRow(); i <= range.getEndRow(); i++) {
            for (int j = range.getStartCol(); j <= range.getEndCol(); j++) {
                doSetValueAt(input, i, j);
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.fillRange ( CellRange  range,
String  s 
) [inline, protected]

Definition at line 511 of file SharpTableModel.java.

                                                        {
        fill(range, SharpTableModel.fieldParser(s, range.getminCorner()));
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.fromString ( String  text,
int  rowOff,
int  colOff,
CellRange  range 
) [inline, package]

fromString is used to convert a string to valus in a range of cells.

One row per line, and each column is tab-delimited.

Parameters:
textthe string
rowOffthe row offset
colOffthe column offset
rangethe range to paste
See also:
Formula::fixRelAddr
FileOp::openTableModel
EditOp::paste
SharpClipboard

Definition at line 1424 of file SharpTableModel.java.

                                                                          {

       try {
           BufferedReader in = new BufferedReader(new StringReader(text));
           String line;
           int row = range.getStartRow();
       
           while (row <= range.getEndRow()) {
              line = in.readLine();
              
              int index;
              int prev = 0;
              
              // set col to startCol before each loop
              int col = range.getStartCol();
              String value;
              
              while (col <= range.getEndCol()) {
                  index = line.indexOf('\t', prev);
                  if (index >= 0) {
                     value = line.substring(prev, index);
                  }
                  else {
                     value = line.substring(prev);
                  }
                  
                  if (value.startsWith("=")) {
                            // need to fix relative address
                     value = 
                         Formula.fixRelAddr(value.substring(1),
                                          rowOff, colOff);
                     if (value == null)
                         value = new String("=$REFS$0");
                     else
                         value = "="+value;
                  }
                  
                  doSetValueAt(value, row, col);
                  
                  prev = index+1;
                  // increment column number
                  col++;
                  
                  if (index == -1)
                     break;
              }
              
              row++;
           }
       }
       catch (Exception e) {           
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Cell SharpTools.SharpTableModel.getCellAt ( int  aRow,
int  aColumn 
) [inline]

This method gets the whole Cell object located at the these coordinates.

This method avoids the casting required when using getValueAt.

Note: here we need to make row 1-based.

If the coordinates specify a cell that is out of bounds then it returns null. If a cell does not exist in the SharpTableModel at that valid coordinate, it creates an empty cell, places it at that spot and returns it.

Parameters:
aRowthe row of the cell
aColumnthe column of the cell
Returns:
the Cell object at this location

Definition at line 158 of file SharpTableModel.java.

                                                 {
       
        /* check for out of bounds */
       if (aRow < 0 || aRow >= getRowCount() ||
           aColumn < 0 || aColumn >= getColumnCount()) {
           return null;
       }

        Cell temp = (Cell)super.getValueAt(aRow, aColumn);
       
       return temp;
    }

Here is the caller graph for this function:

Class SharpTools.SharpTableModel.getColumnClass ( int  c) [inline]

JTable uses this method to determine the default renderer editor for each cell.

This method tells JTable to use SharpCellRender and SharpCellEditor.

Parameters:
cthe column for which we need to determine the class
Returns:
Cell class

Definition at line 1178 of file SharpTableModel.java.

                                       {
        
        /* only cell objects in this TableModel */
        return Cell.class;
    }    
String SharpTools.SharpTableModel.getColumnName ( int  col) [inline]

This is used to return the column name.

Definition at line 125 of file SharpTableModel.java.

                                         {
       Debug.println("name of column "+col);
       if (col < SharpTools.baseCol)
           return "";
       else
           return String.valueOf(Node.translateColumn(col));
    }

Here is the call graph for this function:

Cell SharpTools.SharpTableModel.getCriteria ( int  interest,
int  i,
boolean  isRow 
) [inline, private]

used to make sorting method and helper methods for sort treat row sorting the same as column sorting.

Parameters:
interestcriteria coordinate for sort
iother coordinate
isRowtrue if coordinates are in form (row,col)
Returns:
cell at those coordinates

Definition at line 1635 of file SharpTableModel.java.

                                                {
       if (isRow) {
           return getCellAt(interest, i);
       }else {
           return getCellAt(i, interest);
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Number SharpTools.SharpTableModel.getNumericValueAt ( int  row,
int  col 
) throws ParserException [inline]

This implements a needed class to work with the Formula class.

If it is a data cell, it returns the numerical value of the cell (for a String the value is 0). If it is a formula, then it recalculates the value and returns that as an answer.

Parameters:
rowrow coordinate
colcolumn coordinate
Exceptions:
ParserExceptionif the value doesn't parse
Returns:
numerical value of the cell

Definition at line 1110 of file SharpTableModel.java.

                                                                             {
        Cell cell = getCellAt(row, col);
       if (cell != null) {
           int type = cell.getType();
           if (type == Cell.FORMULA) {
              Object value = cell.getValue();
              Formula form = cell.getFormula();
              // if need recalc
              if (form.needsRecalc()) {
                  try {
                     value = form.evaluate(this, row, col);
                     cell.setValue(value);
                  }
                  catch (ParserException e) {
                     cell.setValue(e);
                     value = e;
                  }         
              }
              
              if (value instanceof ParserException)
                  throw (ParserException)value;
              else
                  return (Number)cell.getValue();
           }
           else if (type == Cell.NUMBER)
              return (Number)cell.getValue();
           else
              return new Float(0);
       }
       else
       // a string or null
       //     return new Float(0);
           throw new ParserException("#REFS?");

    }

Here is the call graph for this function:

Here is the caller graph for this function:

This method copies the cells in a range into a two-dimensional array of cells.

Parameters:
rangerange of cells to copy
Returns:
copy of range

Definition at line 627 of file SharpTableModel.java.

                                              {
        
        //get dimensions of range
        Cell[][] board = new Cell[range.getHeight()][range.getWidth()];
        
        //copy the cells    
        for (int i = range.getStartRow(); i <= range.getEndRow(); i++) {
            for (int j = range.getStartCol(); j <= range.getEndCol(); j++) {
                
                //translate to coordinates in copy array
                int x = i - range.getStartRow();
                int y = j - range.getStartCol();
                
                Cell field = getCellAt(i, j);
             
                /* if it is a formula copy both the value and the formula
                 * The value will be useful with a paste by value 
                 */
                if (field.isFormula()) {
                    try {
                        Formula form = new Formula(field.getFormula(), i, j);
                        board[x][y] = new Cell(form, field.getValue(), null);
                    }catch (ParserException e) {
                        /* if there is a problem, always treat formula
                         * as a string.
                         */
                        board[x][y] = new Cell(field.getFormula().toString());
                    }
                }else {
                    //value cells have immutable objects
                    board[x][y] = new Cell(field.getValue());
                }
            }
        }
        return board;
    }

Here is the call graph for this function:

TreeSet SharpTools.SharpTableModel.getRefs ( int  row,
int  col 
) [inline, private]

This method gets the set of cells that will be affects by a value change for the cpecified cell.

Parameters:
rowthe row
colthe column

Definition at line 780 of file SharpTableModel.java.

                                              {
       TreeSet set = new TreeSet();
       getRefs(row, col, set);
       return set;
    }

Here is the caller graph for this function:

void SharpTools.SharpTableModel.getRefs ( int  row,
int  col,
TreeSet  set 
) [inline, private]

This method is a helper method for getReds(int, int).

It recursively gets refs for each cell and merges it into the set.

Parameters:
rowthe row
colthe column
setthe current of cells

Definition at line 796 of file SharpTableModel.java.

                                                        {

       Cell cell = getCellAt(row, col);
       if (cell == null || !cell.hasRefs())
           return;
       
       Iterator it = cell.getRefs().iterator();
       while (it.hasNext()) {
           CellPoint point = (CellPoint)it.next();
           set.add(point);
           getRefs(point.getRow(), point.getCol(), set);
       }      
    }

Here is the call graph for this function:

static CellPoint SharpTools.SharpTableModel.getSize ( String  input) [inline, static]

From a string input determine how many rows/columns it requires for the table - it corresponds to the number of newlines and tabs.

Parameters:
inputthe string to analyze

Definition at line 1500 of file SharpTableModel.java.

                                                  {
       
       BufferedReader in = new BufferedReader(new StringReader(input));
       String line;
       int rowcount = 0;
       int colcount = 0;

       try {
       
           while ((line = in.readLine()) != null) {
              rowcount++;
              // initialize new tokenizer on line with tab delimiter. 
              //            tokenizer = new StringTokenizer(line, "\t");
              int index;
              int prev = 0;
              
              // set col to 1 before each loop
              int col = 0;
              
              while (true) {
                  index = line.indexOf('\t', prev);            
                  prev = index+1;
                  // increment column number
                  col++;
                  
                  if (index == -1)
                     break;
              }

              if (colcount < col)
                  colcount = col;
           }
       }
       catch (Exception e) {
           return null;
       }

       return new CellPoint(rowcount, colcount);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns JTable.

Returns:
JTable

Definition at line 1259 of file SharpTableModel.java.

                             {
       return sharp.getTable();
    }

Here is the call graph for this function:

Object SharpTools.SharpTableModel.getValueAt ( int  aRow,
int  aColumn 
) [inline]

This class returns the cell object at those coordinates.

It does exactly the same thing as getCellAt except that the return type is Object. It is implemented because TableModel requires this method return an Object.

Parameters:
aRowthe row coordinate
aColumnthe column coordinate
Returns:
the Cell

Definition at line 181 of file SharpTableModel.java.

                                                    {
        return getCellAt(aRow, aColumn);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.insertColumn ( CellRange  insertRange) [inline]

This method inserts columns to the left of the range with the number of new columns equal to the number of columns in the range.

Parameters:
insertRangerange of cells to add new columns to the left of creates the same number of new columns as range has

Definition at line 912 of file SharpTableModel.java.

                                                    {
        /* since the insertion point is given by a selected cell
         * there will never be an out of bounds error
         */
        Debug.println("insertRange: "+insertRange);
        /* start inserting at this coordinate */
        int col = insertRange.getStartCol();
        
        /* number of columns to insert including col */
        int insertNum = insertRange.getWidth();
        
        //the coordinates of the last cell in table
        int lastRow = getRowCount() - 1;
        int lastCol = getColumnCount() - 1;
        
        /* everything right to new columns must be shifted right
         * so cut them to the clipboard. So if col is "C" then it
         * is also copied. The max is a guard for inserting 
         * before the label column.
         */
        CellRange range = new CellRange(SharpTools.baseRow, lastRow, Math.max(col, SharpTools.baseCol), lastCol);
        SharpClipboard scrap = new SharpClipboard(this, range, true);

        JTable table = sharp.getTable();
       TableColumnModel tm = table.getColumnModel();
       TableColumn column = tm.getColumn(col);
        //add the new columns to the end
        for(int i = 0; i < insertNum; i++) {
           int curCol = lastCol+i+1;
            addColumn();
           TableColumn newcol = new TableColumn(curCol, 
                                           column.getPreferredWidth());
           //     TableColumn column = tm.getColumn(tm.getColumnCount() - 1);
           //            TableColumn newcol = new TableColumn(tm.getColumnCount(), 
           //                                                 column.getPreferredWidth());
            newcol.setHeaderValue(Node.translateColumn(curCol));
           tm.addColumn(newcol);
        }
        
        //shift relevant columns left
        scrap.paste(this, new CellPoint(SharpTools.baseRow, col + insertNum));

       recalculateAll();
       // set selection

       if (table.getSelectedColumnCount() == 0) {
           setSelection(new CellRange(SharpTools.baseRow, SharpTools.baseRow,
                                   col, col));       
       }

       //     sharp.setBaseColumnWidth();
       //fireTableStructureChanged();
       sharp.setBaseColumnWidth(0);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.insertRow ( CellRange  insertRange) [inline]

This method inserts rows to the left of range.

It adds as many rows as the range has.

Parameters:
insertRangethe range to the left of to add new rows also adds number of new rows equal to rows in range

Definition at line 1041 of file SharpTableModel.java.

                                                 {
        /* since the insertion point is given by a selected cell
         * there will never be an out of bounds error
         */
                          
        /* insert starting at this coordinate */
       int row = insertRange.getStartRow();
        
        /* number of rows to insert including row */
       int insertNum = insertRange.getHeight();
        
        //coordinates of last cell of table
       int lastRow = getRowCount() - 1;
       int lastCol = getColumnCount() - 1;

        /* copy things below these new rows
         * The max is to prevent inserts above the column headers
         */
       CellRange range = new CellRange(Math.max(row, SharpTools.baseRow), lastRow, SharpTools.baseCol, lastCol);
        SharpClipboard scrap = new SharpClipboard(this, range, true);
        
        //add the rows to the end
        for(int i = 0; i < insertNum; i++) {
            addRow();
        }
        
        //shift old rows down
        scrap.paste(this, new CellPoint(row + insertNum, SharpTools.baseCol));

       recalculateAll();
       
       JTable table = sharp.getTable();
       // set selection
       if (table.getSelectedColumnCount() == 0) {
           setSelection(new CellRange(row, row, SharpTools.baseCol, SharpTools.baseCol));
       }

    }

Here is the call graph for this function:

Here is the caller graph for this function:

int [] SharpTools.SharpTableModel.internalSort ( CellRange  area,
int  primary,
int  second,
boolean  isRow,
boolean  ascend,
boolean  tiebreaker 
) [inline, private]

Helper for sort that does the sorting.

To implement different algorithms for sorting modify this method. Returns an index array after index sorting

Parameters:
areaarea to sort in
primaryprimary criteria to sort
secondsecondary criteria (set equal to primary if not specified)
isRowtrue if criteria are rows
ascendtrue if sort ascending by primary
tiebreakertrue if sort ascending by secondary
Returns:
index array with row/col numbers of how cells should be arranged.

Definition at line 1684 of file SharpTableModel.java.

                                                {
        //initialize index array
        int[] index;
       if (isRow) {
           index = new int[area.getWidth()];
           for(int i = 0; i < index.length; i++) {
              index[i] = i + area.getStartCol();
           }
       }else {
           index = new int[area.getHeight()];
           for(int i = 0; i < index.length; i++) {
              index[i] = i + area.getStartRow();
           }
       }
        
        int j;
        
        for (int p = 1; p < index.length ; p++) {
           int tmp = index[p];
           
            for (j = p; ((j > 0) && rightOrder(primary, second, isRow, tmp, 
                                             index[j - 1], ascend, tiebreaker)); 
               j--) {
                index[j] = index[j - 1];
            }
           index[j] = tmp;
        }        
        return index;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean SharpTools.SharpTableModel.isCellEditable ( int  row,
int  column 
) [inline]

All Cells other than those in row 0 or column 0 are editable.

Parameters:
rowthe row coordinate
columnthe column coordinate
Returns:
true if cell is editable

Definition at line 1165 of file SharpTableModel.java.

                                                       {
       //        return !((row == 0) || (column == 0));
       return column != 0;
    }

check whether the deletion is safe

Parameters:
rangethe range to delete
byRowwhether it's deletion by row
Returns:
true if it's safe

Definition at line 1293 of file SharpTableModel.java.

                                                                  {
       int rowOff, colOff;
       CellRange needCheck;
       
       if (byRow) {
           rowOff = -range.getHeight();
           colOff = 0;
           if (range.getEndRow() == getRowCount()-1)
              return true;
           
           needCheck = new CellRange(range.getEndRow()+1, getRowCount()-1,
                                  SharpTools.baseCol, getColumnCount()-1);
       }
       else {
           rowOff = 0;
           colOff = -range.getWidth();
           if (range.getEndCol() == getColumnCount()-1)
              return true;
           needCheck = new CellRange(SharpTools.baseRow, getRowCount()-1,
                                  range.getEndCol()+1, getColumnCount()-1);
       }

       for (int i = needCheck.getStartRow(); i <= needCheck.getEndRow(); i++)
           for (int j = needCheck.getStartCol(); j <= needCheck.getEndCol();
               j++) {
              Cell cell = getCellAt(i, j);
              if (cell.isFormula() &&
                  !Formula.isSafe(cell.getFormula(), rowOff, colOff)) {
                  Debug.println("relative addresses become invalid");
                  return false;
              }
           }

       return true;
       
    }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean SharpTools.SharpTableModel.isEmptyCell ( int  row,
int  col 
) [inline]

Determines if a cell is empty.

Parameters:
rowrow coordinate of cell
colcolumn coordinate of cell
Returns:
true if cell is empty

Definition at line 1721 of file SharpTableModel.java.

                                                 {
       return getCellAt(row, col).getValue().equals("");
           
    }    

Here is the call graph for this function:

boolean SharpTools.SharpTableModel.isFormula ( int  aRow,
int  aColumn 
) [inline]

Determines if a cell at these coordinates is a formula cell.

Parameters:
aRowrow coordinate
aColumncolumn coordinate
Returns:
true only if the cell at those coordinates is a formula

Definition at line 1153 of file SharpTableModel.java.

                                                    {
        Cell temp = getCellAt(aRow, aColumn);
        return ((temp != null) && (temp.getType() == Cell.FORMULA));
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Starting from cell, detect potential reference loops.

Parameters:
cellspecified CellPoint

Definition at line 1189 of file SharpTableModel.java.

                                           {
       return isLoop(cell, new TreeSet());
    }

Here is the caller graph for this function:

boolean SharpTools.SharpTableModel.isLoop ( CellPoint  cell,
TreeSet  set 
) [inline, private]

Starting from cell, detect potential reference loops.

Parameters:
cellspecified CellPoint

Definition at line 1198 of file SharpTableModel.java.

                                                        {
       if (set.contains(cell))
           return true;
       
       Cell objCell = getCellAt(cell.getRow(), cell.getCol());
       if (objCell == null)
           return false;
       Formula formula = objCell.getFormula();
       if (formula == null)
           return false;

       set.add(cell);
       
       Iterator it = formula.getDependency().iterator();
       while (it.hasNext()) {
           CellPoint newCell = (CellPoint)it.next();
           boolean ret = isLoop(newCell, set);
           if (ret)
              return true;
       }
       
       set.remove(cell);
       return false;
    }

Here is the call graph for this function:

Returns modified state of document.

Returns:
document's modified value - true or false

Definition at line 1250 of file SharpTableModel.java.

                                {
       return modified;
    }

Here is the caller graph for this function:

CellPoint SharpTools.SharpTableModel.look ( CellPoint  begin,
Object  goal,
boolean  matchCase,
boolean  matchCell 
) [inline]

This searches of an object starting from a cell point.

Parameters:
begincellpoint to begin search
goalthe object to search for
matchCasetrue if case sensitive (only active if goal is a string)
matchCelltrue if goal must equal entire content of cell (only active if goal is a string)
Returns:
the CellPoint of next occurence of goal

Definition at line 541 of file SharpTableModel.java.

                                             {
        int startRow = begin.getRow();
        int startCol = begin.getCol();
       
       if ((goal instanceof String) && !matchCase && matchCell) {
            String objective = (String)goal;
           for(int i = startCol; i < getColumnCount(); i++) {
              if (objective.equalsIgnoreCase(
                                getCellAt(startRow, i).getValue().toString())) {
                  return new CellPoint(startRow, i);
              }
           }
           
           for(int i = startRow + 1; i < getRowCount(); i++) {
              for(int j = 1; j < getColumnCount(); j++) {
                  if (objective.equalsIgnoreCase(
                                getCellAt(i, j).getValue().toString())) {
                     return new CellPoint(i, j);
                  }
              }
           }
           
           return null;
            
       }else {
            if ((goal instanceof String) && !matchCell) {
                String objective = (String)goal;
               for(int i = startCol; i < getColumnCount(); i++) {
                  String test = getCellAt(startRow, i).getValue().toString();
                    
                    if (!matchCase) {
                        objective = objective.toUpperCase();
                        test = test.toUpperCase();
                    }
                  for(int k = 0; k < test.length(); k++) {
                     if (test.startsWith(objective, k)) {
                         return new CellPoint(startRow, i);
                     }
                         
                    }
                }                      
                  
              for(int i = startRow + 1; i < getRowCount(); i++) {
                  for(int j = 1; j < getColumnCount(); j++) {
                     String test = getCellAt(i, j).getValue().toString();
                     if (!matchCase) {
                         objective = objective.toUpperCase();
                         test = test.toUpperCase();
                        }
                     for(int k = 0; k < test.length(); k++) {
                         if (test.startsWith(objective, k)) {
                            return new CellPoint(i, j);
                            }
                        }
                    }
                }
                     
              return null;
            }else {                
              for(int i = startCol; i < getColumnCount(); i++) {
                  if (goal.equals(getCellAt(startRow, i).getValue())) {
                     return new CellPoint(startRow, i);
                  }
              }
              
              for(int i = startRow + 1; i < getRowCount(); i++) {
                  for(int j = 1; j < getColumnCount(); j++) {
                     if (goal.equals(getCellAt(i, j).getValue())) {
                         return new CellPoint(i, j);
                     }
                  }
              }
                     
              return null;
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.recalculate ( int  aRow,
int  aColumn 
) [inline]

This is a warper method of the Formula class's evaluate method.

This method recalculates the value of a formula at the given coordinates. If the coordinates do not specify a formula it does nothing.

Parameters:
aRowthe row coordinate
aColumnthe column coordinate

Definition at line 195 of file SharpTableModel.java.

                                                   {
        if (isFormula(aRow, aColumn)) {

           try {
              Debug.println("recalculate");
              Number eVal = Formula.evaluate(this, aRow, aColumn);
              //we set the value here
              getCellAt(aRow, aColumn).setValue(eVal);
           }
           catch (ParserException e) {
                //set value as the appropriate error message
              getCellAt(aRow, aColumn).setValue(e);
           }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

This is the version of recalculate that takes a CellPoint object as an argument.

Parameters:
xthe coordinates of the cell to be updated

Definition at line 217 of file SharpTableModel.java.

                                         {
        recalculate(x.getRow(), x.getCol());
    }

Here is the call graph for this function:

This method recalculates all cells in the table.

See also:
insertRow
insertColumn
removeRow
removeColumn

Definition at line 819 of file SharpTableModel.java.

                                 {
       for (int i = 1; i < getRowCount(); i++)
           for (int j = 1; j < getColumnCount(); j++) {
              addRefs(i, j);
              recalculate(i, j);
           }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.removeColumn ( CellRange  deletionRange) [inline]

This method removes columns in the range.

Parameters:
deletionRangethe range that contains the columns to delete

Definition at line 831 of file SharpTableModel.java.

                                                      {

        /* since the insertion point is given by a selected cell
         * there will never be an out of bounds error
         */
        
        /* first column to delete */
        int col = deletionRange.getStartCol();
        
        /* number of columns to delete including col */
        int removeNum = deletionRange.getWidth();
        
        //last entry of table
        int lastRow = getRowCount() - 1;
        int lastCol = getColumnCount() - 1;
        
        
        /* everything to the right of the columns to remove
         * need to be copied to be shifted right
         */
        CellRange range = new CellRange(SharpTools.baseRow, lastRow,
                                        col + removeNum, lastCol);
       
        
        SharpClipboard scrap = new SharpClipboard(this, range, true);
        
        JTable table = sharp.getTable();
        for(int i = 0; i < removeNum; i++) {
            // delete old column
            removeColumn();
           TableColumnModel tm = table.getColumnModel();
           tm.removeColumn(tm.getColumn(tm.getColumnCount() - 1));
       }
        
        //shift clipboard elements right
        scrap.paste(this, new CellPoint(SharpTools.baseRow, col));

       //     updateRefs(refs);
       recalculateAll();
       
       // set selection
       if (table.getSelectedColumnCount() == 0) {
           setSelection(new CellRange(SharpTools.baseRow, SharpTools.baseRow,
                                   col, col));
       }

        //    fireTableStructureChanged();
       sharp.setBaseColumnWidth(0);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.removeColumn ( ) [inline, private]

Definition at line 881 of file SharpTableModel.java.

                                {

        int lastRow = getRowCount() - 1;
        int lastCol = getColumnCount() - 1;
        
        //remove the data from cells to delete to maintain references
        clearRange(new CellRange(SharpTools.baseRow, lastRow, lastCol, lastCol));
        
        Iterator it = dataVector.iterator();
        while (it.hasNext()) {
            /* Since deleting B makes C the
             * new B, the reference lists in cells of old "B"  
             * should not change. So, we only shift the data in cells right
             * and deleted the last columns.
             */
            Vector temp = (Vector)it.next();
            temp.removeElementAt(getColumnCount() - 1);
        }
        
        //update inherited field from  DefaultTableModel
        columnIdentifiers.removeElementAt(columnIdentifiers.size() - 1);
        
        // Notification is generated within the GUI
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.removeRefs ( int  aRow,
int  aColumn 
) [inline]

This method removes this formula cell from the reference lists of all cells it references.

If this is not a formula cell, it does nothing. This method should be called with a formula cell is being changed to a non-Formula cell.

Parameters:
aRowrow of cell to remove from reference list
aColumncolumn of cell to remove from reference list

Definition at line 706 of file SharpTableModel.java.

                                                  {
        if (isFormula(aRow, aColumn)) {
            Formula temp = getCellAt(aRow, aColumn).getFormula();
            TreeSet list = temp.getDependency();
           
            /* use formula dependcy list to go to cells that it references
             * then remove its entry form their reference list
             */
            Iterator it = list.iterator();
           CellPoint thisRef = new CellPoint(aRow, aColumn);
           while (it.hasNext()) {
                CellPoint update = (CellPoint)it.next();
                Cell field = getCellAt(update.getRow(), update.getCol());
                
              if (field != null)
                  field.removeRef(thisRef);
                
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.removeRow ( CellRange  deletionRange) [inline]

This method removes rows in the range.

Parameters:
deletionRangeCellRange that contains the rows to delete

Definition at line 998 of file SharpTableModel.java.

                                                   {
        /* since the insertion point is given by a selected cell
         * there will never be an out of bounds error
         */
        clearRange(deletionRange);
        
        /* first row to delete */
        int row = deletionRange.getStartRow();
        
        /* number of rows to delete including the first */
        int removeNum = deletionRange.getHeight();
        
        //coordinates of last cell in spreadsheet
        int lastRow = getRowCount() - 1;
        int lastCol = getColumnCount() - 1;
        
        //everything lower than rows to remove must be copied to be shifted
        CellRange range = new CellRange(row + removeNum, lastRow,
                                   SharpTools.baseCol, lastCol);
        SharpClipboard scrap = new SharpClipboard(this, range, true);
           
        for(int i = 0; i < removeNum; i++) {
            super.removeRow(getRowCount() - 1);
        }
        
        
        //shift relevent rows up
        scrap.paste(this, new CellPoint(row, SharpTools.baseCol));    

       recalculateAll();
       
       JTable table = sharp.getTable();
       // set selection
       if (table.getSelectedColumnCount() == 0) {
           setSelection(new CellRange(row, row, SharpTools.baseCol, SharpTools.baseCol));
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean SharpTools.SharpTableModel.rightOrder ( int  primary,
int  second,
boolean  isRow,
int  i,
int  j,
boolean  ascend,
boolean  order 
) [inline, private]

Determines if cells are in the wrong order Used only as helper method for sort.

Definition at line 1647 of file SharpTableModel.java.

                                                                  {
       
        //compare by first criteria                            
        int result = compareLines(primary, isRow, ascend, i, j);
        
        //if equal, use second as tiebreaker
        if (result == 0) {
            result = compareLines(second, isRow, order, i, j);

            if (order) {
              return (result < 0);
            }else {
              return (result > 0);
            }
        //otherwise just return results from primary criteria
        }else {
            if (ascend) {
              return (result < 0);
           }else {
                return (result > 0);
            }
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.setCellAt ( Object  input,
int  aRow,
int  aColumn 
) [inline]

This object assumes that the object passes to it is already the correct object to set the value of the cell as.

For a formula, it also calculcates the value of the formula and records that in the cell.

Parameters:
inputobject to set the Cell value as
aRowrow of cell to set
aColumncolumn of cell to set

Definition at line 395 of file SharpTableModel.java.

                                                               {
        Cell temp = getCellAt(aRow, aColumn);

       /* if for some reason value out of bounds ignore */
        if (temp != null) {

           //always remove references old formula referred to
           removeRefs(aRow, aColumn);
            
           //insert new formula
           if (input instanceof Formula) {
              temp.setFormula((Formula)input);

              if (isLoop(new CellPoint(aRow, aColumn))) {
                  ParserException loop = new ParserException("#LOOP?");
                    Formula form2 = new Formula(input.toString(), aRow, aColumn, loop);
                  setCellAt(form2, aRow, aColumn);
                  getCellAt(aRow, aColumn).setValue(loop);
                  updateRefs(aRow, aColumn);
                  return;
                }else {
                  
                  addRefs(aRow, aColumn);
                  recalculate(aRow, aColumn);
                  updateRefs(aRow, aColumn);

                }               
            }else {
                //treat as normal data cell
              temp.setData(input);
              updateRefs(aRow, aColumn);
            }
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.setHistory ( History  h) [inline, package]

This method associated the proper undo object to this SharpTableModel.

It must be called right after the constructor.

Parameters:
hthe History object to associate with this SharpTableModel

Definition at line 137 of file SharpTableModel.java.

                               {
       history = h;
    }

Here is the caller graph for this function:

void SharpTools.SharpTableModel.setModified ( boolean  modified) [inline]

Sets modified state of current document.

Parameters:
modifiedtrue sets state to modified

Definition at line 1228 of file SharpTableModel.java.

                                              {
       this.modified = modified|passwordModified;
       // enable/disable the "Save" button
       sharp.checkSaveState();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Sets modified state of password; can't undo.

Parameters:
modifiedsets state to modified
See also:
FileOp::setPassword

Definition at line 1239 of file SharpTableModel.java.

                                                      {
       passwordModified = modified;
       setModified(this.modified);
       // enable/disable the "Save" button
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.setRange ( CellRange  range,
Object  data[][] 
) [inline]

This method sets the cells given by the range to the cooresponding value in the Object array.

In other words, this method pastes the object array onto the range. It is assumed that the range and Object array have the same dimensions. (a "placeAt" method for ranges)

Parameters:
rangethe range of cells to paste to
datathe data to paste

Definition at line 438 of file SharpTableModel.java.

                                                           {
        
        /* Loop through the paste range */
        for (int i = range.getStartRow(); i <= range.getEndRow(); i++) {
            for (int j = range.getStartCol(); j <= range.getEndCol(); j++) {
                
                //calculate the corresponding entry in data array
                int x = i - range.getStartRow();
                int y = j - range.getStartCol();
                
                //place data entry at that place
                doSetValueAt(data[x][y], i, j);
            }
        }
    }

Here is the call graph for this function:

void SharpTools.SharpTableModel.setRange ( CellRange  range,
Cell  data[][],
boolean  byValue 
) [inline]

This is a method used to paste cells onto the table.

This method is used by the SharpClipboard class. It's feature is that it can paste only the old evaluated values or it can be told to paste the data cells and formulas.

Parameters:
rangerange to paste to
datacells that need to be pasted
byValuetrue if only paste values if there are formula

Definition at line 465 of file SharpTableModel.java.

                                                                          {
        
        /* there may be formula so if byValue is true paste evaluated formula 
         * value into the range as a data cell
         */
        if (byValue) {
            for (int i = range.getStartRow(); i <= range.getEndRow(); i++) {
                for (int j = range.getStartCol(); j <= range.getEndCol(); j++) {
                    
                    int x = i - range.getStartRow();
                    int y = j - range.getStartCol();
                    
                    //get only value of a formula cell not formula
                  doSetValueAt(data[x][y].getValue(), i, j);
                }
            }
        }else {
            for (int i = range.getStartRow(); i <= range.getEndRow(); i++) {
                for (int j = range.getStartCol(); j <= range.getEndCol(); j++){
                   
                    int x = i - range.getStartRow();
                    int y = j - range.getStartCol();
                    Cell info = data[x][y];
                    
                    //paste new formula to recalculate
                    if (info.isFormula()) {
                        doSetValueAt(info.getFormula(), i, j);
                    }else {
                        doSetValueAt(info.getValue(), i, j);
                    }
                }
            }
        }
    }

Here is the call graph for this function:

set table selection to the range sel

Parameters:
selthe range to be selected

Definition at line 1268 of file SharpTableModel.java.

                                            {
       JTable table = sharp.getTable();   
       // validate sel
       int maxRow = table.getRowCount()-1;
       int maxCol = table.getColumnCount()-1;

       int startRow = sel.getStartRow();
       int startCol = sel.getStartCol();
       int endRow = sel.getEndRow();
       int endCol = sel.getEndCol();

       table.setColumnSelectionInterval(Math.min(startCol, maxCol),
                                    Math.min(endCol, maxCol));
       table.setRowSelectionInterval(Math.min(startRow, maxRow),
                                  Math.min(endRow, maxRow));
                                  
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.setValueAt ( Object  aValue,
int  aRow,
int  aColumn 
) [inline]

Sets the value of the cell.

It takes care of formulas and data. If aValue is a string, it parses it to see if it is a formula (begins with an "=") or a number. It then sets the value of the cell accordingly.

This function is called by JTable automatically, which means user has manually input something. Thus, it records the previous value of the cell into the History object associated with this SharpTableModel.

We should never call it directly (use doSetValueAt instead).

Parameters:
aValuethe formula or data you want to set cell to
aRowrow coordinate
aColumncolumn coordinate

Definition at line 299 of file SharpTableModel.java.

                                                                 {
       CellPoint point = new CellPoint(aRow, aColumn);  
       history.add(this, new CellRange(point, point));
       doSetValueAt(aValue, aRow, aColumn);
    }

Here is the call graph for this function:

void SharpTools.SharpTableModel.sort ( CellRange  area,
int  primary,
int  second,
boolean  isRow,
boolean  ascend,
boolean  tiebreaker 
) [inline]

This method sorts an arbitrary range in the table.

Parameters:
arearange to sort
primaryprimary row/column to sort by
secondsecond row/column to sort by (set equal to primary if there is no secondary criteria specified.
isRowtrue if primary and secondary are row numbers
ascendtrue if sorting in ascending order by primary criteria
tiebreakertrue if sorting in ascending order by secondary criteria data structure

Definition at line 1551 of file SharpTableModel.java.

                                                  {

        
        /* original data order will be saved here 
         * and placed on clipboard for undo
         */
        SharpClipboard[] data;
        if (isRow) {
            data = new SharpClipboard[area.getWidth()];
            for(int i = 0; i < data.length; i++) {
                CellRange temp = new CellRange(area.getStartRow(),
                                               area.getEndRow(),
                                               area.getStartCol() + i,
                                               area.getStartCol() + i);
                data[i] = new SharpClipboard(this, temp, false);
            }
        }else {
            data = new SharpClipboard[area.getHeight()];
            for(int i = 0; i < data.length; i++) {
                CellRange temp = new CellRange(area.getStartRow() + i,
                                               area.getStartRow() + i,
                                               area.getStartCol(),
                                               area.getEndCol());
                data[i] = new SharpClipboard(this, temp, false);
            }
        }
                                            
        
        /* We are going to do the sort within the world of the data array
         * First, we do index sorting to create an index array.
         * Then according to the index array, we paste the entries in data
         * back in the sorted order.
         */
        
        //do index sorting
        int[] indices = internalSort(area, primary, second, isRow, ascend, tiebreaker);
            
        //paste accordingly
        if (isRow) {
           for (int i = area.getStartCol(); i <= area.getEndCol(); i++){
              //point to paste at
                CellPoint point = new CellPoint(area.getStartRow(), i);
                
                int y = i - area.getStartCol();
                data[indices[y] - area.getStartCol()].paste(this, point);
            }
        }else {
            for (int i = area.getStartRow(); i <= area.getEndRow(); i++) {
              //point to paste at
                CellPoint point = new CellPoint(i, area.getStartCol());
                
                int y = i - area.getStartRow();
                data[indices[y] - area.getStartRow()].paste(this, point);
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

String SharpTools.SharpTableModel.to_WIMS ( CellRange  range,
boolean  byValue,
boolean  matrix 
) [inline]

Definition at line 1364 of file SharpTableModel.java.

                                                                            {
       StringBuffer sbf=new StringBuffer();
       Number n=null;
       String row_sep="\t";
       String col_sep="\n";
       
       if(matrix){
           row_sep=",";
           col_sep=";";
           sbf.append("[");
       }
       else
       {
           row_sep="\t";
           col_sep="\n";
       }
       for (int i=range.getStartRow(); i<=range.getEndRow(); i++) {
           for (int j=range.getStartCol(); j<=range.getEndCol(); j++) {
              n=null;
              if(isFormula(i,j)){
                  try { n = getNumericValueAt(i,j);}                                                                                                                              
                  catch (ParserException e) {System.out.println("hmmm this should not happen"); }
              }
              if(n != null){
                  sbf.append(n);
              }
              else
              {
                  if(byValue){
                     sbf.append(getValueAt(i, j));
                  }
                  else
                  {
                     Cell cell = getCellAt(i, j);
                     // if cell is not empty
                     if(cell != null){sbf.append(cell.toString());}
                  }
              }
              if (j<range.getEndCol())
                  sbf.append(row_sep);
           }
           sbf.append(col_sep);
       }
       if(matrix){sbf.append("]");}

       String text = sbf.toString();
       return text;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

String SharpTools.SharpTableModel.toString ( CellRange  range,
boolean  byValue 
) [inline]

toString is used to convert a range of cells into a string.

One row per line, and each column is tab-delimited.

Parameters:
rangethe range in the table
byValueget the value instead of a formula
Returns:
a string
See also:
Formula::fixRelAddr
FileOp::saveTableModel
EditOp::cut
EditOp::copy
SharpClipboard

Definition at line 1341 of file SharpTableModel.java.

                                                             {
       StringBuffer sbf=new StringBuffer();
       for (int i=range.getStartRow(); i<=range.getEndRow(); i++) {
           for (int j=range.getStartCol(); j<=range.getEndCol(); j++) {
              if (byValue) {
                  sbf.append(getValueAt(i, j));
              }
              else {
                  Cell cell = getCellAt(i, j);
                  if(cell != null)
                     sbf.append(cell.toString());
              }
              
              if (j<range.getEndCol())
                  sbf.append("\t");
           }
           sbf.append("\n");
       }

       String text = sbf.toString();
       return text;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

convert the whole table to a string.

Returns:
a string
See also:
FileOp

Definition at line 1485 of file SharpTableModel.java.

                             {
       return toString(new CellRange(SharpTools.baseRow, getRowCount()-1,
                                  SharpTools.baseCol, getColumnCount()-1), false);
    }

Here is the caller graph for this function:

String SharpTools.SharpTableModel.toWIMS ( boolean  matrix) [inline]

Definition at line 1489 of file SharpTableModel.java.

                                         {
       return to_WIMS(new CellRange(SharpTools.baseRow, getRowCount()-1,
                                  SharpTools.baseCol, getColumnCount()-1), false, matrix);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.SharpTableModel.updateRefs ( int  aRow,
int  aColumn 
) [inline]

This method updates the values of all cells that reference this one.

It recursively updates all cells that depend on this one and cells that depend on those, etc.

Parameters:
aRowrow of cell to update
aColumncolumn of cell to update

Definition at line 735 of file SharpTableModel.java.

                                                  {
       
        Cell temp = getCellAt(aRow, aColumn);
       if (temp == null)
           return;

       TreeSet set = getRefs(aRow, aColumn);

       // mark it as "needsRecalc";
       Iterator it = set.iterator();
       while (it.hasNext()) {
           CellPoint point = (CellPoint)it.next();
           Formula formula = getCellAt(point.getRow(), point.getCol()).getFormula();
           
           formula.setNeedsRecalc(true);
           // make sure JTable refreshes it
           //fireTableCellUpdated(point.getRow(), point.getCol());
       }

       // recalculate
       it = set.iterator();
       while (it.hasNext()) {
           CellPoint point = (CellPoint)it.next();
           try {
              getNumericValueAt(point.getRow(), point.getCol());
           }
           catch (ParserException e) {
           }
           
           // make sure JTable refreshes it
           fireTableCellUpdated(point.getRow(), point.getCol());
       }
       
        //make sure to tell JTable things have changed
       fireTableCellUpdated(aRow, aColumn);
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

holds the history information for the table

Definition at line 42 of file SharpTableModel.java.

Stores modified state of document.

Definition at line 33 of file SharpTableModel.java.

true if password has been changed

Definition at line 36 of file SharpTableModel.java.

Stores file name of current document.

Definition at line 39 of file SharpTableModel.java.


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