shared file details panel

This commit is contained in:
Zlatin Balevsky
2019-11-07 19:15:35 +00:00
parent 3b2e1cf98c
commit 26fa757b13
5 changed files with 113 additions and 19 deletions

View File

@@ -376,6 +376,19 @@ class MainFrameController {
JOptionPane.showMessageDialog(null, "Certificate(s) have been issued")
}
}
@ControllerAction
void showFileDetails() {
def selected = view.selectedSharedFiles()
if (selected.size() != 1) {
JOptionPane.showMessageDialog(null, "Please select only one file to view it's details")
return
}
def params = [:]
params['sf'] = selected[0]
params['core'] = core
mvcGroup.createMVCGroup("shared-file", params)
}
void saveMuWireSettings() {
core.saveMuSettings()

View File

@@ -8,11 +8,4 @@ import javax.annotation.Nonnull
@ArtifactProviderFor(GriffonController)
class SharedFileController {
@MVCMember @Nonnull
SharedFileModel model
@ControllerAction
void click() {
model.clickCount++
}
}

View File

@@ -1,10 +1,24 @@
package com.muwire.gui
import com.muwire.core.Core
import com.muwire.core.SharedFile
import griffon.core.artifact.GriffonModel
import griffon.transform.Observable
import griffon.metadata.ArtifactProviderFor
@ArtifactProviderFor(GriffonModel)
class SharedFileModel {
@Observable int clickCount = 0
SharedFile sf
Core core
def searchers = []
def downloaders = []
def certificates = []
public void mvcGroupInit(Map<String,String> args) {
searchers.addAll(sf.searches)
downloaders.addAll(sf.downloaders)
certificates.addAll(core.certificateManager.byInfoHash.get(sf.infoHash))
}
}

View File

@@ -611,6 +611,9 @@ class MainFrameView {
JMenuItem certifySelectedFiles = new JMenuItem("Certify selected files")
certifySelectedFiles.addActionListener({mvcGroup.controller.issueCertificate()})
sharedFilesMenu.add(certifySelectedFiles)
JMenuItem showFileDetails = new JMenuItem("Show file details")
showFileDetails.addActionListener({mvcGroup.controller.showFileDetails()})
sharedFilesMenu.add(showFileDetails)
def sharedFilesMouseListener = new MouseAdapter() {
@Override

View File

@@ -3,7 +3,15 @@ package com.muwire.gui
import griffon.core.artifact.GriffonView
import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import javax.swing.JDialog
import javax.swing.JTabbedPane
import javax.swing.SwingConstants
import java.awt.BorderLayout
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import javax.annotation.Nonnull
@ArtifactProviderFor(GriffonView)
@@ -13,19 +21,82 @@ class SharedFileView {
@MVCMember @Nonnull
SharedFileModel model
def mainFrame
def dialog
def panel
def searchersPanel
def downloadersPanel
def certificatesTable
def certificatesPanel
void initUI() {
builder.with {
application(size: [320, 160], id: 'shared-file',
title: application.configuration['application.title'],
iconImage: imageIcon('/griffon-icon-48x48.png').image,
iconImages: [imageIcon('/griffon-icon-48x48.png').image,
imageIcon('/griffon-icon-32x32.png').image,
imageIcon('/griffon-icon-16x16.png').image]) {
gridLayout(rows: 2, cols: 1)
label(id: 'clickLabel', text: bind { model.clickCount },
horizontalAlignment: SwingConstants.CENTER)
button(id: 'clickButton', clickAction)
mainFrame = application.windowManager.findWindow("main-frame")
int rowHeight = application.context.get("row-height")
dialog = new JDialog(mainFrame,"Details for "+model.sf.getFile().getName(),true)
dialog.setResizable(true)
searchersPanel = builder.panel {
borderLayout()
scrollPane(constraints : BorderLayout.CENTER) {
table(autoCreateRowSorter : true, rowHeight : rowHeight) {
tableModel(list : model.searchers) {
closureColumn(header : "Searcher", type : String, read : {it.searcher.getHumanReadableName()})
closureColumn(header : "Query", type : String, read : {it.query})
closureColumn(header : "Timestamp", type : String, read : {
Date d = new Date(it.timestamp)
d.toString()
})
}
}
}
}
downloadersPanel = builder.panel {
borderLayout()
scrollPane(constraints : BorderLayout.CENTER) {
table(autoCreateRowSorter : true, rowHeight : rowHeight) {
tableModel(list : model.downloaders) {
closureColumn(header : "Downloader", type : String, read : {it})
}
}
}
}
certificatesPanel = builder.panel {
borderLayout()
scrollPane(constraints : BorderLayout.CENTER) {
certificatesTable = table(autoCreateRowSorter : true, rowHeight : rowHeight) {
tableModel(list : model.certificates) {
closureColumn(header : "Issuer", type:String, read : {it.issuer.getHumanReadableName()})
closureColumn(header : "File Name", type : String, read : {it.name.name})
closureColumn(header : "Comment", type : Boolean, read : {it.comment != null})
closureColumn(header : "Timestamp", type : String, read : {
Date d = new Date(it.timestamp)
d.toString()
})
}
}
}
}
}
void mvcGroupInit(Map<String,String> args) {
def tabbedPane = new JTabbedPane()
tabbedPane.addTab("Search Hits", searchersPanel)
tabbedPane.addTab("Downloaders", downloadersPanel)
tabbedPane.addTab("Certificates", certificatesPanel)
dialog.with {
getContentPane().add(tabbedPane)
pack()
setLocationRelativeTo(mainFrame)
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
mvcGroup.destroy()
}
})
show()
}
}
}