move old files into a directory for reference
[webos-internals:applications.git] / org.webosinternals.terminal / old / app / controllers / term-assistant.js
1 ansiBlack               = 0;
2 ansiLightRed            = 1;
3 ansiLightGreen          = 2;
4 ansiYellow              = 3;
5 ansiLightBlue           = 4;
6 ansiLightMagenta        = 5;
7 ansiLightCyan           = 6;
8 ansiHighWhite           = 7;
9
10 normal_width=320
11 normal_height=452-52
12 landscape_width=480
13 landscape_height=320-52
14 scrollHeight=1000; //   change to comfort level
15
16 // this is the desired font size
17 // fontHeight=6; fontWidth=4;
18 //fontHeight=8; fontWidth=8;
19
20 Prefs = {
21   fontHeight: 8,
22   fontWidth: 8,
23   fgColor: ansiLightMagenta,
24   bgColor: ansiBlack
25 };
26
27 var TermAssistant = Class.create( {
28
29         setup : function() {
30
31                 document.addEventListener("keydown", this.onKeyDown, true);
32                 document.addEventListener("keyup", this.onKeyUp, true);
33                 document.addEventListener("gesturestart", this.gestureStartHandler, true );
34                 document.addEventListener("gesturechange", this.gestureChangeHandler, true );
35                 document.addEventListener("gestureend", this.gestureEndHandler, true );
36
37                 //App Menu - Remove default items and add only Help items.
38                 var appMenuModel = {
39                         visible: false,
40                         items: [
41                                 {label: $L("New Session..."), command: "do-newSession"},
42                                 {label: $L("Preferences..."), command: "do-prefs"},
43                         ]
44                 };
45                 this.controller.setupWidget(Mojo.Menu.appMenu, {omitDefaultItems:true}, appMenuModel);
46                 this.controller.window.PalmSystem.setWindowOrientation('free');
47
48                 /*this.controller.setupWidget(
49                         "scrollerId",
50                         this.attributes = { mode: 'vertical' },
51                         this.model = { }
52                 );*/
53
54                 // Create plugin
55                 termPlugin = document.createElement('object');
56                 termPlugin.type = 'application/x-webosinternals-termplugin';
57                 termPlugin.width = normal_width;
58                 //termPlugin.height = normal_height;
59                 var fontHeight = Prefs.fontHeight;
60                 var fontWidth = Prefs.fontWidth;
61                 full_height = scrollHeight * fontHeight;
62                 termPlugin.height = full_height;
63                 this.onTap = this.onTap.bind(this);
64                 document.addEventListener(Mojo.Event.tap,this.onTap,true);
65                 //this.onMouseDown = this.onMouseDown.bind(this);
66                 Mojo.Event.listen(termPlugin,'mousedown',this.onMouseDown,true);
67                 Mojo.Event.listen(termPlugin,'mouseup',this.onMouseUp,true);
68                 Mojo.Event.listen(termPlugin,'flick',this.onFlick,true);
69                 //Mojo.Event.listen(sampleAdapterApp,'mouseup',this._adapterMouseUp,true);
70                 //Mojo.Event.listen(sampleAdapterApp,'mousemove',this._adapterMouseMove,true);
71
72                 // Listen for callback
73                 termPlugin.eventListener = this;
74
75                 // Embed plugin into scene
76                 var placeholder = document.getElementById('install_object_here');
77                 placeholder.parentNode.replaceChild(termPlugin,placeholder);
78                 //full_height = scrollHeight * fontHeight;
79                 //termPlugin.height = full_height;
80                 //termPlugin.setTerminalHeight(normal_height);
81
82                 //this.modesModel = {scrollbars:true,mode:"free"};
83                 //this.controller.setupWidget('scrollerId',{},this.modesModel);
84                 scroller=this.controller.get('scrollerId')
85                 // for some reason the height is 5 pixels less than what we ask for 
86         },
87
88         orientationChanged : function(orientation) {
89                 var new_height;
90                 if (orientation==="left" || orientation==="right") {
91                         termPlugin.width = landscape_width;
92                         new_height = landscape_height;
93                 } else {
94                         termPlugin.width = normal_width;
95                         new_height = normal_height;
96                 }
97                 termPlugin.setTerminalHeight(new_height);
98                 scroller.setStyle({"height":new_height+5+"px"});
99                 if (scroller.mojo) {
100                         scroller.mojo.revealBottom();
101                 }
102         },
103
104         activate : function (event) { 
105                termPlugin.initialize();
106                termPlugin.setColors(Prefs.fgColor, Prefs.bgColor);
107                termPlugin.setFont(Prefs.fontWidth,Prefs.fontHeight);
108                termPlugin.focus();
109                this.orientationChanged("top");
110                scroller.mojo.revealBottom();
111         },
112
113         onTap : function (event) {
114                 //termPlugin.sendTap(event.down.screenX,event.down.screenY);
115         },
116
117         onKeyDown : function(event) {
118                 if (event.keyCode==13) {
119                         // This is the one key that won't get through to the terminal.
120                         termPlugin.sendEnter();
121                 }
122         },
123
124         gestureStartHandler : function(event) {
125                 termPlugin.sendGestureStart();
126         },
127
128         gestureEndHandler : function(event) {
129                 termPlugin.sendGestureEnd();
130         },
131
132         gestureChangeHandler : function(event) {
133                 termPlugin.sendGestureChange();
134         },
135
136         onKeyUp : function(event) {
137                 termPlugin.sendKeyUp(event.keyCode);
138         },
139
140         onKeyPress : function(event) {
141                 termPlugin.sendKeyPress(event.charCode);
142         },
143
144         onMouseDown : function(event) {
145                 termPlugin.sendMouseDown(event.screenX,event.screenY);
146         },
147
148         onMouseUp : function(event) {
149                 termPlugin.sendMouseUp(event.screenX,event.screenY);
150         },
151
152         onFlick : function(event) {
153                 termPlugin.sendFlick(event.screenX,event.screenY);
154         },
155
156         MainWindowQueueProcess : function (interval) {  
157                 this.MainWindowQueueProcessIntervalID = setInterval(function() {} ,interval);   
158         },
159
160         handleShortcut : function(which,event) {
161                 console.log('in handleShortcut');
162         },
163         
164         handleCommand : function(event) {
165                 if (event.type == Mojo.Event.command) {
166                         switch (event.command) {
167                                 case 'do-prefs':
168                                         this.controller.stageController.pushScene('prefs');
169                                         break;
170                                 case 'do-newSession':
171                                         // Do something here
172                                         break;
173                         }
174                 }
175         },
176
177 });