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:
033: package com.vividsolutions.jump.workbench.ui.plugin.skin;
034:
035: import java.awt.Frame;
036: import java.awt.GridBagConstraints;
037: import java.awt.GridBagLayout;
038: import java.awt.Insets;
039: import java.awt.Window;
040: import java.awt.event.ActionEvent;
041: import java.awt.event.ActionListener;
042: import java.util.Collection;
043: import java.util.Iterator;
044:
045: import javax.swing.DefaultComboBoxModel;
046: import javax.swing.JComboBox;
047: import javax.swing.JLabel;
048: import javax.swing.JPanel;
049: import javax.swing.JPopupMenu;
050: import javax.swing.SwingUtilities;
051: import javax.swing.UIManager;
052: import javax.swing.UnsupportedLookAndFeelException;
053:
054: import com.vividsolutions.jts.util.Assert;
055: import com.vividsolutions.jump.util.Blackboard;
056: import com.vividsolutions.jump.workbench.ui.OptionsPanel;
057: import com.vividsolutions.jump.workbench.ui.TrackedPopupMenu;
058:
059: /**
060: *
061: * Implements an {@link OptionsPanel} to allow skin selection.
062: *
063: */
064:
065: public class SkinOptionsPanel extends JPanel implements OptionsPanel {
066: private static final String CURRENT_SKIN_KEY = SkinOptionsPanel.class
067: + " - CURRENT SKIN";
068: public static final String SKINS_KEY = SkinOptionsPanel.class
069: + " - SKINS";
070: private GridBagLayout gridBagLayout1 = new GridBagLayout();
071: private JComboBox comboBox = new JComboBox();
072: private JPanel fillerPanel = new JPanel();
073: private JLabel label = new JLabel();
074: private Blackboard blackboard;
075: //[UT] is not used, commented out
076: // private Window window;
077: private boolean modified;
078:
079: public SkinOptionsPanel(Blackboard blackboard, Window window) {
080: // this.window = window;
081: this .blackboard = blackboard;
082: try {
083: comboBox.addActionListener(new ActionListener() {
084: public void actionPerformed(ActionEvent e) {
085: modified = true;
086: }
087: });
088: jbInit();
089:
090: } catch (Exception ex) {
091: ex.printStackTrace();
092: }
093: }
094:
095: void jbInit() throws Exception {
096: this .setLayout(gridBagLayout1);
097: label.setText("Skin:");
098: this .add(comboBox, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
099: GridBagConstraints.CENTER, GridBagConstraints.NONE,
100: new Insets(10, 0, 10, 10), 0, 0));
101: this .add(fillerPanel, new GridBagConstraints(2, 1, 1, 1, 1.0,
102: 1.0, GridBagConstraints.CENTER,
103: GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
104: this .add(label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
105: GridBagConstraints.CENTER, GridBagConstraints.NONE,
106: new Insets(10, 10, 10, 4), 0, 0));
107:
108: }
109:
110: public void init() {
111: DefaultComboBoxModel model = new DefaultComboBoxModel();
112:
113: for (Iterator i = ((Collection) blackboard.get(SKINS_KEY))
114: .iterator(); i.hasNext();) {
115: LookAndFeelProxy proxy = (LookAndFeelProxy) i.next();
116: model.addElement(proxy);
117: }
118:
119: comboBox.setModel(model);
120: comboBox.setSelectedItem(blackboard.get(CURRENT_SKIN_KEY,
121: comboBox.getModel().getElementAt(0)));
122: modified = false;
123: }
124:
125: public void okPressed() {
126: if (!modified) {
127: return;
128: }
129:
130: blackboard.put(CURRENT_SKIN_KEY, comboBox.getSelectedItem());
131:
132: try {
133: UIManager.setLookAndFeel(((LookAndFeelProxy) comboBox
134: .getSelectedItem()).getLookAndFeel());
135: } catch (UnsupportedLookAndFeelException e) {
136: Assert.shouldNeverReachHere(e.toString());
137: }
138:
139: updateFrames();
140: updatePopupMenus();
141: }
142:
143: private void updatePopupMenus() {
144: for (Iterator i = TrackedPopupMenu.trackedPopupMenus()
145: .iterator(); i.hasNext();) {
146: JPopupMenu menu = (JPopupMenu) i.next();
147: SwingUtilities.updateComponentTreeUI(menu);
148: }
149: }
150:
151: private void updateFrames() {
152: Frame[] frames = Frame.getFrames();
153:
154: for (int i = 0; i < frames.length; i++) {
155: SwingUtilities.updateComponentTreeUI(frames[i]);
156:
157: Window[] windows = frames[i].getOwnedWindows();
158:
159: for (int j = 0; j < windows.length; j++)
160: updateWindow(windows[j]);
161: }
162: }
163:
164: private void updateWindow(Window w) {
165: SwingUtilities.updateComponentTreeUI(w);
166:
167: // [UT] 2005-10-26 bug fix for editing toolbox resize problem found by uwe dalluege
168: w.pack();
169:
170: Window[] children = w.getOwnedWindows();
171:
172: for (int i = 0; i < children.length; i++)
173: updateWindow(children[i]);
174: }
175:
176: public String validateInput() {
177: return null;
178: }
179: }
|