Skip to content

Commit 5fc4b48

Browse files
committed
Module visualization added, Module messages to mediators, commands shown. Sample app improved.
1 parent 78adc75 commit 5fc4b48

File tree

10 files changed

+243
-76
lines changed

10 files changed

+243
-76
lines changed

mvcExpressLogger/com/mindscriptact/mvcExpressLogger/MvcExpressLogger.as

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import org.mvcexpress.MvcExpress;
2424
*/
2525
public class MvcExpressLogger {
2626

27-
static private const LOG_LABEL:String = "LOG";
28-
static private const MESSAGES_LABEL:String = "MESSAGES";
29-
static private const MEDIATORS_LABEL:String = "MEDIATORS";
30-
static private const PROXIES_LABEL:String = "PROXIES";
31-
static private const COMMANDS_LABEL:String = "COMMANDS";
32-
static private const VISUALIZER_LABEL:String = "VISUALIZER";
27+
static public const LOG_TAB:String = "LOG";
28+
static public const MESSAGES_TAB:String = "MESSAGES";
29+
static public const MEDIATORS_TAB:String = "MEDIATORS";
30+
static public const PROXIES_TAB:String = "PROXIES";
31+
static public const COMMANDS_TAB:String = "COMMANDS";
32+
static public const VISUALIZER_TAB:String = "VISUALIZER";
3333
//
3434
static private var allowInstantiation:Boolean;
3535
static private var instance:MvcExpressLogger;
@@ -62,14 +62,15 @@ public class MvcExpressLogger {
6262
private var isRenderWaiting:Boolean = false;
6363
private var autoLogCheckBox:CheckBox;
6464
private var useAutoScroll:Boolean = true;
65+
private var initTab:String;
6566

6667
public function MvcExpressLogger() {
6768
if (!allowInstantiation) {
6869
throw Error("MvcExpressLogger is singleton and will be instantiated with first use or MvcExpressLogger.init() or MvcExpressLogger.showIn()");
6970
}
7071
}
7172

72-
static public function init(stage:Stage, x:int = 0, y:int = 0, width:int = 600, height:int = 400, alpha:Number = 0.9, autoShow:Boolean = false, openKeyCode:int = 192, isCtrlKeyNeeded:Boolean = true, isShiftKeyNeeded:Boolean = false, isAltKeyNeeded:Boolean = false):void {
73+
static public function init(stage:Stage, x:int = 0, y:int = 0, width:int = 600, height:int = 400, alpha:Number = 0.9, autoShow:Boolean = false, initTab:String = "LOG", openKeyCode:int = 192, isCtrlKeyNeeded:Boolean = true, isShiftKeyNeeded:Boolean = false, isAltKeyNeeded:Boolean = false):void {
7374

7475
if (!instance) {
7576
allowInstantiation = true;
@@ -86,6 +87,7 @@ public class MvcExpressLogger {
8687
instance.width = width;
8788
instance.height = height;
8889
instance.alpha = alpha;
90+
instance.initTab = initTab;
8991
instance.openKeyCode = openKeyCode;
9092
instance.isCtrlKeyNeeded = isCtrlKeyNeeded;
9193
instance.isShiftKeyNeeded = isShiftKeyNeeded;
@@ -130,42 +132,42 @@ public class MvcExpressLogger {
130132
setTimeout(resolveCurrentModuleName, 1);
131133
} else {
132134
switch (currentTabButtonName) {
133-
case LOG_LABEL:
135+
case LOG_TAB:
134136
render();
135137
break;
136-
case MESSAGES_LABEL:
138+
case MESSAGES_TAB:
137139
if (logType == "••" || logType == "•>") {
138140
if (!isRenderWaiting) {
139141
isRenderWaiting = true;
140142
setTimeout(render, 1);
141143
}
142144
}
143145
break;
144-
case MEDIATORS_LABEL:
146+
case MEDIATORS_TAB:
145147
if (logType == "§§") {
146148
if (!isRenderWaiting) {
147149
isRenderWaiting = true;
148150
setTimeout(render, 1);
149151
}
150152
}
151153
break;
152-
case PROXIES_LABEL:
154+
case PROXIES_TAB:
153155
if (logType == "¶¶") {
154156
if (!isRenderWaiting) {
155157
isRenderWaiting = true;
156158
setTimeout(render, 1);
157159
}
158160
}
159161
break;
160-
case COMMANDS_LABEL:
162+
case COMMANDS_TAB:
161163
if (logType == "©©") {
162164
if (!isRenderWaiting) {
163165
isRenderWaiting = true;
164166
setTimeout(render, 1);
165167
}
166168
}
167169
break;
168-
case VISUALIZER_LABEL:
170+
case VISUALIZER_TAB:
169171
break;
170172
default:
171173
}
@@ -213,31 +215,31 @@ public class MvcExpressLogger {
213215

214216
allButtons = new Vector.<PushButton>();
215217

216-
var logButton:PushButton = new PushButton(logWindow, 0, -0, LOG_LABEL, handleButtonClick);
218+
var logButton:PushButton = new PushButton(logWindow, 0, -0, LOG_TAB, handleButtonClick);
217219
logButton.toggle = true;
218220
logButton.width = 50;
219221
logButton.x = moduleStepper.x + moduleStepper.width + 10;
220222
allButtons.push(logButton);
221223

222-
var messageMapingButton:PushButton = new PushButton(logWindow, 0, -0, MESSAGES_LABEL, handleButtonClick);
224+
var messageMapingButton:PushButton = new PushButton(logWindow, 0, -0, MESSAGES_TAB, handleButtonClick);
223225
messageMapingButton.toggle = true;
224226
messageMapingButton.width = 60;
225227
messageMapingButton.x = allButtons[allButtons.length - 1].x + allButtons[allButtons.length - 1].width + 5;
226228
allButtons.push(messageMapingButton);
227229

228-
var mediatorMapingButton:PushButton = new PushButton(logWindow, 0, -0, MEDIATORS_LABEL, handleButtonClick);
230+
var mediatorMapingButton:PushButton = new PushButton(logWindow, 0, -0, MEDIATORS_TAB, handleButtonClick);
229231
mediatorMapingButton.toggle = true;
230232
mediatorMapingButton.width = 60;
231233
mediatorMapingButton.x = allButtons[allButtons.length - 1].x + allButtons[allButtons.length - 1].width + 5;
232234
allButtons.push(mediatorMapingButton);
233235

234-
var proxyMapingButton:PushButton = new PushButton(logWindow, 0, -0, PROXIES_LABEL, handleButtonClick);
236+
var proxyMapingButton:PushButton = new PushButton(logWindow, 0, -0, PROXIES_TAB, handleButtonClick);
235237
proxyMapingButton.toggle = true;
236238
proxyMapingButton.width = 50;
237239
proxyMapingButton.x = allButtons[allButtons.length - 1].x + allButtons[allButtons.length - 1].width + 5;
238240
allButtons.push(proxyMapingButton);
239241

240-
var commandMapingButton:PushButton = new PushButton(logWindow, 0, -0, COMMANDS_LABEL, handleButtonClick);
242+
var commandMapingButton:PushButton = new PushButton(logWindow, 0, -0, COMMANDS_TAB, handleButtonClick);
241243
commandMapingButton.toggle = true;
242244
commandMapingButton.width = 60;
243245
commandMapingButton.x = allButtons[allButtons.length - 1].x + allButtons[allButtons.length - 1].width + 5;
@@ -252,7 +254,7 @@ public class MvcExpressLogger {
252254
autoLogCheckBox.x = allButtons[allButtons.length - 1].x + allButtons[allButtons.length - 1].width + 70;
253255
autoLogCheckBox.selected = true;
254256

255-
var visualizerButton:PushButton = new PushButton(logWindow, 0, -0, VISUALIZER_LABEL, handleButtonClick);
257+
var visualizerButton:PushButton = new PushButton(logWindow, 0, -0, VISUALIZER_TAB, handleButtonClick);
256258
visualizerButton.toggle = true;
257259
visualizerButton.width = 60;
258260
visualizerButton.x = 600;
@@ -264,7 +266,19 @@ public class MvcExpressLogger {
264266

265267
resolveCurrentModuleName();
266268

267-
handleButtonClick();
269+
delayedAutoButtonClick()
270+
}
271+
272+
private function delayedAutoButtonClick():void {
273+
if (!currentTabButtonName) {
274+
resolveCurrentModuleName();
275+
if (currentModuleName != "") {
276+
handleButtonClick();
277+
} else {
278+
setTimeout(delayedAutoButtonClick, 100);
279+
}
280+
}
281+
268282
}
269283

270284
private function handleClearLog(event:MouseEvent):void {
@@ -319,8 +333,17 @@ public class MvcExpressLogger {
319333
if (event) {
320334
var targetButton:PushButton = (event.target as PushButton);
321335
} else {
336+
// select first button by default.
322337
targetButton = allButtons[0];
323338
targetButton.selected = true;
339+
// if initTab properly passed - start with that tab.
340+
for (var j:int = 0; j < allButtons.length; j++) {
341+
if (allButtons[j].label == initTab) {
342+
targetButton = allButtons[j];
343+
targetButton.selected = true;
344+
break;
345+
}
346+
}
324347
}
325348

326349
if (currentTogleButton != targetButton) {
@@ -337,10 +360,10 @@ public class MvcExpressLogger {
337360
}
338361
currentTabButtonName = targetButton.label;
339362

340-
autoLogCheckBox.visible = (currentTabButtonName == LOG_LABEL)
363+
autoLogCheckBox.visible = (currentTabButtonName == LOG_TAB)
341364

342365
switch (currentTabButtonName) {
343-
case VISUALIZER_LABEL:
366+
case VISUALIZER_TAB:
344367
currentScreen = new MvcExpressVisualizerScreen(width - 6, height - 52);
345368
currentScreen.x = 3;
346369
currentScreen.y = 25;
@@ -368,27 +391,27 @@ public class MvcExpressLogger {
368391
isRenderWaiting = false;
369392

370393
switch (currentTabButtonName) {
371-
case LOG_LABEL:
394+
case LOG_TAB:
372395
(currentScreen as MvcExpressLogScreen).showLog(logText);
373396
(currentScreen as MvcExpressLogScreen).scrollDown(useAutoScroll);
374397
break;
375-
case MESSAGES_LABEL:
398+
case MESSAGES_TAB:
376399
(currentScreen as MvcExpressLogScreen).showLog(ModuleManager.listMappedMessages(currentModuleName));
377400
(currentScreen as MvcExpressLogScreen).scrollDown(false);
378401
break;
379-
case MEDIATORS_LABEL:
402+
case MEDIATORS_TAB:
380403
(currentScreen as MvcExpressLogScreen).showLog(ModuleManager.listMappedMediators(currentModuleName));
381404
(currentScreen as MvcExpressLogScreen).scrollDown(false);
382405
break;
383-
case PROXIES_LABEL:
406+
case PROXIES_TAB:
384407
(currentScreen as MvcExpressLogScreen).showLog(ModuleManager.listMappedProxies(currentModuleName));
385408
(currentScreen as MvcExpressLogScreen).scrollDown(false);
386409
break;
387-
case COMMANDS_LABEL:
410+
case COMMANDS_TAB:
388411
(currentScreen as MvcExpressLogScreen).showLog(ModuleManager.listMappedCommands(currentModuleName));
389412
(currentScreen as MvcExpressLogScreen).scrollDown(false);
390413
break;
391-
case VISUALIZER_LABEL:
414+
case VISUALIZER_TAB:
392415

393416
break;
394417
default:

mvcExpressLogger/com/mindscriptact/mvcExpressLogger/screens/MvcExpressVisualizerScreen.as

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public class MvcExpressVisualizerScreen extends Sprite {
1414
private var mediators:Vector.<Object>;
1515
private var proxies:Vector.<Object>;
1616
private var commands:Vector.<Object> = new Vector.<Object>();
17+
private var currentModuleName:String;
18+
private var moduleLabel:Label;
19+
static private const PROXY_START_X:Number = 600;
20+
static private const MEDIATOR_END_X:Number = 300;
21+
static private const COMMAND_MIDDLE_X:Number = (PROXY_START_X + MEDIATOR_END_X) / 2;
1722

1823
public function MvcExpressVisualizerScreen(screenWidth:int, screenHeight:int) {
1924
this.screenWidth = screenWidth;
@@ -31,6 +36,28 @@ public class MvcExpressVisualizerScreen extends Sprite {
3136
trace("MvcExpressVisualizerScreen.updateProxies > listMappedProxies : " + listMappedProxies);
3237
}
3338

39+
//----------------------------------
40+
// module
41+
//----------------------------------
42+
43+
public function showModule(currentModuleName:String):void {
44+
this.currentModuleName = currentModuleName;
45+
// remove old
46+
if (moduleLabel) {
47+
this.removeChild(moduleLabel);
48+
}
49+
moduleLabel = new Label(this, 0, 15, "MODULE:" + currentModuleName);
50+
moduleLabel.textField.borderColor = 0xFFFFFF;
51+
moduleLabel.textField.border = true;
52+
moduleLabel.x = COMMAND_MIDDLE_X - moduleLabel.width / 2;
53+
//
54+
var rectangle:Shape = new Shape();
55+
rectangle.graphics.lineStyle(3, 0xFFFFFF);
56+
rectangle.graphics.drawRect(-3, -3, moduleLabel.width + 6, moduleLabel.height + 6);
57+
moduleLabel.addChild(rectangle);
58+
59+
}
60+
3461
//----------------------------------
3562
// mediators
3663
//----------------------------------
@@ -69,7 +96,7 @@ public class MvcExpressVisualizerScreen extends Sprite {
6996
}
7097
mediatorLabel = mediatorLogObj.view;
7198
//
72-
mediatorLabel.x = 300 - mediatorLabel.width;
99+
mediatorLabel.x = MEDIATOR_END_X - mediatorLabel.width;
73100
mediatorLabel.y = (mediators.length - 1) * 20 + 50;
74101
this.addChild(mediatorLabel);
75102
}
@@ -115,6 +142,28 @@ public class MvcExpressVisualizerScreen extends Sprite {
115142
if (mediators[possition]) {
116143
var mediatorLabel:Label = mediators[possition].view;
117144
if (mediatorLabel) {
145+
// handle message from module
146+
messageFromObject = messageLogObj.messageFromModule;
147+
if (messageFromObject) {
148+
if (moduleLabel) {
149+
messageShape = new Shape();
150+
messageShape.graphics.lineStyle(2, 0xE8E8E8, 0.3);
151+
messageShape.graphics.lineTo(40, (moduleLabel.y - mediatorLabel.y) * 0.2);
152+
messageShape.graphics.lineTo(60, (moduleLabel.y - mediatorLabel.y) * 0.8);
153+
messageShape.graphics.lineTo(moduleLabel.x - mediatorLabel.x - mediatorLabel.width, moduleLabel.y - mediatorLabel.y);
154+
155+
messageShape.graphics.moveTo(0, 0);
156+
messageShape.graphics.lineTo(10, -2);
157+
messageShape.graphics.lineTo(10, 2);
158+
messageShape.graphics.lineTo(0, 0);
159+
160+
messageShape.x = mediatorLabel.width;
161+
messageShape.y = 10;
162+
mediatorLabel.addChild(messageShape);
163+
164+
setTimeout(hideShape, 1500, messageShape);
165+
}
166+
}
118167
// handle message from mediator
119168
messageFromObject = messageLogObj.messageFromMediator;
120169
if (messageFromObject) {
@@ -154,7 +203,7 @@ public class MvcExpressVisualizerScreen extends Sprite {
154203
messageShape = new Shape();
155204
messageShape.graphics.lineStyle(2, 0xD2D2FF, 0.3);
156205
//messageShape.graphics.lineTo(50, (sourceProxyLabel.y - mediatorLabel.y) * 0.2);
157-
messageShape.graphics.lineTo(600 - 300, sourceProxyLabel.y - mediatorLabel.y);
206+
messageShape.graphics.lineTo(PROXY_START_X - MEDIATOR_END_X, sourceProxyLabel.y - mediatorLabel.y);
158207

159208
messageShape.graphics.moveTo(0, 0);
160209
messageShape.graphics.lineTo(10, -2);
@@ -182,7 +231,7 @@ public class MvcExpressVisualizerScreen extends Sprite {
182231
messageShape = new Shape();
183232
messageShape.graphics.lineStyle(2, 0xD2D2FF, 0.3);
184233
messageShape.graphics.lineTo(50, (sourceCommandLabel.y - mediatorLabel.y) * 0.2);
185-
messageShape.graphics.lineTo(450 - 300 - sourceCommandLabel.width / 2, sourceCommandLabel.y - mediatorLabel.y);
234+
messageShape.graphics.lineTo(COMMAND_MIDDLE_X - MEDIATOR_END_X - sourceCommandLabel.width / 2, sourceCommandLabel.y - mediatorLabel.y);
186235

187236
messageShape.graphics.moveTo(0, 0);
188237
messageShape.graphics.lineTo(10, -2);
@@ -247,7 +296,7 @@ public class MvcExpressVisualizerScreen extends Sprite {
247296
}
248297
proxyLabel = proxyLogObj.view;
249298
//
250-
proxyLabel.x = 600;
299+
proxyLabel.x = PROXY_START_X;
251300
proxyLabel.y = (proxies.length - 1) * 20 + 50;
252301
this.addChild(proxyLabel);
253302
}
@@ -316,10 +365,27 @@ public class MvcExpressVisualizerScreen extends Sprite {
316365
}
317366
commandLabel = commandLogObj.view;
318367
//
319-
commandLabel.x = 450 - (commandLabel.width >> 1);
368+
commandLabel.x = COMMAND_MIDDLE_X - (commandLabel.width >> 1);
320369
commandLabel.y = commandPosition * 20 + 60;
321370
this.addChild(commandLabel);
322371

372+
// handle message from module
373+
messageFromObject = commandLogObj.messageFromModule;
374+
if (messageFromObject) {
375+
if (moduleLabel) {
376+
commandLabel.graphics.lineStyle(2, 0xFFFFD9, 0.3);
377+
commandLabel.graphics.moveTo(0, 10);
378+
commandLabel.graphics.lineTo(-30, moduleLabel.y - commandLabel.y * 0.2);
379+
commandLabel.graphics.lineTo(-20, moduleLabel.y - commandLabel.y * 0.8);
380+
commandLabel.graphics.lineTo( -commandLabel.x + moduleLabel.x, -commandLabel.y + moduleLabel.y + moduleLabel.height - 10);
381+
382+
commandLabel.graphics.moveTo(0, 10);
383+
commandLabel.graphics.lineTo(-10, 10 - 2);
384+
commandLabel.graphics.lineTo(-10, 10 + 2);
385+
commandLabel.graphics.lineTo(0, 10);
386+
}
387+
}
388+
323389
// handle message from mediator
324390
messageFromObject = commandLogObj.messageFromMediator;
325391
if (messageFromObject) {
@@ -339,6 +405,7 @@ public class MvcExpressVisualizerScreen extends Sprite {
339405
}
340406
}
341407
}
408+
342409
// handle message from proxy
343410
messageFromObject = commandLogObj.messageFromProxy;
344411
if (messageFromObject) {
@@ -369,12 +436,11 @@ public class MvcExpressVisualizerScreen extends Sprite {
369436
if (anotherCommandLabel) {
370437
commandLabel.graphics.lineStyle(2, 0xFFFFD9, 0.3);
371438
commandLabel.graphics.moveTo(0, 10);
372-
commandLabel.graphics.lineTo( - anotherCommandLabel.width / 2 + commandLabel.width / 2 - 30, //
439+
commandLabel.graphics.lineTo(-anotherCommandLabel.width / 2 + commandLabel.width / 2 - 30, //
373440
//-commandLabel.y + anotherCommandLabel.y + anotherCommandLabel.height - 10 //
374-
5
375-
);
376-
377-
commandLabel.graphics.lineTo( - anotherCommandLabel.width / 2 + commandLabel.width / 2, //
441+
5);
442+
443+
commandLabel.graphics.lineTo(-anotherCommandLabel.width / 2 + commandLabel.width / 2, //
378444
-commandLabel.y + anotherCommandLabel.y + anotherCommandLabel.height - 10 //
379445
);
380446

0 commit comments

Comments
 (0)