implemented ability to include the current layout to the list and to save all the layouts to a text file - now I'm implementing the ability to load the layouts from file (the inverse operation)

This commit is contained in:
Felipe Cecagno 2012-05-30 10:17:38 -03:00
parent 1c50815570
commit 29a1aec1c9
5 changed files with 108 additions and 34 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<?xml version="1.0"?>
<layouts>
<layout name="Default" default="true">
<window name="ViewersWindow" width="0.1772793053545586" height="0.33643617021276595" x="0" y="0" />

View File

@ -33,12 +33,12 @@ package org.bigbluebutton.modules.layout.managers
import org.bigbluebutton.modules.layout.model.LayoutDefinition;
public class LayoutManager extends EventDispatcher {
private var _layouts:Dictionary = new Dictionary();
private var _layouts:Dictionary;
private var _dispatcher:Dispatcher = new Dispatcher();
public function loadLayout(layoutUrl:String):void {
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, handleComplete);
urlLoader.addEventListener(Event.COMPLETE, completeHandler);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
var date:Date = new Date();
try {
@ -48,8 +48,10 @@ package org.bigbluebutton.modules.layout.managers
}
}
private function handleComplete(e:Event):void{
public function completeHandler(e:Event):void {
LogUtil.debug("==================================> loaded");
var data:XML = new XML(e.target.data);
_layouts = new Dictionary();
for each (var n:XML in data.layout) {
var layoutDefinition:LayoutDefinition = new LayoutDefinition();
layoutDefinition.load(n);
@ -68,6 +70,10 @@ package org.bigbluebutton.modules.layout.managers
return _layouts;
}
public function append(layoutDefinition:LayoutDefinition):void {
_layouts[layoutDefinition.name] = layoutDefinition;
}
public function getDefault():LayoutDefinition {
for each (var value:LayoutDefinition in _layouts) {
if (value.default_)
@ -79,5 +85,13 @@ package org.bigbluebutton.modules.layout.managers
public function getLayout(name:String):LayoutDefinition {
return _layouts[name];
}
public function toXml():XML {
var xml:XML = <layouts/>;
for each (var value:LayoutDefinition in _layouts) {
xml.appendChild(value.toXml());
}
return xml;
}
}
}

View File

@ -52,15 +52,15 @@ package org.bigbluebutton.modules.layout.model {
return windows[name];
}
public function toXml():String {
var r:String = "<layout name=\"" + name +
(default_? " default=\"true\"": "") +
" \">";
public function toXml():XML {
var xml:XML = <layout/>;
xml.@name = name;
if (default_)
xml.@default = true;
for each (var value:WindowLayout in windows) {
r += "\n\t" + value.toXml();
xml.appendChild(value.toXml());
}
r += "\n</layout>";
return r;
return xml;
}
public function applyToCanvas(canvas:MDICanvas):void {

View File

@ -157,26 +157,36 @@ package org.bigbluebutton.modules.layout.model {
}
}
public function toAbsoluteXml(canvas:MDICanvas):String {
return "<window name=\"" + name + "\"" +
(minimized? " minimized=\"true\"":
(maximized? " maximized=\"true\"":
" width=\"" + int(width * canvas.width) + "\"" +
" height=\"" + int(height * canvas.height) + "\"" +
" x=\"" + int(x * canvas.width) + "\"" +
" y=\"" + int(y * canvas.height) + "\"")) +
" />";
public function toAbsoluteXml(canvas:MDICanvas):XML {
var xml:XML = <window/>;
xml.@name = name;
if (minimized)
xml.@minimized = true;
else if (maximized)
xml.@maximized = true;
else {
xml.@width = int(width * canvas.width);
xml.@height = int(height * canvas.height);
xml.@x = int(x * canvas.width);
xml.@y = int(y * canvas.height);
}
return xml;
}
public function toXml():String {
return "<window name=\"" + name + "\"" +
(minimized? " minimized=\"true\"":
(maximized? " maximized=\"true\"":
" width=\"" + width + "\"" +
" height=\"" + height + "\"" +
" x=\"" + x + "\"" +
" y=\"" + y + "\"")) +
" />";
public function toXml():XML {
var xml:XML = <window/>;
xml.@name = name;
if (minimized)
xml.@minimized = true;
else if (maximized)
xml.@maximized = true;
else {
xml.@width = width;
xml.@height = height;
xml.@x = x;
xml.@y = y;
}
return xml;
}
}
}

View File

@ -39,6 +39,8 @@
import mx.controls.Alert;
import mx.events.ResizeEvent;
import flash.net.FileReference;
import flexlib.mdi.managers.MDIManager;
import flexlib.mdi.containers.MDICanvas;
import flexlib.mdi.containers.MDIWindow;
@ -65,6 +67,12 @@
private var _previousLayout:int = -1;
private var _defaultLayout:int = -1;
private var _defaultLayoutTimer:Timer = new Timer(500, 1);
private var _customLayoutNumber:int = 0;
private var _firstTime:Boolean = true;
private var ADD_LAYOUT:String = "Add layout to list";
private var SAVE_LAYOUTS:String = "Save layouts to disk";
private var LOAD_LAYOUTS:String = "Load layouts from disk";
private function init():void{
_mdiCanvas = getMdiCanvas(parent) as MDICanvas;
@ -108,6 +116,13 @@
private function populateComboBox(e:LayoutsLoadedEvent):void {
_layouts = e.layouts;
updateComboBox();
if (_firstTime)
applyDefaultLayout();
_firstTime = false;
}
private function updateComboBox():void {
dataProvider.removeAll();
for each (var value:LayoutDefinition in _layouts.dict) {
var item:Object = {label:value.name};
@ -115,10 +130,27 @@
if (value.default_)
_defaultLayout = dataProvider.getItemIndex(item);
}
dataProvider.addItem({label:ResourceUtil.getInstance().getString('bbb.layout.copy')});
applyDefaultLayout();
dataProvider.addItem(null);
dataProvider.addItem({label:ADD_LAYOUT});
dataProvider.addItem({label:SAVE_LAYOUTS});
dataProvider.addItem({label:LOAD_LAYOUTS});
//dataProvider.addItem({label:ResourceUtil.getInstance().getString('bbb.layout.copy')});
}
private function selectHandler(e:Event):void {
var file:FileReference = FileReference(e.target);
LogUtil.debug("==================================> loading");
file.load();
}
private function completeHandler(e:Event):void {
LogUtil.debug("==================================> completeHandler");
var loader:Loader = new Loader();
loader.loadBytes(e.target.data);
addChild(loader);
_layouts.completeHandler(e);
}
private function applyDefaultLayout(event:TimerEvent = null):void {
if (_defaultLayout != -1 && _mdiCanvas != null && selectedIndex != _defaultLayout) {
selectedIndex = _defaultLayout;
@ -137,6 +169,8 @@
private function setupWindowListener(window:MDIWindow):void {
window.addEventListener(MDIWindowEvent.RESIZE_START, invalidateLayout);
window.addEventListener(MDIWindowEvent.DRAG_START, invalidateLayout);
window.addEventListener(MDIWindowEvent.MINIMIZE, invalidateLayout);
window.addEventListener(MDIWindowEvent.MAXIMIZE, invalidateLayout);
}
private function invalidateLayout(e:Event):void {
@ -153,15 +187,31 @@
}
private function changeLayout(label:String):void {
if (label == ResourceUtil.getInstance().getString('bbb.layout.copy')) {
var file:FileReference;
if (label == ADD_LAYOUT) {
_customLayoutNumber += 1;
_layouts.append(LayoutDefinition.getLayout(_mdiCanvas, "Custom layout " + _customLayoutNumber));
updateComboBox();
prompt = ResourceUtil.getInstance().getString('bbb.layout.prompt');
selectedIndex = -1;
} else if (label == SAVE_LAYOUTS) {
file = new FileReference();
file.save(_layouts.toXml().toXMLString(), "layouts.xml");
selectedIndex = _previousLayout;
} else if (label == LOAD_LAYOUTS) {
file = new FileReference();
file.addEventListener(Event.SELECT, selectHandler);
file.addEventListener(Event.COMPLETE, completeHandler);
file.browse();
selectedIndex = _previousLayout;
} else if (label == ResourceUtil.getInstance().getString('bbb.layout.copy')) {
var name:String;
if (_previousLayout != -1)
name = dataProvider.getItemAt(_previousLayout).label;
else
name = "Custom layout";
System.setClipboard(LayoutDefinition.getLayout(_mdiCanvas, name).toXml());
System.setClipboard(LayoutDefinition.getLayout(_mdiCanvas, name).toXml().toXMLString());
Alert.show(ResourceUtil.getInstance().getString('bbb.layout.copied'), "", Alert.OK, this);
selectedIndex = _previousLayout;
} else {
_currentLayout = _layouts.getLayout(label);
_currentLayout.applyToCanvas(_mdiCanvas);