public static PrintDocumentFactory getInstance(){
if (instance==null) instance=new PrintDocumentFactory();
return instance;
}
public GraphPageable createDocument(DocumentFrame frame,boolean pdfAsDefault){
BaseView view=frame.getActiveTopView();
SVGRenderer renderer;
NodeModelCache cache;
if (view instanceof GanttView){
renderer=new GanttSVGRenderer();
SpreadSheet sp=frame.getActiveSpreadSheet();
SpreadSheetFieldArray fieldArray=sp.getFieldArrayWithWidths(null);
List<Integer> colWidth=null;
// if (sp!=null){
// fieldArray=(SpreadSheetFieldArray)sp.getFieldArray();
// colWidth=getColWidth(sp, fieldArray);
// }
cache=NodeModelCacheFactory.getInstance().createFilteredCache((ReferenceNodeModelCache)frame.getReferenceCache(true),"OfflineGantt",null);
((GanttSVGRenderer)renderer).init(frame.getProject(),cache,fieldArray,colWidth,frame.getScale(),true);
renderer.getParams().setSupportLeftAndRightParts(true);
}else if (view instanceof ResourceView){
renderer=new GanttSVGRenderer();
SpreadSheet sp=frame.getActiveSpreadSheet();
SpreadSheetFieldArray fieldArray=sp.getFieldArrayWithWidths(null);
List<Integer> colWidth=null;
// if (sp!=null){
// fieldArray=(SpreadSheetFieldArray)sp.getFieldArray();
// colWidth=getColWidth(sp, fieldArray);
// }
cache=NodeModelCacheFactory.getInstance().createFilteredCache((ReferenceNodeModelCache)frame.getReferenceCache(false),"OfflineResources",null);
((GanttSVGRenderer)renderer).init(frame.getProject(),cache,fieldArray,colWidth,frame.getScale(),false);
}else if (view instanceof ProjectView){
renderer=new GanttSVGRenderer();
SpreadSheet sp=frame.getActiveSpreadSheet();
SpreadSheetFieldArray fieldArray=sp.getFieldArrayWithWidths(null);
List<Integer> colWidth=null;
// if (sp!=null){
// fieldArray=(SpreadSheetFieldArray)sp.getFieldArray();
// colWidth=getColWidth(sp, fieldArray);
// }
Portfolio portfolio = frame.getGraphicManager().getProjectFactory().getPortfolio();
cache=NodeModelCacheFactory.getInstance().createDefaultCache(portfolio.getNodeModel(), portfolio,NodeModelCache.PROJECT_TYPE,"OfflineProjects",null);
((GanttSVGRenderer)renderer).init(frame.getProject(),cache,fieldArray,colWidth,frame.getScale(),false);
}else if (view instanceof PertView){
renderer=new NetworkSVGRenderer();
cache=NodeModelCacheFactory.getInstance().createFilteredCache((ReferenceNodeModelCache)frame.getReferenceCache(true),"Network",null);
((NetworkSVGRenderer)renderer).init(frame.getProject(),cache,NetworkSVGRenderer.PERT,frame.getScale());
}else if (view instanceof TreeView){
renderer=new NetworkSVGRenderer();
TreeView treeView=(TreeView)view;
if ("WBS".equals(treeView.getViewName())){
cache=NodeModelCacheFactory.getInstance().createFilteredCache((ReferenceNodeModelCache)frame.getReferenceCache(true),"WBS",null);
((NetworkSVGRenderer)renderer).init(frame.getProject(),cache,NetworkSVGRenderer.WBS,frame.getScale());
}else{
cache=NodeModelCacheFactory.getInstance().createFilteredCache((ReferenceNodeModelCache)frame.getReferenceCache(false),"RBS",null);
((NetworkSVGRenderer)renderer).init(frame.getProject(),cache,NetworkSVGRenderer.RBS,frame.getScale());
}
}else return null;
NodeModelCache srcCache=view.getCache();
ViewTransformer transformer=((NodeCacheTransformer)cache.getVisibleNodes().getTransformer()).getTransformer();
ViewTransformer srcTransformer=((NodeCacheTransformer)srcCache.getVisibleNodes().getTransformer()).getTransformer();
transformer.setUserFilterId(srcTransformer.getUserFilterId()); //this is valid just because the views have the same transformers
transformer.setUserSorterId(srcTransformer.getUserSorterId()); //this is valid just because the views have the same transformers
transformer.setUserGrouperId(srcTransformer.getUserGrouperId()); //this is valid just because the views have the same transformers