View Javadoc

1   /*
2    * @(#) ExperimentParsingThread.java Mar 2, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the 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 2003 <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/gpl.html">General Public
32   * License (GPL) </a>, no warranty <br>
33   * 
34   * @version 1.0 Mar 2, 2004 <br>
35   * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
36   *         Jacobs </a>
37   */
38  public class GUIExperimentParsingThread extends ExperimentParsingThread
39  {
40  
41  	/*** the parent component */
42  	protected Component parent = null;
43  
44  	/***
45  	 * constructs a new ExperimentParsingThread
46  	 * 
47  	 * @param source the source of this thread
48  	 * @param parent the parent component
49  	 * @param experiment the experiment to parse
50  	 */
51  	public GUIExperimentParsingThread(final EventListenerInterface source,
52  			final Component parent, final URL experiment)
53  	{
54  		super(source, experiment);
55  		this.parent = parent;
56  	}
57  
58  	/***
59  	 * @see java.lang.Runnable#run()
60  	 */
61  	public void run()
62  	{
63  		WaitingFrame waitingFrame = new WaitingFrame();
64  		try
65  		{
66  			Experiment experiment = ExperimentParser
67  					.parseExperiment(this.experiment);
68  			this.source.notify(new Event(EXPERIMENT_PARSED_EVENT, this,
69  					experiment));
70  			waitingFrame.dispose();
71  		} catch (IOException exception)
72  		{
73  			waitingFrame.dispose();
74  			Logger.warning(this, "run", exception);
75  			JOptionPane.showMessageDialog(this.parent,
76  					exception.getClass().getName()
77  							.substring(
78  									exception.getClass().getName().lastIndexOf(
79  											".") + 1)
80  							+ " occurred while loading "
81  							+ this.experiment
82  							+ ".\n", "Error", JOptionPane.ERROR_MESSAGE);
83  		}
84  	}
85  }