View Javadoc

1   /*
2    * @(#) ExperimentTree.java Oct 14, 2003
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.util.Calendar;
13  import java.util.Enumeration;
14  import java.util.Iterator;
15  import java.util.Map;
16  import java.util.Properties;
17  
18  import javax.swing.tree.DefaultMutableTreeNode;
19  import javax.swing.tree.DefaultTreeModel;
20  
21  import nl.tudelft.simulation.dsol.experiment.Experiment;
22  import nl.tudelft.simulation.dsol.experiment.Replication;
23  import nl.tudelft.simulation.dsol.experiment.RunControl;
24  import nl.tudelft.simulation.dsol.experiment.Treatment;
25  
26  /***
27   * ExperimentTree <br>
28   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
29   * University of Technology </a>, the Netherlands. <br>
30   * See for project information <a
31   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
32   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
33   * License (GPL) </a>, no warranty <br>
34   * 
35   * @version 1.0 18.10.2003 <br>
36   * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
37   *         Jacobs </a>
38   */
39  public class ExperimentTree extends DefaultTreeModel
40  {
41  	/***
42  	 * constructs a new ExperimentTree
43  	 * 
44  	 * @param experiment experiment
45  	 */
46  	public ExperimentTree(final Experiment experiment)
47  	{
48  		super(new DefaultMutableTreeNode(experiment
49  				.getProperty(Experiment.EXPERIMENT_NAME)));
50  		DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.getRoot();
51  		root.add(new DefaultMutableTreeNode(experiment
52  				.getProperty(Experiment.EXPERIMENT_ANALYST)));
53  		root.add(new DefaultMutableTreeNode(experiment.getUrl()));
54  		for (int i = 0; i < experiment.getTreatments().length; i++)
55  		{
56  			root.add(this.getTreatment(experiment.getTreatments()[i]));
57  		}
58  	}
59  
60  	/***
61  	 * converts a treatment to a treenode
62  	 * 
63  	 * @param treatment the treatent
64  	 * @return DefaultMutableTreeNode
65  	 */
66  	private DefaultMutableTreeNode getTreatment(final Treatment treatment)
67  	{
68  		DefaultMutableTreeNode result = new DefaultMutableTreeNode("Treatment");
69  		result.add(new DefaultMutableTreeNode("time unit="
70  				+ treatment.getTimeUnit()));
71  		Calendar calendar = Calendar.getInstance();
72  		calendar.setTimeInMillis(treatment.getStartTime());
73  		String startTime = calendar.getTime().toString();
74  		result.add(new DefaultMutableTreeNode("start time=" + startTime));
75  		result.add(this.getRunControl(treatment.getRunControl()));
76  		result.add(this.getProperties(treatment.getProperties()));
77  		return result;
78  	}
79  
80  	/***
81  	 * converts properties to a treeNode
82  	 * 
83  	 * @param properties the properties
84  	 * @return DefaultMutableTreeNode
85  	 */
86  	private DefaultMutableTreeNode getProperties(final Properties properties)
87  	{
88  		DefaultMutableTreeNode result = new DefaultMutableTreeNode("Properties");
89  		Enumeration keys = properties.keys();
90  		while (keys.hasMoreElements())
91  		{
92  			String key = (String) keys.nextElement();
93  			String value = properties.getProperty(key);
94  			result.add(new DefaultMutableTreeNode(key + "(" + value + ")"));
95  		}
96  		return result;
97  	}
98  
99  	/***
100 	 * converts a runControl to a treenode
101 	 * 
102 	 * @param runControl the runControl
103 	 * @return DefaultMutableTreeNode
104 	 */
105 	private DefaultMutableTreeNode getRunControl(final RunControl runControl)
106 	{
107 		DefaultMutableTreeNode result = new DefaultMutableTreeNode("RunControl");
108 		result.add(new DefaultMutableTreeNode("run length="
109 				+ runControl.getRunLength()));
110 		result.add(new DefaultMutableTreeNode("warmup period="
111 				+ runControl.getWarmupPeriod()));
112 		for (int i = 0; i < runControl.getReplications().length; i++)
113 		{
114 			result.add(this.getReplication(runControl.getReplications()[i]));
115 		}
116 		return result;
117 	}
118 
119 	/***
120 	 * converts the replication in a tree node
121 	 * 
122 	 * @param replication the replication
123 	 * @return DefaultMutableTreeNode
124 	 */
125 	private DefaultMutableTreeNode getReplication(final Replication replication)
126 	{
127 		DefaultMutableTreeNode result = new DefaultMutableTreeNode(
128 				"Replication");
129 		result.add(new DefaultMutableTreeNode("description="
130 				+ replication.getDescription()));
131 		Map streams = replication.getStreams();
132 		for (Iterator i = streams.keySet().iterator(); i.hasNext();)
133 		{
134 			Object key = i.next();
135 			result.add(new DefaultMutableTreeNode("stream(" + key + ")="
136 					+ streams.get(key)));
137 		}
138 		return result;
139 	}
140 }