mirror of
https://github.com/xfarrow/guify.git
synced 2025-02-21 14:30:36 +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;
|
private IQueueFrame frame;
|
||||||
|
// Accessed only through the EDT, so no need to use ConcurrentHashMap
|
||||||
private HashMap<TransferProgress, Integer> indexHashMap = new HashMap<>();
|
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 ==========
|
* ========== END Attributes ==========
|
||||||
*/
|
*/
|
||||||
@ -47,16 +49,22 @@ public class QueueController implements Observer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Executed by different threads
|
// Executed on different threads
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable o, Object arg) {
|
public void update(Observable o, Object arg) {
|
||||||
TransferProgress transferProgress = (TransferProgress)arg;
|
TransferProgress transferProgress = (TransferProgress)arg;
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
@Override
|
// Do not invoke the Event Dispatch Thread too frequently as
|
||||||
public void run() {
|
// it may impact the performance of low-end computer systems.
|
||||||
frame.manageTransferProgress(transferProgress);
|
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) {
|
public int computePercentage(TransferProgress transferProgress) {
|
||||||
|
@ -98,6 +98,7 @@ public class Desktop extends JFrame implements IDesktopFrame {
|
|||||||
JScrollPane scrollPane = new JScrollPane();
|
JScrollPane scrollPane = new JScrollPane();
|
||||||
scrollPane.setBounds(156, 36, 1098, 634);
|
scrollPane.setBounds(156, 36, 1098, 634);
|
||||||
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
|
scrollPane.getVerticalScrollBar().setUnitIncrement(25);
|
||||||
getContentPane().add(scrollPane);
|
getContentPane().add(scrollPane);
|
||||||
|
|
||||||
desktopPanel = new JPanel();
|
desktopPanel = new JPanel();
|
||||||
|
@ -91,41 +91,22 @@ public class Queue extends JFrame implements IQueueFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void manageTransferProgress(TransferProgress transferProgress) {
|
public void manageTransferProgress(TransferProgress transferProgress) {
|
||||||
|
|
||||||
if(transferProgress.getTransferStatus() == TransferProgress.INIT) {
|
// Remember that when QueueController calls frame.manageTransferProgress(transferProgress),
|
||||||
if(!controller.isTransferProgressInHashMap(transferProgress)) {
|
// here transferProgress might have a different status (as it's updated by a different thread).
|
||||||
controller.putTableIndex(transferProgress,
|
// We do not need a lock as we do not edit it, but just keep it in mind.
|
||||||
addRow(transferProgress.getSource(),
|
|
||||||
transferProgress.getDestination(),
|
|
||||||
transferProgress.getOperation() == SftpProgressMonitor.GET? "Download" : "Upload",
|
|
||||||
0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(transferProgress.getTransferStatus() == TransferProgress.UPDATING) {
|
if(!controller.isTransferProgressInHashMap(transferProgress)) {
|
||||||
if(!controller.isTransferProgressInHashMap(transferProgress)) {
|
controller.putTableIndex(transferProgress,
|
||||||
controller.putTableIndex(transferProgress,
|
addRow(transferProgress.getSource(),
|
||||||
addRow(transferProgress.getSource(),
|
transferProgress.getDestination(),
|
||||||
transferProgress.getDestination(),
|
transferProgress.getOperation() == SftpProgressMonitor.GET? "Download" : "Upload",
|
||||||
transferProgress.getOperation() == SftpProgressMonitor.GET? "Download" : "Upload",
|
controller.computePercentage(transferProgress)));
|
||||||
controller.computePercentage(transferProgress)));
|
}
|
||||||
}
|
else {
|
||||||
else {
|
if(transferProgress.getTransferStatus() != TransferProgress.INIT) {
|
||||||
updateRow(controller.getTableIndex(transferProgress), controller.computePercentage(transferProgress));
|
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