📄 printorga.java
字号:
direction = OrgChartPanel.TREE;
}
}
}
if (fXSIZE == 0)
{
fXSIZE = maxporgaw;
}
else
{
int cwidth = ((Integer) (info.get(OrgChartPanel.WIDTH))).intValue() +
OrgChartPanel.SPACEV;
if (direction == OrgChartPanel.VERTICAL)
{
cwidth += OrgChartPanel.PHOTO_SZ;
}
int nbcaz = fXSIZE / cwidth;
fXSIZE = nbcaz * cwidth;
}
if (fYSIZE == 0)
{
fYSIZE = maxporgah;
}
int nbPageX = ((maxporgaw - SPACE2) / fXSIZE) + 1;
nbPageY = ((maxporgah - SPACE2) / fYSIZE) + 1;
maxporgah = nbPageY * fYSIZE;
Document document = new Document(new Rectangle(fXSIZE, fYSIZE), OrgChartPanel.SPACEV, OrgChartPanel.SPACEV,
OrgChartPanel.SPACEV, OrgChartPanel.SPACEV);
try
{
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(filename));
document.open();
PdfContentByte cb = writer.getDirectContent();
for (int x = 1; x <= nbPageX; x++)
{
for (int y = 1; y <= nbPageY; y++)
{
if ((x > 1) || (y > 1))
{
document.newPage();
}
Graphic grx = new Graphic();
grx.setLineWidth(LINE_SZ);
// 1 - draw rectangles
drawRectangle(grx, tree, x, y);
grx.stroke();
document.add(grx);
// 2 - add attributes
cb.beginText();
BaseFont bf = BaseFont.createFont("Helvetica", "Cp1252",
false);
int size = FONT_SZ;
java.awt.Font f;
/*if ((f = sch.getTextFont()) != null)
{
size = f.getSize();
}*/
cb.setFontAndSize(bf, size);
drawText(cb, tree, attribs, size, x, y);
cb.endText();
// 3 - add images
drawImage(cb, tree, x, y);
}
// end y
}
// end x
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
document.close();
}
/**
* Generates PDF orgchart on stream.
*
* @param tree Orgchart nodes.
* @param attribs Cells attributes.
* @param xpage Page size on X coordinates.
* @param ypage Page size on Y coordinates.
*
* @return PDF orgchart stream.
*/
public static ByteArrayOutputStream doPrintOrga(
final DefaultMutableTreeNode tree, final List attribs, final int xpage,
final int ypage)
{
// NOTE ! assume all x,y,w,h are set
fXSIZE = (xpage * F1) / F2;
fYSIZE = (ypage * F1) / F2;
maxporgaw = 0;
maxporgah = 0;
computePageSize((Hashtable) tree.getUserObject());
computePageSize(tree);
maxporgah += SPACE2;
maxporgaw += SPACE2;
Hashtable info = (Hashtable) tree.getUserObject();
direction = OrgChartPanel.HORIZONTAL;
if (tree.getChildCount() == 1)
{
DefaultMutableTreeNode child = (DefaultMutableTreeNode) tree.getFirstChild();
Hashtable cinfo = (Hashtable) child.getUserObject();
int xc = ((Integer) cinfo.get(OrgChartPanel.XCOORD)).intValue();
int yc = ((Integer) cinfo.get(OrgChartPanel.YCOORD)).intValue();
int xt = ((Integer) info.get(OrgChartPanel.XCOORD)).intValue();
int yt = ((Integer) info.get(OrgChartPanel.YCOORD)).intValue();
if (yc == yt)
{
direction = OrgChartPanel.VERTICAL;
}
else if (xc != xt)
{
direction = OrgChartPanel.TREE;
}
}
else if (tree.getChildCount() != 0)
{
int x1 = ((Integer) ((Hashtable) ((DefaultMutableTreeNode) tree.getFirstChild())
.getUserObject()).get(OrgChartPanel.XCOORD)).intValue();
int x2 = ((Integer) ((Hashtable) ((DefaultMutableTreeNode) tree.getLastChild())
.getUserObject()).get(OrgChartPanel.XCOORD)).intValue();
if (x1 == x2)
{
int y = ((Integer) info.get(OrgChartPanel.YCOORD)).intValue();
int y1 = ((Integer) ((Hashtable) ((DefaultMutableTreeNode) tree.getFirstChild())
.getUserObject()).get(OrgChartPanel.YCOORD)).intValue();
if (y1 < y)
{
direction = OrgChartPanel.VERTICAL;
}
else
{
direction = OrgChartPanel.TREE;
}
}
//DW/2573/Beginpatch
else
{
int h = ((Integer) info.get(OrgChartPanel.HEIGHT)).intValue();
int y = ((Integer) info.get(OrgChartPanel.YCOORD)).intValue();
int y1 = ((Integer) ((Hashtable) ((DefaultMutableTreeNode) tree.getFirstChild())
.getUserObject()).get(OrgChartPanel.YCOORD)).intValue();
int y2 = ((Integer) ((Hashtable) ((DefaultMutableTreeNode) tree.getLastChild())
.getUserObject()).get(OrgChartPanel.YCOORD)).intValue();
if (y1 != y2)
{
direction = OrgChartPanel.SEMALIKE;
}
if (y1 < (y + h + SPACE3))
{
direction = OrgChartPanel.SEMALIKE;
}
}
//DW/2573/EndPatch
}
_logger.debug("direction : " + direction);
if (fXSIZE == 0)
{
fXSIZE = maxporgaw;
}
else
{
int cwidth = ((Integer) (info.get(OrgChartPanel.WIDTH))).intValue() +
OrgChartPanel.SPACEV;
if (direction == OrgChartPanel.VERTICAL)
{
cwidth += OrgChartPanel.PHOTO_SZ;
}
int nbcaz = fXSIZE / cwidth;
fXSIZE = nbcaz * cwidth;
}
if (fYSIZE == 0)
{
fYSIZE = maxporgah;
}
int nbPageX = ((maxporgaw - SPACE2) / fXSIZE) + 1;
nbPageY = ((maxporgah - SPACE2) / fYSIZE) + 1;
maxporgah = nbPageY * fYSIZE;
Document document = new Document(new Rectangle(fXSIZE, fYSIZE), OrgChartPanel.SPACEV, OrgChartPanel.SPACEV,
OrgChartPanel.SPACEV, OrgChartPanel.SPACEV);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
try
{
//BufferedOutputStream buf = new BufferedOutputStream( new OutputStream());
/*PdfWriter writer =
PdfWriter.getInstance(document, new FileOutputStream(filename));*/
PdfWriter writer = PdfWriter.getInstance(document, buf);
document.open();
PdfContentByte cb = writer.getDirectContent();
for (int x = 1; x <= nbPageX; x++)
{
for (int y = 1; y <= nbPageY; y++)
{
if ((x > 1) || (y > 1))
{
document.newPage();
}
Graphic grx = new Graphic();
grx.setLineWidth(LINE_SZ);
// 1 - draw rectangles
//DW/2573/BeginPatch
if (direction == OrgChartPanel.SEMALIKE)
{
drawRectangleSema(grx, tree, x, y);
}
else
{
drawRectangle(grx, tree, x, y);
}
//DW/2573/EndPatch
grx.stroke();
document.add(grx);
// 2 - add attributes
cb.beginText();
BaseFont bf = BaseFont.createFont("Helvetica", "Cp1252",
false);
int size = FONT_SZ;
java.awt.Font f;
/*if ((f = sch.getTextFont()) != null)
{
size = f.getSize();
}*/
cb.setFontAndSize(bf, size);
drawText(cb, tree, attribs, size, x, y);
cb.endText();
// 3 - add images
drawImage(cb, tree, x, y);
}
// end y
}
// end x
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
document.close();
return buf;
}
//DW/2615/BeginPatch
/**
* Sets default photo file name.
*
* @param value File name.
*/
public static void setDefaultPhoto(String value)
{
defaultPhoto = value;
}
//DW/2615/EndPatch
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -