001    /**
002     * planningtool - A Planning Tool with Critiquing Support.
003     * 
004     * Copyright (C) 2006 olale
005    
006     * This program is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU General Public License
008     * as published by the Free Software Foundation; either version 2
009     * of the License, or (at your option) any later version.
010    
011     * This program is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015    
016     * You should have received a copy of the GNU General Public License
017     * along with this program; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019    
020     * Contact information: 
021     * E-mail: olale@ida.liu.se
022     *         olale@lysator.liu.se
023     */
024    package se.liu.ida.critiquer.gui;
025    
026    import java.awt.BorderLayout;
027    import java.awt.Shape;
028    import java.awt.event.ActionEvent;
029    import java.awt.event.ActionListener;
030    import java.util.ArrayList;
031    
032    import javax.swing.DefaultComboBoxModel;
033    import javax.swing.ImageIcon;
034    import javax.swing.JComboBox;
035    import javax.swing.JLabel;
036    import javax.swing.JPanel;
037    import javax.swing.JScrollPane;
038    
039    import se.liu.ida.critiquer.activities.AbstractActivityCreatedListener;
040    import se.liu.ida.critiquer.activities.Activity;
041    import se.liu.ida.critiquer.activities.ActivityUtils;
042    import se.liu.ida.critiquer.activities.parameters.LocationParameter;
043    import se.liu.ida.critiquer.mics.ReferenceHolder;
044    import se.liu.ida.critiquer.mics.Utils;
045    
046    public class GeoView extends AbstractView {
047    
048            /**
049             * 
050             */
051            private static final long       serialVersionUID        = 1L;
052            private ScrollableMap   scrollableMap;
053            private JScrollPane     mapPane;
054            private transient JComboBox activityList;
055            private DefaultComboBoxModel locationModel;
056            private transient JComboBox locationList;
057            private DefaultComboBoxModel activityListModel;
058            /**
059             * Metres per pixel
060             */
061            private double scale = 150;
062            
063    
064            public GeoView() {
065                    super();
066                    setLayout(new BorderLayout());
067                    init();
068                    ReferenceHolder.simulationView=this;
069            }
070            
071            public void init(){
072                    scrollableMap = new ScrollableMap(      new ImageIcon(ReferenceHolder.resourceDir + System.getProperty("file.separator")
073                                                                          + "karta.jpg"),
074                                                                          10);
075                    mapPane = new JScrollPane(scrollableMap);
076                    add(mapPane,BorderLayout.CENTER);
077                    JPanel locationParameterPanel = new JPanel(new BorderLayout());
078                    locationModel = new DefaultComboBoxModel();
079                    locationList = new JComboBox(locationModel);
080                    locationList.setEditable(false);
081                    locationList.addActionListener(new ActionListener(){
082    
083                            public void actionPerformed(ActionEvent e) {
084                                    
085                                            scrollableMap.setLocationParam((LocationParameter) locationList
086                                                    .getSelectedItem());
087                                                            
088                            }
089                            
090                    });
091                    
092                    activityListModel = new DefaultComboBoxModel(Utils.toVector(ReferenceHolder.allActivities));
093                    Activity.addActivityUpdateListener(new AbstractActivityCreatedListener(){
094    
095                            /**
096                             * 
097                             */
098                            private static final long serialVersionUID = 1L;
099    
100                            public void activityCreated(Activity activity) {
101                                    activityListModel.addElement(activity);
102                            }
103    
104                            public void activityRemoved(Activity a) {
105                                    activityListModel.removeElement(a);
106                            }
107                            
108                    });
109                    
110                    activityList = new JComboBox(activityListModel);
111                    activityList.setEditable(false);
112                    activityList.addActionListener(new ActionListener(){
113    
114                            public void actionPerformed(ActionEvent e) {
115                                    Activity activity = (Activity) activityList.getSelectedItem();
116                                    locationModel.removeAllElements();
117                                    ArrayList<LocationParameter> params = ActivityUtils.filterParams(activity, LocationParameter.class);
118                                    for (LocationParameter parameter : params) {
119                                            locationModel.addElement(parameter);
120                                    }
121                            }
122                            
123                    });
124                    locationParameterPanel.add(new JLabel("Select an activity and location parameter"),
125                                    BorderLayout.WEST);
126                    locationParameterPanel.add(activityList,BorderLayout.CENTER);
127                    locationParameterPanel.add(locationList,BorderLayout.EAST);
128                    locationParameterPanel.add(critiqueComponent.getPanel(),BorderLayout.SOUTH);
129                    
130                    add(locationParameterPanel,BorderLayout.SOUTH);
131            }
132            
133            
134            public Shape getActivityArea(Activity activity) {
135                    // TODO Auto-generated method stub
136                    return null;
137            }
138    
139            public ArrayList<Activity> getEvaluationActivities() {
140                    // TODO Auto-generated method stub
141                    return null;
142            }
143    
144            /**
145             * @return Returns the scale.
146             */
147            public double getScale() {
148                    return scale;
149            }
150    
151            /**
152             * @param scale The scale to set.
153             */
154            public void setScale(double scale) {
155                    this.scale = scale;
156            }
157    
158    }