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
// uiSettings.showSearchHashes = showSearchHashes
uiSettings.sharedFilesAsTree = model.sharedFilesAsTree
File uiSettingsFile = new File(core.home, "gui.properties")
uiSettingsFile.withOutputStream {
uiSettings.write(it)
@@ -170,14 +168,4 @@ class OptionsController {
if (rv == JFileChooser.APPROVE_OPTION)
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 downloads = []
def uploads = []
boolean treeVisible = true
def shared
def sharedTree
def treeRoot
@@ -133,12 +134,9 @@ class MainFrameModel {
uiSettings = application.context.get("ui-settings")
if (!uiSettings.sharedFilesAsTree)
shared = []
else {
treeRoot = new DefaultMutableTreeNode()
sharedTree = new DefaultTreeModel(treeRoot)
}
Timer timer = new Timer("download-pumper", true)
timer.schedule({
@@ -331,38 +329,30 @@ class MainFrameModel {
if (e.error != null)
return // TODO do something
runInsideUIAsync {
if (!uiSettings.sharedFilesAsTree) {
shared << e.sharedFile
loadedFiles = shared.size()
JTable table = builder.getVariable("shared-files-table")
table.model.fireTableDataChanged()
} else {
insertIntoTree(e.sharedFile)
loadedFiles = fileToNode.size()
}
}
}
void onFileLoadedEvent(FileLoadedEvent e) {
runInsideUIAsync {
if (!uiSettings.sharedFilesAsTree) {
shared << e.loadedFile
loadedFiles = shared.size()
JTable table = builder.getVariable("shared-files-table")
table.model.fireTableDataChanged()
} else {
insertIntoTree(e.loadedFile)
loadedFiles = fileToNode.size()
}
}
}
void onFileUnsharedEvent(FileUnsharedEvent e) {
runInsideUIAsync {
if (!uiSettings.sharedFilesAsTree) {
shared.remove(e.unsharedFile)
loadedFiles = shared.size()
} else {
def dmtn = fileToNode.remove(e.unsharedFile)
if (dmtn != null) {
loadedFiles = fileToNode.size()
@@ -378,7 +368,6 @@ class MainFrameModel {
break
}
}
}
view.refreshSharedFiles()
}
}
@@ -519,16 +508,13 @@ class MainFrameModel {
if (!core.muOptions.shareDownloadedFiles)
return
runInsideUIAsync {
if (!uiSettings.sharedFilesAsTree) {
shared << e.downloadedFile
JTable table = builder.getVariable("shared-files-table")
table.model.fireTableDataChanged()
} else {
insertIntoTree(e.downloadedFile)
loadedFiles = fileToNode.size()
}
}
}
private void insertIntoTree(SharedFile file) {
Path folder = file.getFile().toPath()

View File

@@ -31,7 +31,6 @@ class OptionsModel {
@Observable boolean clearFinishedDownloads
@Observable boolean excludeLocalResult
@Observable boolean showSearchHashes
@Observable boolean sharedFilesAsTree
// bw options
@Observable String inBw
@@ -68,7 +67,6 @@ class OptionsModel {
clearFinishedDownloads = uiSettings.clearFinishedDownloads
excludeLocalResult = uiSettings.excludeLocalResult
showSearchHashes = uiSettings.showSearchHashes
sharedFilesAsTree = uiSettings.sharedFilesAsTree
if (core.router != null) {
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()
scrollPane(constraints : BorderLayout.CENTER) {
if (!settings.sharedFilesAsTree) {
table(id : "shared-files-table", autoCreateRowSorter: true) {
tableModel(list : model.shared) {
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})
}
}
} else {
}
}
panel (constraints : "shared files tree") {
borderLayout()
scrollPane(constraints : BorderLayout.CENTER) {
def jtree = new JTree(model.sharedTree)
jtree.setCellRenderer(new SharedTreeRenderer())
tree(id : "shared-files-tree", rootVisible : false, jtree)
@@ -243,6 +248,11 @@ class MainFrameView {
panel {
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
if (!settings.sharedFilesAsTree) {
// shared files table and tree
def sharedFilesTable = builder.getVariable("shared-files-table")
sharedFilesTable.columnModel.getColumn(1).setCellRenderer(new SizeRenderer())
@@ -542,7 +551,6 @@ class MainFrameView {
return
model.addCommentButtonEnabled = true
})
} else {
def sharedFilesTree = builder.getVariable("shared-files-tree")
sharedFilesTree.addMouseListener(sharedFilesMouseListener)
@@ -551,8 +559,6 @@ class MainFrameView {
model.addCommentButtonEnabled = selectedNode != null
})
// TODO: other stuff
}
// searches table
def searchesTable = builder.getVariable("searches-table")
@@ -676,6 +682,9 @@ class MainFrameView {
model.markNeutralFromDistrustedButtonEnabled = true
}
})
// show tree by default
showSharedFilesTree.call()
}
private static void showPopupMenu(JPopupMenu menu, MouseEvent event) {
@@ -683,7 +692,7 @@ class MainFrameView {
}
def selectedSharedFiles() {
if (!settings.sharedFilesAsTree) {
if (!model.treeVisible) {
def sharedFilesTable = builder.getVariable("shared-files-table")
int[] selected = sharedFilesTable.getSelectedRows()
if (selected.length == 0)
@@ -868,6 +877,18 @@ class MainFrameView {
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 chooser = new JFileChooser()
chooser.setFileHidingEnabled(false)
@@ -925,10 +946,7 @@ class MainFrameView {
}
public void refreshSharedFiles() {
if (settings.sharedFilesAsTree) {
model.sharedTree.nodeStructureChanged(model.treeRoot)
} 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))
// 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))
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 {
gridBagLayout()

View File

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