View Javadoc

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