Source code: com/vinculum/processeditor/model/ProcessElementFactory.java
1 /* * ** ** BEGIN LICENSE BLOCK * ** **
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is Vinculum Open Source.
15 *
16 * The Initial Developer of the Original Code is
17 * Gerard Toonstra.
18 * Portions created by the Initial Developer are Copyright (C) 2003
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 *
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
34 *
35 * ** ** * END LICENSE BLOCK * ** **
36 */
37
38 /***************************************************************************
39 $RCSfile: ProcessElementFactory.java,v $ - description
40 -------------------
41 begin : $Date: 2003/07/08 08:02:20 $
42 copyright : Vinculum (C) 2002
43 author : $Author: chiraz $
44 ***************************************************************************/
45
46 /* $Log: ProcessElementFactory.java,v $
47 /* Revision 1.1.1.1 2003/07/08 08:02:20 chiraz
48 /* egg
49 /* */
50
51 package com.vinculum.processeditor.model;
52
53 import org.eclipse.gef.requests.CreationFactory;
54
55 import com.vinculum.processeditor.TemplateConstants;
56
57 /**
58 * @author chilan
59 *
60 */
61 public class ProcessElementFactory implements CreationFactory
62 {
63 private String template;
64
65 public ProcessElementFactory(String str)
66 {
67 template = str;
68 }
69
70 protected void connect(ProcessSubPart part1, String conn1, ProcessSubPart part2, String conn2)
71 {
72 Wire wire = new Wire();
73 wire.setSource(part1);
74 wire.setSourceTerminal(conn1);
75 wire.setTarget(part2);
76 wire.setTargetTerminal(conn2);
77 wire.attachSource();
78 wire.attachTarget();
79 }
80
81 /*public Circuit createFullAdder()
82 {
83 final Gate or;
84 final Circuit circuit, circuit1, circuit2;
85
86 circuit1 = createHalfAdder();
87 circuit2 = createHalfAdder();
88 circuit1.setLocation(new Point(2,10));
89 circuit2.setLocation(new Point(38,90));
90
91 circuit= new Circuit();
92 circuit.setSize(new Dimension (120,216));
93 or = new OrGate();
94 or.setLocation(new Point(22,162));
95
96 circuit.addChild(circuit1);
97 circuit.addChild(circuit2);
98
99 connect(circuit, Circuit.TERMINALS_OUT[0], circuit1, Circuit.TERMINALS_IN[0]);
100 connect(circuit, Circuit.TERMINALS_OUT[2], circuit1, Circuit.TERMINALS_IN[3]);
101 connect(circuit, Circuit.TERMINALS_OUT[3], circuit2, Circuit.TERMINALS_IN[3]);
102 connect(circuit1,Circuit.TERMINALS_OUT[7],circuit2, Circuit.TERMINALS_IN[0]);
103
104 circuit.addChild(or);
105 connect(or, SimpleOutput.TERMINAL_OUT, circuit, Circuit.TERMINALS_IN[4]);
106 connect(circuit1, Circuit.TERMINALS_OUT[4], or, Gate.TERMINAL_A);
107 connect(circuit2, Circuit.TERMINALS_OUT[4], or, Gate.TERMINAL_B);
108 connect(circuit2, Circuit.TERMINALS_OUT[7], circuit, Circuit.TERMINALS_IN[7]);
109
110 return circuit;
111 }
112
113 public Circuit createHalfAdder() {
114 Gate and, xor;
115 Circuit circuit;
116
117 circuit = new Circuit();
118 circuit.setSize(new Dimension(60,70));
119 and = new AndGate();
120 and.setLocation(new Point(2,12));
121 xor = new XORGate();
122 xor.setLocation(new Point(22,12));
123
124 circuit.addChild(xor);
125 circuit.addChild(and);
126
127 connect(circuit, Circuit.TERMINALS_OUT[0], and, Gate.TERMINAL_A);
128 connect(circuit, Circuit.TERMINALS_OUT[3], and, Gate.TERMINAL_B);
129 connect(circuit, Circuit.TERMINALS_OUT[0], xor, Gate.TERMINAL_A);
130 connect(circuit, Circuit.TERMINALS_OUT[3], xor, Gate.TERMINAL_B);
131
132 connect(and, SimpleOutput.TERMINAL_OUT, circuit, Circuit.TERMINALS_IN[4]);
133 connect(xor, SimpleOutput.TERMINAL_OUT, circuit, Circuit.TERMINALS_IN[7]);
134 return circuit;
135 }
136 */
137 public Object getNewObject()
138 {
139 if (TemplateConstants.TEMPLATE_START_FLOW.equals(template))
140 return new ProcessFlowStart();
141 if (TemplateConstants.TEMPLATE_TRANSITION.equals(template))
142 return new ProcessTransition();
143 if (TemplateConstants.TEMPLATE_END_FLOW.equals(template))
144 return new ProcessFlowEnd();
145 if (TemplateConstants.TEMPLATE_LABEL.equals(template))
146 return new ProcessLabel();
147 if (TemplateConstants.TEMPLATE_JSP.equals(template))
148 return new ProcessJSP();
149
150 /*
151 if (TemplateConstants.TEMPLATE_AND_GATE.equals(template))
152 return new AndGate();
153 if (TemplateConstants.TEMPLATE_CIRCUIT.equals(template))
154 return new Circuit();
155 if (TemplateConstants.TEMPLATE_FLOW_CONTAINER.equals(template))
156 return new LogicFlowContainer();
157 if (TemplateConstants.TEMPLATE_FULL_ADDER.equals(template))
158 return createFullAdder();
159 if (TemplateConstants.TEMPLATE_GROUND.equals(template))
160 return new GroundOutput();
161 if (TemplateConstants.TEMPLATE_HALF_ADDER.equals(template))
162 return createHalfAdder();
163 if (TemplateConstants.TEMPLATE_LED.equals(template))
164 return new LED();
165 if (TemplateConstants.TEMPLATE_LIVE_OUTPUT.equals(template))
166 return new LiveOutput();
167 if (TemplateConstants.TEMPLATE_LOGIC_LABEL.equals(template))
168 return new LogicLabel();
169 if (TemplateConstants.TEMPLATE_OR_GATE.equals(template))
170 return new OrGate();
171 if (TemplateConstants.TEMPLATE_XOR_GATE.equals(template))
172 return new XORGate();
173 */
174 return null;
175 }
176
177 public Object getObjectType()
178 {
179 return template;
180 }
181 }