01: /*
02: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
03: * for visualizing and manipulating spatial features with geometry and attributes.
04: *
05: * Copyright (C) 2003 Vivid Solutions
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: *
21: * For more information, contact:
22: *
23: * Vivid Solutions
24: * Suite #1A
25: * 2328 Government Street
26: * Victoria BC V8T 5G5
27: * Canada
28: *
29: * (250)385-6040
30: * www.vividsolutions.com
31: */
32: package com.vividsolutions.jump.workbench.ui.style;
33:
34: import java.awt.BorderLayout;
35: import java.awt.Component;
36: import java.util.Vector;
37:
38: import javax.swing.DefaultListCellRenderer;
39: import javax.swing.JList;
40: import javax.swing.JScrollPane;
41: import javax.swing.ListSelectionModel;
42: import javax.swing.event.ListSelectionEvent;
43: import javax.swing.event.ListSelectionListener;
44:
45: import com.vividsolutions.jump.workbench.ui.renderer.style.BasicStyle;
46: import com.vividsolutions.jump.workbench.ui.renderer.style.BasicStyleListCellRenderer;
47:
48: public class ListPalettePanel extends AbstractPalettePanel {
49:
50: private BasicStyleListCellRenderer basicStyleListCellRenderer = new BasicStyleListCellRenderer();
51:
52: /**
53: * @param verticalScrollBarPolicy unfortunately needs to be set because
54: * there seems to be a JScrollPane bug with VERTICAL_SCROLLBAR_AS_NEEDED:
55: * an ugly strip of whitespace is left where the scrollbar would be (J2SE 1.4.1)
56: */
57: public ListPalettePanel(int verticalScrollBarPolicy) {
58: //I've submitted a bug report to Sun (internal review ID 185722). [Jon Aquino]
59: JScrollPane scrollPane = new JScrollPane();
60: scrollPane.setVerticalScrollBarPolicy(verticalScrollBarPolicy);
61: final JList list = new JList(new Vector(basicStyles()));
62: setLayout(new BorderLayout());
63: add(scrollPane, BorderLayout.CENTER);
64: scrollPane.getViewport().add(list);
65: list.setCellRenderer(basicStyleListCellRenderer);
66: list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
67: list.getSelectionModel().addListSelectionListener(
68: new ListSelectionListener() {
69: public void valueChanged(ListSelectionEvent e) {
70: fireBasicStyleChosen((BasicStyle) list
71: .getSelectedValue());
72: }
73: });
74: }
75:
76: public void setAlpha(int alpha) {
77: basicStyleListCellRenderer.setAlpha(alpha);
78: repaint();
79: }
80:
81: public DefaultListCellRenderer testRenderer = new DefaultListCellRenderer() {
82: public Component getListCellRendererComponent(JList list,
83: Object value, int index, boolean isSelected,
84: boolean cellHasFocus) {
85: return super .getListCellRendererComponent(list, "test",
86: index, isSelected, cellHasFocus);
87: }
88: };
89:
90: }
|