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

📄 orgchartpanel.java

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

            if (hasChild)
            {
                JPanel pchild = processChildren(childn);
                vertcn.add(pchild);
            }

            horizc.add(vertcn);

            horizList.add(horizc);

            return horizc;
        }
    }

    /**
     * Computes max width of orgchart cells.
     *
     * @param node Root node.
     */
    public final void computeMaxWidth(final DefaultMutableTreeNode node)
    {
        _logger.debug("computeMaxWidth");

        Enumeration enum = node.children();

        // DW/2549 : case there is no child node
        if (!enum.hasMoreElements()) // only one node
        {
            Hashtable info = (Hashtable) node.getUserObject();
            computeMaxWidthElt(info);
        }

        while (enum.hasMoreElements())
        {
            DefaultMutableTreeNode childnode = (DefaultMutableTreeNode) enum.nextElement();
            Hashtable info = (Hashtable) childnode.getUserObject();

            computeMaxWidthElt(info);

            computeMaxWidth(childnode);
        }

        setMaxWidth(MINW + longest);
    }

    /**
     * Computes max width of one cell.
     *
     * @param info  Node hashtable.
     */
    private void computeMaxWidthElt(final Hashtable info)
    {
        String value2 = (String) info.get(NAME);

        if (value2.length() > nbcar)
        {
            nbcar = value2.length();
            longest = (int) getFontMetrics(textFont)
                                .getStringBounds(value2, getGraphics())
                                .getWidth();
        }

        Iterator iter = attribs.iterator();

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

            if (!attyp.equals(PHOTO))
            {
                String atVal = (String) info.get(attyp);

                if ((atVal != null) && (atVal.length() > nbcar))
                {
                    nbcar = atVal.length();
                    longest = (int) getFontMetrics(titleFont)
                                        .getStringBounds(atVal, getGraphics())
                                        .getWidth();
                }
            }
        }

        if (levelAttribs != null)
        {
            Enumeration allattrs = levelAttribs.elements();

            while (allattrs.hasMoreElements())
            {
                iter = ((List) allattrs.nextElement()).iterator();

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

                    if (!attyp.equals(PHOTO))
                    {
                        String atVal = (String) info.get(attyp);

                        if ((atVal != null) && (atVal.length() > nbcar))
                        {
                            nbcar = atVal.length();
                            longest = (int) getFontMetrics(titleFont)
                                                .getStringBounds(atVal,
                                    getGraphics()).getWidth();
                        }
                    }
                }
            }
        }
    }

    /**
     * Gets maximum width of cells.
     *
     * @return The maximum width.
     */
    private int getMaxWidth()
    {
        return maxWidth;
    }

    /**
     * Sets maximum width of cells.
     *
     * @param w  Maximum width.
     */
    private void setMaxWidth(final int w)
    {
        maxWidth = w;
    }

    /**
     * Gets maximum height of cells for a given level.
     *
     * @param level  Level.
     *
     * @return The maximum height.
     */
    private int getMaxHeight(final Integer level)
    {
        _logger.debug("getMaxHeight");

        List alist = null;

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

        if (alist == null)
        {
            alist = attribs;
        }

        Enumeration enum = getRoot().depthFirstEnumeration();
        maxHeight = 0;

        while (enum.hasMoreElements())
        {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) enum.nextElement();
            boolean isExp = true;
            DefaultMutableTreeNode curnode = (DefaultMutableTreeNode) node.getParent();

            while ((curnode != null) && !isRoot(curnode))
            {
                curnode = (DefaultMutableTreeNode) curnode.getParent();
            }

            boolean isPhoto = false;
            int fh = 0;

            if (isExp)
            {
                Hashtable info = (Hashtable) node.getUserObject();
                Integer alevel = (Integer) info.get(LEVEL);

                if ((alevel == null) ||
                        (alevel.intValue() == level.intValue()))
                {
                    Iterator iter = alist.iterator();
                    int nbatt = 0;

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

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

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

                            if (atVal != null)
                            {
                                int ah = (int) getFontMetrics(titleFont)
                                                   .getStringBounds(atVal,
                                        getGraphics()).getHeight() +
                                    getFontMetrics(titleFont).getDescent();
                                fh += ah;
                            }
                        }

                        if (!isPhoto && (info.get(PHOTO) != null))
                        {
                            isPhoto = true;
                        }
                    }

                    if (isPhoto && (fh < PHOTO_SZ))
                    {
                        fh = PHOTO_SZ;
                    }

                    if (fh > maxHeight)
                    {
                        maxHeight = fh;
                    }
                }
            }
        }

        return maxHeight;
    }

    /**
     * Sets default maximum height.
     *
     * @param h  Maximum height.
     */
    private void setMaxHeight(final int h)
    {
        maxHeight = h;
    }

    /**
     * Creates a panel surrounding a cell and its children (tree mode).
     *
     * @param node      The top cell of the panel
     * @param hasChild  Children presence flag
     * @param type      Kind of required OrgLine
     * @param horiza    Should be the panel containing the cell and brothers
     *                   for the first child, else null.
     * @param horizb    Should be the panel containing the cell and brothers
     *                   for the last child, else null.
     *
     * @return The created panel.
     */
    private JPanel treeCreateVert(final DefaultMutableTreeNode node,
        final boolean hasChild, final short type, final XJPanel horiza,
        final XJPanel horizb)
    {
        _logger.debug("treeCreateVert");

        FlowLayout fl = new FlowLayout();
        fl.setVgap(0);
        fl.setHgap(0);
        fl.setAlignment(FlowLayout.LEFT);

        JPanel cur = new JPanel(fl);

        int level = node.getLevel();
        int hlevel = level;
        Hashtable info = (Hashtable) node.getUserObject();

        if ((crits != null) && (levelAttribs != null) &&
                (hlevel > crits.length))
        {
            hlevel = levelAttribs.size();
        }

        level -= getRoot().getLevel();

        JPanel v1 = new JPanel();
        v1.setLayout(new BorderLayout());

        JPanel pp11 = createPP(node);
        v1.add(pp11, BorderLayout.NORTH);

        if (getNbChildExpanded(node) != 0)
        {
            v1.add(new OrgLine1(backGround), BorderLayout.WEST);
        }
        else
        {
            v1.add(Box.createVerticalStrut(SPACEV), BorderLayout.SOUTH);
        }

        if (level > 0)
        {
            int height = getMaxHeight(new Integer(hlevel));
            boolean last = (((DefaultMutableTreeNode) node.getParent()).getLastChild() == node) ?
                true : false;
            JPanel v0 = new JPanel();
            v0.setLayout(new BorderLayout());
            v0.add(new OrgLine1(HORIZONTAL_LEFT, backGround, height, last),
                BorderLayout.NORTH);

            int lh = height;

            if (getNbChildExpanded(node) != 0)
            {
                if (!last)
                {
                    v0.add(new OrgLine1(VERTICAL, backGround, SPACEV),
                        BorderLayout.CENTER);
                }
                else
                {
                    v0.add(Box.createVerticalStrut(SPACEV), BorderLayout.CENTER);
                }

                lh += SPACEV;
            }
            else
            {
                if (!last)
                {
                    v0.add(new OrgLine1(VERTICAL, backGround, SPACEV),
                        BorderLayout.SOUTH);
                }
                else
                {
                    v0.add(Box.createVerticalStrut(SPACEV), BorderLayout.SOUTH);
                }

                lh += SPACEV;
            }

            TreeNode[] parents = node.getPath();

            level += getRoot().getLevel();

            int i0 = 2 + getRoot().getLevel();

            for (int i = i0; i <= level; i++)
            {
                if (((DefaultMutableTreeNode) parents[i - 2]).getLastChild() != parents[i -
                        1])
                {
                    cur.add(new OrgLine1(VERTICAL, backGround, lh));
                }
                else
                {
                    cur.add(Box.createHorizontalStrut(SPACEH));
                }
            }

            v0.setBackground(backGround);
            cur.add(v0);
        }

        cur.add(v1);
        cur.setBackground(backGround);
        cur.setMaximumSize(new Dimension(
                (int) cur.getMaximumSize().getWidth(),
                (int) v1.getPreferredSize().getHeight()));
        v1.setBackground(backGround);

        return cur;
    }

    /**
     * Creates a panel containing all children of a cell (tree mode).
     *
     * @param node Father node
     *
     */
    private void treeProcessChildren(final DefaultMutableTreeNode node)
    {
        _logger.debug("treeProcessChildren");

        int nbChildren = getNbChildExpanded(node);

        for (int i = 0; i < nbChildren; i++)
        {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i);
            add(treeCreateVert(child, true, NONE, null, null));
            treeProcessChildren(child);
        }
    }

    /**
     * Gets max height in compressed mode.
     *
     * @param info  Node hashtable.
     *
     * @return The max height.
     */
    private int getCompMaxHeight(final Hashtable info)
    {
        _logger.debug("getCompMaxHeight");

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

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

        return getMaxHeight(hlevel);
    }

    /**
     * Gets next node with same level, as the name says it !
     *
     * @param node  Node
     *
     * @return The next node.
     */
    private DefaultMutableTreeNode getNextNodeWithSameLevel(
        final DefaultMutableTreeNode node)
    {
        _logger.debug("getNextNodeWithSameLevel");

        DefaultMutableTreeNode ret = node.getNextNode();

        while ((ret != null) && (node.getLevel() != ret.getLevel()))
        {
            ret = ret.getNextNode();
        }

⌨️ 快捷键说明

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