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;
033:
034: import java.awt.BorderLayout;
035: import java.awt.Color;
036: import java.awt.Dimension;
037: import java.awt.GridLayout;
038: import java.util.Iterator;
039:
040: import javax.swing.JPanel;
041:
042: import com.vividsolutions.jump.workbench.model.Layer;
043: import com.vividsolutions.jump.workbench.ui.renderer.style.BasicStyle;
044: import com.vividsolutions.jump.workbench.ui.renderer.style.ColorThemingStyle;
045: import com.vividsolutions.jump.workbench.ui.renderer.style.DummyStyle;
046: import com.vividsolutions.jump.workbench.ui.renderer.style.Style;
047:
048: public class LayerColorPanel extends JPanel {
049: public LayerColorPanel() {
050: setLayout(new BorderLayout());
051: add(oneColorPanel);
052: setMaximumSize(new Dimension(10, 10));
053: setMinimumSize(new Dimension(10, 10));
054: setPreferredSize(new Dimension(10, 10));
055: }
056:
057: private ColorPanel oneColorPanel = new ColorPanel();
058: private FourColorPanel fourColorPanel = new LayerColorPanel.FourColorPanel();
059:
060: public LayerColorPanel init(Layer layer, boolean selected,
061: Color backgroundColor, Color selectionBackgroundColor) {
062: if (getComponents()[0] == fourColorPanel) {
063: remove(fourColorPanel);
064: add(oneColorPanel);
065: }
066: color(oneColorPanel, layer.getBasicStyle(), selected,
067: backgroundColor, selectionBackgroundColor);
068: ColorThemingStyle colorThemingStyle = (ColorThemingStyle) layer
069: .getStyle(ColorThemingStyle.class);
070: if (colorThemingStyle != null && colorThemingStyle.isEnabled()) {
071: if (getComponents()[0] == oneColorPanel) {
072: remove(oneColorPanel);
073: add(fourColorPanel);
074: }
075: Iterator styles = colorThemingStyle
076: .getAttributeValueToBasicStyleMap().values()
077: .iterator();
078: color(fourColorPanel.panel1, colorThemingStyle
079: .getDefaultStyle(), selected, backgroundColor,
080: selectionBackgroundColor);
081: color(fourColorPanel.panel2,
082: styles.hasNext() ? (Style) styles.next()
083: : DummyStyle.instance(), selected,
084: backgroundColor, selectionBackgroundColor);
085: color(fourColorPanel.panel3,
086: styles.hasNext() ? (Style) styles.next()
087: : DummyStyle.instance(), selected,
088: backgroundColor, selectionBackgroundColor);
089: color(fourColorPanel.panel4,
090: styles.hasNext() ? (Style) styles.next()
091: : DummyStyle.instance(), selected,
092: backgroundColor, selectionBackgroundColor);
093: }
094: return this ;
095: }
096:
097: private void color(ColorPanel colorPanel, Style style,
098: boolean selected, Color backgroundColor,
099: Color selectionBackgroundColor) {
100: colorPanel.setLineColor(style instanceof BasicStyle
101: && ((BasicStyle) style).isRenderingLine() ? GUIUtil
102: .alphaColor(((BasicStyle) style).getLineColor(),
103: ((BasicStyle) style).getAlpha())
104: : (selected ? selectionBackgroundColor
105: : backgroundColor));
106: colorPanel.setFillColor(style instanceof BasicStyle
107: && ((BasicStyle) style).isRenderingFill() ? GUIUtil
108: .alphaColor(((BasicStyle) style).getFillColor(),
109: ((BasicStyle) style).getAlpha())
110: : (selected ? selectionBackgroundColor
111: : backgroundColor));
112: }
113:
114: public static class FourColorPanel extends JPanel {
115: public ColorPanel panel1 = new ColorPanel();
116: public ColorPanel panel2 = new ColorPanel();
117: public ColorPanel panel3 = new ColorPanel();
118: public ColorPanel panel4 = new ColorPanel();
119:
120: public FourColorPanel() {
121: GridLayout gridLayout = new GridLayout(2, 2);
122: setLayout(gridLayout);
123: add(panel1);
124: add(panel2);
125: add(panel3);
126: add(panel4);
127: }
128: }
129: }
|