User interface for file history using the new MetaHistoryService.

cusax-fix
Yana Stamcheva 17 years ago
parent 918a8ec7c0
commit 13b5466ee0

@ -118,6 +118,7 @@ felix.auto.start.60= \
reference:file:sc-bundles/msghistory.jar \
reference:file:sc-bundles/callhistory.jar \
reference:file:sc-bundles/filehistory.jar \
reference:file:sc-bundles/metahistory.jar \
reference:file:sc-bundles/audionotifier.jar \
reference:file:sc-bundles/keybindings.jar \
reference:file:sc-bundles/notification.jar

@ -18,6 +18,7 @@
import net.java.sip.communicator.service.fileaccess.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.keybindings.*;
import net.java.sip.communicator.service.metahistory.*;
import net.java.sip.communicator.service.msghistory.*;
import net.java.sip.communicator.service.notification.*;
import net.java.sip.communicator.service.protocol.*;
@ -42,7 +43,7 @@ public class GuiActivator implements BundleActivator
private static ConfigurationService configService;
private static MessageHistoryService msgHistoryService;
private static MetaHistoryService metaHistoryService;
private static MetaContactListService metaCListService;
@ -221,23 +222,23 @@ public static ConfigurationService getConfigurationService() {
}
/**
* Returns the <tt>MessageHistoryService</tt> obtained from the bundle
* Returns the <tt>MetaHistoryService</tt> obtained from the bundle
* context.
* @return the <tt>MessageHistoryService</tt> obtained from the bundle
* @return the <tt>MetaHistoryService</tt> obtained from the bundle
* context
*/
public static MessageHistoryService getMsgHistoryService() {
if (msgHistoryService == null)
public static MetaHistoryService getMetaHistoryService() {
if (metaHistoryService == null)
{
ServiceReference serviceReference = bundleContext
.getServiceReference(MessageHistoryService.class.getName());
.getServiceReference(MetaHistoryService.class.getName());
if (serviceReference != null)
msgHistoryService = (MessageHistoryService) bundleContext
metaHistoryService = (MetaHistoryService) bundleContext
.getService(serviceReference);
}
return msgHistoryService;
return metaHistoryService;
}
/**

@ -122,6 +122,8 @@ protected void setWarningStyle(boolean isWarningStyle)
backgroundColor = warningColor;
else
backgroundColor = defaultColor;
this.repaint();
}
/**

@ -23,9 +23,10 @@
import net.java.sip.communicator.impl.gui.main.chat.filetransfer.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.filehistory.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.gui.event.*;
import net.java.sip.communicator.service.msghistory.*;
import net.java.sip.communicator.service.metahistory.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@ -454,10 +455,10 @@ public boolean isWriteAreaEmpty()
* @param escapedMessageID The incoming message needed to be ignored if
* contained in history.
*/
private void processHistory( Collection<EventObject> historyList,
private void processHistory( Collection<Object> historyList,
String escapedMessageID)
{
Iterator<EventObject> iterator = historyList.iterator();
Iterator<Object> iterator = historyList.iterator();
String messageType;
@ -542,7 +543,18 @@ else if(o instanceof ChatRoomMessageReceivedEvent)
evt.getMessage().getContentType());
}
}
conversationPanel.appendMessageToEnd(historyString);
else if (o instanceof FileRecord)
{
FileRecord fileRecord = (FileRecord) o;
FileHistoryConversationComponent component
= new FileHistoryConversationComponent(fileRecord);
conversationPanel.addComponent(component);
}
if (historyString != null)
conversationPanel.appendMessageToEnd(historyString);
}
getChatWindow().getMainToolBar()
@ -1264,7 +1276,7 @@ public void loadHistory(final String escapedMessageID)
{
SwingWorker historyWorker = new SwingWorker()
{
private Collection<EventObject> historyList;
private Collection<Object> historyList;
public Object construct() throws Exception
{
@ -1291,7 +1303,6 @@ public void finished()
{
processHistory(historyList, escapedMessageID);
}
isHistoryLoaded = true;
// Add incoming events accumulated while the history was loading
@ -1444,16 +1455,17 @@ public void updateChatTransportStatus(ChatTransport chatTransport)
*/
public void loadPreviousPageFromHistory()
{
final MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
final MetaHistoryService chatHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history service could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (chatHistory == null)
return;
new Thread() {
new Thread()
{
public void run()
{
ChatConversationPanel conversationPanel
@ -1462,7 +1474,7 @@ public void run()
Date firstMsgDate
= conversationPanel.getPageFirstMsgTimestamp();
Collection<EventObject> c = null;
Collection<Object> c = null;
if(firstMsgDate != null)
{
@ -1486,13 +1498,13 @@ public void run()
*/
public void loadNextPageFromHistory()
{
final MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
final MetaHistoryService chatHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (chatHistory == null)
return;
new Thread()
@ -1502,7 +1514,7 @@ public void run()
Date lastMsgDate
= getChatConversationPanel().getPageLastMsgTimestamp();
Collection<EventObject> c = null;
Collection<Object> c = null;
if(lastMsgDate != null)
{
c = chatSession.getHistoryAfterDate(
@ -1522,18 +1534,18 @@ public void run()
*/
private class HistoryMessagesLoader implements Runnable
{
private final Collection<EventObject> msgHistory;
private final Collection<Object> chatHistory;
public HistoryMessagesLoader(Collection<EventObject> msgHistory)
public HistoryMessagesLoader(Collection<Object> history)
{
this.msgHistory = msgHistory;
this.chatHistory = history;
}
public void run()
{
getChatConversationPanel().clear();
processHistory(msgHistory, "");
processHistory(chatHistory, "");
getChatConversationPanel().setDefaultContent();
}

@ -10,12 +10,19 @@
import javax.swing.*;
import net.java.sip.communicator.service.filehistory.*;
import net.java.sip.communicator.service.msghistory.*;
/**
* @author Yana Stamcheva
* @author Lubomir Marinov
*/
public interface ChatSession
{
final String[] chatHistoryFilter
= new String[]{ MessageHistoryService.class.getName(),
FileHistoryService.class.getName()};
/**
* Returns the descriptor of this chat session.
*
@ -84,30 +91,33 @@ public interface ChatSession
public String getChatName();
/**
* Returns a collection of the last N number of messages given by count.
* Returns a collection of the last N number of history messages given by
* count.
*
* @param count The number of messages from history to return.
* @return a collection of the last N number of messages given by count.
*/
public Collection<EventObject> getHistory(int count);
public Collection<Object> getHistory(int count);
/**
* Returns a collection of the last N number of messages given by count.
* Returns a collection of the last N number of history messages given by
* count.
*
* @param date The date up to which we're looking for messages.
* @param count The number of messages from history to return.
* @return a collection of the last N number of messages given by count.
*/
public Collection<EventObject> getHistoryBeforeDate(Date date, int count);
public Collection<Object> getHistoryBeforeDate(Date date, int count);
/**
* Returns a collection of the last N number of messages given by count.
* Returns a collection of the last N number of history messages given by
* count.
*
* @param date The date from which we're looking for messages.
* @param count The number of messages from history to return.
* @return a collection of the last N number of messages given by count.
*/
public Collection<EventObject> getHistoryAfterDate(Date date, int count);
public Collection<Object> getHistoryAfterDate(Date date, int count);
/**
* Returns the start date of the history of this chat session.

@ -15,7 +15,7 @@
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.contactlist.event.*;
import net.java.sip.communicator.service.msghistory.*;
import net.java.sip.communicator.service.metahistory.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
@ -124,19 +124,21 @@ public String getChatName()
* @param count The number of messages from history to return.
* @return a collection of the last N number of messages given by count.
*/
public Collection<EventObject> getHistory(int count)
public Collection<Object> getHistory(int count)
{
final MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
final MetaHistoryService metaHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (metaHistory == null)
return null;
return msgHistory.findLast(
metaContact, ConfigurationManager.getChatHistorySize());
return metaHistory.findLast(
chatHistoryFilter,
metaContact,
ConfigurationManager.getChatHistorySize());
}
/**
@ -146,18 +148,19 @@ public Collection<EventObject> getHistory(int count)
* @param count The number of messages from history to return.
* @return a collection of the last N number of messages given by count.
*/
public Collection<EventObject> getHistoryBeforeDate(Date date, int count)
public Collection<Object> getHistoryBeforeDate(Date date, int count)
{
final MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
final MetaHistoryService metaHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (metaHistory == null)
return null;
return msgHistory.findLastMessagesBefore(
return metaHistory.findLastMessagesBefore(
chatHistoryFilter,
metaContact, date, ConfigurationManager.getChatHistorySize());
}
@ -168,18 +171,19 @@ public Collection<EventObject> getHistoryBeforeDate(Date date, int count)
* @param count The number of messages from history to return.
* @return a collection of the last N number of messages given by count.
*/
public Collection<EventObject> getHistoryAfterDate(Date date, int count)
public Collection<Object> getHistoryAfterDate(Date date, int count)
{
final MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
final MetaHistoryService metaHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (metaHistory == null)
return null;
return msgHistory.findFirstMessagesAfter(
return metaHistory.findFirstMessagesAfter(
chatHistoryFilter,
metaContact, date, ConfigurationManager.getChatHistorySize());
}
@ -192,21 +196,22 @@ public long getHistoryStartDate()
{
long startHistoryDate = 0;
MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
MetaHistoryService metaHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (metaHistory == null)
return startHistoryDate;
Collection<EventObject> firstMessage = msgHistory
.findFirstMessagesAfter(metaContact, new Date(0), 1);
Collection<Object> firstMessage = metaHistory
.findFirstMessagesAfter(
chatHistoryFilter, metaContact, new Date(0), 1);
if(firstMessage.size() > 0)
{
Iterator<EventObject> i = firstMessage.iterator();
Iterator<Object> i = firstMessage.iterator();
Object o = i.next();
@ -237,21 +242,22 @@ public long getHistoryEndDate()
{
long endHistoryDate = 0;
MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
MetaHistoryService metaHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (metaHistory == null)
return endHistoryDate;
Collection<EventObject> lastMessage = msgHistory
.findLastMessagesBefore(metaContact, new Date(Long.MAX_VALUE), 1);
Collection<Object> lastMessage = metaHistory
.findLastMessagesBefore(
chatHistoryFilter, metaContact, new Date(Long.MAX_VALUE), 1);
if(lastMessage.size() > 0)
{
Iterator<EventObject> i1 = lastMessage.iterator();
Iterator<Object> i1 = lastMessage.iterator();
Object o1 = i1.next();

@ -13,7 +13,7 @@
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.msghistory.*;
import net.java.sip.communicator.service.metahistory.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
@ -172,18 +172,19 @@ public String getDefaultSmsNumber()
* @param count The number of messages from history to return.
* @return a collection of the last N number of messages given by count.
*/
public Collection<EventObject> getHistory(int count)
public Collection<Object> getHistory(int count)
{
final MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
final MetaHistoryService metaHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (metaHistory == null)
return null;
return msgHistory.findLast(
return metaHistory.findLast(
chatHistoryFilter,
chatRoomWrapper.getChatRoom(),
ConfigurationManager.getChatHistorySize());
}
@ -195,18 +196,19 @@ public Collection<EventObject> getHistory(int count)
* @param count The number of messages from history to return.
* @return a collection of the last N number of messages given by count.
*/
public Collection<EventObject> getHistoryBeforeDate(Date date, int count)
public Collection<Object> getHistoryBeforeDate(Date date, int count)
{
final MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
final MetaHistoryService metaHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (metaHistory == null)
return null;
return msgHistory.findLastMessagesBefore(
return metaHistory.findLastMessagesBefore(
chatHistoryFilter,
chatRoomWrapper.getChatRoom(),
date,
ConfigurationManager.getChatHistorySize());
@ -219,18 +221,19 @@ public Collection<EventObject> getHistoryBeforeDate(Date date, int count)
* @param count The number of messages from history to return.
* @return a collection of the last N number of messages given by count.
*/
public Collection<EventObject> getHistoryAfterDate(Date date, int count)
public Collection<Object> getHistoryAfterDate(Date date, int count)
{
final MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
final MetaHistoryService metaHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (metaHistory == null)
return null;
return msgHistory.findFirstMessagesAfter(
return metaHistory.findFirstMessagesAfter(
chatHistoryFilter,
chatRoomWrapper.getChatRoom(),
date,
ConfigurationManager.getChatHistorySize());
@ -243,25 +246,27 @@ public Collection<EventObject> getHistoryAfterDate(Date date, int count)
*/
public long getHistoryStartDate()
{
MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
MetaHistoryService metaHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (metaHistory == null)
return 0;
long startHistoryDate = 0;
Collection<EventObject> firstMessage = msgHistory
.findFirstMessagesAfter(chatRoomWrapper.getChatRoom(),
new Date(0),
1);
Collection<Object> firstMessage = metaHistory
.findFirstMessagesAfter(
chatHistoryFilter,
chatRoomWrapper.getChatRoom(),
new Date(0),
1);
if(firstMessage.size() > 0)
{
Iterator<EventObject> i = firstMessage.iterator();
Iterator<Object> i = firstMessage.iterator();
Object o = i.next();
@ -290,24 +295,26 @@ else if(o instanceof MessageReceivedEvent)
*/
public long getHistoryEndDate()
{
MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
MetaHistoryService metaHistory
= GuiActivator.getMetaHistoryService();
// If the MessageHistoryService is not registered we have nothing to do
// here. The MessageHistoryService could be "disabled" from the user
// If the MetaHistoryService is not registered we have nothing to do
// here. The history could be "disabled" from the user
// through one of the configuration forms.
if (msgHistory == null)
if (metaHistory == null)
return 0;
long endHistoryDate = 0;
Collection<EventObject> lastMessage = msgHistory
.findLastMessagesBefore(chatRoomWrapper.getChatRoom(),
new Date(Long.MAX_VALUE), 1);
Collection<Object> lastMessage = metaHistory
.findLastMessagesBefore(
chatHistoryFilter,
chatRoomWrapper.getChatRoom(),
new Date(Long.MAX_VALUE), 1);
if(lastMessage.size() > 0)
{
Iterator<EventObject> i1 = lastMessage.iterator();
Iterator<Object> i1 = lastMessage.iterator();
Object o1 = i1.next();

@ -0,0 +1,100 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.chat.filetransfer;
import net.java.sip.communicator.service.filehistory.*;
/**
* The component used to show a file transfer history record in the chat or
* history window.
*
* @author Yana Stamcheva
*/
public class FileHistoryConversationComponent
extends FileTransferConversationComponent
{
public FileHistoryConversationComponent(FileRecord fileRecord)
{
String contactName = fileRecord.getContact().getDisplayName();
String titleString = "";
if (fileRecord.getDirection().equals(FileRecord.IN))
{
if (fileRecord.getStatus().equals(FileRecord.COMPLETED))
{
titleString = resources.getI18NString(
"service.gui.FILE_RECEIVE_COMPLETED",
new String[]{contactName});
setWarningStyle(false);
}
else if (fileRecord.getStatus().equals(FileRecord.CANCELED))
{
titleString = resources.getI18NString(
"service.gui.FILE_TRANSFER_CANCELED");
setWarningStyle(true);
}
else if (fileRecord.getStatus().equals(FileRecord.FAILED))
{
titleString = resources.getI18NString(
"service.gui.FILE_RECEIVE_FAILED",
new String[]{contactName});
setWarningStyle(true);
}
else if (fileRecord.getStatus().equals(FileRecord.REFUSED))
{
titleString = resources.getI18NString(
"service.gui.FILE_TRANSFER_REFUSED",
new String[]{contactName});
setWarningStyle(true);
}
}
else if (fileRecord.getDirection().equals(FileRecord.OUT))
{
if (fileRecord.getStatus().equals(FileRecord.COMPLETED))
{
titleString = resources.getI18NString(
"service.gui.FILE_SEND_COMPLETED",
new String[]{contactName});
setWarningStyle(false);
}
else if (fileRecord.getStatus().equals(FileRecord.CANCELED))
{
titleString = resources.getI18NString(
"service.gui.FILE_TRANSFER_CANCELED");
setWarningStyle(true);
}
else if (fileRecord.getStatus().equals(FileRecord.FAILED))
{
titleString = resources.getI18NString(
"service.gui.FILE_UNABLE_TO_SEND",
new String[]{contactName});
setWarningStyle(true);
}
else if (fileRecord.getStatus().equals(FileRecord.REFUSED))
{
titleString = resources.getI18NString(
"service.gui.FILE_SEND_REFUSED",
new String[]{contactName});
setWarningStyle(true);
}
}
this.setCompletedDownloadFile(fileRecord.getFile());
titleLabel.setText(titleString);
fileLabel.setText(getFileName(fileRecord.getFile()));
openFileButton.setVisible(true);
openFolderButton.setVisible(true);
}
}

@ -0,0 +1,427 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.chat.filetransfer;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* The <tt>FileTransferConversationComponent</tt> is the parent of all file
* conversation components - for incoming, outgoing and history file transfers.
*
* @author Yana Stamcheva
*/
public abstract class FileTransferConversationComponent
extends ChatConversationComponent
implements ActionListener,
FileTransferProgressListener
{
private final Logger logger
= Logger.getLogger(FileTransferConversationComponent.class);
private final FileImageLabel imageLabel = new FileImageLabel();
protected final JLabel titleLabel = new JLabel();
protected final JLabel fileLabel = new JLabel();
private final JTextArea errorArea = new JTextArea();
private final JLabel errorIconLabel = new JLabel(
new ImageIcon(ImageLoader.getImage(ImageLoader.EXCLAMATION_MARK)));
protected final ChatConversationButton cancelButton
= new ChatConversationButton();
protected final ChatConversationButton retryButton
= new ChatConversationButton();
protected final ChatConversationButton acceptButton
= new ChatConversationButton();
protected final ChatConversationButton rejectButton
= new ChatConversationButton();
protected final ChatConversationButton openFileButton
= new ChatConversationButton();
protected final ChatConversationButton openFolderButton
= new ChatConversationButton();
protected final JProgressBar progressBar = new JProgressBar();
private File downloadFile;
private FileTransfer fileTransfer;
/**
* Creates a file conversation component.
*/
public FileTransferConversationComponent()
{
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 4;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(5, 5, 5, 5);
add(imageLabel, constraints);
imageLabel.setIcon(new ImageIcon(
ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON)));
constraints.gridx = 1;
constraints.gridy = 0;
constraints.gridwidth = 2;
constraints.gridheight = 1;
constraints.fill=GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(5, 5, 5, 5);
add(titleLabel, constraints);
titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 11f));
constraints.gridx = 1;
constraints.gridy = 1;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 5, 5);
add(fileLabel, constraints);
constraints.gridx = 1;
constraints.gridy = 2;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.NONE;
add(errorIconLabel, constraints);
errorIconLabel.setVisible(false);
constraints.gridx = 2;
constraints.gridy = 2;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.HORIZONTAL;
add(errorArea, constraints);
errorArea.setForeground(
new Color(resources.getColor("service.gui.ERROR_FOREGROUND")));
setTextAreaStyle(errorArea);
errorArea.setVisible(false);
constraints.gridx = 1;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
add(retryButton, constraints);
retryButton.setText(
GuiActivator.getResources().getI18NString("service.gui.RETRY"));
retryButton.setVisible(false);
constraints.gridx = 1;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
add(cancelButton, constraints);
cancelButton.setText(
GuiActivator.getResources().getI18NString("service.gui.CANCEL"));
cancelButton.addActionListener(this);
cancelButton.setVisible(false);
constraints.gridx = 1;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.NONE;
add(acceptButton, constraints);
acceptButton.setText(
GuiActivator.getResources().getI18NString("service.gui.ACCEPT"));
acceptButton.setVisible(false);
constraints.gridx = 2;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.NONE;
add(rejectButton, constraints);
rejectButton.setText(
GuiActivator.getResources().getI18NString("service.gui.REJECT"));
rejectButton.setVisible(false);
constraints.gridx = 1;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.NONE;
add(openFileButton, constraints);
openFileButton.setText(
GuiActivator.getResources().getI18NString("service.gui.OPEN"));
openFileButton.setVisible(false);
openFileButton.addActionListener(this);
constraints.gridx = 2;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.NONE;
add(openFolderButton, constraints);
openFolderButton.setText(
GuiActivator.getResources().getI18NString(
"service.gui.OPEN_FOLDER"));
openFolderButton.setVisible(false);
openFolderButton.addActionListener(this);
constraints.gridx = 1;
constraints.gridy = 2;
constraints.gridwidth = 2;
constraints.gridheight = 1;
constraints.weightx = 1.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.ipadx = 150;
constraints.fill = GridBagConstraints.HORIZONTAL;
add(progressBar, constraints);
progressBar.setVisible(false);
progressBar.setStringPainted(true);
}
/**
* Sets a custom style for the given text area.
*
* @param textArea the text area to style
*/
private void setTextAreaStyle(JTextArea textArea)
{
textArea.setOpaque(false);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
}
/**
* Shows the given error message in the error area of this component.
*
* @param message the message to show
*/
protected void showErrorMessage(String message)
{
errorArea.setText(message);
errorIconLabel.setVisible(true);
errorArea.setVisible(true);
}
/**
* Sets the icon for the given file.
*
* @param file the file to set an icon for
*/
protected void setFileIcon(File file)
{
if (FileUtils.isImage(file.getName()))
{
try
{
ImageIcon image = new ImageIcon(file.toURI().toURL());
imageLabel.setToolTipImage(image);
image = ImageUtils
.getScaledRoundedIcon(image.getImage(), 64, 64);
imageLabel.setIcon(image);
}
catch (MalformedURLException e)
{
logger.debug("Could not locate image.", e);
imageLabel.setIcon(new ImageIcon(
ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON)));
}
}
else
{
Icon icon = FileUtils.getIcon(file);
if (icon == null)
icon = new ImageIcon(
ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON));
imageLabel.setIcon(icon);
}
}
/**
* Sets the download file.
*
* @param file the file that has been downloaded or sent
*/
protected void setCompletedDownloadFile(File file)
{
this.downloadFile = file;
imageLabel.setFile(downloadFile);
imageLabel.setToolTipText(
resources.getI18NString("service.gui.OPEN_FILE_FROM_IMAGE"));
imageLabel.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() > 1)
{
openFile(downloadFile);
}
}
});
}
/**
* Sets the file transfer.
*
* @param fileTransfer the file transfer
*/
protected void setFileTransfer(FileTransfer fileTransfer)
{
this.fileTransfer = fileTransfer;
fileTransfer.addProgressListener(this);
}
/**
* Handles buttons action events.
*/
public void actionPerformed(ActionEvent evt)
{
JButton sourceButton = (JButton) evt.getSource();
if (sourceButton.equals(openFileButton))
{
this.openFile(downloadFile);
}
else if (sourceButton.equals(openFolderButton))
{
try
{
File downloadDir = GuiActivator.getFileAccessService()
.getDefaultDownloadDirectory();
GuiActivator.getDesktopService().open(downloadDir);
}
catch (IllegalArgumentException e)
{
logger.debug("Unable to open folder.", e);
this.showErrorMessage(
resources.getI18NString(
"service.gui.FOLDER_DOES_NOT_EXIST"));
}
catch (NullPointerException e)
{
logger.debug("Unable to open folder.", e);
this.showErrorMessage(
resources.getI18NString(
"service.gui.FOLDER_DOES_NOT_EXIST"));
}
catch (UnsupportedOperationException e)
{
logger.debug("Unable to open folder.", e);
this.showErrorMessage(
resources.getI18NString(
"service.gui.FILE_OPEN_NOT_SUPPORTED"));
}
catch (SecurityException e)
{
logger.debug("Unable to open folder.", e);
this.showErrorMessage(
resources.getI18NString(
"service.gui.FOLDER_OPEN_NO_PERMISSION"));
}
catch (IOException e)
{
logger.debug("Unable to open folder.", e);
this.showErrorMessage(
resources.getI18NString(
"service.gui.FOLDER_OPEN_NO_APPLICATION"));
}
catch (Exception e)
{
logger.debug("Unable to open file.", e);
this.showErrorMessage(
resources.getI18NString(
"service.gui.FOLDER_OPEN_FAILED"));
}
}
else if (sourceButton.equals(cancelButton))
{
if (fileTransfer != null)
fileTransfer.cancel();
}
}
/**
* Updates progress bar progress line every time a progress event has been
* received.
*/
public void progressChanged(FileTransferProgressEvent event)
{
progressBar.setValue((int) event.getProgress());
ByteFormat format = new ByteFormat();
String bytesSent = format.format(
event.getFileTransfer().getTransferedBytes());
progressBar.setString(bytesSent
+ " " + resources.getI18NString("service.gui.SENT"));
}
/**
* Returns the name of the given file.
*
* @param file the file
* @return the name of the given file
*/
protected String getFileName(File file)
{
String fileName = file.getName();
long fileSize = file.length();
ByteFormat format = new ByteFormat();
String text = format.format(fileSize);
return fileName + " (" + text + ")";
}
}

@ -6,16 +6,10 @@
*/
package net.java.sip.communicator.impl.gui.main.chat.filetransfer;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@ -29,37 +23,14 @@
* @author Yana Stamcheva
*/
public class ReceiveFileConversationComponent
extends ChatConversationComponent
extends FileTransferConversationComponent
implements ActionListener,
FileTransferStatusListener,
FileTransferProgressListener
FileTransferStatusListener
{
private final Logger logger
= Logger.getLogger(SendFileConversationComponent.class);
private final FileImageLabel imageLabel = new FileImageLabel();
private final JLabel titleLabel = new JLabel();
private final JLabel fileLabel = new JLabel();
private final JTextArea errorArea = new JTextArea();
private final JLabel errorIconLabel = new JLabel(
new ImageIcon(ImageLoader.getImage(ImageLoader.EXCLAMATION_MARK)));
private ChatConversationButton acceptButton = new ChatConversationButton();
private ChatConversationButton rejectButton = new ChatConversationButton();
private ChatConversationButton cancelButton = new ChatConversationButton();
private ChatConversationButton openFileButton
= new ChatConversationButton();
private ChatConversationButton openFolderButton
= new ChatConversationButton();
private JProgressBar progressBar = new JProgressBar();
private IncomingFileTransferRequest fileTransferRequest;
= Logger.getLogger(ReceiveFileConversationComponent.class);
private FileTransfer fileTransfer;
private File downloadFile;
private final IncomingFileTransferRequest fileTransferRequest;
/**
* Creates a <tt>ReceiveFileConversationComponent</tt>.
@ -68,248 +39,53 @@ public class ReceiveFileConversationComponent
* associated with this component
*/
public ReceiveFileConversationComponent(
IncomingFileTransferRequest fileTransferRequest)
final IncomingFileTransferRequest request)
{
this.fileTransferRequest = fileTransferRequest;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 4;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(5, 5, 5, 5);
add(imageLabel, constraints);
imageLabel.setIcon(new ImageIcon(
ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON)));
constraints.gridx = 1;
constraints.gridy = 0;
constraints.gridwidth = 2;
constraints.gridheight = 1;
constraints.fill=GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(5, 5, 5, 5);
add(titleLabel, constraints);
this.fileTransferRequest = request;
titleLabel.setText(resources.getI18NString(
"service.gui.FILE_TRANSFER_REQUEST_RECIEVED",
new String[]{fileTransferRequest.getSender().getDisplayName()}));
titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 11f));
constraints.gridx = 1;
constraints.gridy = 1;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 5, 5);
add(fileLabel, constraints);
fileLabel.setText(fileTransferRequest.getFileName());
constraints.gridx = 1;
constraints.gridy = 2;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.NONE;
add(errorIconLabel, constraints);
errorIconLabel.setVisible(false);
constraints.gridx = 2;
constraints.gridy = 2;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.HORIZONTAL;
add(errorArea, constraints);
errorArea.setForeground(
new Color(resources.getColor("service.gui.ERROR_FOREGROUND")));
setTextAreaStyle(errorArea);
errorArea.setVisible(false);
constraints.gridx = 1;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.NONE;
add(acceptButton, constraints);
acceptButton.setText(
GuiActivator.getResources().getI18NString("service.gui.ACCEPT"));
acceptButton.addActionListener(this);
constraints.gridx = 2;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
add(rejectButton, constraints);
rejectButton.setText(
GuiActivator.getResources().getI18NString("service.gui.REJECT"));
rejectButton.addActionListener(this);
constraints.gridx = 1;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
add(cancelButton, constraints);
cancelButton.setText(
GuiActivator.getResources().getI18NString("service.gui.CANCEL"));
cancelButton.addActionListener(this);
cancelButton.setVisible(false);
constraints.gridx = 1;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
add(openFileButton, constraints);
openFileButton.setText(
GuiActivator.getResources().getI18NString("service.gui.OPEN"));
openFileButton.setVisible(false);
openFileButton.addActionListener(this);
constraints.gridx = 2;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
add(openFolderButton, constraints);
openFolderButton.setText(
GuiActivator.getResources().getI18NString(
"service.gui.OPEN_FOLDER"));
openFolderButton.setVisible(false);
openFolderButton.addActionListener(this);
constraints.gridx = 1;
constraints.gridy = 2;
constraints.gridwidth = 2;
constraints.gridheight = 1;
constraints.weightx = 1.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.ipadx = 150;
add(progressBar, constraints);
progressBar.setVisible(false);
progressBar.setStringPainted(true);
progressBar.setMaximum((int)fileTransferRequest.getFileSize());
}
/**
* Handles button actions.
*/
public void actionPerformed(ActionEvent evt)
{
JButton sourceButton = (JButton) evt.getSource();
if (sourceButton.equals(acceptButton))
{
titleLabel.setText(resources
.getI18NString("service.gui.FILE_TRANSFER_PREPARING",
new String[]{fileTransferRequest.getSender()
.getDisplayName()}));
acceptButton.setVisible(false);
rejectButton.setVisible(false);
cancelButton.setVisible(true);
progressBar.setVisible(true);
downloadFile = createFile();
new AcceptFile().start();
}
else if (sourceButton.equals(rejectButton))
{
fileTransferRequest.rejectFile();
acceptButton.setVisible(false);
rejectButton.setVisible(false);
fileLabel.setText("");
titleLabel.setText(
resources.getI18NString("service.gui.FILE_TRANSFER_CANCELED"));
}
else if (sourceButton.equals(cancelButton))
{
fileTransfer.cancel();
}
else if (sourceButton.equals(openFileButton))
{
this.openFile(downloadFile);
}
else if (sourceButton.equals(openFolderButton))
acceptButton.setVisible(true);
acceptButton.addActionListener(new ActionListener()
{
try
{
File downloadDir = GuiActivator.getFileAccessService()
.getDefaultDownloadDirectory();
GuiActivator.getDesktopService().open(downloadDir);
}
catch (IllegalArgumentException e)
public void actionPerformed(ActionEvent e)
{
logger.debug("Unable to open folder.", e);
this.showErrorMessage(
resources.getI18NString(
"service.gui.FOLDER_DOES_NOT_EXIST"));
}
catch (NullPointerException e)
{
logger.debug("Unable to open folder.", e);
titleLabel.setText(resources
.getI18NString("service.gui.FILE_TRANSFER_PREPARING",
new String[]{fileTransferRequest.getSender()
.getDisplayName()}));
acceptButton.setVisible(false);
rejectButton.setVisible(false);
cancelButton.setVisible(true);
progressBar.setVisible(true);
this.showErrorMessage(
resources.getI18NString(
"service.gui.FOLDER_DOES_NOT_EXIST"));
}
catch (UnsupportedOperationException e)
{
logger.debug("Unable to open folder.", e);
File downloadFile = createFile(fileTransferRequest);
this.showErrorMessage(
resources.getI18NString(
"service.gui.FILE_OPEN_NOT_SUPPORTED"));
new AcceptFile(downloadFile).start();
}
catch (SecurityException e)
{
logger.debug("Unable to open folder.", e);
});
this.showErrorMessage(
resources.getI18NString(
"service.gui.FOLDER_OPEN_NO_PERMISSION"));
}
catch (IOException e)
rejectButton.setVisible(true);
rejectButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
logger.debug("Unable to open folder.", e);
fileTransferRequest.rejectFile();
this.showErrorMessage(
acceptButton.setVisible(false);
rejectButton.setVisible(false);
fileLabel.setText("");
titleLabel.setText(
resources.getI18NString(
"service.gui.FOLDER_OPEN_NO_APPLICATION"));
"service.gui.FILE_TRANSFER_CANCELED"));
}
catch (Exception e)
{
logger.debug("Unable to open file.", e);
});
this.showErrorMessage(
resources.getI18NString(
"service.gui.FOLDER_OPEN_FAILED"));
}
}
progressBar.setMaximum((int)fileTransferRequest.getFileSize());
}
/**
@ -317,7 +93,7 @@ else if (sourceButton.equals(openFolderButton))
*
* @return the file to download.
*/
private File createFile()
private File createFile(IncomingFileTransferRequest fileTransferRequest)
{
File downloadFile = null;
File downloadDir = null;
@ -370,6 +146,8 @@ private File createFile()
public void statusChanged(FileTransferStatusChangeEvent event)
{
int status = event.getNewStatus();
FileTransfer fileTransfer = event.getFileTransfer();
String fromContactName
= fileTransferRequest.getSender().getDisplayName();
@ -403,11 +181,7 @@ else if (status == FileTransferStatusChangeEvent.IN_PROGRESS)
}
else if (status == FileTransferStatusChangeEvent.COMPLETED)
{
if (downloadFile != null)
{
imageLabel.setFile(downloadFile);
setFileIcon(downloadFile);
}
this.setCompletedDownloadFile(fileTransfer.getFile());
progressBar.setVisible(false);
cancelButton.setVisible(false);
@ -417,20 +191,6 @@ else if (status == FileTransferStatusChangeEvent.COMPLETED)
titleLabel.setText(resources.getI18NString(
"service.gui.FILE_RECEIVE_COMPLETED",
new String[]{fromContactName}));
imageLabel.setToolTipText(
resources.getI18NString("service.gui.OPEN_FILE_FROM_IMAGE"));
imageLabel.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() > 1)
{
openFile(downloadFile);
}
}
});
}
else if (status == FileTransferStatusChangeEvent.CANCELED)
{
@ -453,62 +213,19 @@ else if (status == FileTransferStatusChangeEvent.REFUSED)
}
/**
* Updates progress bar progress line every time a progress event has been
* received.
* Accepts the file in a new thread.
*/
public void progressChanged(FileTransferProgressEvent event)
private class AcceptFile extends SwingWorker
{
progressBar.setValue((int) event.getProgress());
private FileTransfer fileTransfer;
ByteFormat format = new ByteFormat();
String bytesSent = format.format(
event.getFileTransfer().getTransferedBytes());
progressBar.setString(bytesSent
+ " " + resources.getI18NString("service.gui.SENT"));
}
/**
* Sets the icon for the given file.
*
* @param file the file to set an icon for
*/
private void setFileIcon(File file)
{
if (FileUtils.isImage(file.getName()))
{
try
{
ImageIcon image = new ImageIcon(file.toURI().toURL());
imageLabel.setToolTipImage(image);
private final File downloadFile;
image = ImageUtils
.getScaledRoundedIcon(image.getImage(), 64, 64);
imageLabel.setIcon(image);
}
catch (MalformedURLException e)
{
logger.debug("Could not locate image.", e);
imageLabel.setIcon(new ImageIcon(
ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON)));
}
}
else
public AcceptFile(File downloadFile)
{
Icon icon = FileUtils.getIcon(file);
if (icon == null)
icon = new ImageIcon(
ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON));
imageLabel.setIcon(icon);
this.downloadFile = downloadFile;
}
}
/**
* Accepts the file in a new thread.
*/
private class AcceptFile extends SwingWorker
{
public Object construct()
{
fileTransfer = fileTransferRequest.acceptFile(downloadFile);
@ -520,35 +237,11 @@ public void finished()
{
if (fileTransfer != null)
{
setFileTransfer(fileTransfer);
fileTransfer.addStatusListener(
ReceiveFileConversationComponent.this);
fileTransfer.addProgressListener(
ReceiveFileConversationComponent.this);
}
}
}
/**
* Shows the given error message in the error area of this component.
*
* @param message the message to show
*/
protected void showErrorMessage(String message)
{
errorArea.setText(message);
errorIconLabel.setVisible(true);
errorArea.setVisible(true);
}
/**
* Sets a custom style for the given text area.
*
* @param textArea the text area to style
*/
private void setTextAreaStyle(JTextArea textArea)
{
textArea.setOpaque(false);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
}
}

@ -6,19 +6,14 @@
*/
package net.java.sip.communicator.impl.gui.main.chat.filetransfer;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* The <tt>SendFileConversationComponent</tt> is the component added in the
@ -27,34 +22,13 @@
* @author Yana Stamcheva
*/
public class SendFileConversationComponent
extends ChatConversationComponent
implements ActionListener,
FileTransferStatusListener,
FileTransferProgressListener
extends FileTransferConversationComponent
implements FileTransferStatusListener
{
private final Logger logger
= Logger.getLogger(SendFileConversationComponent.class);
private final FileImageLabel imageLabel = new FileImageLabel();
private final JLabel titleLabel = new JLabel();
private final JLabel fileLabel = new JLabel();
private final JTextArea errorArea = new JTextArea();
private final JLabel errorIconLabel = new JLabel(
new ImageIcon(ImageLoader.getImage(ImageLoader.EXCLAMATION_MARK)));
private ChatConversationButton cancelButton = new ChatConversationButton();
private ChatConversationButton retryButton = new ChatConversationButton();
private JProgressBar progressBar = new JProgressBar();
private final String toContactName;
private FileTransfer fileTransfer;
private final ChatPanel parentChatPanel;
private final File file;
/**
* Creates a <tt>SendFileConversationComponent</tt> by specifying the parent
* chat panel, where this component is added, the destination contact of
@ -70,107 +44,33 @@ public SendFileConversationComponent( ChatPanel chatPanel,
{
this.parentChatPanel = chatPanel;
this.toContactName = toContactName;
this.file = file;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 4;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(5, 5, 5, 5);
this.setCompletedDownloadFile(file);
add(imageLabel, constraints);
this.setFileIcon(file);
imageLabel.setToolTipText(
resources.getI18NString("service.gui.OPEN_FILE_FROM_IMAGE"));
imageLabel.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() > 1)
{
openFile(file);
}
}
});
constraints.gridx = 1;
constraints.gridy = 0;
constraints.gridwidth = 2;
constraints.gridheight = 1;
constraints.weightx = 1.0;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.insets = new Insets(5, 5, 5, 5);
add(titleLabel, constraints);
titleLabel.setText(resources.getI18NString(
"service.gui.FILE_WAITING_TO_ACCEPT",
new String[]{toContactName}));
titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 11f));
constraints.gridx = 1;
constraints.gridy = 1;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 5, 5);
add(fileLabel, constraints);
fileLabel.setText(getFileName(file));
constraints.gridx = 1;
constraints.gridy = 2;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.NONE;
add(errorIconLabel, constraints);
errorIconLabel.setVisible(false);
constraints.gridx = 2;
constraints.gridy = 2;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridx = 1;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
add(cancelButton, constraints);
cancelButton.setText(
GuiActivator.getResources().getI18NString("service.gui.CANCEL"));
cancelButton.addActionListener(this);
constraints.gridx = 1;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
progressBar.setMaximum((int) file.length());
cancelButton.setVisible(true);
add(retryButton, constraints);
retryButton.setText(
GuiActivator.getResources().getI18NString("service.gui.RETRY"));
retryButton.addActionListener(this);
retryButton.setVisible(false);
retryButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JButton sourceButton = (JButton) e.getSource();
constraints.gridx = 1;
constraints.gridy = 2;
constraints.gridwidth = 2;
constraints.gridheight = 1;
constraints.weightx = 1.0;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.ipadx = 150;
if (sourceButton.equals(retryButton))
{
setWarningStyle(false);
add(progressBar, constraints);
progressBar.setMaximum((int) file.length());
progressBar.setVisible(false);
progressBar.setStringPainted(true);
parentChatPanel
.sendFile(file, SendFileConversationComponent.this);
}
}
});
}
/**
@ -182,63 +82,9 @@ public void mouseClicked(MouseEvent e)
*/
public void setProtocolFileTransfer(FileTransfer fileTransfer)
{
this.fileTransfer = fileTransfer;
this.setFileTransfer(fileTransfer);
fileTransfer.addStatusListener(this);
fileTransfer.addProgressListener(this);
}
/**
* Returns the name of the given file.
*
* @param file the file
* @return the name of the given file
*/
private String getFileName(File file)
{
String fileName = file.getName();
long fileSize = file.length();
ByteFormat format = new ByteFormat();
String text = format.format(fileSize);
return fileName + " (" + text + ")";
}
/**
* Sets the icon for the given file.
*
* @param file the file to set an icon for
*/
private void setFileIcon(File file)
{
if (FileUtils.isImage(file.getName()))
{
try
{
ImageIcon image = new ImageIcon(file.toURI().toURL());
imageLabel.setToolTipImage(image);
image = ImageUtils
.getScaledRoundedIcon(image.getImage(), 64, 64);
imageLabel.setIcon(image);
}
catch (MalformedURLException e)
{
logger.debug("Could not locate image.", e);
imageLabel.setIcon(new ImageIcon(
ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON)));
}
}
else
{
Icon icon = FileUtils.getIcon(file);
if (icon == null)
icon = new ImageIcon(
ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON));
imageLabel.setIcon(icon);
}
}
/**
@ -309,49 +155,4 @@ else if (status == FileTransferStatusChangeEvent.REFUSED)
setWarningStyle(true);
}
}
/**
* Updates progress bar progress line every time a progress event has been
* received.
*/
public void progressChanged(FileTransferProgressEvent event)
{
progressBar.setValue((int) event.getProgress());
ByteFormat format = new ByteFormat();
String bytesSent = format.format(
event.getFileTransfer().getTransferedBytes());
progressBar.setString(bytesSent
+ " " + resources.getI18NString("service.gui.SENT"));
}
/**
* Handles button actions.
*/
public void actionPerformed(ActionEvent e)
{
JButton sourceButton = (JButton) e.getSource();
if (sourceButton.equals(cancelButton))
{
if (fileTransfer != null)
fileTransfer.cancel();
}
else if (sourceButton.equals(retryButton))
{
parentChatPanel.sendFile(file, this);
}
}
/**
* Shows the given error message in the error area of this component.
*
* @param message the message to show
*/
protected void showErrorMessage(String message)
{
errorArea.setText(message);
errorIconLabel.setVisible(true);
errorArea.setVisible(true);
}
}

@ -19,10 +19,13 @@
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.main.chat.conference.*;
import net.java.sip.communicator.impl.gui.main.chat.filetransfer.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.filehistory.*;
import net.java.sip.communicator.service.history.event.*;
import net.java.sip.communicator.service.metahistory.*;
import net.java.sip.communicator.service.msghistory.*;
import net.java.sip.communicator.service.msghistory.event.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@ -38,7 +41,7 @@
public class HistoryWindow
extends SIPCommFrame
implements ChatConversationContainer,
MessageHistorySearchProgressListener,
HistorySearchProgressListener,
MessageListener,
ChatRoomMessageListener
{
@ -63,22 +66,26 @@ public class HistoryWindow
private Object historyContact;
private MessageHistoryService msgHistory;
private MetaHistoryService history;
private Hashtable<Date, HTMLDocument> dateHistoryTable
= new Hashtable<Date, HTMLDocument>();
private JLabel readyLabel = new JLabel(
GuiActivator.getResources().getI18NString("service.gui.READY"));
private String searchKeyword;
private Vector<Date> datesVector = new Vector<Date>();
private static final String[] historyFilter
= new String[]{ MessageHistoryService.class.getName(),
FileHistoryService.class.getName()};
private Date ignoreProgressDate;
private int lastProgress = 0;
/**
* Creates an instance of the <tt>HistoryWindow</tt>.
* @param mainFrame the main application window
@ -91,14 +98,14 @@ public HistoryWindow(Object historyContact)
chatConvPanel = new ChatConversationPanel(this);
this.progressBar = new JProgressBar(
MessageHistorySearchProgressListener.PROGRESS_MINIMUM_VALUE,
MessageHistorySearchProgressListener.PROGRESS_MAXIMUM_VALUE);
HistorySearchProgressListener.PROGRESS_MINIMUM_VALUE,
HistorySearchProgressListener.PROGRESS_MAXIMUM_VALUE);
this.progressBar.setValue(0);
this.progressBar.setStringPainted(true);
this.msgHistory = GuiActivator.getMsgHistoryService();
this.msgHistory.addSearchProgressListener(this);
this.history = GuiActivator.getMetaHistoryService();
this.history.addSearchProgressListener(this);
this.datesPanel = new DatesPanel(this);
this.historyMenu = new HistoryMenu(this);
@ -121,11 +128,11 @@ public HistoryWindow(Object historyContact)
new String[]{metaContact.getDisplayName()}));
Iterator<Contact> protoContacts = metaContact.getContacts();
while(protoContacts.hasNext())
{
Contact protoContact = protoContacts.next();
((OperationSetBasicInstantMessaging) protoContact
.getProtocolProvider().getOperationSet(
OperationSetBasicInstantMessaging.class))
@ -165,7 +172,7 @@ private void initPanels()
* with the given contact is availabled.
*/
private void initDates()
{
{
this.initProgressBar(null);
new DatesLoader().start();
}
@ -176,19 +183,20 @@ private void initDates()
* @param endDate the end date of the period
*/
public void showHistoryByPeriod(Date startDate, Date endDate)
{
{
if((searchKeyword == null || searchKeyword == "")
&& dateHistoryTable.containsKey(startDate)) {
&& dateHistoryTable.containsKey(startDate))
{
HTMLDocument document = dateHistoryTable.get(startDate);
this.chatConvPanel.setContent(document);
}
else {
else
{
this.chatConvPanel.clear();
//init progress bar by precising the date that will be loaded.
this.initProgressBar(startDate);
new MessagesLoader(startDate, endDate).start();
}
}
@ -200,12 +208,12 @@ public void showHistoryByPeriod(Date startDate, Date endDate)
public void showHistoryByKeyword(String keyword)
{
this.initProgressBar(null);
chatConvPanel.clear();
chatConvPanel.clear();
datesPanel.setLastSelectedIndex(-1);
new KeywordDatesLoader(keyword).start();
searchKeyword = keyword;
}
@ -213,11 +221,11 @@ public void showHistoryByKeyword(String keyword)
* Shows the history given by the collection into a ChatConversationPanel.
* @param historyRecords a collection of history records
*/
private HTMLDocument createHistory(Collection<EventObject> historyRecords)
private HTMLDocument createHistory(Collection<Object> historyRecords)
{
if((historyRecords != null) && (historyRecords.size() > 0)) {
Iterator<EventObject> i = historyRecords.iterator();
if((historyRecords != null) && (historyRecords.size() > 0))
{
Iterator<Object> i = historyRecords.iterator();
String processedMessage = "";
while (i.hasNext())
{
@ -274,6 +282,15 @@ else if(o instanceof ChatRoomMessageDeliveredEvent)
evt.getMessage().getContent(),
evt.getMessage().getContentType());
}
else if (o instanceof FileRecord)
{
FileRecord fileRecord = (FileRecord) o;
FileHistoryConversationComponent component
= new FileHistoryConversationComponent(fileRecord);
chatConvPanel.addComponent(component);
}
if (chatMessage != null)
{
@ -284,6 +301,7 @@ else if(o instanceof ChatRoomMessageDeliveredEvent)
}
}
}
this.chatConvPanel.setDefaultContent();
return this.chatConvPanel.getContent();
@ -311,11 +329,12 @@ public Window getConversationContainerWindow()
*/
public class HistoryWindowAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent e) {
msgHistory.removeSearchProgressListener(HistoryWindow.this);
public void windowClosing(WindowEvent e)
{
history.removeSearchProgressListener(HistoryWindow.this);
}
}
/**
* Returns the next date from the history.
*
@ -338,21 +357,22 @@ public Date getNextDateFromHistory(Date date)
public void progressChanged(ProgressEvent evt)
{
int progress = evt.getProgress();
if((lastProgress != progress)
&& evt.getStartDate() == null
|| evt.getStartDate() != ignoreProgressDate) {
|| evt.getStartDate() != ignoreProgressDate)
{
this.progressBar.setValue(progress);
if(progressBar.getPercentComplete() == 1.0) {
if(progressBar.getPercentComplete() == 1.0)
{
new ProgressBarTimer().start();
}
lastProgress = progress;
}
}
/**
* Waits 1 second and removes the progress bar from the main panel.
*/
@ -387,11 +407,12 @@ private class DatesLoader extends Thread
{
public void run()
{
Collection<EventObject> msgList = null;
Collection<Object> msgList = null;
if (historyContact instanceof MetaContact)
{
msgList = msgHistory.findByEndDate(
msgList = history.findByEndDate(
historyFilter,
(MetaContact) historyContact,
new Date(System.currentTimeMillis()));
}
@ -403,13 +424,14 @@ else if(historyContact instanceof ChatRoomWrapper)
if(chatRoomWrapper.getChatRoom() == null)
return;
msgList = msgHistory.findByEndDate(
msgList = history.findByEndDate(
historyFilter,
chatRoomWrapper.getChatRoom(),
new Date(System.currentTimeMillis()));
}
if (msgList != null)
for (EventObject o : msgList)
for (Object o : msgList)
{
long date = 0;
@ -435,13 +457,18 @@ else if (o instanceof ChatRoomMessageDeliveredEvent)
evt = (ChatRoomMessageDeliveredEvent) o;
date = evt.getTimestamp();
}
else if (o instanceof FileRecord)
{
FileRecord fileRecord = (FileRecord) o;
date = fileRecord.getDate();
}
boolean containsDate = false;
long milisecondsPerDay = 24*60*60*1000;
for(int j = 0; !containsDate && j < datesVector.size(); j ++)
{
Date date1 = datesVector.get(j);
containsDate = Math.floor(date1.getTime()/milisecondsPerDay)
== Math.floor(date/milisecondsPerDay);
}
@ -451,7 +478,7 @@ else if (o instanceof ChatRoomMessageDeliveredEvent)
datesVector.add(new Date(date - date % milisecondsPerDay));
}
}
if((msgList != null) && (msgList.size() > 0))
{
Runnable updateDatesPanel = new Runnable() {
@ -498,12 +525,14 @@ public MessagesLoader (Date startDate, Date endDate)
public void run()
{
final Collection<EventObject> msgList;
final Collection<Object> msgList;
if(historyContact instanceof MetaContact)
{
msgList = msgHistory.findByPeriod(
(MetaContact) historyContact, startDate, endDate);
msgList = history.findByPeriod(
historyFilter,
(MetaContact) historyContact,
startDate, endDate);
}
else if (historyContact instanceof ChatRoomWrapper)
{
@ -513,8 +542,10 @@ else if (historyContact instanceof ChatRoomWrapper)
if(chatRoomWrapper.getChatRoom() == null)
return;
msgList = msgHistory.findByPeriod(
chatRoomWrapper.getChatRoom(), startDate, endDate);
msgList = history.findByPeriod(
historyFilter,
chatRoomWrapper.getChatRoom(),
startDate, endDate);
}
else
msgList = null;
@ -556,11 +587,12 @@ public KeywordDatesLoader(String keyword)
public void run()
{
Collection<EventObject> msgList = null;
Collection<Object> msgList = null;
if (historyContact instanceof MetaContact)
{
msgList = msgHistory.findByKeyword(
msgList = history.findByKeyword(
historyFilter,
(MetaContact) historyContact, keyword);
}
else if (historyContact instanceof ChatRoomWrapper)
@ -571,7 +603,8 @@ else if (historyContact instanceof ChatRoomWrapper)
if (chatRoomWrapper.getChatRoom() == null)
return;
msgList = msgHistory.findByKeyword(
msgList = history.findByKeyword(
historyFilter,
chatRoomWrapper.getChatRoom(), keyword);
}

@ -18,7 +18,9 @@ Import-Package: org.osgi.framework,
net.java.sip.communicator.service.gui.event,
net.java.sip.communicator.service.keybindings,
net.java.sip.communicator.service.msghistory,
net.java.sip.communicator.service.msghistory.event,
net.java.sip.communicator.service.filehistory,
net.java.sip.communicator.service.metahistory,
net.java.sip.communicator.service.history.event,
net.java.sip.communicator.service.notification,
net.java.sip.communicator.service.protocol,
net.java.sip.communicator.service.protocol.icqconstants,

@ -8,6 +8,8 @@
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
@ -24,6 +26,8 @@
public class FileImageLabel
extends FileDragLabel
{
private static final Logger logger = Logger.getLogger(FileImageLabel.class);
private ImageIcon tooltipIcon;
private String tooltipTitle;
@ -71,6 +75,18 @@ public JToolTip createToolTip()
return tip;
}
/**
* Sets the file associated with this file drag label.
*
* @param file the file associated with this file drag label
*/
public void setFile(File file)
{
super.setFile(file);
setFileIcon(file);
}
/**
* Returns the string to be used as the tooltip for <i>event</i>. We
* don't really use this string, but we need to return different string
@ -86,4 +102,41 @@ public String getToolTipText(MouseEvent event)
return "";
}
/**
* Sets the icon for the given file.
*
* @param file the file to set an icon for
*/
private void setFileIcon(File file)
{
if (FileUtils.isImage(file.getName()))
{
try
{
ImageIcon image = new ImageIcon(file.toURI().toURL());
this.setToolTipImage(image);
image = ImageUtils
.getScaledRoundedIcon(image.getImage(), 64, 64);
this.setIcon(image);
}
catch (MalformedURLException e)
{
logger.debug("Could not locate image.", e);
this.setIcon(new ImageIcon(
ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON)));
}
}
else
{
Icon icon = FileUtils.getIcon(file);
if (icon == null)
icon = new ImageIcon(
ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON));
this.setIcon(icon);
}
}
}

@ -13,7 +13,6 @@
import net.java.sip.communicator.service.callhistory.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.filehistory.*;
import net.java.sip.communicator.service.history.HistoryReader;
import net.java.sip.communicator.service.metahistory.*;
import net.java.sip.communicator.service.msghistory.*;
import net.java.sip.communicator.service.history.event.*;

@ -11,4 +11,9 @@ Import-Package: org.osgi.framework,
net.java.sip.communicator.util,
net.java.sip.communicator.service.protocol,
net.java.sip.communicator.service.protocol.event,
net.java.sip.communicator.service.msghistory,
net.java.sip.communicator.service.msghistory.event,
net.java.sip.communicator.service.callhistory,
net.java.sip.communicator.service.filehistory,
net.java.sip.communicator.service.contactlist
Export-Package: net.java.sip.communicator.service.metahistory

@ -8,11 +8,14 @@
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.util.*;
/**

Loading…
Cancel
Save