⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zstatecontrol.java

📁 用Java写的报表.功能如下: 0.内建网络打印,网络预览功能! 1.文件操作。包括url 指定的文件。 2.全功能打印支持。包括打印预览。 3.Undo 和 redo。 4.合并单元格。 5.Cel
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     */
    public void dragOver(DragSourceDragEvent event) {
    }

    /**
     *
     * @param event
     */
    public void dragOver(DropTargetDragEvent event) { // you can provide visual feedback here

        try {
            ZCellID cid = modal.hitCell(modal.dp2lp(event.getLocation()));

            if ((cid.row == info.startRow) && (cid.col == info.startCol)) {
                return;
            }

            if (dropTarget.type(modal.getSheet()) != ZRect.COLUMNS) {
                dropTarget.top = dropHelper.top + cid.row;
                dropTarget.bottom = dropHelper.bottom + cid.row;

                if (dropTarget.top < 1) {
                    dropTarget.bottom = dropTarget.getHeight() + 1;
                    dropTarget.top = 1;
                } else if (dropTarget.bottom > modal.getSheet().getLastRow()) {
                    dropTarget.top = modal.getSheet().getLastRow() - dropTarget.getHeight();
                    dropTarget.bottom = modal.getSheet().getLastRow();
                }
            }

            if (dropTarget.type(modal.getSheet()) != ZRect.ROWS) {
                dropTarget.left = dropHelper.left + cid.col;
                dropTarget.right = dropHelper.right + cid.col;

                if (dropTarget.left < 1) {
                    dropTarget.right = dropTarget.getWidth() + 1;
                    dropTarget.left = 1;
                } else if (dropTarget.right > modal.getSheet().getLastCol()) {
                    dropTarget.left = modal.getSheet().getLastCol() - dropTarget.getWidth();
                    dropTarget.right = modal.getSheet().getLastCol();
                }
            }

            /// add drag tracker
            ZRect visibleDragger = (ZRect) modal.getVisibleCells().clone();

            if (!visibleDragger.isIntersects(dropTarget)) {
                return;
            }

            visibleDragger.intersection(dropTarget);

            // get draw rect of clip cells;
            ZRect frame = modal.getCellsRect(visibleDragger);

            if (dragger == null) {
                dragger = new ZShape.Rectangle(frame.left, frame.top, frame.right, frame.bottom, -100);
                dragger.pen = hiLinePen;
                modal.addShape(dragger);
            } else {
                modal.moveShape(dragger, frame);
            }

            info.startRow = cid.row;
            info.startCol = cid.col;
        } catch (ZException ex) {
        }
    }

    /**
     *
     * @param event
     */
    public void drop(DropTargetDropEvent event) {
        if (!isDropAcceptable(event)) {
            event.rejectDrop();
            dragSource = null;

            return;
        }

        if(dragger!=null)
          modal.killShape(dragger);

        try {
            ZCmdFormat cmdClear = null;

            if ((((DropTarget) event.getSource()).getComponent() == dragSource) &&
                    (event.getDropAction() == DnDConstants.ACTION_MOVE)) {
                boolean autoUndo = ZCmdFormat.getAutoUndo();
                ZCmdFormat.setAutoUndo(false);
                cmdClear = modal.getSheet().clearSelection(modal.getSelection());
                ZCmdFormat.setAutoUndo(autoUndo);
            }

            dragSource = null;
            event.acceptDrop(event.getDropAction());

            Transferable tf = event.getTransferable();
            ZCopyItem item = (ZCopyItem) tf.getTransferData(ZSerializableSelection.serializableFlavor);
            modal.setSelection((ZRect) dropTarget.clone());
            item.pasteToWithFormat((ZDefaultSheet) (modal.getSheet()), dropTarget, cmdClear);
            event.dropComplete(true);
        } catch (Exception ex) {
        }

        info.subState = SUBSTATE_IDLE;
    }

    /**
     *
     * @param event
     */
    public void dropActionChanged(DragSourceDragEvent event) {
    }

    /**
     *
     * @param event
     */
    public void dropActionChanged(DropTargetDragEvent event) {
        if (!isDragAcceptable(event)) {
            event.rejectDrag();

            return;
        }
    }

    /**
     *
     * @param editor
     */
    public void editFinished(ZEditor editor) {
        if (modal == null) {
            return;
        }

        if (editor.isChanged()) {
            ((ZDefaultSheet) editor.getModal().getSheet()).setCellText(editor.getRow(), editor.getCol(), editor.getText());
        }

        modal.killEditor(editor);
    }

    /**
     *
     * @param e
     */
    public void focusGained(FocusEvent e) {
        if (modal != null) {
            modal.requestFocus();
        }
    }

    /**
     *
     * @param e
     */
    public void focusLost(FocusEvent e) {
    }

    /**
     *
     * @param e
     */
    public void keyPressed(KeyEvent e) {    }

    /**
     *
     * @param e
     */
    public void keyReleased(KeyEvent e) {
    }

    /**
     *
     * @param e
     */
    public void keyTyped(KeyEvent e) {
        if ((e.getModifiers() & (KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK)) != 0) {
            return;
        }

        switch (e.getKeyChar()) {
        case KeyEvent.VK_ENTER:
        case KeyEvent.VK_ESCAPE:
            break;

        default:
            e.consume();

            ZCellID fs = modal.getFocus();

            if (!modal.getVisibleCells().containCell(fs.row, fs.col)) {
                modal.scrollCellIntoView(fs.row, fs.col);
            }

            editCell(modal.getFocus());
            sendKey(editor, e.getKeyCode(), e.getKeyChar());

            break;
        }
    }

    /**
     *
     * @param e
     */
    public void mouseClicked(MouseEvent e) {
        endDrag();
    }

    /**
     *
     * @param e
     */
    public void mouseDragged(MouseEvent e) {
        Point curPos = null;

        if (info.mainState == STATE_RESIZING) {
            curPos = modal.dp2lp(e.getPoint());
            doResize(curPos);
        } else if (info.mainState == STATE_SELECTING) {
            if (!modal.getClip().contain(e.getX(), e.getY())) {
                curPos = modal.dp2lp(adjustOuterPoint(e.getPoint()));
            } else {
                curPos = modal.dp2lp(e.getPoint());
            }

            doSelect(curPos);
        } else if (info.mainState == STATE_IDLE) {
            curPos = modal.dp2lp(e.getPoint());

            if ((info.subState == SUBSTATE_ROW_RESIZE_READY) || (info.subState == SUBSTATE_COLUMN_RESIZE_READY)) {
                startResize(curPos);
            } else if (info.subState != SUBSTATE_DRAG_READY) {
                startSelect(curPos);
            }
        } else {
            curPos = modal.dp2lp(e.getPoint());
        }

        info.lastMousePosition = curPos;
    }

    /**
     *
     * @param e
     */
    public void mouseEntered(MouseEvent e) {
    }

    /**
     *
     * @param e
     */
    public void mouseExited(MouseEvent e) {
    }

    /**
     *
     * @param e
     */
    public void mouseMoved(MouseEvent e) {
        Point curPos = modal.dp2lp(e.getPoint());

        try {
            if (info.mainState == STATE_IDLE) {
                ZShape ho = modal.hit(curPos);

                switch (ho.getID()) {
                case ZSheetState.HIT_LEFT_BREAK:
                    modal.setCursor(ZSheetState.RESIZE_ROW_CURSOR);

                    ZShape.Row row = (ZShape.Row) ((ZShape.Rectangle) ho).object;
                    info.minPoint.y = row.top;
                    info.startRow = row.id;
                    info.subState = SUBSTATE_ROW_RESIZE_READY;

                    break;

                case ZSheetState.HIT_TOP_BREAK:
                    modal.setCursor(ZSheetState.RESIZE_COL_CURSOR);

                    ZShape.Col col = (ZShape.Col) ((ZShape.Rectangle) ho).object;
                    info.minPoint.x = col.left;
                    info.startCol = col.id;
                    info.subState = SUBSTATE_COLUMN_RESIZE_READY;

                    break;

                case ZSheetState.HIT_DRAG_TRACKER:
                    modal.setCursor(ZSheetState.MOVE_CURSOR);
                    info.subState = SUBSTATE_DRAG_READY;

                    break;

                default:
                    modal.setCursor(ZSheetState.DEFAULT_CURSOR);
                    info.subState = SUBSTATE_IDLE;
                }
            } else {
                endDrag();
            }

            info.lastMousePosition = curPos;
        } catch (Exception ex) {
        }
    }

    /**
     *
     * @param e
     */
    public void mousePressed(MouseEvent e) {
        if (modal != null) {
            modal.requestFocus();
        }

        Point curPos = modal.dp2lp(e.getPoint());

        try {
            if (e.getClickCount() > 1) {
                if (!modal.isEditable()) {
                    return;
                }

                ZCellID cid = modal.hitCell(curPos);

                if ((cid.row == 0) || (cid.col == 0)) {
                    return;
                }

                editCell(cid);
            } else {
                if (info.subState == SUBSTATE_IDLE) {
                    startSelect(curPos);
                    endSelect();
                }
            }
        } catch (ZException ex) {
        }
    }

    /**
     *
     * @param e
     */
    public void mouseReleased(MouseEvent e) {
        endDrag();
    }

    /**
     *
     * @param comp
     * @param p
     * @param is
     */
    public void scrolled(Component comp, Point p, Insets is) {
        if (p.x < is.left) {
            p.x -= is.left;
        } else if (p.x > (comp.getWidth() - is.right)) {
            p.x += is.right;
        }

        if (p.y < is.top) {
            p.y -= is.top;
        } else if (p.y > (comp.getHeight() - is.bottom)) {
            p.y += is.bottom;
        }

        adjustOuterPoint(p);
        dragger = null;
    }

    /**
     *
     * @param comp
     * @param vk_code
     * @param keyChar
     */
    public static void sendKey(Component comp, int vk_code, char keyChar) {
        KeyEvent k = new KeyEvent(comp, KeyEvent.KEY_TYPED, new Date().getTime(), 0, KeyEvent.VK_UNDEFINED, keyChar);
        comp.dispatchEvent(k);
    }

    /**
     *
     * @param comp
     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -