Skip to content

Commit

Permalink
> VacuumLayout now extends Element (from useless.swc)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmshv committed Mar 15, 2013
1 parent aa71ebf commit 17b18b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 41 deletions.
50 changes: 13 additions & 37 deletions src/ru/gotoandstop/nodes/VacuumLayout.as
Expand Up @@ -9,6 +9,7 @@ import ru.gotoandstop.nodes.links.ILink;
import ru.gotoandstop.nodes.links.ILinkProvider;
import ru.gotoandstop.nodes.links.IPort;
import ru.gotoandstop.nodes.links.PortPoint;
import ru.gotoandstop.ui.Element;
import ru.gotoandstop.vacuum.Layout;
import ru.gotoandstop.vacuum.core.Vertex;
import ru.gotoandstop.vacuum.view.VertexView;
Expand All @@ -17,15 +18,9 @@ import ru.gotoandstop.vacuum.view.VertexView;
/**
* @author tmshv
*/
public class VacuumLayout extends EventDispatcher implements IDisposable {
public class VacuumLayout extends Element implements IDisposable {
private var vertices:Vector.<Vertex>;
private var _container:DisplayObjectContainer;

public function get container():DisplayObjectContainer {
return this._container;
}

private var layers:Object;
private var _layout:Layout;
public function get layout():Layout {
return this._layout;
Expand All @@ -37,18 +32,16 @@ public class VacuumLayout extends EventDispatcher implements IDisposable {

private var __inited:Boolean;

public function VacuumLayout(container:DisplayObjectContainer, layout:Layout) {
public function VacuumLayout(layout:Layout) {
super();
this._container = container;
this._layout = layout;
this.vertices = new Vector.<Vertex>();
this.layers = new Object();
this._links = new Vector.<ILink>();

this.addLayer('lines');
this.addLayer('nodes');
this.addLayer('activepoints');
this.addLayer("vertex");
element("lines");
element("nodes");
element("activepoints");
element("vertex");
}

public function init(linkProvider:ILinkProvider):void{
Expand All @@ -57,16 +50,6 @@ public class VacuumLayout extends EventDispatcher implements IDisposable {
__inited = true;
}

public function addLayer(name:String):void {
var layer:Sprite = new Sprite();
this.container.addChild(layer);
this.layers[name] = layer;
}

public function getLayer(name:String):Sprite {
return this.layers[name];
}

public function connect(first:IPort, second:IPort, id:String=null):String {
var connection:ILink;
if (id) {
Expand All @@ -79,7 +62,7 @@ public class VacuumLayout extends EventDispatcher implements IDisposable {
}

if (!connection) {
const layer:Sprite = layers['lines'];
const layer:Sprite = element("lines");
connection = _linkProvider.provideLink(first, second);
_links.push(connection);
}else{
Expand Down Expand Up @@ -116,23 +99,21 @@ public class VacuumLayout extends EventDispatcher implements IDisposable {
}

public function showVertex(v:VertexView):void {
const layer:Sprite = this.layers['vertex'];
layer.addChild(v);
element("vertex").push(v);
}

public function hideVertex(v:VertexView):void {
const layer:Sprite = this.layers['vertex'];
const layer:Sprite = element("vertex");
if(v && layer.contains(v)) layer.removeChild(v);
}

public function showPort(point:PortPoint):void {
const layer:Sprite = this.layers['activepoints'];
layer.addChild(point);
element("activepoints").push(point);
super.dispatchEvent(new VacuumEvent(VacuumEvent.ADDED_VERTEX, false, false, point));
}

public function deletePoint(point:PortPoint):void {
const layer:Sprite = this.layers['activepoints'];
const layer:Sprite = element("activepoints");
if(layer.contains(point)) {
layer.removeChild(point);
super.dispatchEvent(new VacuumEvent(VacuumEvent.REMOVED_VERTEX, false, false, point));
Expand All @@ -144,12 +125,7 @@ public class VacuumLayout extends EventDispatcher implements IDisposable {
c.dispose();
}
_links = null;

for each(var layer:DisplayObject in layers) {
container.removeChild(layer);
}
layers = null;

removeChildren();
if(cursor) cursor.dispose();
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/ru/gotoandstop/nodes/core/NodeSystem.as
Expand Up @@ -14,6 +14,7 @@ import ru.gotoandstop.nodes.MouseVertex;
import ru.gotoandstop.nodes.VacuumEvent;
import ru.gotoandstop.nodes.VacuumLayout;
import ru.gotoandstop.nodes.commands.DeleteNodeCommand;
import ru.gotoandstop.nodes.links.BezierQuadLinkProvider;
import ru.gotoandstop.nodes.links.DirectLinkProvider;
import ru.gotoandstop.nodes.links.PortPoint;
import ru.gotoandstop.nodes.links.PortPointType;
Expand Down Expand Up @@ -66,10 +67,12 @@ public class NodeSystem extends Sprite implements INodeSystem {
nodeLibrary = new Object();
nodes = new Vector.<Node>();
connections = new Vector.<Object>();
_vacuum = new VacuumLayout(this, new Layout());
_vacuum.init(new DirectLinkProvider(_vacuum.getLayer("lines")));
_vacuum = new VacuumLayout(new Layout());
// _vacuum.init(new DirectLinkProvider(_vacuum.getLayer("lines")));
_vacuum.init(new BezierQuadLinkProvider(_vacuum.element("lines")));
_vacuum.cursor = new MouseVertex(stage);
_vacuum.addEventListener(VacuumEvent.ADDED_VERTEX, handleAddedVertexToVacuum);
addChild(_vacuum);

_stage.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
_stage.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
Expand Down Expand Up @@ -145,7 +148,7 @@ public class NodeSystem extends Sprite implements INodeSystem {
node.set(key, p);
}

var container:DisplayObjectContainer = _vacuum.getLayer('nodes');
var container:DisplayObjectContainer = _vacuum.element("nodes");
container.addChild(node);
node.setCloseCommand(new DeleteNodeCommand(node, deleteNode));
nodes.push(node);
Expand Down Expand Up @@ -307,7 +310,7 @@ public class NodeSystem extends Sprite implements INodeSystem {

super.dispatchEvent(new NodeSystemEvent(NodeSystemEvent.REMOVED_NODE, false, false, node));
node_visual.dispose();
var container:DisplayObjectContainer = _vacuum.getLayer('nodes');
var container:DisplayObjectContainer = _vacuum.element("nodes");
if (container.contains(node_visual)) {
container.removeChild(node_visual);
}
Expand Down

0 comments on commit 17b18b3

Please sign in to comment.