package org.openslx.dozmod.gui.window.layout;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Window;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
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.WordWrapLabel;
import org.openslx.dozmod.gui.helper.GridManager;
import org.openslx.dozmod.gui.helper.I18n;
import org.openslx.dozmod.thrift.Session;
import org.openslx.sat.thrift.version.Feature;
import org.openslx.virtualization.configuration.VirtualizationConfiguration.DDAcceleration;
import org.openslx.virtualization.configuration.VirtualizationConfiguration.EthernetDevType;
import org.openslx.virtualization.Version;
import org.openslx.virtualization.configuration.VirtualizationConfiguration.SoundCardType;
import org.openslx.virtualization.configuration.VirtualizationConfiguration.UsbSpeed;
public class VirtDropDownConfigEditorWindowLayout extends JDialog {
/**
* Version for serialization.
*/
private static final long serialVersionUID = -8808628177189132030L;
protected final JScrollPane pnlScrollPane;
protected final JEditorPane pnlEditor;
protected final JButton btnSave;
protected final JButton btnCancel;
protected final JButton btnMore;
protected final JComboBox<SoundCardType> cboSound;
protected final JComboBox<DDAcceleration> cbo3DAcceleration;
protected final JComboBox<Version> cboHWVersion;
protected final JComboBox<EthernetDevType> cboE0VirtDev;
protected final JComboBox<UsbSpeed> cboMaxUsbSpeed;
protected VirtDropDownConfigEditorWindowLayout(Window modalParent) {
super(modalParent, I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Dialog.title"),
modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS);
GridManager grid = new GridManager(getContentPane(), 2, true, new Insets(2, 2, 2, 2));
/*
* extra JPanel for the Warning message
*/
JPanel pnlWarning = new JPanel();
pnlWarning.setBorder(BorderFactory.createTitledBorder(
I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.TitledBorder.pnlWarning.title")));
pnlWarning.setLayout(new BorderLayout());
pnlWarning.add(new WordWrapLabel(
I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Label.pnlWarning.text")),
BorderLayout.CENTER);
/*
* ComboBoxes - one for each device
*/
cboSound = new ComboBox<SoundCardType>(new ComboBoxRenderer<SoundCardType>() {
@Override
public String renderItem(SoundCardType item) {
return item.displayName;
}
}, SoundCardType.class);
// 3D accelerationBox
cbo3DAcceleration = new ComboBox<DDAcceleration>(new ComboBoxRenderer<DDAcceleration>() {
@Override
public String renderItem(DDAcceleration item) {
return item.displayName;
}
}, DDAcceleration.class);
// HardwareVersioBox
cboHWVersion = new ComboBox<Version>(new ComboBoxRenderer<Version>() {
@Override
public String renderItem(org.openslx.virtualization.Version item) {
return item.getName();
}
}, Version.class);
// HardwareVersioBox
cboE0VirtDev = new ComboBox<EthernetDevType>(new ComboBoxRenderer<EthernetDevType>() {
@Override
public String renderItem(EthernetDevType item) {
return item.displayName;
}
}, EthernetDevType.class);
cboMaxUsbSpeed = new ComboBox<UsbSpeed>(new ComboBoxRenderer<UsbSpeed>() {
@Override
public String renderItem(UsbSpeed item) {
return item.displayName;
}
}, UsbSpeed.class);
pnlEditor = new JEditorPane("text/plain", null);
pnlScrollPane = new JScrollPane(pnlEditor, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
grid.add(pnlWarning, 2).fill(true, false).expand(true, false);
grid.nextRow();
grid.add(new JLabel(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Label.sound.text")))
.fill(true, false).expand(false, false);
grid.add(cboSound).fill(true, false).expand(false, false);
grid.nextRow();
grid.add(new JLabel(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Label.3DAcceleration.text")))
.fill(true, false).expand(false, false);
grid.add(cbo3DAcceleration).fill(true, false).expand(true, false);
grid.nextRow();
grid.add(new JLabel(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Label.HWVersion.text")))
.fill(true, false).expand(false, false);
grid.add(cboHWVersion).fill(true, false).expand(true, false);
grid.nextRow();
grid.add(new JLabel(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Label.E0VirtDev.text")))
.fill(true, false).expand(false, false);
grid.add(cboE0VirtDev).fill(true, false).expand(true, false);
grid.nextRow();
if (Session.hasFeature(Feature.CONFIGURE_USB)) {
grid.add(new JLabel(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Label.maxUSBSpeed.text")))
.fill(true, false).expand(false, false);
grid.add(cboMaxUsbSpeed).fill(true, false).expand(true, false);
grid.nextRow();
}
grid.add(Box.createVerticalGlue(), 2).expand(true, true);
grid.nextRow();
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
buttonPane.add(Box.createHorizontalGlue());
btnMore = new JButton(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Button.more.text"));
buttonPane.add(btnMore);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
btnCancel = new JButton(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Button.cancel.text"));
buttonPane.add(btnCancel);
buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
btnSave = new JButton(I18n.WINDOW_LAYOUT.getString("VirtDropDownConfigEditor.Button.save.text"));
buttonPane.add(btnSave);
grid.add(buttonPane, 2).fill(true, false).expand(true, false);
grid.finish(false);
setPreferredSize(Gui.getScaledDimension(600, 400));
setMinimumSize(Gui.getScaledDimension(450, 375));
if (modalParent != null) {
Gui.centerShellOverShell(modalParent, this);
}
}
// SoundBox
public void initializeSoundBox(List<SoundCardType> list) {
for (SoundCardType i : list) {
cboSound.addItem(i);
}
}
// 3 D acceleration
public void initializeDDABox(List<DDAcceleration> list) {
for (DDAcceleration i : list) {
cbo3DAcceleration.addItem(i);
}
}
// Hardware version
public void initializeHWVersBox(List<Version> list) {
if (list == null || list.isEmpty()) {
// disable selection of items if list does not contain any items
cboHWVersion.setEnabled(false);
} else {
// append items to combobox if list contains items
for (Version i : list) {
cboHWVersion.addItem(i);
}
// enable selection of items
cboHWVersion.setEnabled(true);
}
}
// Ethernet Device type
public void initializeEDTBox(List<EthernetDevType> list) {
for (EthernetDevType i : list) {
cboE0VirtDev.addItem(i);
}
}
// USB Speed
public void initializeUsbBox(List<UsbSpeed> list) {
for (UsbSpeed i : list) {
cboMaxUsbSpeed.addItem(i);
}
}
}