summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/GenericNoticeWindowLayout.java
blob: 2297256e10550c9ecf439bb80491629413078d78 (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
package org.openslx.dozmod.gui.window.layout;

import java.awt.BorderLayout;
import java.awt.Frame;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import org.openslx.dozmod.Branding;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.QLabel;
import org.openslx.dozmod.gui.helper.GridManager;
import org.openslx.dozmod.gui.helper.I18n;

public abstract class GenericNoticeWindowLayout extends JDialog {

	/**
	 * Version for serialization.
	 */
	private static final long serialVersionUID = 265942744790417984L;

	protected String info = I18n.WINDOW_LAYOUT.getString("GenericNotice.Label.noticePanel.text");
	protected JTextArea notice;
	protected JScrollPane disclaimerPanel;

	protected String checkboxText = I18n.WINDOW_LAYOUT.getString("GenericNotice.CheckBox.agree.text");

	private static String title = Branding.getApplicationName();

	// Buttons
	protected final JCheckBox chkAgreeBox;
	protected final JButton btnContinue;

	public GenericNoticeWindowLayout(Frame modalParent) {
		super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL
				: ModalityType.MODELESS);
		this.setLayout(new BorderLayout());

		// Panel used for creating border. We'll add everything into this.
		JPanel borderPanel = new JPanel();
		borderPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
		add(borderPanel);

		// information before the notice
		QLabel noticePanel = new QLabel();
		noticePanel.setBorder(BorderFactory.createTitledBorder(
				I18n.WINDOW_LAYOUT.getString("GenericNotice.TitledBorder.noticePanel.title")));
		noticePanel.setText(info);

		// the disclaimer text box with scrolling functionality
		notice = new JTextArea(30, 20);
		notice.setEditable(false);
		notice.setLineWrap(true);
		notice.setWrapStyleWord(true);
		disclaimerPanel = new JScrollPane(notice, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

		// checkbox for acknowledging the notice
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
		chkAgreeBox = new JCheckBox(checkboxText);
		chkAgreeBox.setEnabled(false);
		buttonPanel.add(chkAgreeBox);
		// spacer
		buttonPanel.add(Box.createHorizontalGlue());
		// the continue button
		btnContinue = new JButton(I18n.WINDOW_LAYOUT.getString("GenericNotice.Button.continue.text"));
		btnContinue.setEnabled(false);
		buttonPanel.add(btnContinue);

		// put everything together
		GridManager grid = new GridManager(borderPanel, 1);
		grid.add(noticePanel).fill(true, false).expand(true, false);
		grid.nextRow();

		grid.add(disclaimerPanel).fill(true, true).expand(true, true);
		grid.nextRow();

		grid.add(buttonPanel).fill(true, false).expand(true, false);
		grid.finish(false);

		pack();
		if (modalParent != null) {
			Gui.centerShellOverShell(modalParent, this);
		}
	}

	public void setNoticeText(String text) {
		if (notice != null) {
			notice.setText(text);
			notice.setCaretPosition(0);
		}
	}
}