001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032: package com.vividsolutions.jump.workbench.ui.renderer.style;
033:
034: import java.awt.Component;
035: import java.awt.Dimension;
036: import java.awt.Font;
037: import java.awt.GridBagConstraints;
038: import java.awt.GridBagLayout;
039: import java.awt.Insets;
040:
041: import javax.swing.DefaultListCellRenderer;
042: import javax.swing.JLabel;
043: import javax.swing.JList;
044: import javax.swing.JPanel;
045: import javax.swing.ListCellRenderer;
046:
047: import com.vividsolutions.jump.workbench.ui.ColorPanel;
048: import com.vividsolutions.jump.workbench.ui.GUIUtil;
049:
050: public class BasicStyleListCellRenderer implements ListCellRenderer {
051:
052: protected ColorPanel colorPanel = new ColorPanel();
053: private JPanel panel = new JPanel();
054: protected DefaultListCellRenderer defaultListCellRenderer = new DefaultListCellRenderer() {
055: public Component getListCellRendererComponent(JList list,
056: Object value, int index, boolean isSelected,
057: boolean cellHasFocus) {
058: JLabel label = (JLabel) super .getListCellRendererComponent(
059: list, value, index, isSelected, cellHasFocus);
060: label.setFont(new Font("Dialog", 0, 10));
061: return label;
062: }
063: };
064: {
065: panel.setLayout(new GridBagLayout());
066: panel.add(colorPanel, new GridBagConstraints(0, 0, 1, 1, 1, 0,
067: GridBagConstraints.WEST, GridBagConstraints.NONE,
068: new Insets(2, 2, 2, 2), 0, 0));
069: setColorPanelSize(new Dimension(45, 8));
070: }
071:
072: protected void setColorPanelSize(Dimension d) {
073: colorPanel.setMinimumSize(d);
074: colorPanel.setMaximumSize(d);
075: colorPanel.setPreferredSize(d);
076: }
077:
078: private int alpha = 255;
079:
080: public void setAlpha(int alpha) {
081: this .alpha = alpha;
082: }
083:
084: public Component getListCellRendererComponent(JList list,
085: Object value, int index, boolean isSelected,
086: boolean cellHasFocus) {
087: if (value instanceof String) {
088: //Get here for "Custom..." [Jon Aquino]
089: return defaultListCellRenderer
090: .getListCellRendererComponent(list, value, index,
091: isSelected, cellHasFocus);
092: }
093: BasicStyle basicStyle = (BasicStyle) value;
094: //colorPanel.setLineWidth(Math.min(3, basicStyle.getLineWidth()));
095: //colorPanel.setLineStroke(basicStyle.getLineStroke());
096: colorPanel.setStyle(basicStyle);
097: colorPanel
098: .setLineColor(basicStyle instanceof BasicStyle
099: && ((BasicStyle) basicStyle).isRenderingLine() ? GUIUtil
100: .alphaColor(((BasicStyle) basicStyle)
101: .getLineColor(), alpha)
102: : (isSelected ? list.getSelectionBackground()
103: : list.getBackground()));
104: colorPanel
105: .setFillColor(basicStyle instanceof BasicStyle
106: && ((BasicStyle) basicStyle).isRenderingFill() ? GUIUtil
107: .alphaColor(((BasicStyle) basicStyle)
108: .getFillColor(), alpha)
109: : (isSelected ? list.getSelectionBackground()
110: : list.getBackground()));
111: if (isSelected) {
112: colorPanel.setForeground(list.getSelectionForeground());
113: colorPanel.setBackground(list.getSelectionBackground());
114: panel.setForeground(list.getSelectionForeground());
115: panel.setBackground(list.getSelectionBackground());
116: } else {
117: colorPanel.setForeground(list.getForeground());
118: colorPanel.setBackground(list.getBackground());
119: panel.setForeground(list.getForeground());
120: panel.setBackground(list.getBackground());
121: }
122: return panel;
123: }
124:
125: }
|