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.net.URL;
032:
033: import javax.swing.ImageIcon;
034: import javax.swing.JToggleButton;
035: import javax.swing.SwingConstants;
036:
037: import uk.ac.leeds.ccg.geotools.Theme;
038:
039: /**
040: * This class implements clickable theme buttons of the (Geo)Object viewer.
041: *
042: * @author Thierry Badard & Arnaud Braun
043: * @version 1.0
044: *
045: */
046:
047: class ObjectViewerThemeButton extends JToggleButton {
048:
049: private ObjectViewerInterface objectViewerInterface;
050: private ObjectViewerThemeProperties themeProperties;
051:
052: public ObjectViewerThemeButton(
053: ObjectViewerInterface objectViewerInterface,
054: ObjectViewerThemeProperties themeProp) {
055:
056: super (themeProp.getObjectViewerTheme().getName(), themeProp
057: .isActive());
058: URL imageUrl;
059:
060: final Theme theme = themeProp.getObjectViewerTheme();
061: boolean themeIsVisible = themeProp.isVisible();
062: boolean themeIsActive = themeProp.isActive();
063:
064: if (themeIsVisible) {
065: imageUrl = this .getClass()
066: .getResource("images/checked.gif");
067: setIcon(new ImageIcon(imageUrl));
068: } else {
069: imageUrl = this .getClass().getResource(
070: "images/unchecked.gif");
071: setIcon(new ImageIcon(imageUrl));
072: }
073:
074: this .objectViewerInterface = objectViewerInterface;
075: this .themeProperties = themeProp;
076:
077: setHorizontalAlignment(SwingConstants.LEFT);
078:
079: addActionListener(new ActionListener() {
080: public void actionPerformed(ActionEvent e) {
081: if (getThemeProperties().isActive()) {
082: //System.out.println("Theme unpressed !");
083: getObjectViewerInterface().getActiveThemes()
084: .remove(theme);
085: getThemeProperties().setActive(false);
086: theme.setSelectionManager(null);
087: theme.setHighlightManager(null);
088: } else {
089: //System.out.println("Theme pressed !");
090: getObjectViewerInterface().getActiveThemes().add(
091: theme);
092: getThemeProperties().setActive(true);
093: theme.setSelectionManager(getThemeProperties()
094: .getThemeSelectionManager());
095: theme.setHighlightManager(getThemeProperties()
096: .getThemeHighlightManager());
097: }
098: }
099: });
100:
101: }
102:
103: public ObjectViewerInterface getObjectViewerInterface() {
104: return objectViewerInterface;
105: }
106:
107: public ObjectViewerThemeProperties getThemeProperties() {
108: return themeProperties;
109: }
110:
111: }
|