wip on hooking UI with core
This commit is contained in:
@@ -4,14 +4,49 @@ import griffon.core.artifact.GriffonController
|
||||
import griffon.core.controller.ControllerAction
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
import net.i2p.crypto.DSAEngine
|
||||
import net.i2p.data.DataHelper
|
||||
import net.i2p.data.Signature
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
import javax.annotation.Nonnull
|
||||
|
||||
import com.muwire.core.chat.ChatConnection
|
||||
import com.muwire.core.chat.ChatMessageEvent
|
||||
import com.muwire.core.chat.ChatServer
|
||||
|
||||
@ArtifactProviderFor(GriffonController)
|
||||
class ChatRoomController {
|
||||
@MVCMember @Nonnull
|
||||
ChatRoomModel model
|
||||
@MVCMember @Nonnull
|
||||
ChatRoomView view
|
||||
|
||||
@ControllerAction
|
||||
void say() {
|
||||
String words = view.sayField.text
|
||||
view.sayField.setText(null)
|
||||
|
||||
long now = System.currentTimeMillis()
|
||||
UUID uuid = UUID.randomUUID()
|
||||
String room = model.console ? ChatServer.CONSOLE : model.room
|
||||
|
||||
byte [] sig = ChatConnection.sign(uuid, now, room, words, model.core.me, mvcGroup.parentGroup.model.host, model.core.spk)
|
||||
|
||||
def event = new ChatMessageEvent(uuid : uuid,
|
||||
payload : words,
|
||||
sender : model.core.me,
|
||||
host : mvcGroup.parentGroup.model.host,
|
||||
room : room,
|
||||
chatTime : now,
|
||||
sig : sig)
|
||||
|
||||
model.core.eventBus.publish(event)
|
||||
|
||||
String toShow = DataHelper.formatTime(now) + " <" + model.core.me.getHumanReadableName() + "> "+words
|
||||
|
||||
view.roomTextArea.append(toShow)
|
||||
view.roomTextArea.append('\n')
|
||||
}
|
||||
}
|
@@ -11,4 +11,7 @@ class ChatRoomModel {
|
||||
Core core
|
||||
String tabName
|
||||
String room
|
||||
boolean console
|
||||
|
||||
def members = []
|
||||
}
|
@@ -3,6 +3,8 @@ package com.muwire.gui
|
||||
import griffon.core.artifact.GriffonView
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
|
||||
import javax.swing.JSplitPane
|
||||
import javax.swing.SwingConstants
|
||||
|
||||
import java.awt.BorderLayout
|
||||
@@ -20,17 +22,48 @@ class ChatRoomView {
|
||||
|
||||
def pane
|
||||
def parent
|
||||
def sayField
|
||||
def roomTextArea
|
||||
|
||||
void initUI() {
|
||||
pane = builder.panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.CENTER) {
|
||||
textArea(editable : false)
|
||||
}
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
int rowHeight = application.context.get("row-height")
|
||||
if (model.console) {
|
||||
pane = builder.panel {
|
||||
borderLayout()
|
||||
textField(actionPerformed : {controller.say()}, constraints : BorderLayout.CENTER)
|
||||
button(text : "Say", constraints : BorderLayout.EAST, sayAction)
|
||||
panel(constraints : BorderLayout.CENTER) {
|
||||
gridLayout(rows : 1, cols : 1)
|
||||
roomTextArea = textArea(editable : false, lineWrap : true, wrapStyleWord : true)
|
||||
}
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
borderLayout()
|
||||
sayField = textField(actionPerformed : {controller.say()}, constraints : BorderLayout.CENTER)
|
||||
button(text : "Say", constraints : BorderLayout.EAST, sayAction)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pane = builder.panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.CENTER) {
|
||||
splitPane(orientation : JSplitPane.HORIZONTAL_SPLIT, continuousLayout : true, dividerLocation : 200)
|
||||
panel {
|
||||
table(autoCreateRowSorter : true, rowHeight : rowHeight) {
|
||||
tableModel(list : model.members) {
|
||||
closureColumn(header : "Name", type: String, read : {it.getHumanReadableName()})
|
||||
closureColumn(header : "Trust Status", type : String, read : {String.valueOf(model.core.trustService.getLevel(it.destination))})
|
||||
}
|
||||
}
|
||||
}
|
||||
panel {
|
||||
gridLayout(rows : 1, cols : 1)
|
||||
roomTextArea = textArea(editable : false, lineWrap : true, wrapStyleWord : true)
|
||||
}
|
||||
}
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
borderLayout()
|
||||
sayField = textField(actionPerformed : {controller.say()}, constraints : BorderLayout.CENTER)
|
||||
button(text : "Say", constraints : BorderLayout.EAST, sayAction)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +83,8 @@ class ChatRoomView {
|
||||
button(icon : imageIcon("/close_tab.png"), preferredSize: [20, 20], constraints : BorderLayout.EAST,
|
||||
actionPerformed : closeTab )
|
||||
}
|
||||
parent.setTabComponentAt(index, tabPanel)
|
||||
if (!model.console)
|
||||
parent.setTabComponentAt(index, tabPanel)
|
||||
}
|
||||
|
||||
def closeTab = {
|
||||
|
@@ -54,6 +54,7 @@ class ChatServerView {
|
||||
params['core'] = model.core
|
||||
params['tabName'] = model.host.getHumanReadableName() + "-chat-rooms"
|
||||
params['room'] = 'Console'
|
||||
params['console'] = true
|
||||
mvcGroup.createMVCGroup("chat-room","Console", params)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user