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

📄 trombinoscope.java

📁 OPIAM stands for Open Identity and Access Management. This Suite will provide modules for user & rig
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.service.services.trombinoscope;

import Acme.JPM.Encoders.GifEncoder;

import opiam.admin.faare.service.services.views.orgchart.OrgChartPanel;

//DW/2591/BeginPatch
import com.lowagie.text.Document;
import com.lowagie.text.Graphic;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

//DW/2591/EndPatch
import org.apache.commons.beanutils.PropertyUtils;

import org.apache.log4j.Logger;

//DW/2597/BeginPatch
import quantize.ImageFrame;
import quantize.Quantize;
import quantize.TestQuantize;

//DW/2597/EndPatch
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.image.BufferedImage;

import java.io.ByteArrayOutputStream;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

//DW/2697/BeginPatch
import java.net.URLDecoder;
//DW/2697/EndPatch

import javax.imageio.ImageIO;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;


/**
 * Class which allows to generate a "Trombinoscope".
 */
public class Trombinoscope extends JPanel
{
    /** Instance of logger. */
    private static Logger _logger = Logger.getLogger(Trombinoscope.class);

    /** Type of image to generate : GIF image. */
    public static final String TYPE_GIF = "gif";

    /** Photo background. */
    private static Color photoColor = Color.lightGray;

    /** Text background. */
    private static Color textColor = Color.lightGray;

    /** Text alignment. */
    private static int align = JLabel.LEFT;

    /** Ten value. */
    private static final int TEN = 10;

    /** number of colors in a GIF file. */
    private static final int GIFCOLORS = 256;

    /** Start index in the entries list. */
    private int startIndex;

    /** Number of cells per line. */
    private int nbCols;

    /** Number of entries to take into account in the list. */
    private int nbEntries;

    /** List of entries. */
    private List entries;

    /** List of attributes to use. */
    private List attribs;

    /** Name of the property which contains the photo. */
    private String photoAttr = "photo";

    /** The photo is a collection or not. */
    private boolean photoCollection = true;

    /** List of cells. */
    private List cells = new ArrayList();

    /** Photo maximum size. */
    private final int photoSize = 100;

    /** Space between cells. */
    private final int cellSpace = 20;

//DW/2615/BeginPatch
    /** default photo file name. */
    private String defaultPhoto = null;
//DW/2615/EndPatch

    /**
     * Constructs a Trombinoscope object.
     *
     * @param si  Start index in the list of entries.
     * @param nc  Number of columns.
     * @param ne  Number of entries to take into account.
     * @param e  List of entries.
     * @param a  List of attributes to take into account.
     */
    public Trombinoscope(final int si, final int nc, final int ne,
        final List e, final List a)
    {
        startIndex = si;
        nbCols = nc;
        nbEntries = ne;
        entries = e;
        attribs = a;
    }

    /**
     * Method which sets the name of the property containing the photo.
     * Default : "photo".
     *
     * @param value  Name of the property containing the photo.
     *
     */
    public final void setPhotoAttr(final String value)
    {
        photoAttr = value;
    }

    /**
     * Method which sets the photo background color.
     * Default : lightGray.
     *
     * @param value  Color.
     *
     */
    public final void setPhotoColor(final Color value)
    {
        if (value != null)
        {
            photoColor = value;
        }
    }

    /**
     * Method which sets the text background color.
     * Default : lightGray.
     *
     * @param value  Color.
     *
     */
    public final void setTextColor(final Color value)
    {
        if (value != null)
        {
            textColor = value;
        }
    }

    /**
     * Method which sets the text alignment.
     * Default : left.
     *
     * @param talign  Alignement value.
     *
     */
    public final void setTextAlignment(final String talign)
    {
        if (talign != null)
        {
            if (talign.toUpperCase().equals("CENTER"))
            {
                align = JLabel.CENTER;
            }
            else if (talign.toUpperCase().equals("RIGHT"))
            {
                align = JLabel.RIGHT;
            }
        }
    }

    /**
     * Method which build a cell of the "Trombinoscope".
     *
     * @param index  Index of entry in list.
     *
     * @return Trombinoscope cell.
     */
    private JPanel createCell(final int index)
    {
        JPanel cell = new JPanel();
        cell.setLayout(new BorderLayout());

        //DW/2588/BeginPatch
        //cell.setBackground(Color.lightGray);
        cell.setBackground(photoColor);

        //DW/2588/EndPatch
        Object entry = entries.get(index);

        // photo
        try
        {
            byte[] photo = null;
            Object aPhoto = PropertyUtils.getProperty(entry, photoAttr);
//DW/2611/BeginPatch
            photoCollection = ((aPhoto != null) && (aPhoto instanceof Collection));
//DW/2611/EndPatch

            if (photoCollection && (aPhoto != null))
            {
                Iterator iter = ((Collection) aPhoto).iterator();

                if ((iter != null) && (iter.hasNext()))
                {
                    photo = (byte[]) iter.next();
                }
            }
            else if (aPhoto != null)
            {
                photo = (byte[]) aPhoto;
            }

//DW/2615/BeginPatch
            ImageIcon image = null;
//DW/2615/EndPatch
            if (photo != null)
            {
//DW/2615/BeginPatch
                //ImageIcon image = new ImageIcon(photo);
                image = new ImageIcon(photo);
            }
            else if (defaultPhoto != null)
            {
                image = new ImageIcon(defaultPhoto);
            }

            if (image != null)
            {
//DW/2615/EndPatch
                if ((image.getIconHeight() > photoSize) ||
                        (image.getIconWidth() > photoSize))
                {
                    Image im = image.getImage();
                    Image newIm = im.getScaledInstance(-1, photoSize,
                            Image.SCALE_FAST);
                    image = new ImageIcon(newIm);
                }

                if (image != null)
                {
                    JLabel photoLab = new JLabel(image);
                    cell.add(photoLab, BorderLayout.CENTER);
                }
            }

        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }

        // attributes
        Iterator iter = attribs.iterator();
        String attr = "";
        JPanel attrPan = new JPanel();

        //DW/2588/BeginPatch

⌨️ 快捷键说明

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