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)
@@ -170,14 +168,4 @@ class OptionsController {
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,6 +71,7 @@ class MainFrameModel {
def results = new ConcurrentHashMap<>() def results = new ConcurrentHashMap<>()
def downloads = [] def downloads = []
def uploads = [] def uploads = []
boolean treeVisible = true
def shared def shared
def sharedTree def sharedTree
def treeRoot def treeRoot
@@ -133,12 +134,9 @@ class MainFrameModel {
uiSettings = application.context.get("ui-settings") uiSettings = application.context.get("ui-settings")
if (!uiSettings.sharedFilesAsTree)
shared = [] shared = []
else {
treeRoot = new DefaultMutableTreeNode() treeRoot = new DefaultMutableTreeNode()
sharedTree = new DefaultTreeModel(treeRoot) sharedTree = new DefaultTreeModel(treeRoot)
}
Timer timer = new Timer("download-pumper", true) Timer timer = new Timer("download-pumper", true)
timer.schedule({ timer.schedule({
@@ -331,38 +329,30 @@ 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()
} else {
insertIntoTree(e.sharedFile) insertIntoTree(e.sharedFile)
loadedFiles = fileToNode.size() 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()
} else {
insertIntoTree(e.loadedFile) insertIntoTree(e.loadedFile)
loadedFiles = fileToNode.size() 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()
} else {
def dmtn = fileToNode.remove(e.unsharedFile) def dmtn = fileToNode.remove(e.unsharedFile)
if (dmtn != null) { if (dmtn != null) {
loadedFiles = fileToNode.size() loadedFiles = fileToNode.size()
@@ -378,7 +368,6 @@ class MainFrameModel {
break break
} }
} }
}
view.refreshSharedFiles() view.refreshSharedFiles()
} }
} }
@@ -519,16 +508,13 @@ 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()
} else {
insertIntoTree(e.downloadedFile) insertIntoTree(e.downloadedFile)
loadedFiles = fileToNode.size() loadedFiles = fileToNode.size()
} }
} }
}
private void insertIntoTree(SharedFile file) { private void insertIntoTree(SharedFile file) {
Path folder = file.getFile().toPath() Path folder = file.getFile().toPath()

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"){
cardLayout()
panel (constraints : "shared files table") {
borderLayout() borderLayout()
scrollPane(constraints : BorderLayout.CENTER) { scrollPane(constraints : BorderLayout.CENTER) {
if (!settings.sharedFilesAsTree) {
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,8 +535,7 @@ 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())
@@ -542,7 +551,6 @@ class MainFrameView {
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)
@@ -551,8 +559,6 @@ class MainFrameView {
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)
@@ -868,6 +877,18 @@ class MainFrameView {
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()
chooser.setFileHidingEnabled(false) chooser.setFileHidingEnabled(false)
@@ -925,10 +946,7 @@ class MainFrameView {
} }
public void refreshSharedFiles() { public void refreshSharedFiles() {
if (settings.sharedFilesAsTree) {
model.sharedTree.nodeStructureChanged(model.treeRoot) model.sharedTree.nodeStructureChanged(model.treeRoot)
} else {
builder.getVariable("shared-files-table").model.fireTableDataChanged() 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)