📄 zdefaultsheet.java
字号:
* put your documentation comment here
* @param rect
* @param value
*/
public void setSelectionReadOnly(ZRect rect, boolean value)
throws ZSelectionNoSupported {
validateSelection(rect);
ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_ReadOnly, new Boolean(value),
new ZCmdWorker() {
/**
* put your documentation comment here
* @param cmd
* @param obj
*/
public void workOnObject(ZCmdFormat cmd, ZBase obj) {
Boolean value = (Boolean) cmd.getValueObject();
obj.setReadOnly(value.booleanValue());
}
});
cmd.commit();
}
/**
* put your documentation comment here
* @param rect
* @param value
*/
public void setSelectionTextBrush(ZRect rect, ZBrush value)
throws ZSelectionNoSupported {
validateSelection(rect);
ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_TextBrush, value,
new ZCmdWorker() {
/**
* put your documentation comment here
* @param cmd
* @param obj
*/
public void workOnObject(ZCmdFormat cmd, ZBase obj) {
ZBrush value = (ZBrush) cmd.getValueObject();
obj.setTextBrush((ZBrush) value.clone());
}
});
cmd.commit();
}
/**
*
* @param rect
* @param dropHelper
*
* @return
*/
public Transferable getSelectionTransferable(ZRect rect, ZRect dropHelper) {
Vector cells = new Vector();
Vector rows = new Vector();
Vector cols = new Vector();
if (rect.type(this) == ZRect.CELLS) {
copyCells(rect, cells);
} else if (rect.type(this) == ZRect.ROWS) {
copyRows(rect.top, rect.bottom, rows, cells);
} else {
copyCols(rect.left, rect.right, cols, cells);
}
ZCopyItem item = new ZCopyItem((ZRect) rect.clone(), dropHelper, cells, rows, cols);
return new ZSerializableSelection(item);
}
/**
* put your documentation comment here
* @param rect
* @param value
*/
public void setSelectionVertAlign(ZRect rect, int value)
throws ZSelectionNoSupported {
validateSelection(rect);
ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_VertAlign, new Integer(value),
new ZCmdWorker() {
/**
* put your documentation comment here
* @param cmd
* @param obj
*/
public void workOnObject(ZCmdFormat cmd, ZBase obj) {
Integer value = (Integer) cmd.getValueObject();
obj.setVertAlign(value.intValue());
}
});
cmd.commit();
}
/**
* put your documentation comment here
* @param rect
* @param width
*/
public void setSelectionWidth(ZRect rect, int width)
throws ZSelectionNoSupported {
// validateSelection(rect, ZRect.COLUMNS | ZRect.CELLS);
rect = (ZRect) rect.clone();
rect.top = 0;
rect.bottom = lastRow;
//
// make sure selection type is Cols
// validateSelection(rect, ZRect.COLUMNS);
ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_Width, new Integer(width),
new ZCmdWorker(ZCmdWorker.ACCEPT_COLUMN) {
/**
* put your documentation comment here
* @param cmd
* @param obj
*/
public void workOnObject(ZCmdFormat cmd, ZBase obj) {
Integer width = (Integer) cmd.getValueObject();
ZCol col = (ZCol) obj;
col.setWidth(width.intValue());
}
});
cmd.commit();
}
/**
*
* @param rect
* @param value
*
* @throws ZSelectionNoSupported
*/
public void setSelectionWordWrap(ZRect rect, boolean value)
throws ZSelectionNoSupported {
validateSelection(rect);
ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_WordWrap, new Boolean(value),
new ZCmdWorker() {
/**
* put your documentation comment here
* @param cmd
* @param obj
*/
public void workOnObject(ZCmdFormat cmd, ZBase obj) {
Boolean value = (Boolean) cmd.getValueObject();
obj.setWordWrap(value.booleanValue());
}
});
cmd.commit();
}
/**
*
* @param byrow
*
* @return
*/
public Vector getSortedCells(boolean byrow) {
Vector obs = (Vector) getCells().clone();
ZDefaultCell.compareByRow = byrow;
Collections.sort(obs);
return obs;
}
/**
*
* @param title
*/
public void setTitle(String title) {
if (this.title.equals(title)) {
return;
}
this.title = title;
this.firePropertyChanged(this, false);
}
/**
* put your documentation comment here
* @return
*/
public String getTitle() {
return title;
}
/**
*
* @param cell
*
* @return
*
* @throws Exception
*/
public String getValue(ZCell cell) throws Exception {
return getCalculator().getText(cell);
}
/**
* put your documentation comment here
* @param obj
*/
public void add(ZBase obj) {
int i;
int r0 = obj.getRow() / maxElement;
int c0 = obj.getCol() / maxElement;
int r1 = obj.getRow() % maxElement;
int c1 = obj.getCol() % maxElement;
Vector tmpVect = null;
ZBase oldObj;
switch (obj.type()) {
case ZBase.CELL:
oldObj = getExistCell(obj.getRow(), obj.getCol());
if (oldObj != null) {
remove(oldObj);
}
if ((tmpVect = (Vector) cellsTable.elementAt((maxElement * r0) + c0)) == null) // the block not exist, create one!
{
tmpVect = new Vector(100);
tmpVect.setSize(maxElement * maxElement);
cellsTable.setElementAt(tmpVect, (maxElement * r0) + c0);
}
tmpVect.setElementAt(obj, (maxElement * r1) + c1);
cellsList.add(obj);
getCalculator().set((ZDefaultCell) obj);
if (obj.hasProperty(ZBase.PTY_MergeAsParent)) {
addParentCell((ZDefaultCell) obj);
}
break;
case ZBase.ROW:
oldObj = getExistRow(obj.getRow());
if (oldObj != null) {
remove(oldObj);
}
if ((tmpVect = (Vector) rowsTable.elementAt(r0)) == null) {
tmpVect = new Vector(100);
tmpVect.setSize(maxElement);
rowsTable.setElementAt(tmpVect, r0);
}
tmpVect.setElementAt(obj, r1);
rowsList.add(obj);
break;
case ZBase.COLUMN:
oldObj = getExistCol(obj.getCol());
if (oldObj != null) {
remove(oldObj);
}
if ((tmpVect = (Vector) colsTable.elementAt(c0)) == null) {
tmpVect = new Vector(100);
tmpVect.setSize(maxElement);
colsTable.setElementAt(tmpVect, c0);
}
tmpVect.setElementAt(obj, c1);
colsList.add(obj);
break;
}
obj.setSheet(this);
}
/**
*
* @param listener
*/
public void addListener(ZSheetListener listener) {
listeners.add(listener);
}
/**
* put your documentation comment here
* @param cell
*/
public void addParentCell(ZDefaultCell cell) {
if (parentCellsList.indexOf(cell) == -1) {
parentCellsList.add(cell);
}
}
/**
*
* @param rect
*
* @return
*
* @throws ZSelectionNoSupported
*/
public ZCmdFormat clearSelectionText(ZRect rect) throws ZSelectionNoSupported {
validateSelection(rect);
ZCmdFormat cmd = new ZCmdFormat(this, rect, ZBase.PTY_Text, "",
new ZCmdWorker() {
/**
* put your documentation comment here
* @param cmd
* @param obj
*/
public void workOnObject(ZCmdFormat cmd, ZBase obj) {
if (obj.type() != ZBase.CELL) {
return;
}
ZDefaultCell cell = (ZDefaultCell) obj;
cell.setText("");
}
});
cmd.commit();
return cmd;
}
/**
*
* @param sid
*
* @return
*/
static public int intId(String sid) {
int result = 0;
int carry = 1;
for (int i = sid.length() - 1; i >= 0; i--) {
result += ((sid.charAt(i) - 'A' + 1) * carry);
carry *= 26;
}
return result;
}
/**
* put your documentation comment here
* @param index
* @return
*/
static public String strId(int index) {
String result = new String();
int k = (--index) % 26;
char ch;
while ((index = index / 26) != 0) {
result = String.valueOf((char) (k + 'A')) + result;
k = index % 26;
}
result = String.valueOf((char) (k + 'A')) + result;
return result;
}
/**
* put your documentation comment here
* @param cookie
*/
public void setCookie(int cookie) {
this.cookie = cookie;
}
/**
* put your documentation comment here
* @param from
* @param count
*/
public void setInsertCols(int from, int count) {
try {
insertSelection(new ZRect(from, 0, (from + count) - 1, lastRow));
} catch (ZSelectionNoSupported e) {
}
}
/**
* put your documentation comment here
* @param from
* @param count
*/
public void setInsertRows(int from, int count) {
try {
insertSelection(new ZRect(0, from, lastCol, (from + count) - 1));
} catch (ZSelectionNoSupported e) {
}
}
/**
* put your documentation comment here
* @return
*/
public int getLastCol() {
return lastCol;
}
/**
* put your documentation comment here
* @return
*/
public int getLastRow() {
return lastRow;
}
/**
*
* @param seed
*
* @return
*/
public ZRect getMerged(ZRect seed) {
Vector pcs = (Vector) parentCellsList.clone();
while (pcs.size() > 0) {
boolean go = false;
for (int i = 0; i < pcs.size(); i++) {
ZCell cell = (ZCell) pcs.get(i);
ZRect parentRect = cell.getSpan();
if (seed.isIntersects(parentRect)) {
seed.union(parentRect);
pcs.remove(cell);
go = true;
break;
}
}
if (go) {
continue;
} else {
break;
}
}
return seed;
}
/**
* put your documentation comment here
* @param modified
*/
public void setModified(boolean modified) {
book.setModified(modified);
}
/**
* put your documentation comment here
* @return
*/
public Enumeration getParentCellsEnum() {
return parentCellsList.elements();
}
/**
* put your documentation comment here
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -