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.mics;
025    
026    import java.util.ArrayList;
027    import java.util.HashSet;
028    
029    import javax.swing.JFrame;
030    
031    import org.tigris.gef.graph.presentation.DefaultGraphModel;
032    
033    import se.liu.ida.critiquer.activities.Activity;
034    import se.liu.ida.critiquer.activities.ActivityFactory;
035    import se.liu.ida.critiquer.activities.parameters.Commanders;
036    import se.liu.ida.critiquer.constraints.AgentMutex;
037    import se.liu.ida.critiquer.constraints.ConstraintFactory;
038    import se.liu.ida.critiquer.constraints.FuelLowCritic;
039    import se.liu.ida.critiquer.constraints.IncompleteActivity;
040    import se.liu.ida.critiquer.constraints.NonSuitableAgent;
041    import se.liu.ida.critiquer.constraints.ResourceUsageCritic;
042    import se.liu.ida.critiquer.constraints.StandardConstraint;
043    import se.liu.ida.critiquer.constraints.TestActivityArea;
044    import se.liu.ida.critiquer.constraints.TimeCalculator;
045    import se.liu.ida.critiquer.constraints.TimeParameterOrdering;
046    import se.liu.ida.critiquer.constraints.TooLongTime;
047    import se.liu.ida.critiquer.gui.CriticTextArea;
048    import se.liu.ida.critiquer.gui.GeoView;
049    import se.liu.ida.critiquer.gui.ResourceView;
050    import se.liu.ida.critiquer.gui.TimeView;
051    import se.liu.ida.critiquer.resources.AgentFactory;
052    import se.liu.ida.critiquer.resources.OrganizationModel;
053    import se.liu.ida.critiquer.scenarios.standard.CorrectOrdering;
054    import se.liu.ida.critiquer.scenarios.standard.StandardActivityFactory;
055    import se.liu.ida.critiquer.scenarios.standard.StandardAgentFactory;
056    
057    /**
058     * 
059     * <p>If it makes sense to have global references to something, then put it here.
060     * This could be references to activity classes, constraint classes or such
061     * like.
062     * </p> 
063     */
064    
065    public class ReferenceHolder {
066            /**
067         * 
068         * The scenario specific factories that create a list of activity classes as
069         * well as a resource structure as required by the
070         * <code>OrganizationModel</code>.
071         * 
072         * TODO: Change these by creating a scenario selection possibility
073         */
074            public static ActivityFactory                                                           activityFactory  = new StandardActivityFactory();
075    
076            public static AgentFactory                                                                 agentFactory         = new StandardAgentFactory();
077    
078            /**
079         * The activity classes used in the current scenario. These are created by
080         * the <code>activityFactory</code>.
081         */
082            public static ArrayList<Class<? extends Activity>>             activityClasses;
083            static {
084                    /**
085             * Retrieve a list of activities from the ActivityFactory represented by
086             * the current scenario.
087             */
088                    activityClasses = activityFactory.getActivityClasses();
089            }
090    
091            public static ArrayList<Class<? extends StandardConstraint>> constraintClasses   = new ArrayList<Class<? extends StandardConstraint>>();
092            static {
093                    constraintClasses.add(TooLongTime.class);
094                    constraintClasses.add(NonSuitableAgent.class);
095                    constraintClasses.add(ResourceUsageCritic.class);
096                    constraintClasses.add(IncompleteActivity.class);
097                    constraintClasses.add(FuelLowCritic.class);
098                    constraintClasses.add(AgentMutex.class);
099                    constraintClasses.add(TimeCalculator.class);
100                    constraintClasses.add(CorrectOrdering.class);
101                    
102                    /**
103             * 
104             * Add more constraint classes here
105             * 
106             */
107    
108                    for (Class c : constraintClasses) {
109                            ConstraintFactory.createSingletonVisualConstraint(c,false);
110                    }
111    
112            }
113    
114            
115            /**
116         * Static reference to all constraints that order activities in time in some
117         * way.
118         */
119            public static ArrayList<TimeParameterOrdering>                       temporalConstraints = new ArrayList<TimeParameterOrdering>();
120    
121            /**
122         * Model of all the resources that are available in the organization,
123         * ordered hierarchically according to subsumption. That is, a larger force
124         * element subsumes a smaller iff the smaller element is contained as a part
125         * of the larger.
126         */
127            public static OrganizationModel                                                   organizationModel   = new OrganizationModel();
128    
129            /**
130         * 
131         * Static reference to a set of all activities that are created.
132         * 
133         */
134            public static HashSet<Activity>                                                     allActivities    = new HashSet<Activity>();
135    
136            /**
137         * Activity that is currently selected in some view and may therefore be of
138         * particular interest to critics that highlight information on the
139         * currently selected activity.
140         */
141            public static Activity                                                                     selectedActivity;
142    
143            public static JFrame                                                                             topFrame;
144    
145            public static TimeView                                                                     timeView;
146    
147            public static ResourceView                                                                 resourceView;
148            public static GeoView simulationView; 
149    
150            private static DefaultGraphModel                                                         graphModel;
151    
152            /**
153         * 
154         * To make sure that there is only one graph model used by all views that
155         * want to represent tasks in a graph, we have a singleton graph model
156         * factory here.
157         * 
158         * @return a new graph model if none exists or the one that was created
159         *         during a previous call to this method.
160         */
161            public static DefaultGraphModel getGraphModel() {
162                    if (graphModel == null) {
163                            graphModel = new DefaultGraphModel();
164                    }
165                    return graphModel;
166            }
167    
168            /**
169         * 
170         * Since the list of commanders should be available to several views that
171         * are not related (the task view and resource view for instance), there is
172         * a reference to it here.
173         * 
174         */
175            public static Commanders commanders = new Commanders();
176    
177            /**
178         * 
179         * Directory containing the map and other image resources
180         * 
181         */
182            public static String     resourceDir;
183    
184            /**
185         * Information area that can be used by critics if they want to display
186         * information in textual form
187         */
188            public static CriticTextArea  critiqueInfoArea;
189    
190    }