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

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.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerDateModel;
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 JDatePickerImpl startDate;
	protected JDatePickerImpl endDate;
	protected JSpinner startTime;
	protected JSpinner endTime;
	protected JCheckBox networkAccessCheck;
	protected JCheckBox examCheck;

	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) {
		super(wizard, "Eingabe Ihrer Daten");
		setDescription("Geben Sie bitte einen aussagekräftigen Namen für die neue Veranstaltung ein");

		setLayout(new GridBagLayout());

		// lecture name
		JLabel lectureNameLabel = new JLabel("Veranstaltungsname");
		lectureNameTextField = new JTextField();
		add(lectureNameLabel, GridPos.get(0, 0));
		add(lectureNameTextField, GridPos.get(1, 0, 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, 1));
		add(startDate, GridPos.get(1, 1));
		add(startTime, GridPos.get(2, 1));

		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, 2));
		add(endDate, GridPos.get(1, 2));
		add(endTime, GridPos.get(2, 2));

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

		// Options related to exams
		examCheck = new JCheckBox("Veranstaltung ist eine Prüfung");
		networkAccessCheck = new JCheckBox("Internet verfügbar");
		add(examCheck, GridPos.get(1, 4, 2, 1));
		add(examCheck, GridPos.get(1, 5, 2, 1));

		add(Box.createVerticalGlue(), GridPos.get(0, 6, 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;
	}

}