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.print;
051:
052: import java.awt.print.PrinterJob;
053: import java.util.ArrayList;
054: import java.util.List;
055:
056: import javax.swing.table.TableColumn;
057: import javax.swing.table.TableColumnModel;
058:
059: import com.projity.graphic.configuration.SpreadSheetFieldArray;
060: import com.projity.grouping.core.transform.ViewTransformer;
061: import com.projity.offline_graphics.GanttSVGRenderer;
062: import com.projity.offline_graphics.NetworkSVGRenderer;
063: import com.projity.offline_graphics.SVGRenderer;
064: import com.projity.pm.graphic.frames.DocumentFrame;
065: import com.projity.pm.graphic.model.cache.NodeModelCache;
066: import com.projity.pm.graphic.model.cache.NodeModelCacheFactory;
067: import com.projity.pm.graphic.model.cache.ReferenceNodeModelCache;
068: import com.projity.pm.graphic.model.transform.NodeCacheTransformer;
069: import com.projity.pm.graphic.spreadsheet.SpreadSheet;
070: import com.projity.pm.graphic.views.BaseView;
071: import com.projity.pm.graphic.views.GanttView;
072: import com.projity.pm.graphic.views.PertView;
073: import com.projity.pm.graphic.views.ProjectView;
074: import com.projity.pm.graphic.views.ResourceView;
075: import com.projity.pm.graphic.views.TreeView;
076: import com.projity.pm.task.Portfolio;
077:
078: public class PrintDocumentFactory {
079: protected static PrintDocumentFactory instance;
080:
081: public static PrintDocumentFactory getInstance() {
082: if (instance == null)
083: instance = new PrintDocumentFactory();
084: return instance;
085: }
086:
087: public GraphPageable createDocument(DocumentFrame frame) {
088: BaseView view = frame.getActiveTopView();
089: SVGRenderer renderer;
090: NodeModelCache cache;
091: if (view instanceof GanttView) {
092: renderer = new GanttSVGRenderer();
093: SpreadSheet sp = frame.getActiveSpreadSheet();
094: SpreadSheetFieldArray fieldArray = null;
095: List<Integer> colWidth = null;
096: if (sp != null) {
097: fieldArray = (SpreadSheetFieldArray) sp.getFieldArray();
098: colWidth = getColWidth(sp, fieldArray);
099: }
100: cache = NodeModelCacheFactory.getInstance()
101: .createFilteredCache(
102: (ReferenceNodeModelCache) frame
103: .getReferenceCache(true),
104: "OfflineGantt", null);
105: ((GanttSVGRenderer) renderer)
106: .init(frame.getProject(), cache, fieldArray,
107: colWidth, frame.getScale(), true);
108: renderer.getParams().setSupportLeftAndRightParts(true);
109: } else if (view instanceof ResourceView) {
110: renderer = new GanttSVGRenderer();
111: SpreadSheet sp = frame.getActiveSpreadSheet();
112: SpreadSheetFieldArray fieldArray = null;
113: List<Integer> colWidth = null;
114: if (sp != null) {
115: fieldArray = (SpreadSheetFieldArray) sp.getFieldArray();
116: colWidth = getColWidth(sp, fieldArray);
117: }
118: cache = NodeModelCacheFactory.getInstance()
119: .createFilteredCache(
120: (ReferenceNodeModelCache) frame
121: .getReferenceCache(false),
122: "OfflineResources", null);
123: ((GanttSVGRenderer) renderer).init(frame.getProject(),
124: cache, fieldArray, colWidth, frame.getScale(),
125: false);
126: } else if (view instanceof ProjectView) {
127: renderer = new GanttSVGRenderer();
128: SpreadSheet sp = frame.getActiveSpreadSheet();
129: SpreadSheetFieldArray fieldArray = null;
130: List<Integer> colWidth = null;
131: if (sp != null) {
132: fieldArray = (SpreadSheetFieldArray) sp.getFieldArray();
133: colWidth = getColWidth(sp, fieldArray);
134: }
135: Portfolio portfolio = frame.getGraphicManager()
136: .getProjectFactory().getPortfolio();
137: cache = NodeModelCacheFactory.getInstance()
138: .createDefaultCache(portfolio.getNodeModel(),
139: portfolio, NodeModelCache.PROJECT_TYPE,
140: "OfflineProjects", null);
141: ((GanttSVGRenderer) renderer).init(frame.getProject(),
142: cache, fieldArray, colWidth, frame.getScale(),
143: false);
144: } else if (view instanceof PertView) {
145: renderer = new NetworkSVGRenderer();
146: cache = NodeModelCacheFactory.getInstance()
147: .createFilteredCache(
148: (ReferenceNodeModelCache) frame
149: .getReferenceCache(true),
150: "Network", null);
151: ((NetworkSVGRenderer) renderer).init(frame.getProject(),
152: cache, NetworkSVGRenderer.PERT, frame.getScale());
153: } else if (view instanceof TreeView) {
154: renderer = new NetworkSVGRenderer();
155: TreeView treeView = (TreeView) view;
156: if ("WBS".equals(treeView.getViewName())) {
157: cache = NodeModelCacheFactory.getInstance()
158: .createFilteredCache(
159: (ReferenceNodeModelCache) frame
160: .getReferenceCache(true),
161: "WBS", null);
162: ((NetworkSVGRenderer) renderer).init(
163: frame.getProject(), cache,
164: NetworkSVGRenderer.WBS, frame.getScale());
165: } else {
166: cache = NodeModelCacheFactory.getInstance()
167: .createFilteredCache(
168: (ReferenceNodeModelCache) frame
169: .getReferenceCache(false),
170: "RBS", null);
171: ((NetworkSVGRenderer) renderer).init(
172: frame.getProject(), cache,
173: NetworkSVGRenderer.RBS, frame.getScale());
174: }
175: } else
176: return null;
177: NodeModelCache srcCache = view.getCache();
178: ViewTransformer transformer = ((NodeCacheTransformer) cache
179: .getVisibleNodes().getTransformer()).getTransformer();
180: ViewTransformer srcTransformer = ((NodeCacheTransformer) srcCache
181: .getVisibleNodes().getTransformer()).getTransformer();
182: transformer.setUserFilterId(srcTransformer.getUserFilterId()); //this is valid just because the views have the same transformers
183: transformer.setUserSorterId(srcTransformer.getUserSorterId()); //this is valid just because the views have the same transformers
184: transformer.setUserGrouperId(srcTransformer.getUserGrouperId()); //this is valid just because the views have the same transformers
185: GraphPageable document = new GraphPageable(PrinterJob
186: .getPrinterJob(), renderer);
187: return document;
188: }
189:
190: private List<Integer> getColWidth(SpreadSheet sp,
191: SpreadSheetFieldArray fieldArray) {
192: List<Integer> colWidth = new ArrayList<Integer>(fieldArray
193: .size());
194: colWidth.add(sp.getRowHeader().getColumnModel().getColumn(0)
195: .getWidth());
196: TableColumnModel columnModel = sp.getColumnModel();
197: TableColumn tc;
198: for (int i = 0; i < columnModel.getColumnCount(); i++) {
199: tc = columnModel.getColumn(i);
200: colWidth.add(tc.getWidth());
201: }
202: return colWidth;
203: }
204: }
|