View Javadoc

1   /*
2    * @(#) ExperimentParsingThread.java Mar 2, 2004
3    * 
4    * Copyright (c) 2002-2005 Delft University of Technology Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the Lesser General Public License
9    */
10  package nl.tudelft.simulation.dsol.gui.panels;
11  
12  import java.awt.Component;
13  import java.io.IOException;
14  import java.net.URL;
15  
16  import javax.swing.JOptionPane;
17  
18  import nl.tudelft.simulation.dsol.experiment.Experiment;
19  import nl.tudelft.simulation.event.Event;
20  import nl.tudelft.simulation.event.EventListenerInterface;
21  import nl.tudelft.simulation.logger.Logger;
22  import nl.tudelft.simulation.xml.dsol.ExperimentParser;
23  import nl.tudelft.simulation.xml.dsol.ExperimentParsingThread;
24  
25  /***
26   * A ExperimentParsingThread <br>
27   * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft
28   * University of Technology </a>, the Netherlands. <br>
29   * See for project information <a
30   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
31   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
32   * General Public License (LGPL) </a>, no warranty.
33   * 
34   * @version $Revision: 1.4 $ $Date: 2005/01/13 16:28:55 $
35   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja">Peter Jacobs </a>
36   */
37  public class GUIExperimentParsingThread extends ExperimentParsingThread
38  {
39  
40  	/*** the parent component */
41  	protected Component parent = null;
42  
43  	/***
44  	 * constructs a new ExperimentParsingThread
45  	 * 
46  	 * @param source the source of this thread
47  	 * @param parent the parent component
48  	 * @param experiment the experiment to parse
49  	 */
50  	public GUIExperimentParsingThread(final EventListenerInterface source,
51  			final Component parent, final URL experiment)
52  	{
53  		super(source, experiment);
54  		this.parent = parent;
55  	}
56  
57  	/***
58  	 * @see java.lang.Runnable#run()
59  	 */
60  	public void run()
61  	{
62  		WaitingFrame waitingFrame = new WaitingFrame();
63  		try
64  		{
65  			Experiment experiment = ExperimentParser
66  					.parseExperiment(this.experiment);
67  			this.source.notify(new Event(EXPERIMENT_PARSED_EVENT, this,
68  					experiment));
69  			waitingFrame.dispose();
70  		} catch (IOException exception)
71  		{
72  			waitingFrame.dispose();
73  			Logger.warning(this, "run", exception);
74  			JOptionPane.showMessageDialog(this.parent,
75  					exception.getClass().getName()
76  							.substring(
77  									exception.getClass().getName().lastIndexOf(
78  											".") + 1)
79  							+ " occurred while loading "
80  							+ this.experiment
81  							+ ".\n", "Error", JOptionPane.ERROR_MESSAGE);
82  		}
83  	}
84  }