package org.openslx.dozmod.gui.window.layout; import java.awt.BorderLayout; import java.awt.Insets; import java.awt.Window; import javax.swing.*; import javax.swing.UIManager.LookAndFeelInfo; import org.openslx.dozmod.Branding; import org.openslx.dozmod.Config; import org.openslx.dozmod.gui.control.ComboBox; import org.openslx.dozmod.gui.control.QLabel; import org.openslx.dozmod.gui.control.WordWrapLabel; import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.dozmod.gui.helper.I18n; import org.openslx.dozmod.gui.helper.Language; public class ConfigWindowLayout extends JDialog { /** * Version for serialization. */ private static final long serialVersionUID = -9134937794208526938L; protected final JRadioButton btnProxyNone; protected final JRadioButton btnProxyAuto; protected final JRadioButton btnProxySocks = null; protected final JRadioButton btnProxyHttp = null; protected final JCheckBox chkSendMeMail; protected final QLabel lblYourAddress; protected final JSlider sldFontSize; protected final JSlider sldConnections; protected ButtonGroup btnGroupLookAndFeel = null; protected final ComboBox cboLanguage; protected final JButton btnSave; protected final JButton btnClose; public ConfigWindowLayout(Window modalParent) { super(modalParent, I18n.WINDOW_LAYOUT.getString("Config.Dialog.title", Branding.getApplicationName()), modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); // regular layout as a helper for the whole page getContentPane().setLayout(new BorderLayout()); Insets headingInset = new Insets(16, 12, 3, 3); // Panel to add everything into, needed for the border. JPanel contentPanel = new JPanel(); getContentPane().add(contentPanel, BorderLayout.CENTER); GridManager grid = new GridManager(contentPanel, 1, false, new Insets(4, 3, 1, 3)); // mail config grid.add(new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.mailNotifications.text"), true, false)) .insets(headingInset) .expand(true, false) .fill(true, false); chkSendMeMail = new JCheckBox(I18n.WINDOW_LAYOUT.getString("Config.CheckBox.sendMeMail.text")); grid.add(chkSendMeMail).fill(true, false).expand(true, false); grid.add( new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.sendMeMail.text"), false, true)) .expand(true, false) .fill(true, false); lblYourAddress = new QLabel(); grid.add(lblYourAddress).fill(true, false).expand(true, false); // proxy config grid.add(new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.proxyConfig.text"), true, false)) .insets(headingInset) .fill(true, false) .expand(true, false); JPanel radioGroupPanel = new JPanel(); radioGroupPanel.setLayout(new BoxLayout(radioGroupPanel, BoxLayout.LINE_AXIS)); // radio buttons ButtonGroup radioGroup = new ButtonGroup(); btnProxyNone = new JRadioButton(I18n.WINDOW_LAYOUT.getString("Config.RadioButton.proxyNone.text")); btnProxyAuto = new JRadioButton(I18n.WINDOW_LAYOUT.getString("Config.RadioButton.proxyAuto.text")); radioGroup.add(btnProxyNone); radioGroup.add(btnProxyAuto); radioGroupPanel.add(btnProxyNone); radioGroupPanel.add(btnProxyAuto); grid.add(radioGroupPanel).expand(true, false).fill(true, false); // font config grid.add(new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.fontConfig.text"), true, false)) .insets(headingInset) .fill(true, false) .expand(true, false); grid.add( new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.fontConfigInfo.text"), false, true)) .expand(true, false) .fill(true, false); UIManager.put("Slider.paintValue", false); sldFontSize = new JSlider(JSlider.HORIZONTAL); sldFontSize.setModel(new DefaultBoundedRangeModel(100, 0, Config.FONT_SCALING_MIN, Config.FONT_SCALING_MAX)); sldFontSize.setMinorTickSpacing(5); sldFontSize.setMajorTickSpacing(25); sldFontSize.setSnapToTicks(true); sldFontSize.setPaintTicks(true); sldFontSize.setPaintLabels(true); grid.add(sldFontSize).fill(true, false).expand(true, false); // look and feel grid.add(new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.lookAndFeel.text"), true, false)) .insets(headingInset) .fill(true, false) .expand(true, false); grid.add(new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.lookAndFeelInfo.text"), false, true)) .fill(true, false) .expand(true, false); JPanel lafGroupPanel = new JPanel(); lafGroupPanel.setLayout(new BoxLayout(lafGroupPanel, BoxLayout.LINE_AXIS)); btnGroupLookAndFeel = new ButtonGroup(); for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) { JRadioButton btn = new JRadioButton(laf.getName()); btn.setToolTipText(laf.getClassName()); btnGroupLookAndFeel.add(btn); lafGroupPanel.add(btn); } grid.add(lafGroupPanel).expand(true, false).fill(true, false); // Concurrent Connections grid.add(new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.concurrentConnections.text"), true, false)) .insets(headingInset) .fill(true, false) .expand(true, false); grid.add( new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.concurrentConnectionsInfo.text"), false, true)) .fill(true, false) .expand(true, false); sldConnections = new JSlider(JSlider.HORIZONTAL); sldConnections.setModel(new DefaultBoundedRangeModel(1, 0, 1, 4)); sldConnections.setMajorTickSpacing(1); sldConnections.setPaintTicks(true); sldConnections.setPaintLabels(true); grid.add(sldConnections).expand(true, false).fill(true, false); // Language grid.add(new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.language.text"), true, false)) .insets(headingInset) .fill(true, false) .expand(true, false); grid.add( new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.languageInfo.text"), false, true)) .fill(true, false) .expand(true, false); cboLanguage = new ComboBox(new ComboBox.ComboBoxRenderer() { @Override public String renderItem(Language item) { return item.displayName; } }, Language.class); cboLanguage.setModel(new DefaultComboBoxModel<>(Language.values())); grid.add(cboLanguage).fill(true, false).expand(true, false); // Finish grid.finish(true); // bottom button panel JPanel buttonPanel = new JPanel(); btnClose = new JButton(I18n.WINDOW_LAYOUT.getString("Config.Button.close.text")); btnSave = new JButton(I18n.WINDOW_LAYOUT.getString("Config.Button.save.text")); buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); buttonPanel.add(Box.createGlue()); buttonPanel.add(btnClose); buttonPanel.add(btnSave); getContentPane().add(buttonPanel, BorderLayout.PAGE_END); } }