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> <layouts>
<layout name="Default" default="true"> <layout name="Default" default="true">
<window name="ViewersWindow" width="0.1772793053545586" height="0.33643617021276595" x="0" y="0" /> <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; import org.bigbluebutton.modules.layout.model.LayoutDefinition;
public class LayoutManager extends EventDispatcher { public class LayoutManager extends EventDispatcher {
private var _layouts:Dictionary = new Dictionary(); private var _layouts:Dictionary;
private var _dispatcher:Dispatcher = new Dispatcher(); private var _dispatcher:Dispatcher = new Dispatcher();
public function loadLayout(layoutUrl:String):void { public function loadLayout(layoutUrl:String):void {
var urlLoader:URLLoader = new URLLoader(); var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, handleComplete); urlLoader.addEventListener(Event.COMPLETE, completeHandler);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
var date:Date = new Date(); var date:Date = new Date();
try { 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); var data:XML = new XML(e.target.data);
_layouts = new Dictionary();
for each (var n:XML in data.layout) { for each (var n:XML in data.layout) {
var layoutDefinition:LayoutDefinition = new LayoutDefinition(); var layoutDefinition:LayoutDefinition = new LayoutDefinition();
layoutDefinition.load(n); layoutDefinition.load(n);
@ -68,6 +70,10 @@ package org.bigbluebutton.modules.layout.managers
return _layouts; return _layouts;
} }
public function append(layoutDefinition:LayoutDefinition):void {
_layouts[layoutDefinition.name] = layoutDefinition;
}
public function getDefault():LayoutDefinition { public function getDefault():LayoutDefinition {
for each (var value:LayoutDefinition in _layouts) { for each (var value:LayoutDefinition in _layouts) {
if (value.default_) if (value.default_)
@ -79,5 +85,13 @@ package org.bigbluebutton.modules.layout.managers
public function getLayout(name:String):LayoutDefinition { public function getLayout(name:String):LayoutDefinition {
return _layouts[name]; 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]; return windows[name];
} }
public function toXml():String { public function toXml():XML {
var r:String = "<layout name=\"" + name + var xml:XML = <layout/>;
(default_? " default=\"true\"": "") + xml.@name = name;
" \">"; if (default_)
xml.@default = true;
for each (var value:WindowLayout in windows) { for each (var value:WindowLayout in windows) {
r += "\n\t" + value.toXml(); xml.appendChild(value.toXml());
} }
r += "\n</layout>"; return xml;
return r;
} }
public function applyToCanvas(canvas:MDICanvas):void { public function applyToCanvas(canvas:MDICanvas):void {

View File

@ -157,26 +157,36 @@ package org.bigbluebutton.modules.layout.model {
} }
} }
public function toAbsoluteXml(canvas:MDICanvas):String { public function toAbsoluteXml(canvas:MDICanvas):XML {
return "<window name=\"" + name + "\"" + var xml:XML = <window/>;
(minimized? " minimized=\"true\"": xml.@name = name;
(maximized? " maximized=\"true\"": if (minimized)
" width=\"" + int(width * canvas.width) + "\"" + xml.@minimized = true;
" height=\"" + int(height * canvas.height) + "\"" + else if (maximized)
" x=\"" + int(x * canvas.width) + "\"" + xml.@maximized = true;
" y=\"" + int(y * canvas.height) + "\"")) + 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 { public function toXml():XML {
return "<window name=\"" + name + "\"" + var xml:XML = <window/>;
(minimized? " minimized=\"true\"": xml.@name = name;
(maximized? " maximized=\"true\"": if (minimized)
" width=\"" + width + "\"" + xml.@minimized = true;
" height=\"" + height + "\"" + else if (maximized)
" x=\"" + x + "\"" + xml.@maximized = true;
" y=\"" + y + "\"")) + 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.controls.Alert;
import mx.events.ResizeEvent; import mx.events.ResizeEvent;
import flash.net.FileReference;
import flexlib.mdi.managers.MDIManager; import flexlib.mdi.managers.MDIManager;
import flexlib.mdi.containers.MDICanvas; import flexlib.mdi.containers.MDICanvas;
import flexlib.mdi.containers.MDIWindow; import flexlib.mdi.containers.MDIWindow;
@ -65,6 +67,12 @@
private var _previousLayout:int = -1; private var _previousLayout:int = -1;
private var _defaultLayout:int = -1; private var _defaultLayout:int = -1;
private var _defaultLayoutTimer:Timer = new Timer(500, 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{ private function init():void{
_mdiCanvas = getMdiCanvas(parent) as MDICanvas; _mdiCanvas = getMdiCanvas(parent) as MDICanvas;
@ -108,6 +116,13 @@
private function populateComboBox(e:LayoutsLoadedEvent):void { private function populateComboBox(e:LayoutsLoadedEvent):void {
_layouts = e.layouts; _layouts = e.layouts;
updateComboBox();
if (_firstTime)
applyDefaultLayout();
_firstTime = false;
}
private function updateComboBox():void {
dataProvider.removeAll(); dataProvider.removeAll();
for each (var value:LayoutDefinition in _layouts.dict) { for each (var value:LayoutDefinition in _layouts.dict) {
var item:Object = {label:value.name}; var item:Object = {label:value.name};
@ -115,10 +130,27 @@
if (value.default_) if (value.default_)
_defaultLayout = dataProvider.getItemIndex(item); _defaultLayout = dataProvider.getItemIndex(item);
} }
dataProvider.addItem({label:ResourceUtil.getInstance().getString('bbb.layout.copy')}); dataProvider.addItem(null);
applyDefaultLayout(); 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 { private function applyDefaultLayout(event:TimerEvent = null):void {
if (_defaultLayout != -1 && _mdiCanvas != null && selectedIndex != _defaultLayout) { if (_defaultLayout != -1 && _mdiCanvas != null && selectedIndex != _defaultLayout) {
selectedIndex = _defaultLayout; selectedIndex = _defaultLayout;
@ -137,6 +169,8 @@
private function setupWindowListener(window:MDIWindow):void { private function setupWindowListener(window:MDIWindow):void {
window.addEventListener(MDIWindowEvent.RESIZE_START, invalidateLayout); window.addEventListener(MDIWindowEvent.RESIZE_START, invalidateLayout);
window.addEventListener(MDIWindowEvent.DRAG_START, invalidateLayout); window.addEventListener(MDIWindowEvent.DRAG_START, invalidateLayout);
window.addEventListener(MDIWindowEvent.MINIMIZE, invalidateLayout);
window.addEventListener(MDIWindowEvent.MAXIMIZE, invalidateLayout);
} }
private function invalidateLayout(e:Event):void { private function invalidateLayout(e:Event):void {
@ -153,15 +187,31 @@
} }
private function changeLayout(label:String):void { 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; var name:String;
if (_previousLayout != -1) if (_previousLayout != -1)
name = dataProvider.getItemAt(_previousLayout).label; name = dataProvider.getItemAt(_previousLayout).label;
else else
name = "Custom layout"; 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); Alert.show(ResourceUtil.getInstance().getString('bbb.layout.copied'), "", Alert.OK, this);
selectedIndex = _previousLayout;
} else { } else {
_currentLayout = _layouts.getLayout(label); _currentLayout = _layouts.getLayout(label);
_currentLayout.applyToCanvas(_mdiCanvas); _currentLayout.applyToCanvas(_mdiCanvas);