File transfer related changes as follows:

- show transfer speed and estimated transfer time.
 - introduced new event that notifies the gui when a file transfer request has been cancelled by the sender.
cusax-fix
Yana Stamcheva 17 years ago
parent fba5784542
commit 41f655c482

@ -136,6 +136,7 @@ service.gui.EMPTY_HISTORY=&Empty history
service.gui.ENABLE_TYPING_NOTIFICATIONS=Enable &typing notifications
service.gui.ENTER_PHONE_NUMBER=Enter phone number
service.gui.ERROR=Error
service.gui.ESTIMATED_TIME=Estimated time:
service.gui.EXIT=E&xit
service.gui.EXTENDED_CRITERIA=Extended criteria
service.gui.GENERAL=General
@ -366,6 +367,7 @@ service.gui.TRANSFER_BUTTON_TOOL_TIP=Transfer Call
service.gui.SECURITY_INFO=Security information
service.gui.SECURITY_WARNING=Security warning
service.gui.SECURITY_ERROR=Security error
service.gui.SPEED=Speed:
service.gui.JANUARY=Jan
service.gui.FEBRUARY=Feb

@ -833,6 +833,10 @@ public void fileTransferRequestRejected(FileTransferRequestEvent event)
}
}
public void fileTransferRequestCanceled(FileTransferRequestEvent event)
{
}
/**
* Used to compare FileRecords
* and to be ordered in TreeSet according their timestamp

@ -1693,13 +1693,15 @@ public void setChatSubject(String subject)
* @param date the date on which the request has been received
*/
public void addIncomingFileTransferRequest(
OperationSetFileTransfer fileTransferOpSet,
IncomingFileTransferRequest request,
Date date)
{
this.addActiveFileTransfer(request.getID(), request);
ReceiveFileConversationComponent component
= new ReceiveFileConversationComponent(this, request, date);
= new ReceiveFileConversationComponent(
this, fileTransferOpSet, request, date);
if (ConfigurationManager.isHistoryShown() && !isHistoryLoaded)
{

@ -77,15 +77,4 @@ public void updateChatContactStatus(ChatContact chatContact,
* @param subject the new subject to set.
*/
public void setChatSubject(String subject);
/**
* Adds the given <tt>IncomingFileTransferRequest</tt> to the conversation
* panel in order to notify the user of the incoming file.
*
* @param request the request to display in the conversation panel
* @param date the date on which the request has been received
*/
public void addIncomingFileTransferRequest(
IncomingFileTransferRequest request,
Date date);
}

@ -19,6 +19,7 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.swing.*;
/**
* The <tt>FileTransferConversationComponent</tt> is the parent of all file
@ -58,10 +59,27 @@ public abstract class FileTransferConversationComponent
protected final JProgressBar progressBar = new JProgressBar();
private final TransparentPanel progressPropertiesPanel
= new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
private final JLabel progressSpeedLabel = new JLabel();
private final JLabel estimatedTimeLabel = new JLabel();
private File downloadFile;
private FileTransfer fileTransfer;
private long lastSpeedTimestamp = 0;
private long lastEstimatedTimeTimestamp = 0;
private long lastTransferredBytes = 0;
private long lastProgressSpeed;
private long lastEstimatedTime;
/**
* Creates a file conversation component.
*/
@ -80,7 +98,7 @@ public FileTransferConversationComponent()
constraints.gridx = 1;
constraints.gridy = 0;
constraints.gridwidth = 2;
constraints.gridwidth = 3;
constraints.gridheight = 1;
constraints.fill=GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
@ -99,6 +117,7 @@ public FileTransferConversationComponent()
constraints.gridx = 1;
constraints.gridy = 2;
constraints.gridwidth = 1;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.NONE;
@ -108,6 +127,7 @@ public FileTransferConversationComponent()
constraints.gridx = 2;
constraints.gridy = 2;
constraints.gridwidth = 2;
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.fill = GridBagConstraints.HORIZONTAL;
@ -145,6 +165,36 @@ public FileTransferConversationComponent()
cancelButton.addActionListener(this);
cancelButton.setVisible(false);
constraints.gridx = 2;
constraints.gridy = 3;
constraints.gridwidth = GridBagConstraints.RELATIVE;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.EAST;
constraints.insets = new Insets(0, 5, 0, 5);
constraints.gridx = 3;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0.0;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.LINE_END;
constraints.insets = new Insets(0, 5, 0, 5);
add(progressPropertiesPanel, constraints);
estimatedTimeLabel.setFont(
estimatedTimeLabel.getFont().deriveFont(11f));
estimatedTimeLabel.setVisible(false);
progressSpeedLabel.setFont(
progressSpeedLabel.getFont().deriveFont(11f));
progressSpeedLabel.setVisible(false);
progressPropertiesPanel.add(progressSpeedLabel);
progressPropertiesPanel.add(estimatedTimeLabel);
constraints.gridx = 1;
constraints.gridy = 3;
constraints.gridwidth = 1;
@ -206,7 +256,7 @@ public FileTransferConversationComponent()
constraints.gridx = 1;
constraints.gridy = 2;
constraints.gridwidth = 2;
constraints.gridwidth = 3;
constraints.gridheight = 1;
constraints.weightx = 1.0;
constraints.anchor = GridBagConstraints.WEST;
@ -402,10 +452,48 @@ public void progressChanged(FileTransferProgressEvent event)
{
progressBar.setValue((int) event.getProgress());
long transferredBytes = event.getFileTransfer().getTransferedBytes();
long progressTimestamp = event.getTimestamp();
ByteFormat format = new ByteFormat();
String bytesString = format.format(
event.getFileTransfer().getTransferedBytes());
String bytesString = format.format(transferredBytes);
if ((progressTimestamp - lastSpeedTimestamp) >= 5000)
{
lastProgressSpeed
= Math.round(calculateProgressSpeed(transferredBytes));
this.lastSpeedTimestamp = progressTimestamp;
this.lastTransferredBytes = transferredBytes;
}
if ((progressTimestamp - lastEstimatedTimeTimestamp) >= 5000
&& lastProgressSpeed > 0)
{
lastEstimatedTime = Math.round(calculateEstimatedTransferTime(
lastProgressSpeed,
event.getFileTransfer().getFile().length() - transferredBytes));
lastEstimatedTimeTimestamp = progressTimestamp;
}
progressBar.setString(getProgressLabel(bytesString));
if (lastProgressSpeed > 0)
{
progressSpeedLabel.setText(
resources.getI18NString("service.gui.SPEED")
+ format.format(lastProgressSpeed));
progressSpeedLabel.setVisible(true);
}
if (lastEstimatedTime > 0)
{
estimatedTimeLabel.setText(
resources.getI18NString("service.gui.ESTIMATED_TIME")
+ GuiUtils.formatSeconds(lastEstimatedTime*1000));
estimatedTimeLabel.setVisible(true);
}
}
/**
@ -440,6 +528,16 @@ protected String getFileLabel(String fileName, long fileSize)
return fileName + " (" + text + ")";
}
/**
* Hides all progress related components.
*/
protected void hideProgressRelatedComponents()
{
progressBar.setVisible(false);
progressSpeedLabel.setVisible(false);
estimatedTimeLabel.setVisible(false);
}
/**
* Returns the label to show on the progress bar.
*
@ -447,4 +545,29 @@ protected String getFileLabel(String fileName, long fileSize)
* @return the label to show on the progress bar
*/
protected abstract String getProgressLabel(String bytesString);
/**
* Returns the speed of the transfer.
*
* @param progressTimestamp the time indicating when the progress event
* occured.
* @param transferredBytes the number of bytes that have been transferred
* @return the speed of the transfer
*/
private double calculateProgressSpeed(long transferredBytes)
{
// Bytes per second = bytes per 5000 miliseconds * 1000.
return (transferredBytes - lastTransferredBytes) / 5;
}
/**
*
* @param speed
* @param fileSize
* @return
*/
private double calculateEstimatedTransferTime(double speed, long bytesLeft)
{
return bytesLeft / speed;
}
}

@ -27,13 +27,16 @@
public class ReceiveFileConversationComponent
extends FileTransferConversationComponent
implements ActionListener,
FileTransferStatusListener
FileTransferStatusListener,
FileTransferListener
{
private final Logger logger
= Logger.getLogger(ReceiveFileConversationComponent.class);
private final IncomingFileTransferRequest fileTransferRequest;
private final OperationSetFileTransfer fileTransferOpSet;
private final ChatPanel chatPanel;
private final Date date;
@ -48,14 +51,18 @@ public class ReceiveFileConversationComponent
*/
public ReceiveFileConversationComponent(
ChatPanel chatPanel,
final OperationSetFileTransfer opSet,
final IncomingFileTransferRequest request,
final Date date)
{
this.chatPanel = chatPanel;
this.fileTransferOpSet = opSet;
this.fileTransferRequest = request;
this.date = date;
this.dateString = getDateString(date);
fileTransferOpSet.addFileTransferListener(this);
titleLabel.setText(
dateString
+ resources.getI18NString(
@ -176,7 +183,8 @@ public void statusChanged(FileTransferStatusChangeEvent event)
if (status == FileTransferStatusChangeEvent.PREPARING)
{
progressBar.setVisible(false);
hideProgressRelatedComponents();
titleLabel.setText(
dateString
+ resources.getI18NString(
@ -185,7 +193,8 @@ public void statusChanged(FileTransferStatusChangeEvent event)
}
else if (status == FileTransferStatusChangeEvent.FAILED)
{
progressBar.setVisible(false);
hideProgressRelatedComponents();
titleLabel.setText(
dateString
+ resources.getI18NString(
@ -212,8 +221,9 @@ else if (status == FileTransferStatusChangeEvent.COMPLETED)
{
this.setCompletedDownloadFile(fileTransfer.getFile());
progressBar.setVisible(false);
hideProgressRelatedComponents();
cancelButton.setVisible(false);
openFileButton.setVisible(true);
openFolderButton.setVisible(true);
@ -225,7 +235,8 @@ else if (status == FileTransferStatusChangeEvent.COMPLETED)
}
else if (status == FileTransferStatusChangeEvent.CANCELED)
{
progressBar.setVisible(false);
hideProgressRelatedComponents();
cancelButton.setVisible(false);
titleLabel.setText(
@ -236,7 +247,8 @@ else if (status == FileTransferStatusChangeEvent.CANCELED)
}
else if (status == FileTransferStatusChangeEvent.REFUSED)
{
progressBar.setVisible(false);
hideProgressRelatedComponents();
titleLabel.setText(
dateString
+ resources.getI18NString(
@ -245,6 +257,7 @@ else if (status == FileTransferStatusChangeEvent.REFUSED)
cancelButton.setVisible(false);
openFileButton.setVisible(false);
openFolderButton.setVisible(false);
setWarningStyle(true);
}
}
@ -279,6 +292,11 @@ public Object construct()
chatPanel.addActiveFileTransfer(fileTransfer.getID(), fileTransfer);
// Remove previously added listener, that notified us for request
// cancellations.
fileTransferOpSet.removeFileTransferListener(
ReceiveFileConversationComponent.this);
// Add the status listener that would notify us when the file
// transfer has been completed and should be removed from
// active components.
@ -310,4 +328,31 @@ protected String getProgressLabel(String bytesString)
return bytesString
+ " " + resources.getI18NString("service.gui.RECEIVED");
}
public void fileTransferCreated(FileTransferCreatedEvent event)
{}
public void fileTransferRequestCanceled(FileTransferRequestEvent event)
{
IncomingFileTransferRequest request = event.getRequest();
if (request.equals(fileTransferRequest))
{
acceptButton.setVisible(false);
rejectButton.setVisible(false);
titleLabel.setText(
dateString
+ resources.getI18NString(
"service.gui.FILE_TRANSFER_CANCELED"));
setWarningStyle(true);
}
}
public void fileTransferRequestReceived(FileTransferRequestEvent event)
{}
public void fileTransferRequestRejected(FileTransferRequestEvent event)
{}
}

@ -108,7 +108,7 @@ public void statusChanged(FileTransferStatusChangeEvent event)
if (status == FileTransferStatusChangeEvent.PREPARING)
{
progressBar.setVisible(false);
hideProgressRelatedComponents();
titleLabel.setText(
dateString
+ resources.getI18NString(
@ -119,7 +119,8 @@ public void statusChanged(FileTransferStatusChangeEvent event)
}
else if (status == FileTransferStatusChangeEvent.FAILED)
{
progressBar.setVisible(false);
hideProgressRelatedComponents();
titleLabel.setText(
dateString
+ resources.getI18NString(
@ -145,7 +146,8 @@ else if (status == FileTransferStatusChangeEvent.IN_PROGRESS)
}
else if (status == FileTransferStatusChangeEvent.COMPLETED)
{
progressBar.setVisible(false);
hideProgressRelatedComponents();
titleLabel.setText(
dateString
+ resources.getI18NString(
@ -156,7 +158,8 @@ else if (status == FileTransferStatusChangeEvent.COMPLETED)
}
else if (status == FileTransferStatusChangeEvent.CANCELED)
{
progressBar.setVisible(false);
hideProgressRelatedComponents();
titleLabel.setText(
dateString
+ resources.getI18NString(
@ -167,7 +170,8 @@ else if (status == FileTransferStatusChangeEvent.CANCELED)
}
else if (status == FileTransferStatusChangeEvent.REFUSED)
{
progressBar.setVisible(false);
hideProgressRelatedComponents();
titleLabel.setText(
dateString
+ resources.getI18NString(

@ -216,16 +216,6 @@ public void protocolContactClicked(ContactListEvent evt)
contactHandler.contactClicked(protoContact, evt.getClickCount());
}
/**
* Called when a new <tt>IncomingFileTransferRequest</tt> has been rejected.
*
* @param event the <tt>FileTransferRequestEvent</tt> containing the
* received request which was rejected.
*/
public void fileTransferRequestRejected(FileTransferRequestEvent event)
{
}
/**
* Runs the chat window for the specified contact. We examine different
* cases here, depending on the chat window mode.
@ -463,32 +453,33 @@ public void messageDeliveryFailed(MessageDeliveryFailedEvent evt)
.findMetaContactByContact(sourceContact);
if (evt.getErrorCode()
== MessageDeliveryFailedEvent.OFFLINE_MESSAGES_NOT_SUPPORTED) {
== MessageDeliveryFailedEvent.OFFLINE_MESSAGES_NOT_SUPPORTED)
{
errorMsg = GuiActivator.getResources().getI18NString(
"service.gui.MSG_DELIVERY_NOT_SUPPORTED");
}
else if (evt.getErrorCode()
== MessageDeliveryFailedEvent.NETWORK_FAILURE) {
== MessageDeliveryFailedEvent.NETWORK_FAILURE)
{
errorMsg = GuiActivator.getResources().getI18NString(
"service.gui.MSG_NOT_DELIVERED",
new String[]{evt.getReason()});
}
else if (evt.getErrorCode()
== MessageDeliveryFailedEvent.PROVIDER_NOT_REGISTERED) {
== MessageDeliveryFailedEvent.PROVIDER_NOT_REGISTERED)
{
errorMsg = GuiActivator.getResources().getI18NString(
"service.gui.MSG_SEND_CONNECTION_PROBLEM");
}
else if (evt.getErrorCode()
== MessageDeliveryFailedEvent.INTERNAL_ERROR) {
== MessageDeliveryFailedEvent.INTERNAL_ERROR)
{
errorMsg = GuiActivator.getResources().getI18NString(
"service.gui.MSG_DELIVERY_INTERNAL_ERROR",
new String[]{evt.getReason()});
}
else {
else
{
errorMsg = GuiActivator.getResources().getI18NString(
"service.gui.MSG_DELIVERY_UNKNOWN_ERROR",
new String[]{evt.getReason()});
@ -596,7 +587,8 @@ public void fileTransferRequestReceived(FileTransferRequestEvent event)
final ChatPanel chatPanel = chatWindowManager
.getContactChat(metaContact, sourceContact);
chatPanel.addIncomingFileTransferRequest(request, event.getTimestamp());
chatPanel.addIncomingFileTransferRequest(
event.getFileTransferOperationSet(), request, event.getTimestamp());
ChatTransport chatTransport
= chatPanel.getChatSession()
@ -632,6 +624,28 @@ public void run()
public void fileTransferCreated(FileTransferCreatedEvent event)
{}
/**
* Called when a new <tt>IncomingFileTransferRequest</tt> has been rejected.
* Nothing to do here, because we are the one who rejects the request.
*
* @param event the <tt>FileTransferRequestEvent</tt> containing the
* received request which was rejected.
*/
public void fileTransferRequestRejected(FileTransferRequestEvent event)
{
}
/**
* Called when an <tt>IncomingFileTransferRequest</tt> has been canceled
* from the contact who sent it.
*
* @param event the <tt>FileTransferRequestEvent</tt> containing the
* request which was canceled.
*/
public void fileTransferRequestCanceled(FileTransferRequestEvent event)
{
}
/**
* Send a proactive notification according to the proactive timer.
* The notification is fired only if another notification hasn't been
@ -742,7 +756,8 @@ public void actionPerformed(ActionEvent e)
{
Object selectedValue = contactList.getSelectedValue();
if (selectedValue instanceof MetaContact) {
if (selectedValue instanceof MetaContact)
{
MetaContact contact = (MetaContact) selectedValue;
SwingUtilities.invokeLater(new RunMessageWindow(contact));

@ -163,7 +163,7 @@ public void rejectFile()
fileTransferRequest.reject();
fileTransferOpSet.fireFileTransferRequestRejected(
new FileTransferRequestEvent(this, this.date));
new FileTransferRequestEvent(fileTransferOpSet, this, this.date));
}
/**

@ -273,8 +273,10 @@ public void fileTransferRequest(FileTransferRequest request)
// Create an event associated to this global request.
FileTransferRequestEvent fileTransferRequestEvent
= new FileTransferRequestEvent( incomingFileTransferRequest,
requestDate);
= new FileTransferRequestEvent(
OperationSetFileTransferJabberImpl.this,
incomingFileTransferRequest,
requestDate);
// Notify the global listener that a request has arrived.
fireFileTransferRequest(fileTransferRequestEvent);
@ -403,7 +405,8 @@ public void run()
}
fileTransfer.fireStatusChangeEvent(status);
fileTransfer.fireProgressChangeEvent((int)progress);
fileTransfer.fireProgressChangeEvent(
System.currentTimeMillis(), (int) progress);
}
catch (InterruptedException e)
{
@ -419,7 +422,8 @@ public void run()
}
fileTransfer.fireStatusChangeEvent(status);
fileTransfer.fireProgressChangeEvent((int)progress);
fileTransfer.fireProgressChangeEvent(
System.currentTimeMillis(), (int) progress);
}
}

@ -84,56 +84,57 @@ public void receiveFile(final File file,
fireFileTransferRequest(
new FileTransferRequestEvent(
this,
new IncomingFileTransferRequest()
{
public String getID()
{
return id;
}
public String getFileName()
{
return file.getName();
}
public String getFileDescription()
{
return file.toString();
}
public long getFileSize()
{
return file.length();
}
public Contact getSender()
{
return from;
}
public FileTransfer acceptFile(File file)
{
MockFileTransferImpl fileTrans =
new MockFileTransferImpl(
from,
file,
id,
FileTransfer.IN);
fireFileTransferCreated(
new FileTransferCreatedEvent(fileTrans, requestDate));
changeFileTransferStatus(fileTrans,
FileTransferStatusChangeEvent.PREPARING);
return fileTrans;
}
public void rejectFile()
{
}
}, requestDate));
{
public String getID()
{
return id;
}
public String getFileName()
{
return file.getName();
}
public String getFileDescription()
{
return file.toString();
}
public long getFileSize()
{
return file.length();
}
public Contact getSender()
{
return from;
}
public FileTransfer acceptFile(File file)
{
MockFileTransferImpl fileTrans =
new MockFileTransferImpl(
from,
file,
id,
FileTransfer.IN);
fireFileTransferCreated(
new FileTransferCreatedEvent(fileTrans, requestDate));
changeFileTransferStatus(fileTrans,
FileTransferStatusChangeEvent.PREPARING);
return fileTrans;
}
public void rejectFile()
{
}
}, requestDate));
}
/**

@ -163,7 +163,8 @@ public void rejectFile()
yahooProvider.getYahooSession().fileTransferReject(id);
fileTransferOpSet.fireFileTransferRequestRejected(
new FileTransferRequestEvent(this, this.getDate()));
new FileTransferRequestEvent(
fileTransferOpSet, this, this.getDate()));
}
/**

@ -313,8 +313,7 @@ public void fileTransferRequestReceived(SessionFileTransferEvent ev)
activeFileTransfers.put(ev.getId(), req);
fireFileTransferRequest(
new FileTransferRequestEvent(req, recvDate));
new FileTransferRequestEvent(this, req, recvDate));
}
}
@ -344,7 +343,7 @@ public void statusChanged(SessionFileTransferEvent ev)
IncomingFileTransferRequestYahooImpl req =
(IncomingFileTransferRequestYahooImpl)ftObj;
fireFileTransferRequestRejected(
new FileTransferRequestEvent(req, req.getDate()));
new FileTransferRequestEvent(this, req, req.getDate()));
return;
}
}
@ -365,7 +364,8 @@ public void statusChanged(SessionFileTransferEvent ev)
FileTransferStatusChangeEvent.IN_PROGRESS);
ft.setTransferedBytes(ev.getProgress());
ft.fireProgressChangeEvent((int)ev.getProgress());
ft.fireProgressChangeEvent(
System.currentTimeMillis(), (int)ev.getProgress());
}
else
ft.fireStatusChangeEvent(getStateMapping(newState));

@ -159,7 +159,7 @@ public void fireStatusChangeEvent(int newStatus)
* Notifies all status listeners that a new
* <tt>FileTransferProgressEvent</tt> occured.
*/
public void fireProgressChangeEvent(int progress)
public void fireProgressChangeEvent(long timestamp, int progress)
{
Collection<FileTransferProgressListener> listeners = null;
synchronized (progressListeners)
@ -169,7 +169,7 @@ public void fireProgressChangeEvent(int progress)
}
FileTransferProgressEvent progressEvent
= new FileTransferProgressEvent(this, progress);
= new FileTransferProgressEvent(this, timestamp, progress);
Iterator<FileTransferProgressListener> listenersIter
= listeners.iterator();

@ -35,10 +35,19 @@ public interface FileTransferListener
public void fileTransferCreated(FileTransferCreatedEvent event);
/**
* Called when a new <tt>IncomingFileTransferRequest</tt> has been rejected.
* Called when an <tt>IncomingFileTransferRequest</tt> has been rejected.
*
* @param event the <tt>FileTransferRequestEvent</tt> containing the
* received request which was rejected.
*/
public void fileTransferRequestRejected(FileTransferRequestEvent event);
/**
* Called when an <tt>IncomingFileTransferRequest</tt> has been canceled
* from the contact who sent it.
*
* @param event the <tt>FileTransferRequestEvent</tt> containing the
* request which was canceled.
*/
public void fileTransferRequestCanceled(FileTransferRequestEvent event);
}

@ -24,6 +24,11 @@ public class FileTransferProgressEvent
*/
private int progress;
/**
* Indicates when this event occured.
*/
private long timestamp;
/**
* Creates a <tt>FileTransferProgressEvent</tt> by specifying the source
* file transfer object, that triggered the event and the new progress
@ -31,13 +36,16 @@ public class FileTransferProgressEvent
*
* @param fileTransfer the source file transfer object, that triggered the
* event
* @param timestamp when this event occured
* @param progress the new progress value
*/
public FileTransferProgressEvent( FileTransfer fileTransfer,
long timestamp,
int progress)
{
super(fileTransfer);
this.timestamp = timestamp;
this.progress = progress;
}
@ -60,4 +68,14 @@ public int getProgress()
{
return progress;
}
/**
* Returns the timestamp when this event initially occured.
*
* @return the timestamp when this event initially occured
*/
public long getTimestamp()
{
return timestamp;
}
}

@ -20,6 +20,11 @@
public class FileTransferRequestEvent
extends EventObject
{
/**
* The request that triggered this event.
*/
private final IncomingFileTransferRequest request;
/**
* The timestamp indicating the exact date when the event occurred.
*/
@ -29,19 +34,34 @@ public class FileTransferRequestEvent
* Creates a <tt>FileTransferRequestEvent</tt> representing reception
* of an incoming file transfer request.
*
* @param the operation set, where this event initially occurred
* @param request the <tt>IncomingFileTranferRequest</tt> whose reception
* this event represents.
* @param timestamp the timestamp indicating the exact date when the event
* occurred
*/
public FileTransferRequestEvent(IncomingFileTransferRequest request,
public FileTransferRequestEvent(OperationSetFileTransfer fileTransferOpSet,
IncomingFileTransferRequest request,
Date timestamp)
{
super(request);
super(fileTransferOpSet);
this.request = request;
this.timestamp = timestamp;
}
/**
* Returns the <tt>OperationSetFileTransfer</tt>, where this event initially
* occurred.
*
* @return the <tt>OperationSetFileTransfer</tt>, where this event initially
* occurred
*/
public OperationSetFileTransfer getFileTransferOperationSet()
{
return (OperationSetFileTransfer) getSource();
}
/**
* Returns the incoming file transfer request that triggered this event.
*
@ -50,7 +70,7 @@ public FileTransferRequestEvent(IncomingFileTransferRequest request,
*/
public IncomingFileTransferRequest getRequest()
{
return (IncomingFileTransferRequest) getSource();
return request;
}
/**

@ -61,22 +61,26 @@ public StringBuffer format(Object obj, StringBuffer buf, FieldPosition pos)
if (obj instanceof Long)
{
long numBytes = (Long) obj;
if (numBytes < 1024) {
if (numBytes < 1024)
{
DecimalFormat formatter = new DecimalFormat("#,##0");
buf.append(formatter.format((double)numBytes)).append(" bytes");
}
else if (numBytes < 1024 * 1024) {
else if (numBytes < 1024 * 1024)
{
DecimalFormat formatter = new DecimalFormat("#,##0.0");
buf.append(
formatter.format((double)numBytes / 1024.0)).append(" K");
}
else if (numBytes < 1024 * 1024 * 1024) {
else if (numBytes < 1024 * 1024 * 1024)
{
DecimalFormat formatter = new DecimalFormat("#,##0.0");
buf.append(
formatter.format((double)numBytes / (1024.0 * 1024.0)))
.append(" MB");
}
else {
else
{
DecimalFormat formatter = new DecimalFormat("#,##0.0");
buf.append(
formatter.format(

@ -21,9 +21,27 @@
public class GuiUtils
{
private static Calendar c1 = Calendar.getInstance();
private static Calendar c2 = Calendar.getInstance();
/**
* Number of milliseconds in a second.
*/
public static final long MILLIS_PER_SECOND = 1000;
/**
* Number of milliseconds in a standard minute.
*/
public static final long MILLIS_PER_MINUTE = 60 * MILLIS_PER_SECOND;
/**
* Number of milliseconds in a standard hour.
*/
public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
/**
* Number of milliseconds in a standard day.
*/
public static final long MILLIS_PER_DAY = 24 * MILLIS_PER_HOUR;
/**
* Replaces some chars that are special in a regular expression.
* @param text The initial text.
@ -95,7 +113,7 @@ public static String formatDate(Date date)
* @param date the date to format
* @return the formatted date string
*/
public static String formatDate(long date)
public static String formatDate(final long date)
{
c1.setTimeInMillis(date);
@ -249,4 +267,48 @@ private static String formatTime(int time)
return (timeString.length() < 2) ? "0".concat(timeString) : timeString;
}
/**
* Formats the given long to X hour, Y min, Z sec.
*/
public static String formatSeconds(long millis)
{
long[] values = new long[4];
values[0] = millis / MILLIS_PER_DAY;
values[1] = (millis / MILLIS_PER_HOUR) % 24;
values[2] = (millis / MILLIS_PER_MINUTE) % 60;
values[3] = (millis / MILLIS_PER_SECOND) % 60;
String[] fields = { " d ", " h ", " min ", " sec" };
StringBuffer buf = new StringBuffer(64);
boolean valueOutput = false;
for (int i = 0; i < 4; i++)
{
long value = values[i];
if (value == 0)
{
// handle zero
if (valueOutput)
{
buf.append('0').append(fields[i]);
}
}
else if (value == 1)
{
// one
valueOutput = true;
buf.append('1').append(fields[i]);
}
else
{
// other
valueOutput = true;
buf.append(value).append(fields[i]);
}
}
return buf.toString().trim();
}
}

@ -1006,5 +1006,8 @@ public void fileTransferRequestRejected(FileTransferRequestEvent event)
{
}
public void fileTransferRequestCanceled(FileTransferRequestEvent event)
{
}
}
}

@ -842,6 +842,10 @@ public void fileTransferRequestRejected(FileTransferRequestEvent event)
}
}
public void fileTransferRequestCanceled(FileTransferRequestEvent event)
{
}
public void clear()
{
collectedEvents.clear();

Loading…
Cancel
Save