📄 zstatecontrol.java
字号:
public void loadShortKeys(JPanel comp) {
InputMap im = comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
ActionMap am = comp.getActionMap();
for (int i = 0; i < keyStrokes.length; i++) {
if (keyStrokes[i] != null) {
ZShortKey shortKey = new ZShortKey(i);
Object key = new Integer(i);
im.put(keyStrokes[i], key);
am.put(key, shortKey);
}
}
}
/**
*
* @param ui
*/
public void updateUI(ZDefaultUI ui) {
hiLinePen = (ZPen) ui.get(ZDefaultUI.RESIZE_BAR_PEN);
}
/**
*
* @param modal
*/
void setModal(ZSheetState modal) {
this.modal = modal;
updateUI(ZUIManager.getDefault());
info.mainState = STATE_IDLE;
info.subState = SUBSTATE_IDLE;
}
/**
*
* @param point
*/
void doResize(Point point) {
if (info.subState == SUBSTATE_COLUMN_RESIZING) {
if (point.x == info.lastMousePosition.x) {
return;
}
point.x = Math.max(point.x, info.minPoint.x);
modal.moveShape(vertResizeBar, point);
} else {
if (point.y == info.lastMousePosition.y) {
return;
}
point.y = Math.max(point.y, info.minPoint.y);
modal.moveShape(horzResizeBar, point);
}
}
/**
*
* @param point
*/
void doSelect(Point point) {
ZRect selection = new ZRect();
try {
ZCellID cid = modal.hitCell(point);
// if last selection be the same as current one, do nothing
if ((info.lastSelCell.x == cid.col) && (info.lastSelCell.y == cid.row)) {
return;
}
info.lastSelCell.x = cid.col;
info.lastSelCell.y = cid.row;
selection.setRect(info.startCol, info.startRow, cid.col, cid.row);
selection.normalize();
if (info.subState == SUBSTATE_COLUMN_SELECTED) {
selection.bottom = modal.getSheet().getLastRow();
selection.top = 0;
selection.left = Math.max(1, selection.left);
} else if (info.subState == SUBSTATE_ROW_SELECTED) {
selection.right = modal.getSheet().getLastCol();
selection.left = 0;
selection.top = Math.max(1, selection.top);
} else {
selection.left = Math.max(1, selection.left);
selection.top = Math.max(1, selection.top);
}
modal.setSelection((ZRect) selection.clone());
} catch (ZException e) {
}
;
}
/**
*/
void endDrag() {
if (info.mainState != STATE_IDLE) {
if (info.mainState == STATE_SELECTING) {
endSelect();
} else {
endResize();
}
}
info.mainState = STATE_IDLE;
info.subState = SUBSTATE_IDLE;
}
/**
*/
void endResize() {
int s;
ZRect cells;
try {
ZRect selection = modal.getSelection();
if (info.subState == SUBSTATE_COLUMN_RESIZING) {
if (selection.containCell(0, info.startCol) && (selection.type(modal.getSheet()) == ZRect.COLUMNS)) {
cells = selection;
} else {
cells = new ZRect(info.startCol, 0, info.startCol, modal.getSheet().getLastRow());
}
s = info.lastMousePosition.x - info.minPoint.x;
modal.killShape(vertResizeBar);
modal.getSheet().setSelectionWidth(cells, s);
} else if (info.subState == SUBSTATE_ROW_RESIZING) {
if (selection.containCell(info.startRow, 0) && (selection.type(modal.getSheet()) == ZRect.ROWS)) {
cells = selection;
} else {
cells = new ZRect(0, info.startRow, modal.getSheet().getLastCol(), info.startRow);
}
s = info.lastMousePosition.y - info.minPoint.y;
modal.killShape(horzResizeBar);
modal.getSheet().setSelectionHeight(cells, s);
}
} catch (ZSelectionNoSupported e) {
System.out.println(e.toString());
}
}
/**
*/
void endSelect() {
info.mainState = STATE_IDLE;
}
/**
*
* @param point
*/
void startResize(Point point) {
info.mainState = STATE_RESIZING;
info.subState = (info.subState == SUBSTATE_ROW_RESIZE_READY) ? SUBSTATE_ROW_RESIZING : SUBSTATE_COLUMN_RESIZING;
if (info.subState == SUBSTATE_COLUMN_RESIZING) {
point.x = Math.max(point.x, info.minPoint.x);
vertResizeBar = new ZShape.HLine(ZShape.VERTICAL, point.x, hiLinePen);
modal.addShape(vertResizeBar);
} else {
point.y = Math.max(point.y, info.minPoint.y);
horzResizeBar = new ZShape.HLine(ZShape.HORIZONTAL, point.y, hiLinePen);
modal.addShape(horzResizeBar);
}
}
/**
*
* @param point
*/
void startSelect(Point point) {
try {
ZCellID cid = modal.hitCell(point);
if ((cid.row == 0) && (cid.col == 0)) {
return;
}
ZRect selection = new ZRect();
if (cid.col == 0) // if hit the top header
{
selection.setRect(0, cid.row, modal.getSheet().getLastCol(), cid.row);
cid.col = modal.getVisibleCells().left;
info.subState = SUBSTATE_ROW_SELECTED;
} else if (cid.row == 0) {
selection.setRect(cid.col, 0, cid.col, modal.getSheet().getLastRow());
cid.row = modal.getVisibleCells().top;
info.subState = SUBSTATE_COLUMN_SELECTED;
} else {
selection.setRect(cid.col, cid.row, cid.col, cid.row);
info.subState = SUBSTATE_CELL_SELECTED;
}
// change focused cell
// save current state and selection start from ...
info.startRow = selection.top;
info.startCol = selection.left;
info.lastSelCell.x = info.startCol;
info.lastSelCell.y = info.startRow;
info.mainState = STATE_SELECTING;
modal.setFocus(cid);
modal.setSelection((ZRect) selection.clone());
} catch (ZException e) {
// e.printStackTrace();
}
}
/**
*
* @param p
*
* @return
*/
private Point adjustOuterPoint(Point p) {
p = new Point(p);
if (p.x > modal.getClip().right) {
ZRect vc = (ZRect) modal.getVisibleCells().clone();
vc.left++;
modal.setVisibleCells(vc);
p.x = modal.getClip().right;
}
if (p.x < 0) {
ZRect vc = (ZRect) modal.getVisibleCells().clone();
vc.left--;
modal.setVisibleCells(vc);
p.x = 1;
}
if (p.y > modal.getClip().bottom) {
ZRect vc = (ZRect) modal.getVisibleCells().clone();
vc.top++;
modal.setVisibleCells(vc);
p.y = modal.getClip().bottom - 1;
}
if (p.y < 0) {
ZRect vc = (ZRect) modal.getVisibleCells().clone();
vc.top--;
modal.setVisibleCells(vc);
p.y = 1;
}
return p;
}
/**
*
* @param cid
*/
private void editCell(ZCellID cid) {
try {
ZRect loc = null;
ZCell cell = modal.getSheet().getCell(cid.row, cid.col);
if (cell.isChild()) {
cell = cell.getParent();
}
if (cell.isParent()) {
loc = modal.getCellsRect(cell.getSpan());
} else {
loc = modal.getCellRect(cell);
}
loc.grow(2, 2);
editor.init(cell.getRow(), cell.getCol(), cell.getText(), modal.lr2dr(loc));
modal.addEditor(editor);
} catch (Exception ex) {
}
}
/**
* DOCUMENT ME!
*
* @version 1.00
* @author W.John
*/
class _inputInfo {
public int mainState; // STATE_IDLE/STATE_SELECTING/STATE_RESIZING
// STATE_IDLE{SUBSTATE_IDLE,SUBSTATE_ROW_RESIZE_READY,SUBSTATE_COLUMN_RESIZE_READY}
// STATE_SELECTING,
// STATE_RESIZING{SUBSTATE_ROW_RESIZING,SUBSTATE_COLUMN_RESIZING}
public int subState;
public ZRect lastResizeLine = new ZRect();
public int startRow;
public int startCol;
// when resizing ,it save the left of column or the top of the row which resized
// if selecting ,limited min left or min top can be painted
// if resizing , saving current row and col
public Point minPoint = new Point();
public Point lastSelCell = new Point();
public Point lastMousePosition;
}
/**
* DOCUMENT ME!
*
* @version 1.00
* @author W.John
*/
class ZShortKey extends AbstractAction {
private int command;
ZShortKey(int command) {
this.command = command;
}
/**
*
* @param e
*/
public void actionPerformed(ActionEvent e) {
switch (command) {
case EXPAND_SELECTION_DOWN:
case EXPAND_SELECTION_RIGHT:
case EXPAND_SELECTION_LEFT:
case EXPAND_SELECTION_UP:
modal.expandSelection(command - EXPAND_SELECTION_UP);
break;
case MOVE_FOCUS_IN_SELECTION_DOWN:
case MOVE_FOCUS_IN_SELECTION_RIGHT:
case MOVE_FOCUS_IN_SELECTION_LEFT:
case MOVE_FOCUS_IN_SELECTION_UP:
modal.moveFocusInSelection(command - MOVE_FOCUS_IN_SELECTION_UP);
break;
case MOVE_FOCUS_WITH_SELECTION_DOWN:
case MOVE_FOCUS_WITH_SELECTION_RIGHT:
case MOVE_FOCUS_WITH_SELECTION_LEFT:
case MOVE_FOCUS_WITH_SELECTION_UP:
modal.moveFocusWithSelection(command - MOVE_FOCUS_WITH_SELECTION_UP);
break;
case COPY:
modal.copy();
break;
case CUT:
modal.cut();
break;
case PASTE:
modal.paste();
break;
case CLEAR:
modal.clear();
break;
case UNDO:
try {
ZCmdFormat.undoManager.undo();
} catch (CannotUndoException ex) {
}
break;
case REDO:
try {
ZCmdFormat.undoManager.redo();
} catch (CannotUndoException ex) {
}
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -