allow switching without restart

This commit is contained in:
Zlatin Balevsky
2019-10-14 21:40:03 +01:00
parent 965fa79bbf
commit 6c26019164
6 changed files with 91 additions and 110 deletions

View File

@@ -144,8 +144,6 @@ class OptionsController {
// model.showSearchHashes = showSearchHashes // model.showSearchHashes = showSearchHashes
// uiSettings.showSearchHashes = showSearchHashes // uiSettings.showSearchHashes = showSearchHashes
uiSettings.sharedFilesAsTree = model.sharedFilesAsTree
File uiSettingsFile = new File(core.home, "gui.properties") File uiSettingsFile = new File(core.home, "gui.properties")
uiSettingsFile.withOutputStream { uiSettingsFile.withOutputStream {
uiSettings.write(it) uiSettings.write(it)
@@ -169,15 +167,5 @@ class OptionsController {
int rv = chooser.showOpenDialog(null) int rv = chooser.showOpenDialog(null)
if (rv == JFileChooser.APPROVE_OPTION) if (rv == JFileChooser.APPROVE_OPTION)
model.downloadLocation = chooser.getSelectedFile().getAbsolutePath() model.downloadLocation = chooser.getSelectedFile().getAbsolutePath()
} }
@ControllerAction
void sharedTree() {
model.sharedFilesAsTree = true
}
@ControllerAction
void sharedTable() {
model.sharedFilesAsTree = false
}
} }

View File

@@ -71,7 +71,8 @@ class MainFrameModel {
def results = new ConcurrentHashMap<>() def results = new ConcurrentHashMap<>()
def downloads = [] def downloads = []
def uploads = [] def uploads = []
def shared boolean treeVisible = true
def shared
def sharedTree def sharedTree
def treeRoot def treeRoot
final Map<SharedFile, TreeNode> fileToNode = new HashMap<>() final Map<SharedFile, TreeNode> fileToNode = new HashMap<>()
@@ -133,12 +134,9 @@ class MainFrameModel {
uiSettings = application.context.get("ui-settings") uiSettings = application.context.get("ui-settings")
if (!uiSettings.sharedFilesAsTree) shared = []
shared = [] treeRoot = new DefaultMutableTreeNode()
else { sharedTree = new DefaultTreeModel(treeRoot)
treeRoot = new DefaultMutableTreeNode()
sharedTree = new DefaultTreeModel(treeRoot)
}
Timer timer = new Timer("download-pumper", true) Timer timer = new Timer("download-pumper", true)
timer.schedule({ timer.schedule({
@@ -331,52 +329,43 @@ class MainFrameModel {
if (e.error != null) if (e.error != null)
return // TODO do something return // TODO do something
runInsideUIAsync { runInsideUIAsync {
if (!uiSettings.sharedFilesAsTree) { shared << e.sharedFile
shared << e.sharedFile loadedFiles = shared.size()
loadedFiles = shared.size() JTable table = builder.getVariable("shared-files-table")
JTable table = builder.getVariable("shared-files-table") table.model.fireTableDataChanged()
table.model.fireTableDataChanged() insertIntoTree(e.sharedFile)
} else { loadedFiles = fileToNode.size()
insertIntoTree(e.sharedFile)
loadedFiles = fileToNode.size()
}
} }
} }
void onFileLoadedEvent(FileLoadedEvent e) { void onFileLoadedEvent(FileLoadedEvent e) {
runInsideUIAsync { runInsideUIAsync {
if (!uiSettings.sharedFilesAsTree) { shared << e.loadedFile
shared << e.loadedFile loadedFiles = shared.size()
loadedFiles = shared.size() JTable table = builder.getVariable("shared-files-table")
JTable table = builder.getVariable("shared-files-table") table.model.fireTableDataChanged()
table.model.fireTableDataChanged() insertIntoTree(e.loadedFile)
} else { loadedFiles = fileToNode.size()
insertIntoTree(e.loadedFile)
loadedFiles = fileToNode.size()
}
} }
} }
void onFileUnsharedEvent(FileUnsharedEvent e) { void onFileUnsharedEvent(FileUnsharedEvent e) {
runInsideUIAsync { runInsideUIAsync {
if (!uiSettings.sharedFilesAsTree) { shared.remove(e.unsharedFile)
shared.remove(e.unsharedFile) loadedFiles = shared.size()
loadedFiles = shared.size() def dmtn = fileToNode.remove(e.unsharedFile)
} else { if (dmtn != null) {
def dmtn = fileToNode.remove(e.unsharedFile) loadedFiles = fileToNode.size()
if (dmtn != null) { while (true) {
loadedFiles = fileToNode.size() def parent = dmtn.getParent()
while (true) { parent.remove(dmtn)
def parent = dmtn.getParent() if (parent == treeRoot)
parent.remove(dmtn)
if (parent == treeRoot)
break
if (parent.getChildCount() == 0) {
dmtn = parent
continue
}
break break
if (parent.getChildCount() == 0) {
dmtn = parent
continue
} }
break
} }
} }
view.refreshSharedFiles() view.refreshSharedFiles()
@@ -519,14 +508,11 @@ class MainFrameModel {
if (!core.muOptions.shareDownloadedFiles) if (!core.muOptions.shareDownloadedFiles)
return return
runInsideUIAsync { runInsideUIAsync {
if (!uiSettings.sharedFilesAsTree) { shared << e.downloadedFile
shared << e.downloadedFile JTable table = builder.getVariable("shared-files-table")
JTable table = builder.getVariable("shared-files-table") table.model.fireTableDataChanged()
table.model.fireTableDataChanged() insertIntoTree(e.downloadedFile)
} else { loadedFiles = fileToNode.size()
insertIntoTree(e.downloadedFile)
loadedFiles = fileToNode.size()
}
} }
} }

View File

@@ -31,7 +31,6 @@ class OptionsModel {
@Observable boolean clearFinishedDownloads @Observable boolean clearFinishedDownloads
@Observable boolean excludeLocalResult @Observable boolean excludeLocalResult
@Observable boolean showSearchHashes @Observable boolean showSearchHashes
@Observable boolean sharedFilesAsTree
// bw options // bw options
@Observable String inBw @Observable String inBw
@@ -68,7 +67,6 @@ class OptionsModel {
clearFinishedDownloads = uiSettings.clearFinishedDownloads clearFinishedDownloads = uiSettings.clearFinishedDownloads
excludeLocalResult = uiSettings.excludeLocalResult excludeLocalResult = uiSettings.excludeLocalResult
showSearchHashes = uiSettings.showSearchHashes showSearchHashes = uiSettings.showSearchHashes
sharedFilesAsTree = uiSettings.sharedFilesAsTree
if (core.router != null) { if (core.router != null) {
inBw = String.valueOf(settings.inBw) inBw = String.valueOf(settings.inBw)

View File

@@ -209,10 +209,11 @@ class MainFrameView {
} }
} }
} }
panel { panel (id : "shared-files-panel"){
borderLayout() cardLayout()
scrollPane(constraints : BorderLayout.CENTER) { panel (constraints : "shared files table") {
if (!settings.sharedFilesAsTree) { borderLayout()
scrollPane(constraints : BorderLayout.CENTER) {
table(id : "shared-files-table", autoCreateRowSorter: true) { table(id : "shared-files-table", autoCreateRowSorter: true) {
tableModel(list : model.shared) { tableModel(list : model.shared) {
closureColumn(header : "Name", preferredWidth : 500, type : String, read : {row -> row.getCachedPath()}) closureColumn(header : "Name", preferredWidth : 500, type : String, read : {row -> row.getCachedPath()})
@@ -220,7 +221,11 @@ class MainFrameView {
closureColumn(header : "Comments", preferredWidth : 100, type : Boolean, read : {it.getComment() != null}) closureColumn(header : "Comments", preferredWidth : 100, type : Boolean, read : {it.getComment() != null})
} }
} }
} else { }
}
panel (constraints : "shared files tree") {
borderLayout()
scrollPane(constraints : BorderLayout.CENTER) {
def jtree = new JTree(model.sharedTree) def jtree = new JTree(model.sharedTree)
jtree.setCellRenderer(new SharedTreeRenderer()) jtree.setCellRenderer(new SharedTreeRenderer())
tree(id : "shared-files-tree", rootVisible : false, jtree) tree(id : "shared-files-tree", rootVisible : false, jtree)
@@ -243,6 +248,11 @@ class MainFrameView {
panel { panel {
button(text : "Add Comment", enabled : bind {model.addCommentButtonEnabled}, addCommentAction) button(text : "Add Comment", enabled : bind {model.addCommentButtonEnabled}, addCommentAction)
} }
panel {
buttonGroup(id : "sharedViewType")
radioButton(text : "Tree", selected : true, buttonGroup : sharedViewType, actionPerformed : showSharedFilesTree)
radioButton(text : "Table", selected : false, buttonGroup : sharedViewType, actionPerformed : showSharedFilesTable)
}
} }
} }
} }
@@ -525,34 +535,30 @@ class MainFrameView {
} }
} }
// shared files table or tree // shared files table and tree
if (!settings.sharedFilesAsTree) { def sharedFilesTable = builder.getVariable("shared-files-table")
def sharedFilesTable = builder.getVariable("shared-files-table") sharedFilesTable.columnModel.getColumn(1).setCellRenderer(new SizeRenderer())
sharedFilesTable.columnModel.getColumn(1).setCellRenderer(new SizeRenderer())
sharedFilesTable.rowSorter.addRowSorterListener({evt -> lastSharedSortEvent = evt}) sharedFilesTable.rowSorter.addRowSorterListener({evt -> lastSharedSortEvent = evt})
sharedFilesTable.rowSorter.setSortsOnUpdates(true) sharedFilesTable.rowSorter.setSortsOnUpdates(true)
sharedFilesTable.addMouseListener(sharedFilesMouseListener) sharedFilesTable.addMouseListener(sharedFilesMouseListener)
selectionModel = sharedFilesTable.getSelectionModel() selectionModel = sharedFilesTable.getSelectionModel()
selectionModel.addListSelectionListener({ selectionModel.addListSelectionListener({
def selectedFiles = selectedSharedFiles() def selectedFiles = selectedSharedFiles()
if (selectedFiles == null || selectedFiles.isEmpty()) if (selectedFiles == null || selectedFiles.isEmpty())
return return
model.addCommentButtonEnabled = true model.addCommentButtonEnabled = true
}) })
} else { def sharedFilesTree = builder.getVariable("shared-files-tree")
def sharedFilesTree = builder.getVariable("shared-files-tree") sharedFilesTree.addMouseListener(sharedFilesMouseListener)
sharedFilesTree.addMouseListener(sharedFilesMouseListener)
sharedFilesTree.addTreeSelectionListener({
sharedFilesTree.addTreeSelectionListener({ def selectedNode = sharedFilesTree.getLastSelectedPathComponent()
def selectedNode = sharedFilesTree.getLastSelectedPathComponent() model.addCommentButtonEnabled = selectedNode != null
model.addCommentButtonEnabled = selectedNode != null
})
})
// TODO: other stuff
}
// searches table // searches table
def searchesTable = builder.getVariable("searches-table") def searchesTable = builder.getVariable("searches-table")
@@ -676,6 +682,9 @@ class MainFrameView {
model.markNeutralFromDistrustedButtonEnabled = true model.markNeutralFromDistrustedButtonEnabled = true
} }
}) })
// show tree by default
showSharedFilesTree.call()
} }
private static void showPopupMenu(JPopupMenu menu, MouseEvent event) { private static void showPopupMenu(JPopupMenu menu, MouseEvent event) {
@@ -683,7 +692,7 @@ class MainFrameView {
} }
def selectedSharedFiles() { def selectedSharedFiles() {
if (!settings.sharedFilesAsTree) { if (!model.treeVisible) {
def sharedFilesTable = builder.getVariable("shared-files-table") def sharedFilesTable = builder.getVariable("shared-files-table")
int[] selected = sharedFilesTable.getSelectedRows() int[] selected = sharedFilesTable.getSelectedRows()
if (selected.length == 0) if (selected.length == 0)
@@ -867,6 +876,18 @@ class MainFrameView {
model.monitorPaneButtonEnabled = true model.monitorPaneButtonEnabled = true
model.trustPaneButtonEnabled = false model.trustPaneButtonEnabled = false
} }
def showSharedFilesTable = {
model.treeVisible = false
def cardsPanel = builder.getVariable("shared-files-panel")
cardsPanel.getLayout().show(cardsPanel, "shared files table")
}
def showSharedFilesTree = {
model.treeVisible = true
def cardsPanel = builder.getVariable("shared-files-panel")
cardsPanel.getLayout().show(cardsPanel, "shared files tree")
}
def shareFiles = { def shareFiles = {
def chooser = new JFileChooser() def chooser = new JFileChooser()
@@ -924,11 +945,8 @@ class MainFrameView {
selectedRow selectedRow
} }
public void refreshSharedFiles() { public void refreshSharedFiles() {
if (settings.sharedFilesAsTree) { model.sharedTree.nodeStructureChanged(model.treeRoot)
model.sharedTree.nodeStructureChanged(model.treeRoot) builder.getVariable("shared-files-table").model.fireTableDataChanged()
} else {
builder.getVariable("shared-files-table").model.fireTableDataChanged()
}
} }
} }

View File

@@ -126,12 +126,6 @@ class OptionsView {
excludeLocalResultCheckbox = checkBox(selected : bind {model.excludeLocalResult}, constraints : gbc(gridx: 1, gridy : 6)) excludeLocalResultCheckbox = checkBox(selected : bind {model.excludeLocalResult}, constraints : gbc(gridx: 1, gridy : 6))
// label(text : "Show Hash Searches In Monitor", constraints: gbc(gridx:0, gridy:7)) // label(text : "Show Hash Searches In Monitor", constraints: gbc(gridx:0, gridy:7))
// showSearchHashesCheckbox = checkBox(selected : bind {model.showSearchHashes}, constraints : gbc(gridx: 1, gridy: 7)) // showSearchHashesCheckbox = checkBox(selected : bind {model.showSearchHashes}, constraints : gbc(gridx: 1, gridy: 7))
label(text : "Show Shared Files as", constraints: gbc(gridx: 0, gridy:8))
panel( constraints : gbc(gridx: 1, gridy: 8)) {
buttonGroup(id : "viewShared")
radioButton(text: "Tree", selected : bind {model.sharedFilesAsTree}, buttonGroup: viewShared, sharedTreeAction)
radioButton(text: "Table", selected : bind {!model.sharedFilesAsTree}, buttonGroup: viewShared, sharedTableAction)
}
} }
bandwidth = builder.panel { bandwidth = builder.panel {
gridBagLayout() gridBagLayout()

View File

@@ -9,7 +9,6 @@ class UISettings {
boolean clearFinishedDownloads boolean clearFinishedDownloads
boolean excludeLocalResult boolean excludeLocalResult
boolean showSearchHashes boolean showSearchHashes
boolean sharedFilesAsTree
UISettings(Properties props) { UISettings(Properties props) {
lnf = props.getProperty("lnf", "system") lnf = props.getProperty("lnf", "system")
@@ -19,7 +18,6 @@ class UISettings {
clearFinishedDownloads = Boolean.parseBoolean(props.getProperty("clearFinishedDownloads","false")) clearFinishedDownloads = Boolean.parseBoolean(props.getProperty("clearFinishedDownloads","false"))
excludeLocalResult = Boolean.parseBoolean(props.getProperty("excludeLocalResult","true")) excludeLocalResult = Boolean.parseBoolean(props.getProperty("excludeLocalResult","true"))
showSearchHashes = Boolean.parseBoolean(props.getProperty("showSearchHashes","true")) showSearchHashes = Boolean.parseBoolean(props.getProperty("showSearchHashes","true"))
sharedFilesAsTree = Boolean.parseBoolean(props.getProperty("sharedFilesAsTree","true"))
} }
void write(OutputStream out) throws IOException { void write(OutputStream out) throws IOException {
@@ -30,7 +28,6 @@ class UISettings {
props.setProperty("clearFinishedDownloads", String.valueOf(clearFinishedDownloads)) props.setProperty("clearFinishedDownloads", String.valueOf(clearFinishedDownloads))
props.setProperty("excludeLocalResult", String.valueOf(excludeLocalResult)) props.setProperty("excludeLocalResult", String.valueOf(excludeLocalResult))
props.setProperty("showSearchHashes", String.valueOf(showSearchHashes)) props.setProperty("showSearchHashes", String.valueOf(showSearchHashes))
props.setProperty("sharedFilesAsTree", String.valueOf(sharedFilesAsTree))
if (font != null) if (font != null)
props.setProperty("font", font) props.setProperty("font", font)