View Javadoc

1   /*
2    * @(#) ContentUtilities.java Nov 24, 2004
3    * 
4    * 
5    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
6    * Delft, the Netherlands. All rights reserved.
7    * 
8    * See for project information <a href="http://www.simulation.tudelft.nl/">
9    * www.simulation.tudelft.nl </a>.
10   * 
11   * The source code and binary code of this software is proprietary information
12   * of Delft University of Technology.
13   */
14  package org.gscg.gameleader.dialogs.content.components;
15  
16  import java.text.DateFormat;
17  import java.util.Calendar;
18  
19  import nl.tudelft.simulation.dsol.experiment.TimeUnit;
20  import nl.tudelft.simulation.dsol.experiment.TimeUnitInterface;
21  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
22  import nl.tudelft.simulation.logger.Logger;
23  
24  /***
25   * Utilities for the content dialog panels.
26   * <p>
27   * 
28   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
29   * Delft, the Netherlands. All rights reserved.
30   * 
31   * See for project information <a href="http://www.simulation.tudelft.nl/">
32   * www.simulation.tudelft.nl </a>.
33   * 
34   * The source code and binary code of this software is proprietary information
35   * of Delft University of Technology.
36   * 
37   * @author <a
38   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
39   *         van Houten </a>
40   * @version $Revision: 1.1 $ $Date: 2005/06/16 12:33:57 $
41   * @since 1.0.7
42   */
43  public final class ContentUtilities
44  {
45  
46  	/***
47  	 * constructs a new ContentUtilities
48  	 */
49  	private ContentUtilities()
50  	{
51  		// utility classes should not be instantiated
52  	}
53  
54  	/***
55  	 * Method parseTimeToDateString parses the given time to a date in the form
56  	 * of a String
57  	 * 
58  	 * @param date the date to parse
59  	 * @param simulator the simulator to use
60  	 * @return returns a string representing the date
61  	 */
62  	public static String parseDateToDateString(final double date,
63  			final SimulatorInterface simulator)
64  	{
65  		Calendar calendar = Calendar.getInstance();
66  		long time = 0L;
67  		try
68  		{
69  			time = (long) TimeUnit.convert(date, simulator.getReplication()
70  					.getRunControl().getTreatment().getTimeUnit(),
71  					TimeUnitInterface.MILLISECOND);
72  
73  			calendar.setTimeInMillis((time)
74  					+ simulator.getReplication().getRunControl().getTreatment()
75  							.getStartTime());
76  
77  			return DateFormat.getDateInstance().format(calendar.getTime());
78  		} catch (Exception exception)
79  		{
80  			Logger.severe(ContentUtilities.class, "parseTimeToDate", exception);
81  			return "";
82  		}
83  	}
84  }