1
- /**
2
- * Copyright (c) 2006-2010 MoVe - Laboratoire d'Informatique de Paris 6 (LIP6).
3
- * All rights reserved. This program and the accompanying materials
4
- * are made available under the terms of the Eclipse Public License v1.0
5
- * which accompanies this distribution, and is available at
6
- * http://www.eclipse.org/legal/epl-v10.html
7
- *
8
- * Contributors:
9
- * Jean-Baptiste VORON (LIP6) - Project Head / Initial contributor
10
- * Clément DÉMOULINS (LIP6) - Project Manager
11
- * Yann THIERRY-MIEG (LIP6)
12
- *
13
- * Official contacts:
14
- * coloane@lip6.fr
15
- * http://coloane.lip6.fr
16
- */
17
- package fr .lip6 .move .coloane .projects .its .io ;
1
+ package fr .lip6 .move .coloane .extension .importExportRomeo .importFromRomeo ;
18
2
19
- import fr .lip6 .move .coloane .projects .its .CompositeTypeDeclaration ;
20
- import fr .lip6 .move .coloane .projects .its .Concept ;
21
- import fr .lip6 .move .coloane .projects .its .ITypeDeclaration ;
22
- import fr .lip6 .move .coloane .projects .its .TypeDeclaration ;
23
- import fr .lip6 .move .coloane .projects .its .TypeDeclarationFactory ;
24
- import fr .lip6 .move .coloane .projects .its .TypeList ;
25
- import fr .lip6 .move .coloane .projects .its .checks .CheckList ;
26
- import fr .lip6 .move .coloane .projects .its .expression .IEvaluationContext ;
27
- import fr .lip6 .move .coloane .projects .its .expression .IVariable ;
28
- import fr .lip6 .move .coloane .projects .its .expression .Variable ;
29
-
30
- import java .io .File ;
31
- import java .io .IOException ;
32
- import java .net .URI ;
33
- import java .util .ArrayDeque ;
34
- import java .util .Deque ;
3
+ import java .util .ArrayList ;
35
4
import java .util .HashMap ;
5
+ import java .util .List ;
36
6
import java .util .Map ;
7
+ import java .util .Stack ;
37
8
import java .util .logging .Logger ;
38
9
39
- import org .apache .commons .lang .StringEscapeUtils ;
10
+ import org .eclipse .draw2d .ColorConstants ;
11
+ import org .eclipse .draw2d .geometry .Point ;
12
+ import org .eclipse .swt .graphics .Color ;
40
13
import org .xml .sax .Attributes ;
41
14
import org .xml .sax .SAXException ;
42
- import org .xml .sax .SAXParseException ;
43
15
import org .xml .sax .helpers .DefaultHandler ;
44
16
45
- /**
46
- * Classe destinee a la lecture d'un fichier XML. La lecture du fichier permet la construction d'un modele
47
- * @author yann based on jbvoron
48
- *
49
- */
50
- public class ModelHandler extends DefaultHandler {
51
- private final Logger logger = Logger .getLogger ("fr.lip6.move.coloane.its" ); //$NON-NLS-1$
52
-
53
- private Deque <Object > stack = new ArrayDeque <Object >();
54
-
55
- // Correspondance entre les id du document xml et celle des nouveaux objets.
56
- private Map <Integer , Object > ids = new HashMap <Integer , Object >();
57
-
58
- // object constructed
59
- private TypeList types ;
60
-
61
- private String readString ;
62
-
63
- private URI workFile ;
64
-
65
- public ModelHandler (URI workFile ) {
66
- this .workFile = workFile ;
67
- }
68
-
69
-
70
-
71
- /** {@inheritDoc} */
72
- @ Override
73
- public final void startElement (String uri , String localName , String baliseName , Attributes attributes ) throws SAXException {
74
- // Balise MODEL
75
- if ("model" .equals (baliseName )) { //$NON-NLS-1$
76
- // NOP
77
- } else if ("types" .equals (baliseName )) { //$NON-NLS-1$
78
- // stack a new TypeList
79
- stack .push (new TypeList (workFile ));
80
- } else if ("type" .equals (baliseName )) { //$NON-NLS-1$
81
- startType (attributes );
82
- } else if ("concept" .equals (baliseName )) { //$NON-NLS-1$
83
- handleConcept (attributes );
84
- } else if ("concepts" .equals (baliseName )) { //$NON-NLS-1$
85
- // NOP
86
- } else if ("parameter" .equals (baliseName )) { //$NON-NLS-1$
87
- handleParameter (attributes );
88
- } else if ("parameters" .equals (baliseName )) { //$NON-NLS-1$
89
- // NOP
90
- } else if ("checks" .equals (baliseName )) { //$NON-NLS-1$
91
- // NOP
92
- } else if ("check" .equals (baliseName )) { //$NON-NLS-1$
93
- // NOP
94
- } else if ("typeid" .equals (baliseName )) { //$NON-NLS-1$
95
- // NOP
96
- } else if ("formula" .equals (baliseName )) { //$NON-NLS-1$
97
- // NOP
98
- handleFormula (attributes );
99
- } else if ("formulas" .equals (baliseName )) { //$NON-NLS-1$
100
- // NOP
101
- } else {
102
- logger .warning ("Unknown XML tag in source file: " + baliseName ); //$NON-NLS-1$
103
- }
104
- }
105
-
17
+ import fr .lip6 .move .coloane .core .model .factory .GraphModelFactory ;
18
+ import fr .lip6 .move .coloane .interfaces .exceptions .ModelException ;
19
+ import fr .lip6 .move .coloane .interfaces .formalism .IArcFormalism ;
20
+ import fr .lip6 .move .coloane .interfaces .formalism .IFormalism ;
21
+ import fr .lip6 .move .coloane .interfaces .formalism .INodeFormalism ;
22
+ import fr .lip6 .move .coloane .interfaces .model .IArc ;
23
+ import fr .lip6 .move .coloane .interfaces .model .IAttribute ;
24
+ import fr .lip6 .move .coloane .interfaces .model .IGraph ;
25
+ import fr .lip6 .move .coloane .interfaces .model .INode ;
106
26
27
+ public class ModelHandler extends DefaultHandler {
28
+ private final Logger logger = Logger .getLogger ("fr.lip6.move.coloane.its" );
107
29
108
- /** {@inheritDoc} */
109
- @ Override
110
- public final void endElement (String uri , String localName , String baliseName ) throws SAXException {
111
- // Balise MODEL
112
- if ("model" .equals (baliseName )) { //$NON-NLS-1$
113
- // NOP
114
- } else if ("types" .equals (baliseName )) { //$NON-NLS-1$
115
- // assign the constructed TypeList
116
- this .types = (TypeList ) stack .pop ();
117
- } else if ("type" .equals (baliseName )) { //$NON-NLS-1$
118
- // NOP
119
- } else if ("concept" .equals (baliseName )) { //$NON-NLS-1$
120
- // NOP
121
- } else if ("concepts" .equals (baliseName )) { //$NON-NLS-1$
122
- // NOP
123
- } else if ("parameter" .equals (baliseName )) { //$NON-NLS-1$
124
- // NOP
125
- } else if ("parameters" .equals (baliseName )) { //$NON-NLS-1$
126
- // NOP
127
- } else if ("checks" .equals (baliseName )) { //$NON-NLS-1$
128
- // NOP
129
- } else if ("check" .equals (baliseName )) { //$NON-NLS-1$
130
- // NOP
131
- CheckList cl = (CheckList ) stack .pop ();
132
- types .addCheckList (cl );
133
- } else if ("typeid" .equals (baliseName )) { //$NON-NLS-1$
134
- stack .push (handleCheck (readString ));
135
- } else if ("formula" .equals (baliseName )) { //$NON-NLS-1$
136
- // NOP
137
- } else if ("formulas" .equals (baliseName )) { //$NON-NLS-1$
138
- // NOP
139
- } else {
140
- logger .warning ("Unknown XML tag in source file: " + baliseName ); //$NON-NLS-1$
141
- }
142
- }
30
+ private Stack <Object > stack = new Stack <Object >();
31
+ private Map <String , INode > placeIds = null ;
32
+ private Map <String , INode > transIds = null ;
33
+ private IGraph graph ;
34
+ private Map <String , List <INode >> transColors ;
35
+ private Map <String , List <INode >> placeColors ;
36
+ private boolean hasColors = false ;
37
+ private final IFormalism formalism ;
38
+ private final INodeFormalism placeFormalism ;
39
+ private final INodeFormalism transitionFormalism ;
40
+ private final IArcFormalism arcFormalism ;
41
+ private final IArcFormalism resetFormalism ;
42
+ private final IArcFormalism testFormalism ;
43
+ private final IArcFormalism inhibitorFormalism ;
44
+ private StringBuilder textBuffer = new StringBuilder (); // Added for potential text content
143
45
144
- /**
145
- * {@inheritDoc}
146
- */
147
- @ Override
148
- public void characters (char [] arg0 , int arg1 , int arg2 ) throws SAXException {
149
- readString = new String (arg0 , arg1 , arg2 );
150
- }
151
-
152
- /**
153
- * Parse a check description :type declaration field.
154
- * @param typeid the type name
155
- * @throws SAXException any parse error
156
- */
157
- private CheckList handleCheck (String typeid ) throws SAXException {
158
- // Get effective with maximum safeguards
159
- int idEffective ;
160
- try {
161
- idEffective = Integer .parseInt (typeid ); //$NON-NLS-1$
162
- } catch (NumberFormatException e ) {
163
- throw new SAXException ("Corrupted XML file, effective id " + typeid + " should be an integer referring to a type declaration" );
164
- }
165
-
166
- TypeDeclaration effective ;
167
- try {
168
- effective = (TypeDeclaration ) ids .get (idEffective );
169
- } catch (ClassCastException e ) {
170
- throw new SAXException ("Corrupted XML file, effective id " + idEffective + " should refer to a type declaration" );
171
- }
172
- return new CheckList (effective );
173
- }
46
+ public ModelHandler (IFormalism formalism ) {
47
+ this .formalism = formalism ;
48
+ this .placeFormalism = (INodeFormalism ) formalism .getRootGraph ().getElementFormalism ("place" );
49
+ this .transitionFormalism = (INodeFormalism ) formalism .getRootGraph ().getElementFormalism ("transition" );
50
+ this .arcFormalism = (IArcFormalism ) formalism .getRootGraph ().getElementFormalism ("arc" );
51
+ this .resetFormalism = (IArcFormalism ) formalism .getRootGraph ().getElementFormalism ("reset" );
52
+ this .testFormalism = (IArcFormalism ) formalism .getRootGraph ().getElementFormalism ("test" );
53
+ this .inhibitorFormalism = (IArcFormalism ) formalism .getRootGraph ().getElementFormalism ("inhibitor" );
54
+ }
174
55
56
+ @ Override
57
+ public void characters (char [] chars , int beg , int length ) throws SAXException {
58
+ // Log unexpected character data, but don’t process it since the parser uses attributes
59
+ String data = new String (chars , beg , length );
60
+ textBuffer .append (chars , beg , length );
61
+ logger .fine ("Unexpected character data encountered: '" + data + "' (buffer now: '" + textBuffer .toString () + "')" );
62
+ }
175
63
176
- private void handleFormula (Attributes attributes ) {
177
- String name = attributes .getValue ("name" );
178
- String comment = attributes .getValue ("description" );
179
- String form = StringEscapeUtils .unescapeXml (attributes .getValue ("formula" ));
180
- CheckList cl = (CheckList ) stack .peek ();
181
- cl .addCTLFormula (name , form , comment );
182
- }
64
+ @ Override
65
+ public final void startElement (String uri , String localName , String baliseName , Attributes attributes ) throws SAXException {
66
+ // Clear textBuffer for tags where text might theoretically appear, though not currently used
67
+ if ("place" .equals (baliseName ) || "transition" .equals (baliseName ) || "arc" .equals (baliseName )) {
68
+ textBuffer .setLength (0 );
69
+ }
183
70
184
-
185
- /**
186
- * Parse a concept description
187
- * @param attributes the attributes of the concept in XML
188
- * @throws SAXException any parse error
189
- */
190
- private void handleConcept (Attributes attributes ) throws SAXException {
191
- String name = attributes .getValue ("name" ); //$NON-NLS-1$
192
- int idEffective = Integer .parseInt (attributes .getValue ("effective" )); //$NON-NLS-1$
193
- int idParent = Integer .parseInt (attributes .getValue ("parent" )); //$NON-NLS-1$
71
+ if ("TPN" .equals (baliseName )) {
72
+ graph = new GraphModelFactory ().createGraph (formalism );
73
+ placeIds = new HashMap <String , INode >();
74
+ transIds = new HashMap <String , INode >();
75
+ transColors = new HashMap <String , List <INode >>();
76
+ placeColors = new HashMap <String , List <INode >>();
77
+ hasColors = false ;
78
+ for (int i = 0 ; i < 6 ; i ++) {
79
+ String lab = "c" + i ;
80
+ transColors .put (lab , new ArrayList <INode >());
81
+ placeColors .put (lab , new ArrayList <INode >());
82
+ }
83
+ } else if ("place" .equals (baliseName )) {
84
+ stack .push (handlePlace (attributes ));
85
+ } else if ("graphics" .equals (baliseName )) {
86
+ String colorLab = attributes .getValue ("color" );
87
+ if (colorLab != null ) {
88
+ storeObjectColor (colorLab );
89
+ }
90
+ } else if ("position" .equals (baliseName )) {
91
+ handleNodePosition ((INode ) stack .peek (), attributes );
92
+ } else if ("deltaLabel" .equals (baliseName )) {
93
+ handleNodeLabelPosition ((INode ) stack .peek (), attributes );
94
+ } else if ("scheduling" .equals (baliseName )) {
95
+ // TODO: Do something to the place?
96
+ } else if ("transition" .equals (baliseName )) {
97
+ stack .push (handleTransition (attributes ));
98
+ } else if ("arc" .equals (baliseName )) {
99
+ stack .push (handleArc (attributes ));
100
+ } else if ("nail" .equals (baliseName )) {
101
+ handleArcNail ((IArc ) stack .peek (), attributes );
102
+ } else if ("preferences" .equals (baliseName )) {
103
+ // NOP
104
+ } else if ("colorPlace" .equals (baliseName )) {
105
+ hasColors = true ;
106
+ handlePlaceColors (attributes );
107
+ } else if ("colorTransition" .equals (baliseName )) {
108
+ hasColors = true ;
109
+ handleTransitionColors (attributes );
110
+ } else if ("colorArc" .equals (baliseName )) {
111
+ // Ignored
112
+ } else {
113
+ logger .warning ("Unknown XML tag in source file: " + baliseName );
114
+ }
115
+ }
194
116
195
- if (idEffective == -1 ) {
196
- // concept is not assigned
197
- return ;
198
- }
117
+ @ Override
118
+ public final void endElement (String uri , String localName , String baliseName ) throws SAXException {
119
+ if ("TPN" .equals (baliseName )) {
120
+ if (!hasColors ) {
121
+ for (INode node : graph .getNodes ())
122
+ if ("place" .equals (node .getNodeFormalism ().getName ())) {
123
+ node .getGraphicInfo ().setBackground (ColorConstants .lightBlue );
124
+ } else {
125
+ node .getGraphicInfo ().setBackground (ColorConstants .yellow );
126
+ }
127
+ }
128
+ placeIds = null ;
129
+ transIds = null ;
130
+ transColors = null ;
131
+ placeColors = null ;
132
+ hasColors = false ;
133
+ } else if ("place" .equals (baliseName ) || "transition" .equals (baliseName ) || "arc" .equals (baliseName )) {
134
+ stack .pop ();
135
+ textBuffer .setLength (0 ); // Clear after processing, though not currently used
136
+ } else if ("graphics" .equals (baliseName ) || "position" .equals (baliseName ) || "deltaLabel" .equals (baliseName ) ||
137
+ "nail" .equals (baliseName ) || "preferences" .equals (baliseName ) || "colorPlace" .equals (baliseName ) ||
138
+ "colorTransition" .equals (baliseName ) || "colorArc" .equals (baliseName )) {
139
+ // NOP
140
+ } else {
141
+ logger .warning ("Unknown XML tag in source file: " + baliseName );
142
+ }
143
+ }
199
144
200
- // Get parent with maximum safeguards
201
- CompositeTypeDeclaration parent ;
202
- try {
203
- parent = (CompositeTypeDeclaration ) ids .get (idParent );
204
- } catch (ClassCastException e ) {
205
- throw new SAXException ("Corrupted XML file, id " + idParent + " should refer to a composite type declaration" );
206
- }
207
- if (parent == null ) {
208
- throw new SAXException ("Corrupted XML file, Dangling parent type id " + idParent + " in concept " + name );
209
- }
210
- // Get effective with maximum safeguards
211
- ITypeDeclaration effective ;
212
- try {
213
- effective = (ITypeDeclaration ) ids .get (idEffective );
214
- } catch (ClassCastException e ) {
215
- throw new SAXException ("Corrupted XML file, effective id " + idEffective + " should refer to a type declaration" );
216
- }
217
- if (effective == null ) {
218
- throw new SAXException ("Corrupted XML file, Dangling Effective type id " + idEffective + " in concept " + name );
219
- }
220
- // get the concept
221
- Concept concept = parent .getConcept (name );
222
- if (concept == null ) {
223
- logger .warning ("Concept effective definition which should belong to CompositeType " + parent
224
- + " does not exist in the actual model file. Ignoring Concept setting." );
225
- } else {
226
- concept .setEffective (effective );
227
- }
228
- }
145
+ // Remaining methods (handlePlace, handleTransition, etc.) unchanged since they use attributes
146
+ private INode handlePlace (Attributes attributes ) {
147
+ INode place = null ;
148
+ try {
149
+ place = graph .createNode (placeFormalism );
150
+ String label = attributes .getValue ("label" );
151
+ if (label != null )
152
+ place .getAttribute ("name" ).setValue (label );
153
+ String initialMarking = attributes .getValue ("initialMarking" );
154
+ if (initialMarking != null )
155
+ place .getAttribute ("marking" ).setValue (initialMarking );
156
+ placeIds .put (attributes .getValue ("id" ), place );
157
+ } catch (ModelException e ) {
158
+ e .printStackTrace ();
159
+ }
160
+ return place ;
161
+ }
229
162
230
- /**
231
- * Parse a parameter description
232
- * @param attributes the attributes of the concept in XML
233
- * @throws SAXException any parse error
234
- */
235
- private void handleParameter (Attributes attributes ) throws SAXException {
236
- String name = attributes .getValue ("name" ); //$NON-NLS-1$
237
- int value = Integer .parseInt (attributes .getValue ("value" )); //$NON-NLS-1$
238
- int idParent = Integer .parseInt (attributes .getValue ("parent" )); //$NON-NLS-1$
163
+ private INode handleTransition (Attributes attributes ) {
164
+ INode transition = null ;
165
+ try {
166
+ transition = graph .createNode (transitionFormalism );
167
+ String label = attributes .getValue ("label" );
168
+ if (label != null )
169
+ transition .getAttribute ("label" ).setValue (label );
170
+ String eft = attributes .getValue ("eft" );
171
+ transition .getAttribute ("earliestFiringTime" ).setValue (eft );
172
+ String lft = attributes .getValue ("lft" );
173
+ if (lft .equals ("infini" )) {
174
+ transition .getAttribute ("latestFiringTime" ).setValue ("inf" );
175
+ } else {
176
+ transition .getAttribute ("latestFiringTime" ).setValue (lft );
177
+ }
178
+ transIds .put (attributes .getValue ("id" ), transition );
179
+ } catch (ModelException e ) {
180
+ e .printStackTrace ();
181
+ }
182
+ return transition ;
183
+ }
239
184
185
+ private IArc handleArc (Attributes attributes ) {
186
+ IArc arc = null ;
187
+ try {
188
+ INode place = placeIds .get (attributes .getValue ("place" ));
189
+ INode trans = transIds .get (attributes .getValue ("transition" ));
190
+ String type = attributes .getValue ("type" );
191
+ if ("PlaceTransition" .equals (type )) {
192
+ arc = graph .createArc (arcFormalism , place , trans );
193
+ } else if ("TransitionPlace" .equals (type )) {
194
+ arc = graph .createArc (arcFormalism , trans , place );
195
+ } else if ("flush" .equals (type )) {
196
+ arc = graph .createArc (resetFormalism , place , trans );
197
+ } else if ("read" .equals (type )) {
198
+ arc = graph .createArc (testFormalism , place , trans );
199
+ } else if ("logicalInhibitor" .equals (type )) {
200
+ arc = graph .createArc (inhibitorFormalism , place , trans );
201
+ }
202
+ IAttribute val = arc .getAttribute ("valuation" );
203
+ if (val != null ) {
204
+ String weight = attributes .getValue ("weight" );
205
+ val .setValue (weight );
206
+ }
207
+ } catch (ModelException e ) {
208
+ e .printStackTrace ();
209
+ }
210
+ return arc ;
211
+ }
240
212
241
- // Get parent with maximum safeguards
242
- ITypeDeclaration parent ;
243
- try {
244
- parent = (ITypeDeclaration ) ids .get (idParent );
245
- } catch (ClassCastException e ) {
246
- throw new SAXException ("Corrupted XML file, id " + idParent + " should refer to a type declaration" );
247
- }
248
- if (parent == null ) {
249
- throw new SAXException ("Corrupted XML file, Dangling parent type id " + idParent + " in parameter " + name );
250
- }
251
- // get the evaluation context
252
- IEvaluationContext params = parent .getParameters ();
253
- IVariable var = new Variable (name );
254
- if (!params .containsVariable (var )) {
255
- logger .warning ("Concept effective definition which should belong to CompositeType " + parent
256
- + " does not exist in the actual model file. Ignoring Concept setting." );
257
- } else {
258
- params .setVariableValue (var , value );
259
- }
260
- }
213
+ private void handleNodePosition (INode node , Attributes attributes ) {
214
+ float x = Float .parseFloat (attributes .getValue ("x" ));
215
+ float y = Float .parseFloat (attributes .getValue ("y" ));
216
+ node .getGraphicInfo ().setLocation (new Point (x , y ));
217
+ }
261
218
262
- /**
263
- * Analyze a type declaration
264
- * @param attributes Les attributs attachée à la balise
265
- * @throws SAXException if the referenced model file is bad.
266
- */
267
- private void startType (Attributes attributes ) throws SAXException {
268
- TypeList types = (TypeList ) stack .peek ();
219
+ private void handleNodeLabelPosition (INode node , Attributes attributes ) {
220
+ Point nodePos = node .getGraphicInfo ().getLocation ();
221
+ float x = Float .parseFloat (attributes .getValue ("deltax" ));
222
+ float y = Float .parseFloat (attributes .getValue ("deltay" ));
223
+ Point labPos = new Point (x , y );
224
+ IAttribute label ;
225
+ if ("place" .equals (node .getNodeFormalism ().getName ())) {
226
+ label = node .getAttribute ("name" );
227
+ } else {
228
+ label = node .getAttribute ("label" );
229
+ }
230
+ label .getGraphicInfo ().setLocation (labPos .translate (nodePos ));
231
+ }
269
232
270
- int id = Integer .parseInt (attributes .getValue ("id" )); //$NON-NLS-1$
233
+ private void handleArcNail (IArc arc , Attributes attributes ) {
234
+ float x = Float .parseFloat (attributes .getValue ("xnail" ));
235
+ float y = Float .parseFloat (attributes .getValue ("ynail" ));
236
+ if (x != 0 && y != 0 ) {
237
+ Point nail = new Point (x , y );
238
+ arc .addInflexPoint (nail );
239
+ }
240
+ }
271
241
272
- String name = attributes .getValue ("name" ); //$NON-NLS-1$
273
- String formalism = attributes .getValue ("formalism" ); //$NON-NLS-1$
274
-
275
- String workDir = new File (workFile ).getParentFile ().toURI ().getPath ();
276
- String filePath = workDir + "/" + attributes .getValue ("path" );
277
-
278
-
279
- URI file = new File (filePath ).toURI ();
280
-
281
- if (file == null || ! new File (filePath ).canRead () ) {
282
- throw new SAXException ("Could not open referenced file " + filePath , null );
283
- }
284
- ITypeDeclaration type ;
285
- try {
286
- type = TypeDeclarationFactory .create (name , file , types );
287
- } catch (IOException e ) {
288
- throw new SAXException ("Could not open referenced file " + filePath , null );
289
- }
290
- if (!formalism .equals (type .getTypeType ())) {
291
- String errmsg = "Model formalism type for file " + filePath + " does not match file contents.\n "
292
- + "Expected type " + formalism + " read type " + type .getTypeType ();
293
- logger .fine (errmsg );
242
+ private void handlePlaceColors (Attributes attributes ) {
243
+ for (int i = 0 ; i < 6 ; i ++) {
244
+ String colorIndex = "c" + i ;
245
+ String color = attributes .getValue (colorIndex );
246
+ Color bgColor = getColor (color );
247
+ if (color == null ) {
248
+ break ;
249
+ }
250
+ for (INode place : placeColors .get (colorIndex )) {
251
+ place .getGraphicInfo ().setBackground (bgColor );
252
+ }
253
+ }
254
+ }
294
255
295
- throw new SAXParseException (errmsg , null );
296
- }
297
- // store type in hash
298
- ids .put (id , type );
299
- types .addTypeDeclaration (type );
300
- }
256
+ private void handleTransitionColors (Attributes attributes ) {
257
+ for (int i = 0 ; i < 6 ; i ++) {
258
+ String colorIndex = "c" + i ;
259
+ String color = attributes .getValue (colorIndex );
260
+ Color bgColor = getColor (color );
261
+ if (color == null ) {
262
+ break ;
263
+ }
264
+ for (INode trans : transColors .get (colorIndex )) {
265
+ trans .getGraphicInfo ().setBackground (bgColor );
266
+ }
267
+ }
268
+ }
301
269
302
- /**
303
- * @return the type list loaded from the XML file
304
- */
305
- public final TypeList getTypes () {
306
- return types ;
307
- }
308
- }
270
+ private Color getColor (String color ) {
271
+ Color bgColor = null ;
272
+ if ("cyan" .equals (color )) {
273
+ bgColor = ColorConstants .cyan ;
274
+ } else if ("yellow" .equals (color )) {
275
+ bgColor = ColorConstants .yellow ;
276
+ } else if ("gray" .equals (color )) {
277
+ bgColor = ColorConstants .gray ;
278
+ } else if ("brown" .equals (color )) {
279
+ bgColor = ColorConstants .darkGreen ;
280
+ } else if ("SkyBlue2" .equals (color )) {
281
+ bgColor = ColorConstants .lightBlue ;
282
+ } else if ("green" .equals (color )) {
283
+ bgColor = ColorConstants .green ;
284
+ }
285
+ return bgColor ;
286
+ }
309
287
288
+ public final IGraph getGraph () {
289
+ return graph ;
290
+ }
291
+ }
0 commit comments