001: /*--------------------------------------------------------------------------*
002: | Copyright (C) 2006 Christopher Kohlhaas |
003: | |
004: | This program is free software; you can redistribute it and/or modify |
005: | it under the terms of the GNU General Public License as published by the |
006: | Free Software Foundation. A copy of the license has been included with |
007: | these distribution in the COPYING file, if not go to www.fsf.org |
008: | |
009: | As a special exception, you are granted the permissions to link this |
010: | program with every library, which license fulfills the Open Source |
011: | Definition as published by the Open Source Initiative (OSI). |
012: *--------------------------------------------------------------------------*/
013: package org.rapla.gui;
014:
015: import java.util.HashSet;
016: import java.util.Set;
017: import java.util.StringTokenizer;
018:
019: import org.apache.avalon.framework.configuration.Configuration;
020: import org.rapla.framework.RaplaException;
021:
022: /** <strong>WARNING!!</strong> This class should not be public to the outside. Please use the interface */
023: public class CalendarOptionsImpl implements CalendarOptions {
024: public final static String CALENDAR_OPTIONS = "org.rapla.calendarview";
025:
026: public static final String WORKTIME = "worktime";
027: public static final String EXCLUDE_DAYS = "exclude-days";
028: public static final String ROWS_PER_HOUR = "rows-per-hour";
029: public final static String EXCEPTIONS_VISIBLE = "exceptions-visible";
030: public final static String COMPACT_COLUMNS = "compact-columns";
031: public final static String COLOR_BLOCKS = "color";
032:
033: public final static String COLOR_RESOURCES = "resources";
034: public final static String COLOR_EVENTS = "reservations";
035:
036: public final int MAX_INTERVALLS = 10000;
037:
038: Set excludeDays = new HashSet();
039:
040: int maxtime = -1;
041: int mintime = -1;
042: int rowsPerHour = 4;
043: boolean exceptionsVisible;
044: boolean compactColumns = false;
045: Configuration config;
046: String colorField;
047:
048: public CalendarOptionsImpl(Configuration config)
049: throws RaplaException {
050: this .config = config;
051: Configuration worktime = config.getChild(WORKTIME);
052: StringTokenizer tokenizer = new StringTokenizer(worktime
053: .getValue("8-18"), "-");
054: try {
055: if (tokenizer.hasMoreTokens())
056: mintime = new Integer(tokenizer.nextToken()
057: .toLowerCase().trim()).intValue();
058: if (tokenizer.hasMoreTokens())
059: maxtime = new Integer(tokenizer.nextToken()
060: .toLowerCase().trim()).intValue();
061: } catch (NumberFormatException e) {
062: throw new RaplaException("Invalid time in "
063: + worktime.getLocation()
064: + ". only numbers are allowed e.g. 8-18!");
065: }
066: if (mintime == -1 || maxtime == -1 /*|| mintime >= maxtime*/)
067: throw new RaplaException("Invalid intervall in "
068: + worktime.getLocation()
069: + ". Use the following format 8-16 !");
070:
071: Configuration exclude = config.getChild(EXCLUDE_DAYS);
072: tokenizer = new StringTokenizer(exclude.getValue(""), ",");
073: while (tokenizer.hasMoreTokens()) {
074: String token = tokenizer.nextToken().toLowerCase().trim();
075: try {
076: excludeDays.add(new Integer(token));
077: } catch (NumberFormatException e) {
078: throw new RaplaException("Invalid day in "
079: + exclude.getLocation()
080: + ". only numbers are allowed!");
081: }
082: } // end of while ()
083:
084: rowsPerHour = config.getChild(ROWS_PER_HOUR).getValueAsInteger(
085: 4);
086: exceptionsVisible = config.getChild(EXCEPTIONS_VISIBLE)
087: .getValueAsBoolean(false);
088:
089: colorField = config.getChild(COLOR_BLOCKS).getValue(
090: COLOR_RESOURCES);
091: }
092:
093: public Configuration getConfig() {
094: return config;
095: }
096:
097: public int getWorktimeStart() {
098: return mintime;
099: }
100:
101: public int getRowsPerHour() {
102: return rowsPerHour;
103: }
104:
105: public int getWorktimeEnd() {
106: return maxtime;
107: }
108:
109: public Set getExcludeDays() {
110: return excludeDays;
111: }
112:
113: public boolean isExceptionsVisible() {
114: return exceptionsVisible;
115: }
116:
117: public boolean isCompactColumns() {
118: return compactColumns;
119: }
120:
121: public boolean isResourceColoring() {
122: return colorField.equals(COLOR_RESOURCES);
123: }
124:
125: public boolean isEventColoring() {
126: return colorField.equals(COLOR_EVENTS);
127: }
128:
129: }
|