private JButton cancelButton;
public FontChooserDialog(final MainWindow mainWindow) {
super(mainWindow);
final ConfigData configManager = mainWindow.getConfigData();
setTitle(Translator.tr("Font settings"));
setResizable(false);
setModal(true);
String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames();
fontFamilyCombo = new JComboBox<>(fonts);
fontFamilyCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
updatePreview();
}
}
});
fontSizeCombo = new JSpinner(new SpinnerNumberModel(10,
8, 72, 1));
fontSizeCombo.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
updatePreview();
}
});
previewTextField = new JTextField("[INFO] Log line example");
okButton = new JButton(Translator.tr("Save"));
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setVisible(false);
Font font = getSelectedFont();
configManager.setFontFamily(fontFamilyCombo.getSelectedItem()
.toString());
configManager.setFontSize(Integer.parseInt(fontSizeCombo.getValue()
.toString()));
ConfigPersistence configPersistence = new ConfigPersistence();
configPersistence.saveProperties(mainWindow,
configManager.getConfiguration());
JInternalFrame[] internalFrames = mainWindow.getDesktop().getAllFrames();
for (JInternalFrame internalFrame : internalFrames) {
LogWindow logWindow = (LogWindow) internalFrame;
logWindow.updateFont(font);
}
dispose();
}
});
cancelButton = new JButton(Translator.tr("Cancel"));
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setVisible(false);
dispose();
}
});
fontFamilyCombo.setSelectedItem(configManager.getFontFamily());
fontSizeCombo.setValue(configManager.getFontSize());
updatePreview();
defineLayout();
}