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

📄 orgchartpanel.java

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

        return ret;
    }

    /**
     * Computes cells coordinates in compressed mode.
     */
    private void doComputeCondenseCoords()
    {
        _logger.debug("doComputeCondenseCoords");

        DefaultMutableTreeNode cur;
        Hashtable info;
        int curx = 0;
        int maxLevel = getRoot().getDepth();

        cur = getRoot();
        info = (Hashtable) cur.getUserObject();
        info.put(X, new Float((float) curx));

        int l0 = cur.getLevel();
        maxLevel += l0;

        // init
        for (int l = l0 + 1; l <= maxLevel; l++)
        {
            curx = 0;

            Enumeration enum = getRoot().depthFirstEnumeration();

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

                if (cur.getLevel() == l)
                {
                    info = (Hashtable) cur.getUserObject();
                    info.put(X, new Float((float) curx));

                    if (direction == HORIZONTAL)
                    {
                        curx += (float) (getMaxWidth() + SPACEV);
                    }
                    else
                    {
                        curx += (float) (getCompMaxHeight(info) + SPACEV);
                    }
                }
            }
        }

        // computing
        for (int l = maxLevel - 1; l >= l0; l--)
        {
            Enumeration enum = getRoot().depthFirstEnumeration();

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

                if ((cur.getLevel() == l) && (getNbChildExpanded(cur) > 0))
                {
                    DefaultMutableTreeNode fc = (DefaultMutableTreeNode) cur.getFirstChild();

                    if (getNbChildExpanded(fc) == 0)
                    {
                        DefaultMutableTreeNode achild = fc.getNextSibling();
                        boolean found = false;

                        while (!found && (achild != null))
                        {
                            found = (getNbChildExpanded(achild) > 0);

                            if (!found)
                            {
                                achild = achild.getNextSibling();
                            }
                        }

                        if (found)
                        {
                            int cidx = cur.getIndex(achild);
                            Hashtable ichild = (Hashtable) achild.getUserObject();
                            float xchild = ((Float) ichild.get(X)).floatValue();

                            for (int ci = 0; ci < cidx; ci++)
                            {
                                DefaultMutableTreeNode childi = (DefaultMutableTreeNode) cur.getChildAt(ci);
                                Hashtable ii = (Hashtable) childi.getUserObject();
                                float dx;

                                if (direction == HORIZONTAL)
                                {
                                    dx = (float) (getMaxWidth() + SPACEV);
                                }
                                else
                                {
                                    dx = (float) (getCompMaxHeight(ii) + SPACEV);
                                }

                                ii.put(X, new Float(xchild -
                                        ((cidx - ci) * dx)));
                            }
                        }
                        else
                        {
                            achild = getNextNodeWithSameLevel((DefaultMutableTreeNode) cur.getLastChild());

                            if (achild != null)
                            {
                                Hashtable ichild = (Hashtable) achild.getUserObject();
                                float xchild = ((Float) ichild.get(X)).floatValue();
                                int cn = cur.getChildCount();

                                for (int ci = 0; ci < cn; ci++)
                                {
                                    DefaultMutableTreeNode childi = (DefaultMutableTreeNode) cur.getChildAt(ci);
                                    Hashtable ii = (Hashtable) childi.getUserObject();
                                    float dx;

                                    if (direction == HORIZONTAL)
                                    {
                                        dx = (float) (getMaxWidth() + SPACEV);
                                    }
                                    else
                                    {
                                        dx = (float) (getCompMaxHeight(ii) +
                                            SPACEV);
                                    }

                                    ii.put(X,
                                        new Float(xchild - ((cn - ci) * dx)));
                                }
                            }
                        }
                    }
                }
            }

            enum = getRoot().depthFirstEnumeration();

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

                if (cur.getLevel() == l)
                {
                    if (getNbChildExpanded(cur) > 0)
                    {
                        DefaultMutableTreeNode fc = (DefaultMutableTreeNode) cur.getFirstChild();
                        DefaultMutableTreeNode lc = (DefaultMutableTreeNode) cur.getLastChild();
                        Hashtable fi = (Hashtable) fc.getUserObject();
                        Hashtable li = (Hashtable) lc.getUserObject();
                        Hashtable ci = (Hashtable) cur.getUserObject();
                        float fx = ((Float) fi.get(X)).floatValue();
                        float lx = ((Float) li.get(X)).floatValue();
                        float cx = ((Float) ci.get(X)).floatValue();
                        float delta = ((fx + lx) / 2) - cx;

                        if (direction == VERTICAL)
                        {
                            delta += (((float) (getCompMaxHeight(fi) -
                            getCompMaxHeight(ci))) / (float) 2);
                        }

                        if (delta <= (float) 0)
                        {
                            delta = -delta;

                            int nbc = cur.getChildCount();
                            boolean isChildLevel2 = false;

                            for (int childi = 0;
                                    (childi < nbc) && !isChildLevel2;
                                    childi++)
                            {
                                isChildLevel2 = getNbChildExpanded((DefaultMutableTreeNode) cur.getChildAt(
                                            childi)) > 0;
                            }

                            boolean collision = false;

                            if (isChildLevel2)
                            {
                                collision = true;
                            }
                            else
                            {
                                DefaultMutableTreeNode next = getNextNodeWithSameLevel(lc);

                                if (next != null)
                                {
                                    Hashtable nexti = (Hashtable) next.getUserObject();
                                    float nextx = ((Float) nexti.get(X)).floatValue();
                                    float dx;

                                    if (direction == HORIZONTAL)
                                    {
                                        dx = (float) (getMaxWidth() + SPACEV);
                                    }
                                    else
                                    {
                                        dx = (float) (getCompMaxHeight(li) +
                                            SPACEV);
                                    }

                                    if ((lx + delta + dx) > nextx)
                                    {
                                        collision = true;
                                    }
                                }
                            }

                            Enumeration enum1 = getRoot().depthFirstEnumeration();

                            while (enum1.hasMoreElements() && collision)
                            {
                                DefaultMutableTreeNode cur1 = (DefaultMutableTreeNode) enum1.nextElement();

                                //!!
                                if ((cur1.getLevel() > (l + 1)))
                                {
                                    DefaultMutableTreeNode cur2 = (DefaultMutableTreeNode) (cur1.getPath()[l +
                                        1]);
                                    Hashtable i1 = (Hashtable) cur1.getUserObject();
                                    Hashtable i2 = (Hashtable) cur2.getUserObject();
                                    float x1 = ((Float) i1.get(X)).floatValue();
                                    float x2 = ((Float) i2.get(X)).floatValue();

                                    if (x2 >= fx)
                                    {
                                        i1.put(X, new Float(x1 + delta));
                                    }
                                }
                            }

                            enum1 = getRoot().depthFirstEnumeration();

                            while (enum1.hasMoreElements())
                            {
                                DefaultMutableTreeNode cur1 = (DefaultMutableTreeNode) enum1.nextElement();

                                if ((cur1.getLevel() == (l + 1)) &&
                                        (collision || cur.isNodeChild(cur1)))
                                {
                                    Hashtable i1 = (Hashtable) cur1.getUserObject();
                                    float x1 = ((Float) i1.get(X)).floatValue();

                                    if (x1 >= fx)
                                    {
                                        i1.put(X, new Float(x1 + delta));
                                    }
                                }
                            }
                        }
                        else
                        {
                            Enumeration enum1 = getRoot().depthFirstEnumeration();

                            while (enum1.hasMoreElements())
                            {
                                DefaultMutableTreeNode cur1 = (DefaultMutableTreeNode) enum1.nextElement();

                                if (cur1.getLevel() == l)
                                {
                                    Hashtable i1 = (Hashtable) cur1.getUserObject();
                                    float x1 = ((Float) i1.get(X)).floatValue();

                                    if (x1 >= cx)
                                    {
                                        i1.put(X, new Float(x1 + delta));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    /**
     * Generates orgchart in compressed mode.
     */
    private void doDessineCondense()
    {
        _logger.debug("doDessineCondense");

        int maxLevel = getRoot().getDepth();
        int l0 = getRoot().getLevel();
        maxLevel += l0;

        if (direction == HORIZONTAL)
        {
            setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        }
        else
        {
            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
        }

        for (int l = l0; l <= maxLevel; l++)
        {
            JPanel panel = new JPanel();

            if (direction == HORIZONTAL)
            {
                panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
            }
            else
            {
                panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
            }

            Enumeration enum = getRoot().depthFirstEnumeration();
            boolean first = true;
            float x = (float) 0;
            float prevx = (float) 0;

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

                if (cur.getLevel() == l)
                {
                    Hashtable info = (Hashtable) cur.getUserObject();
                    int delta;

                    if (direction == HORIZONTAL)
                    {
                        delta = getMaxWidth() + SPACEV;
                    }
                    else
                    {
                        delta = getCompMaxHeight(info) + SPACEV;
                    }

                    x = ((Float) info.get(X)).floatValue();

                    if (first)
                    {
                        if (x > (float) 0)
                        {
                            if (direction == HORIZONTAL)
                            {
                                panel.add(Box.createHorizontalStrut((int) x));
                            }
                            else
                            {
                                panel.add(Box.createVerticalStrut((int) x));
                            }
                        }
                    }
                    else if ((x - prevx) > (float) delta)
                    {
                        int size = (int) (x - prevx - delta);

                        if (cur.getParent().getChildAt(0) == cur)
                        {
                            if (direction == HORIZONTAL)
                            {
                                panel.add(Box.createHorizontalStrut(size));
                            }
                            else
                            {
                                panel.add(Box.createVerticalStrut(size));
                            }
                        }
                        else
                        {
                            XJPanel1 xjp1 = new XJPanel1(size);
                            xjp1.setBackground(backGround);
                            panel.add(xjp1);
                        }
                    }

                    JPanel cpanel = new XJPanel2(cur);
                    cpanel.setLayout(new BorderLayout());

                    int w = 0;
                    int h = 0;

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

                    if (getRoot() != cur)
                    {
                        if (direction == HORIZONTAL)
                        {
                            cpanel.add(new OrgLine(NONE, backGround),
                                BorderLayout.NORTH);
                            h += SSPACE;
                        }
                        else
                        {
                            cpanel.add(new OrgLine(NONE, backGround),
                                BorderLayout.WEST);
                            w += SSPACE;
                        }
                    }

                    if (getNbChildExpanded(cur) > 0)
                    {
                        if (direction == HORIZONTAL)
                        {
                            cpanel.add(new OrgLine(NONE, backGround),
                                BorderLayout.SOUTH);
                        }
                        else
                        {
                            cpanel.add(new OrgLine(NONE, backGround),
                                BorderLayout.EAST);
                        }
                    }
                    else
                    {
                        if (direction == HORIZONTAL)
                        {
                            cpanel.add(Box.createVerticalStrut(SSPACE),
                                BorderLayout.SOUTH);
                        }
                        else
                        {

⌨️ 快捷键说明

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