📄 zcopyitem.java
字号:
/*
* Copyright 2002 EZCell , Inc. All rights reserved.
* Version 1.0.
* Author W.John
*/
/*
* put your module comment here
* formatted with JxBeauty (c) johann.langhofer@nextra.at
*/
package ezcell;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Enumeration;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2001</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
import java.util.Vector;
/**
* put your documentation comment here
*/
public class ZCopyItem implements Serializable {
ZRect rect;
ZRect dropHelper; // to figure out drag target area
Vector cells = new Vector();
Vector rows = new Vector();
Vector cols = new Vector();
/**
* put your documentation comment here
*/
public ZCopyItem(ZRect rect, ZRect dropHelper, Vector cells, Vector rows, Vector cols) {
this.rect = rect;
this.dropHelper = dropHelper;
this.cells = cells;
this.rows = rows;
this.cols = cols;
retrieveDownRightBorders();
}
/**
*
* @return
*/
public ZRect getDropHelper() {
return dropHelper;
}
/**
* Pastes just texts from clipboard to the specified rectangular area .
* @param sheet
* @param rect
* @param cmdPrev
*
* @throws Exception
*/
public void pasteTo(ZDefaultSheet sheet, ZRect rect, ZCmdFormat cmdPrev)
throws Exception {
int offx;
int offy;
// Computes the target area
ZRect target = (ZRect) rect.clone();
target.right = target.left + this.rect.getWidth();
target.bottom = target.top + this.rect.getHeight();
// Is the target an invalid selection,For example ,it is intersected with merged cell.
// In that case ,Exception will be thrown.
sheet.validateSelection(target);
// Creates a ZCmdGroup used for holding every text edit(ZCmdFormat) .
ZCmdGroup cmdGroup = new ZCmdGroup(sheet, (ZRect) target.clone(), 0);
// Don't automatically add the following operations to undo list.
// Each of them composes a group command.
boolean autoUndo = ZCmdFormat.getAutoUndo();
ZCmdFormat.setAutoUndo(false);
// Clear target cells'text
ZCmdFormat cmdClear = sheet.clearSelectionText(target);
cmdGroup.add(cmdClear) ;
// Computes offset in x,y axis
offx = rect.left - this.rect.left;
offy = rect.top - this.rect.top;
// Walks through every cell ,with that of which replaces the target cell's text.
Enumeration enum = cells.elements();
while (enum.hasMoreElements()) {
ZDefaultCell cell = (ZDefaultCell) enum.nextElement();
ZCmdFormat cmd = sheet.setCellText(offy + cell.getRow(), offx + cell.getCol(), cell.getText());
cmdGroup.add(cmd);
}
// From now on,allows automatically undo journal.
ZCmdFormat.setAutoUndo(autoUndo);
}
/**
* put your documentation comment here
* @param sheet
* @param rect
*/
public void pasteToWithFormat(ZDefaultSheet sheet, ZRect rect, ZCmdFormat cmdPrev)
throws Exception {
int offx;
int offy;
boolean autoUndo = ZCmdFormat.getAutoUndo();
ZCmdFormat.setAutoUndo(false);
ZRect target = (ZRect) rect.clone();
target.right = target.left + this.rect.getWidth();
target.bottom = target.top + this.rect.getHeight();
sheet.validateSelection(target);
ZCmdClear cmdClear = new ZCmdClear(sheet, target);
cmdClear.commit();
offx = rect.left - this.rect.left;
offy = rect.top - this.rect.top;
Vector objects = new Vector();
Enumeration enum = cells.elements();
while (enum.hasMoreElements()) {
ZDefaultCell cell = (ZDefaultCell) enum.nextElement();
cell = (ZDefaultCell) cell.clone();
cell.setSheet(sheet);
cell.setRow(offy + cell.getRow());
cell.setCol(offx + cell.getCol());
objects.add(cell);
}
enum = rows.elements();
while (enum.hasMoreElements()) {
ZRow row = (ZRow) enum.nextElement();
row = (ZRow) row.clone();
row.setSheet(sheet);
row.setRow(offy + row.getRow());
objects.add(row);
}
enum = cols.elements();
while (enum.hasMoreElements()) {
ZCol col = (ZCol) enum.nextElement();
col = (ZCol) col.clone();
col.setSheet(sheet);
col.setCol(offx + col.getCol());
objects.add(col);
}
ZCmdAdd cmdAdd = new ZCmdAdd(sheet, objects);
cmdAdd.commit();
ZCmdFormat.setAutoUndo(autoUndo);
ZCmdGroup cmd = new ZCmdGroup(sheet, target, 0);
if (cmdPrev != null) {
cmd.add(cmdPrev);
}
cmd.add(cmdClear);
cmd.add(cmdAdd);
}
/**
*
* @param ois
*
* @throws ClassNotFoundException
* @throws IOException
*/
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
}
/**
* put your documentation comment here
*/
private void retrieveDownRightBorders() {
Enumeration enum = cells.elements();
while (enum.hasMoreElements()) {
ZDefaultCell cell = (ZDefaultCell) enum.nextElement();
if ((cell.col == rect.right) &&
((ZDefaultCell) cell.getSheet().getCell(cell.row, cell.col + 1)).hasProperty(ZBase.PTY_LeftBorder)) {
cell.setRightBorder(((ZDefaultCell) cell.getSheet().getCell(cell.row, cell.col + 1)).getLeftBorder0());
}
if ((cell.row == rect.bottom) &&
((ZDefaultCell) cell.getSheet().getCell(cell.row + 1, cell.col)).hasProperty(ZBase.PTY_TopBorder)) {
cell.setBottomBorder(((ZDefaultCell) cell.getSheet().getCell(cell.row + 1, cell.col)).getTopBorder0());
}
}
}
/**
*
* @param oos
*
* @throws IOException
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
}
}
/**
* put your documentation comment here
*/
class ZCopyItemSelection implements Transferable, ClipboardOwner {
static public DataFlavor clipFormat;
static {
try {
clipFormat = new DataFlavor(Class.forName("ezcell.ZCopyItem"), "CopyItem");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public ZCopyItem item;
private DataFlavor[] flavors = { clipFormat };
/**
* put your documentation comment here
* @param ZCopyItem item
*/
public ZCopyItemSelection(ZCopyItem item) {
this.item = item;
}
/**
* put your documentation comment here
* @param flavor
* @return
*/
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(clipFormat);
}
/**
* put your documentation comment here
* @param flavor
* @return
* @exception UnsupportedFlavorException, IOException
*/
public synchronized Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
if (flavor.equals(clipFormat)) {
return item;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
/**
* put your documentation comment here
* @return
*/
public synchronized DataFlavor[] getTransferDataFlavors() {
return flavors;
}
/**
* put your documentation comment here
* @param c
* @param t
*/
public void lostOwnership(Clipboard c, Transferable t) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -