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 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.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.JDatePicker; import org.openslx.bwlp.thrift.iface.ImageVersionDetails; import org.openslx.dozmod.Branding; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.configurator.LdapFilterConfigurator; import org.openslx.dozmod.gui.configurator.LecturePermissionConfigurator; import org.openslx.dozmod.gui.configurator.NetrulesConfigurator; import org.openslx.dozmod.gui.configurator.NetshareConfigurator; import org.openslx.dozmod.gui.configurator.StartupConfigurator; import org.openslx.dozmod.gui.control.ComboBox; import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer; 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.Session; import org.openslx.dozmod.thrift.cache.MetaDataCache; import org.openslx.dozmod.util.FormatHelper; import org.openslx.sat.thrift.version.Feature; 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 JTextField 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 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 QLabel lblError; protected final JButton btnSaveChanges; protected final JButton btnClose; protected final JButton btnDownloadImage; protected final JDatePicker dtpStartDate; protected final JDatePicker dtpEndDate; protected final JSpinner spnStartTime; protected final JSpinner spnEndTime; protected final JTabbedPane pnlTabs; protected final LecturePermissionConfigurator ctlPermissionManager; protected final LocationSelector ctlLocationSelector; protected final StartupConfigurator ctlRunscriptConfigurator; protected final NetshareConfigurator ctlNetshareConfigurator; protected final LdapFilterConfigurator ctlLdapFilterConfigurator; protected final NetrulesConfigurator ctlNetrulesConfigurator; protected final JCheckBox chkCustomPermEdit; protected final JCheckBox chkCustomPermAdmin; protected final JPanel pnlTabGeneral; protected final JPanel pnlTabInfo; protected final JPanel pnlTabNetrules; protected final JPanel pnlTabRestrictions; protected final JPanel pnlTabPermissions; protected final JPanel pnlTabLocations; protected final JPanel pnlTabRunscript; protected final JPanel pnlTabNetshare; protected final JPanel pnlTabLdapFilter; public LectureDetailsWindowLayout(Frame modalParent) { super(modalParent, "Veranstaltungsdetails", ModalityType.APPLICATION_MODAL); setResizable(true); setPreferredSize(Gui.getScaledDimension(570, 650)); 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); // Make general tab 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 JTextField(); 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() { @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(); 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(); 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); Insets descriptionInset = new Insets(2, 4, 2, 4); Insets firstInset = new Insets(12, 4, 2, 4); // Network rules pnlTabNetrules = new JPanel(); GridManager grdNetrules = new GridManager(pnlTabNetrules, 1, true, new Insets(9, 4, 2, 4)); // "restrictions": internet access / usb access / exam chkHasInternetAccess = new JCheckBox("Netzwerk-/Internetzugriff zulassen"); grdNetrules.add(chkHasInternetAccess).expand(true, false).insets(firstInset); grdNetrules.nextRow(); grdNetrules.add( new WordWrapLabel( "Legen Sie hier fest, ob die Veranstaltung Zugriff zum Internet haben soll." + " In der Liste können Sie bestimmte Adressen und Services" + " ein- oder ausschließen.", false, true)) .fill(true, false) .expand(true, false) .insets(descriptionInset); grdNetrules.nextRow(); ctlNetrulesConfigurator = new NetrulesConfigurator(); grdNetrules.add(ctlNetrulesConfigurator).fill(true, true).expand(true, true); grdNetrules.nextRow(); grdNetrules.finish(false); // Tab restrictions pnlTabRestrictions = new JPanel(); GridManager grdRestrictions = new GridManager(pnlTabRestrictions, 2, true, new Insets(9, 4, 2, 4)); chkHasUsbAccess = new JCheckBox("Externe Speichermedien zulassen"); grdRestrictions.add(chkHasUsbAccess, 2); grdRestrictions.nextRow(); grdRestrictions.add( new WordWrapLabel("Legen Sie hier fest, ob die Veranstaltung den Zugriff" + " auf Speichermedien (CD, USB, ...) erlauben soll", false, true), 2) .fill(true, false) .expand(true, false) .insets(descriptionInset); grdRestrictions.nextRow(); chkIsExam = new JCheckBox("Prüfungsmodus"); grdRestrictions.add(chkIsExam, 2); grdRestrictions.nextRow(); grdRestrictions.add( new WordWrapLabel( "Markieren Sie diese Veranstaltung als E-Prüfung.\n" + "Die Veranstaltung wird nur dann startbar sein, wenn " + Branding.getServiceName() + " in den" + " Prüfungsmodus versetzt wird. Kontaktieren Sie dazu Ihren lokalen " + Branding.getServiceName() + "-Administrator.", false, true), 2) .fill(true, false) .expand(true, false) .insets(descriptionInset); grdRestrictions.finish(true); /* ******************************************************************************* * * Tab "Permissions" * ********************************************************************************/ ctlPermissionManager = new LecturePermissionConfigurator(); 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 "Runscript" * ********************************************************************************/ ctlRunscriptConfigurator = new StartupConfigurator(); pnlTabRunscript = new JPanel(); GridManager grdAdvanced = new GridManager(pnlTabRunscript, 1, false); grdAdvanced.add(ctlRunscriptConfigurator).fill(true, true).expand(true, true); grdAdvanced.finish(false); /* ******************************************************************************* * * Tab "Network-Shares" * ********************************************************************************/ ctlNetshareConfigurator = new NetshareConfigurator(); pnlTabNetshare = new JPanel(); GridManager grdNetshare = new GridManager(pnlTabNetshare, 1, false, new Insets(8, 2, 8, 2)); grdNetshare.add(ctlNetshareConfigurator).fill(true, true).expand(true, true); grdNetshare.finish(false); /* ******************************************************************************* * * Tab "LDAP-Filters" * ********************************************************************************/ ctlLdapFilterConfigurator = new LdapFilterConfigurator(); pnlTabLdapFilter = new JPanel(); GridManager grdLdap = new GridManager(pnlTabLdapFilter, 1, false, new Insets(8, 2, 8, 2)); grdLdap.add(ctlLdapFilterConfigurator).fill(true, true).expand(true, true); grdLdap.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); if (Session.isLectureRestrictionsSupported()) { pnlTabs.addTab("Beschränkungen", pnlTabRestrictions); pnlTabs.addTab("Firewall", pnlTabNetrules); } if (MetaDataCache.getLocations() != null && !MetaDataCache.getLocations().isEmpty()) { pnlTabs.addTab("Raumauswahl", pnlTabLocations); } if (Session.isLectureRestrictionsSupported()) { pnlTabs.addTab("VM-Start", pnlTabRunscript); } pnlTabs.addTab("Berechtigungen", pnlTabPermissions); if (Session.hasFeature(Feature.NETWORK_SHARES)) { pnlTabs.addTab("Netzlaufwerke", pnlTabNetshare); } if (Session.hasFeature(Feature.LECTURE_FILTER_LDAP)) { pnlTabs.addTab("LDAP-Filter", pnlTabLdapFilter); } add(pnlTabs, BorderLayout.CENTER); // usage counter + button panel on the bottom JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); btnClose = new JButton("Schließen"); btnSaveChanges = new JButton("Speichern"); lblError = new QLabel(""); lblError.setForeground(Color.RED); 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; } }