KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > slideshow > gui > ImageRenderer


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.slideshow.gui;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Image JavaDoc;
25 import java.util.HashMap JavaDoc;
26
27 import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.JList JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.ListCellRenderer JavaDoc;
31
32 public class ImageRenderer implements ListCellRenderer JavaDoc
33 {
34     private HashMap JavaDoc scaledImages = new HashMap JavaDoc();
35     
36     public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value,
37         int index, boolean isSelected, boolean cellHasFocus)
38     {
39                 
40         JPanel JavaDoc container = (JPanel JavaDoc)scaledImages.get(value);
41         if(container == null)
42         {
43             Image JavaDoc img = (Image JavaDoc)value;
44             ImageComponent component = new ImageComponent();
45             Image JavaDoc scaled = img.getScaledInstance(128, -1, Image.SCALE_FAST);
46             component.setImage(scaled, false);
47             container = new JPanel JavaDoc(new BorderLayout JavaDoc());
48             container.add(component, BorderLayout.CENTER);
49             scaledImages.put(value, container);
50         }
51         
52         Color JavaDoc color = Color.LIGHT_GRAY;
53         if (isSelected)
54             color = Color.ORANGE;
55
56         container.setBorder(BorderFactory.createLineBorder(color, 2));
57         return container;
58     }
59 }
60
Popular Tags