001: /*
002: * This file is part of the GeOxygene project source files.
003: *
004: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
005: * the development and deployment of geographic (GIS) applications. It is a open source
006: * contribution of the COGIT laboratory at the Institut Géographique National (the French
007: * National Mapping Agency).
008: *
009: * See: http://oxygene-project.sourceforge.net
010: *
011: * Copyright (C) 2005 Institut Géographique National
012: *
013: * This library is free software; you can redistribute it and/or modify it under the terms
014: * of the GNU Lesser General Public License as published by the Free Software Foundation;
015: * either version 2.1 of the License, or any later version.
016: *
017: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
018: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
019: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License along with
022: * this library (see file LICENSE if present); if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: *
025: */
026:
027: package fr.ign.cogit.geoxygene.util.viewer;
028:
029: import java.awt.event.ActionEvent;
030: import java.awt.event.ActionListener;
031: import java.awt.event.WindowAdapter;
032: import java.awt.event.WindowEvent;
033: import java.net.URL;
034:
035: import javax.swing.ButtonGroup;
036: import javax.swing.Icon;
037: import javax.swing.ImageIcon;
038: import javax.swing.JMenuItem;
039: import javax.swing.JPopupMenu;
040: import javax.swing.JRadioButtonMenuItem;
041:
042: import uk.ac.leeds.ccg.geotools.Theme;
043:
044: /**
045: * This class defines the PopMenu for the ThemeButton of the ObjectViewer's GUI.
046: *
047: * @author Thierry Badard & Arnaud Braun
048: * @version 1.0
049: *
050: */
051:
052: class ObjectViewerThemePopupMenu extends JPopupMenu {
053: //Default
054:
055: //Public variables
056: public ObjectViewerInterface objectViewerInterface;
057: public ObjectViewerThemeButton objectViewerThemeButton;
058: public ObjectViewerThemeProperties objectViewerThemeProperties;
059:
060: public ObjectViewerThemePopupMenu(
061: ObjectViewerInterface objectViewerInterface,
062: ObjectViewerThemeButton objectViewerThemeButton,
063: ObjectViewerThemeProperties objectViewerThemeProperties) {
064:
065: super ();
066:
067: setObjectViewerInterface(objectViewerInterface);
068: setObjectViewerThemeButton(objectViewerThemeButton);
069: setObjectViewerThemeProperties(objectViewerThemeProperties);
070:
071: addDefaultItems();
072: }
073:
074: private void addDefaultItems() {
075: URL imageUrl;
076: imageUrl = this .getClass().getResource("images/checked.gif");
077: final Icon checked = new ImageIcon(imageUrl);
078: imageUrl = this .getClass().getResource("images/unchecked.gif");
079: final Icon unchecked = new ImageIcon(imageUrl);
080:
081: ButtonGroup rbGroup = new ButtonGroup();
082: JRadioButtonMenuItem rbMenuItem = new JRadioButtonMenuItem(
083: "Visible");
084: if (getObjectViewerThemeProperties().isVisible())
085: rbMenuItem.setSelected(true);
086: rbGroup.add(rbMenuItem);
087: rbMenuItem.addActionListener(new ActionListener() {
088: public void actionPerformed(ActionEvent e) {
089: if (getObjectViewerThemeButton().getIcon().toString()
090: .equals(unchecked.toString())) {
091: getObjectViewerThemeButton().setIcon(checked);
092: getObjectViewerThemeProperties().setVisible(true);
093: getObjectViewerInterface().view
094: .setThemeIsVisible(
095: getObjectViewerThemeProperties()
096: .getObjectViewerTheme(),
097: true, true);
098: }
099: }
100: });
101: add(rbMenuItem);
102:
103: rbMenuItem = new JRadioButtonMenuItem("Unvisible");
104: if (!getObjectViewerThemeProperties().isVisible())
105: rbMenuItem.setSelected(true);
106: rbGroup.add(rbMenuItem);
107: rbMenuItem.addActionListener(new ActionListener() {
108: public void actionPerformed(ActionEvent e) {
109: if (getObjectViewerThemeButton().getIcon().toString()
110: .equals(checked.toString())) {
111: getObjectViewerThemeButton().setIcon(unchecked);
112: getObjectViewerThemeProperties().setVisible(false);
113: getObjectViewerInterface().view.setThemeIsVisible(
114: getObjectViewerThemeProperties()
115: .getObjectViewerTheme(), false,
116: true);
117: }
118: }
119: });
120: add(rbMenuItem);
121:
122: JMenuItem menuItem = new JMenuItem("Up");
123: menuItem.addActionListener(new ActionListener() {
124: public void actionPerformed(ActionEvent e) {
125: Theme t = getObjectViewerThemeProperties()
126: .getObjectViewerTheme();
127: getObjectViewerInterface().upTheme(t);
128: }
129: });
130: add(menuItem);
131:
132: menuItem = new JMenuItem("Down");
133: menuItem.addActionListener(new ActionListener() {
134: public void actionPerformed(ActionEvent e) {
135: Theme t = getObjectViewerThemeProperties()
136: .getObjectViewerTheme();
137: getObjectViewerInterface().downTheme(t);
138: }
139: });
140: add(menuItem);
141:
142: menuItem = new JMenuItem("Remove");
143: menuItem.addActionListener(new ActionListener() {
144: public void actionPerformed(ActionEvent e) {
145: getObjectViewerInterface().removeTheme(
146: getObjectViewerThemeProperties());
147: }
148: });
149: add(menuItem);
150:
151: menuItem = new JMenuItem("Show attributes");
152: menuItem.addActionListener(new ActionListener() {
153: public void actionPerformed(ActionEvent e) {
154: System.out.println("Showing theme attributes ...");
155:
156: final ObjectViewerAttributesTableFrame themeAttributesFrame = new ObjectViewerAttributesTableFrame(
157: getObjectViewerThemeProperties()
158: .getObjectViewerTheme(),
159: getObjectViewerThemeProperties()
160: .getDataSourceType(),
161: getObjectViewerThemeProperties()
162: .getDataSource());
163:
164: themeAttributesFrame
165: .addWindowListener(new WindowAdapter() {
166: public void windowClosing(WindowEvent e) {
167: themeAttributesFrame.dispose();
168: }
169: });
170: themeAttributesFrame.setResizable(true);
171: themeAttributesFrame.pack();
172: themeAttributesFrame.setVisible(true);
173: }
174: });
175: add(menuItem);
176:
177: addSeparator();
178:
179: menuItem = new JMenuItem("Properties");
180: menuItem.addActionListener(new ActionListener() {
181: public void actionPerformed(ActionEvent e) {
182: //final JFrame ccframe = new ObjectViewerColorChooser();
183: //final ObjectViewerThemePropertiesFrame themePropertiesFrame = new ObjectViewerThemePropertiesFrame(objectViewerThemeProperties.getFillInThemeColor(),objectViewerThemeProperties.getOutlineThemeColor());
184: final ObjectViewerThemePropertiesFrame themePropertiesFrame = new ObjectViewerThemePropertiesFrame(
185: objectViewerThemeProperties);
186: themePropertiesFrame
187: .addWindowListener(new WindowAdapter() {
188: public void windowClosing(WindowEvent e) {
189: themePropertiesFrame.dispose();
190: //System.exit(0);
191: }
192: });
193: themePropertiesFrame.setResizable(false);
194: themePropertiesFrame.pack();
195: themePropertiesFrame.setVisible(true);
196: }
197: });
198: add(menuItem);
199:
200: }
201:
202: public void setObjectViewerInterface(
203: ObjectViewerInterface objectViewerInterface) {
204: this .objectViewerInterface = objectViewerInterface;
205: }
206:
207: public ObjectViewerInterface getObjectViewerInterface() {
208: return objectViewerInterface;
209: }
210:
211: public void setObjectViewerThemeButton(
212: ObjectViewerThemeButton objectViewerThemeButton) {
213: this .objectViewerThemeButton = objectViewerThemeButton;
214: }
215:
216: public ObjectViewerThemeButton getObjectViewerThemeButton() {
217: return objectViewerThemeButton;
218: }
219:
220: public void setObjectViewerThemeProperties(
221: ObjectViewerThemeProperties objectViewerThemeProperties) {
222: this .objectViewerThemeProperties = objectViewerThemeProperties;
223: }
224:
225: public ObjectViewerThemeProperties getObjectViewerThemeProperties() {
226: return objectViewerThemeProperties;
227: }
228:
229: }
|