summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java
blob: 432654f7667f5b7cee51cf2cb2220b7f7e80bf07 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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.Config.FileTransferMode;
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 ButtonGroup btnGroupTransferEnc = null;

	protected final ComboBox<Language> 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);
		
		// Transfer SSL or plain
		grid.add(new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.transferEncryption.text"),
				true, false))
		.insets(headingInset)
		.fill(true, false)
		.expand(true, false);
		JPanel encGroupPanel = new JPanel();
		encGroupPanel.setLayout(new BoxLayout(encGroupPanel, BoxLayout.LINE_AXIS));
		btnGroupTransferEnc = new ButtonGroup();

		for (FileTransferMode mode : Config.FileTransferMode.values()) {
			JRadioButton btn = new JRadioButton(I18n.WINDOW_LAYOUT.getString("Config.Button.transfermode." + mode.name()));
			btn.setToolTipText(mode.name());
			btnGroupTransferEnc.add(btn);
			encGroupPanel.add(btn);
		}
		grid.add(encGroupPanel).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<Language>(new ComboBox.ComboBoxRenderer<Language>() {
			@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);

		
	}

}