📄 zdocument.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.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.awt.print.PageFormat;
import java.awt.print.Pageable;
import java.awt.print.Printable;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JComponent;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* put your documentation comment here
*/
class ZDocument implements Pageable {
static final int PAGE_HEADER = 0;
static final int PAGE_BODY = 1;
static final int PAGE_FOOTER = 2;
static final int NONE = 3;
static ZDefaultUI ui;
private ZBook book;
private ArrayList pages = new ArrayList();
private ZPrintableCells header;
private ZPrintableCells footer;
private ZSheetState headerModal;
private ZSheetCanvas headerCanvas;
private ZSheetState bodyModal;
private ZSheetCanvas bodyCanvas;
private ZSheetCanvas footerCanvas;
private ZSheetState footerModal;
private ZSheetStateControl control;
private ZSheetState editingModel;
float scale = 1.0f;
private Vector listeners = new Vector(); // for scale ,margin ,format changed notify it;
/**
* put your documentation comment here
* @param ZBook book
*/
public ZDocument(ZBook book) {
this.book = book;
this.book.addListener(new ZBookAdapter() {
/**
* put your documentation comment here
* @param e
*/
public void pageFormatChanged(ChangeEvent e) {
updateFormat();
}
;
});
ZSheet pe = null;
// prepare ui
// header
ui = (ZDefaultUI) ZUIManager.getDefault().clone();
ui.put(ZDefaultUI.LEFT_HEAD_VISIBLE, new Boolean(false));
ui.put(ZDefaultUI.TOP_HEAD_VISIBLE, new Boolean(false));
ui.put(ZDefaultUI.GRID_X_VISIBLE, new Boolean(false));
ui.put(ZDefaultUI.GRID_Y_VISIBLE, new Boolean(false));
ui.put(ZDefaultUI.SELECTION_VISIBLE, new Boolean(false));
ZSheetStateListener lst = new ZSheetStateAdapter() {
/**
* put your documentation comment here
* @param modal
*/
public void uiStateChanged(ZSheetState modal) {
if (scale != modal.getScale()) {
setScale(modal.getScale());
}
}
};
if ((pe = book.getHeader()) != null) {
headerModal = new ZPrintSheetState(pe);
headerModal.setUI(ui);
headerModal.addListener(lst);
headerCanvas = new ZSheetCanvas(headerModal);
headerCanvas.setPainter(new ZDefaultSheetPainter(ui), new ZDefaultHeadCellPainter(ui), new ZDefaultCellPainter(ui),
new ZDefaultSelectionPainter(ui));
}
if ((pe = book.getFooter()) != null) {
footerModal = new ZPrintSheetState(pe);
footerModal.setUI(ui);
footerModal.addListener(lst);
footerCanvas = new ZSheetCanvas(footerModal);
footerCanvas.setPainter(new ZDefaultSheetPainter(ui), new ZDefaultHeadCellPainter(ui), new ZDefaultCellPainter(ui),
new ZDefaultSelectionPainter(ui));
}
if ((pe = book.getSheet(0)) != null) {
bodyModal = new ZPrintSheetState(pe);
bodyModal.setUI(ui);
bodyModal.addListener(lst);
bodyCanvas = new ZSheetCanvas(bodyModal);
bodyCanvas.setPainter(new ZDefaultSheetPainter(ui), new ZDefaultHeadCellPainter(ui), new ZDefaultCellPainter(ui),
new ZDefaultSelectionPainter(ui));
}
setScale(scale);
}
/**
* put your documentation comment here
* @return
*/
public ZRect getBodyArea() {
ZRect imageable = getImageArea();
imageable.top += book.getHeaderHeight();
imageable.bottom -= book.getFooterHeight();
return imageable;
}
/**
* put your documentation comment here
* @param modal
* @param editable
*/
public void setEditable(ZSheetState modal, boolean editable) {
ui.put(ZDefaultUI.SELECTION_VISIBLE, new Boolean(editable));
ui.put(ZDefaultUI.GRID_X_VISIBLE, new Boolean(editable));
ui.put(ZDefaultUI.GRID_Y_VISIBLE, new Boolean(editable));
if (editable) {
editingModel = modal;
}
modal.setUI(ui);
}
/**
* put your documentation comment here
* @return
*/
public ZPrintableCells getFooter() {
return footer;
}
/**
* put your documentation comment here
* @return
*/
public ZRect getFooterArea() {
ZRect footerArea = getImageArea();
footerArea.top = footerArea.bottom - book.getFooterHeight();
return footerArea;
}
/**
* put your documentation comment here
* @param h
*/
public void setFooterHeight(int h) {
book.setFooterHeight(h);
}
/**
* put your documentation comment here
* @return
*/
public int getFooterHeight() {
return book.getFooterHeight();
}
/**
* put your documentation comment here
* @return
*/
public ZSheetState getFooterModal() {
return footerModal;
}
/**
* put your documentation comment here
* @return
*/
public ZPrintableCells getHeader() {
return header;
}
/**
* put your documentation comment here
* @return
*/
public ZRect getHeaderArea() {
ZRect headerArea = getImageArea();
headerArea.bottom = headerArea.top + book.getHeaderHeight();
return headerArea;
}
/**
* put your documentation comment here
* @param h
*/
public void setHeaderHeight(int h) {
book.setHeaderHeight(h);
}
/**
* put your documentation comment here
* @return
*/
public int getHeaderHeight() {
return book.getHeaderHeight();
}
/**
* put your documentation comment here
* @return
*/
public ZSheetState getHeaderModal() {
return headerModal;
}
/**
* put your documentation comment here
* @return
*/
public ZRect getImageArea() {
PageFormat pf = book.getPageFormat();
return new ZRect((int) pf.getImageableX(), (int) pf.getImageableY(),
(int) (pf.getImageableX() + pf.getImageableWidth()),
(int) (pf.getImageableY() + pf.getImageableHeight()));
}
/**
*
* @return
*/
public int getNumberOfPages() {
return pages.size();
}
/**
* put your documentation comment here
* @param index
* @return
*/
public ZPage getPage(int index) {
if ((index >= 0) && (index < pages.size())) {
return (ZPage) pages.get(index);
} else {
return null;
}
}
/**
* put your documentation comment here
* @return
*/
public int getPageCount() {
return pages.size();
}
/**
* put your documentation comment here
* @param pf
*/
public void setPageFormat(PageFormat pf) {
book.setPageFormat(pf);
}
/**
* put your documentation comment here
* @return
*/
public PageFormat getPageFormat() {
return book.getPageFormat();
}
/**
* put your documentation comment here
* @param index
* @return
* @exception IndexOutOfBoundsException
*/
public PageFormat getPageFormat(int index) throws IndexOutOfBoundsException {
return book.getPageFormat();
}
/**
* put your documentation comment here
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -