Back to index

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

This contain certain higher level edit operations on the spreadsheet table. More...

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

List of all members.

Public Member Functions

void init (SharpTools sharp)
 init method.
void cut ()
 Perfroms a clipboard function of cutting COPY + CLEAR.
void copy ()
 Perfroms a clipboard function of cutting COPY + CLEAR.
void paste ()
 Performs a clipboard function of pasting.
void clear ()
 Wrapper function to clear cell and range of cells....
void fill ()
 Wrapper function to fill a range of cell with a user defined value.
void find (boolean newValue)
 Wrapper function to fill a range of cell with a user defined value.
boolean hasFindValue ()
 Whether a value has been searched by the user.
void actionPerformed (ActionEvent e)
 Whether the clipboard has data.

Package Functions

 EditOp (SharpTools sharp)
 constructor

Package Attributes

final ImageIcon fillIcon = new ImageIcon(getClass().getResource("/images/fill32.gif"))
final ImageIcon findIcon = new ImageIcon(getClass().getResource("/images/find32.gif"))

Private Member Functions

void doCopy (boolean isCut)
 Performs a clipboard function of cut/copy.
void setFindValue (String s)

Private Attributes

SharpTools sharp
JTable table
SharpTableModel tableModel
History history
JToolBar toolBar
CellPoint copyPoint = new CellPoint(SharpTools.baseRow, SharpTools.baseCol)
Clipboard my_local_clipboard
String findValue
boolean matchCase = false
boolean matchCell = false

Detailed Description

This contain certain higher level edit operations on the spreadsheet table.

Author:
Hua Zhong
Version:
Revision:
1.37

Definition at line 24 of file EditOp.java.


Constructor & Destructor Documentation

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

constructor

Parameters:
sharpthe GUI object

Definition at line 49 of file EditOp.java.

                             {
       this.sharp = sharp;
       table = sharp.getTable();

       // Identifying the undo KeyStroke user can modify this
       // to undo on some other Key combination.
       KeyStroke undo = KeyStroke.getKeyStroke
           (KeyEvent.VK_Z,ActionEvent.CTRL_MASK,false); 

       // Identifying the undo KeyStroke user can modify this
       // to undo on some other Key combination.
       KeyStroke redo = KeyStroke.getKeyStroke
           (KeyEvent.VK_Y,ActionEvent.CTRL_MASK,false);
       
       // Identifying the cut KeyStroke user can modify this
       // to cut on some other Key combination.
       KeyStroke cut = KeyStroke.getKeyStroke
           (KeyEvent.VK_X,ActionEvent.CTRL_MASK,false);
       
       // Identifying the copy KeyStroke user can modify this
       // to copy on some other Key combination.
       KeyStroke copy = KeyStroke.getKeyStroke
           (KeyEvent.VK_C,ActionEvent.CTRL_MASK,false); 
       
       // Identifying the Paste KeyStroke user can modify this
       // to copy on some other Key combination.
       KeyStroke paste = KeyStroke.getKeyStroke
           (KeyEvent.VK_V,ActionEvent.CTRL_MASK,false);

       KeyStroke fill = KeyStroke.getKeyStroke
           (KeyEvent.VK_L, ActionEvent.CTRL_MASK, false);
       
       KeyStroke clear = KeyStroke.getKeyStroke
           (KeyEvent.VK_DELETE, 0, false);

       // Identifying the find/findnext KeyStroke user can modify this
       // to find on some other Key combination.
       KeyStroke find = KeyStroke.getKeyStroke
           (KeyEvent.VK_F,ActionEvent.CTRL_MASK,false);
       
       KeyStroke findnext = KeyStroke.getKeyStroke
           (KeyEvent.VK_F3,0,false);
       
       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Undo"), undo,
                                 JComponent.WHEN_FOCUSED);

       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Redo"), redo,
                                 JComponent.WHEN_FOCUSED);     
       
       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Cut"), cut,
                                 JComponent.WHEN_FOCUSED);

       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Copy"), copy,
                                 JComponent.WHEN_FOCUSED);

       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Paste"),paste,
                                 JComponent.WHEN_FOCUSED);

       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Fill"),fill,
                                 JComponent.WHEN_FOCUSED);
       
       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Clear"),clear,
                                 JComponent.WHEN_FOCUSED);

       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Find"),find,
                                 JComponent.WHEN_FOCUSED);
       
       table.registerKeyboardAction(this,SharpTools.translation.getProperty("Find_Next"),findnext,
                                 JComponent.WHEN_FOCUSED);


       init(sharp);
    }

Here is the call graph for this function:


Member Function Documentation

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

Whether the clipboard has data.

Returns:
true if clipboard has been set 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 411 of file EditOp.java.

                                               {

       if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Undo"))==0) {
           history.undo(tableModel);
       }
       else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Redo"))==0) {
           history.redo(tableModel);
       }      
       else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Cut"))==0) {
           cut();
       }      
       else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Copy"))==0) {
           copy();
       }             
       else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Paste"))==0) {
           paste();
       }
       else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Fill"))==0) {
           fill();
       }
       else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Find"))==0) {
           find(true);
       }
       else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Find_Next"))==0) {
           find(false);
       }
    }

Here is the call graph for this function:

void SharpTools.EditOp.clear ( ) [inline]

Wrapper function to clear cell and range of cells....

Definition at line 239 of file EditOp.java.

                        {
       //checks if anything is selected
       if (table.getSelectedRowCount() != 0) {
           CellRange range = new CellRange(
                      table.getSelectedRows(), table.getSelectedColumns());
           history.add(tableModel, range);
           Debug.println("Clear");
           tableModel.clearRange(range);
       } else { 
           sharp.noCellsSelected(SharpTools.translation.getProperty("Clear"));
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.EditOp.copy ( ) [inline]

Perfroms a clipboard function of cutting COPY + CLEAR.

Definition at line 147 of file EditOp.java.

                       {
       doCopy(false); //sets isCut to false
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.EditOp.cut ( ) [inline]

Perfroms a clipboard function of cutting COPY + CLEAR.

Parameters:
clipboardthe SharpClipboard object

Definition at line 140 of file EditOp.java.

                     {
       doCopy(true); //sets isCut to true
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.EditOp.doCopy ( boolean  isCut) [inline, private]

Performs a clipboard function of cut/copy.

Parameters:
isCuttrue for cut, false for copy

Definition at line 156 of file EditOp.java.

                                       {
       if (table.getSelectedRowCount() != 0) { 
           CellRange range = new CellRange(
                         table.getSelectedRows(), table.getSelectedColumns());

           if (isCut) {
              history.add(tableModel, range);
           }      

           //     toolBar.getComponent(8).setEnabled(true);
           // now do the copy operation
           StringBuffer sbf=new StringBuffer();

           int startRow = table.getSelectedRow();
           int startCol = table.getSelectedColumn();
           
           int numrows=table.getSelectedRowCount();
           int numcols=table.getSelectedColumnCount();
           
           copyPoint = new CellPoint(table.getSelectedRow(),
                                  table.getSelectedColumn());

           String str = tableModel.toString(range, false);
           StringSelection stsel = new StringSelection(str);
           //jm.evers using a local clipboard to avoid jar-signing
           //Clipboard clipboard = new Clipboard ("name").
           my_local_clipboard = new Clipboard("my_local_clipboard");
           my_local_clipboard.setContents(stsel,stsel);

           if (isCut)
              tableModel.clearRange(range);
           
       } else {
            if (isCut) {
               sharp.noCellsSelected(SharpTools.translation.getProperty("Cut"));
            }else {
                sharp.noCellsSelected(SharpTools.translation.getProperty("Copy"));
           }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.EditOp.fill ( ) [inline]

Wrapper function to fill a range of cell with a user defined value.

Definition at line 256 of file EditOp.java.

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

           Cell first = tableModel.getCellAt(range.getStartRow(),
                                         range.getStartCol());
           String fillValue = null;
           if (first.isFormula())
              fillValue = "="+first.getFormula().toString();
           else
              fillValue = first.getValue().toString();
           
           Object inputValue =
              SharpOptionPane.showInputDialog
              (sharp, SharpTools.translation.getProperty("Please_enter_a_value_to_fill_the_range"),
               SharpTools.translation.getProperty("Fill"), JOptionPane.INFORMATION_MESSAGE,
               fillIcon, null, fillValue);

           //if input is cancelled or nothing is entered 
           //then don't change anything
           if (inputValue != null){
              if (((String)inputValue).length() != 0) {
                  history.add(tableModel, range);
                  tableModel.fillRange(range, (String)inputValue);
                  //            fillValue = inputValue;
              }
           }
       }else { 
           sharp.noCellsSelected(SharpTools.translation.getProperty("Fill"));
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.EditOp.find ( boolean  newValue) [inline]

Wrapper function to fill a range of cell with a user defined value.

Parameters:
newValueis true if it should require a new value (Find...) is false if it already has a value (Find Next)

Definition at line 296 of file EditOp.java.

                                       {
        CellPoint start;
        
       //checks if anything is selected

       if (table.getSelectedRowCount() != 0) {
           int x = table.getSelectedRow();
           int y = table.getSelectedColumn();
           // start from the next cell
           if (!newValue)
              if (y < table.getColumnCount()-1)
                  y++;
              else {
                  y = 1;
                  x++;
              }
           
           start = new CellPoint(x, y);
           
        }
       else {
           // or start from the beginning
            start = new CellPoint(SharpTools.baseRow, SharpTools.baseCol);
        }

       if (newValue) {
           // ask for new value
           //String inputValue = SharpOptionPane.showInputDialog
              //(sharp, "Find: ", "Find", findIcon, findValue, 10);
           FindDialog findDialog = new FindDialog(sharp, findValue, matchCase, matchCell);
           findDialog.pack();
           findDialog.setLocationRelativeTo(sharp);
           findDialog.setVisible(true);

           String inputValue = findDialog.getString();
           /*     
           matchCase = findDialog.isCaseSensitive();
           matchCell = findDialog.isCellMatching();

           Debug.println("case sens : " + findDialog.isCaseSensitive());
           Debug.println("match cell : " + findDialog.isCellMatching());
           */
           //if input is cancelled or nothing is entered 
           //then don't change anything
           if (inputValue == null || inputValue.length() == 0)
              return;
           else {
              setFindValue(inputValue);
              matchCase = findDialog.isCaseSensitive();
              matchCell = findDialog.isCellMatching();

              Debug.println("case sens : " + findDialog.isCaseSensitive());
              Debug.println("match cell : " + findDialog.isCellMatching());
           }
              
       }
       else if (!hasFindValue())
           return;

       CellPoint found = tableModel.look(start, SharpTableModel.fieldParser(findValue), matchCase, matchCell);
       if (found != null) {
           //System.out.println(found);
           table.setColumnSelectionInterval(found.getCol(), 
                                        found.getCol());
           table.setRowSelectionInterval(found.getRow(),
                                     found.getRow());
           // set it visible
           table.scrollRectToVisible
              (new Rectangle
                  (table.getCellRect(found.getRow(), found.getCol(), true)));
       }      
       else {
           SharpOptionPane.showMessageDialog
              (sharp, 
              SharpTools.translation.getProperty("SharpTools_has_finished_the_search") + "  : "+ findValue ,
               SharpTools.translation.getProperty("Find_Completed"),
               JOptionPane.INFORMATION_MESSAGE, findIcon); 
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Whether a value has been searched by the user.

Returns:
true if the findValue has been set

Definition at line 381 of file EditOp.java.

                                  {
       return findValue != null && findValue.length() != 0;
    }

Here is the caller graph for this function:

void SharpTools.EditOp.init ( SharpTools  sharp) [inline]

init method.

The reason to have this is to reset the EditOp but keep the findValue and clipboard.

Parameters:
sharpthe GUI object

Definition at line 130 of file EditOp.java.

Here is the caller graph for this function:

void SharpTools.EditOp.paste ( ) [inline]

Performs a clipboard function of pasting.

Definition at line 200 of file EditOp.java.

                       {
        //checks if anything is selected  
        if (table.getSelectedRowCount() != 0) {
           int startRow=table.getSelectedRow();
           int startCol=table.getSelectedColumn(); 
           
           int rowOff = startRow-copyPoint.getRow();
           int colOff = startCol-copyPoint.getCol();
           
           try {
              
              String trstring=
                  (String)(my_local_clipboard.getContents(this).
                          getTransferData(DataFlavor.stringFlavor));

              CellPoint size = SharpTableModel.getSize(trstring);
              int endRow = Math.min(table.getRowCount()-1,
                                  startRow+size.getRow()-1);
              int endCol = Math.min(table.getColumnCount()-1,
                                  startCol+size.getCol()-1);

              CellRange affectedRange = new CellRange(startRow, endRow,
                                                 startCol, endCol);
              // add to history
              history.add(tableModel, affectedRange);
              //            System.out.println(affectedRange);
              
              tableModel.fromString(trstring, rowOff, colOff, affectedRange);
           }
           catch(Exception e){
                     System.out.println(e.toString());
           }
       } else {
           sharp.noCellsSelected(SharpTools.translation.getProperty("Paste"));
       }
    }    

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.EditOp.setFindValue ( String  s) [inline, private]

Definition at line 385 of file EditOp.java.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 32 of file EditOp.java.

final ImageIcon SharpTools.EditOp.fillIcon = new ImageIcon(getClass().getResource("/images/fill32.gif")) [package]

Definition at line 40 of file EditOp.java.

final ImageIcon SharpTools.EditOp.findIcon = new ImageIcon(getClass().getResource("/images/find32.gif")) [package]

Definition at line 41 of file EditOp.java.

String SharpTools.EditOp.findValue [private]

Definition at line 37 of file EditOp.java.

Definition at line 30 of file EditOp.java.

Definition at line 38 of file EditOp.java.

Definition at line 39 of file EditOp.java.

Definition at line 34 of file EditOp.java.

Definition at line 27 of file EditOp.java.

JTable SharpTools.EditOp.table [private]

Definition at line 28 of file EditOp.java.

Definition at line 29 of file EditOp.java.

JToolBar SharpTools.EditOp.toolBar [private]

Definition at line 31 of file EditOp.java.


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