📄 zdefaultcellpainter.java
字号:
/*
* Copyright 2002 EZCell , Inc. All rights reserved.
* Version 1.0.
* Author W.John
*/
package ezcell;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.text.DecimalFormat;
/**
* DOCUMENT ME!
*
* @version 1.00
* @author W.John
*/
class ZDefaultCellPainter extends ZAbstractCellPainter {
static DecimalFormat formatter = new DecimalFormat();
ZDefaultCellPainter(ZDefaultUI ui) {
super(ui);
}
/**
*
* @param g2
* @param cellLoc
* @param cell
*/
public void paint(Graphics2D g2, ZRect cellLoc, ZCell cell) {
if (!isDirtyRect(g2, cellLoc)) {
return;
}
ZDefaultSheet sheet = cell.getSheet();
// draw background and set text color
ZFont font;
ZBrush textBrush;
{
ZBrush brush = cell.getBackBrush();
brush.fill(g2, cellLoc);
textBrush = cell.getTextBrush();
}
// draw border line
paintBorder(cell, g2, cellLoc);
//{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ now draw text
String str = cell.getText();
try {
if (str != null) {
if (str.indexOf("&") >= 0) {
str = ZScriptEngine.getSharedInstance().translate(str);
} else if (str.charAt(0) == '?') {
str = sheet.getValue(cell);
}
}
} catch (Exception ex) {
}
if ((str != "") || cell.isHead()) {
try {
double d = Double.parseDouble(str);
String format = cell.getFormat();
if (format != "") {
formatter.applyPattern(format);
str = formatter.format(d);
}
} catch (Exception e) {
}
textBrush.setPaint(g2, cellLoc);
cellLoc.grow(-2, -2);
// max size of frame of a cell is 4 ,then should decrease the clip by 4/2;
Shape saveClip = g2.getClip();
g2.clipRect(cellLoc.left, cellLoc.top, cellLoc.getWidth(), cellLoc.getHeight());
paintText(cell, g2, cellLoc, str, cell.getHorzAlign(), cell.getVertAlign(), cell.getFont());
g2.setClip(saveClip);
cellLoc.grow(2, 2);
}
}
/**
* put your documentation comment here
* @param cell
* @param g2
* @param cellLoc
*/
protected void paintBorder(ZCell cell, Graphics2D g2, ZRect cellLoc) {
// top border
Color color = g2.getColor();
ZPen pen;
int w;
pen = ((ZDefaultCell) cell).getTopBorder();
if ((pen != null) && (pen.getWidth() > 0)) {
// System.out.println("ZDefaultCellPainter.paintBorder().top border:"+cell);
line.setLine(cellLoc.left, cellLoc.top, cellLoc.right, cellLoc.top);
pen.paint(g2);
g2.draw(line);
} else {
if (gridxVisible) {
gridxPen.paint(g2);
line.setLine(cellLoc.right, cellLoc.top, cellLoc.left, cellLoc.top);
g2.draw(line);
}
}
pen = ((ZDefaultCell) cell).getLeftBorder();
// System.out.println("ZDefaultCellPainter.paintBorder() .getleftborder"+cell);
if ((pen != null) && (pen.getWidth() > 0)) {
//System.out.println("ZDefaultCellPainter.paintBorder().left border:"+cell);
line.setLine(cellLoc.left, cellLoc.top, cellLoc.left, cellLoc.bottom);
pen.paint(g2);
g2.draw(line);
} else {
if (gridyVisible) {
gridyPen.paint(g2);
line.setLine(cellLoc.left, cellLoc.top, cellLoc.left, cellLoc.bottom);
g2.draw(line);
}
}
g2.setColor(color);
paintBottomRightBorder(cell, g2, cellLoc);
}
/**
*
* @param cell
* @param g2
* @param cellLoc
*/
protected void paintBottomRightBorder(ZCell cell, Graphics2D g2, ZRect cellLoc) {
ZPen pen;
int w;
pen = ((ZDefaultCell) cell).getBottomBorder();
if (pen != null) {
// System.out.println("ZDefaultCellPainter.paintBorder().bottom border:"+cell);
line.setLine(cellLoc.left, cellLoc.bottom, cellLoc.right, cellLoc.bottom);
pen.paint(g2);
g2.draw(line);
} else {
if (gridxVisible) {
gridxPen.paint(g2);
line.setLine(cellLoc.left, cellLoc.bottom, cellLoc.right, cellLoc.bottom);
g2.draw(line);
}
}
pen = ((ZDefaultCell) cell).getRightBorder();
if (pen != null) {
// System.out.println("ZDefaultCellPainter.paintBorder().right border:"+cell);
line.setLine(cellLoc.right, cellLoc.top, cellLoc.right, cellLoc.bottom);
pen.paint(g2);
g2.draw(line);
} else {
if (gridyVisible) {
gridyPen.paint(g2);
line.setLine(cellLoc.right, cellLoc.top, cellLoc.right, cellLoc.bottom);
g2.draw(line);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -