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  CPViz Constraint Visualization System
15// The Initial Developer of the Original Code is  Helmut Simonis
16// Portions created by the Initial Developer are
17// Copyright (C) 2009-2010 Helmut Simonis
18//
19// Contributor(s): 	Helmut Simonis, 4C, Univerity College Cork, Cork
20//
21//
22// END LICENSE BLOCK
23// ----------------------------------------------------------------------
24package ie.ucc.cccc.viz;
25
26import java.io.*;
27
28/**
29 * This is a dispatcher for VisualizerDrawer instances. It create
30 * the context to store parameters of the visualizers, and then create the
31 * Drawer subclass instances
32 * @author hsimonis
33 *
34 */
35public class Visualizer {
36	private VisualizerDrawer visualizerDrawer;
37
38	/**
39	 * This constructor must be extended when adding new visualizers.
40	 * This should be considered for replacement when sorting out extension of
41	 * the XML format.
42	 * @param id
43	 * @param type
44	 * @param display
45	 * @param x
46	 * @param y
47	 * @param width
48	 * @param height
49	 * @param group
50	 * @param min
51	 * @param max
52	 */
53	public Visualizer(int id,String type,String display,
54			int x, int y, int width, int height,
55			String group,
56			int min,int max,int indexStart) {
57		VisualContext context = new VisualContext(id,type,display,
58			x, y,width,height,
59			group,
60			min,max,indexStart);
61		if (type.equals("vector")) {
62			visualizerDrawer = new VisualizerVector(context);
63		} else if (type.equals("vector_waterfall")) {
64			visualizerDrawer = new VisualizerVectorWaterfall(context);
65		} else if (type.equals("vector_size")) {
66			visualizerDrawer = new VisualizerVectorSize(context);
67		} else if (type.equals("binary_vector")) {
68			visualizerDrawer = new VisualizerBinaryVector(context);
69		} else if (type.equals("domain_matrix")) {
70			visualizerDrawer = new VisualizerMatrix(context);
71		} else if (type.equals("binary_matrix")) {
72			visualizerDrawer = new VisualizerBinaryMatrix(context);
73		} else if (type.equals("alldifferent")) {
74			visualizerDrawer = new VisualizerAllDifferent(context);
75		} else if (type.equals("bin_packing")) {
76			visualizerDrawer = new VisualizerBinPacking(context);
77		} else if (type.equals("lex_le")) {
78			visualizerDrawer = new VisualizerLexLe(context);
79		} else if (type.equals("lex_lt")) {
80			visualizerDrawer = new VisualizerLexLe(context);
81		} else if (type.equals("inverse")) {
82			visualizerDrawer = new VisualizerInverse(context);
83		} else if (type.equals("element")) {
84			visualizerDrawer = new VisualizerElement(context);
85		} else if (type.equals("bool_channeling")) {
86			visualizerDrawer = new VisualizerBoolChanneling(context);
87		} else if (type.equals("gcc")) {
88			visualizerDrawer = new VisualizerGCC(context);
89		} else if (type.equals("disjoint2")) {
90			visualizerDrawer = new VisualizerDisjoint2D(context);
91		} else if (type.equals("alldifferent_matrix")) {
92			visualizerDrawer = new VisualizerAllDifferentMatrix(context);
93		} else if (type.equals("gcc_matrix")) {
94			visualizerDrawer = new VisualizerGCCMatrix(context);
95		} else if (type.equals("same")) {
96			visualizerDrawer = new VisualizerSame(context);
97			/**
98			 *  We can handle display display variant by calling a different
99			 *  constructor, as for cumulative here, or by handling it inside the
100			 *  visualizer code itself, like for VisualizerMatrix
101			 */
102		} else if (type.equals("cumulative") && display.equals("gantt")) {
103			visualizerDrawer = new VisualizerCumulativeGantt(context);
104		} else if (type.equals("cumulative")) {
105			visualizerDrawer = new VisualizerCumulative(context);
106		} else if (type.equals("cumulative_cost")) {
107			visualizerDrawer = new VisualizerCumulativeCost(context);
108		} else if (type.equals("sequence_total")) {
109			visualizerDrawer = new VisualizerSequenceTotal(context);
110		} else if (type.equals("soft_prec")) {
111			visualizerDrawer = new VisualizerSoftPrec(context);
112		} else {
113			System.out.println("Do not know this visualizer: "+type);
114			visualizerDrawer = new VisualizerUnknown(context,type);
115
116		}
117
118	}
119
120	/**
121	 * Utility method to get the enclosing box when drawing a state
122	 * @return Box
123	 */
124	public Box getBox() {
125		return visualizerDrawer.getBox();
126	}
127
128	/**
129	 * Draw the visualizer for a given VisualizerState.
130	 * @param out file descriptor for SVG output
131	 * @param visualState
132	 */
133	public void draw(PrintWriter out, VisualState visualState) {
134		visualizerDrawer.draw(out,visualState);
135	}
136	public void drawBox(PrintWriter out, VisualState visualState,Colors color) {
137		visualizerDrawer.drawBox(out,visualState,color);
138	}
139	public InvariantType invariant(PrintWriter out, VisualState visualState) {
140		return visualizerDrawer.invariant(out,visualState);
141	}
142}
143