Version 5.0.0 notes and API changes

In the planned version 5.0.0 I want to take the major step of the attribute and event handling of shapes.

Attributes
The new hero in draw2d is the .attr() method that isn't so chatty like the „setBackgroundColor“ or all the other attribute methods with regards to how often attributes were handled. It is more like the famous jQuery interface. I did this in a new release because I thing this is a major step.

Example of draw2d < 5.0.0

     
    // you can use only the "text" attribute in the constructor.
    //
    textFigure = new draw2d.shape.basic.Text("The quick brown fox jumps over the lazy dog");

    // all other attributes must be set by calling the related setter method
    //
    textFigure.setFontSize("20");
    textFigure.setBackgroundColor("#f0f0f0");
    textFigure.setFontColor("#fF00f0");

    canvas.addFigure(textFigure,150,300);


New draw2d API

    // it is now possible to add all required attributes of the shape in the constructor
    //
    textFigure = new draw2d.shape.basic.Text({
          text:"The quick brown fox jumps over the lazy dog", 
          fontSize:20, 
          bgColor:"#f0f0f0", 
          fontColor:"#ff00f0", 
          x:150, 
          y:300});
    
    canvas.addFigure(textFigure);



Additional it is possible to call the attribute method after shape creation

    // it is now possible to addrequired attributes of the shape in the constructor
    //
    textFigure = new draw2d.shape.basic.Text({x:150, y:300});

    // or by the attar method 
    //
    textFigure.attr({
          text:"The quick brown fox jumps over the lazy dog", 
          fontSize:20, 
          bgColor:"#f0f0f0", 
          fontColor:"#ff00f0"});
    
    canvas.addFigure(textFigure);


Please note that the constructor of the shape has changed and calls like new draw2d.shape.basic.Rectangle(300,150) didn’t work anymore! You must call new draw2d.shape.basic.Rectangle({width:300, height:150}). All getter/setter method are still there - but the construct has changed dramatic in this release. Reading shapes from JSON is working fine as well.


Events

This part is still in draft but the direction is clear

Old API (still working)

	  canvas.getCommandStack().addEventListener(function(e){
	      if(e.isPostChangeEvent()){
	          //...more  inspection code here about the executed command---
	      }
	  });


New API

	// register a listener if a shape has move by the user or API call
	//
	figure.on(„move", function(figure){ console.log(„figure moved)});

	// register some listener to the canvas
	// 
	canvas.on(„move“, function(figure){ console.log(„figure „moved);});
	canvas.on(„delete“, function(figure){ console.log(„figure“ deleted)});
	canvas.on(„add“, function(figure){ console.log(„figure“ added)});