mirror of https://github.com/sipwise/jitsi.git
parent
918a8ec7c0
commit
13b5466ee0
@ -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 + ")";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue