mirror of https://github.com/zlatinb/muwire
uploads panel
parent
e667442cc2
commit
45e6adf07c
|
@ -14,6 +14,8 @@ import com.muwire.core.files.FileHashedEvent
|
|||
import com.muwire.core.files.FileLoadedEvent
|
||||
import com.muwire.core.files.FileSharedEvent
|
||||
import com.muwire.core.search.UIResultEvent
|
||||
import com.muwire.core.upload.UploadEvent
|
||||
import com.muwire.core.upload.UploadFinishedEvent
|
||||
|
||||
import griffon.core.GriffonApplication
|
||||
import griffon.core.artifact.GriffonModel
|
||||
|
@ -31,6 +33,7 @@ class MainFrameModel {
|
|||
|
||||
@Observable def results = []
|
||||
@Observable def downloads = []
|
||||
@Observable def uploads = []
|
||||
@Observable def shared = []
|
||||
@Observable int connections
|
||||
@Observable String me
|
||||
|
@ -50,11 +53,14 @@ class MainFrameModel {
|
|||
core.eventBus.register(DisconnectionEvent.class, this)
|
||||
core.eventBus.register(FileHashedEvent.class, this)
|
||||
core.eventBus.register(FileLoadedEvent.class, this)
|
||||
core.eventBus.register(UploadEvent.class, this)
|
||||
core.eventBus.register(UploadFinishedEvent.class, this)
|
||||
})
|
||||
Timer timer = new Timer("download-pumper", true)
|
||||
timer.schedule({
|
||||
runInsideUIAsync {
|
||||
builder.getVariable("downloads-table").model.fireTableDataChanged()
|
||||
builder.getVariable("uploads-table").model.fireTableDataChanged()
|
||||
}
|
||||
}, 1000, 1000)
|
||||
}
|
||||
|
@ -108,4 +114,20 @@ class MainFrameModel {
|
|||
table.model.fireTableDataChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void onUploadEvent(UploadEvent e) {
|
||||
runInsideUIAsync {
|
||||
uploads << e.uploader
|
||||
JTable table = builder.getVariable("uploads-table")
|
||||
table.model.fireTableDataChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void onUploadFinishedEvent(UploadFinishedEvent e) {
|
||||
runInsideUIAsync {
|
||||
uploads.remove(e.uploader)
|
||||
JTable table = builder.getVariable("uploads-table")
|
||||
table.model.fireTableDataChanged()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -117,7 +117,22 @@ class MainFrameView {
|
|||
}
|
||||
}
|
||||
panel {
|
||||
label("Uploads go here")
|
||||
borderLayout()
|
||||
label("Uploads", constraints : BorderLayout.NORTH)
|
||||
scrollPane (constraints : BorderLayout.CENTER) {
|
||||
table(id : "uploads-table") {
|
||||
tableModel(list : model.uploads) {
|
||||
closureColumn(header : "Name", type : String, read : {row -> row.file.getName() })
|
||||
closureColumn(header : "Progress", type : String, read : { row ->
|
||||
int position = row.getPosition()
|
||||
def range = row.request.getRange()
|
||||
int total = range.end - range.start
|
||||
int percent = (int)((position * 100.0) / total)
|
||||
"$percent%"
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue