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

import java.util.Calendar;

import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.JEditorPane;
import javax.swing.SpinnerDateModel;
import javax.swing.text.DateFormatter;

import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.QDatePickerImpl;
import org.openslx.dozmod.gui.control.QLabel;
import org.openslx.dozmod.gui.helper.GridManager;
import org.openslx.dozmod.gui.helper.I18n;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.WizardPage;

import java.awt.Dimension;

public abstract class LectureCreationPageLayout extends WizardPage {

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

	protected final JTextField txtName;
	protected final JEditorPane txtDescription;
	protected final QDatePickerImpl dtpStartDate;
	protected final QDatePickerImpl dtpEndDate;
	protected final JSpinner spnStartTime;
	protected final JSpinner spnEndTime;
	protected final QLabel lblCalcPeriod;

	/**
	 * 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(I18n.PAGE_LAYOUT.getString("LectureCreation.WizardPage.description"));
		GridManager grid = new GridManager(this, 3);

		// lecture name
		txtName = new JTextField();
		grid.add(new QLabel(I18n.PAGE_LAYOUT.getString("LectureCreation.Label.name.text")));
		grid.add(txtName, 2).fill(true, false).expand(true, false);
		grid.nextRow();

		// description
		txtDescription = new JEditorPane();
		txtDescription.setPreferredSize(new Dimension(600,800));
		JScrollPane descPane = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		txtDescription.setMinimumSize(Gui.getScaledDimension(0, 60));
		descPane.setMinimumSize(txtDescription.getMinimumSize());
		grid.add(new QLabel(I18n.PAGE_LAYOUT.getString("LectureCreation.Label.description.text")));
		grid.add(descPane, 2).fill(true, false).expand(true, false);
		grid.nextRow();

		// Start date/time
		dtpStartDate = new QDatePickerImpl();
		spnStartTime = makeTimeSpinner(0, 0);
		grid.add(new QLabel(I18n.PAGE_LAYOUT.getString("LectureCreation.Label.startTime.text")));
		grid.add(dtpStartDate).fill(true, false).expand(true, false);
		grid.add(spnStartTime);
		grid.nextRow();

		dtpEndDate = new QDatePickerImpl();
		spnEndTime = makeTimeSpinner(23, 59);
		grid.add(new QLabel(I18n.PAGE_LAYOUT.getString("LectureCreation.Label.endTime.text")));
		grid.add(dtpEndDate).fill(true, false).expand(true, false);
		grid.add(spnEndTime);
		grid.nextRow();

		grid.add(new QLabel(I18n.PAGE_LAYOUT.getString("LectureCreation.Label.period.text")));
		lblCalcPeriod = new QLabel();
		grid.add(lblCalcPeriod, 2);
		grid.nextRow();

		grid.finish(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;
	}

}