class ConversationWindow(Conversation): """A GUI window of a conversation with a specific person""" def __init__(self, person, chatui): """ConversationWindow(basesupport.AbstractPerson:person)""" Conversation.__init__(self, person, chatui) self.mainframe = JFrame("Conversation with "+person.name) self.display = JTextArea(columns=100, rows=15, editable=0, lineWrap=1) self.typepad = JTextField() self.buildpane() self.lentext = 0 def buildpane(self): buttons = JPanel(doublebuffered) buttons.add(JButton("Send", actionPerformed=self.send)) buttons.add(JButton("Hide", actionPerformed=self.hidewindow)) mainpane = self.mainframe.getContentPane() mainpane.setLayout(BoxLayout(mainpane, BoxLayout.Y_AXIS)) mainpane.add(JScrollPane(self.display)) self.typepad.actionPerformed = self.send mainpane.add(self.typepad) mainpane.add(buttons) def show(self): self.mainframe.pack() self.mainframe.show() def hide(self): self.mainframe.hide() def sendText(self, text): self.displayText("\n"+self.person.client.name+": "+text) Conversation.sendText(self, text) def showMessage(self, text, metadata=None): self.displayText("\n"+self.person.name+": "+text) def contactChangedNick(self, person, newnick): Conversation.contactChangedNick(self, person, newnick) self.mainframe.setTitle("Conversation with "+newnick) #GUI code def displayText(self, text): self.lentext = self.lentext + len(text) self.display.append(text) self.display.setCaretPosition(self.lentext) #actionlisteners def hidewindow(self, ae): self.hide() def send(self, ae): text = self.typepad.getText() self.typepad.setText("") if text != "" and text != None: self.sendText(text)
class ConversationWindow(Conversation): """A GUI window of a conversation with a specific person""" def __init__(self, person, chatui): """ConversationWindow(basesupport.AbstractPerson:person)""" Conversation.__init__(self, person, chatui) self.mainframe = JFrame("Conversation with " + person.name) self.display = JTextArea(columns=100, rows=15, editable=0, lineWrap=1) self.typepad = JTextField() self.buildpane() self.lentext = 0 def buildpane(self): buttons = JPanel(doublebuffered) buttons.add(JButton("Send", actionPerformed=self.send)) buttons.add(JButton("Hide", actionPerformed=self.hidewindow)) mainpane = self.mainframe.getContentPane() mainpane.setLayout(BoxLayout(mainpane, BoxLayout.Y_AXIS)) mainpane.add(JScrollPane(self.display)) self.typepad.actionPerformed = self.send mainpane.add(self.typepad) mainpane.add(buttons) def show(self): self.mainframe.pack() self.mainframe.show() def hide(self): self.mainframe.hide() def sendText(self, text): self.displayText("\n" + self.person.client.name + ": " + text) Conversation.sendText(self, text) def showMessage(self, text, metadata=None): self.displayText("\n" + self.person.name + ": " + text) def contactChangedNick(self, person, newnick): Conversation.contactChangedNick(self, person, newnick) self.mainframe.setTitle("Conversation with " + newnick) #GUI code def displayText(self, text): self.lentext = self.lentext + len(text) self.display.append(text) self.display.setCaretPosition(self.lentext) #actionlisteners def hidewindow(self, ae): self.hide() def send(self, ae): text = self.typepad.getText() self.typepad.setText("") if text != "" and text != None: self.sendText(text)
class GroupConversationWindow(GroupConversation): """A GUI window of a conversation witha group of people""" def __init__(self, group, chatui): GroupConversation.__init__(self, group, chatui) self.mainframe = JFrame(self.group.name) self.headers = ["Member"] self.memberdata = UneditableTableModel([], self.headers) self.display = JTextArea(columns=100, rows=15, editable=0, lineWrap=1) self.typepad = JTextField() self.buildpane() self.lentext = 0 def show(self): self.mainframe.pack() self.mainframe.show() def hide(self): self.mainframe.hide() def showGroupMessage(self, sender, text, metadata=None): self.displayText(sender + ": " + text) def setGroupMembers(self, members): GroupConversation.setGroupMembers(self, members) self.updatelist() def setTopic(self, topic, author): topictext = "Topic: " + topic + ", set by " + author self.mainframe.setTitle(self.group.name + ": " + topictext) self.displayText(topictext) def memberJoined(self, member): GroupConversation.memberJoined(self, member) self.updatelist() def memberChangedNick(self, oldnick, newnick): GroupConversation.memberChangedNick(self, oldnick, newnick) self.updatelist() def memberLeft(self, member): GroupConversation.memberLeft(self, member) self.updatelist() #GUI code def buildpane(self): buttons = JPanel(doublebuffered) buttons.add(JButton("Hide", actionPerformed=self.hidewindow)) memberpane = JTable(self.memberdata) memberframe = JScrollPane(memberpane) chat = JPanel(doublebuffered) chat.setLayout(BoxLayout(chat, BoxLayout.Y_AXIS)) chat.add(JScrollPane(self.display)) self.typepad.actionPerformed = self.send chat.add(self.typepad) chat.add(buttons) mainpane = self.mainframe.getContentPane() mainpane.setLayout(BoxLayout(mainpane, BoxLayout.X_AXIS)) mainpane.add(chat) mainpane.add(memberframe) def displayText(self, text): self.lentext = self.lentext + len(text) self.display.append(text) self.display.setCaretPosition(self.lentext) def updatelist(self): self.memberdata.setDataVector([self.members], self.headers) #actionListener def send(self, ae): text = self.typepad.getText() self.typepad.setText("") if text != "" and text != None: GroupConversation.sendText(self, text) def hidewindow(self, ae): self.hide()