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.style;
033:
034: import java.awt.Color;
035: import java.io.InputStream;
036: import java.io.InputStreamReader;
037: import java.util.ArrayList;
038: import java.util.Collections;
039: import java.util.Iterator;
040: import java.util.List;
041:
042: import javax.swing.JPanel;
043:
044: import com.vividsolutions.jts.util.Assert;
045: import com.vividsolutions.jump.util.StringUtil;
046: import com.vividsolutions.jump.util.java2xml.XML2Java;
047: import com.vividsolutions.jump.workbench.ui.renderer.style.BasicStyle;
048:
049: public abstract class AbstractPalettePanel extends JPanel {
050:
051: protected ArrayList listeners = new ArrayList();
052:
053: public static class BasicStyleList {
054: private ArrayList basicStyles = new ArrayList();
055:
056: public List getBasicStyles() {
057: return Collections.unmodifiableList(basicStyles);
058: }
059:
060: public void addBasicStyle(BasicStyle basicStyle) {
061: basicStyles.add(basicStyle);
062: }
063: }
064:
065: public static interface Listener {
066: public void basicStyleChosen(BasicStyle basicStyle);
067: }
068:
069: public void add(Listener listener) {
070: listeners.add(listener);
071: }
072:
073: public abstract void setAlpha(int alpha);
074:
075: protected void fireBasicStyleChosen(BasicStyle basicStyle) {
076: for (Iterator i = listeners.iterator(); i.hasNext();) {
077: Listener listener = (Listener) i.next();
078: listener.basicStyleChosen(basicStyle);
079: }
080: }
081:
082: public static List basicStyles() {
083: try {
084: if (basicStyleList == null) {
085: InputStream stream = AbstractPalettePanel.class
086: .getResourceAsStream(StringUtil
087: .classNameWithoutQualifiers(AbstractPalettePanel.class
088: .getName())
089: + ".xml");
090: try {
091: InputStreamReader reader = new InputStreamReader(
092: stream);
093: try {
094: basicStyleList = ((BasicStyleList) new XML2Java()
095: .read(reader, BasicStyleList.class));
096: } finally {
097: reader.close();
098: }
099: } finally {
100: stream.close();
101: }
102: }
103: } catch (Exception e) {
104: e.printStackTrace(System.err);
105: Assert.shouldNeverReachHere();
106: return null;
107: }
108: return basicStyleList.getBasicStyles();
109: }
110:
111: private static BasicStyleList basicStyleList = null;
112:
113: public static void main(String[] args) {
114: Color c = new Color(255, 28, 174).darker();
115: System.out.println(c.getRed() + ", " + c.getGreen() + ", "
116: + c.getBlue());
117: }
118: }
|