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

📄 orgchartpanel.java

📁 OPIAM stands for Open Identity and Access Management. This Suite will provide modules for user & rig
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                            cpanel.add(Box.createHorizontalStrut(SSPACE),
                                BorderLayout.EAST);
                        }
                    }

                    JPanel dpanel = createPP(cur);
                    w += (int) dpanel.getPreferredSize().getWidth();
                    h += (int) dpanel.getPreferredSize().getHeight();

                    if (direction == HORIZONTAL)
                    {
                        w += SPACEV;
                    }
                    else
                    {
                        h += SPACEV;
                    }

                    cpanel.add(dpanel, BorderLayout.CENTER);

                    if (direction == HORIZONTAL)
                    {
                        cpanel.add(Box.createHorizontalStrut(SPACEV),
                            BorderLayout.WEST);
                    }
                    else
                    {
                        cpanel.add(Box.createVerticalStrut(SPACEV),
                            BorderLayout.NORTH);
                    }

                    cpanel.setPreferredSize(new Dimension(w, h));
                    cpanel.setMaximumSize(new Dimension(w, h));
                    cpanel.setBackground(backGround);

                    //cpanel.setBorder (new javax.swing.border.LineBorder(Color.red));
                    panel.add(cpanel);

                    if (first)
                    {
                        if (direction == HORIZONTAL)
                        {
                            panel.setMaximumSize(new Dimension(
                                    Integer.MAX_VALUE,
                                    (int) cpanel.getMaximumSize().getHeight()));
                        }
                        else
                        {
                            panel.setMaximumSize(new Dimension(
                                    (int) cpanel.getMaximumSize().getWidth(),
                                    Integer.MAX_VALUE));
                        }

                        first = false;
                    }

                    prevx = x;
                }
            }

            if (direction == HORIZONTAL)
            {
                panel.add(Box.createHorizontalGlue());
            }
            else
            {
                panel.add(Box.createVerticalGlue());
            }

            panel.setBackground(backGround);
            add(panel);
        }
    }

    /**
     * Generates an orgchart in Sema mode.
     */
    private void processSema()
    {
        XJPanel3 pan = new XJPanel3();
        pan.setH(getMaxHeight(new Integer(1)));

        pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS));
        pan.setBackground(backGround);

        JPanel vert1 = createPP(getRoot());
        pan.add(vert1);
        pan.add(new OrgLine1(backGround));

        int nbChild = getNbChildExpanded(getRoot());

        int nbFLignes = nbChild / nbCols;
        int nbReste = nbChild % nbCols;
        pan.setReste(nbReste);

        for (int i = 0; i < nbFLignes; i++)
        {
            XJPanel xpan = new XJPanel();
            xpan.setLayout(new BoxLayout(xpan, BoxLayout.X_AXIS));
            xpan.setBackground(backGround);
            xpan.add(Box.createHorizontalStrut(SPACEV));

            for (int j = 0; j < nbCols; j++)
            {
                JPanel pi = new JPanel();
                pi.setLayout(new BoxLayout(pi, BoxLayout.Y_AXIS));
                pi.setBackground(backGround);

                JPanel verti = createPP((DefaultMutableTreeNode) getRoot()
                                                                     .getChildAt((i * nbCols) +
                            j));
                pi.add(new OrgLine1(backGround));
                pi.add(verti);
                xpan.add(pi);
                xpan.add(Box.createHorizontalStrut(SPACEV));

                if (j == 0)
                {
                    xpan.setV1(verti);
                    xpan.setP1(pi);
                }
                else if (j == (nbCols - 1))
                {
                    xpan.setV2(verti);
                    xpan.setP2(pi);
                }
            }

            pan.add(xpan);
            horizList.add(xpan);
            pan.add(Box.createVerticalStrut(SPACEV));
        }

        if (nbReste > 0)
        {
            XJPanel xpan = new XJPanel();
            xpan.setLayout(new BoxLayout(xpan, BoxLayout.X_AXIS));
            xpan.setBackground(backGround);
            xpan.add(Box.createHorizontalStrut(SPACEV));

            for (int i = 0; i < nbReste; i++)
            {
                JPanel pi = new JPanel();
                pi.setLayout(new BoxLayout(pi, BoxLayout.Y_AXIS));
                pi.setBackground(backGround);

                JPanel verti = createPP((DefaultMutableTreeNode) getRoot()
                                                                     .getChildAt((nbFLignes * nbCols) +
                            i));
                pi.add(new OrgLine1(backGround));
                pi.add(verti);
                xpan.add(pi);
                xpan.add(Box.createHorizontalStrut(SPACEV));

                if (i == 0)
                {
                    xpan.setV1(verti);
                    xpan.setP1(pi);
                }

                if (i == (nbReste - 1))
                {
                    xpan.setV2(verti);
                    xpan.setP2(pi);
                }
            }

            pan.add(xpan);
            horizList.add(xpan);
        }

        add(pan);
    }

    /**
     * Generates org chart.
     */
    public final void doIt()
    {
        _logger.debug("doIt");
        horizList = new ArrayList();
        computeMaxWidth(getRoot());

        int rnlen = ((String) ((Hashtable) getRoot().getUserObject()).get(NAME)).length();
        int rlen = MINW + ((rnlen + 2) * W_FACTOR);

        /*
             if ((rlen > getMaxWidth()) && ((schema == null) || (schema.getOrgchartCellWidth() == 0)))
             {
                setMaxWidth(rlen);
             }
        */
        if (direction == TREE)
        {
            setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
            add(treeCreateVert(getRoot(), true, NONE, null, null));

            if (getNbChildExpanded(getRoot()) > 0)
            {
                treeProcessChildren(getRoot());
            }

            //DW/2573/BeginPatch
        }
        else if (direction == SEMALIKE)
        {
            int nbChild = getNbChildExpanded(getRoot());

            if (nbChild == 0)
            {
                add(createPP(getRoot()));
            }
            else
            {
                processSema();
            }

            //DW/2573/EndPatch
        }
        else
        {
            if (mode == COMPRESSED)
            {
                doComputeCondenseCoords();
                doDessineCondense();
            }
            else
            {
                JPanel vert1 = null;

                int nbChild = getNbChildExpanded(getRoot());

                if (nbChild == 0)
                {
                    vert1 = createVert(getRoot(), false, NONE, null, null);
                }
                else
                {
                    vert1 = createVert(getRoot(), true, NONE, null, null);

                    JPanel horiz1 = processChildren(getRoot());
                    vert1.add(horiz1);
                }

                add(vert1);

                recalcule();
            }
        }

        invalidate();
        repaint();
        validate();
    }

    /**
     * Draws the orgchart.
     *
     * @param g  Graphics on which to draw.
     */
    public final void paint(final Graphics g)
    {
        _logger.debug("paint");
        recalcule();
        super.paint(g);
        doCompute(this);

        //DW/2587/BeginPatch

        /*
                Enumeration enum = getRoot().depthFirstEnumeration();

                while (enum.hasMoreElements()) {
                    DefaultMutableTreeNode curnode =
                        (DefaultMutableTreeNode) enum.nextElement();

                    Hashtable info = (Hashtable) curnode.getUserObject();
                    int x = ((Integer) info.get(XCOORD)).intValue();
                    int y = ((Integer) info.get(YCOORD)).intValue();
                    int w = ((Integer) info.get(WIDTH)).intValue();
                    int h = ((Integer) info.get(HEIGHT)).intValue();

                    g.drawLine(x + w, y + 4, x + w, y + h + 3);
                    g.drawLine(x + w + 1, y + 4, x + w + 1, y + h + 3);
                    g.drawLine(x + w + 2, y + 4, x + w + 2, y + h + 3);
                    g.drawLine(x + w + 3, y + 4, x + w + 3, y + h + 3);
                    g.drawLine(x + 4, y + h, x + w + 3, y + h);
                    g.drawLine(x + 4, y + h + 1, x + w + 3, y + h + 1);
                    g.drawLine(x + 4, y + h + 2, x + w + 3, y + h + 2);
                    g.drawLine(x + 4, y + h + 3, x + w + 3, y + h + 3);
                }
        */

        //DW/2587/EndPatch
    }

    /**
     * Computes cells coordinates.
     *
     * @param c  Top container.
     */
    private void doCompute(final Container c)
    {
        doCompute(c, null);
    }

    /**
     * Computes cells coordinates ans stores them.
     *
     * @param c  Top container.
     * @param l  List where to store coordinates.
     */
    private void doCompute(final Container c, final List l)
    {
        _logger.debug("doCompute");

        Component[] compo = c.getComponents();

        for (int n = 0; n < compo.length; n++)
        {
            if (compo[n] instanceof XJButton)
            {
                Container cur = (Container) compo[n];
                Hashtable info = (Hashtable) (((XJButton) cur).getNode()).getUserObject();
                int w = (int) cur.getBounds().getWidth();
                int h = (int) cur.getBounds().getHeight();
                info.put(WIDTH, new Integer(w));
                info.put(HEIGHT, new Integer(h));

                int cX = 0;
                int cY = 0;

                do
                {
                    cX += cur.getBounds().getX();
                    cY += cur.getBounds().getY();
                    cur = cur.getParent();
                }
                while (cur.getClass().toString().indexOf("OrgChartPanel") == -1);

                info.put(XCOORD, new Integer(cX));
                info.put(YCOORD, new Integer(cY));

                //DW/2572/BeginPatch
                if (l != null)
                {
                    Hashtable resinfo = new Hashtable();
                    resinfo.put(NAME, info.get(NAME));
                    resinfo.put(DN, info.get(DN));
                    resinfo.put(XCOORD, new Integer(cX));
                    resinfo.put(YCOORD, new Integer(cY));
                    resinfo.put(WIDTH, new Integer(w));
                    resinfo.put(HEIGHT, new Integer(h));
                    l.add(resinfo);
                }

                //DW/2572/EndPatch
                if ((cX + w) > maxX)
                {
                    maxX = cX + w;
                }

                if ((cY + h) > maxY)
                {
                    maxY = cY + h;
                }

                Integer alevel = (Integer) info.get(LEVEL);

                if ((crits != null) && (levelAttribs != null) &&
                        (alevel.intValue() > crits.length))
                {
                    alevel = new Integer(levelAttribs.size() - 1);
                }

                List alist = null;

                if (levelAttribs != null)
                {
                    alist = (List) levelAttribs.get(alevel);
                }

                if (alist != null)
                {
                    info.put(ATTRIBS, alist);
                }
            }

            if (compo[n] instanceof Container)
            {
                //DW/2572/BeginPatch
                //doCompute((Container) compo[n]);
                doCompute((Container) compo[n], l);

                //DW/2572/EndPatch
            }
        }
    }

    /**
     * Generates PDF orgchart on file.
     *
     * @param filename  PDF file name.
     */
    public void doPrint(final String filename)
    {
        _logger.debug("doPrint");

        Container cur = (Container) baseCell;

        do
        {
            cur = cur.getParent();
        }
        while (cur.getClass().toString().indexOf("OrgChartPanel") == -1);

        maxX = 0;
        maxY = 0;
        doCompute((Container) cur);

        if ((maxX > MAX_PDF) || (maxY > MAX_PDF))
        {
            throw new RuntimeException(
                "Organigramme trop large pour g閚閞ation PDF");
        }

        //DW/2551

⌨️ 快捷键说明

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