mirror of
https://github.com/xfarrow/guify.git
synced 2025-02-17 12:30:45 +01:00
Improvements
1) The Queue does not get updated each time a chunk of data gets transferred, but only after a certain amount of time has passed (1/100th of a second) 2) Improved desktop's scroll behaviour
This commit is contained in:
parent
b39d82a671
commit
ad4d91708d
@ -18,8 +18,10 @@ public class QueueController implements Observer{
|
||||
*/
|
||||
|
||||
private IQueueFrame frame;
|
||||
// Accessed only through the EDT, so no need to use ConcurrentHashMap
|
||||
private HashMap<TransferProgress, Integer> indexHashMap = new HashMap<>();
|
||||
|
||||
private long lastGuiExecutionTime = 0;
|
||||
private static final long THROTTLE_TIME_MS = 10; // 10ms = 1/100th of second
|
||||
/*
|
||||
* ========== END Attributes ==========
|
||||
*/
|
||||
@ -47,16 +49,22 @@ public class QueueController implements Observer{
|
||||
}
|
||||
}
|
||||
|
||||
// Executed by different threads
|
||||
// Executed on different threads
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
TransferProgress transferProgress = (TransferProgress)arg;
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
frame.manageTransferProgress(transferProgress);
|
||||
}
|
||||
});
|
||||
|
||||
// Do not invoke the Event Dispatch Thread too frequently as
|
||||
// it may impact the performance of low-end computer systems.
|
||||
if(System.currentTimeMillis() - lastGuiExecutionTime >= THROTTLE_TIME_MS || transferProgress.getTransferStatus() == TransferProgress.END) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
frame.manageTransferProgress(transferProgress);
|
||||
lastGuiExecutionTime = System.currentTimeMillis();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public int computePercentage(TransferProgress transferProgress) {
|
||||
|
@ -98,6 +98,7 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setBounds(156, 36, 1098, 634);
|
||||
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
scrollPane.getVerticalScrollBar().setUnitIncrement(25);
|
||||
getContentPane().add(scrollPane);
|
||||
|
||||
desktopPanel = new JPanel();
|
||||
|
@ -91,41 +91,22 @@ public class Queue extends JFrame implements IQueueFrame {
|
||||
@Override
|
||||
public void manageTransferProgress(TransferProgress transferProgress) {
|
||||
|
||||
if(transferProgress.getTransferStatus() == TransferProgress.INIT) {
|
||||
if(!controller.isTransferProgressInHashMap(transferProgress)) {
|
||||
controller.putTableIndex(transferProgress,
|
||||
addRow(transferProgress.getSource(),
|
||||
transferProgress.getDestination(),
|
||||
transferProgress.getOperation() == SftpProgressMonitor.GET? "Download" : "Upload",
|
||||
0));
|
||||
}
|
||||
}
|
||||
// Remember that when QueueController calls frame.manageTransferProgress(transferProgress),
|
||||
// here transferProgress might have a different status (as it's updated by a different thread).
|
||||
// We do not need a lock as we do not edit it, but just keep it in mind.
|
||||
|
||||
else if(transferProgress.getTransferStatus() == TransferProgress.UPDATING) {
|
||||
if(!controller.isTransferProgressInHashMap(transferProgress)) {
|
||||
controller.putTableIndex(transferProgress,
|
||||
addRow(transferProgress.getSource(),
|
||||
transferProgress.getDestination(),
|
||||
transferProgress.getOperation() == SftpProgressMonitor.GET? "Download" : "Upload",
|
||||
controller.computePercentage(transferProgress)));
|
||||
}
|
||||
else {
|
||||
if(!controller.isTransferProgressInHashMap(transferProgress)) {
|
||||
controller.putTableIndex(transferProgress,
|
||||
addRow(transferProgress.getSource(),
|
||||
transferProgress.getDestination(),
|
||||
transferProgress.getOperation() == SftpProgressMonitor.GET? "Download" : "Upload",
|
||||
controller.computePercentage(transferProgress)));
|
||||
}
|
||||
else {
|
||||
if(transferProgress.getTransferStatus() != TransferProgress.INIT) {
|
||||
updateRow(controller.getTableIndex(transferProgress), controller.computePercentage(transferProgress));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else if(transferProgress.getTransferStatus() == TransferProgress.END) {
|
||||
if(!controller.isTransferProgressInHashMap(transferProgress)) {
|
||||
controller.putTableIndex(transferProgress,
|
||||
addRow(transferProgress.getSource(),
|
||||
transferProgress.getDestination(),
|
||||
transferProgress.getOperation() == SftpProgressMonitor.GET? "Download" : "Upload",
|
||||
100));
|
||||
}
|
||||
else {
|
||||
updateRow(controller.getTableIndex(transferProgress), 100);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user