mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
Temporary removing adium themes for post 2.5 release.
git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@6619 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
BIN
build/lib/dist/synthetica.jar
vendored
BIN
build/lib/dist/synthetica.jar
vendored
Binary file not shown.
BIN
build/lib/dist/syntheticaBlackMoon.jar
vendored
Normal file
BIN
build/lib/dist/syntheticaBlackMoon.jar
vendored
Normal file
Binary file not shown.
BIN
build/lib/dist/syntheticaBlueMoon.jar
vendored
Normal file
BIN
build/lib/dist/syntheticaBlueMoon.jar
vendored
Normal file
Binary file not shown.
@ -154,15 +154,6 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library" exported="">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../lib/dist/systeminfo.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library" exported="">
|
||||
<library>
|
||||
<CLASSES>
|
||||
@ -190,15 +181,6 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../lib/dist/webrenderer-win.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
@ -208,15 +190,6 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../lib/dist/webrenderer.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
@ -226,6 +199,24 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../lib/dist/syntheticaBlueMoon.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../lib/dist/syntheticaBlackMoon.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntryProperties />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
|
||||
@ -10,17 +10,17 @@
|
||||
|
||||
package org.jivesoftware;
|
||||
|
||||
import de.javasoft.plaf.synthetica.SyntheticaBlueMoonLookAndFeel;
|
||||
import org.jivesoftware.resource.Default;
|
||||
import org.jivesoftware.resource.SparkRes;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Insets;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JFrame;
|
||||
@ -113,8 +113,13 @@ public final class Spark {
|
||||
String classname = UIManager.getSystemLookAndFeelClassName();
|
||||
|
||||
if (classname.indexOf("Windows") != -1) {
|
||||
UIManager.setLookAndFeel(new com.jgoodies.looks.windows.WindowsLookAndFeel());
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel(new SyntheticaBlueMoonLookAndFeel());
|
||||
}
|
||||
catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
installBaseUIProperties();
|
||||
}
|
||||
else if (classname.indexOf("mac") != -1 || classname.indexOf("apple") != -1) {
|
||||
UIManager.setLookAndFeel(classname);
|
||||
@ -130,6 +135,7 @@ public final class Spark {
|
||||
|
||||
|
||||
buf.append(classPath);
|
||||
buf.append(";").append(RESOURCE_DIRECTORY.getAbsolutePath());
|
||||
|
||||
// Update System Properties
|
||||
System.setProperty("java.library.path", buf.toString());
|
||||
@ -153,37 +159,6 @@ public final class Spark {
|
||||
|
||||
// Setup the look and feel of this application.
|
||||
static {
|
||||
|
||||
|
||||
UIManager.put("Tree.openIcon", SparkRes.getImageIcon(SparkRes.FOLDER));
|
||||
UIManager.put("Tree.closedIcon", SparkRes.getImageIcon(SparkRes.FOLDER_CLOSED));
|
||||
UIManager.put("Button.showMnemonics", Boolean.TRUE);
|
||||
UIManager.put("CollapsiblePane.titleFont", new Font("Dialog", Font.BOLD, 11));
|
||||
UIManager.put("DockableFrameTitlePane.font", new Font("Dialog", Font.BOLD, 10));
|
||||
UIManager.put("DockableFrame.inactiveTitleForeground", Color.white);
|
||||
UIManager.put("DockableFrame.inactiveTitleBackground", new Color(180, 176, 160));
|
||||
UIManager.put("DockableFrame.activeTitleBackground", new Color(105, 132, 188));
|
||||
UIManager.put("DockableFrame.activeTitleForeground", Color.white);
|
||||
UIManager.put("CollapsiblePane.background", Color.white);
|
||||
UIManager.put("TextField.font", new Font("Dialog", Font.PLAIN, 11));
|
||||
if (isWindows()) {
|
||||
UIManager.put("DockableFrameTitlePane.titleBarComponent", true);
|
||||
}
|
||||
else {
|
||||
UIManager.put("DockableFrameTitlePane.titleBarComponent", false);
|
||||
}
|
||||
|
||||
UIManager.put("SidePane.lineColor", Color.BLACK);
|
||||
UIManager.put("SidePane.foreground", Color.BLACK);
|
||||
|
||||
|
||||
Color menuBarColor = new Color(255, 255, 255);//235, 233, 237);
|
||||
UIManager.put("MenuBar.background", menuBarColor);
|
||||
UIManager.put("JideTabbedPane.tabInsets", new Insets(3, 10, 3, 10));
|
||||
UIManager.put("JideTabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
|
||||
|
||||
installBaseUIProperties();
|
||||
|
||||
com.install4j.api.launcher.StartupNotification.registerStartupListener(new SparkStartupListener());
|
||||
}
|
||||
|
||||
@ -321,6 +296,8 @@ public final class Spark {
|
||||
UIManager.put("List.selectionBorder", new Color(187, 195, 215));
|
||||
UIManager.put("List.foreground", Color.black);
|
||||
UIManager.put("List.background", Color.white);
|
||||
UIManager.put("MenuItem.selectionBackground", new Color(217, 232, 250));
|
||||
UIManager.put("MenuItem.selectionForeground", Color.black);
|
||||
UIManager.put("TextPane.foreground", Color.black);
|
||||
UIManager.put("TextPane.background", Color.white);
|
||||
UIManager.put("TextPane.inactiveForeground", Color.white);
|
||||
@ -341,9 +318,10 @@ public final class Spark {
|
||||
UIManager.put("Link.foreground", Color.blue);
|
||||
UIManager.put("User.foreground", Color.blue);
|
||||
UIManager.put("OtherUser.foreground", Color.red);
|
||||
UIManager.put("Notification.foreground", new Color(51, 153, 51));
|
||||
UIManager.put("Notification.foreground", new Color(0, 128, 0));
|
||||
UIManager.put("Error.foreground", Color.red);
|
||||
UIManager.put("Question.foreground", Color.red);
|
||||
UIManager.put("History.foreground", new Color(0, 57, 109));
|
||||
|
||||
UIManager.put("SparkTabbedPane.startColor", new Color(236, 236, 236));
|
||||
UIManager.put("SparkTabbedPane.endColor", new Color(236, 236, 236));
|
||||
|
||||
@ -1,79 +0,0 @@
|
||||
/**
|
||||
* $Revision: $
|
||||
* $Date: $
|
||||
*
|
||||
* Copyright (C) 2006 Jive Software. All rights reserved.
|
||||
*
|
||||
* This software is published under the terms of the GNU Lesser Public License (LGPL),
|
||||
* a copy of which is included in this distribution.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.resource;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EmotionRes {
|
||||
private static final Map<String,String> emotionMap = new LinkedHashMap<String,String>();
|
||||
static ClassLoader cl = EmotionRes.class.getClassLoader();
|
||||
|
||||
static {
|
||||
emotionMap.put(":)", "images/emoticons/happy.png");
|
||||
emotionMap.put(":-)", "images/emoticons/happy.png");
|
||||
emotionMap.put(":(", "images/emoticons/sad.png");
|
||||
emotionMap.put(":D", "images/emoticons/grin.png");
|
||||
emotionMap.put(":x", "images/emoticons/love.png");
|
||||
emotionMap.put(";\\", "images/emoticons/mischief.png");
|
||||
emotionMap.put("B-)", "images/emoticons/cool.png");
|
||||
emotionMap.put("]:)", "images/emoticons/devil.png");
|
||||
emotionMap.put(":p", "images/emoticons/silly.png");
|
||||
emotionMap.put("X-(", "images/emoticons/angry.png");
|
||||
emotionMap.put(":^0", "images/emoticons/laugh.png");
|
||||
emotionMap.put(";)", "images/emoticons/wink.png");
|
||||
emotionMap.put(";-)", "images/emoticons/wink.png");
|
||||
emotionMap.put(":8}", "images/emoticons/blush.png");
|
||||
emotionMap.put(":_|", "images/emoticons/cry.png");
|
||||
emotionMap.put("?:|", "images/emoticons/confused.png");
|
||||
emotionMap.put(":0", "images/emoticons/shocked.png");
|
||||
emotionMap.put(":|", "images/emoticons/plain.png");
|
||||
emotionMap.put("8-)", "images/emoticons/eyeRoll.gif");
|
||||
emotionMap.put("|-)", "images/emoticons/sleepy.gif");
|
||||
emotionMap.put("<:o)", "images/emoticons/party.gif");
|
||||
}
|
||||
|
||||
public static ImageIcon getImageIcon(String face) {
|
||||
final String value = emotionMap.get(face);
|
||||
if (value != null) {
|
||||
final URL url = cl.getResource(value);
|
||||
if (url != null) {
|
||||
return new ImageIcon(url);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static URL getURL(String face) {
|
||||
final String value = emotionMap.get(face);
|
||||
if (value != null) {
|
||||
final URL url = cl.getResource(value);
|
||||
if (url != null) {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map getEmoticonMap() {
|
||||
Map<String,String> newMap = new HashMap<String,String>(emotionMap);
|
||||
newMap.remove("8-)");
|
||||
newMap.remove("|-)");
|
||||
newMap.remove("<:o)");
|
||||
newMap.remove(":-)");
|
||||
return newMap;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
":)" = images/emoticons/happy.png
|
||||
:-) = images/emoticons/happy.png
|
||||
:( = images/emoticons/sad.png
|
||||
:-( = images/emoticons/sad.png
|
||||
:D = images/emoticons/grin.png
|
||||
:x = images/emoticons/love.png
|
||||
;\ = images/emoticons/mischief.png
|
||||
B-) = images/emoticons/cool.png
|
||||
]:) = images/emoticons/devil.png
|
||||
:p = images/emoticons/silly.png
|
||||
X-( = images/emoticons/angry.png
|
||||
:^0 = images/emoticons/laugh.png
|
||||
;) = images/emoticons/wink.png
|
||||
;-) = images/emoticons/wink.png
|
||||
:8} = images/emoticons/blush.png
|
||||
:_| = images/emoticons/cry.png
|
||||
?:| = images/emoticons/confused.png
|
||||
:0 = images/emoticons/shocked.png
|
||||
:| = images/emoticons/plain.png
|
||||
@ -278,7 +278,7 @@ public final class SparkManager {
|
||||
final ChatPrinter printer = new ChatPrinter();
|
||||
final TranscriptWindow currentWindow = room.getTranscriptWindow();
|
||||
if (currentWindow != null) {
|
||||
// printer.print(currentWindow);
|
||||
printer.print(currentWindow);
|
||||
}
|
||||
}
|
||||
|
||||
@ -319,7 +319,7 @@ public final class SparkManager {
|
||||
*/
|
||||
public static void printChatTranscript(TranscriptWindow transcriptWindow) {
|
||||
final ChatPrinter printer = new ChatPrinter();
|
||||
//printer.print(transcriptWindow);
|
||||
printer.print(transcriptWindow);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -30,7 +30,6 @@ import org.jivesoftware.spark.ui.ChatRoom;
|
||||
import org.jivesoftware.spark.ui.ChatRoomNotFoundException;
|
||||
import org.jivesoftware.spark.ui.ContactItem;
|
||||
import org.jivesoftware.spark.ui.ContactList;
|
||||
import org.jivesoftware.spark.ui.themes.ThemeManager;
|
||||
import org.jivesoftware.spark.ui.conferences.Conferences;
|
||||
import org.jivesoftware.spark.ui.status.StatusBar;
|
||||
import org.jivesoftware.spark.util.SwingWorker;
|
||||
@ -84,12 +83,12 @@ public class Workspace extends JPanel implements PacketListener {
|
||||
|
||||
private static Workspace singleton;
|
||||
private static final Object LOCK = new Object();
|
||||
private List offlineMessages = new ArrayList();
|
||||
private List<Message> offlineMessages = new ArrayList<Message>();
|
||||
|
||||
private JPanel cardPanel;
|
||||
private CardLayout cardLayout;
|
||||
|
||||
final public static String WORKSPACE_PANE = "WORKSPACE_PANE";
|
||||
public static final String WORKSPACE_PANE = "WORKSPACE_PANE";
|
||||
|
||||
private final CollapsiblePane alerts = new CollapsiblePane();
|
||||
private final JPanel alertPanel = new JPanel();
|
||||
@ -148,8 +147,6 @@ public class Workspace extends JPanel implements PacketListener {
|
||||
|
||||
// Initialize workspace pane, defaulting the tabs to the bottom.
|
||||
workspacePane = new SparkTabbedPane(JTabbedPane.BOTTOM);
|
||||
workspacePane.setBackgroundColor(new Color(180, 207, 247));
|
||||
workspacePane.setBorderColor(Color.lightGray);
|
||||
workspacePane.setActiveButtonBold(true);
|
||||
|
||||
// Add Panels.
|
||||
@ -191,9 +188,6 @@ public class Workspace extends JPanel implements PacketListener {
|
||||
* Builds the Workspace layout.
|
||||
*/
|
||||
public void buildLayout() {
|
||||
// Initialize ThemeManager
|
||||
ThemeManager.getInstance();
|
||||
|
||||
new Enterprise();
|
||||
|
||||
// Initilaize tray
|
||||
@ -282,11 +276,11 @@ public class Workspace extends JPanel implements PacketListener {
|
||||
public void run() {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
final Iterator offlineMessage = offlineMessages.iterator();
|
||||
while (offlineMessage.hasNext()) {
|
||||
Message offline = (Message)offlineMessage.next();
|
||||
handleOfflineMessage(offline);
|
||||
for(Message offlineMessage : offlineMessages){
|
||||
handleOfflineMessage(offlineMessage);
|
||||
}
|
||||
|
||||
offlineMessages.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -332,7 +326,12 @@ public class Workspace extends JPanel implements PacketListener {
|
||||
final String body = message.getBody();
|
||||
boolean broadcast = message.getProperty("broadcast") != null;
|
||||
|
||||
if (body == null || isGroupChat || broadcast || message.getType() == Message.Type.normal || message.getType() == Message.Type.headline) {
|
||||
if (body == null ||
|
||||
isGroupChat ||
|
||||
broadcast ||
|
||||
message.getType() == Message.Type.normal ||
|
||||
message.getType() == Message.Type.headline ||
|
||||
message.getType() == Message.Type.error) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -421,7 +420,9 @@ public class Workspace extends JPanel implements PacketListener {
|
||||
private void insertMessage(final String bareJID, final Message message) throws ChatRoomNotFoundException {
|
||||
ChatRoom chatRoom = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
|
||||
chatRoom.insertMessage(message);
|
||||
|
||||
int chatLength = chatRoom.getTranscriptWindow().getDocument().getLength();
|
||||
chatRoom.getTranscriptWindow().setCaretPosition(chatLength);
|
||||
chatRoom.getChatInputEditor().requestFocusInWindow();
|
||||
}
|
||||
|
||||
public void addAlert(Component comp) {
|
||||
@ -486,4 +487,4 @@ public class Workspace extends JPanel implements PacketListener {
|
||||
public JPanel getAlertPanel() {
|
||||
return alertPanel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,22 +55,6 @@ import org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui.ReceiveMessage
|
||||
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;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.GraphicsDevice;
|
||||
@ -79,7 +63,6 @@ import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
@ -99,6 +82,22 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Responsible for the handling of File Transfer within Spark. You would use the SparkManager
|
||||
* for sending of images, files, multiple files and adding your own transfer listeners for plugin work.
|
||||
@ -236,9 +235,12 @@ public class SparkTransferManager {
|
||||
}
|
||||
|
||||
TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow();
|
||||
StyledDocument doc = (StyledDocument)transcriptWindow.getDocument();
|
||||
|
||||
// The image must first be wrapped in a style
|
||||
Style style = doc.addStyle("StyleName", null);
|
||||
|
||||
final ReceiveMessage receivingMessageUI = new ReceiveMessage();
|
||||
receivingMessageUI.setChatRoom(chatRoom);
|
||||
receivingMessageUI.acceptFileTransfer(request);
|
||||
|
||||
chatRoom.addClosingListener(new ChatRoomClosingListener() {
|
||||
@ -247,7 +249,18 @@ public class SparkTransferManager {
|
||||
}
|
||||
});
|
||||
|
||||
transcriptWindow.add(receivingMessageUI, BorderLayout.AFTER_LAST_LINE);
|
||||
StyleConstants.setComponent(style, receivingMessageUI);
|
||||
|
||||
// Insert the image at the end of the text
|
||||
try {
|
||||
doc.insertString(doc.getLength(), "ignored text", style);
|
||||
doc.insertString(doc.getLength(), "\n", null);
|
||||
}
|
||||
catch (BadLocationException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
chatRoom.scrollToBottom();
|
||||
|
||||
SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom);
|
||||
}
|
||||
@ -396,123 +409,122 @@ public class SparkTransferManager {
|
||||
}
|
||||
|
||||
private void sendScreenshot(final ChatRoomButton button, final ChatRoom room) {
|
||||
button.setEnabled(false);
|
||||
button.setEnabled(false);
|
||||
|
||||
final MainWindow mainWindow = SparkManager.getMainWindow();
|
||||
final ChatFrame chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();
|
||||
final MainWindow mainWindow = SparkManager.getMainWindow();
|
||||
final ChatFrame chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();
|
||||
|
||||
final boolean mainWindowVisible = mainWindow.isVisible();
|
||||
final boolean chatFrameVisible = chatFrame.isVisible();
|
||||
final boolean mainWindowVisible = mainWindow.isVisible();
|
||||
final boolean chatFrameVisible = chatFrame.isVisible();
|
||||
|
||||
if (mainWindowVisible) {
|
||||
mainWindow.setVisible(false);
|
||||
}
|
||||
if (mainWindowVisible) {
|
||||
mainWindow.setVisible(false);
|
||||
}
|
||||
|
||||
if (chatFrameVisible) {
|
||||
chatFrame.setVisible(false);
|
||||
}
|
||||
if (chatFrameVisible) {
|
||||
chatFrame.setVisible(false);
|
||||
}
|
||||
|
||||
final SwingWorker worker = new SwingWorker() {
|
||||
public Object construct() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
final Robot robot = new Robot();
|
||||
Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
|
||||
return robot.createScreenCapture(area);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.error(e);
|
||||
final SwingWorker worker = new SwingWorker() {
|
||||
public Object construct() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
final Robot robot = new Robot();
|
||||
Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
|
||||
return robot.createScreenCapture(area);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.error(e);
|
||||
|
||||
if (mainWindowVisible) {
|
||||
mainWindow.setVisible(true);
|
||||
}
|
||||
if (mainWindowVisible) {
|
||||
mainWindow.setVisible(true);
|
||||
}
|
||||
|
||||
if (chatFrameVisible) {
|
||||
chatFrame.setVisible(true);
|
||||
}
|
||||
if (chatFrameVisible) {
|
||||
chatFrame.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void finished() {
|
||||
final JFrame frame = new JFrame();
|
||||
frame.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
||||
public void finished() {
|
||||
final JFrame frame = new JFrame();
|
||||
frame.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
||||
|
||||
final BufferedImage bufferedImage = (BufferedImage)get();
|
||||
final ImageSelectionPanel mainPanel = new ImageSelectionPanel(bufferedImage);
|
||||
mainPanel.addMouseListener(new MouseAdapter() {
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
Rectangle clip = mainPanel.getClip();
|
||||
BufferedImage newImage = null;
|
||||
try {
|
||||
newImage = bufferedImage.getSubimage((int)clip.getX(), (int)clip.getY(), (int)clip.getWidth(), (int)clip.getHeight());
|
||||
}
|
||||
catch (Exception e1) {
|
||||
final BufferedImage bufferedImage = (BufferedImage)get();
|
||||
final ImageSelectionPanel mainPanel = new ImageSelectionPanel(bufferedImage);
|
||||
mainPanel.addMouseListener(new MouseAdapter() {
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
Rectangle clip = mainPanel.getClip();
|
||||
BufferedImage newImage = null;
|
||||
try {
|
||||
newImage = bufferedImage.getSubimage((int)clip.getX(), (int)clip.getY(), (int)clip.getWidth(), (int)clip.getHeight());
|
||||
}
|
||||
catch (Exception e1) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (newImage != null) {
|
||||
sendImage(newImage, room);
|
||||
}
|
||||
if (newImage != null) {
|
||||
sendImage(newImage, room);
|
||||
}
|
||||
|
||||
frame.dispose();
|
||||
frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
frame.dispose();
|
||||
frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
|
||||
if (mainWindowVisible) {
|
||||
mainWindow.setVisible(true);
|
||||
}
|
||||
if (mainWindowVisible) {
|
||||
mainWindow.setVisible(true);
|
||||
}
|
||||
|
||||
if (chatFrameVisible) {
|
||||
chatFrame.setVisible(true);
|
||||
}
|
||||
if (chatFrameVisible) {
|
||||
chatFrame.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
frame.addKeyListener(new KeyAdapter() {
|
||||
public void keyTyped(KeyEvent e) {
|
||||
if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
|
||||
frame.dispose();
|
||||
frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
if (mainWindowVisible) {
|
||||
mainWindow.setVisible(true);
|
||||
}
|
||||
frame.addKeyListener(new KeyAdapter() {
|
||||
public void keyTyped(KeyEvent e) {
|
||||
if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
|
||||
frame.dispose();
|
||||
frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
if (mainWindowVisible) {
|
||||
mainWindow.setVisible(true);
|
||||
}
|
||||
|
||||
if (chatFrameVisible) {
|
||||
chatFrame.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if (chatFrameVisible) {
|
||||
chatFrame.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (bufferedImage != null) {
|
||||
if (bufferedImage != null) {
|
||||
|
||||
frame.setUndecorated(true);
|
||||
frame.setSize(bufferedImage.getWidth(null), bufferedImage.getHeight());
|
||||
frame.getContentPane().add(mainPanel);
|
||||
frame.setUndecorated(true);
|
||||
frame.setSize(bufferedImage.getWidth(null), bufferedImage.getHeight());
|
||||
frame.getContentPane().add(mainPanel);
|
||||
|
||||
// Determine if full-screen mode is supported directly
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice gs = ge.getDefaultScreenDevice();
|
||||
if (gs.isFullScreenSupported()) {
|
||||
// Determine if full-screen mode is supported directly
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice gs = ge.getDefaultScreenDevice();
|
||||
if (gs.isFullScreenSupported()) {
|
||||
|
||||
gs.setFullScreenWindow(frame);
|
||||
}
|
||||
else {
|
||||
// Full-screen mode will be simulated
|
||||
}
|
||||
}
|
||||
gs.setFullScreenWindow(frame);
|
||||
}
|
||||
else {
|
||||
// Full-screen mode will be simulated
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
button.setEnabled(true);
|
||||
}
|
||||
};
|
||||
worker.start();
|
||||
}
|
||||
|
||||
button.setEnabled(true);
|
||||
}
|
||||
};
|
||||
worker.start();
|
||||
}
|
||||
|
||||
private void addPresenceListener() {
|
||||
SparkManager.getConnection().addPacketListener(new PacketListener() {
|
||||
@ -599,7 +611,10 @@ public class SparkTransferManager {
|
||||
|
||||
|
||||
TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow();
|
||||
StyledDocument doc = (StyledDocument)transcriptWindow.getDocument();
|
||||
|
||||
// The image must first be wrapped in a style
|
||||
Style style = doc.addStyle("StyleName", null);
|
||||
|
||||
SendMessage sendingUI = new SendMessage();
|
||||
try {
|
||||
@ -636,7 +651,18 @@ public class SparkTransferManager {
|
||||
});
|
||||
|
||||
sendingUI.sendFile(transfer, transferManager, presence.getFrom(), contactItem.getNickname());
|
||||
transcriptWindow.addComponent(sendingUI);
|
||||
StyleConstants.setComponent(style, sendingUI);
|
||||
|
||||
// Insert the image at the end of the text
|
||||
try {
|
||||
doc.insertString(doc.getLength(), "ignored text", style);
|
||||
doc.insertString(doc.getLength(), "\n", null);
|
||||
}
|
||||
catch (BadLocationException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
chatRoom.scrollToBottom();
|
||||
return chatRoom;
|
||||
}
|
||||
|
||||
|
||||
@ -12,12 +12,25 @@ package org.jivesoftware.spark.ui;
|
||||
|
||||
import org.jdesktop.jdic.desktop.Desktop;
|
||||
import org.jivesoftware.Spark;
|
||||
import org.jivesoftware.resource.EmotionRes;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.plugin.ContextMenuListener;
|
||||
import org.jivesoftware.spark.util.BrowserLauncher;
|
||||
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;
|
||||
@ -36,19 +49,6 @@ 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.
|
||||
@ -91,10 +91,14 @@ public class ChatArea extends JTextPane implements MouseListener, MouseMotionLis
|
||||
|
||||
private List interceptors = new ArrayList();
|
||||
|
||||
private EmoticonManager emoticonManager;
|
||||
|
||||
/**
|
||||
* ChatArea Constructor.
|
||||
*/
|
||||
public ChatArea() {
|
||||
emoticonManager = EmoticonManager.getInstance();
|
||||
|
||||
final Action cutAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String selectedText = getSelectedText();
|
||||
@ -178,7 +182,7 @@ public class ChatArea extends JTextPane implements MouseListener, MouseMotionLis
|
||||
setCursor(HAND_CURSOR);
|
||||
|
||||
// Make sure the message is not null.
|
||||
// message = message.trim();
|
||||
// message = message.trim();
|
||||
message = message.replaceAll("/\"", "");
|
||||
if (ModelUtil.hasLength(message)) {
|
||||
try {
|
||||
@ -229,7 +233,7 @@ public class ChatArea extends JTextPane implements MouseListener, MouseMotionLis
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String textFound = tokenizer.nextToken();
|
||||
if (textFound.startsWith("http://") || textFound.startsWith("ftp://")
|
||||
|| textFound.startsWith("https://") || textFound.startsWith("www.") || textFound.startsWith("\\") || textFound.indexOf("://") != -1) {
|
||||
|| textFound.startsWith("https://") || textFound.startsWith("www.") || textFound.startsWith("\\") || textFound.indexOf("://") != -1) {
|
||||
insertLink(textFound);
|
||||
}
|
||||
else if (!insertImage(textFound)) {
|
||||
@ -293,19 +297,16 @@ public class ChatArea extends JTextPane implements MouseListener, MouseMotionLis
|
||||
/**
|
||||
* Inserts an emotion icon into the current document.
|
||||
*
|
||||
* @param image - the smiley representation of the image.( ex. :) )
|
||||
* @param imageKey - the smiley representation of the image.( ex. :) )
|
||||
* @return true if the image was found, otherwise false.
|
||||
*/
|
||||
public boolean insertImage(String image) {
|
||||
public boolean insertImage(String imageKey) {
|
||||
final Document doc = getDocument();
|
||||
Icon emotion = EmotionRes.getImageIcon(image.toLowerCase());
|
||||
if (emotion == null) {
|
||||
emotion = EmotionRes.getImageIcon(image);
|
||||
}
|
||||
|
||||
Icon emotion = emoticonManager.getEmoticonImage(imageKey.toLowerCase());
|
||||
if (emotion == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setEditable(true);
|
||||
select(doc.getLength(), doc.getLength());
|
||||
insertIcon(emotion);
|
||||
@ -570,7 +571,7 @@ public class ChatArea extends JTextPane implements MouseListener, MouseMotionLis
|
||||
|
||||
// swing text.. :-/
|
||||
if (j == rootElem.getElementCount() - 1
|
||||
&& i == pElem.getElementCount() - 1) {
|
||||
&& i == pElem.getElementCount() - 1) {
|
||||
end = text.length();
|
||||
}
|
||||
|
||||
@ -591,7 +592,7 @@ public class ChatArea extends JTextPane implements MouseListener, MouseMotionLis
|
||||
while (tkn.hasMoreTokens()) {
|
||||
final String token = tkn.nextToken();
|
||||
if (token.startsWith("http://") || token.startsWith("ftp://")
|
||||
|| token.startsWith("https://")) {
|
||||
|| token.startsWith("https://")) {
|
||||
buf.append("[url]").append(token).append("[/url]");
|
||||
}
|
||||
else if (token.startsWith("www")) {
|
||||
|
||||
@ -21,17 +21,22 @@ import org.jivesoftware.spark.ChatAreaSendField;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.component.BackgroundPanel;
|
||||
import org.jivesoftware.spark.component.RolloverButton;
|
||||
import org.jivesoftware.spark.plugin.ContextMenuListener;
|
||||
import org.jivesoftware.spark.util.GraphicUtils;
|
||||
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.Icon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JOptionPane;
|
||||
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;
|
||||
@ -44,7 +49,6 @@ import javax.swing.text.Document;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
@ -67,28 +71,30 @@ import java.util.List;
|
||||
public abstract class ChatRoom extends BackgroundPanel implements ActionListener, PacketListener, DocumentListener, ConnectionListener {
|
||||
private final JPanel chatPanel;
|
||||
private final JSplitPane splitPane;
|
||||
private final JLabel notificationLabel;
|
||||
private final TranscriptWindow transcriptWindow;
|
||||
private final ChatAreaSendField chatAreaButton;
|
||||
private final ChatToolBar toolbar;
|
||||
private final JScrollPane textScroller;
|
||||
private final JPanel bottomPanel;
|
||||
private final JPanel editorBar;
|
||||
private JPanel chatWindowPanel;
|
||||
|
||||
private final List packetIDList;
|
||||
private final List messageListeners;
|
||||
private List transcript;
|
||||
private List fileDropListeners;
|
||||
|
||||
private int unreadMessageCount;
|
||||
|
||||
private boolean mousePressed;
|
||||
|
||||
private List closingListeners = new ArrayList();
|
||||
|
||||
protected final TranscriptWindow transcriptWindow;
|
||||
|
||||
|
||||
final JSplitPane verticalSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
||||
|
||||
private ChatRoomTransferHandler transferHandler;
|
||||
|
||||
private final List packetIDList;
|
||||
private final List messageListeners;
|
||||
private List transcript;
|
||||
private List fileDropListeners;
|
||||
|
||||
/**
|
||||
* Initializes the base layout and base background color.
|
||||
@ -98,6 +104,7 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
transcriptWindow = new TranscriptWindow();
|
||||
splitPane = new JSplitPane();
|
||||
packetIDList = new ArrayList();
|
||||
notificationLabel = new JLabel();
|
||||
toolbar = new ChatToolBar();
|
||||
bottomPanel = new JPanel();
|
||||
|
||||
@ -112,24 +119,28 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
|
||||
if (transcriptWindow.getSelectedText() == null) {
|
||||
getChatInputEditor().requestFocus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
textScroller = new JScrollPane(transcriptWindow);
|
||||
|
||||
chatAreaButton = new ChatAreaSendField(SparkRes.getString(SparkRes.SEND)) {
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension dim = super.getPreferredSize();
|
||||
|
||||
int windowHeight = getChatRoom().getHeight();
|
||||
|
||||
if (dim.getHeight() > windowHeight - 200) {
|
||||
dim.height = windowHeight - 200;
|
||||
}
|
||||
|
||||
return dim;
|
||||
textScroller.getVerticalScrollBar().addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
mousePressed = true;
|
||||
}
|
||||
};
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
mousePressed = false;
|
||||
}
|
||||
});
|
||||
|
||||
textScroller.setBackground(transcriptWindow.getBackground());
|
||||
textScroller.getViewport().setBackground(Color.white);
|
||||
|
||||
chatAreaButton = new ChatAreaSendField(SparkRes.getString(SparkRes.SEND));
|
||||
|
||||
getChatInputEditor().setSelectedTextColor((Color)UIManager.get("ChatInput.SelectedTextColor"));
|
||||
getChatInputEditor().setSelectionColor((Color)UIManager.get("ChatInput.SelectionColor"));
|
||||
@ -140,7 +151,9 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
// Initally, set the right pane to null to keep it empty.
|
||||
getSplitPane().setRightComponent(null);
|
||||
|
||||
/*
|
||||
notificationLabel.setIcon(SparkRes.getImageIcon(SparkRes.BLANK_IMAGE));
|
||||
|
||||
|
||||
getTranscriptWindow().addContextMenuListener(new ContextMenuListener() {
|
||||
public void poppingUp(Object component, JPopupMenu popup) {
|
||||
Action saveAction = new AbstractAction() {
|
||||
@ -163,7 +176,6 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
return false;
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("F12"), "showDebugger");
|
||||
this.getActionMap().put("showDebugger", new AbstractAction("showDebugger") {
|
||||
@ -173,11 +185,16 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
}
|
||||
});
|
||||
|
||||
getTranscriptWindow().setTransferHandler(new ChatRoomTransferHandler(this));
|
||||
getChatInputEditor().setTransferHandler(new ChatRoomTransferHandler(this));
|
||||
|
||||
transferHandler = new ChatRoomTransferHandler(this);
|
||||
|
||||
getTranscriptWindow().setTransferHandler(transferHandler);
|
||||
getChatInputEditor().setTransferHandler(transferHandler);
|
||||
|
||||
add(toolbar, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
|
||||
|
||||
// Add Connection Listener
|
||||
SparkManager.getConnection().addConnectionListener(this);
|
||||
}
|
||||
|
||||
// Setup base layout.
|
||||
@ -186,16 +203,22 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
|
||||
|
||||
add(splitPane, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
|
||||
// add(notificationLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 2, 5, 0), 0, 0));
|
||||
|
||||
// Remove Default Beveled Borders
|
||||
splitPane.setBorder(null);
|
||||
verticalSplit.setBorder(null);
|
||||
splitPane.setLeftComponent(verticalSplit);
|
||||
|
||||
textScroller.setAutoscrolls(true);
|
||||
|
||||
// Speed up scrolling. It was way too slow.
|
||||
textScroller.getVerticalScrollBar().setBlockIncrement(50);
|
||||
textScroller.getVerticalScrollBar().setUnitIncrement(20);
|
||||
|
||||
chatWindowPanel = new JPanel();
|
||||
chatWindowPanel.setLayout(new GridBagLayout());
|
||||
chatWindowPanel.add(transcriptWindow, new GridBagConstraints(0, 10, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
|
||||
chatWindowPanel.add(textScroller, new GridBagConstraints(0, 10, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
|
||||
chatWindowPanel.setOpaque(false);
|
||||
|
||||
// Layout Components
|
||||
@ -211,14 +234,14 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
bottomPanel.setOpaque(false);
|
||||
splitPane.setOpaque(false);
|
||||
bottomPanel.setLayout(new GridBagLayout());
|
||||
bottomPanel.add(chatAreaButton, new GridBagConstraints(0, 1, 5, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 10));
|
||||
bottomPanel.add(chatAreaButton, new GridBagConstraints(0, 1, 5, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 15));
|
||||
bottomPanel.add(editorBar, new GridBagConstraints(0, 0, 5, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
|
||||
verticalSplit.setOpaque(false);
|
||||
|
||||
verticalSplit.setTopComponent(chatPanel);
|
||||
verticalSplit.setBottomComponent(bottomPanel);
|
||||
verticalSplit.setResizeWeight(1.0);
|
||||
verticalSplit.setDividerSize(1);
|
||||
verticalSplit.setDividerSize(2);
|
||||
|
||||
// Add listener to send button
|
||||
chatAreaButton.getButton().addActionListener(this);
|
||||
@ -236,16 +259,10 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
getChatInputEditor().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ctrl F4"), "closeTheRoom");
|
||||
getChatInputEditor().getActionMap().put("closeTheRoom", new AbstractAction("closeTheRoom") {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
final int ok = JOptionPane.showConfirmDialog(SparkManager.getMainWindow(), Res.getString("message.end.chat"),
|
||||
Res.getString("title.confirmation"), JOptionPane.YES_NO_OPTION);
|
||||
if (ok == JOptionPane.OK_OPTION) {
|
||||
// Leave this chat.
|
||||
closeChatRoom();
|
||||
}
|
||||
// Leave this chat.
|
||||
closeChatRoom();
|
||||
}
|
||||
});
|
||||
|
||||
SparkManager.getConnection().addConnectionListener(this);
|
||||
}
|
||||
|
||||
|
||||
@ -327,6 +344,12 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
|
||||
transcript.add(newMessage);
|
||||
|
||||
// Add current date if this is the current agent
|
||||
if (updateDate && transcriptWindow.getLastUpdated() != null) {
|
||||
// Set new label date
|
||||
notificationLabel.setIcon(SparkRes.getImageIcon(SparkRes.SMALL_ABOUT_IMAGE));
|
||||
notificationLabel.setText(Res.getString("message.last.message.received", SparkManager.DATE_SECOND_FORMATTER.format(transcriptWindow.getLastUpdated())));
|
||||
}
|
||||
|
||||
scrollToBottom();
|
||||
}
|
||||
@ -339,7 +362,32 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
return;
|
||||
}
|
||||
|
||||
transcriptWindow.scrollToBottom();
|
||||
int chatLength = transcriptWindow.getDocument().getLength();
|
||||
transcriptWindow.setCaretPosition(chatLength);
|
||||
|
||||
try {
|
||||
JScrollBar sb = textScroller.getVerticalScrollBar();
|
||||
sb.setValue(sb.getMaximum());
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
/*
|
||||
try {
|
||||
JScrollBar vbar = textScroller.getVerticalScrollBar();
|
||||
int whereWeAt = vbar.getValue() + vbar.getVisibleAmount();
|
||||
if (whereWeAt < vbar.getMaximum() - 50) {
|
||||
|
||||
}
|
||||
else {
|
||||
vbar.setValue(vbar.getMaximum());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.error(e);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@ -356,8 +404,6 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
else {
|
||||
chatAreaButton.getButton().setEnabled(false);
|
||||
}
|
||||
|
||||
verticalSplit.setDividerLocation(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -516,6 +562,7 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
* @param docEvent the document event.
|
||||
*/
|
||||
public void changedUpdate(DocumentEvent docEvent) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
@ -541,6 +588,17 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
*/
|
||||
public void closeChatRoom() {
|
||||
fireClosingListeners();
|
||||
|
||||
// Remove Connection Listener
|
||||
SparkManager.getConnection().removeConnectionListener(this);
|
||||
getTranscriptWindow().setTransferHandler(null);
|
||||
getChatInputEditor().setTransferHandler(null);
|
||||
|
||||
transferHandler = null;
|
||||
|
||||
packetIDList.clear();
|
||||
messageListeners.clear();
|
||||
fileDropListeners.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -594,6 +652,17 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
public abstract boolean isActive();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the notification label. The notification label notifies the
|
||||
* user of chat room activity, such as the date of the last message
|
||||
* and typing notifications.
|
||||
*
|
||||
* @return the notification label.
|
||||
*/
|
||||
public JLabel getNotificationLabel() {
|
||||
return notificationLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a packetID to the packedIDList. The packetIDLlist
|
||||
* keeps track of all messages coming into the chatroom.
|
||||
@ -669,7 +738,7 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
*/
|
||||
public ChatToolBar() {
|
||||
buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 0));
|
||||
buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0));
|
||||
|
||||
rightPanel = new JPanel();
|
||||
rightPanel.setOpaque(false);
|
||||
@ -679,7 +748,7 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
setLayout(new GridBagLayout());
|
||||
|
||||
buttonPanel.setOpaque(false);
|
||||
add(buttonPanel, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
|
||||
add(buttonPanel, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
|
||||
setOpaque(false);
|
||||
}
|
||||
|
||||
@ -825,6 +894,9 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
}
|
||||
}
|
||||
|
||||
public JScrollPane getScrollPaneForTranscriptWindow() {
|
||||
return textScroller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the "Send" button.
|
||||
@ -851,16 +923,16 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
public void connectionClosed() {
|
||||
}
|
||||
|
||||
public void connectionClosedOnError(Exception exception) {
|
||||
public void connectionClosedOnError(Exception e) {
|
||||
}
|
||||
|
||||
public void reconnectingIn(int i) {
|
||||
public void reconnectingIn(int seconds) {
|
||||
}
|
||||
|
||||
public void reconnectionSuccessful() {
|
||||
}
|
||||
|
||||
public void reconnectionFailed(Exception exception) {
|
||||
public void reconnectionFailed(Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -122,11 +122,7 @@ public class ChatRoomTransferHandler extends TransferHandler {
|
||||
if (!DataFlavor.stringFlavor.equals(flavor)) {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
return "";
|
||||
return item.getSelectedText();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -10,189 +10,169 @@
|
||||
|
||||
package org.jivesoftware.spark.ui;
|
||||
|
||||
import com.webrenderer.BrowserFactory;
|
||||
import com.webrenderer.IBrowserCanvas;
|
||||
import com.webrenderer.event.MouseEvent;
|
||||
import com.webrenderer.event.MouseListener;
|
||||
import com.webrenderer.event.NetworkEvent;
|
||||
import com.webrenderer.event.NetworkListener;
|
||||
import org.jdesktop.swingx.calendar.DateUtils;
|
||||
import org.jivesoftware.Spark;
|
||||
import org.jivesoftware.resource.SparkRes;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.packet.DelayInformation;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.component.VerticalFlowLayout;
|
||||
import org.jivesoftware.spark.ui.themes.ThemeManager;
|
||||
import org.jivesoftware.spark.plugin.ContextMenuListener;
|
||||
import org.jivesoftware.spark.preference.PreferenceManager;
|
||||
import org.jivesoftware.spark.util.ModelUtil;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
import org.jivesoftware.sparkimpl.plugin.emoticons.Emoticon;
|
||||
import org.jivesoftware.sparkimpl.plugin.emoticons.EmoticonManager;
|
||||
import org.jivesoftware.sparkimpl.profile.VCardManager;
|
||||
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.JComponent;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
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 JPanel {
|
||||
public class TranscriptWindow extends ChatArea {
|
||||
|
||||
private List<TranscriptWindowInterceptor> interceptors = new ArrayList<TranscriptWindowInterceptor>();
|
||||
private final SimpleDateFormat notificationDateFormatter;
|
||||
private final SimpleDateFormat messageDateFormatter;
|
||||
|
||||
|
||||
private Date lastUpdated;
|
||||
|
||||
private IBrowserCanvas browser;
|
||||
/**
|
||||
* The default font used in the chat window for all messages.
|
||||
*/
|
||||
private Font font = new Font("Dialog", Font.PLAIN, 12);
|
||||
|
||||
private ThemeManager themeManager;
|
||||
private Date lastPost;
|
||||
|
||||
private String activeUser;
|
||||
private String activeHistoryUser;
|
||||
|
||||
|
||||
private boolean documentLoaded;
|
||||
|
||||
private JPanel extraPanel;
|
||||
|
||||
private VCardManager vcardManager;
|
||||
|
||||
private Timer timer;
|
||||
|
||||
private javax.swing.Timer activeTimer;
|
||||
|
||||
private StringBuilder scriptBuilder = new StringBuilder();
|
||||
|
||||
private final SimpleDateFormat formatter = new SimpleDateFormat("h:mm");
|
||||
private Image customBackgroundImage;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a default instance of <code>TranscriptWindow</code>.
|
||||
*/
|
||||
public TranscriptWindow() {
|
||||
setLayout(new BorderLayout());
|
||||
setEditable(false);
|
||||
|
||||
themeManager = ThemeManager.getInstance();
|
||||
vcardManager = SparkManager.getVCardManager();
|
||||
/* Load Preferences for this instance */
|
||||
PreferenceManager preferenceManager = SparkManager.getPreferenceManager();
|
||||
|
||||
extraPanel = new JPanel();
|
||||
addMouseListener(this);
|
||||
addMouseMotionListener(this);
|
||||
setDragEnabled(true);
|
||||
|
||||
//Core function to create browser
|
||||
browser = BrowserFactory.spawnMozilla();
|
||||
browser.addNetworkListener(new NetworkListener() {
|
||||
public void onProgressChange(NetworkEvent networkEvent) {
|
||||
}
|
||||
|
||||
public void onDocumentLoad(NetworkEvent networkEvent) {
|
||||
documentLoaded = true;
|
||||
}
|
||||
|
||||
public void onDocumentComplete(NetworkEvent networkEvent) {
|
||||
}
|
||||
|
||||
public void onNetworkStatus(NetworkEvent networkEvent) {
|
||||
}
|
||||
|
||||
public void onNetworkError(NetworkEvent networkEvent) {
|
||||
}
|
||||
|
||||
public void onHTTPResponse(NetworkEvent networkEvent) {
|
||||
}
|
||||
|
||||
public void onHTTPInterceptHeaders(NetworkEvent networkEvent) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
browser.loadURL(themeManager.getTemplateURL());
|
||||
|
||||
documentLoaded = true;
|
||||
|
||||
browser.enableDefaultContextMenu(false);
|
||||
|
||||
browser.addMouseListener(new MouseListener() {
|
||||
public void onClick(MouseEvent mouseEvent) {
|
||||
}
|
||||
|
||||
public void onDoubleClick(MouseEvent mouseEvent) {
|
||||
mouseEvent.consume();
|
||||
}
|
||||
|
||||
public void onMouseDown(MouseEvent mouseEvent) {
|
||||
mouseEvent.consume();
|
||||
}
|
||||
|
||||
public void onMouseUp(MouseEvent mouseEvent) {
|
||||
mouseEvent.consume();
|
||||
}
|
||||
});
|
||||
|
||||
add((Canvas)browser, BorderLayout.CENTER);
|
||||
|
||||
|
||||
extraPanel.setBackground(Color.white);
|
||||
extraPanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));
|
||||
|
||||
add(extraPanel, BorderLayout.SOUTH);
|
||||
|
||||
setBorder(BorderFactory.createLineBorder(Color.lightGray));
|
||||
|
||||
final Action resetAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
activeUser = null;
|
||||
}
|
||||
};
|
||||
|
||||
int fiveMinutes = 5000 * 60;
|
||||
activeTimer = new javax.swing.Timer(fiveMinutes, resetAction);
|
||||
activeTimer.start();
|
||||
|
||||
final Action insertAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (documentLoaded) {
|
||||
final String script = scriptBuilder.toString();
|
||||
if (ModelUtil.hasLength(script)) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
browser.executeScript(script);
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
|
||||
scriptBuilder.setLength(0);
|
||||
final TranscriptWindow window = this;
|
||||
addContextMenuListener(new ContextMenuListener() {
|
||||
public void poppingUp(Object component, JPopupMenu popup) {
|
||||
Action printAction = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
SparkManager.printChatTranscript(window);
|
||||
}
|
||||
}
|
||||
timer.restart();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
timer = new Timer(50, insertAction);
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
// Make sure ctrl-c works
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("Ctrl c"), "copy");
|
||||
|
||||
getActionMap().put("copy", new AbstractAction("copy") {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
StringSelection ss = new StringSelection(getSelectedText());
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
|
||||
}
|
||||
});
|
||||
|
||||
notificationDateFormatter = new SimpleDateFormat("EEEEE, MMMMM d, yyyy");
|
||||
messageDateFormatter = new SimpleDateFormat("h:mm a");
|
||||
}
|
||||
|
||||
public void addComponent(Component component) {
|
||||
StyledDocument doc = (StyledDocument)getDocument();
|
||||
|
||||
// The image must first be wrapped in a style
|
||||
Style style = doc.addStyle("StyleName", null);
|
||||
|
||||
|
||||
StyleConstants.setComponent(style, component);
|
||||
|
||||
// Insert the image at the end of the text
|
||||
try {
|
||||
doc.insertString(doc.getLength(), "ignored text", style);
|
||||
doc.insertString(doc.getLength(), "\n", null);
|
||||
}
|
||||
catch (BadLocationException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
if (customBackgroundImage != null) {
|
||||
Rectangle rec = getVisibleRect();
|
||||
setOpaque(false);
|
||||
g.drawImage(customBackgroundImage, getWidth() - customBackgroundImage.getWidth(null), (int)rec.getY(), customBackgroundImage.getWidth(null), customBackgroundImage.getHeight(null), this);
|
||||
}
|
||||
super.paintComponent(g);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and insert a message from the current user.
|
||||
@ -201,6 +181,7 @@ public class TranscriptWindow extends JPanel {
|
||||
* @param message the message to insert.
|
||||
*/
|
||||
public void insertMessage(String userid, Message message) {
|
||||
|
||||
// Check interceptors.
|
||||
for (TranscriptWindowInterceptor interceptor : interceptors) {
|
||||
boolean handled = interceptor.handleInsertMessage(userid, message);
|
||||
@ -211,42 +192,70 @@ public class TranscriptWindow extends JPanel {
|
||||
}
|
||||
|
||||
String body = message.getBody();
|
||||
body = org.jivesoftware.spark.util.StringUtils.escapeHTMLTags(body);
|
||||
body = filterBody(body);
|
||||
String date = getDate(null);
|
||||
|
||||
String jid = SparkManager.getSessionManager().getJID();
|
||||
try {
|
||||
String date = getDate(null);
|
||||
|
||||
// Agent color is always blue
|
||||
StyleConstants.setBold(styles, false);
|
||||
StyleConstants.setForeground(styles, (Color)UIManager.get("User.foreground"));
|
||||
final Document doc = getDocument();
|
||||
styles.removeAttribute("link");
|
||||
|
||||
if (userid.equals(activeUser)) {
|
||||
String text = themeManager.getNextOutgoingMessage(body, date);
|
||||
executeScript("appendNextMessage('" + text + "')");
|
||||
StyleConstants.setFontSize(styles, font.getSize());
|
||||
doc.insertString(doc.getLength(), date + userid + ": ", styles);
|
||||
|
||||
// Reset Styles for message
|
||||
StyleConstants.setBold(styles, false);
|
||||
setText(body);
|
||||
insertText("\n");
|
||||
}
|
||||
else {
|
||||
String text = themeManager.getOutgoingMessage(userid, date, body, vcardManager.getAvatar(jid));
|
||||
executeScript("appendMessage('" + text + "')");
|
||||
catch (BadLocationException e) {
|
||||
Log.error("Error message.", e);
|
||||
}
|
||||
|
||||
setActiveUser(userid);
|
||||
}
|
||||
|
||||
|
||||
public void insertCustomMessage(String prefix, String message) {
|
||||
message = filterBody(message);
|
||||
String text = themeManager.getOutgoingMessage(prefix, "", message, vcardManager.getAvatar(""));
|
||||
executeScript("appendMessage('" + text + "')");
|
||||
try {
|
||||
// Agent color is always blue
|
||||
StyleConstants.setBold(styles, false);
|
||||
StyleConstants.setForeground(styles, (Color)UIManager.get("User.foreground"));
|
||||
final Document doc = getDocument();
|
||||
styles.removeAttribute("link");
|
||||
|
||||
StyleConstants.setFontSize(styles, font.getSize());
|
||||
if (prefix != null) {
|
||||
doc.insertString(doc.getLength(), prefix + ": ", styles);
|
||||
}
|
||||
|
||||
// Reset Styles for message
|
||||
StyleConstants.setBold(styles, false);
|
||||
setText(message);
|
||||
insertText("\n");
|
||||
}
|
||||
catch (BadLocationException e) {
|
||||
Log.error("Error message.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a custom message into the transcript window.
|
||||
*
|
||||
* @param prefix the prefix of the message (ex: johndoe:)
|
||||
* @param message the body of the message.
|
||||
*/
|
||||
public void insertCustomOtherMessage(String prefix, String message) {
|
||||
message = filterBody(message);
|
||||
String text = themeManager.getIncomingMessage(prefix, "", message, vcardManager.getAvatar(""));
|
||||
executeScript("appendMessage('" + text + "')");
|
||||
try {
|
||||
StyleConstants.setBold(styles, false);
|
||||
StyleConstants.setForeground(styles, (Color)UIManager.get("OtherUser.foreground"));
|
||||
final Document doc = getDocument();
|
||||
styles.removeAttribute("link");
|
||||
|
||||
StyleConstants.setFontSize(styles, font.getSize());
|
||||
doc.insertString(doc.getLength(), prefix + ": ", styles);
|
||||
|
||||
StyleConstants.setBold(styles, false);
|
||||
setText(message);
|
||||
insertText("\n");
|
||||
}
|
||||
catch (BadLocationException ex) {
|
||||
Log.error("Error message.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -267,7 +276,6 @@ public class TranscriptWindow extends JPanel {
|
||||
|
||||
String body = message.getBody();
|
||||
|
||||
|
||||
try {
|
||||
DelayInformation inf = (DelayInformation)message.getExtension("x", "jabber:x:delay");
|
||||
Date sentDate = null;
|
||||
@ -282,21 +290,81 @@ public class TranscriptWindow extends JPanel {
|
||||
|
||||
String theDate = getDate(sentDate);
|
||||
|
||||
body = org.jivesoftware.spark.util.StringUtils.escapeHTMLTags(body);
|
||||
body = filterBody(body);
|
||||
StyleConstants.setBold(styles, false);
|
||||
StyleConstants.setForeground(styles, (Color)UIManager.get("OtherUser.foreground"));
|
||||
final Document doc = getDocument();
|
||||
styles.removeAttribute("link");
|
||||
|
||||
if (userid.equals(activeUser)) {
|
||||
String text = themeManager.getNextIncomingMessage(body, theDate);
|
||||
executeScript("appendNextMessage('" + text + "')");
|
||||
}
|
||||
else {
|
||||
String text = themeManager.getIncomingMessage(userid, theDate, body, vcardManager.getAvatar(message.getFrom()));
|
||||
executeScript("appendMessage('" + text + "')");
|
||||
}
|
||||
StyleConstants.setFontSize(styles, font.getSize());
|
||||
doc.insertString(doc.getLength(), theDate + userid + ": ", styles);
|
||||
|
||||
setActiveUser(userid);
|
||||
StyleConstants.setBold(styles, false);
|
||||
setText(body);
|
||||
insertText("\n");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (BadLocationException ex) {
|
||||
Log.error("Error message.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create and insert a notification message. A notification message generally is a
|
||||
* presence update, but can be used for most anything related to the room.
|
||||
*
|
||||
* @param timestamp the information message to insert.
|
||||
*/
|
||||
public synchronized void insertTimestamp(String timestamp) {
|
||||
try {
|
||||
// Agent color is always blue
|
||||
StyleConstants.setBold(styles, true);
|
||||
StyleConstants.setForeground(styles, Color.lightGray);
|
||||
final Document doc = getDocument();
|
||||
styles.removeAttribute("link");
|
||||
|
||||
StyleConstants.setFontSize(styles, font.getSize());
|
||||
doc.insertString(doc.getLength(), "", styles);
|
||||
|
||||
// Reset Styles for message
|
||||
StyleConstants.setBold(styles, true);
|
||||
StyleConstants.setUnderline(styles, true);
|
||||
setForeground(Color.lightGray);
|
||||
setText(timestamp);
|
||||
insertText("\n");
|
||||
StyleConstants.setUnderline(styles, false);
|
||||
setForeground(Color.black);
|
||||
}
|
||||
catch (BadLocationException ex) {
|
||||
Log.error("Error message.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and inserts a title notification message.
|
||||
*
|
||||
* @param title the title to insert into the chat transcript.
|
||||
*/
|
||||
public synchronized void insertTitle(String title) {
|
||||
try {
|
||||
// Agent color is always blue
|
||||
StyleConstants.setBold(styles, true);
|
||||
StyleConstants.setForeground(styles, Color.gray);
|
||||
final Document doc = getDocument();
|
||||
styles.removeAttribute("link");
|
||||
|
||||
StyleConstants.setFontSize(styles, font.getSize());
|
||||
doc.insertString(doc.getLength(), "", styles);
|
||||
|
||||
// Reset Styles for message
|
||||
StyleConstants.setBold(styles, true);
|
||||
StyleConstants.setUnderline(styles, true);
|
||||
setForeground(Color.gray);
|
||||
setText(title);
|
||||
insertText("\n");
|
||||
StyleConstants.setUnderline(styles, false);
|
||||
setForeground(Color.black);
|
||||
}
|
||||
catch (BadLocationException ex) {
|
||||
Log.error("Error message.", ex);
|
||||
}
|
||||
}
|
||||
@ -309,9 +377,29 @@ public class TranscriptWindow extends JPanel {
|
||||
* @param message the information message to insert.
|
||||
*/
|
||||
public synchronized void insertNotificationMessage(String message) {
|
||||
message = filterBody(message);
|
||||
String text = themeManager.getStatusMessage(message, "");
|
||||
executeScript("appendMessage('" + text + "')");
|
||||
try {
|
||||
|
||||
Color notificationColor = (Color)UIManager.get("Notification.foreground");
|
||||
|
||||
// Agent color is always blue
|
||||
StyleConstants.setBold(styles, false);
|
||||
StyleConstants.setForeground(styles, notificationColor);
|
||||
final Document doc = getDocument();
|
||||
styles.removeAttribute("link");
|
||||
|
||||
StyleConstants.setFontSize(styles, font.getSize());
|
||||
doc.insertString(doc.getLength(), "", styles);
|
||||
|
||||
// Reset Styles for message
|
||||
StyleConstants.setBold(styles, false);
|
||||
setForeground(notificationColor);
|
||||
setText(message);
|
||||
insertText("\n");
|
||||
setForeground(Color.black);
|
||||
}
|
||||
catch (BadLocationException ex) {
|
||||
Log.error("Error message.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,9 +408,26 @@ public class TranscriptWindow extends JPanel {
|
||||
* @param message the information message to insert.
|
||||
*/
|
||||
public void insertErrorMessage(String message) {
|
||||
message = filterBody(message);
|
||||
String text = themeManager.getStatusMessage(message, "");
|
||||
executeScript("appendMessage('" + text + "')");
|
||||
try {
|
||||
// Agent color is always blue
|
||||
StyleConstants.setBold(styles, false);
|
||||
StyleConstants.setForeground(styles, (Color)UIManager.get("Error.foreground"));
|
||||
final Document doc = getDocument();
|
||||
styles.removeAttribute("link");
|
||||
|
||||
StyleConstants.setFontSize(styles, font.getSize());
|
||||
doc.insertString(doc.getLength(), "", styles);
|
||||
|
||||
// Reset Styles for message
|
||||
StyleConstants.setBold(styles, false);
|
||||
setForeground(Color.red);
|
||||
setText(message);
|
||||
insertText("\n");
|
||||
setForeground(Color.black);
|
||||
}
|
||||
catch (BadLocationException ex) {
|
||||
Log.error("Error message.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -332,12 +437,25 @@ public class TranscriptWindow extends JPanel {
|
||||
* @param question the question asked by the customer.
|
||||
*/
|
||||
public void insertQuestionMessage(String question) {
|
||||
String text = themeManager.getStatusMessage(question, "");
|
||||
executeScript("appendMessage('" + text + "')");
|
||||
}
|
||||
|
||||
public void insertHTML(String html) {
|
||||
executeScript("appendMessage('" + html + "')");
|
||||
try {
|
||||
StyleConstants.setBold(styles, false);
|
||||
StyleConstants.setForeground(styles, (Color)UIManager.get("Question.foreground"));
|
||||
final Document doc = getDocument();
|
||||
styles.removeAttribute("link");
|
||||
|
||||
StyleConstants.setFontSize(styles, font.getSize());
|
||||
StyleConstants.setFontFamily(styles, font.getFamily());
|
||||
doc.insertString(doc.getLength(), "Question - ", styles);
|
||||
|
||||
StyleConstants.setBold(styles, false);
|
||||
setText(question);
|
||||
insertText("\n");
|
||||
}
|
||||
catch (BadLocationException e) {
|
||||
Log.error("Error message.", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -348,15 +466,20 @@ public class TranscriptWindow extends JPanel {
|
||||
* @return the formatted date.
|
||||
*/
|
||||
private String getDate(Date insertDate) {
|
||||
final LocalPreferences localPreferences = SettingsManager.getLocalPreferences();
|
||||
final LocalPreferences pref = SettingsManager.getLocalPreferences();
|
||||
|
||||
if (insertDate == null) {
|
||||
insertDate = new Date();
|
||||
}
|
||||
|
||||
StyleConstants.setFontFamily(styles, font.getFontName());
|
||||
StyleConstants.setFontSize(styles, font.getSize());
|
||||
|
||||
if (localPreferences.isTimeDisplayedInChat()) {
|
||||
return formatter.format(insertDate);
|
||||
if (pref.isTimeDisplayedInChat()) {
|
||||
final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
|
||||
final String date = formatter.format(insertDate);
|
||||
|
||||
return "[" + date + "] ";
|
||||
}
|
||||
lastUpdated = insertDate;
|
||||
return "";
|
||||
@ -375,52 +498,45 @@ public class TranscriptWindow extends JPanel {
|
||||
/**
|
||||
* Inserts a history message.
|
||||
*
|
||||
* @param jid the users jid.
|
||||
* @param userid the userid of the sender.
|
||||
* @param message the message to insert.
|
||||
* @param date the Date object created when the message was delivered.
|
||||
*/
|
||||
public void insertHistoryMessage(String jid, String userid, String message, Date date) {
|
||||
final String sessionJID = SparkManager.getSessionManager().getJID();
|
||||
boolean outgoingMessage = false;
|
||||
if (StringUtils.parseBareAddress(sessionJID).equals(jid)) {
|
||||
outgoingMessage = true;
|
||||
public void insertHistoryMessage(String userid, String message, Date date) {
|
||||
try {
|
||||
String value = "";
|
||||
|
||||
long lastPostTime = lastPost != null ? lastPost.getTime() : 0;
|
||||
int diff = DateUtils.getDaysDiff(lastPostTime, date.getTime());
|
||||
if (diff != 0) {
|
||||
insertTimestamp(notificationDateFormatter.format(date));
|
||||
}
|
||||
|
||||
value = "[" + messageDateFormatter.format(date) + "] ";
|
||||
value = value + userid + ": ";
|
||||
|
||||
|
||||
lastPost = date;
|
||||
|
||||
// Agent color is always blue
|
||||
StyleConstants.setBold(styles, false);
|
||||
StyleConstants.setForeground(styles, Color.gray);
|
||||
final Document doc = getDocument();
|
||||
styles.removeAttribute("link");
|
||||
|
||||
StyleConstants.setFontSize(styles, font.getSize());
|
||||
doc.insertString(doc.getLength(), value, styles);
|
||||
|
||||
// Reset Styles for message
|
||||
StyleConstants.setBold(styles, false);
|
||||
setForeground((Color)UIManager.get("History.foreground"));
|
||||
setText(message);
|
||||
setForeground(Color.BLACK);
|
||||
insertText("\n");
|
||||
}
|
||||
|
||||
final SimpleDateFormat formatter = new SimpleDateFormat("h:mm");
|
||||
String time = formatter.format(date);
|
||||
|
||||
message = filterBody(message);
|
||||
|
||||
if (userid.equals(activeHistoryUser)) {
|
||||
if (outgoingMessage) {
|
||||
String text = themeManager.getNextOutgoingHistoryString(message, time);
|
||||
executeScript("appendNextMessage('" + text + "')");
|
||||
}
|
||||
else {
|
||||
String text = themeManager.getNextIncomingHistoryMessage(message, time);
|
||||
executeScript("appendNextMessage('" + text + "')");
|
||||
}
|
||||
catch (BadLocationException ex) {
|
||||
Log.error("Error message.", ex);
|
||||
}
|
||||
else {
|
||||
if (outgoingMessage) {
|
||||
String text = themeManager.getOutgoingHistoryMessage(userid, time, message, vcardManager.getAvatar(jid));
|
||||
executeScript("appendMessage('" + text + "')");
|
||||
}
|
||||
else {
|
||||
String text = null;
|
||||
try {
|
||||
text = themeManager.getIncomingHistoryMessage(userid, time, message, vcardManager.getAvatar(jid));
|
||||
executeScript("appendMessage('" + text + "')");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
activeHistoryUser = userid;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -428,7 +544,13 @@ public class TranscriptWindow extends JPanel {
|
||||
* it as disabled.
|
||||
*/
|
||||
public void showDisabledWindowUI() {
|
||||
//TODO: Update disabled code.
|
||||
final Document document = getDocument();
|
||||
final SimpleAttributeSet attrs = new SimpleAttributeSet();
|
||||
StyleConstants.setForeground(attrs, Color.LIGHT_GRAY);
|
||||
|
||||
final int length = document.getLength();
|
||||
StyledDocument styledDocument = getStyledDocument();
|
||||
styledDocument.setCharacterAttributes(0, length, attrs, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -491,19 +613,23 @@ public class TranscriptWindow extends JPanel {
|
||||
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) {
|
||||
Log.error("Unable to save chat transcript.", ex);
|
||||
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), "Could not save transcript.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void scrollToBottom() {
|
||||
executeScript("scrollToBottom();");
|
||||
public void setFont(Font font) {
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
public Font getFont() {
|
||||
return font;
|
||||
}
|
||||
|
||||
public void addTranscriptWindowInterceptor(TranscriptWindowInterceptor interceptor) {
|
||||
interceptors.add(interceptor);
|
||||
@ -513,95 +639,8 @@ public class TranscriptWindow extends JPanel {
|
||||
interceptors.remove(interceptor);
|
||||
}
|
||||
|
||||
public boolean isDocumentLoaded() {
|
||||
return documentLoaded;
|
||||
public void setCustomBackgroundImage(Image customBackgroundImage) {
|
||||
this.customBackgroundImage = customBackgroundImage;
|
||||
}
|
||||
|
||||
public void setInnerHTML(String elementID, String value) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("var myVar = document.getElementById(\"").append(elementID).append("\");");
|
||||
builder.append("if(myVar){ myVar.innerHTML = '").append(value).append("';}");
|
||||
executeScript(builder.toString());
|
||||
}
|
||||
|
||||
public void executeScript(final String script) {
|
||||
scriptBuilder.append(script);
|
||||
if (!script.endsWith(";")) {
|
||||
scriptBuilder.append(";");
|
||||
}
|
||||
|
||||
scriptBuilder.append(" ");
|
||||
timer.restart();
|
||||
}
|
||||
|
||||
public void setURL(URL url) {
|
||||
documentLoaded = false;
|
||||
|
||||
browser.loadURL(url);
|
||||
}
|
||||
|
||||
public void addComponent(JComponent component) {
|
||||
extraPanel.add(component);
|
||||
extraPanel.setVisible(true);
|
||||
invalidate();
|
||||
validate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void removeComponent(JComponent component) {
|
||||
if (extraPanel.getComponentCount() == 0) {
|
||||
extraPanel.setVisible(false);
|
||||
}
|
||||
|
||||
extraPanel.remove(component);
|
||||
invalidate();
|
||||
validate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
final Dimension size = super.getPreferredSize();
|
||||
size.width = 0;
|
||||
return size;
|
||||
}
|
||||
|
||||
private String filterBody(String text) {
|
||||
EmoticonManager emoticonManager = EmoticonManager.getInstance();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
|
||||
final StringTokenizer tokenizer = new StringTokenizer(text, " \n \t", true);
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String textFound = tokenizer.nextToken();
|
||||
if (textFound.startsWith("http://") || textFound.startsWith("ftp://")
|
||||
|| textFound.startsWith("https://") || textFound.startsWith("www.") || textFound.startsWith("\\") || textFound.indexOf("://") != -1) {
|
||||
builder.append("<a href=\"").append(textFound).append("\" target=_blank>").append(textFound).append("</a>");
|
||||
}
|
||||
else if (emoticonManager.getEmoticon(textFound) != null) {
|
||||
Emoticon emot = emoticonManager.getEmoticon(textFound);
|
||||
URL url = emoticonManager.getEmoticonURL(emot);
|
||||
builder.append("<img src=\"").append(url.toExternalForm()).append("\" />");
|
||||
}
|
||||
else {
|
||||
builder.append(textFound);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current active user.
|
||||
*
|
||||
* @param user the active user.
|
||||
*/
|
||||
private void setActiveUser(String user) {
|
||||
activeUser = user;
|
||||
activeTimer.stop();
|
||||
activeTimer.start();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@ import org.jivesoftware.spark.ui.ContactItem;
|
||||
import org.jivesoftware.spark.ui.ContactList;
|
||||
import org.jivesoftware.spark.ui.MessageEventListener;
|
||||
import org.jivesoftware.spark.ui.RosterDialog;
|
||||
import org.jivesoftware.spark.ui.VCardPanel;
|
||||
import org.jivesoftware.spark.util.ModelUtil;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
import org.jivesoftware.sparkimpl.plugin.transcripts.ChatTranscript;
|
||||
@ -46,6 +47,8 @@ import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
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;
|
||||
@ -189,6 +192,10 @@ public class ChatRoomImpl extends ChatRoom {
|
||||
|
||||
typingTimer.start();
|
||||
lastActivity = System.currentTimeMillis();
|
||||
|
||||
// Add VCard Panel
|
||||
final VCardPanel vcardPanel = new VCardPanel(participantJID);
|
||||
getToolBar().add(vcardPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
|
||||
}
|
||||
|
||||
|
||||
@ -531,7 +538,16 @@ public class ChatRoomImpl extends ChatRoom {
|
||||
* @param typing true if the typing notification should show, otherwise hide it.
|
||||
*/
|
||||
public void showTyping(boolean typing) {
|
||||
|
||||
if (typing) {
|
||||
String isTypingText = Res.getString("message.is.typing.a.message", participantNickname);
|
||||
getNotificationLabel().setText(isTypingText);
|
||||
getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE));
|
||||
}
|
||||
else {
|
||||
// Remove is typing text.
|
||||
getNotificationLabel().setText("");
|
||||
getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.BLANK_IMAGE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -628,6 +644,7 @@ public class ChatRoomImpl extends ChatRoom {
|
||||
return alternativeIcon;
|
||||
}
|
||||
|
||||
|
||||
private void loadHistory() {
|
||||
final LocalPreferences pref = SettingsManager.getLocalPreferences();
|
||||
if (!pref.isChatHistoryEnabled()) {
|
||||
@ -641,9 +658,8 @@ public class ChatRoomImpl extends ChatRoom {
|
||||
String from = message.getFrom();
|
||||
String nickname = StringUtils.parseName(from);
|
||||
Date date = message.getDate();
|
||||
getTranscriptWindow().insertHistoryMessage(getParticipantJID(), nickname, message.getBody(), date);
|
||||
getTranscriptWindow().insertHistoryMessage(nickname, message.getBody(), date);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.packet.StreamError;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.Form;
|
||||
import org.jivesoftware.smackx.MessageEventManager;
|
||||
import org.jivesoftware.smackx.MessageEventNotificationListener;
|
||||
import org.jivesoftware.smackx.muc.DefaultParticipantStatusListener;
|
||||
@ -32,29 +33,40 @@ import org.jivesoftware.smackx.packet.DelayInformation;
|
||||
import org.jivesoftware.smackx.packet.MUCUser;
|
||||
import org.jivesoftware.smackx.packet.MUCUser.Destroy;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.plugin.ContextMenuListener;
|
||||
import org.jivesoftware.spark.ui.ChatContainer;
|
||||
import org.jivesoftware.spark.ui.ChatFrame;
|
||||
import org.jivesoftware.spark.ui.ChatRoom;
|
||||
import org.jivesoftware.spark.ui.ChatRoomNotFoundException;
|
||||
import org.jivesoftware.spark.ui.conferences.GroupChatParticipantList;
|
||||
import org.jivesoftware.spark.ui.conferences.ConferenceUtils;
|
||||
import org.jivesoftware.spark.ui.conferences.DataFormDialog;
|
||||
import org.jivesoftware.spark.util.ModelUtil;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
|
||||
/**
|
||||
* GroupChatRoom is the conference chat room UI used to have Multi-User Chats.
|
||||
*/
|
||||
@ -72,6 +84,7 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
private final String roomTitle;
|
||||
private boolean isActive = true;
|
||||
private boolean showPresenceMessages = true;
|
||||
private SubjectPanel subjectPanel;
|
||||
|
||||
private List currentUserList = new ArrayList();
|
||||
|
||||
@ -79,16 +92,13 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
private List blockedUsers = new ArrayList();
|
||||
|
||||
private ChatRoomMessageManager messageManager;
|
||||
private Timer typingTimer;
|
||||
private int typedChars;
|
||||
|
||||
private GroupChatParticipantList roomInfo;
|
||||
|
||||
private long lastActivity;
|
||||
|
||||
private boolean sendNotifications = false;
|
||||
|
||||
private SubjectPanel subjectPanel;
|
||||
|
||||
/**
|
||||
* Creates a GroupChatRoom from a <code>MultiUserChat</code>.
|
||||
*
|
||||
@ -118,7 +128,7 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
getSplitPane().setRightComponent(roomInfo.getGUI());
|
||||
|
||||
roomInfo.setChatRoom(this);
|
||||
getSplitPane().setResizeWeight(.75);
|
||||
getSplitPane().setResizeWeight(.60);
|
||||
|
||||
setupListeners();
|
||||
|
||||
@ -128,10 +138,9 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
subjectPanel = new SubjectPanel();
|
||||
|
||||
// Do not show top toolbar
|
||||
getToolBar().add(subjectPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
|
||||
getToolBar().add(subjectPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 2, 0, 2), 0, 0));
|
||||
|
||||
// Add ContextMenuListener
|
||||
/*
|
||||
getTranscriptWindow().addContextMenuListener(new ContextMenuListener() {
|
||||
public void poppingUp(Object component, JPopupMenu popup) {
|
||||
popup.addSeparator();
|
||||
@ -222,7 +231,7 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
messageManager = new ChatRoomMessageManager();
|
||||
|
||||
@ -453,7 +462,9 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
getTranscriptWindow().showDisabledWindowUI();
|
||||
|
||||
// Update Notification Label
|
||||
getTranscriptWindow().insertNotificationMessage(Res.getString("message.chat.session.ended", SparkManager.DATE_SECOND_FORMATTER.format(new java.util.Date())));
|
||||
getNotificationLabel().setText(Res.getString("message.chat.session.ended", SparkManager.DATE_SECOND_FORMATTER.format(new java.util.Date())));
|
||||
getNotificationLabel().setIcon(null);
|
||||
getNotificationLabel().setEnabled(false);
|
||||
|
||||
getSplitPane().setRightComponent(null);
|
||||
getSplitPane().setDividerSize(0);
|
||||
@ -561,7 +572,7 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
String from = StringUtils.parseResource(message.getFrom());
|
||||
|
||||
if (inf != null) {
|
||||
getTranscriptWindow().insertHistoryMessage(message.getFrom(), from, message.getBody(), sentDate);
|
||||
getTranscriptWindow().insertHistoryMessage(from, message.getBody(), sentDate);
|
||||
}
|
||||
else {
|
||||
if (isBlocked(message.getFrom())) {
|
||||
@ -577,7 +588,10 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
getTranscriptWindow().insertOthersMessage(from, message);
|
||||
}
|
||||
|
||||
|
||||
if (typingTimer != null) {
|
||||
getNotificationLabel().setText("");
|
||||
getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.BLANK_IMAGE));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (message.getType() == Message.Type.chat) {
|
||||
@ -658,16 +672,6 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
}
|
||||
}
|
||||
|
||||
public void inviteUser(String jid, String message) {
|
||||
message = message != null ? message : Res.getString("message.please.join.in.conference");
|
||||
|
||||
// Invite User
|
||||
getMultiUserChat().invite(jid, message);
|
||||
|
||||
// Add Invite
|
||||
roomInfo.addInvitee(jid, message);
|
||||
}
|
||||
|
||||
private void setupListeners() {
|
||||
chat.addParticipantStatusListener(new DefaultParticipantStatusListener() {
|
||||
public void kicked(String participant) {
|
||||
@ -900,17 +904,33 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
* true to use typing notifications.
|
||||
*/
|
||||
public void setSendAndReceiveTypingNotifications(boolean sendAndReceiveTypingNotifications) {
|
||||
sendNotifications = sendAndReceiveTypingNotifications;
|
||||
|
||||
if (sendAndReceiveTypingNotifications) {
|
||||
typingTimer = new Timer(10000, new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
getNotificationLabel().setText("");
|
||||
getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.BLANK_IMAGE));
|
||||
}
|
||||
});
|
||||
SparkManager.getMessageEventManager().addMessageEventNotificationListener(messageManager);
|
||||
}
|
||||
else {
|
||||
|
||||
if (typingTimer != null) {
|
||||
typingTimer.stop();
|
||||
}
|
||||
SparkManager.getMessageEventManager().removeMessageEventNotificationListener(messageManager);
|
||||
}
|
||||
}
|
||||
|
||||
public void inviteUser(String jid, String message) {
|
||||
message = message != null ? message : Res.getString("message.please.join.in.conference");
|
||||
|
||||
// Invite User
|
||||
getMultiUserChat().invite(jid, message);
|
||||
|
||||
// Add Invite
|
||||
roomInfo.addInvitee(jid, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private implementation of the MessageEventNotificationListener.
|
||||
*/
|
||||
@ -936,7 +956,9 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
if (bareAddress.equals(getRoomname())) {
|
||||
String nickname = StringUtils.parseResource(from);
|
||||
String isTypingText = Res.getString("message.is.typing.a.message", nickname);
|
||||
|
||||
getNotificationLabel().setText(isTypingText);
|
||||
getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE));
|
||||
typingTimer.restart();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -962,7 +984,7 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
// If the user pauses for more than two seconds, send out a new notice.
|
||||
if (typedChars >= 10) {
|
||||
try {
|
||||
if (sendNotifications) {
|
||||
if (typingTimer != null) {
|
||||
final Iterator iter = chat.getOccupants();
|
||||
while (iter.hasNext()) {
|
||||
String from = (String)iter.next();
|
||||
@ -989,6 +1011,7 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
return lastActivity;
|
||||
}
|
||||
|
||||
|
||||
public void connectionClosed() {
|
||||
handleDisconnect();
|
||||
}
|
||||
@ -1017,6 +1040,7 @@ public final class GroupChatRoom extends ChatRoom {
|
||||
SparkManager.getChatManager().getChatContainer().useTabDefault(this);
|
||||
}
|
||||
|
||||
|
||||
private class SubjectPanel extends JPanel {
|
||||
|
||||
private JLabel iconLabel;
|
||||
|
||||
@ -24,8 +24,23 @@ import org.jivesoftware.spark.util.SwingWorker;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
import org.jivesoftware.sparkimpl.profile.VCardManager;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
@ -43,19 +58,6 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
public class StatusBar extends JPanel {
|
||||
private List<StatusItem> statusList = new ArrayList<StatusItem>();
|
||||
|
||||
@ -76,13 +78,28 @@ public class StatusBar extends JPanel {
|
||||
backgroundImage = Default.getImageIcon(Default.TOP_BOTTOM_BACKGROUND_IMAGE).getImage();
|
||||
|
||||
// Initialze command panel
|
||||
commandPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
commandPanel = new JPanel() {
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension dim = super.getPreferredSize();
|
||||
Component[] comps = getComponents();
|
||||
for (int i = 0; i < comps.length; i++) {
|
||||
if (comps[i].isVisible()) {
|
||||
|
||||
}
|
||||
else {
|
||||
System.out.println("Nope");
|
||||
}
|
||||
}
|
||||
return dim;
|
||||
}
|
||||
};
|
||||
commandPanel.setLayout(new BoxLayout(commandPanel, BoxLayout.X_AXIS));
|
||||
commandPanel.setOpaque(false);
|
||||
|
||||
ImageIcon brandedImage = Default.getImageIcon(Default.BRANDED_IMAGE);
|
||||
if (brandedImage != null && brandedImage.getIconWidth() > 1) {
|
||||
final JLabel brandedLabel = new JLabel(brandedImage);
|
||||
// brandedLabel.setBorder(new PartialLineBorder(Color.LIGHT_GRAY, 1));
|
||||
add(brandedLabel, new GridBagConstraints(3, 0, 1, 3, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
|
||||
}
|
||||
|
||||
@ -356,7 +373,7 @@ public class StatusBar extends JPanel {
|
||||
|
||||
if (presence.getStatus() != null && item.getPresence().getStatus() != null) {
|
||||
if ((presence.getMode() == item.getPresence().getMode()) && (presence.getType() == item.getPresence().getType()) &&
|
||||
(presence.getStatus().equals(item.getPresence().getStatus()))) {
|
||||
(presence.getStatus().equals(item.getPresence().getStatus()))) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@ -554,4 +571,10 @@ public class StatusBar extends JPanel {
|
||||
return commandPanel;
|
||||
}
|
||||
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension dim = super.getPreferredSize();
|
||||
dim.width = 0;
|
||||
return dim;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,549 +0,0 @@
|
||||
/**
|
||||
* $Revision: $
|
||||
* $Date: $
|
||||
*
|
||||
* Copyright (C) 2006 Jive Software. All rights reserved.
|
||||
*
|
||||
* This software is published under the terms of the GNU Lesser Public License (LGPL),
|
||||
* a copy of which is included in this distribution.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.spark.ui.themes;
|
||||
|
||||
import com.webrenderer.BrowserFactory;
|
||||
import org.jdesktop.jdic.browser.BrowserEngineManager;
|
||||
import org.jdesktop.jdic.browser.IBrowserEngine;
|
||||
import org.jivesoftware.Spark;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.util.StringUtils;
|
||||
import org.jivesoftware.spark.util.SwingWorker;
|
||||
import org.jivesoftware.spark.util.URLFileSystem;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
import org.jivesoftware.sparkimpl.plugin.emoticons.EmoticonManager;
|
||||
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
|
||||
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* Manages Themes.
|
||||
*
|
||||
* @author Derek DeMoro
|
||||
* @todo FINISH :)
|
||||
*/
|
||||
public class ThemeManager {
|
||||
|
||||
private static ThemeManager singleton;
|
||||
private static final Object LOCK = new Object();
|
||||
|
||||
private StringBuilder builder = new StringBuilder();
|
||||
|
||||
private String templateText;
|
||||
private String incomingText;
|
||||
private String outgoingText;
|
||||
private String statusText;
|
||||
private String nextIncomingText;
|
||||
private String nextOutgoingText;
|
||||
private String outgoingTransferText;
|
||||
private String incomingTransferText;
|
||||
|
||||
private String incomingHistoryText;
|
||||
private String outgoingHistoryText;
|
||||
private String nextIncomingHistoryText;
|
||||
private String nextOutgoingHistoryText;
|
||||
|
||||
private File tempFile;
|
||||
private String chatName;
|
||||
|
||||
private EmoticonManager emoticonManager;
|
||||
|
||||
/**
|
||||
* The root themes directory.
|
||||
*/
|
||||
public static File THEMES_DIRECTORY;
|
||||
|
||||
/**
|
||||
* Returns the singleton instance of <CODE>ThemeManager</CODE>,
|
||||
* creating it if necessary.
|
||||
* <p/>
|
||||
*
|
||||
* @return the singleton instance of <Code>ThemeManager</CODE>
|
||||
*/
|
||||
public static ThemeManager getInstance() {
|
||||
// Synchronize on LOCK to ensure that we don't end up creating
|
||||
// two singletons.
|
||||
synchronized (LOCK) {
|
||||
if (null == singleton) {
|
||||
ThemeManager controller = new ThemeManager();
|
||||
singleton = controller;
|
||||
return controller;
|
||||
}
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
|
||||
private ThemeManager() {
|
||||
BrowserFactory.setLicenseData("30dtrial", "VO3I81PG53P21111DROMSQJ0");
|
||||
|
||||
emoticonManager = EmoticonManager.getInstance();
|
||||
|
||||
BrowserEngineManager bem = BrowserEngineManager.instance();
|
||||
//specific engine if you want and the engine you specified will return
|
||||
bem.setActiveEngine(BrowserEngineManager.IE);
|
||||
|
||||
//IBrowserEngine be = bem.setActiveEngine(...);
|
||||
IBrowserEngine be = bem.getActiveEngine();//default or specified engine is returned
|
||||
|
||||
// Note that the install directory is my name for temporary files and
|
||||
// not about mozilla. Me love Mozilla.
|
||||
//be.setEnginePath("C:\\mozilla\\mozilla.exe");
|
||||
|
||||
// File mozilla = new File(Spark.getBinDirectory(), "mozilla");
|
||||
// be.setEnginePath(mozilla.getAbsolutePath());
|
||||
try {
|
||||
THEMES_DIRECTORY = new File(Spark.getBinDirectory().getParent(), "xtra/themes").getCanonicalFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
// For Testing
|
||||
//THEMES_DIRECTORY = new File("c:\\xtra\\themes");
|
||||
|
||||
expandNewThemes();
|
||||
|
||||
final LocalPreferences pref = SettingsManager.getLocalPreferences();
|
||||
|
||||
String themeName = pref.getTheme();
|
||||
|
||||
File theme = new File(THEMES_DIRECTORY, themeName);
|
||||
if (!theme.exists()) {
|
||||
File themeDir = ThemeManager.THEMES_DIRECTORY;
|
||||
File[] dirs = themeDir.listFiles();
|
||||
for (int i = 0; i < dirs.length; i++) {
|
||||
File file = dirs[i];
|
||||
if (file.isDirectory()) {
|
||||
themeName = file.getName();
|
||||
pref.setTheme(themeName);
|
||||
theme = new File(THEMES_DIRECTORY, themeName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
setTheme(theme);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println("Could not locate " + theme);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Add Preference
|
||||
SparkManager.getPreferenceManager().addPreference(new ThemePreference());
|
||||
|
||||
|
||||
SwingWorker worker = new SwingWorker() {
|
||||
public Object construct() {
|
||||
return BrowserFactory.spawnMozilla();
|
||||
}
|
||||
};
|
||||
|
||||
worker.start();
|
||||
}
|
||||
|
||||
private void expandNewThemes() {
|
||||
File[] jars = THEMES_DIRECTORY.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
boolean accept = false;
|
||||
String smallName = name.toLowerCase();
|
||||
if (smallName.endsWith(".zip")) {
|
||||
accept = true;
|
||||
}
|
||||
return accept;
|
||||
}
|
||||
});
|
||||
|
||||
// Do nothing if no jar or zip files were found
|
||||
if (jars == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < jars.length; i++) {
|
||||
if (jars[i].isFile()) {
|
||||
File file = jars[i];
|
||||
|
||||
URL url = null;
|
||||
try {
|
||||
url = file.toURL();
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
String name = URLFileSystem.getName(url);
|
||||
File directory = new File(THEMES_DIRECTORY, name);
|
||||
if (directory.exists() && directory.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// Unzip contents into directory
|
||||
unzipTheme(file, directory.getParentFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void installTheme(File theme) {
|
||||
// Copy the file to the themes directory
|
||||
unzipTheme(theme, THEMES_DIRECTORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unzips a theme from a ZIP file into a directory.
|
||||
*
|
||||
* @param zip the ZIP file
|
||||
* @param dir the directory to extract the plugin to.
|
||||
*/
|
||||
private void unzipTheme(File zip, File dir) {
|
||||
try {
|
||||
ZipFile zipFile = new JarFile(zip);
|
||||
|
||||
dir.mkdir();
|
||||
for (Enumeration e = zipFile.entries(); e.hasMoreElements();) {
|
||||
JarEntry entry = (JarEntry)e.nextElement();
|
||||
File entryFile = new File(dir, entry.getName());
|
||||
// Ignore any manifest.mf entries.
|
||||
if (entry.getName().toLowerCase().endsWith("manifest.mf")) {
|
||||
continue;
|
||||
}
|
||||
if (!entry.isDirectory()) {
|
||||
entryFile.getParentFile().mkdirs();
|
||||
FileOutputStream out = new FileOutputStream(entryFile);
|
||||
InputStream zin = zipFile.getInputStream(entry);
|
||||
byte[] b = new byte[512];
|
||||
int len = 0;
|
||||
while ((len = zin.read(b)) != -1) {
|
||||
out.write(b, 0, len);
|
||||
}
|
||||
out.flush();
|
||||
out.close();
|
||||
zin.close();
|
||||
}
|
||||
}
|
||||
zipFile.close();
|
||||
zipFile = null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.error("Error unzipping Theme", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setTheme(File theme) throws Exception {
|
||||
theme = new File(theme, "/Contents/Resources");
|
||||
|
||||
File template = new File(theme, "template.html");
|
||||
templateText = URLFileSystem.getContents(template);
|
||||
|
||||
// Load header
|
||||
File header = new File(theme, "Header.html");
|
||||
if (header.exists()) {
|
||||
String headerText = URLFileSystem.getContents(header);
|
||||
headerText = filter(headerText);
|
||||
templateText = templateText.replaceAll("%header%", headerText);
|
||||
}
|
||||
else {
|
||||
templateText = templateText.replaceAll("%header%", "");
|
||||
}
|
||||
|
||||
// Load Footer
|
||||
File footer = new File(theme, "Footer.html");
|
||||
if (footer.exists()) {
|
||||
String footerText = URLFileSystem.getContents(footer);
|
||||
templateText = templateText.replaceAll("%footer%", footerText);
|
||||
}
|
||||
else {
|
||||
templateText = templateText.replaceAll("%footer%", "");
|
||||
}
|
||||
|
||||
// Load Outgoing
|
||||
File outgoingMessage = new File(theme, "/Outgoing/Content.html");
|
||||
outgoingText = URLFileSystem.getContents(outgoingMessage);
|
||||
|
||||
// Load Incoming
|
||||
File incomingMessage = new File(theme, "/Incoming/Content.html");
|
||||
incomingText = URLFileSystem.getContents(incomingMessage);
|
||||
|
||||
// Load status
|
||||
File statusFile = new File(theme, "Status.html");
|
||||
statusText = URLFileSystem.getContents(statusFile);
|
||||
|
||||
// Load Next Incoming Text
|
||||
File nextIncomingTextFile = new File(theme, "/Incoming/NextContent.html");
|
||||
nextIncomingText = URLFileSystem.getContents(nextIncomingTextFile);
|
||||
|
||||
// Load Next Outgoing Text
|
||||
File nextOutgoingTextFile = new File(theme, "/Outgoing/NextContent.html");
|
||||
nextOutgoingText = URLFileSystem.getContents(nextOutgoingTextFile);
|
||||
|
||||
// Set Base Href
|
||||
String baseHref = null;
|
||||
try {
|
||||
baseHref = theme.toURL().toExternalForm();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
baseHref = StringUtils.replace(baseHref, "\\", "\\\\");
|
||||
templateText = templateText.replaceAll("%base_href%", baseHref);
|
||||
|
||||
tempFile = new File(theme, "temp.html");
|
||||
try {
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
|
||||
out.write(templateText);
|
||||
out.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
|
||||
// Load outgoing transfer text
|
||||
File outgoingTransferFile = new File(theme, "/Outgoing/filetransfer.html");
|
||||
outgoingTransferText = URLFileSystem.getContents(outgoingTransferFile);
|
||||
|
||||
// Load incoming transfer text
|
||||
File incomingTransferFile = new File(theme, "/Incoming/filetransfer.html");
|
||||
incomingTransferText = URLFileSystem.getContents(incomingTransferFile);
|
||||
|
||||
// Load incoming history text
|
||||
incomingHistoryText = URLFileSystem.getContents(new File(theme, "/Incoming/Context.html"));
|
||||
|
||||
// Load outgoing history text
|
||||
outgoingHistoryText = URLFileSystem.getContents(new File(theme, "/Outgoing/Context.html"));
|
||||
|
||||
// Load next incoming history text
|
||||
nextIncomingHistoryText = URLFileSystem.getContents(new File(theme, "/Incoming/NextContext.html"));
|
||||
|
||||
// Load next outgoing history text
|
||||
nextOutgoingHistoryText = URLFileSystem.getContents(new File(theme, "/Outgoing/NextContext.html"));
|
||||
}
|
||||
|
||||
public String getTemplate() {
|
||||
return templateText;
|
||||
}
|
||||
|
||||
public URL getTemplateURL() {
|
||||
try {
|
||||
return tempFile.toURL();
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String getIncomingMessage(String sender, String time, String message, URL iconPath) {
|
||||
String incoming = incomingText;
|
||||
if (sender == null) {
|
||||
sender = "";
|
||||
}
|
||||
incoming = incoming.replaceAll("%sender%", sender);
|
||||
incoming = incoming.replaceAll("%time%", time);
|
||||
incoming = incoming.replaceAll("%message%", message);
|
||||
incoming = incoming.replaceAll("%service%", " ");
|
||||
|
||||
incoming = filter(incoming);
|
||||
if (iconPath != null) {
|
||||
incoming = incoming.replaceAll("%userIconPath%", iconPath.toExternalForm());
|
||||
}
|
||||
return incoming;
|
||||
}
|
||||
|
||||
public String getIncomingHistoryMessage(String sender, String time, String message, URL iconPath) throws Exception {
|
||||
String incoming = incomingHistoryText;
|
||||
if (incoming == null) {
|
||||
incoming = incomingText;
|
||||
}
|
||||
if (sender == null) {
|
||||
sender = "";
|
||||
}
|
||||
incoming = incoming.replaceAll("%sender%", sender);
|
||||
incoming = incoming.replaceAll("%time%", time);
|
||||
incoming = StringUtils.replace(incoming, "%message%", message);
|
||||
incoming = incoming.replaceAll("%service%", " ");
|
||||
incoming = filter(incoming);
|
||||
if (iconPath != null) {
|
||||
incoming = incoming.replaceAll("%userIconPath%", iconPath.toExternalForm());
|
||||
}
|
||||
return incoming;
|
||||
}
|
||||
|
||||
|
||||
public String getOutgoingMessage(String sender, String time, String message, URL iconPath) {
|
||||
String outgoing = outgoingText;
|
||||
if (sender == null) {
|
||||
sender = "";
|
||||
}
|
||||
outgoing = outgoing.replaceAll("%sender%", sender);
|
||||
outgoing = outgoing.replaceAll("%time%", time);
|
||||
outgoing = outgoing.replaceAll("%message%", message);
|
||||
outgoing = outgoing.replaceAll("%service%", " ");
|
||||
outgoing = filter(outgoing);
|
||||
if (iconPath != null) {
|
||||
outgoing = outgoing.replaceAll("%userIconPath%", iconPath.toExternalForm());
|
||||
}
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
public String getOutgoingHistoryMessage(String sender, String time, String message, URL iconPath) {
|
||||
String outgoing = outgoingHistoryText;
|
||||
if (outgoing == null) {
|
||||
outgoing = outgoingText;
|
||||
}
|
||||
if (sender == null) {
|
||||
sender = "";
|
||||
}
|
||||
outgoing = outgoing.replaceAll("%sender%", sender);
|
||||
outgoing = outgoing.replaceAll("%time%", time);
|
||||
outgoing = outgoing.replaceAll("%message%", message);
|
||||
outgoing = outgoing.replaceAll("%service%", " ");
|
||||
outgoing = filter(outgoing);
|
||||
if (iconPath != null) {
|
||||
outgoing = outgoing.replaceAll("%userIconPath%", iconPath.toExternalForm());
|
||||
}
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
public String getStatusMessage(String message, String time) {
|
||||
String status = statusText;
|
||||
status = status.replaceAll("%time%", time);
|
||||
status = status.replaceAll("%message%", message);
|
||||
status = filter(status);
|
||||
return status;
|
||||
}
|
||||
|
||||
public String getNotificationMessage(String message, boolean allowQuotes) {
|
||||
String status = statusText;
|
||||
status = StringUtils.replace(status, "%time%", "");
|
||||
status = StringUtils.replace(status, "%message%", message);
|
||||
if (!allowQuotes) {
|
||||
status = filter(status);
|
||||
}
|
||||
else {
|
||||
status = status.replaceAll("\"", "\\\"");
|
||||
status = status.replaceAll("\n", "");
|
||||
status = status.replaceAll("\t", "");
|
||||
status = status.replaceAll("\r", "");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
public String getNextIncomingMessage(String message, String time) {
|
||||
String incoming = nextIncomingText;
|
||||
incoming = incoming.replaceAll("%time%", time);
|
||||
incoming = incoming.replaceAll("%message%", message);
|
||||
incoming = filter(incoming);
|
||||
return incoming;
|
||||
}
|
||||
|
||||
public String getNextIncomingHistoryMessage(String message, String time) {
|
||||
String incoming = nextIncomingHistoryText;
|
||||
if (incoming == null) {
|
||||
incoming = nextIncomingText;
|
||||
}
|
||||
incoming = incoming.replaceAll("%time%", time);
|
||||
incoming = incoming.replaceAll("%message%", message);
|
||||
incoming = filter(incoming);
|
||||
return incoming;
|
||||
}
|
||||
|
||||
public String getNextOutgoingMessage(String message, String time) {
|
||||
String out = nextOutgoingText;
|
||||
out = out.replaceAll("%time%", time);
|
||||
out = out.replaceAll("%message%", message);
|
||||
out = filter(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
public String getNextOutgoingHistoryString(String message, String time) {
|
||||
String out = nextOutgoingHistoryText;
|
||||
if (out == null) {
|
||||
out = nextOutgoingText;
|
||||
}
|
||||
out = out.replaceAll("%time%", time);
|
||||
out = out.replaceAll("%message%", message);
|
||||
out = filter(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
public String getIncomingTransferUI(String title, String filename, String size, String requestID) {
|
||||
String text = incomingTransferText;
|
||||
text = text.replaceAll("%title%", title);
|
||||
text = text.replaceAll("%filename%", filename);
|
||||
text = text.replaceAll("%filesize%", size);
|
||||
text = text.replaceAll("%requestID%", requestID);
|
||||
text = htmlKeepQuotes(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
public String htmlKeepQuotes(String text) {
|
||||
text = text.replaceAll("\n", "");
|
||||
text = text.replaceAll("\"", "\\\"");
|
||||
text = text.replaceAll("\t", "");
|
||||
text = text.replaceAll("\r", "");
|
||||
text = text.replaceAll("%userIconPath%", "file:///c:/zapwire_desktop.png");
|
||||
|
||||
if (getChatName() != null) {
|
||||
text = text.replaceAll("%chatName%", getChatName());
|
||||
}
|
||||
|
||||
final SimpleDateFormat formatter = new SimpleDateFormat("h:mm");
|
||||
String time = formatter.format(new Date());
|
||||
|
||||
text = text.replaceAll("%timeOpened", time);
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
private String filter(String text) {
|
||||
text = text.replaceAll("\n", "");
|
||||
text = text.replaceAll("\'", "´");
|
||||
text = text.replaceAll("\t", "");
|
||||
text = text.replaceAll("\r", "");
|
||||
|
||||
final SimpleDateFormat formatter = new SimpleDateFormat("h:mm");
|
||||
String time = formatter.format(new Date());
|
||||
|
||||
text = text.replaceAll("%timeOpened", time);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
public void setChatName(String chatName) {
|
||||
this.chatName = chatName;
|
||||
}
|
||||
|
||||
public String getChatName() {
|
||||
return chatName;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -11,10 +11,8 @@
|
||||
package org.jivesoftware.spark.ui.themes;
|
||||
|
||||
import org.jivesoftware.Spark;
|
||||
import org.jivesoftware.resource.SparkRes;
|
||||
import org.jivesoftware.spark.ui.TranscriptWindow;
|
||||
import org.jivesoftware.spark.util.ResourceUtils;
|
||||
import org.jivesoftware.spark.util.URLFileSystem;
|
||||
import org.jivesoftware.spark.util.WindowsFileSystemView;
|
||||
import org.jivesoftware.sparkimpl.plugin.emoticons.Emoticon;
|
||||
import org.jivesoftware.sparkimpl.plugin.emoticons.EmoticonManager;
|
||||
@ -27,7 +25,6 @@ import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
@ -35,6 +32,7 @@ import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -52,13 +50,10 @@ public class ThemePanel extends JPanel {
|
||||
private JButton addEmoticonButton;
|
||||
|
||||
private JFileChooser fc;
|
||||
private ThemeManager themeManager;
|
||||
|
||||
public ThemePanel() {
|
||||
setLayout(new GridBagLayout());
|
||||
|
||||
themeManager = ThemeManager.getInstance();
|
||||
|
||||
messageStyleLabel = new JLabel();
|
||||
messageStyleBox = new JComboBox();
|
||||
|
||||
@ -85,43 +80,20 @@ public class ThemePanel extends JPanel {
|
||||
// Add Viewer
|
||||
add(new JScrollPane(transcript), new GridBagConstraints(0, 0, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
|
||||
|
||||
/*
|
||||
add(messageStyleLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
add(messageStyleBox, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
|
||||
add(addThemeButton, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
*/
|
||||
|
||||
add(emoticonsLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
add(emoticonBox, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
|
||||
add(addEmoticonButton, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
|
||||
|
||||
File themeDir = ThemeManager.THEMES_DIRECTORY;
|
||||
File[] dirs = themeDir.listFiles();
|
||||
for (int i = 0; i < dirs.length; i++) {
|
||||
File file = dirs[i];
|
||||
if (file.isDirectory()) {
|
||||
addTheme(file);
|
||||
}
|
||||
}
|
||||
|
||||
messageStyleBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
showSelectedTheme();
|
||||
}
|
||||
});
|
||||
|
||||
// Activate live one.
|
||||
LocalPreferences pref = SettingsManager.getLocalPreferences();
|
||||
String theme = pref.getTheme();
|
||||
|
||||
messageStyleBox.setSelectedItem(theme);
|
||||
|
||||
|
||||
addThemeButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
addTheme();
|
||||
}
|
||||
});
|
||||
|
||||
// messageStyleBox.setSelectedItem(theme);
|
||||
|
||||
final EmoticonManager emoticonManager = EmoticonManager.getInstance();
|
||||
for (String pack : emoticonManager.getEmoticonPacks()) {
|
||||
@ -135,7 +107,7 @@ public class ThemePanel extends JPanel {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
emoticonManager.addEmoticonPack((String)emoticonBox.getSelectedItem());
|
||||
emoticonManager.setActivePack((String)emoticonBox.getSelectedItem());
|
||||
showSelectedTheme();
|
||||
showSelectedEmoticon();
|
||||
}
|
||||
});
|
||||
|
||||
@ -145,6 +117,7 @@ public class ThemePanel extends JPanel {
|
||||
}
|
||||
});
|
||||
|
||||
showSelectedEmoticon();
|
||||
}
|
||||
|
||||
private void addTheme(File dir) {
|
||||
@ -152,44 +125,32 @@ public class ThemePanel extends JPanel {
|
||||
}
|
||||
|
||||
|
||||
protected void showSelectedTheme() {
|
||||
final ThemeManager manager = ThemeManager.getInstance();
|
||||
protected void showSelectedEmoticon() {
|
||||
EmoticonManager emoticonManager = EmoticonManager.getInstance();
|
||||
String activeEmoticonName = emoticonManager.getActiveEmoticonSetName();
|
||||
|
||||
String themeName = (String)messageStyleBox.getSelectedItem();
|
||||
|
||||
File themeDir = new File(ThemeManager.THEMES_DIRECTORY, themeName);
|
||||
transcript.clear();
|
||||
transcript.insertTitle(activeEmoticonName + " Emoticons");
|
||||
try {
|
||||
manager.setTheme(themeDir);
|
||||
transcript.insertText("\n");
|
||||
}
|
||||
catch (Exception e) {
|
||||
transcript.insertCustomMessage("", "Unable to view theme.");
|
||||
catch (BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
transcript.setURL(manager.getTemplateURL());
|
||||
|
||||
String status = manager.getStatusMessage("Welcome to this theme.", "7 a.m.");
|
||||
String message1 = manager.getOutgoingMessage("DrunkMan", "7 a.m.", "Hey, any idea where to drink early in the morning?", SparkRes.getURL(SparkRes.DUMMY_CONTACT_IMAGE));
|
||||
String message2 = manager.getIncomingMessage("Mr. Responsible", "7 a.m.", "I would go ahead and ask one of the Clearspace guys.", SparkRes.getURL(SparkRes.DUMMY_CONTACT_IMAGE));
|
||||
|
||||
transcript.setInnerHTML("chatName", "Template Chat");
|
||||
transcript.setInnerHTML("timeOpened", "Conversation started at 7 on the noise.");
|
||||
transcript.setInnerHTML("incomingIconPath", "<img src=\"" + SparkRes.getURL(SparkRes.DUMMY_CONTACT_IMAGE).toExternalForm() + "\">");
|
||||
|
||||
transcript.insertNotificationMessage("Welcome to this theme.");
|
||||
transcript.executeScript(("appendMessage('" + message1 + "')"));
|
||||
transcript.executeScript("appendMessage('" + message2 + "')");
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
EmoticonManager emoticonManager = EmoticonManager.getInstance();
|
||||
for (Emoticon emoticon : emoticonManager.getActiveEmoticonSet()) {
|
||||
String eq = emoticon.getEquivalants().get(0);
|
||||
builder.append(eq);
|
||||
builder.append(" ");
|
||||
}
|
||||
|
||||
|
||||
transcript.insertCustomMessage("Emoticon Man:", builder.toString());
|
||||
try {
|
||||
transcript.insert(builder.toString());
|
||||
}
|
||||
catch (BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getSelectedTheme() {
|
||||
@ -200,43 +161,6 @@ public class ThemePanel extends JPanel {
|
||||
return (String)emoticonBox.getSelectedItem();
|
||||
}
|
||||
|
||||
private void addTheme() {
|
||||
if (fc == null) {
|
||||
fc = new JFileChooser();
|
||||
if (Spark.isWindows()) {
|
||||
fc.setFileSystemView(new WindowsFileSystemView());
|
||||
}
|
||||
}
|
||||
fc.setDialogTitle("Add Theme");
|
||||
|
||||
fc.addChoosableFileFilter(new ZipFilter());
|
||||
|
||||
int returnVal = fc.showOpenDialog(this);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File theme = fc.getSelectedFile();
|
||||
themeManager.installTheme(theme);
|
||||
try {
|
||||
String name = URLFileSystem.getName(theme.toURL());
|
||||
|
||||
// If the name does not exists, add it to the message box.
|
||||
for (int i = 0; i < messageStyleBox.getItemCount(); i++) {
|
||||
String n = (String)messageStyleBox.getItemAt(i);
|
||||
if (name.equals(n)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
messageStyleBox.addItem(name);
|
||||
|
||||
// Set Selected
|
||||
messageStyleBox.setSelectedItem(name);
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addEmoticon() {
|
||||
if (fc == null) {
|
||||
|
||||
@ -33,7 +33,7 @@ public class ThemePreference implements Preference {
|
||||
|
||||
|
||||
public String getTitle() {
|
||||
return "Appearance";
|
||||
return "Customization";
|
||||
}
|
||||
|
||||
public Icon getIcon() {
|
||||
@ -82,7 +82,6 @@ public class ThemePreference implements Preference {
|
||||
final String theme = panel.getSelectedTheme();
|
||||
final String pack = panel.getSelectedEmoticonPack();
|
||||
LocalPreferences pref = SettingsManager.getLocalPreferences();
|
||||
pref.setTheme(theme);
|
||||
pref.setEmoticonPack(pack);
|
||||
}
|
||||
|
||||
|
||||
@ -39,6 +39,8 @@ import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
/**
|
||||
* Responsible for the handling of all Emoticon packs. Using the EmoticonManager, you can specify
|
||||
* any defined Emoticon Pack, retrieve any emoticon based on its text equivalant, and retrieve its
|
||||
@ -238,6 +240,16 @@ public class EmoticonManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ImageIcon getEmoticonImage(String key){
|
||||
final Emoticon emoticon = getEmoticon(key);
|
||||
if(emoticon != null){
|
||||
URL url = getEmoticonURL(emoticon);
|
||||
return new ImageIcon(url);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<String> getEmoticonPacks() {
|
||||
final List<String> emoticonList = new ArrayList<String>();
|
||||
|
||||
|
||||
@ -16,7 +16,9 @@ import org.jivesoftware.spark.component.RolloverButton;
|
||||
import org.jivesoftware.spark.plugin.Plugin;
|
||||
import org.jivesoftware.spark.ui.ChatInputEditor;
|
||||
import org.jivesoftware.spark.ui.ChatRoom;
|
||||
import org.jivesoftware.spark.ui.ChatRoomClosingListener;
|
||||
import org.jivesoftware.spark.ui.ChatRoomListenerAdapter;
|
||||
import org.jivesoftware.spark.ui.themes.ThemePreference;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
import org.jivesoftware.sparkimpl.plugin.emoticons.EmoticonUI.EmoticonPickListener;
|
||||
|
||||
@ -35,8 +37,6 @@ public class EmoticonPlugin implements Plugin {
|
||||
|
||||
|
||||
public void initialize() {
|
||||
|
||||
|
||||
final ChatManager chatManager = SparkManager.getChatManager();
|
||||
chatManager.addChatRoomListener(new ChatRoomListenerAdapter() {
|
||||
public void chatRoomOpened(final ChatRoom room) {
|
||||
@ -48,10 +48,10 @@ public class EmoticonPlugin implements Plugin {
|
||||
|
||||
// Add Emoticon button
|
||||
ImageIcon icon = new ImageIcon(smileURL);
|
||||
final RolloverButton button = new RolloverButton(icon);
|
||||
room.getEditorBar().add(button);
|
||||
final RolloverButton emoticonPicker = new RolloverButton(icon);
|
||||
room.getEditorBar().add(emoticonPicker);
|
||||
|
||||
button.addMouseListener(new MouseAdapter() {
|
||||
emoticonPicker.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// Show popup
|
||||
final JPopupMenu popup = new JPopupMenu();
|
||||
@ -79,14 +79,20 @@ public class EmoticonPlugin implements Plugin {
|
||||
|
||||
|
||||
popup.add(ui);
|
||||
popup.show(button, e.getX(), e.getY());
|
||||
popup.show(emoticonPicker, e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
|
||||
room.addClosingListener(new ChatRoomClosingListener() {
|
||||
public void closing() {
|
||||
room.getEditorBar().remove(emoticonPicker);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void chatRoomClosed(ChatRoom room) {
|
||||
}
|
||||
});
|
||||
|
||||
// Add Preferences
|
||||
SparkManager.getPreferenceManager().addPreference(new ThemePreference());
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
|
||||
@ -13,20 +13,16 @@ package org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui;
|
||||
import org.jdesktop.jdic.desktop.Desktop;
|
||||
import org.jdesktop.jdic.desktop.DesktopException;
|
||||
import org.jivesoftware.Spark;
|
||||
import org.jivesoftware.resource.Res;
|
||||
import org.jivesoftware.resource.SparkRes;
|
||||
import org.jivesoftware.resource.Res;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.filetransfer.FileTransfer;
|
||||
import org.jivesoftware.smackx.filetransfer.FileTransferRequest;
|
||||
import org.jivesoftware.smackx.filetransfer.IncomingFileTransfer;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.component.RolloverButton;
|
||||
import org.jivesoftware.spark.ui.ChatRoom;
|
||||
import org.jivesoftware.spark.ui.ContactItem;
|
||||
import org.jivesoftware.spark.ui.ContactList;
|
||||
import org.jivesoftware.spark.ui.TranscriptWindow;
|
||||
import org.jivesoftware.spark.ui.themes.ThemeManager;
|
||||
import org.jivesoftware.spark.util.ByteFormat;
|
||||
import org.jivesoftware.spark.util.GraphicUtils;
|
||||
import org.jivesoftware.spark.util.ResourceUtils;
|
||||
@ -35,25 +31,6 @@ import org.jivesoftware.spark.util.URLFileSystem;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
import org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.Downloads;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BorderFactory;
|
||||
@ -67,6 +44,23 @@ import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JProgressBar;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class ReceiveMessage extends JPanel {
|
||||
private JLabel imageLabel = new JLabel();
|
||||
private JLabel titleLabel = new JLabel();
|
||||
@ -78,31 +72,21 @@ public class ReceiveMessage extends JPanel {
|
||||
private IncomingFileTransfer transfer;
|
||||
private TransferButton cancelButton = new TransferButton();
|
||||
|
||||
private ChatRoom chatRoom;
|
||||
|
||||
|
||||
public ReceiveMessage() {
|
||||
setLayout(new GridBagLayout());
|
||||
setOpaque(false);
|
||||
setBackground(new Color(250, 249, 242));
|
||||
add(imageLabel, new GridBagConstraints(0, 0, 1, 3, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
|
||||
|
||||
add(titleLabel, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
|
||||
setBackground(new Color(250, 249, 242));
|
||||
add(imageLabel, new GridBagConstraints(0, 0, 1, 3, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
|
||||
add(titleLabel, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
titleLabel.setFont(new Font("Dialog", Font.BOLD, 11));
|
||||
titleLabel.setForeground(new Color(211, 174, 102));
|
||||
add(fileLabel, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 2, 2), 0, 0));
|
||||
add(fileLabel, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
|
||||
|
||||
final RolloverButton hideButton = new RolloverButton("Hide", SparkRes.getImageIcon(SparkRes.SMALL_CLOSE_BUTTON));
|
||||
add(hideButton, new GridBagConstraints(2, 0, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
|
||||
hideButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
add(acceptLabel, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
|
||||
|
||||
add(acceptLabel, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 2), 0, 0));
|
||||
|
||||
add(declineLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 2), 0, 0));
|
||||
add(declineLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
|
||||
|
||||
|
||||
ResourceUtils.resButton(acceptLabel, Res.getString("accept"));
|
||||
@ -145,10 +129,6 @@ public class ReceiveMessage extends JPanel {
|
||||
});
|
||||
}
|
||||
|
||||
public void setChatRoom(ChatRoom chatRoom) {
|
||||
this.chatRoom = chatRoom;
|
||||
}
|
||||
|
||||
public void acceptFileTransfer(final FileTransferRequest request) {
|
||||
String fileName = request.getFileName();
|
||||
long fileSize = request.getFileSize();
|
||||
@ -205,13 +185,6 @@ public class ReceiveMessage extends JPanel {
|
||||
private void rejectRequest(FileTransferRequest request) {
|
||||
request.reject();
|
||||
|
||||
this.setVisible(true);
|
||||
final TranscriptWindow window = chatRoom.getTranscriptWindow();
|
||||
window.remove(this);
|
||||
|
||||
String message = ThemeManager.getInstance().getStatusMessage(Res.getString("message.file.transfer.canceled"), "");
|
||||
window.insertHTML(message);
|
||||
|
||||
setBackground(new Color(239, 245, 250));
|
||||
acceptLabel.setText("");
|
||||
declineLabel.setText("");
|
||||
@ -219,9 +192,9 @@ public class ReceiveMessage extends JPanel {
|
||||
titleLabel.setText(Res.getString("message.file.transfer.canceled"));
|
||||
titleLabel.setForeground(new Color(65, 139, 179));
|
||||
|
||||
window.invalidate();
|
||||
window.validate();
|
||||
window.repaint();
|
||||
invalidate();
|
||||
validate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void acceptRequest(final FileTransferRequest request) {
|
||||
@ -238,8 +211,8 @@ public class ReceiveMessage extends JPanel {
|
||||
titleLabel.setForeground(new Color(65, 139, 179));
|
||||
|
||||
|
||||
add(progressBar, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 2), 150, 0));
|
||||
add(cancelButton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 2, 2), 0, 0));
|
||||
add(progressBar, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 150, 0));
|
||||
add(cancelButton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
|
||||
cancelButton.setVisible(true);
|
||||
transfer = request.accept();
|
||||
try {
|
||||
@ -281,8 +254,8 @@ public class ReceiveMessage extends JPanel {
|
||||
progressBar.setValue((int)bytesRead);
|
||||
FileTransfer.Status status = transfer.getStatus();
|
||||
if (status == FileTransfer.Status.error ||
|
||||
status == FileTransfer.Status.complete || status == FileTransfer.Status.cancelled ||
|
||||
status == FileTransfer.Status.refused) {
|
||||
status == FileTransfer.Status.complete || status == FileTransfer.Status.cancelled ||
|
||||
status == FileTransfer.Status.refused) {
|
||||
break;
|
||||
}
|
||||
else if (status == FileTransfer.Status.negotiating_stream) {
|
||||
@ -298,7 +271,7 @@ public class ReceiveMessage extends JPanel {
|
||||
|
||||
public void finished() {
|
||||
if (transfer.getAmountWritten() >= request.getFileSize()) {
|
||||
//transferDone(request, transfer);
|
||||
transferDone(request, transfer);
|
||||
|
||||
imageLabel.setToolTipText(Res.getString("message.click.to.open"));
|
||||
titleLabel.setToolTipText(Res.getString("message.click.to.open"));
|
||||
@ -342,20 +315,10 @@ public class ReceiveMessage extends JPanel {
|
||||
}
|
||||
});
|
||||
|
||||
TranscriptWindow window = chatRoom.getTranscriptWindow();
|
||||
|
||||
try {
|
||||
String message = ThemeManager.getInstance().getNotificationMessage(getFinishedText(titleLabel.getText(), downloadedFile), true);
|
||||
System.out.println(message);
|
||||
window.insertHTML(message);
|
||||
setVisible(false);
|
||||
window.invalidate();
|
||||
window.validate();
|
||||
window.repaint();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
invalidate();
|
||||
validate();
|
||||
repaint();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -370,7 +333,7 @@ public class ReceiveMessage extends JPanel {
|
||||
transferMessage = Res.getString("message.transfer.refused");
|
||||
}
|
||||
else if (transfer.getStatus() == FileTransfer.Status.cancelled ||
|
||||
transfer.getAmountWritten() < request.getFileSize()) {
|
||||
transfer.getAmountWritten() < request.getFileSize()) {
|
||||
transferMessage = Res.getString("message.transfer.cancelled");
|
||||
}
|
||||
|
||||
@ -422,8 +385,8 @@ public class ReceiveMessage extends JPanel {
|
||||
|
||||
final TransferButton openFileButton = new TransferButton();
|
||||
final TransferButton openFolderButton = new TransferButton();
|
||||
add(openFileButton, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 2), 0, 0));
|
||||
add(openFolderButton, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 2), 0, 0));
|
||||
add(openFileButton, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
|
||||
add(openFolderButton, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
|
||||
|
||||
Downloads downloads = Downloads.getInstance();
|
||||
final File downloadedFile = new File(downloads.getDownloadDirectory(), request.getFileName());
|
||||
@ -451,7 +414,7 @@ public class ReceiveMessage extends JPanel {
|
||||
});
|
||||
|
||||
|
||||
add(fileLabel, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 2, 2), 0, 0));
|
||||
add(fileLabel, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
|
||||
|
||||
ResourceUtils.resButton(openFileButton, Res.getString("open"));
|
||||
ResourceUtils.resButton(openFolderButton, Res.getString("open.folder"));
|
||||
@ -672,44 +635,4 @@ public class ReceiveMessage extends JPanel {
|
||||
popup.show(this, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getFinishedText(String title, File file) throws Exception {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
BufferedImage image = GraphicUtils.getBufferedImage(file);
|
||||
File f = new File("c:\\test.png");
|
||||
try {
|
||||
ImageIO.write(image, "PNG", f);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String iconURL = f.toURL().toString();
|
||||
String fileURL = file.toURL().toString();
|
||||
String folderURL = file.getParentFile().toURL().toString();
|
||||
builder.append("<table width=\"100%\">" +
|
||||
" <tr>" +
|
||||
" <td><img src=\"" + iconURL + "\"></td>" +
|
||||
" <td>" +
|
||||
" " + title + "" +
|
||||
" </td>" +
|
||||
" </tr>" +
|
||||
" <tr>" +
|
||||
" <td colspan=\"2\">" +
|
||||
" " + file.getName() + "" +
|
||||
" </td>" +
|
||||
" </tr>" +
|
||||
" <tr>" +
|
||||
" <td width=\"5%\">" +
|
||||
" <a href=\"" + fileURL + "\" target=\"_blank\">Open</a>" +
|
||||
" </td>" +
|
||||
" <td align=\"left\">" +
|
||||
" <a href=\"" + folderURL + "\" target=\"_blank\">Open Folder</a>" +
|
||||
" </td>" +
|
||||
" </tr>" +
|
||||
"</table>");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ import org.jivesoftware.smackx.filetransfer.FileTransfer.Status;
|
||||
import org.jivesoftware.smackx.filetransfer.FileTransferManager;
|
||||
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.component.RolloverButton;
|
||||
import org.jivesoftware.spark.ui.ContactItem;
|
||||
import org.jivesoftware.spark.ui.ContactList;
|
||||
import org.jivesoftware.spark.util.ByteFormat;
|
||||
@ -73,27 +72,18 @@ public class SendMessage extends JPanel {
|
||||
setLayout(new GridBagLayout());
|
||||
|
||||
setBackground(new Color(250, 249, 242));
|
||||
add(imageLabel, new GridBagConstraints(0, 0, 1, 3, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
|
||||
add(imageLabel, new GridBagConstraints(0, 0, 1, 3, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
|
||||
add(titleLabel, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
|
||||
add(titleLabel, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
|
||||
titleLabel.setFont(new Font("Dialog", Font.BOLD, 11));
|
||||
titleLabel.setForeground(new Color(211, 174, 102));
|
||||
|
||||
final RolloverButton hideButton = new RolloverButton("Hide", SparkRes.getImageIcon(SparkRes.SMALL_CLOSE_BUTTON));
|
||||
add(hideButton, new GridBagConstraints(2, 0, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
|
||||
hideButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
add(fileLabel, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 2, 2), 0, 0));
|
||||
add(fileLabel, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
|
||||
|
||||
cancelButton.setText(Res.getString("cancel"));
|
||||
retryButton.setText(Res.getString("retry"));
|
||||
|
||||
add(cancelButton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 2), 0, 0));
|
||||
add(retryButton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 2), 0, 0));
|
||||
add(cancelButton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
|
||||
add(retryButton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
|
||||
retryButton.setVisible(false);
|
||||
|
||||
retryButton.addActionListener(new ActionListener() {
|
||||
@ -183,7 +173,7 @@ public class SendMessage extends JPanel {
|
||||
progressBar.setMaximum((int)fileSize);
|
||||
progressBar.setVisible(false);
|
||||
progressBar.setStringPainted(true);
|
||||
add(progressBar, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 2), 150, 0));
|
||||
add(progressBar, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 150, 0));
|
||||
|
||||
|
||||
SwingWorker worker = new SwingWorker() {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user