summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClément DAVID <clement.david@scilab.org>2010-05-11 16:06:07 +0200
committerBruno JOFRET <bruno.jofret@scilab.org>2010-05-25 10:52:02 +0200
commit5db8ccac140c300a0944e47dab49e1ab27785e04 (patch)
tree5023a9b83c8cabb49d0c68fc5b4a211345ac5d4b
parentf06b8a6995add91d1c479628fe91a3901f832476 (diff)
downloadscilab-5db8ccac140c300a0944e47dab49e1ab27785e04.zip
scilab-5db8ccac140c300a0944e47dab49e1ab27785e04.tar.gz
Xcos: add a PropertyChangeListener for block parameters
Support block parameters modification listeners (will help java block implementation) Add an "interfaceFunctionName" update listener for changing the associated style. Improve the clone method to reinstall the right PCS. Change-Id: I16868460e8319aa2af21120f32fafb3b482ab58e
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BasicBlock.java237
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BlockFactory.java10
-rw-r--r--scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/BasicBlockCodec.java2
3 files changed, 215 insertions, 34 deletions
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BasicBlock.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BasicBlock.java
index cb0fb5a..d35d49f 100644
--- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BasicBlock.java
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BasicBlock.java
@@ -17,6 +17,9 @@ import static org.scilab.modules.xcos.utils.FileUtils.delete;
17import java.awt.MouseInfo; 17import java.awt.MouseInfo;
18import java.awt.event.ActionEvent; 18import java.awt.event.ActionEvent;
19import java.awt.event.ActionListener; 19import java.awt.event.ActionListener;
20import java.beans.PropertyChangeEvent;
21import java.beans.PropertyChangeListener;
22import java.beans.PropertyChangeSupport;
20import java.io.File; 23import java.io.File;
21import java.io.IOException; 24import java.io.IOException;
22import java.util.HashMap; 25import java.util.HashMap;
@@ -94,12 +97,37 @@ public class BasicBlock extends ScilabGraphUniqueObject {
94 private static final double DEFAULT_WIDTH = 40.0; 97 private static final double DEFAULT_WIDTH = 40.0;
95 private static final double DEFAULT_HEIGHT = 40.0; 98 private static final double DEFAULT_HEIGHT = 40.0;
96 99
100 private static final PropertyChangeListener styleUpdater = new UpdateStyleFromInterfunction();
97 private static final Log LOG = LogFactory.getLog(BasicBlock.class); 101 private static final Log LOG = LogFactory.getLog(BasicBlock.class);
98 102
103 /**
104 * Manage events for block parameters.
105 *
106 * The property name is the field name, is one of:
107 * - "interfaceFunctionName"
108 * - "simulationFunctionName"
109 * - "simulationFunctionType"
110 * - "exprs"
111 * - "realParameters"
112 * - "integerParameters"
113 * - "objectsParameters"
114 * - "nbZerosCrossing"
115 * - "nmode"
116 * - "state"
117 * - "dState"
118 * - "oDState"
119 * - "equations"
120 * - "dependsOnU"
121 * - "dependsOnT"
122 * - "blockType"
123 * - "ordering"
124 */
125 protected PropertyChangeSupport parameters = new PropertyChangeSupport(this);
126
99 private String interfaceFunctionName = "xcos_block"; 127 private String interfaceFunctionName = "xcos_block";
100 private String simulationFunctionName = "xcos_simulate"; 128 private String simulationFunctionName = "xcos_simulate";
101 private SimulationFunctionType simulationFunctionType = SimulationFunctionType.DEFAULT; 129 private SimulationFunctionType simulationFunctionType = SimulationFunctionType.DEFAULT;
102 private transient XcosDiagram parentDiagram; 130 private transient XcosDiagram parentDiagram;
103 131
104 private int angle; 132 private int angle;
105 private boolean isFlipped; 133 private boolean isFlipped;
@@ -183,6 +211,26 @@ public class BasicBlock extends ScilabGraphUniqueObject {
183 } 211 }
184 }; 212 };
185 213
214 private static class UpdateStyleFromInterfunction implements PropertyChangeListener {
215
216 /**
217 * Update the label on interfunction change.
218 *
219 * @param evt the property change event.
220 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
221 */
222 @Override
223 public void propertyChange(PropertyChangeEvent evt) {
224 BasicBlock source = (BasicBlock) evt.getSource();
225
226 StyleMap style = new StyleMap(source.getStyle());
227 style.remove((String) evt.getOldValue());
228 style.put((String) evt.getNewValue(), null);
229 source.setStyle(style.toString());
230 }
231
232 }
233
186 /** 234 /**
187 * 235 *
188 */ 236 */
@@ -191,6 +239,9 @@ public class BasicBlock extends ScilabGraphUniqueObject {
191 setDefaultValues(); 239 setDefaultValues();
192 setVisible(true); 240 setVisible(true);
193 setVertex(true); 241 setVertex(true);
242
243 parameters.addPropertyChangeListener("interfaceFunctionName",
244 styleUpdater);
194 } 245 }
195 246
196 /** 247 /**
@@ -250,23 +301,27 @@ public class BasicBlock extends ScilabGraphUniqueObject {
250 * @param interfaceFunctionName interface function name 301 * @param interfaceFunctionName interface function name
251 */ 302 */
252 public void setInterfaceFunctionName(String interfaceFunctionName) { 303 public void setInterfaceFunctionName(String interfaceFunctionName) {
253 String interfunction = getInterfaceFunctionName(); 304 if ((this.interfaceFunctionName == null && interfaceFunctionName != null)
254 this.interfaceFunctionName = interfaceFunctionName; 305 || !this.interfaceFunctionName.equals(interfaceFunctionName)) {
255 306
256 /* 307 final String oldValue = this.interfaceFunctionName;
257 * Update style 308 this.interfaceFunctionName = interfaceFunctionName;
258 */ 309 parameters.firePropertyChange("interfaceFunctionName", oldValue,
259 StyleMap style = new StyleMap(getStyle()); 310 interfaceFunctionName);
260 style.remove(interfunction); 311 }
261 style.put(interfaceFunctionName, null);
262 setStyle(style.toString());
263 } 312 }
264 313
265 /** 314 /**
266 * @param simulationFunctionName sumulation function name 315 * @param simulationFunctionName sumulation function name
267 */ 316 */
268 public void setSimulationFunctionName(String simulationFunctionName) { 317 public void setSimulationFunctionName(String simulationFunctionName) {
269 this.simulationFunctionName = simulationFunctionName; 318 if ((this.simulationFunctionName == null && simulationFunctionName != null)
319 || !this.simulationFunctionName.equals(simulationFunctionName)) {
320
321 final String oldValue = this.simulationFunctionName;
322 this.simulationFunctionName = simulationFunctionName;
323 parameters.firePropertyChange("simulationFunctionName", oldValue, simulationFunctionName);
324 }
270 } 325 }
271 326
272 /** 327 /**
@@ -280,15 +335,23 @@ public class BasicBlock extends ScilabGraphUniqueObject {
280 * @param scilabValue simulation function type 335 * @param scilabValue simulation function type
281 */ 336 */
282 public void setSimulationFunctionType(int scilabValue) { 337 public void setSimulationFunctionType(int scilabValue) {
283 this.simulationFunctionType = SimulationFunctionType.convertScilabValue(scilabValue); 338 SimulationFunctionType simulationFunctionType = SimulationFunctionType.convertScilabValue(scilabValue);
339 setSimulationFunctionType(simulationFunctionType);
284 } 340 }
285 341
286 /** 342 /**
287 * @param simulationFunctionType simulation function type 343 * @param simulationFunctionType simulation function type
288 */ 344 */
289 public void setSimulationFunctionType(SimulationFunctionType simulationFunctionType) { 345 public void setSimulationFunctionType(SimulationFunctionType simulationFunctionType) {
290 this.simulationFunctionType = simulationFunctionType; 346 if ((this.simulationFunctionType == null && simulationFunctionType != null)
291 } 347 || !this.simulationFunctionType.equals(simulationFunctionType)) {
348
349 final SimulationFunctionType oldValue = this.simulationFunctionType;
350 this.simulationFunctionType = simulationFunctionType;
351 parameters.firePropertyChange("simulationFunctionType", oldValue,
352 simulationFunctionType);
353 }
354 }
292 355
293 /** 356 /**
294 * @return simulation function type 357 * @return simulation function type
@@ -308,7 +371,13 @@ public class BasicBlock extends ScilabGraphUniqueObject {
308 * @param realParameters reaL parameter ( rpar ) 371 * @param realParameters reaL parameter ( rpar )
309 */ 372 */
310 public void setRealParameters(ScilabType realParameters) { 373 public void setRealParameters(ScilabType realParameters) {
311 this.realParameters = realParameters; 374 if ((this.realParameters == null && realParameters != null)
375 || !this.realParameters.equals(realParameters)) {
376
377 final ScilabType oldValue = this.realParameters;
378 this.realParameters = realParameters;
379 parameters.firePropertyChange("realParameters", oldValue, realParameters);
380 }
312 } 381 }
313 382
314 /** 383 /**
@@ -322,7 +391,13 @@ public class BasicBlock extends ScilabGraphUniqueObject {
322 * @param integerParameters integer parameter ( ipar ) 391 * @param integerParameters integer parameter ( ipar )
323 */ 392 */
324 public void setIntegerParameters(ScilabType integerParameters) { 393 public void setIntegerParameters(ScilabType integerParameters) {
325 this.integerParameters = integerParameters; 394 if ((this.integerParameters == null && integerParameters != null)
395 || !this.integerParameters.equals(integerParameters)) {
396
397 final ScilabType oldValue = this.integerParameters;
398 this.integerParameters = integerParameters;
399 parameters.firePropertyChange("integerParameters", oldValue, integerParameters);
400 }
326 } 401 }
327 402
328 /** 403 /**
@@ -336,14 +411,25 @@ public class BasicBlock extends ScilabGraphUniqueObject {
336 * @param objectsParameters object parameter ( opar ) 411 * @param objectsParameters object parameter ( opar )
337 */ 412 */
338 public void setObjectsParameters(ScilabType objectsParameters) { 413 public void setObjectsParameters(ScilabType objectsParameters) {
339 this.objectsParameters = objectsParameters; 414 if ((this.objectsParameters == null && objectsParameters != null)
415 || !this.objectsParameters.equals(objectsParameters)) {
416
417 final ScilabType oldValue = this.objectsParameters;
418 this.objectsParameters = objectsParameters;
419 parameters.firePropertyChange("objectsParameters", oldValue, objectsParameters);
420 }
340 } 421 }
341 422
342 /** 423 /**
343 * @param dependsOnU ? 424 * @param dependsOnU ?
344 */ 425 */
345 public void setDependsOnU(boolean dependsOnU) { 426 public void setDependsOnU(boolean dependsOnU) {
346 this.dependsOnU = dependsOnU; 427 if (this.dependsOnU != dependsOnU) {
428
429 final boolean oldValue = this.dependsOnU;
430 this.dependsOnU = dependsOnU;
431 parameters.firePropertyChange("dependsOnU", oldValue, dependsOnU);
432 }
347 } 433 }
348 434
349 /** 435 /**
@@ -357,7 +443,12 @@ public class BasicBlock extends ScilabGraphUniqueObject {
357 * @param dependsOnT ? 443 * @param dependsOnT ?
358 */ 444 */
359 public void setDependsOnT(boolean dependsOnT) { 445 public void setDependsOnT(boolean dependsOnT) {
360 this.dependsOnT = dependsOnT; 446 if (this.dependsOnT != dependsOnT) {
447
448 final boolean oldValue = this.dependsOnT;
449 this.dependsOnT = dependsOnT;
450 parameters.firePropertyChange("dependsOnT", oldValue, dependsOnT);
451 }
361 } 452 }
362 453
363 /** 454 /**
@@ -371,7 +462,13 @@ public class BasicBlock extends ScilabGraphUniqueObject {
371 * @param blockType block type 462 * @param blockType block type
372 */ 463 */
373 public void setBlockType(String blockType) { 464 public void setBlockType(String blockType) {
374 this.blockType = blockType; 465 if ((this.blockType == null && blockType != null)
466 || !this.blockType.equals(blockType)) {
467
468 final String oldValue = this.blockType;
469 this.blockType = blockType;
470 parameters.firePropertyChange("blockType", oldValue, blockType);
471 }
375 } 472 }
376 473
377 /** 474 /**
@@ -385,7 +482,12 @@ public class BasicBlock extends ScilabGraphUniqueObject {
385 * @param ordering order value 482 * @param ordering order value
386 */ 483 */
387 public void setOrdering(int ordering) { 484 public void setOrdering(int ordering) {
388 this.ordering = ordering; 485 if (this.ordering != ordering) {
486
487 final int oldValue = this.ordering;
488 this.ordering = ordering;
489 parameters.firePropertyChange("ordering", oldValue, ordering);
490 }
389 } 491 }
390 492
391 /** 493 /**
@@ -399,7 +501,13 @@ public class BasicBlock extends ScilabGraphUniqueObject {
399 * @param exprs expression 501 * @param exprs expression
400 */ 502 */
401 public void setExprs(ScilabType exprs) { 503 public void setExprs(ScilabType exprs) {
402 this.exprs = exprs; 504 if ((this.exprs == null && exprs != null)
505 || !this.exprs.equals(exprs)) {
506
507 final ScilabType oldValue = this.exprs;
508 this.exprs = exprs;
509 parameters.firePropertyChange("exprs", oldValue, exprs);
510 }
403 } 511 }
404 512
405 /** 513 /**
@@ -420,7 +528,13 @@ public class BasicBlock extends ScilabGraphUniqueObject {
420 * @param nbZerosCrossing zero crossing value 528 * @param nbZerosCrossing zero crossing value
421 */ 529 */
422 public void setNbZerosCrossing(ScilabType nbZerosCrossing) { 530 public void setNbZerosCrossing(ScilabType nbZerosCrossing) {
423 this.nbZerosCrossing = nbZerosCrossing; 531 if ((this.nbZerosCrossing == null && nbZerosCrossing != null)
532 || !this.nbZerosCrossing.equals(nbZerosCrossing)) {
533
534 final ScilabType oldValue = this.nbZerosCrossing;
535 this.nbZerosCrossing = nbZerosCrossing;
536 parameters.firePropertyChange("nbZerosCrossing", oldValue, nbZerosCrossing);
537 }
424 } 538 }
425 539
426 /** 540 /**
@@ -434,7 +548,13 @@ public class BasicBlock extends ScilabGraphUniqueObject {
434 * @param nmode nmode 548 * @param nmode nmode
435 */ 549 */
436 public void setNmode(ScilabType nmode) { 550 public void setNmode(ScilabType nmode) {
437 this.nmode = nmode; 551 if ((this.nmode == null && nmode != null)
552 || !this.nmode.equals(nmode)) {
553
554 final ScilabType oldValue = this.nmode;
555 this.nmode = nmode;
556 parameters.firePropertyChange("nmode", oldValue, nmode);
557 }
438 } 558 }
439 559
440 /** 560 /**
@@ -448,7 +568,13 @@ public class BasicBlock extends ScilabGraphUniqueObject {
448 * @param state new state 568 * @param state new state
449 */ 569 */
450 public void setState(ScilabType state) { 570 public void setState(ScilabType state) {
451 this.state = state; 571 if ((this.state == null && state != null)
572 || !this.state.equals(state)) {
573
574 final ScilabType oldValue = this.state;
575 this.state = state;
576 parameters.firePropertyChange("state", oldValue, state);
577 }
452 } 578 }
453 579
454 /** 580 /**
@@ -461,8 +587,14 @@ public class BasicBlock extends ScilabGraphUniqueObject {
461 /** 587 /**
462 * @param state new dstate 588 * @param state new dstate
463 */ 589 */
464 public void setDState(ScilabType state) { 590 public void setDState(ScilabType dState) {
465 dState = state; 591 if ((this.dState == null && dState != null)
592 || !this.dState.equals(dState)) {
593
594 final ScilabType oldValue = this.dState;
595 this.dState = dState;
596 parameters.firePropertyChange("dState", oldValue, dState);
597 }
466 } 598 }
467 599
468 /** 600 /**
@@ -475,8 +607,14 @@ public class BasicBlock extends ScilabGraphUniqueObject {
475 /** 607 /**
476 * @param state new ostate 608 * @param state new ostate
477 */ 609 */
478 public void setODState(ScilabType state) { 610 public void setODState(ScilabType oDState) {
479 oDState = state; 611 if ((this.oDState == null && oDState != null)
612 || !this.oDState.equals(oDState)) {
613
614 final ScilabType oldValue = this.oDState;
615 this.oDState = oDState;
616 parameters.firePropertyChange("oDState", oldValue, oDState);
617 }
480 } 618 }
481 619
482 /** 620 /**
@@ -490,7 +628,13 @@ public class BasicBlock extends ScilabGraphUniqueObject {
490 * @param equations equations 628 * @param equations equations
491 */ 629 */
492 public void setEquations(ScilabType equations) { 630 public void setEquations(ScilabType equations) {
493 this.equations = equations; 631 if ((this.equations == null && equations != null)
632 || !this.equations.equals(equations)) {
633
634 final ScilabType oldValue = this.equations;
635 this.equations = equations;
636 parameters.firePropertyChange("equations", oldValue, equations);
637 }
494 } 638 }
495 639
496 /** 640 /**
@@ -611,7 +755,6 @@ public class BasicBlock extends ScilabGraphUniqueObject {
611 parentBlock.getParentDiagram().fireEvent(new mxEventObject(XcosEvent.SUPER_BLOCK_UPDATED, 755 parentBlock.getParentDiagram().fireEvent(new mxEventObject(XcosEvent.SUPER_BLOCK_UPDATED,
612 XcosConstants.EVENT_BLOCK_UPDATED, parentBlock)); 756 XcosConstants.EVENT_BLOCK_UPDATED, parentBlock));
613 } 757 }
614
615 } 758 }
616 759
617 /** 760 /**
@@ -1080,4 +1223,32 @@ public class BasicBlock extends ScilabGraphUniqueObject {
1080 geom.setX(DEFAULT_POSITION_X); 1223 geom.setX(DEFAULT_POSITION_X);
1081 geom.setY(DEFAULT_POSITION_Y); 1224 geom.setY(DEFAULT_POSITION_Y);
1082 } 1225 }
1226
1227 /**
1228 * Get the parameters change support.
1229 *
1230 * The property name for each event is the field name, so one of:
1231 * - "interfaceFunctionName"
1232 * - "simulationFunctionName"
1233 * - "simulationFunctionType"
1234 * - "exprs"
1235 * - "realParameters"
1236 * - "integerParameters"
1237 * - "objectsParameters"
1238 * - "nbZerosCrossing"
1239 * - "nmode"
1240 * - "state"
1241 * - "dState"
1242 * - "oDState"
1243 * - "equations"
1244 * - "dependsOnU"
1245 * - "dependsOnT"
1246 * - "blockType"
1247 * - "ordering"
1248 *
1249 * @return the associated {@link PropertyChangeSupport} instance
1250 */
1251 public PropertyChangeSupport getParametersPCS() {
1252 return parameters;
1253 }
1083} 1254}
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BlockFactory.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BlockFactory.java
index b8e9c97..29bb74d 100644
--- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BlockFactory.java
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BlockFactory.java
@@ -12,6 +12,9 @@
12 12
13package org.scilab.modules.xcos.block; 13package org.scilab.modules.xcos.block;
14 14
15import java.beans.PropertyChangeListener;
16import java.beans.PropertyChangeSupport;
17
15import org.scilab.modules.xcos.block.io.EventInBlock; 18import org.scilab.modules.xcos.block.io.EventInBlock;
16import org.scilab.modules.xcos.block.io.EventOutBlock; 19import org.scilab.modules.xcos.block.io.EventOutBlock;
17import org.scilab.modules.xcos.block.io.ExplicitInBlock; 20import org.scilab.modules.xcos.block.io.ExplicitInBlock;
@@ -187,6 +190,13 @@ public final class BlockFactory {
187 clone.insert((mxICell) port.clone()); 190 clone.insert((mxICell) port.clone());
188 } 191 }
189 192
193 /* Reinstall the PropertyChangeSupport and all of it listeners */
194 clone.parameters = new PropertyChangeSupport(clone);
195 PropertyChangeSupport pcs = block.getParametersPCS();
196 for (PropertyChangeListener iter : pcs.getPropertyChangeListeners()) {
197 clone.parameters.addPropertyChangeListener(iter);
198 }
199
190 return clone; 200 return clone;
191 } catch (CloneNotSupportedException e) { 201 } catch (CloneNotSupportedException e) {
192 e.printStackTrace(); 202 e.printStackTrace();
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/BasicBlockCodec.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/BasicBlockCodec.java
index bb42e4d..0e8c352 100644
--- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/BasicBlockCodec.java
+++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/codec/BasicBlockCodec.java
@@ -35,7 +35,7 @@ import com.mxgraph.model.mxCell;
35public class BasicBlockCodec extends XcosObjectCodec { 35public class BasicBlockCodec extends XcosObjectCodec {
36 36
37 private static final String SIMULATION_FUNCTION_TYPE = "simulationFunctionType"; 37 private static final String SIMULATION_FUNCTION_TYPE = "simulationFunctionType";
38 private static final String[] IGNORED_FIELDS = new String[] {SIMULATION_FUNCTION_TYPE, "locked"}; 38 private static final String[] IGNORED_FIELDS = new String[] {SIMULATION_FUNCTION_TYPE, "locked", "parameters"};
39 39
40 /** 40 /**
41 * The constructor used on for configuration 41 * The constructor used on for configuration