001    package org.hackystat.projectbrowser.page.trajectory;
002    
003    import java.io.Serializable;
004    import java.text.SimpleDateFormat;
005    import java.util.Date;
006    import java.util.Locale;
007    
008    import org.hackystat.projectbrowser.page.ProjectBrowserBasePage;
009    import org.hackystat.sensorbase.resource.projects.jaxb.Project;
010    import org.hackystat.utilities.tstamp.Tstamp;
011    
012    /**
013     * The container for the project and some auxiliary information.
014     * 
015     * @author Pavel Senin.
016     * 
017     */
018    public class ProjectRecord implements Serializable {
019    
020      /**
021       * Serial.
022       */
023      private static final long serialVersionUID = 1L;
024    
025      // the project record
026      private Project project;
027    
028      // the selected start date
029      private Date startDate;
030      // the selected end date
031      private Date endDate;
032      // the shift for the data displayed
033      private Integer indent = 0;
034    
035      private String color;
036    
037      private static final String CR = "\n";
038    
039      /**
040       * Constructor.
041       * 
042       * @param project The project.
043       * @param selectedStartDate The start date for the interval.
044       * @param selectedEndDate The end date for the interval.
045       * @param indent The shift.
046       */
047      public ProjectRecord(Project project, Date selectedStartDate, Date selectedEndDate, 
048                                                                                     Integer indent) {
049        this.project = project;
050        this.startDate = new Date(selectedStartDate.getTime());
051        this.endDate = new Date(selectedStartDate.getTime());
052        this.indent = indent;
053      }
054    
055      /**
056       * Constructor.
057       * 
058       * @param project The project.
059       * @param indent The shift in days.
060       */
061      public ProjectRecord(Project project, Integer indent) {
062        this.project = project;
063        this.startDate = new Date();
064        this.endDate = new Date();
065        this.indent = indent;
066      }
067    
068      /**
069       * Constructor.
070       */
071      public ProjectRecord() {
072        super();
073        this.project = null;
074        this.startDate = new Date(ProjectBrowserBasePage.getDateBefore(7).getTime());
075        this.endDate = new Date(ProjectBrowserBasePage.getDateBefore(1).getTime());
076        this.indent = 0;
077      }
078    
079      /**
080       * Returns the project.
081       * 
082       * @return The project.
083       */
084      public Project getProject() {
085        return this.project;
086      }
087    
088      /**
089       * Prints the debug log message.
090       * 
091       * @return The debug message.
092       */
093      public String toLabelMessage() {
094        StringBuffer sb = new StringBuffer(1024);
095        sb.append("project: " + this.project.getName() + CR);
096        sb.append("owner " + this.project.getOwner() + CR);
097        SimpleDateFormat labelDateFormat = new SimpleDateFormat("MM/dd/yy", Locale.US);
098        sb.append("life:"
099            + labelDateFormat.format(new Date(Tstamp.makeTimestamp(this.project.getStartTime())
100                .getTime()))
101            + "-"
102            + labelDateFormat
103                .format(new Date(Tstamp.makeTimestamp(this.project.getEndTime()).getTime())) + CR);
104        sb.append("interval:" + labelDateFormat.format(this.startDate) + "-"
105            + labelDateFormat.format(this.endDate) + CR);
106        sb.append("shift " + this.indent + CR);
107        return sb.toString();
108      }
109    
110      /**
111       * Set the indent.
112       * 
113       * @param indent The indent to set.
114       */
115      public void setIndent(Integer indent) {
116        this.indent = indent;
117      }
118    
119      /**
120       * Get the indent.
121       * 
122       * @return The indent for the project interval.
123       */
124      public Integer getIndent() {
125        return this.indent;
126      }
127    
128      /**
129       * Set the start date for this record.
130       * 
131       * @param timeInMillis The time to set.
132       */
133      public void setStartDate(long timeInMillis) {
134        this.startDate = new Date(timeInMillis);
135      }
136    
137      /**
138       * Get the start date for this record.
139       * 
140       * @return The start date for this project.
141       */
142      public Date getStartDate() {
143        return new Date(this.startDate.getTime());
144      }
145    
146      /**
147       * Set the end date for this record.
148       * 
149       * @param timeInMillis The time to set.
150       */
151      public void setEndDate(long timeInMillis) {
152        this.endDate = new Date(timeInMillis);
153      }
154    
155      /**
156       * Get the end date for this record.
157       * 
158       * @return The end date for this project.
159       */
160      public Date getEndDate() {
161        return new Date(this.endDate.getTime());
162      }
163    
164      /**
165       * Set the project.
166       * 
167       * @param project The project to set.
168       */
169      public void setProject(Project project) {
170        this.project = project;
171      }
172    
173      /**
174       * Set the color used for the telemetry trajectory rendering.
175       * 
176       * @param color the color to use.
177       */
178      public void setStreamColor(String color) {
179        this.color = color;
180      }
181    
182      /**
183       * Get the stream color to use.
184       * 
185       * @return the stream color.
186       */
187      public String getStreamColor() {
188        return this.color;
189      }
190    }