summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/LectureCreationPageLayout.java
blob: 458fc7291cb8043448afdaa4402e1e6996e8f20f (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
package org.openslx.dozmod.gui.wizard.layout;

import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;

import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpinnerDateModel;
import javax.swing.border.TitledBorder;
import javax.swing.text.DateFormatter;

import org.jdatepicker.impl.JDatePanelImpl;
import org.jdatepicker.impl.JDatePickerImpl;
import org.jdatepicker.impl.UtilDateModel;
import org.openslx.dozmod.gui.helper.GridPos;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.WizardPage;
import org.openslx.dozmod.util.DateLabelFormatter;

@SuppressWarnings("serial")
public abstract class LectureCreationPageLayout extends WizardPage {

	protected JTextField lectureNameTextField;
	protected JTextArea descriptionText;
	protected JDatePickerImpl startDate;
	protected JDatePickerImpl endDate;
	protected JSpinner startTime;
	protected JSpinner endTime;
	protected JCheckBox networkAccessCheck;
	protected JCheckBox examCheck;
	protected JCheckBox autoUpdate;
	// permissions checks
	protected JCheckBox editPermissionsCheck;
	protected JCheckBox adminPermissionsCheck;
	protected JCheckBox enabledCheck;

	private static final Properties pickerStrings = new Properties();

	static {
		pickerStrings.put("text.today", "Heute");
		pickerStrings.put("text.month", "Monat");
		pickerStrings.put("text.year", "Jahr");
	}

	/**
	 * Page for creating lectures
	 * 
	 * @param editExistingLecture whether to edit existing lecture or create new
	 *            one
	 */
	public LectureCreationPageLayout(Wizard wizard, String title) {
		super(wizard, title);
		setDescription("Geben Sie bitte einen aussagekräftigen Namen für die neue Veranstaltung ein");
		setLayout(new GridBagLayout());

		// helper index
		int row = 0;

		// lecture name
		JLabel lectureNameLabel = new JLabel("Veranstaltungsname");
		lectureNameTextField = new JTextField();
		add(lectureNameLabel, GridPos.get(0, row));
		add(lectureNameTextField, GridPos.get(1, row++, 2, 1, true, false));

		JLabel descriptionCaption = new JLabel("Beschreibung");
		descriptionText = new JTextArea(3, 50);
		descriptionText.setLineWrap(true);
		descriptionText.setWrapStyleWord(true);
		JScrollPane descPane = new JScrollPane(descriptionText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		descriptionText.setMinimumSize(new Dimension(0, 60));
		descPane.setMinimumSize(descriptionText.getMinimumSize());
		add(descriptionCaption, GridPos.get(0, row));
		add(descPane, GridPos.get(1, row++, 2, 1, true, false));

		// Start date/time
		JLabel startDateLabel = new JLabel("Startdatum");
		startDate = new JDatePickerImpl(new JDatePanelImpl(new UtilDateModel(new Date()), pickerStrings),
				new DateLabelFormatter());
		startTime = makeTimeSpinner(0, 0);
		add(startDateLabel, GridPos.get(0, row));
		add(startDate, GridPos.get(1, row));
		add(startTime, GridPos.get(2, row++));

		JLabel endDateLabel = new JLabel("Enddatum");
		endDate = new JDatePickerImpl(new JDatePanelImpl(new UtilDateModel(new Date()), pickerStrings),
				new DateLabelFormatter());
		endTime = makeTimeSpinner(23, 59);
		add(endDateLabel, GridPos.get(0, row));
		add(endDate, GridPos.get(1, row));
		add(endTime, GridPos.get(2, row++));

		add(Box.createVerticalStrut(10), GridPos.get(0, row++, 3, 1));

		// Options related to exams
		examCheck = new JCheckBox("Veranstaltung ist eine Prüfung");
		add(examCheck, GridPos.get(0, row++, 3, 1));

		networkAccessCheck = new JCheckBox("Internet verfügbar");
		add(networkAccessCheck, GridPos.get(0, row++, 3, 1));

		autoUpdate = new JCheckBox("Aktuellste Imageversion verwenden");
		add(autoUpdate, GridPos.get(0, row++, 3, 1));

		add(Box.createVerticalStrut(10), GridPos.get(0, row++, 3, 1));

		// -- default permissions group --
		JPanel permissionsGroup = new JPanel();
		permissionsGroup.setBorder(new TitledBorder("Standardberechtigungen"));

		editPermissionsCheck = new JCheckBox("Bearbeiten");
		adminPermissionsCheck = new JCheckBox("Administrieren");
		permissionsGroup.add(editPermissionsCheck);
		permissionsGroup.add(adminPermissionsCheck);
		add(permissionsGroup, GridPos.get(0, row++, 3, 1, true, false));
		enabledCheck = new JCheckBox("Vorlesung ist aktiv", true);
		add(enabledCheck, GridPos.get(0, row++, 3, 1));
		add(Box.createVerticalGlue(), GridPos.get(0, row++, 3, 1, true, true));
	}

	private JSpinner makeTimeSpinner(int h, int m) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.HOUR_OF_DAY, h); // 24 == 12 PM == 00:00:00
		calendar.set(Calendar.MINUTE, m);
		calendar.set(Calendar.SECOND, 0);
		SpinnerDateModel model = new SpinnerDateModel();
		model.setValue(calendar.getTime());
		JSpinner spinner = new JSpinner(model);
		JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner, "HH:mm");
		DateFormatter formatter = (DateFormatter) editor.getTextField().getFormatter();
		formatter.setAllowsInvalid(false); // this makes what you want
		formatter.setOverwriteMode(true);
		spinner.setEditor(editor);
		return spinner;
	}

}