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.graphic.configuration;
051:
052: import java.util.ArrayList;
053: import java.util.Iterator;
054: import java.util.StringTokenizer;
055:
056: import org.apache.commons.collections.Closure;
057: import org.apache.commons.digester.Digester;
058:
059: import com.projity.configuration.NamedItem;
060: import com.projity.strings.Messages;
061:
062: /**
063: * Styles of bars on the gantt chart. Holds a collection of bar formats.
064: */
065: public class BarStyles implements NamedItem {
066: // static Log log = LogFactory.getLog(BarStyles.class);
067: public static final String category = "BarStylesCategory";
068:
069: public String getCategory() {
070: return category;
071: }
072:
073: String name = null;
074: String id = null;
075: ArrayList rows = new ArrayList();
076:
077: public BarStyles() {
078: }
079:
080: /**
081: * Applies a closure to all bars which should be displayed. The renderer is called back
082: * with the BarFormat to apply for bars which meet their display conditions.
083: * @param ganttable - A task, resource, assignment... whatever can be displayed in gantt
084: * @param action - Callback - The callback parametes are BarFormats
085: */
086: public void apply(Object ganttable, Closure action) {
087: apply(ganttable, action, false, false, false);
088: }
089:
090: public void apply(Object ganttable, Closure action, boolean link,
091: boolean annotation, boolean calendar) {
092: Iterator i = rows.iterator();
093: BarStyle row;
094: while (i.hasNext()) {
095: row = (BarStyle) i.next();
096: if (row.isLink() == link
097: && row.isAnnotation() == annotation
098: && row.isCalendar() == calendar
099: && row.evaluate(ganttable)) { // see if meets filter
100: action.execute(row.getBarFormat());
101: }
102: }
103: }
104:
105: public void addStyle(BarStyle style) {
106: style.setBelongsTo(this );
107: style.build(); // set references
108: rows.add(style);
109: }
110:
111: /**
112: * @return Returns the name.
113: */
114: public String getName() {
115: return name;
116: }
117:
118: /**
119: * @param name The name to set.
120: */
121: public void setName(String name) {
122: this .name = name;
123: }
124:
125: public void setId(String id) {
126: this .id = id;
127: setName(Messages.getString(id));
128: }
129:
130: /**
131: * @return Returns the id.
132: */
133: public String getId() {
134: return id;
135: }
136:
137: /**
138: * @return Returns the rows.
139: */
140: public ArrayList getRows() {
141: return rows;
142: }
143:
144: String zoomX = null;
145:
146: public String getZoomX() {
147: return zoomX;
148: }
149:
150: public void setZoomX(String zoomX) {
151: this .zoomX = zoomX;
152: }
153:
154: String zoomY = null;
155:
156: public String getZoomY() {
157: return zoomY;
158: }
159:
160: public void setZoomY(String zoomY) {
161: this .zoomY = zoomY;
162: }
163:
164: double[] zoomRatioX = null;
165: int defaultZoomIndexX;
166:
167: public double getRatioX(int zoom, boolean in) {
168: initZoomX();
169: if (zoomX == null)
170: return 1.0;
171: int index = defaultZoomIndexX + zoom - ((in) ? 0 : 1);
172: if (index < 0 || index >= zoomRatioX.length)
173: return 1.0;
174: return (in) ? zoomRatioX[index] : 1.0 / zoomRatioX[index];
175: }
176:
177: protected void initZoomX() {
178: if (zoomRatioX == null) {
179: if (zoomX == null)
180: return;
181: StringTokenizer st = new StringTokenizer(zoomX, ",;:|");
182: zoomRatioX = new double[st.countTokens()];
183: int index = 0;
184: while (st.hasMoreTokens()) {
185: String s = st.nextToken();
186: if ("*".equals(s))
187: defaultZoomIndexX = index;
188: else
189: zoomRatioX[index++] = Double.parseDouble(s);
190: }
191: }
192: }
193:
194: double[] zoomRatioY = null;
195: int defaultZoomIndexY;
196:
197: public double getRatioY(int zoom, boolean in) {
198: initZoomY();
199: if (zoomY == null)
200: return 1.0;
201: int index = defaultZoomIndexY + zoom - ((in) ? 0 : 1);
202: if (index < 0 || index >= zoomRatioY.length)
203: return 1.0;
204: return (in) ? zoomRatioY[index] : 1.0 / zoomRatioY[index];
205: }
206:
207: protected void initZoomY() {
208: if (zoomRatioY == null) {
209: if (zoomY == null)
210: return;
211: StringTokenizer st = new StringTokenizer(zoomY, ",;:|");
212: zoomRatioY = new double[st.countTokens()];
213: int index = 0;
214: while (st.hasMoreTokens()) {
215: String s = st.nextToken();
216: if ("*".equals(s))
217: defaultZoomIndexY = index;
218: else
219: zoomRatioY[index++] = Double.parseDouble(s);
220: }
221: }
222: }
223:
224: public int getMinZoom() {
225: initZoomX();
226: initZoomY();
227: if (zoomRatioX == null || zoomRatioY == null)
228: return 0;
229: return Math.min(-defaultZoomIndexX, -defaultZoomIndexY);
230: }
231:
232: public int getMaxZoom() {
233: initZoomX();
234: initZoomY();
235: if (zoomRatioX == null || zoomRatioY == null)
236: return 0;
237: return Math.min(zoomRatioX.length - defaultZoomIndexX - 1,
238: zoomRatioY.length - defaultZoomIndexY - 1);
239: }
240:
241: public static void addDigesterEvents(Digester digester) {
242: // main properties of bar
243: digester.addFactoryCreate("*/bar/styles",
244: "com.projity.graphic.configuration.BarStylesFactory");
245: digester.addSetProperties("*/bar/styles");
246: digester.addSetNext("*/bar/styles", "add",
247: "com.projity.configuration.NamedItem");
248:
249: // start section
250: digester.addObjectCreate("*/bar/styles/style",
251: "com.projity.graphic.configuration.BarStyle");
252: digester.addSetProperties("*/bar/styles/style");
253: digester.addSetNext("*/bar/styles/style", "addStyle",
254: "com.projity.graphic.configuration.BarStyle");
255:
256: }
257: }
|