summaryrefslogblamecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java
blob: d405ba169b564e308a5b8bf71243e3b32e17e917 (plain) (tree)
1
2
3
4
5
6
7
8


                                             
                      

                      
                                   
                       


                            



                                 

                             

                           
                          

                               
                            
                               

                              

                                      
 


                                            
                                                         
                                  
                                                           

                                                                

                                                                     
                                                  
                                                      
                                             
                                                    
                                                 
                                                     
                                                  

                                            



                                                                  

                                                                                                    
                                           
                                                 
                                                
                                            
                                             
                                                 
                                             
                                               
                                             
                                               


                                             
                                                
                                              
                                                                  

                                                       
                                                  
                                              
 
                                         
                                           


                                               
                                        

                                               
                                                 
 



                                                     
 
                                          




                                                                            
 

                                                                         








                                               





                                                         
                                                              

                                                                
                                   
                                                                   

                                                               


























































                                                                                         
                                           


                                                                                  
 

                                                 
                                                 
                                                      



                                                                         


                                                                        










                                                                               
 


                                                        



                                                                 
 
 
                               
                       
                                            


                                                                    
                                        
                                                      

                                                               
 

                                         
                                                                                    
                                 

                                                                             






                                                                                                           

                                                                                                          


                                                 
                                                           

                                                                                             
                                                                     
                                                                   
                                                                    



                                                                   
 
                                            
                                                     



                                                                              
                                                          


                                                       

                                                                                 


                                                         
 
                                          
                                                   



                                                                                             


                                                     

                                                                             

























                                                                                                                                                                                       
                                                                                                                                                                                                                   






                                                              
                                                                                                                                                              























































                                                                                                        


                                                                                                      

                                                                       

                                                               


                                                                    

                                                                                    
                                                     
                                                          



                                                  

                                                  
                                                
                                                 

                                                     


                                                           
                                                      





                                                                                       

                                                                               
                                                  



                                                 
 
package org.openslx.dozmod.gui.window.layout;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;

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.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
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.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.AdvancedConfigurator;
import org.openslx.dozmod.gui.control.ComboBox;
import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer;
import org.openslx.dozmod.gui.control.LectureCustomPermissionManager;
import org.openslx.dozmod.gui.control.LocationSelector;
import org.openslx.dozmod.gui.control.PersonLabel;
import org.openslx.dozmod.gui.control.QDatePickerImpl;
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.thrift.cache.MetaDataCache;
import org.openslx.dozmod.util.DateLabelFormatter;
import org.openslx.dozmod.util.FormatHelper;
import org.openslx.thrifthelper.Comparators;

@SuppressWarnings("serial")
public abstract class LectureDetailsWindowLayout extends JDialog {

	// stuff ending in '...Info' are supposed to be the read-only labels for the information tab
	protected final QLabel lblTitleInfo;
	protected final JTextArea txtTitle;
	protected final JTextArea txtDescription;
	protected final QLabel lblImageNameInfo;
	protected final QLabel txtImageName;
	protected final JButton btnLinkImage;
	protected final PersonLabel lblOwnerInfo;
	protected final PersonLabel lblOwner;
	protected final JButton btnChangeOwner;
	protected final QLabel lblCreateTime;
	protected final PersonLabel lblUpdater;
	protected final QLabel lblUpdateTime;
	protected final QLabel lblStartTime;
	protected final QLabel lblEndTime;
	protected final JCheckBox chkAutoUpdate;
	protected final QLabel lblVersionInfo;
	protected final ComboBox<ImageVersionDetails> cboVersions;
	protected final JCheckBox chkIsExam;
	protected final JCheckBox chkHasInternetAccess;
	protected final JCheckBox chkHasUsbAccess;
	protected final JCheckBox chkIsActive;

	protected final JTextField txtId;
	protected final QLabel lblUseCount;

	protected final JButton btnPermissions;

	protected final QLabel lblError;
	protected final JButton btnSaveChanges;
	protected final JButton btnClose;
	protected final JButton btnDownloadImage;

	protected final JDatePickerImpl dtpStartDate;
	protected final JDatePickerImpl dtpEndDate;
	protected final JSpinner spnStartTime;
	protected final JSpinner spnEndTime;

	protected Color dateTimeTextColor;
	
	protected JTabbedPane pnlTabs;
	protected final LectureCustomPermissionManager ctlPermissionManager;
	protected final LocationSelector ctlLocationSelector;
	protected final AdvancedConfigurator ctlAdvancedConfigurator;

	private static final Properties pickerStrings = new Properties();

	protected JCheckBox chkCustomPermEdit;
	protected JCheckBox chkCustomPermAdmin;
	protected JPanel pnlTabGeneral;
	protected JPanel pnlTabInfo;
	protected JPanel pnlTabRestrictions;
	protected JPanel pnlTabPermissions;
	protected JPanel pnlTabLocations;
	protected JPanel pnlTabAdvanced;

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

	public LectureDetailsWindowLayout(Frame modalParent) {
		super(modalParent, "Veranstaltungsdetails",
				ModalityType.APPLICATION_MODAL);
		setResizable(true);
		setPreferredSize(Gui.getScaledDimension(525, 550));
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setLayout(new BorderLayout());
		((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(
				10, 10, 10, 10));

		pnlTabInfo = new JPanel();
		pnlTabInfo.setBorder(BorderFactory.createEmptyBorder(25, 25, 25, 25));
		GridManager grdInfo = new GridManager(pnlTabInfo, 3, true, new Insets(7,
				7, 7, 7));
		
		// title
		lblTitleInfo = new QLabel();
		lblTitleInfo.setFont(lblTitleInfo.getFont().deriveFont(Font.BOLD,
				lblTitleInfo.getFont().getSize2D() * 1.5f));
		grdInfo.add(lblTitleInfo, 3);
		grdInfo.nextRow();
		// lblOwner
		lblOwnerInfo = new PersonLabel();
		grdInfo.add(new QLabel("Besitzer"));
		grdInfo.add(lblOwnerInfo, 2).expand(true, false);
		grdInfo.nextRow();
		// creation time
		lblCreateTime = new QLabel();
		grdInfo.add(new QLabel("Erstellt am"));
		grdInfo.add(lblCreateTime, 2);
		grdInfo.nextRow();

		// last updater
		lblUpdater = new PersonLabel();
		grdInfo.add(new QLabel("Geändert durch"));
		grdInfo.add(lblUpdater, 2);
		grdInfo.nextRow();

		// last updated
		lblUpdateTime = new QLabel();
		grdInfo.add(new QLabel("Geändert am"));
		grdInfo.add(lblUpdateTime, 2);
		grdInfo.nextRow();
		lblVersionInfo = new QLabel(); // UNUSED
		lblImageNameInfo = new QLabel();
		grdInfo.add(new QLabel("Verknüpfte VM"), 2);
		grdInfo.add(lblImageNameInfo);
		grdInfo.nextRow();
		lblStartTime = new QLabel();
		grdInfo.add(new QLabel("Startdatum"), 2);
		grdInfo.add(lblStartTime);
		grdInfo.nextRow();
		lblEndTime = new QLabel();
		grdInfo.add(new QLabel("Enddatum"), 2);
		grdInfo.add(lblEndTime);
		grdInfo.nextRow();
		lblUseCount = new QLabel();
		grdInfo.add(new QLabel("Aufrufe"));
		grdInfo.add(lblUseCount, 2);
		grdInfo.finish(true);

		pnlTabGeneral = new JPanel();
		pnlTabGeneral.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		GridManager grdGeneral = new GridManager(pnlTabGeneral, 5, true,
				new Insets(3, 3, 3, 3));
		// lecture title
		txtTitle = new JTextArea();
		grdGeneral.add(new QLabel("Name"));
		grdGeneral.add(txtTitle, 4).expand(true, false).fill(true, false);
		grdGeneral.nextRow();

		// description
		txtDescription = new JTextArea();
		txtDescription.setLineWrap(true);
		txtDescription.setWrapStyleWord(true);
		grdGeneral.add(new QLabel("Beschreibung")).anchor(
				GridBagConstraints.FIRST_LINE_START);
		JScrollPane jsp = new JScrollPane(txtDescription,
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		jsp.setMinimumSize(Gui.getScaledDimension(450, 120));
		jsp.setPreferredSize(Gui.getScaledDimension(450, 120));
		grdGeneral.add(jsp, 4).expand(true, true).fill(true, true);
		grdGeneral.nextRow();

		// ID. NOTE: currently disabled
		txtId = new JTextField();
		txtId.setEditable(false);
		txtId.setFont(txtId.getFont().deriveFont(Font.BOLD,
				txtId.getFont().getSize2D() * 0.66f));
		grdGeneral.add(new QLabel("ID"));
		grdGeneral.add(txtId, 4).expand(true, false).fill(true, false);
		grdGeneral.nextRow();

		// owner
		lblOwner = new PersonLabel();
		btnChangeOwner = new JButton("Ändern");
		grdGeneral.add(new QLabel("Besitzer"));
		grdGeneral.add(lblOwner, 3).expand(true, false);
		grdGeneral.add(btnChangeOwner).fill(true, false);
		grdGeneral.nextRow();


		// linked image
		// name
		txtImageName = new QLabel();
		grdGeneral.add(new QLabel("Verknüpfte VM"));
		grdGeneral.add(txtImageName, 3).expand(true, false);
		
		// link button for image
		btnLinkImage = new JButton("Ändern");
		grdGeneral.add(btnLinkImage).fill(true, false);
		grdGeneral.nextRow();

		// image version handling
		// auto update
		chkAutoUpdate = new JCheckBox("Immer aktuellste Version verwenden");
		// versions combo
		cboVersions = new ComboBox<>(Comparators.imageVersionDetails,
				new ComboBoxRenderer<ImageVersionDetails>() {
					@Override
					public String renderItem(ImageVersionDetails item) {
						if (item == null)
							return null;
						if (item.isValid) {
							return FormatHelper.longDate(item.getCreateTime());
						} else {
							return FormatHelper.longDate(item.getCreateTime())
									+ " [ungültig]";
						}
					}
				});
		btnDownloadImage = new JButton("Download");
		btnDownloadImage
				.setToolTipText("Momentan verwendete Version herunterladen");
		JPanel versionPanel = new JPanel(new BorderLayout());
		versionPanel.add(cboVersions, BorderLayout.CENTER);
		versionPanel.add(chkAutoUpdate, BorderLayout.SOUTH);
		grdGeneral.add(new QLabel("VM-Version"));
		grdGeneral.add(versionPanel, 3);
		grdGeneral.add(btnDownloadImage).fill(true, false);
		grdGeneral.nextRow();

		// start time of the lecture
		JPanel startTimePanel = new JPanel();
		startTimePanel.setLayout(new BoxLayout(startTimePanel,
				BoxLayout.LINE_AXIS));
		dtpStartDate = new QDatePickerImpl(new JDatePanelImpl(
				new UtilDateModel(new Date()), pickerStrings),
				new DateLabelFormatter());
		spnStartTime = makeTimeSpinner(23, 59);
		startTimePanel.add(dtpStartDate);
		startTimePanel.add(spnStartTime);
		startTimePanel.setMinimumSize(startTimePanel.getPreferredSize());
		startTimePanel.setMaximumSize(startTimePanel.getPreferredSize());
		grdGeneral.add(new QLabel("Startdatum"));
		grdGeneral.add(startTimePanel, 4);
		grdGeneral.nextRow();

		// end time of the lecture
		JPanel endTimePanel = new JPanel();
		endTimePanel
				.setLayout(new BoxLayout(endTimePanel, BoxLayout.LINE_AXIS));
		dtpEndDate = new QDatePickerImpl(new JDatePanelImpl(new UtilDateModel(
				new Date()), pickerStrings), new DateLabelFormatter());
		spnEndTime = makeTimeSpinner(00, 59);
		endTimePanel.add(dtpEndDate);
		endTimePanel.add(spnEndTime);
		endTimePanel.setMinimumSize(endTimePanel.getPreferredSize());
		endTimePanel.setMaximumSize(endTimePanel.getPreferredSize());
		grdGeneral.add(new QLabel("Enddatum"));
		grdGeneral.add(endTimePanel, 4);
		grdGeneral.nextRow();

		// lecture active
		chkIsActive = new JCheckBox("Veranstaltung aktiv");
		grdGeneral.skip();
		grdGeneral.add(chkIsActive, 4);
		grdGeneral.nextRow();
		grdGeneral.finish(true);

		pnlTabRestrictions = new JPanel();
		GridManager grdRestrictions = new GridManager(pnlTabRestrictions, 2, true,
				new Insets(3, 3, 3, 3));

		// "restrictions": internet access / usb access / exam
		grdRestrictions.add(new JLabel("Internetzugriff"));
		chkHasInternetAccess = new JCheckBox("zulassen");
		grdRestrictions.add(new WordWrapLabel("Legen Sie hier fest, ob die Veranstaltung Zugriff zum Internet haben soll", false, true)).fill(true, false).expand(true, false);
		grdRestrictions.nextRow();
		grdRestrictions.skip();
		grdRestrictions.add(chkHasInternetAccess).fill(true, false).expand(true, false);
		grdRestrictions.nextRow();

		grdRestrictions.add(new JLabel("Speichermedium-Zugriff"));
		chkHasUsbAccess = new JCheckBox("zulassen");
		grdRestrictions.add(new WordWrapLabel("Legen Sie hier fest, ob die Veranstaltung den Zugriff auf Speichermedien (CD, USB, ...) erlauben soll", false, true)).fill(true, false).expand(true, false);
		grdRestrictions.nextRow();
		grdRestrictions.skip();
		grdRestrictions.add(chkHasUsbAccess);
		grdRestrictions.nextRow();

		grdRestrictions.add(new JLabel("E-Prüfung"));
		chkIsExam = new JCheckBox("aktiv");
		grdRestrictions.add(new WordWrapLabel("Markieren Sie diese Veranstaltung als E-Prüfung", false, true)).fill(true, false).expand(true, false);
		grdRestrictions.nextRow();
		grdRestrictions.skip();
		grdRestrictions.add(chkIsExam);
		btnPermissions = new JButton("Ändern");
		grdRestrictions.finish(true);

		/* *******************************************************************************	
		 * 
		 *                        		Tab "Permissions"
		 *
		 ********************************************************************************/
		ctlPermissionManager = new LectureCustomPermissionManager();
		pnlTabPermissions = new JPanel();
		GridManager grdPermissions = new GridManager(pnlTabPermissions, 1, false);
		JPanel defaultPermissionPane = new JPanel();
		defaultPermissionPane.setBorder(BorderFactory.createTitledBorder("Andere Nutzer"));
		chkCustomPermEdit = new JCheckBox("Bearbeiten");
		chkCustomPermAdmin = new JCheckBox("Admin");
		defaultPermissionPane.add(chkCustomPermEdit);
		defaultPermissionPane.add(chkCustomPermAdmin);
		grdPermissions.add(ctlPermissionManager).fill(true, true).expand(true, true);
		grdPermissions.nextRow();
		grdPermissions.add(defaultPermissionPane).fill(true, false).expand(true, false);
		grdPermissions.finish(false);

		/* *******************************************************************************	
		 * 
		 *                        		Tab "Locations"
		 *
		 ********************************************************************************/
		ctlLocationSelector = new LocationSelector();
		pnlTabLocations = new JPanel();
		GridManager grdLocations = new GridManager(pnlTabLocations, 1, false); 
		grdLocations.add(ctlLocationSelector).fill(true, true).expand(true, true);
		grdLocations.finish(false);

		/* *******************************************************************************	
		 * 
		 *                        		Tab "Advanced"
		 *
		 ********************************************************************************/
		ctlAdvancedConfigurator = new AdvancedConfigurator();
		pnlTabAdvanced = new JPanel();
		GridManager grdAdvanced = new GridManager(pnlTabAdvanced, 1, false); 
		grdAdvanced.add(ctlAdvancedConfigurator).fill(true, true).expand(true, true);
		grdAdvanced.finish(false);

		/* *******************************************************************************	
		 * 
		 *                        Main panel containing the tabs 
		 *
		 ********************************************************************************/
		// finally build the tabbedPane and add it to the main view
		pnlTabs = new JTabbedPane();
		pnlTabs.addTab("Übersicht", pnlTabInfo);
		pnlTabs.addTab("Allgemein", pnlTabGeneral);
		// TODO enable when restriction stuff is done
		// pnlTabs.addTab("Beschränkungen", pnlTabRestrictions);
		if (MetaDataCache.getLocations() != null && !MetaDataCache.getLocations().isEmpty()) {
			pnlTabs.addTab("Raumauswahl", pnlTabLocations);
		}
		// TODO enable when advanced stuff is done
		// pnlTabs.addTab("Erweitert", pnlTabAdvanced);
		pnlTabs.addTab("Berechtigungen", pnlTabPermissions);
		add(pnlTabs, BorderLayout.CENTER);
		// usage counter + button panel on the bottom
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
		btnClose = new JButton("Schließen");
		btnSaveChanges = new JButton("Speichern");
		lblError = new QLabel("");
		lblError.setForeground(Color.RED);
		buttonPanel.add(Box.createGlue());
		buttonPanel.add(lblError);
		buttonPanel.add(Box.createGlue());
		buttonPanel.add(btnClose);
		buttonPanel.add(btnSaveChanges);
		// buttons at the end of the page
		add(buttonPanel, BorderLayout.SOUTH);
	}

	private JSpinner makeTimeSpinner(int h, int m) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.HOUR_OF_DAY, h);
		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);
		formatter.setOverwriteMode(true);
		spinner.setEditor(editor);
		return spinner;
	}
}