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

📄 trombinoscope.java

📁 OPIAM stands for Open Identity and Access Management. This Suite will provide modules for user & rig
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        attrPan.setBackground(textColor);

        //DW/2588/EndPatch
        //DW/2589/BeginPatch
        //attrPan.setLayout(new BoxLayout(attrPan, BoxLayout.Y_AXIS));
        attrPan.setLayout(new GridLayout(0, 1));

        //DW/2589/EndPatch
        while (iter.hasNext())
        {
            try
            {
                attr = (String) iter.next();

                String value = (String) PropertyUtils.getProperty(entry, attr);

                if (value != null)
                {
                    JLabel label = new JLabel(value);

                    //DW/2589/BeginPatch
                    //label.setHorizontalAlignment(label.CENTER);
                    label.setHorizontalAlignment(align);

                    //DW/2589/EndPatch
                    attrPan.add(label);
                }
                else
                {
                    JLabel label = new JLabel(" ");
                    label.setHorizontalAlignment(JLabel.CENTER);
                    attrPan.add(label);
                }
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
                _logger.error(attr + " : " + ex.getMessage());
            }
        }

        cell.add(attrPan, BorderLayout.SOUTH);

        Hashtable infos = new Hashtable();
        infos.put("CELL", cell);

        try
        {
            infos.put(OrgChartPanel.DN, PropertyUtils.getProperty(entry, "dn"));
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            _logger.error("dn : " + ex.getMessage());
        }

        cells.add(infos);

        return cell;
    }

    /**
     * Method which builds the "Trombinoscope".
     */
    public final void doIt()
    {
        this.setLayout(new GridLayout(0, nbCols, cellSpace, cellSpace));
        this.setBackground(Color.white);

        if (entries == null)
        {
            return;
        }

        int len = entries.size() - startIndex;

        if (len < nbEntries)
        {
            nbEntries = len;
        }

        int nbLines = ((nbEntries + nbCols) - 1) / nbCols;

        for (int curline = 0; curline < nbLines; curline++)
        {
            for (int curcol = 0; curcol < nbCols; curcol++)
            {
                if (((curline * nbCols) + curcol) < nbEntries)
                {
                    add(createCell((curline * nbCols) + curcol + startIndex));
                }
            }
        }
    }

    /**
     * Method which generates the "Trombinoscope".
     *
     * @param imgtype  Type of image to generate.
     *
     * @return a list with : image as first element (java.io.ByteArrayOutputStream)
     *                  as second element, a java.util.Hashtable with for each
     *                  Trombinoscope cell :
     *                  the entry dn (OrgChartPanel.DN), the coordinates
     *                  (OrgChartPanel.XCOORD, OrgChartPanel.YCOORD,
     *                   OrgChartPanel.WIDTH and OrgChartPanel.HEIGHT)
     */
    public final List doPrint(final String imgtype)
    {
        List lresult = new ArrayList();

        int maxX = 0;
        int maxY = 0;

        Iterator iter = cells.iterator();

        while (iter.hasNext())
        {
            Hashtable info = (Hashtable) iter.next();
            JPanel cell = (JPanel) info.get("CELL");
            int x = (int) cell.getBounds().getX();
            int y = (int) cell.getBounds().getY();
            int w = (int) cell.getBounds().getWidth();
            int h = (int) cell.getBounds().getHeight();

            if ((x + w) > maxX)
            {
                maxX = x + w;
            }

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

            info.put(OrgChartPanel.XCOORD, new Integer(x));
            info.put(OrgChartPanel.YCOORD, new Integer(y));
            info.put(OrgChartPanel.WIDTH, new Integer(w));
            info.put(OrgChartPanel.HEIGHT, new Integer(h));
        }

        try
        {
            BufferedImage img = new BufferedImage(maxX, maxY,
                    BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = img.createGraphics();
            this.paint(graphics);

            ByteArrayOutputStream result = new ByteArrayOutputStream();

            if (imgtype.toLowerCase().equals(TYPE_GIF))
            {
                //DW/2597/BeginPatch
                int[][] pixels = TestQuantize.getPixels(img);
                int[] palette = Quantize.quantizeImage(pixels, GIFCOLORS);
                ImageFrame reduced = new ImageFrame();
                reduced.setImage(palette, pixels);

                Image gifimg = reduced.getImage();
                new GifEncoder(gifimg, result).encode();

                /*
                                new GifEncoder(img, result).encode();
                */

                //DW/2597/EndPatch
//DW/2641/BeginPatch
                reduced.dispose();
//DW/2641/EndPatch
            }
            else
            {
                ImageIO.write(img, imgtype.toLowerCase(), result);
            }

            lresult.add(result);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            _logger.error("doPrint : " + ex.getMessage());
        }

        lresult.add(cells);

        return lresult;
    }

    //DW/2591/BeginPatch

    /**
     * Method which generates the "Trombinoscope" as a PDF stream.
     *
     * @return PDF Trombinoscope as a stream.
     *
     */
    public final ByteArrayOutputStream doPrintAsPdf()
    {
        int maxX = 0;
        int maxY = 0;

        Iterator iter = cells.iterator();

        while (iter.hasNext())
        {
            Hashtable info = (Hashtable) iter.next();
            JPanel cell = (JPanel) info.get("CELL");
            int x = (int) cell.getBounds().getX();
            int y = (int) cell.getBounds().getY();
            int w = (int) cell.getBounds().getWidth();
            int h = (int) cell.getBounds().getHeight();

            if ((x + w) > maxX)
            {
                maxX = x + w;
            }

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

            info.put(OrgChartPanel.XCOORD, new Integer(x));
            info.put(OrgChartPanel.YCOORD, new Integer(y));
            info.put(OrgChartPanel.WIDTH, new Integer(w));
            info.put(OrgChartPanel.HEIGHT, new Integer(h));
        }

        Document document = new Document(new Rectangle(maxX, maxY), TEN, TEN,
                TEN, TEN);
        ByteArrayOutputStream buf = new ByteArrayOutputStream();

        try
        {
            PdfWriter writer = PdfWriter.getInstance(document, buf);
            document.open();

            PdfContentByte cb = writer.getDirectContent();

            Graphic grx = new Graphic();
            BufferedImage img = new BufferedImage(maxX, maxY,
                    BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = img.createGraphics();
            this.paint(graphics);

            ByteArrayOutputStream result = new ByteArrayOutputStream();
            ImageIO.write(img, "jpg", result);

            byte[] data = result.toByteArray();
            com.lowagie.text.Image img1 = com.lowagie.text.Image.getInstance(data);
            img1.setAbsolutePosition(0, 0);
            cb.addImage(img1);
        }
        catch (Exception e)
        {
            _logger.error(e.getMessage());
        }

        document.close();

        return buf;
    }
    //DW/2591/EndPatch

//DW/2615/BeginPatch
    /**
     * Sets default photo file name.
     *
     * @param value  File name.
     */
    public void setDefaultPhoto(String value)
    {
//DW/2697/BeginPatch
        try
        {
           value = URLDecoder.decode (value, "UTF-8");
        }
        catch (Exception ex)
        {
           _logger.error ("invalid photo name");
        }
//DW/2697/EndPatch
        defaultPhoto = value;
    }
//DW/2615/EndPatch

}

⌨️ 快捷键说明

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