SPARK-584 Ctrl-x and cut now work correctly in send area. (Also, paste now works correctly)

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@7516 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2007-03-14 21:45:17 +00:00
committed by derek
parent dc5010d311
commit e774668d61
3 changed files with 53 additions and 58 deletions

View File

@ -27,8 +27,8 @@ import org.jivesoftware.smackx.filetransfer.FileTransferManager;
import org.jivesoftware.smackx.filetransfer.FileTransferRequest;
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer;
import org.jivesoftware.spark.ChatManager;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.PresenceManager;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.filetransfer.preferences.FileTransferPreference;
import org.jivesoftware.spark.preference.PreferenceManager;
@ -56,17 +56,13 @@ import org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui.SendMessage;
import org.jivesoftware.sparkimpl.plugin.manager.Enterprise;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
@ -79,11 +75,13 @@ import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
@ -299,27 +297,23 @@ public class SparkTransferManager {
final ChatInputEditor chatSendField = room.getChatInputEditor();
chatSendField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("Ctrl v"), "paste");
chatSendField.getActionMap().put("paste", new AbstractAction("paste") {
public void actionPerformed(ActionEvent evt) {
String clipboardText = SparkManager.getClipboard();
if (clipboardText == null && getClipboard() != null) {
chatSendField.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent ke) {
if (ke.getKeyCode() == KeyEvent.VK_V) {
int i = ke.getModifiers();
if ((i & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
Clipboard clb = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clb.getContents(ke.getSource());
if (contents != null) {
if (contents.isDataFlavorSupported(DataFlavor.imageFlavor)) {
sendImage(getClipboard(), room);
}
else {
try {
Document document = chatSendField.getDocument();
document.insertString(chatSendField.getCaretPosition(), clipboardText, null);
}
catch (BadLocationException e) {
Log.error(e);
}
}
}
});
}
});
fileDropListener = new FileDropListener() {
public void filesDropped(Collection files, Component component) {
@ -572,7 +566,7 @@ public class SparkTransferManager {
String bareJID = StringUtils.parseBareAddress(jid);
String fullJID = PresenceManager.getFullyQualifiedJID(jid);
if (!PresenceManager.isOnline(jid)){
if (!PresenceManager.isOnline(jid)) {
List list = (List)waitMap.get(jid);
if (list == null) {
list = new ArrayList();
@ -594,7 +588,6 @@ public class SparkTransferManager {
return null;
}
// Create the outgoing file transfer
final OutgoingFileTransfer transfer = transferManager.createOutgoingFileTransfer(fullJID);

View File

@ -19,19 +19,6 @@ import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.emoticons.EmoticonManager;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
@ -49,6 +36,19 @@ import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
/**
* The ChatArea class handles proper chat text formatting such as url handling. Use ChatArea for proper
* formatting of bold, italics, underlined and urls.
@ -99,42 +99,36 @@ public class ChatArea extends JTextPane implements MouseListener, MouseMotionLis
public ChatArea() {
emoticonManager = EmoticonManager.getInstance();
// Cut Action
final Action cutAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
String selectedText = getSelectedText();
try {
getDocument().remove(getSelectionStart(), getSelectionEnd());
replaceSelection("");
SparkManager.setClipboard(selectedText);
}
catch (BadLocationException e1) {
Log.error("Error removing selected text", e1);
}
}
};
cutAction.putValue(Action.NAME, "Cut");
Action copyAction = new AbstractAction() {
// Copy Action
final Action copyAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
SparkManager.setClipboard(getSelectedText());
}
};
copyAction.putValue(Action.NAME, "Copy");
Action pasteAction = new AbstractAction() {
// Paste Action
final Action pasteAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
String text = SparkManager.getClipboard();
try {
Document document = getDocument();
document.insertString(getCaretPosition(), text, null);
}
catch (BadLocationException e1) {
Log.error("Unable to insert clipboard text.", e1);
if (text != null) {
replaceSelection(text);
}
}
};
pasteAction.putValue(Action.NAME, "Paste");
// Select All Action
Action selectAllAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
requestFocus();
@ -169,6 +163,14 @@ public class ChatArea extends JTextPane implements MouseListener, MouseMotionLis
}
});
getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("Ctrl v"), "paste");
getActionMap().put("paste", new AbstractAction("paste") {
public void actionPerformed(ActionEvent evt) {
pasteAction.actionPerformed(evt);
}
});
}
/**

View File

@ -507,7 +507,7 @@ public class ChatContainer extends SparkTabbedPane implements MessageListener, C
*
* @param location the tab location.
* @return the ChatRoom found.
* @throws ChatRoomNotFoundException
* @throws ChatRoomNotFoundException thrown if the room is not found.
*/
public ChatRoom getChatRoom(int location) throws ChatRoomNotFoundException {
if (getTabCount() < location) {