Implement automatic font sizing; set all font properties on change of font
This commit is contained in:
@@ -131,10 +131,9 @@ class OptionsController {
|
|||||||
text = view.fontField.text
|
text = view.fontField.text
|
||||||
model.font = text
|
model.font = text
|
||||||
uiSettings.font = text
|
uiSettings.font = text
|
||||||
|
|
||||||
// boolean showMonitor = view.monitorCheckbox.model.isSelected()
|
uiSettings.autoFontSize = model.automaticFontSize
|
||||||
// model.showMonitor = showMonitor
|
uiSettings.fontSize = Integer.parseInt(view.fontSizeField.text)
|
||||||
// uiSettings.showMonitor = showMonitor
|
|
||||||
|
|
||||||
boolean clearCancelledDownloads = view.clearCancelledDownloadsCheckbox.model.isSelected()
|
boolean clearCancelledDownloads = view.clearCancelledDownloadsCheckbox.model.isSelected()
|
||||||
model.clearCancelledDownloads = clearCancelledDownloads
|
model.clearCancelledDownloads = clearCancelledDownloads
|
||||||
@@ -148,10 +147,6 @@ class OptionsController {
|
|||||||
model.excludeLocalResult = excludeLocalResult
|
model.excludeLocalResult = excludeLocalResult
|
||||||
uiSettings.excludeLocalResult = excludeLocalResult
|
uiSettings.excludeLocalResult = excludeLocalResult
|
||||||
|
|
||||||
// boolean showSearchHashes = view.showSearchHashesCheckbox.model.isSelected()
|
|
||||||
// model.showSearchHashes = showSearchHashes
|
|
||||||
// uiSettings.showSearchHashes = showSearchHashes
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -176,4 +171,15 @@ class OptionsController {
|
|||||||
if (rv == JFileChooser.APPROVE_OPTION)
|
if (rv == JFileChooser.APPROVE_OPTION)
|
||||||
model.downloadLocation = chooser.getSelectedFile().getAbsolutePath()
|
model.downloadLocation = chooser.getSelectedFile().getAbsolutePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void automaticFontAction() {
|
||||||
|
model.automaticFontSize = true
|
||||||
|
model.customFontSize = 12
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void customFontAction() {
|
||||||
|
model.automaticFontSize = false
|
||||||
|
}
|
||||||
}
|
}
|
@@ -10,14 +10,17 @@ import com.muwire.gui.UISettings
|
|||||||
|
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import javax.swing.JLabel
|
||||||
import javax.swing.JTable
|
import javax.swing.JTable
|
||||||
import javax.swing.LookAndFeel
|
import javax.swing.LookAndFeel
|
||||||
import javax.swing.UIManager
|
import javax.swing.UIManager
|
||||||
|
import javax.swing.plaf.FontUIResource
|
||||||
|
|
||||||
import static griffon.util.GriffonApplicationUtils.isMacOSX
|
import static griffon.util.GriffonApplicationUtils.isMacOSX
|
||||||
import static groovy.swing.SwingBuilder.lookAndFeel
|
import static groovy.swing.SwingBuilder.lookAndFeel
|
||||||
|
|
||||||
import java.awt.Font
|
import java.awt.Font
|
||||||
|
import java.awt.Toolkit
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
|
||||||
@Log
|
@Log
|
||||||
@@ -52,25 +55,43 @@ class Initialize extends AbstractLifecycleHandler {
|
|||||||
guiPropsFile.withInputStream { props.load(it) }
|
guiPropsFile.withInputStream { props.load(it) }
|
||||||
uiSettings = new UISettings(props)
|
uiSettings = new UISettings(props)
|
||||||
|
|
||||||
|
def lnf
|
||||||
log.info("settting user-specified lnf $uiSettings.lnf")
|
log.info("settting user-specified lnf $uiSettings.lnf")
|
||||||
try {
|
try {
|
||||||
lookAndFeel(uiSettings.lnf)
|
lnf = lookAndFeel(uiSettings.lnf)
|
||||||
} catch (Throwable bad) {
|
} catch (Throwable bad) {
|
||||||
log.log(Level.WARNING,"couldn't set desired look and feeel, switching to defaults", bad)
|
log.log(Level.WARNING,"couldn't set desired look and feel, switching to defaults", bad)
|
||||||
uiSettings.lnf = lookAndFeel("system","gtk","metal").getID()
|
lnf = lookAndFeel("system","gtk","metal")
|
||||||
|
uiSettings.lnf = lnf.getID()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uiSettings.font != null) {
|
if (uiSettings.font != null || uiSettings.autoFontSize || uiSettings.fontSize > 0) {
|
||||||
log.info("setting user-specified font $uiSettings.font")
|
|
||||||
Font font = new Font(uiSettings.font, Font.PLAIN, 12)
|
FontUIResource defaultFont = lnf.getDefaults().getFont("Label.font")
|
||||||
def defaults = UIManager.getDefaults()
|
|
||||||
defaults.put("Button.font", font)
|
String fontName
|
||||||
defaults.put("RadioButton.font", font)
|
if (uiSettings.font != null)
|
||||||
defaults.put("Label.font", font)
|
fontName = uiSettings.font
|
||||||
defaults.put("CheckBox.font", font)
|
else
|
||||||
defaults.put("Table.font", font)
|
fontName = defaultFont.getName()
|
||||||
defaults.put("TableHeader.font", font)
|
|
||||||
// TODO: add others
|
int fontSize = defaultFont.getSize()
|
||||||
|
if (uiSettings.autoFontSize) {
|
||||||
|
int resolution = Toolkit.getDefaultToolkit().getScreenResolution()
|
||||||
|
fontSize = resolution / 9;
|
||||||
|
} else {
|
||||||
|
fontSize = uiSettings.fontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
FontUIResource font = new FontUIResource(fontName, Font.PLAIN, fontSize)
|
||||||
|
|
||||||
|
def keys = lnf.getDefaults().keys()
|
||||||
|
while(keys.hasMoreElements()) {
|
||||||
|
def key = keys.nextElement()
|
||||||
|
def value = lnf.getDefaults().get(key)
|
||||||
|
if (value instanceof FontUIResource)
|
||||||
|
lnf.getDefaults().put(key, font)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Properties props = new Properties()
|
Properties props = new Properties()
|
||||||
|
@@ -29,6 +29,8 @@ class OptionsModel {
|
|||||||
@Observable boolean showMonitor
|
@Observable boolean showMonitor
|
||||||
@Observable String lnf
|
@Observable String lnf
|
||||||
@Observable String font
|
@Observable String font
|
||||||
|
@Observable boolean automaticFontSize
|
||||||
|
@Observable int customFontSize
|
||||||
@Observable boolean clearCancelledDownloads
|
@Observable boolean clearCancelledDownloads
|
||||||
@Observable boolean clearFinishedDownloads
|
@Observable boolean clearFinishedDownloads
|
||||||
@Observable boolean excludeLocalResult
|
@Observable boolean excludeLocalResult
|
||||||
@@ -67,6 +69,8 @@ class OptionsModel {
|
|||||||
showMonitor = uiSettings.showMonitor
|
showMonitor = uiSettings.showMonitor
|
||||||
lnf = uiSettings.lnf
|
lnf = uiSettings.lnf
|
||||||
font = uiSettings.font
|
font = uiSettings.font
|
||||||
|
automaticFontSize = uiSettings.autoFontSize
|
||||||
|
customFontSize = uiSettings.fontSize
|
||||||
clearCancelledDownloads = uiSettings.clearCancelledDownloads
|
clearCancelledDownloads = uiSettings.clearCancelledDownloads
|
||||||
clearFinishedDownloads = uiSettings.clearFinishedDownloads
|
clearFinishedDownloads = uiSettings.clearFinishedDownloads
|
||||||
excludeLocalResult = uiSettings.excludeLocalResult
|
excludeLocalResult = uiSettings.excludeLocalResult
|
||||||
|
@@ -12,6 +12,7 @@ import javax.swing.SwingConstants
|
|||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
|
|
||||||
import java.awt.BorderLayout
|
import java.awt.BorderLayout
|
||||||
|
import java.awt.GridBagConstraints
|
||||||
import java.awt.event.WindowAdapter
|
import java.awt.event.WindowAdapter
|
||||||
import java.awt.event.WindowEvent
|
import java.awt.event.WindowEvent
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ class OptionsView {
|
|||||||
def lnfField
|
def lnfField
|
||||||
def monitorCheckbox
|
def monitorCheckbox
|
||||||
def fontField
|
def fontField
|
||||||
|
def fontSizeField
|
||||||
def clearCancelledDownloadsCheckbox
|
def clearCancelledDownloadsCheckbox
|
||||||
def clearFinishedDownloadsCheckbox
|
def clearFinishedDownloadsCheckbox
|
||||||
def excludeLocalResultCheckbox
|
def excludeLocalResultCheckbox
|
||||||
@@ -121,19 +123,28 @@ class OptionsView {
|
|||||||
gridBagLayout()
|
gridBagLayout()
|
||||||
label(text : "Changing these settings requires a restart", constraints : gbc(gridx : 0, gridy : 0, gridwidth: 2))
|
label(text : "Changing these settings requires a restart", constraints : gbc(gridx : 0, gridy : 0, gridwidth: 2))
|
||||||
label(text : "Look And Feel", constraints : gbc(gridx: 0, gridy:1))
|
label(text : "Look And Feel", constraints : gbc(gridx: 0, gridy:1))
|
||||||
lnfField = textField(text : bind {model.lnf}, columns : 4, constraints : gbc(gridx : 1, gridy : 1))
|
lnfField = textField(text : bind {model.lnf}, columns : 4, constraints : gbc(gridx : 1, gridy : 1, anchor : GridBagConstraints.LINE_START))
|
||||||
label(text : "Font", constraints : gbc(gridx: 0, gridy : 2))
|
label(text : "Font", constraints : gbc(gridx: 0, gridy : 2))
|
||||||
fontField = textField(text : bind {model.font}, columns : 4, constraints : gbc(gridx : 1, gridy:2))
|
fontField = textField(text : bind {model.font}, columns : 4, constraints : gbc(gridx : 1, gridy:2, anchor : GridBagConstraints.LINE_START))
|
||||||
// label(text : "Show Monitor", constraints : gbc(gridx :0, gridy: 3))
|
|
||||||
// monitorCheckbox = checkBox(selected : bind {model.showMonitor}, constraints : gbc(gridx : 1, gridy: 3))
|
label(text : "Font Size", constraints : gbc(gridx: 0, gridy : 3))
|
||||||
label(text : "Automatically Clear Cancelled Downloads", constraints: gbc(gridx: 0, gridy:4))
|
buttonGroup(id: "fontSizeGroup")
|
||||||
clearCancelledDownloadsCheckbox = checkBox(selected : bind {model.clearCancelledDownloads}, constraints : gbc(gridx : 1, gridy:4))
|
radioButton(text: "Automatic", selected : bind {model.automaticFontSize}, buttonGroup : fontSizeGroup,
|
||||||
label(text : "Automatically Clear Finished Downloads", constraints: gbc(gridx: 0, gridy:5))
|
constraints : gbc(gridx : 1, gridy: 3, anchor : GridBagConstraints.LINE_START), automaticFontAction)
|
||||||
clearFinishedDownloadsCheckbox = checkBox(selected : bind {model.clearFinishedDownloads}, constraints : gbc(gridx : 1, gridy:5))
|
radioButton(text: "Custom", selected : bind {!model.automaticFontSize}, buttonGroup : fontSizeGroup,
|
||||||
label(text : "Exclude Local Files From Results", constraints: gbc(gridx:0, gridy:6))
|
constraints : gbc(gridx : 1, gridy: 4, anchor : GridBagConstraints.LINE_START), customFontAction)
|
||||||
excludeLocalResultCheckbox = checkBox(selected : bind {model.excludeLocalResult}, constraints : gbc(gridx: 1, gridy : 6))
|
fontSizeField = textField(text : bind {model.customFontSize}, enabled : bind {!model.automaticFontSize}, constraints : gbc(gridx : 2, gridy : 4))
|
||||||
// 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 : "Automatically Clear Cancelled Downloads", constraints: gbc(gridx: 0, gridy:5))
|
||||||
|
clearCancelledDownloadsCheckbox = checkBox(selected : bind {model.clearCancelledDownloads},
|
||||||
|
constraints : gbc(gridx : 1, gridy:5, anchor : GridBagConstraints.LINE_START))
|
||||||
|
label(text : "Automatically Clear Finished Downloads", constraints: gbc(gridx: 0, gridy:6))
|
||||||
|
clearFinishedDownloadsCheckbox = checkBox(selected : bind {model.clearFinishedDownloads},
|
||||||
|
constraints : gbc(gridx : 1, gridy:6, anchor : GridBagConstraints.LINE_START))
|
||||||
|
label(text : "Exclude Local Files From Results", constraints: gbc(gridx:0, gridy:7))
|
||||||
|
excludeLocalResultCheckbox = checkBox(selected : bind {model.excludeLocalResult},
|
||||||
|
constraints : gbc(gridx: 1, gridy : 7, anchor : GridBagConstraints.LINE_START))
|
||||||
|
|
||||||
}
|
}
|
||||||
bandwidth = builder.panel {
|
bandwidth = builder.panel {
|
||||||
gridBagLayout()
|
gridBagLayout()
|
||||||
|
@@ -5,11 +5,13 @@ class UISettings {
|
|||||||
String lnf
|
String lnf
|
||||||
boolean showMonitor
|
boolean showMonitor
|
||||||
String font
|
String font
|
||||||
|
boolean autoFontSize
|
||||||
|
int fontSize
|
||||||
boolean clearCancelledDownloads
|
boolean clearCancelledDownloads
|
||||||
boolean clearFinishedDownloads
|
boolean clearFinishedDownloads
|
||||||
boolean excludeLocalResult
|
boolean excludeLocalResult
|
||||||
boolean showSearchHashes
|
boolean showSearchHashes
|
||||||
|
|
||||||
UISettings(Properties props) {
|
UISettings(Properties props) {
|
||||||
lnf = props.getProperty("lnf", "system")
|
lnf = props.getProperty("lnf", "system")
|
||||||
showMonitor = Boolean.parseBoolean(props.getProperty("showMonitor", "false"))
|
showMonitor = Boolean.parseBoolean(props.getProperty("showMonitor", "false"))
|
||||||
@@ -18,6 +20,8 @@ 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"))
|
||||||
|
autoFontSize = Boolean.parseBoolean(props.getProperty("autoFontSize","false"))
|
||||||
|
fontSize = Integer.parseInt(props.getProperty("fontSize","12"))
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(OutputStream out) throws IOException {
|
void write(OutputStream out) throws IOException {
|
||||||
@@ -28,6 +32,8 @@ 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("autoFontSize", String.valueOf(autoFontSize))
|
||||||
|
props.setProperty("fontSize", String.valueOf(fontSize))
|
||||||
if (font != null)
|
if (font != null)
|
||||||
props.setProperty("font", font)
|
props.setProperty("font", font)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user