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 javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.ShareMode;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.ComboBox;
import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer;
import org.openslx.dozmod.gui.control.PersonLabel;
import org.openslx.dozmod.gui.control.QLabel;
import org.openslx.dozmod.gui.control.table.ImageVersionTable;
import org.openslx.dozmod.gui.control.table.QScrollPane;
import org.openslx.dozmod.gui.helper.GridManager;
import org.openslx.thrifthelper.Comparators;
@SuppressWarnings("serial")
public abstract class ImageDetailsWindowLayout extends JDialog {
private static final int ICON_SIZE_Y = 24;
protected final JTextField txtTitle;
protected final JTextArea txtDescription;
protected QLabel lblError;
protected final PersonLabel lblOwner;
protected final JButton btnChangeOwner;
protected final QLabel lblCreateTime;
protected final PersonLabel lblUpdater;
protected final QLabel lblUpdateTime;
protected final ComboBox<OperatingSystem> cboOperatingSystem;
protected final QLabel lblVirtualizer;
protected final JTextField txtTags;
protected final JCheckBox chkIsTemplate;
protected final JComboBox<ShareMode> cboShareMode;
protected final JTextField txtId;
protected final JTextField txtVersion;
protected final JButton btnPermissions;
protected final JButton btnSaveChanges;
protected final JButton btnUpdateImage;
protected final JButton btnUploadToMaster;
protected final JButton btnClose;
protected final JButton btnEditVmx;
protected final JButton btnShowLinkingLectures;
protected final QLabel lblLinkedLectureCount;
protected final ImageVersionTable tblVersions;
protected final QScrollPane scpVersions;
public ImageDetailsWindowLayout(Frame modalParent) {
super(modalParent, "<init>", ModalityType.APPLICATION_MODAL);
setResizable(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
// create left panel for info and buttons and right panel for the table and add
// them to split pane
// use panel to put every info related widget in it
// then we we'll set the panel with BorderLayout.CENTER
JPanel infoPanel = new JPanel();
GridManager grid = new GridManager(infoPanel, 3, true, new Insets(2, 2, 2, 2));
infoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// -- name --
txtTitle = new JTextField();
txtTitle.setFont(txtTitle.getFont().deriveFont(Font.BOLD, txtTitle.getFont().getSize2D() * 2));
grid.add(txtTitle, 3).expand(true, false).fill(true, false);
grid.nextRow();
// description
txtDescription = new JTextArea();
txtDescription.setLineWrap(true);
txtDescription.setWrapStyleWord(true);
grid.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(0, 120));
jsp.setPreferredSize(Gui.getScaledDimension(0, 120));
grid.add(jsp, 2).expand(true, true).fill(true, true);
grid.nextRow();
// owner
lblOwner = new PersonLabel();
btnChangeOwner = new JButton("Ändern");
grid.add(new QLabel("Besitzer"));
grid.add(lblOwner).expand(true, false);
grid.add(btnChangeOwner).fill(true, false);
grid.nextRow();
// creation time
lblCreateTime = new QLabel();
grid.add(new QLabel("Erstellt am"));
grid.add(lblCreateTime, 2);
grid.nextRow();
// last updater
lblUpdater = new PersonLabel();
grid.add(new QLabel("Geändert durch"));
grid.add(lblUpdater, 2);
grid.nextRow();
// last updated
lblUpdateTime = new QLabel();
grid.add(new QLabel("Geändert am"));
grid.add(lblUpdateTime, 2);
grid.nextRow();
// os
cboOperatingSystem = new ComboBox<OperatingSystem>(Comparators.operatingSystem,
new ComboBoxRenderer<OperatingSystem>() {
@Override
public String renderItem(OperatingSystem item) {
if (item == null)
return null;
return item.getOsName();
}
});
cboOperatingSystem.setEditable(false);
grid.add(new QLabel("Betriebssystem"));
grid.add(cboOperatingSystem, 2).expand(true, false).fill(true, false);
grid.nextRow();
// tags
txtTags = new JTextField();
/* TODO
grid.add(new QLabel("Tags"), GridPos.get(0, row, false, false));
grid.add(txtTags, GridPos.get(1, row++, true, false));
grid.nextRow();
*/
// share mode
cboShareMode = new JComboBox<ShareMode>();
grid.add(new QLabel("Freigabemodus"));
grid.add(cboShareMode, 2).expand(true, false).fill(true, false);
grid.nextRow();
// template
chkIsTemplate = new JCheckBox("Vorlage");
grid.add(Box.createGlue());
grid.add(chkIsTemplate, 2);
grid.nextRow();
// version
txtVersion = new JTextField();
grid.add(new QLabel("Versions-ID"));
grid.add(txtVersion, 2).expand(true, false).fill(true, false);
grid.nextRow();
// id
txtId = new JTextField();
txtId.setEditable(false);
grid.add(new QLabel("VM-ID"));
grid.add(txtId, 2).expand(true, false).fill(true, false);
grid.nextRow();
// virtualizer
lblVirtualizer = new QLabel();
btnEditVmx = new JButton("VMX Editieren");
grid.add(new QLabel("Virtualisierer"));
grid.add(lblVirtualizer, 2).expand(true, false).fill(true, false);
//grid.add(btnEditVmx);
grid.nextRow();
btnPermissions = new JButton("Berechtigungen");
grid.skip();
grid.add(btnPermissions, 2);
grid.nextRow();
grid.add(new QLabel("Veranstaltungen"));
lblLinkedLectureCount = new QLabel();
grid.add(lblLinkedLectureCount).expand(true, false);
btnShowLinkingLectures = new JButton("Anzeigen");
grid.add(btnShowLinkingLectures).fill(true, false);
grid.nextRow();
grid.add(Box.createVerticalStrut(10), 3);
grid.nextRow();
grid.finish(true);
infoPanel.setPreferredSize(Gui.getScaledDimension(500, 400));
infoPanel.setMinimumSize(Gui.getScaledDimension(350, 300));
// finally add the infoPanel itself to the left panel
// button panel at the bottom
JPanel buttonPanel = new JPanel();
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
btnSaveChanges = new JButton("Speichern");
btnClose = new JButton("Schließen");
btnUpdateImage = new JButton("Neue VM-Version hochladen", Gui.getScaledIconResource("/img/upload-icon.png", "New VM", ICON_SIZE_Y, buttonPanel));
buttonPanel.add(btnUpdateImage);
btnUploadToMaster = new JButton("Landesweit veröffentlichen", Gui.getScaledIconResource("/img/publish-icon.png", "Publish VM", ICON_SIZE_Y, buttonPanel));
buttonPanel.add(btnUploadToMaster);
buttonPanel.add(Box.createGlue());
// user feedback slot
lblError = new QLabel("");
lblError.setForeground(Color.RED);
buttonPanel.add(lblError);
buttonPanel.add(Box.createGlue());
buttonPanel.add(btnClose);
buttonPanel.add(btnSaveChanges);
// --- Version table on the right (EAST) side
JPanel versionTablePanel = new JPanel();
versionTablePanel.setLayout(new BorderLayout());
versionTablePanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
QLabel lblVersion = new QLabel("VM-Versionen");
lblVersion.setFont(lblVersion.getFont().deriveFont(Font.BOLD));
versionTablePanel.add(lblVersion, BorderLayout.PAGE_START);
tblVersions = new ImageVersionTable();
scpVersions = new QScrollPane(tblVersions);
scpVersions.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
versionTablePanel.add(scpVersions, BorderLayout.CENTER);
// add the tabel panel to the right panel
JPanel rightPanel = new JPanel();
rightPanel.setLayout(new BorderLayout());
rightPanel.add(versionTablePanel, BorderLayout.CENTER);
// add left and right panel to the split pane
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, infoPanel, rightPanel);
splitPane.setResizeWeight(0.5);
// add the split pane
add(splitPane, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.PAGE_END);
}
}