Memory work.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@9260 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2007-10-02 18:45:54 +00:00
committed by derek
parent 898309f75e
commit c3c056d8ba
3 changed files with 101 additions and 68 deletions

View File

@ -16,7 +16,6 @@ import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow;
import org.jivesoftware.spark.ChatAreaSendField;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.BackgroundPanel;
@ -27,6 +26,26 @@ import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
@ -48,26 +67,6 @@ import java.util.Date;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
/**
* The base implementation of all ChatRoom conversations. You would implement this class to have most types of Chat.
*/
@ -101,6 +100,8 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
private MouseAdapter transcriptWindowMouseListener;
private KeyAdapter chatEditorKeyListener;
/**
* Initializes the base layout and base background color.
*/
@ -120,11 +121,11 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
transcriptWindowMouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
getChatInputEditor().requestFocus();
getChatInputEditor().requestFocus();
}
public void mouseReleased(MouseEvent e) {
if (transcriptWindow.getSelectedText() == null) {
if (transcriptWindow.getSelectedText() == null) {
getChatInputEditor().requestFocus();
}
}
@ -167,15 +168,6 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
getTranscriptWindow().addContextMenuListener(this);
this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("F12"), "showDebugger");
this.getActionMap().put("showDebugger", new AbstractAction("showDebugger") {
public void actionPerformed(ActionEvent evt) {
EnhancedDebuggerWindow window = EnhancedDebuggerWindow.getInstance();
window.setVisible(true);
}
});
transferHandler = new ChatRoomTransferHandler(this);
getTranscriptWindow().setTransferHandler(transferHandler);
@ -252,11 +244,13 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
getChatInputEditor().getDocument().addDocumentListener(this);
// Add Key Listener to Send Field
getChatInputEditor().addKeyListener(new KeyAdapter() {
chatEditorKeyListener = new KeyAdapter() {
public void keyPressed(KeyEvent e) {
checkForEnter(e);
checkForEnter(e);
}
});
};
getChatInputEditor().addKeyListener(chatEditorKeyListener);
getChatInputEditor().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ctrl F4"), "closeTheRoom");
getChatInputEditor().getActionMap().put("closeTheRoom", new AbstractAction("closeTheRoom") {
@ -465,7 +459,7 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
private void checkForEnter(KeyEvent e) {
final KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
if (!keyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK)) &&
e.getKeyChar() == KeyEvent.VK_ENTER) {
e.getKeyChar() == KeyEvent.VK_ENTER) {
e.consume();
sendMessage();
getChatInputEditor().setText("");
@ -609,6 +603,7 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
getTranscriptWindow().removeContextMenuListener(this);
getTranscriptWindow().removeMouseListener(transcriptWindowMouseListener);
getChatInputEditor().removeKeyListener(chatEditorKeyListener);
// Remove Connection Listener
@ -622,6 +617,9 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
messageListeners.clear();
fileDropListeners.clear();
getChatInputEditor().close();
getChatInputEditor().getActionMap().remove("closeTheRoom");
chatAreaButton.getButton().removeActionListener(this);
}
/**

View File

@ -47,10 +47,13 @@ import org.jivesoftware.sparkimpl.profile.VCardManager;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import javax.swing.Icon;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
@ -59,10 +62,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.TimerTask;
import javax.swing.Icon;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
/**
* This is the Person to Person implementation of <code>ChatRoom</code>
* This room only allows for 1 to 1 conversations.
@ -94,6 +93,11 @@ public class ChatRoomImpl extends ChatRoom {
private boolean active;
// Information button
private ChatRoomButton infoButton;
private ChatRoomButton addToRosterButton;
/**
* Constructs a 1-to-1 ChatRoom.
*
@ -140,34 +144,23 @@ public class ChatRoomImpl extends ChatRoom {
tabIcon = PresenceManager.getIconFromPresence(presence);
// Create toolbar buttons.
ChatRoomButton infoButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_24x24));
infoButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_24x24));
infoButton.setToolTipText(Res.getString("message.view.information.about.this.user"));
// Create basic toolbar.
getToolBar().addChatRoomButton(infoButton);
// If the user is not in the roster, then allow user to add them.
addToRosterButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.ADD_IMAGE_24x24));
if (entry == null && !StringUtils.parseResource(participantJID).equals(participantNickname)) {
ChatRoomButton addToRosterButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.ADD_IMAGE_24x24));
addToRosterButton.setToolTipText(Res.getString("message.add.this.user.to.your.roster"));
getToolBar().addChatRoomButton(addToRosterButton);
addToRosterButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
RosterDialog rosterDialog = new RosterDialog();
rosterDialog.setDefaultJID(participantJID);
rosterDialog.setDefaultNickname(getParticipantNickname());
rosterDialog.showRosterDialog(SparkManager.getChatManager().getChatContainer().getChatFrame());
}
});
addToRosterButton.addActionListener(this);
}
// Show VCard.
infoButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
VCardManager vcard = SparkManager.getVCardManager();
vcard.viewProfile(participantJID, SparkManager.getChatManager().getChatContainer());
}
});
infoButton.addActionListener(this);
// If this is a private chat from a group chat room, do not show toolbar.
if (StringUtils.parseResource(participantJID).equals(participantNickname)) {
@ -203,6 +196,10 @@ public class ChatRoomImpl extends ChatRoom {
super.closeChatRoom();
// Remove info listener
infoButton.removeActionListener(this);
addToRosterButton.removeActionListener(this);
// Send a cancel notification event on closing if listening.
if (!sendNotification) {
// send cancel
@ -422,7 +419,7 @@ public class ChatRoomImpl extends ChatRoom {
// If this is a group chat message, discard
if (message.getType() == Message.Type.groupchat || broadcast || message.getType() == Message.Type.normal ||
message.getType() == Message.Type.headline) {
message.getType() == Message.Type.headline) {
return;
}
@ -669,4 +666,22 @@ public class ChatRoomImpl extends ChatRoom {
Presence presence = roster.getPresence(getParticipantJID());
return presence.isAvailable();
}
// I would normally use the command pattern, but
// have no real use when dealing with just a couple options.
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
if (e.getSource() == infoButton) {
VCardManager vcard = SparkManager.getVCardManager();
vcard.viewProfile(participantJID, SparkManager.getChatManager().getChatContainer());
}
else if (e.getSource() == addToRosterButton) {
RosterDialog rosterDialog = new RosterDialog();
rosterDialog.setDefaultJID(participantJID);
rosterDialog.setDefaultNickname(getParticipantNickname());
rosterDialog.showRosterDialog(SparkManager.getChatManager().getChatContainer().getChatFrame());
}
}
}

View File

@ -22,6 +22,7 @@ import org.jivesoftware.spark.component.BackgroundPanel;
import org.jivesoftware.spark.plugin.ContextMenuListener;
import org.jivesoftware.spark.ui.ChatRoom;
import org.jivesoftware.spark.ui.ChatRoomButton;
import org.jivesoftware.spark.ui.ChatRoomClosingListener;
import org.jivesoftware.spark.ui.ChatRoomListener;
import org.jivesoftware.spark.ui.ContactItem;
import org.jivesoftware.spark.ui.ContactList;
@ -168,16 +169,7 @@ public class ChatTranscriptPlugin implements ChatRoomListener {
}
if (room instanceof ChatRoomImpl) {
// Add History Button
ChatRoomButton chatRoomButton = new ChatRoomButton(SparkRes.getImageIcon(SparkRes.HISTORY_24x24_IMAGE));
room.getToolBar().addChatRoomButton(chatRoomButton);
chatRoomButton.setToolTipText(Res.getString("tooltip.view.history"));
chatRoomButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
ChatRoomImpl roomImpl = (ChatRoomImpl)room;
showHistory(roomImpl.getParticipantJID());
}
});
new ChatRoomDecorator(room);
}
}
@ -392,5 +384,33 @@ public class ChatTranscriptPlugin implements ChatRoomListener {
}
};
private class ChatRoomDecorator implements ActionListener, ChatRoomClosingListener {
private ChatRoom chatRoom;
private ChatRoomButton chatHistoryButton;
public ChatRoomDecorator(ChatRoom chatRoom) {
this.chatRoom = chatRoom;
chatRoom.addClosingListener(this);
// Add History Button
chatHistoryButton = new ChatRoomButton(SparkRes.getImageIcon(SparkRes.HISTORY_24x24_IMAGE));
chatRoom.getToolBar().addChatRoomButton(chatHistoryButton);
chatHistoryButton.setToolTipText(Res.getString("tooltip.view.history"));
chatHistoryButton.addActionListener(this);
}
public void closing() {
chatHistoryButton.removeActionListener(this);
chatRoom.removeClosingListener(this);
}
public void actionPerformed(ActionEvent e) {
ChatRoomImpl roomImpl = (ChatRoomImpl)chatRoom;
showHistory(roomImpl.getParticipantJID());
}
}
}