mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
Memory work.
git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@9250 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
@ -71,7 +71,7 @@ import javax.swing.text.Document;
|
||||
/**
|
||||
* The base implementation of all ChatRoom conversations. You would implement this class to have most types of Chat.
|
||||
*/
|
||||
public abstract class ChatRoom extends BackgroundPanel implements ActionListener, PacketListener, DocumentListener, ConnectionListener, FocusListener {
|
||||
public abstract class ChatRoom extends BackgroundPanel implements ActionListener, PacketListener, DocumentListener, ConnectionListener, FocusListener, ContextMenuListener {
|
||||
private final JPanel chatPanel;
|
||||
private final JSplitPane splitPane;
|
||||
private JSplitPane verticalSplit;
|
||||
@ -171,28 +171,7 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
notificationLabel.setIcon(SparkRes.getImageIcon(SparkRes.BLANK_IMAGE));
|
||||
|
||||
|
||||
getTranscriptWindow().addContextMenuListener(new ContextMenuListener() {
|
||||
public void poppingUp(Object component, JPopupMenu popup) {
|
||||
Action saveAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
saveTranscript();
|
||||
}
|
||||
};
|
||||
saveAction.putValue(Action.NAME, "Save");
|
||||
saveAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SAVE_AS_16x16));
|
||||
|
||||
|
||||
popup.add(saveAction);
|
||||
}
|
||||
|
||||
public void poppingDown(JPopupMenu popup) {
|
||||
|
||||
}
|
||||
|
||||
public boolean handleDefaultAction(MouseEvent e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
getTranscriptWindow().addContextMenuListener(this);
|
||||
|
||||
this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("F12"), "showDebugger");
|
||||
this.getActionMap().put("showDebugger", new AbstractAction("showDebugger") {
|
||||
@ -634,6 +613,8 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
public void closeChatRoom() {
|
||||
fireClosingListeners();
|
||||
|
||||
getTranscriptWindow().removeContextMenuListener(this);
|
||||
|
||||
// Remove Connection Listener
|
||||
SparkManager.getConnection().removeConnectionListener(this);
|
||||
getTranscriptWindow().setTransferHandler(null);
|
||||
@ -972,6 +953,28 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
verticalSplit.setDividerLocation(-1);
|
||||
}
|
||||
|
||||
public void poppingUp(Object component, JPopupMenu popup) {
|
||||
Action saveAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
saveTranscript();
|
||||
}
|
||||
};
|
||||
saveAction.putValue(Action.NAME, "Save");
|
||||
saveAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SAVE_AS_16x16));
|
||||
|
||||
|
||||
popup.add(saveAction);
|
||||
}
|
||||
|
||||
public void poppingDown(JPopupMenu popup) {
|
||||
|
||||
}
|
||||
|
||||
public boolean handleDefaultAction(MouseEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void focusLost(FocusEvent focusEvent) {
|
||||
}
|
||||
|
||||
|
||||
@ -23,21 +23,6 @@ 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.JComponent;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.SimpleAttributeSet;
|
||||
import javax.swing.text.Style;
|
||||
import javax.swing.text.StyleConstants;
|
||||
import javax.swing.text.StyledDocument;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
@ -53,12 +38,27 @@ import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.SimpleAttributeSet;
|
||||
import javax.swing.text.Style;
|
||||
import javax.swing.text.StyleConstants;
|
||||
import javax.swing.text.StyledDocument;
|
||||
|
||||
/**
|
||||
* The <CODE>TranscriptWindow</CODE> class. Provides a default implementation
|
||||
* of a Chat Window. In general, extensions could override this class
|
||||
* to offer more support within the chat, but should not be necessary.
|
||||
*/
|
||||
public class TranscriptWindow extends ChatArea {
|
||||
public class TranscriptWindow extends ChatArea implements ContextMenuListener {
|
||||
|
||||
|
||||
private final SimpleDateFormat notificationDateFormatter;
|
||||
@ -90,42 +90,7 @@ public class TranscriptWindow extends ChatArea {
|
||||
addMouseMotionListener(this);
|
||||
setDragEnabled(true);
|
||||
|
||||
final TranscriptWindow window = this;
|
||||
addContextMenuListener(new ContextMenuListener() {
|
||||
public void poppingUp(Object object, JPopupMenu popup) {
|
||||
Action printAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
SparkManager.printChatTranscript(window);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Action clearAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
printAction.putValue(Action.NAME, "Print");
|
||||
printAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.PRINTER_IMAGE_16x16));
|
||||
|
||||
clearAction.putValue(Action.NAME, "Clear");
|
||||
clearAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.ERASER_IMAGE));
|
||||
popup.addSeparator();
|
||||
popup.add(printAction);
|
||||
|
||||
popup.add(clearAction);
|
||||
}
|
||||
|
||||
public void poppingDown(JPopupMenu popup) {
|
||||
|
||||
}
|
||||
|
||||
public boolean handleDefaultAction(MouseEvent e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
addContextMenuListener(this);
|
||||
|
||||
// Make sure ctrl-c works
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("Ctrl c"), "copy");
|
||||
@ -476,7 +441,7 @@ public class TranscriptWindow extends ChatArea {
|
||||
writer.write(buf.toString());
|
||||
writer.close();
|
||||
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), "Chat transcript has been saved.",
|
||||
"Chat Transcript Saved", JOptionPane.INFORMATION_MESSAGE);
|
||||
"Chat Transcript Saved", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@ -488,6 +453,11 @@ public class TranscriptWindow extends ChatArea {
|
||||
|
||||
public void cleanup() {
|
||||
clear();
|
||||
|
||||
removeMouseListener(this);
|
||||
removeMouseMotionListener(this);
|
||||
|
||||
removeContextMenuListener(this);
|
||||
}
|
||||
|
||||
|
||||
@ -498,4 +468,44 @@ public class TranscriptWindow extends ChatArea {
|
||||
public Font getFont() {
|
||||
return defaultFont;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds Print and Clear actions.
|
||||
* @param object the TransferWindow
|
||||
* @param popup the popup menu to add to.
|
||||
*/
|
||||
public void poppingUp(final Object object, JPopupMenu popup) {
|
||||
Action printAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
SparkManager.printChatTranscript((TranscriptWindow)object);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Action clearAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
printAction.putValue(Action.NAME, "Print");
|
||||
printAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.PRINTER_IMAGE_16x16));
|
||||
|
||||
clearAction.putValue(Action.NAME, "Clear");
|
||||
clearAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.ERASER_IMAGE));
|
||||
popup.addSeparator();
|
||||
popup.add(printAction);
|
||||
|
||||
popup.add(clearAction);
|
||||
}
|
||||
|
||||
public void poppingDown(JPopupMenu popup) {
|
||||
|
||||
}
|
||||
|
||||
public boolean handleDefaultAction(MouseEvent e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ public class ChatRoomImpl extends ChatRoom {
|
||||
|
||||
public void closeChatRoom() {
|
||||
// If already closed, don't bother.
|
||||
if(!active){
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -214,8 +214,10 @@ public class ChatRoomImpl extends ChatRoom {
|
||||
SparkManager.getChatManager().removeChat(this);
|
||||
|
||||
SparkManager.getConnection().removePacketListener(this);
|
||||
TaskEngine.getInstance().cancelScheduledTask(typingTimerTask);
|
||||
typingTimerTask = null;
|
||||
if (typingTimerTask != null) {
|
||||
TaskEngine.getInstance().cancelScheduledTask(typingTimerTask);
|
||||
typingTimerTask = null;
|
||||
}
|
||||
active = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user