options dialog

pull/4/head
Zlatin Balevsky 2019-06-03 14:40:32 +01:00
parent 3642736cfe
commit 1ee389ff91
4 changed files with 39 additions and 6 deletions

View File

@ -34,7 +34,7 @@ class MuWireSettings {
props.setProperty("crawlerResponse", crawlerResponse.toString())
props.setProperty("nickname", nickname)
props.setProperty("downloadLocation", downloadLocation.getAbsolutePath())
props.setProperty("downloadRetryInterval", "15")
props.setProperty("downloadRetryInterval", String.valueOf(downloadRetryInterval))
if (sharedFiles != null)
props.setProperty("sharedFiles", sharedFiles)
props.store(out, "")

View File

@ -10,9 +10,28 @@ import javax.annotation.Nonnull
class OptionsController {
@MVCMember @Nonnull
OptionsModel model
@MVCMember @Nonnull
OptionsView view
@ControllerAction
void click() {
model.clickCount++
void save() {
String text = view.retryField.text
model.downloadRetryInterval = text
def settings = application.context.get("muwire-settings")
settings.downloadRetryInterval = Integer.valueOf(text)
File settingsFile = new File(application.context.get("core").home, "MuWire.properties")
settingsFile.withOutputStream {
settings.write(it)
}
cancel()
}
@ControllerAction
void cancel() {
view.d.setVisible(false)
mvcGroup.destroy()
}
}

View File

@ -6,5 +6,9 @@ import griffon.metadata.ArtifactProviderFor
@ArtifactProviderFor(GriffonModel)
class OptionsModel {
@Observable int clickCount = 0
@Observable String downloadRetryInterval
void mvcGroupInit(Map<String, String> args) {
downloadRetryInterval = application.context.get("muwire-settings").downloadRetryInterval
}
}

View File

@ -17,18 +17,28 @@ class OptionsView {
def d
def p
def retryField
def mainFrame
void initUI() {
def mainFrame = application.windowManager.findWindow("main-frame")
mainFrame = application.windowManager.findWindow("main-frame")
d = new JDialog(mainFrame, "Options", true)
d.setResizable(false)
p = builder.panel {
label(text : "Text")
gridBagLayout()
label(text : "Retry failed downloads every", constraints : gbc(gridx: 0, gridy: 0))
retryField = textField(text : bind { model.downloadRetryInterval }, columns : 2, constraints : gbc(gridx: 1, gridy: 0))
label(text : "minutes", constraints : gbc(gridx : 2, gridy: 0))
button(text : "Save", constraints : gbc(gridx : 1, gridy: 1), saveAction)
button(text : "Cancel", constraints : gbc(gridx : 2, gridy: 1), cancelAction)
}
}
void mvcGroupInit(Map<String,String> args) {
d.getContentPane().add(p)
d.pack()
d.setLocationRelativeTo(mainFrame)
d.show()
}
}