Skip to content

Commit

Permalink
grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
James committed Aug 11, 2009
1 parent 35bb557 commit ae567ea
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 35 deletions.
26 changes: 24 additions & 2 deletions css/WireIt.css
Expand Up @@ -78,6 +78,9 @@ div.WireIt-Container-ddhandle {
font-weight:bold;
text-align:center;
font-size: 10pt;
float : none;
padding-left : 2px;
padding-right : 2px;
}
div.WireIt-Container-ddhandle span {
/*margin-right: 32px;*/
Expand Down Expand Up @@ -105,13 +108,32 @@ div.WireIt-Container-resizehandle {
div.WireIt-Container-closebutton {
background-image: url(../images/close.png);
width: 25px;
height: 15px;
height: 15px;/*
position: absolute;
top: 4px;
right: 4px;
right: 4px;*/
float : right;
cursor: pointer;
}

div.WireIt-Container-groupbutton {
background-image: url(../images/group.png);
width: 25px;
height: 15px;/*
position: absolute;
top: 4px;
right: 4px;*/
float : right;
cursor: pointer;
}

div.WireIt-Container-toolbar {

}

.floatleft {
float : left;
}

div.WireIt-Container-focused {
z-index: 6;
Expand Down
71 changes: 57 additions & 14 deletions js/Container.js
Expand Up @@ -51,6 +51,8 @@ WireIt.Container = function(options, layer) {
*/
this.bodyEl = null;

this.grouper = GLOBAL.grouper;

/**
* Event that is fired when a wire is added
* You can register this event with myTerminal.eventAddWire.subscribe(function(e,params) { var wire=params[0];}, scope);
Expand Down Expand Up @@ -188,7 +190,7 @@ WireIt.Container.prototype = {

// Set title
if(this.options.title) {
this.ddHandle.appendChild( WireIt.cn('span', null, null, this.options.title) );
this.ddHandle.appendChild( WireIt.cn('span', {className: 'floatleft'}, null, this.options.title) );
}

// Icon
Expand All @@ -208,11 +210,17 @@ WireIt.Container.prototype = {
this.ddResizeHandle = WireIt.cn('div', {className: this.options.resizeHandleClassName} );
this.el.appendChild(this.ddResizeHandle);
}


//if(this.options.groupable) {
this.groupButton = WireIt.cn('div', {className: 'WireIt-Container-groupbutton'} );
this.ddHandle.appendChild(this.groupButton)
Event.addListener(this.groupButton, "click", this.onGroupButton, this, true);
//}

if(this.options.close) {
// Close button
this.closeButton = WireIt.cn('div', {className: this.options.closeButtonClassName} );
this.el.appendChild(this.closeButton);
this.ddHandle.appendChild(this.closeButton);
Event.addListener(this.closeButton, "click", this.onCloseButton, this, true);
}

Expand Down Expand Up @@ -278,22 +286,44 @@ WireIt.Container.prototype = {
this.layer.removeContainer(this);
},

onGroupButton: function(e, args) {
Event.stopEvent(e);

this.grouper.toggle(this)
},

addedToGroup: function() {
this.ddHandle.style.backgroundColor = "red";
},

removedFromGroup: function() {
this.ddHandle.style.backgroundColor = "";
},

/**
* Remove this container from the dom
* @method remove
*/
remove: function() {

// Remove the terminals (and thus remove the wires)
this.removeAllTerminals();

// Remove from the dom
this.layer.el.removeChild(this.el);

// Remove all event listeners
Event.purgeElement(this.el);
this.removeUI();
this.removeModel();
},

removeModel: function() {
this.removeAllTerminalsModel();
Event.purgeElement(this.el);
},

removeUI: function() {
this.removeAllTerminalsUI();

this.layer.el.removeChild(this.el);
},

addUI: function() {
this.addAllTerminalsUI();
this.layer.el.appendChild(this.el);
},

/**
* Call the addTerminal method for each terminal configuration.
Expand Down Expand Up @@ -364,13 +394,26 @@ WireIt.Container.prototype = {
* Remove all terminals
* @method removeAllTerminals
*/
removeAllTerminals: function() {
removeAllTerminalsModel: function() {
for(var i = 0 ; i < this.terminals.length ; i++) {
this.terminals[i].remove();
this.terminals[i].removeModel();
}
this.terminals = [];
},

removeAllTerminalsUI: function() {
for(var i = 0 ; i < this.terminals.length ; i++) {
this.terminals[i].removeUI();
}
},

addAllTerminalsUI: function() {
for(var i = 0 ; i < this.terminals.length ; i++) {
this.terminals[i].addUI();
}
},


/**
* Redraw all the wires connected to the terminals of this container
* @method redrawAllTerminals
Expand Down
26 changes: 21 additions & 5 deletions js/Layer.js
Expand Up @@ -185,6 +185,9 @@ WireIt.Layer.prototype = {
}
var container = new type(containerConfig, this);

return this.addContainerDirect(container);
},
addContainerDirect: function(container) {
this.containers.push( container );

// Event listeners
Expand All @@ -208,24 +211,37 @@ WireIt.Layer.prototype = {

this.eventChanged.fire(this);

return container;
return container;
},

addContainerUI: function(container) {
this.containers.push(container);
container.addUI();

this.eventChanged.fire(this)
},

/**
* Remove a container
* @method removeContainer
* @param {WireIt.Container} container Container instance to remove
*/
removeContainer: function(container) {
removeContainer: function(container, uiOnly) {
var index = WireIt.indexOf(container, this.containers);
if( index != -1 ) {
container.remove();

if (uiOnly == true)
container.removeUI();
else
container.remove();

this.containers[index] = null;
this.containers = WireIt.compact(this.containers);

this.eventRemoveContainer.fire(container);
if (uiOnly != true)
this.eventRemoveContainer.fire(container);

this.eventChanged.fire(this);
this.eventChanged.fire(this);
}
},

Expand Down
22 changes: 19 additions & 3 deletions js/Terminal.js
Expand Up @@ -659,19 +659,21 @@ WireIt.Terminal.prototype = {
return [curleft+15,curtop+15];
},


remove: function() {
this.removeUI();
this.removeModel();
},

/**
* Remove the terminal from the DOM
* @method remove
*/
remove: function() {
removeModel: function() {
// This isn't very nice but...
// the method Wire.remove calls Terminal.removeWire to remove the reference
while(this.wires.length > 0) {
this.wires[0].remove();
}
this.parentEl.removeChild(this.el);

// Remove all event listeners
Event.purgeElement(this.el);
Expand All @@ -683,7 +685,21 @@ WireIt.Terminal.prototype = {

},

removeUI: function() {
for (var i in this.wires) {
this.wires[i].remove(true);
}

this.parentEl.removeChild(this.el);
},

addUI: function() {
this.parentEl.appendChild(this.el);

for (var i in this.wires) {
this.wires[i].show();
}
},

/**
* Returns a list of all the terminals connecter to this terminal through its wires.
Expand Down
36 changes: 25 additions & 11 deletions js/Wire.js
Expand Up @@ -117,22 +117,36 @@ YAHOO.lang.extend(WireIt.Wire, WireIt.CanvasElement, {
* Remove a Wire from the Dom
* @method remove
*/
remove: function() {
remove: function(uiOnly) {

// Remove the canvas from the dom
this.parentEl.removeChild(this.element);

// Remove the wire reference from the connected terminals
if(this.terminal1 && this.terminal1.removeWire) {
this.terminal1.removeWire(this);
try {
this.parentEl.removeChild(this.element);
}
if(this.terminal2 && this.terminal2.removeWire) {
this.terminal2.removeWire(this);
catch (ex)
{
if (!(ex.name && ex.name == "NS_ERROR_DOM_NOT_FOUND_ERR"))
throw ex
}

// Remove references to old terminals
this.terminal1 = null;
this.terminal2 = null;
if (uiOnly != true)
{
// Remove the wire reference from the connected terminals
if(this.terminal1 && this.terminal1.removeWire) {
this.terminal1.removeWire(this);
}
if(this.terminal2 && this.terminal2.removeWire) {
this.terminal2.removeWire(this);
}

// Remove references to old terminals
this.terminal1 = null;
this.terminal2 = null;
}
},

show: function() {
this.parentEl.appendChild(this.element);
},

/**
Expand Down

0 comments on commit ae567ea

Please sign in to comment.