Back to index

wims  3.65+svn20090927
SharpClipboard.java
Go to the documentation of this file.
00001 /*
00002  * @(#)SharpClipboard.java
00003  *
00004  * $Id: SharpClipboard.java,v 1.18 2002/08/08 05:15:07 huaz Exp $
00005  *
00006  * Created on October 27, 2000, 9:40 PM
00007  */
00008 
00018 package SharpTools;
00019 public class SharpClipboard {
00020 
00023     private String text;
00026     private CellRange source;
00027     
00036     public SharpClipboard(SharpTableModel model, CellRange range,
00037                        boolean isCut) {
00038        text = model.toString(range, false);
00039 
00040         source = range;
00041         
00042         //if it is a cut, set the old cells to null
00043         if (isCut) {
00044             model.clearRange(range);
00045         }
00046     }
00047     
00054     public CellRange getRange(SharpTableModel model, CellPoint corner) {
00055         //limit to paste region
00056         int rowLimit = model.getRowCount() - 1;
00057         int colLimit = model.getColumnCount() - 1;
00058         
00059         //calculate dimensions of clipboard
00060         int rowMax = corner.getRow() + source.getHeight() - 1;
00061         int colMax = corner.getCol() + source.getWidth() - 1;
00062         
00063         //cannot paste to nonexistent cells
00064         if ((corner.getRow() < SharpTools.baseRow) ||
00065            (corner.getCol() < SharpTools.baseCol)) {
00066            return null;
00067         }else {
00068             //paste as much as you can
00069            return new CellRange(corner,
00070                              new CellPoint(Math.min(rowMax, rowLimit),
00071                                           Math.min(colMax, colLimit)));
00072         }
00073     }
00074             
00082     public void paste(SharpTableModel table, CellPoint corner) {
00083         //if region to paste to is out of bounds
00084        CellRange range = getRange(table, corner);
00085        paste(table, range);
00086     }
00087 
00093     public void paste(SharpTableModel table, CellRange range) {
00094 
00095         //if region to paste to is out of bounds
00096        if (range != null) {
00097            int rowOff = range.getStartRow()-source.getStartRow();
00098            int colOff = range.getStartCol()-source.getStartCol();
00099            table.fromString(text, rowOff, colOff, range);
00100        }
00101     }            
00102     
00106     public CellRange getSource() {
00107         return source;
00108     }
00109     
00113     public void setSource(CellRange x) {
00114         source = x;
00115     }
00116 
00120     public String toString() { return text; }
00121 }
00122 
00123