1// BEGIN LICENSE BLOCK 2// Version: CMPL 1.1 3// 4// The contents of this file are subject to the Cisco-style Mozilla Public 5// License Version 1.1 (the "License"); you may not use this file except 6// in compliance with the License. You may obtain a copy of the License 7// at www.eclipse-clp.org/license. 8// 9// Software distributed under the License is distributed on an "AS IS" 10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11// the License for the specific language governing rights and limitations 12// under the License. 13// 14// The Original Code is The ECLiPSe Constraint Logic Programming System. 15// The Initial Developer of the Original Code is Cisco Systems, Inc. 16// Portions created by the Initial Developer are 17// Copyright (C) 2006 Cisco Systems, Inc. All Rights Reserved. 18// 19// Contributor(s): 20// 21// END LICENSE BLOCK 22 23package com.parctechnologies.eclipse.visualisation.viewers; 24 25import java.util.*; 26import com.parctechnologies.eclipse.visualisation.ElementType; 27import com.parctechnologies.eclipse.visualisation.VisClientStateModel; 28import com.parctechnologies.eclipse.visualisation.ViewletFactory; 29import com.parctechnologies.eclipse.visualisation.ViewerFactory; 30import com.parctechnologies.eclipse.visualisation.ViewableType; 31import com.parctechnologies.eclipse.visualisation.Viewer; 32import com.parctechnologies.eclipse.visualisation.Viewable; 33import com.parctechnologies.eclipse.visualisation.Chart2DViewer; 34 35/** 36 * Factory for building 2D Chart Viewers 37 */ 38public class Chart2DViewerFactory implements ViewerFactory 39{ 40 private VisClientStateModel stateModel; 41 private int type; 42 private Class elementTypeClass; 43 44 public Chart2DViewerFactory(VisClientStateModel stateModel, 45 int type, 46 Class elementTypeClass) 47 { 48 this.stateModel = stateModel; 49 this.type = type; 50 this.elementTypeClass = elementTypeClass; 51 } 52 53 /** 54 * Note that both the dimensions and type affect the ability of a 55 * GanttViewer to be built. 56 **/ 57 public boolean canBuildFrom(ViewableType viewableType) 58 { 59 ViewableType.ArrayType arrayType = 60 (ViewableType.ArrayType)viewableType; 61 // Gantt viewers require a 2D array with specific dimensions and 62 // element types 63 if (elementTypeClass.isInstance(arrayType.getElementType())) { 64 return(true); 65 } 66 return(false); 67 } 68 69 public Viewer build(Viewable viewable) 70 { 71 String changeable = null; 72 ViewableType viewableType = viewable.getType(); 73 if (viewableType instanceof ViewableType.ArrayType) { 74 ElementType elementType = 75 ((ViewableType.ArrayType)viewableType).getElementType(); 76 changeable = elementType.getChangeableSolver(); 77 } 78 Collection viewletTypeCollection = new LinkedList(); 79 viewletTypeCollection.add(new ChartBarViewletType(changeable)); 80 Viewer newViewer = 81 new Chart2DViewer(viewletTypeCollection, 82 stateModel, 83 viewable); 84 newViewer.setDescription("2D Chart viewer"); 85 return(newViewer); 86 } 87 88} 89