001: /*
002: The contents of this file are subject to the Common Public Attribution License
003: Version 1.0 (the "License"); you may not use this file except in compliance with
004: the License. You may obtain a copy of the License at
005: http://www.projity.com/license . The License is based on the Mozilla Public
006: License Version 1.1 but Sections 14 and 15 have been added to cover use of
007: software over a computer network and provide for limited attribution for the
008: Original Developer. In addition, Exhibit A has been modified to be consistent
009: with Exhibit B.
010:
011: Software distributed under the License is distributed on an "AS IS" basis,
012: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
013: specific language governing rights and limitations under the License. The
014: Original Code is OpenProj. The Original Developer is the Initial Developer and
015: is Projity, Inc. All portions of the code written by Projity are Copyright (c)
016: 2006, 2007. All Rights Reserved. Contributors Projity, Inc.
017:
018: Alternatively, the contents of this file may be used under the terms of the
019: Projity End-User License Agreeement (the Projity License), in which case the
020: provisions of the Projity License are applicable instead of those above. If you
021: wish to allow use of your version of this file only under the terms of the
022: Projity License and not to allow others to use your version of this file under
023: the CPAL, indicate your decision by deleting the provisions above and replace
024: them with the notice and other provisions required by the Projity License. If
025: you do not delete the provisions above, a recipient may use your version of this
026: file under either the CPAL or the Projity License.
027:
028: [NOTE: The text of this license may differ slightly from the text of the notices
029: in Exhibits A and B of the license at http://www.projity.com/license. You should
030: use the latest text at http://www.projity.com/license for your modifications.
031: You may not remove this license text from the source files.]
032:
033: Attribution Information: Attribution Copyright Notice: Copyright © 2006, 2007
034: Projity, Inc. Attribution Phrase (not exceeding 10 words): Powered by OpenProj,
035: an open source solution from Projity. Attribution URL: http://www.projity.com
036: Graphic Image as provided in the Covered Code as file: openproj_logo.png with
037: alternatives listed on http://www.projity.com/logo
038:
039: Display of Attribution Information is required in Larger Works which are defined
040: in the CPAL as a work which combines Covered Code or portions thereof with code
041: not governed by the terms of the CPAL. However, in addition to the other notice
042: obligations, all copies of the Covered Code in Executable and Source Code form
043: distributed must, as a form of attribution of the original author, include on
044: each user interface screen the "OpenProj" logo visible to all users. The
045: OpenProj logo should be located horizontally aligned with the menu bar and left
046: justified on the top left of the screen adjacent to the File menu. The logo
047: must be at least 100 x 25 pixels. When users click on the "OpenProj" logo it
048: must direct them back to http://www.projity.com.
049: */
050: package com.projity.options;
051:
052: import java.util.GregorianCalendar;
053:
054: import com.projity.datatype.Duration;
055: import com.projity.pm.calendar.WorkCalendar;
056: import com.projity.util.DateTime;
057:
058: /**
059: *
060: */
061: public class CalendarOption {
062: private static CalendarOption instance = null;
063: private static CalendarOption defaultInstance = null;
064:
065: public final boolean isAddedCalendarTimeIsNonStop() {
066: return addedCalendarTimeIsNonStop;
067: }
068:
069: public final void setAddedCalendarTimeIsNonStop(
070: boolean addedCalendarTimeIsNonStop) {
071: this .addedCalendarTimeIsNonStop = addedCalendarTimeIsNonStop;
072: }
073:
074: public static CalendarOption getInstance() {
075: if (instance == null)
076: instance = new CalendarOption();
077: return instance;
078: }
079:
080: public static CalendarOption getDefaultInstance() {
081: if (defaultInstance == null)
082: defaultInstance = new CalendarOption();
083: return defaultInstance;
084: }
085:
086: // allow setting of options so that default options can be toggled on and off for import export
087: public static final void setInstance(CalendarOption instance) {
088: CalendarOption.instance = instance;
089: }
090:
091: private CalendarOption() {
092: // note that the mpxj library uses the default values when importing or exporting
093: defaultStartTime.set(GregorianCalendar.HOUR_OF_DAY,
094: defaultStartHour);
095: defaultStartTime.set(GregorianCalendar.MINUTE, 0);
096: defaultStartTime.set(GregorianCalendar.SECOND, 0);
097: defaultStartTime.set(GregorianCalendar.MILLISECOND, 0);
098: defaultEndTime.set(GregorianCalendar.HOUR_OF_DAY,
099: defaultEndHour);
100: defaultEndTime.set(GregorianCalendar.MINUTE, 0);
101: defaultEndTime.set(GregorianCalendar.SECOND, 0);
102: defaultEndTime.set(GregorianCalendar.MILLISECOND, 0);
103:
104: }
105:
106: int weekStartsOn = GregorianCalendar.SUNDAY;
107: int fiscalYearStartsIn = GregorianCalendar.JANUARY;
108: int defaultStartHour = 8;
109: int defaultEndHour = 17;
110:
111: GregorianCalendar defaultStartTime = DateTime.calendarInstance();
112: GregorianCalendar defaultEndTime = DateTime.calendarInstance();
113: double hoursPerDay = 8.0D;
114: double hoursPerWeek = 40.0D;
115: double daysPerMonth = 20.0D;
116:
117: public double getFractionOfDayThatIsWorking() {
118: return hoursPerDay / 24.0;
119: }
120:
121: long defaultDuration = Duration.setAsEstimated(
122: (long) (WorkCalendar.MILLIS_IN_HOUR * hoursPerDay), true);
123: // when typing values on a non work day, the day is added to the assignment calendar. If it is non stop, then a 24 hour exception
124: // is used (MSP does this). If false, a default day is used. The MSP behaviour is the default. I don't think it is all that logical
125: // so i provide the option to use a default day instead
126:
127: boolean addedCalendarTimeIsNonStop = false;
128:
129: /**
130: * @return Returns the daysPerMonth.
131: */
132: public double getDaysPerMonth() {
133: return daysPerMonth;
134: }
135:
136: /**
137: * @param daysPerMonth The daysPerMonth to set.
138: */
139: public void setDaysPerMonth(double daysPerMonth) {
140: this .daysPerMonth = daysPerMonth;
141: }
142:
143: public long getMillisPerDay() {
144: return (long) (WorkCalendar.MILLIS_IN_HOUR * hoursPerDay);
145: }
146:
147: /**
148: * @return Returns the fiscalYearStartsIn.
149: */
150: public int getFiscalYearStartsIn() {
151: return fiscalYearStartsIn;
152: }
153:
154: /**
155: * @param fiscalYearStartsIn The fiscalYearStartsIn to set.
156: */
157: public void setFiscalYearStartsIn(int fiscalYearStartsIn) {
158: this .fiscalYearStartsIn = fiscalYearStartsIn;
159: }
160:
161: /**
162: * @return Returns the hoursPerDay.
163: */
164: public double getHoursPerDay() {
165: return hoursPerDay;
166: }
167:
168: /**
169: * @param hoursPerDay The hoursPerDay to set.
170: */
171: public void setHoursPerDay(double hoursPerDay) {
172: this .hoursPerDay = hoursPerDay;
173: defaultDuration = Duration.setAsEstimated(
174: (long) (WorkCalendar.MILLIS_IN_HOUR * hoursPerDay),
175: true);
176:
177: }
178:
179: /**
180: * @return Returns the hoursPerWeek.
181: */
182: public double getHoursPerWeek() {
183: return hoursPerWeek;
184: }
185:
186: /**
187: * @param hoursPerWeek The hoursPerWeek to set.
188: */
189: public void setHoursPerWeek(double hoursPerWeek) {
190: this .hoursPerWeek = hoursPerWeek;
191: }
192:
193: /**
194: * @return Returns the weekStartsOn.
195: */
196: public int getWeekStartsOn() {
197: return weekStartsOn;
198: }
199:
200: /**
201: * @param weekStartsOn The weekStartsOn to set.
202: */
203: public void setWeekStartsOn(int weekStartsOn) {
204: this .weekStartsOn = weekStartsOn;
205: }
206:
207: public double hoursPerMonth() {
208: return hoursPerDay * daysPerMonth;
209: }
210:
211: /**
212: * @return Returns the defaultEndTime.
213: */
214: public GregorianCalendar getDefaultEndTime() {
215: return defaultEndTime;
216: }
217:
218: /**
219: * @param defaultEndTime The defaultEndTime to set.
220: */
221: public void setDefaultEndTime(GregorianCalendar defaultEndTime) {
222: this .defaultEndTime = defaultEndTime;
223: }
224:
225: /**
226: * @return Returns the defaultStartTime.
227: */
228: public GregorianCalendar getDefaultStartTime() {
229: return defaultStartTime;
230: }
231:
232: /**
233: * @param defaultStartTime The defaultStartTime to set.
234: */
235: public void setDefaultStartTime(GregorianCalendar defaultStartTime) {
236: this .defaultStartTime = defaultStartTime;
237: }
238:
239: public long makeValidStart(long start, boolean force) {
240:
241: start = DateTime.minuteFloor(start);
242: GregorianCalendar cal = DateTime.calendarInstance();
243: cal.setTimeInMillis(start);
244: int year = cal.get(GregorianCalendar.YEAR);
245: int dayOfYear = cal.get(GregorianCalendar.DAY_OF_YEAR);
246: if (force || cal.get(GregorianCalendar.HOUR_OF_DAY) == 0
247: && cal.get(GregorianCalendar.MINUTE) == 0) {
248: cal.set(GregorianCalendar.HOUR_OF_DAY,
249: getDefaultStartTime().get(
250: GregorianCalendar.HOUR_OF_DAY));
251: cal.set(GregorianCalendar.MINUTE, getDefaultStartTime()
252: .get(GregorianCalendar.MINUTE));
253: cal.set(GregorianCalendar.YEAR, year);
254: cal.set(GregorianCalendar.DAY_OF_YEAR, dayOfYear);
255: }
256: return cal.getTimeInMillis();
257: }
258:
259: public long makeValidEnd(long end, boolean force) {
260: end = DateTime.minuteFloor(end);
261: GregorianCalendar cal = DateTime.calendarInstance();
262: cal.setTimeInMillis(end);
263: if (force || cal.get(GregorianCalendar.HOUR_OF_DAY) == 0
264: && cal.get(GregorianCalendar.MINUTE) == 0) {
265: cal.set(GregorianCalendar.HOUR_OF_DAY, getDefaultEndTime()
266: .get(GregorianCalendar.HOUR_OF_DAY));
267: cal.set(GregorianCalendar.MINUTE, getDefaultEndTime().get(
268: GregorianCalendar.MINUTE));
269: }
270: return cal.getTimeInMillis();
271: }
272:
273: /**
274: * @return Returns the defaultDuration.
275: */
276: public long getDefaultDuration() {
277: return defaultDuration;
278: }
279:
280: /**
281: * @param defaultDuration The defaultDuration to set.
282: */
283: public void setDefaultDuration(long defaultDuration) {
284: this .defaultDuration = defaultDuration;
285: }
286:
287: public final int getDefaultEndHour() {
288: return defaultEndHour;
289: }
290:
291: public final void setDefaultEndHour(int defaultEndHour) {
292: this .defaultEndHour = defaultEndHour;
293: }
294:
295: public final int getDefaultStartHour() {
296: return defaultStartHour;
297: }
298:
299: public final void setDefaultStartHour(int defaultStartHour) {
300: this.defaultStartHour = defaultStartHour;
301: }
302: }
|