01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.mlm.debug.ui;
28:
29: import java.text.DateFormat;
30: import java.util.Date;
31: import java.util.TimeZone;
32:
33: import org.cougaar.planning.ldm.plan.Schedule;
34:
35: /** A tree node for a Schedule.
36: Overrides the UITreeNode loadChildren, toString and isLeaf
37: methods to dynamically display the Schedule which has no children.
38: */
39:
40: public class UIScheduleNode extends UITreeNode {
41: Schedule schedule;
42: String prefix;
43:
44: /** Create a tree node for the schedule.
45: @param schedule schedule for which to create a tree node
46: */
47: public UIScheduleNode(Schedule schedule, String prefix) {
48: super (schedule);
49: this .schedule = schedule;
50: this .prefix = prefix;
51: }
52:
53: /** The Schedule is a leaf.
54: @return true
55: */
56: public boolean isLeaf() {
57: return true;
58: }
59:
60: /** This shouldn't be called because this is a leaf.
61: */
62:
63: public void loadChildren() {
64: System.out
65: .println("UIScheduleNode:loadChildren called, but Schedule is a leaf.");
66: }
67:
68: /** Return representation of a Schedule in a tree:
69: The startLocation and endLocation are displayed only if they are
70: specified in the schedule.
71: @return From (startLocation) (startDate) to (endLocation) (endDate).
72: */
73:
74: public String toString() {
75: //String startLocation = schedule.getStartLocation();
76: //String endLocation = schedule.getEndLocation();
77: String s = "From ";
78: //if (startLocation != null)
79: //s = s + startLocation + " ";
80: s = s + getDateLabel(new Date(schedule.getStartTime()))
81: + " to ";
82: //if (endLocation != null)
83: //s = s + endLocation + " ";
84: s = s + getDateLabel(new Date(schedule.getEndTime()));
85: return prefix + s;
86: }
87:
88: /** Return a string for the date and time in GMT.
89: */
90:
91: private String getDateLabel(Date date) {
92: DateFormat dateFormat = DateFormat.getDateTimeInstance(
93: DateFormat.LONG, DateFormat.SHORT);
94: dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
95: return dateFormat.format(date);
96: }
97:
98: }
|