#REFACTORING by stefan
class: JavaVM class
changed: #loadClassesIn:matching:
use \"asFilename pathName\" instead of \"asFilename asAbsoluteFilename pathName\"
ist is equivalent!
"{ Package: 'stx:libjava/examples/chat' }"
ApplicationModel subclass:#Chat
instanceVariableNames:'client'
classVariableNames:''
poolDictionaries:''
category:'stx-libjava-examples-chat'
!
!Chat class methodsFor:'interface specs'!
windowSpec
"This resource specification was automatically generated
by the UIPainter of ST/X."
"Do not manually edit this!! If it is corrupted,
the UIPainter may not be able to read the specification."
"
UIPainter new openOnClass:Chat andSelector:#windowSpec
Chat new openInterface:#windowSpec
Chat open
"
<resource: #canvas>
^
#(FullSpec
name: windowSpec
window:
(WindowSpec
label: 'ChatStartup'
name: 'ChatStartup'
min: (Point 10 10)
bounds: (Rectangle 0 0 300 300)
menu: mainMenu
)
component:
(SpecCollection
collection: (
(ViewSpec
name: 'Box2'
layout: (LayoutFrame 0 0 -26 1 0 1 0 1)
level: 1
component:
(SpecCollection
collection: (
(LabelSpec
label: 'InfoLabel'
name: 'Label2'
layout: (LayoutFrame 0 0 -26 1 -1 1 0 1)
level: -1
translateLabel: true
labelChannel: infoLabelHolder
adjust: left
)
)
)
)
)
)
)
! !
!Chat class methodsFor:'menu specs'!
mainMenu
"This resource specification was automatically generated
by the MenuEditor of ST/X."
"Do not manually edit this!! If it is corrupted,
the MenuEditor may not be able to read the specification."
"
MenuEditor new openOnClass:Chat andSelector:#mainMenu
(Menu new fromLiteralArrayEncoding:(Chat mainMenu)) startUp
"
<resource: #menu>
^
#(Menu
(
(MenuItem
label: 'Buddies'
submenu:
(Menu
(
(MenuItem
enabled: isConnected
label: 'Chat with...'
itemValue: menuChatWith
)
(MenuItem
label: '-'
)
(MenuItem
enabled: isDisconnected
label: 'Connect...'
itemValue: menuConnect
)
(MenuItem
enabled: isConnected
label: 'Disconnect'
itemValue: menuDisconnect
)
(MenuItem
label: '-'
)
(MenuItem
label: 'Exit'
itemValue: closeRequest
)
)
nil
nil
)
)
(MenuItem
label: 'Help'
startGroup: right
submenu:
(Menu
(
(MenuItem
label: 'Documentation'
itemValue: openDocumentation
)
(MenuItem
label: '-'
)
(MenuItem
label: 'About this Application...'
itemValue: openAboutThisApplication
)
)
nil
nil
)
)
)
nil
nil
)
"Modified: / 23-09-2013 / 23:12:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
toolbarMenu
"This resource specification was automatically generated by the CodeGeneratorTool."
"Do not manually edit this!! If it is corrupted,
the MenuEditor may not be able to read the specification."
"
MenuEditor new openOnClass:ChatStartup andSelector:#toolbarMenu
"
<resource: #menu>
^ #(Menu ((MenuItem label: 'Reload' itemValue: menuReload isButton: true labelImage: (ResourceRetriever ToolbarIconLibrary reload24x24Icon))) nil nil)
! !
!Chat methodsFor:'initialization & release'!
closeDownViews
"This is a hook method generated by the Browser/CodeGeneratorTool.
It will be invoked when your app/dialog-window is really closed.
See also #closeDownViews, which is invoked before and may suppress the close
or ask the user for confirmation."
"/ change the code below as required ...
"/ This should cleanup any leftover resources
"/ (for example, temporary files)
"/ super closeRequest will initiate the closeDown
"/ add your code here
"/ do not remove the one below ...
^ super closeDownViews
!
postBuildWith:aBuilder
"This is a hook method generated by the Browser/CodeGeneratorTool.
It will be invoked during the initialization of your app/dialog,
after all of the visual components have been built,
but BEFORE the top window is made visible.
Add any app-specific actions here (reading files, setting up values etc.)
See also #postOpenWith:, which is invoked after opening."
"/ add any code here ...
^ super postBuildWith:aBuilder
!
postOpenWith:aBuilder
"This is a hook method generated by the Browser/CodeGeneratorTool.
It will be invoked right after the applications window has been opened.
Add any app-specific actions here (starting background processes etc.).
See also #postBuildWith:, which is invoked before opening."
"/ add any code here ...
^ super postOpenWith:aBuilder
! !
!Chat methodsFor:'menu actions'!
menuChatWith
| id |
id := Dialog request: 'Jabber ID to chat with' initialAnswer:'janfrog@jabber.cz/neso'.
id notEmptyOrNil ifTrue:[
self menuChatWith: id.
]
"Created: / 23-09-2013 / 22:47:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
menuChatWith:id
ChatWindow new
buddy: id;
client: client;
open.
"Created: / 23-09-2013 / 22:47:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
menuConnect
| dialog server username password |
server := 'jabber.cz' asValue.
username := 'janfrog' asValue.
password := nil asValue.
dialog := Dialog new.
dialog addLabelledInputField: 'Server' adjust: #left on: server tabable: true separateAtX: 0.3.
dialog addLabelledInputField: 'Username' adjust: #left on: username tabable: true separateAtX: 0.3.
(dialog addLabelledInputField: 'Password' adjust: #left on: password tabable: true separateAtX: 0.3)
bePassword.
dialog addOkButton.
dialog addAbortButton.
dialog open.
dialog accepted ifFalse:[ ^ self ].
client := JAVA stx libjava examples chat SimpleClient new.
client connect: server value username: username value password: password value.
"Created: / 23-09-2013 / 23:02:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
menuDisconnect
client disconnect.
client := nil.
"Created: / 23-09-2013 / 23:02:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
openAboutThisApplication
"This method was generated by the Browser/CodeGeneratorTool.
It will be invoked when the menu-item 'help-about' is selected."
"/ could open a customized aboutBox here ...
super openAboutThisApplication
!
openDocumentation
"This method was generated by the Browser/CodeGeneratorTool.
It will be invoked when the menu-item 'help-documentation' is selected."
"/ change below as required ...
"/ to open an HTML viewer on some document (under 'doc/online/<language>/' ):
self openDocumentationFile:'TOP.html'.
"/ add application-specific help files under the 'doc/online/<language>/help/appName'
"/ directory, and open a viewer with:
"/ self openDocumentationFile:'help/<MyApplication>/TOP.html'.
! !
!Chat methodsFor:'menu-queries'!
isConnected
^ client notNil and:[client isConnected].
"Created: / 23-09-2013 / 23:03:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
isDisconnected
^ self isConnected not
"Created: / 24-09-2013 / 00:09:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !