Manipulating Factory

When speaking about factory, we should refer to the visualizer.itemsFactory method. It is the main responsible of instantiating all Visualizer artifacts (node, links, groups, decorators, controllers, knobs and default renderers). This method return an instance of IFactory class. This class provides a factory method interface to each of the subclasses. In this class we find the addOrReplaceClassReference method that represents the factory method. It maps a class reference to a referenceID. If the referenceID already exists in the factory, its referenced class will be replaced by newClass. This method is useful to enable the generation of a new class reference instance or to replace an existing one. The basic idea so is that all items classes are uncoupled from the client. One example of malipulating factory is using custom Knobs. we can use a custom knob like follows:

diagrammer.itemsFactory.addOrReplaceClassReference('anchorKnob',CustomAnchorKnob);
Here is an example showing how user can change the default behavior of the anchor knob ( the ports where links are connected ). To do that, user have to create his own CustomAnchorKnob and then refer to it using the statement :
diagrammer.itemsFactory.addOrReplaceClassReference('anchorKnob',CustomAnchorKnob);
on his main project creation complete handler.

package 
{
	import fr.kapit.diagrammer.Diagrammer;
	import fr.kapit.diagrammer.artifacts.AnchorKnob;


	public class CustomAnchorKnob extends AnchorKnob
	{
		public function CustomAnchorKnob()
		{
			super();
			
		}
		protected function initParams():void
		{
			
			_borderThickness = 2;
			_borderColor = 0x000000;
			_borderAlpha = 1;
			_alpha = 1;
			_color=0xffffff;
			_shape = 'circle';
			_length = 10;
		}
		public override function draw():void
		{
			initParams();
			super.draw();
		}
	}
}