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

📄 printorga.java

📁 OPIAM stands for Open Identity and Access Management. This Suite will provide modules for user & rig
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

            /* rectangles and vertical lines at top of sons */
            Enumeration enum = node.children();

            int prevx = -1;
            int prevy = -1;

            while (enum.hasMoreElements())
            {
                DefaultMutableTreeNode childnode = (DefaultMutableTreeNode) enum.nextElement();
                Hashtable cinfo = (Hashtable) childnode.getUserObject();
                int cx = ((Integer) cinfo.get(OrgChartPanel.XCOORD)).intValue();
                int cw = ((Integer) cinfo.get(OrgChartPanel.WIDTH)).intValue();
                int cy = ((Integer) cinfo.get(OrgChartPanel.YCOORD)).intValue();
                int ch = ((Integer) cinfo.get(OrgChartPanel.HEIGHT)).intValue();

                g.rectangle(cx - xd, maxporgah - cy - h - OrgChartPanel.SPACEV - yd, cw, ch);

                g.moveTo((cx + (fw / 2)) - xd, (maxporgah - cy + OrgChartPanel.DX) - yd);
                g.lineTo((cx + (lw / 2)) - xd, maxporgah - cy - OrgChartPanel.SPACEV - yd);

                if (cy == prevy)
                {
                    g.moveTo((prevx + (fw / 2)) - xd, (maxporgah - cy + OrgChartPanel.DX) -
                        yd);
                    g.lineTo((cx + (fw / 2)) - xd, (maxporgah - cy + OrgChartPanel.DX) - yd);
                }

                prevx = cx;
                prevy = cy;
            }
        }
    }

    //DW/2573/EndPatch

    /**
     * Draws text in cells.
     *
     * @param cb  PDF content on which to draw.
     * @param node  Current node.
     * @param attribs  Attributes of node to insert.
     * @param defsize  Font default size.
     * @param px  Page number on X coordinates.
     * @param py  Page number on Y coordinates.
     */
    private static void drawText(final PdfContentByte cb,
        final DefaultMutableTreeNode node, final List attribs,
        final int defsize, final int px, final int py)
    {
        Hashtable info = (Hashtable) node.getUserObject();
        int x = ((Integer) info.get(OrgChartPanel.XCOORD)).intValue();
        int y = ((Integer) info.get(OrgChartPanel.YCOORD)).intValue();

        int ipx = x;
        int xd = (px - 1) * fXSIZE;
        int xf = px * fXSIZE;
        int yd = (nbPageY - py) * fYSIZE;

        x = x - xd;
        y = y + yd;

        Iterator iter = attribs.iterator();
        List alist = (List) info.get(OrgChartPanel.ATTRIBS);

        if (alist != null)
        {
            iter = alist.iterator();
        }

        int line = 1;

        int dx;

        if (info.get(OrgChartPanel.PHOTO) != null)
        {
            dx = OrgChartPanel.DX_PHOTO;
        }
        else
        {
            dx = OrgChartPanel.SPACEV;
        }

        cb.setTextMatrix(x + dx, maxporgah - y - SPACE4);

        BaseFont bf = null;

        try
        {
            bf = BaseFont.createFont("Helvetica", "Cp1252", false);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

        int newsize = defsize;
        int linesSpace = 0;

        while (iter.hasNext())
        {
            String attyp = (String) iter.next();

            if (!attyp.equals(OrgChartPanel.PHOTO))
            {
                String atVal = null;

                if (attyp.equals("displayname"))
                {
                    atVal = (String) info.get(OrgChartPanel.NAME);
                }
                else
                {
                    atVal = (String) info.get(attyp);
                }

                if (atVal != null)
                {
                    newsize = defsize;

                    float space = ((Integer) info.get(OrgChartPanel.WIDTH)).intValue() -
                        bf.getWidthPoint(atVal, newsize) - dx;

                    while (space < 0)
                    {
                        newsize--;
                        cb.setFontAndSize(bf, newsize);
                        space = ((Integer) info.get(OrgChartPanel.WIDTH)).intValue() -
                            bf.getWidthPoint(atVal, newsize) - dx;
                    }

                    float availspace = ((Integer) info.get(OrgChartPanel.WIDTH)).intValue() -
                        bf.getWidthPoint(atVal, newsize) - dx;
                    float coef = 1.1f;
                    cb.setTextMatrix(x + dx + (availspace / 2),
                        maxporgah - y - OrgChartPanel.SPACEV - ((int) (newsize * coef)) -
                        linesSpace);
                    linesSpace += (int) (newsize * coef);
                    line++;
                    cb.showText(atVal);
                }
            }
        }

        if (newsize != defsize)
        {
            cb.setFontAndSize(bf, defsize);
        }

        Enumeration enum = node.children();

        while (enum.hasMoreElements())
        {
            DefaultMutableTreeNode childnode = (DefaultMutableTreeNode) enum.nextElement();
            drawText(cb, childnode, attribs, defsize, px, py);
        }
    }

    /**
     * Draws photos in cells.
     *
     * @param cb  PDF Content on which to draw.
     * @param node  Current node.
     * @param px  Page number on X coordinates.
     * @param py  Page number on Y coordinates.
     *
     * @throws Exception  In case the photo is not in a recognized format.
     */
    private static void drawImage(final PdfContentByte cb,
        final DefaultMutableTreeNode node, final int px, final int py)
        throws Exception
    {
        Hashtable info = (Hashtable) node.getUserObject();
        int x = ((Integer) info.get(OrgChartPanel.XCOORD)).intValue();
        int y = ((Integer) info.get(OrgChartPanel.YCOORD)).intValue();

        int ipx = x;
        int xd = (px - 1) * fXSIZE;
        int xf = px * fXSIZE;

        int yd = (nbPageY - py) * fYSIZE;

        if ((xd <= ipx) && (ipx <= xf))
        {
            x = x - xd;
            y = y + yd;

            byte[] photo = (byte[]) info.get(OrgChartPanel.PHOTO);

//DW/2615/BeginPatch
            Image img1 = null;


            if (photo != null)
            {
                img1 = Image.getInstance(photo);
            }
//DW/2643/BeginPatch
            else if (defaultPhoto != null)
//DW/2643/EndPatch
            {
                img1 = Image.getInstance(defaultPhoto);
            }

            if (img1 != null)
            {
//DW/2615/EndPatch
                float coef1 = (float) 100.0;
                float coef2 = (float) 100.0;
                int h = ((Integer) info.get(OrgChartPanel.HEIGHT)).intValue() -
                    SPACE1;

                if (img1.top() > h)
                {
                    coef1 = (int) ((h * 100) / img1.top());
                }

                if (img1.right() > OrgChartPanel.PHOTO_SZ)
                {
                    coef2 = (int) (OrgChartPanel.PHOTO_SZ * 100 / img1.right());
                }

                float coef = ((coef1 < coef2) ? coef1 : coef2);
                img1.setAbsolutePosition(x + OrgChartPanel.DX,
                    maxporgah - y - SPACE1 - ((img1.top() * coef) / 100));
                img1.scalePercent(coef, coef);

                try
                {
                    cb.addImage(img1);
                }
                catch (Exception e)
                {
                    System.out.println(e.getMessage());
                }
            }
        }

        // end test ipx
        Enumeration enum = node.children();

        while (enum.hasMoreElements())
        {
            DefaultMutableTreeNode childnode = (DefaultMutableTreeNode) enum.nextElement();
            drawImage(cb, childnode, px, py);
        }
    }

    /**
     * Generates PDF orgchart on file.
     *
     * @param filename  Output file name.
     * @param tree  Orgchart nodes.
     * @param attribs  Cells attributes.
     * @param xpage  Page size on X coordinates.
     * @param ypage  Page size on Y coordinates.
     */
    public static void doPrintOrga(final String filename,
        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
                {

⌨️ 快捷键说明

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