From 74e4a77ccd9c2097d66ab8c7b560167c476b5022 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 18 Jun 2019 17:36:47 +0200 Subject: [client] Support configuring USB speed of VMs --- .../dozmod/gui/window/VirtConfigEditorWindow.java | 2 +- .../gui/window/VirtDropDownConfigEditorWindow.java | 19 ++++++++++++++++--- .../layout/VirtDropDownConfigEditorWindowLayout.java | 19 +++++++++++++++++++ .../main/java/org/openslx/dozmod/util/VmWrapper.java | 7 +++++-- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java index a1a28d96..be06f8ae 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtConfigEditorWindow.java @@ -87,7 +87,7 @@ public class VirtConfigEditorWindow extends VirtConfigEditorWindowLayout impleme // cs is now either the detected encoding, or latin1 as a default uiBytes = userInput.getBytes(cs); // now we should have the correct bytes... - VmMetaData metaCandidate = null; + VmMetaData metaCandidate = null; try { metaCandidate = VmMetaData.getInstance(MetaDataCache.getOperatingSystems(), uiBytes, uiBytes.length); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java index 6dba2a08..3edb0642 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtDropDownConfigEditorWindow.java @@ -23,6 +23,7 @@ import org.openslx.util.vm.VmMetaData.DDAcceleration; import org.openslx.util.vm.VmMetaData.EthernetDevType; import org.openslx.util.vm.VmMetaData.HWVersion; import org.openslx.util.vm.VmMetaData.SoundCardType; +import org.openslx.util.vm.VmMetaData.UsbSpeed; @SuppressWarnings("serial") public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWindowLayout @@ -37,7 +38,7 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind private final String imageVersionId; private final String originalMachineDescription; private final VirtDropDownConfigEditorWindow me = this; - private final VmMetaData meta; + private final VmMetaData meta; private final ImageDetailsActions actionHandler; protected VirtDropDownConfigEditorWindow(Window modalParent, final ImageDetailsActions actionHandler, @@ -48,7 +49,7 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind this.imageVersionId = imageVersionId; // and now for the meta data - VmMetaData metaCandidate = null; + VmMetaData metaCandidate = null; byte[] machineData = ThriftUtil.unwrapByteBuffer(machineDescription); try { metaCandidate = VmMetaData.getInstance(MetaDataCache.getOperatingSystems(), machineData, @@ -69,6 +70,7 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind initializeDDABox(meta.getSupportedDDAccs()); initializeHWVersBox(meta.getSupportedHWVersions()); initializeEDTBox(meta.getSupportedEthernetDevices()); + initializeUsbBox(meta.getSupportedUsbSpeeds()); //set the initial state of the buttons initializeComboBoxes(meta); @@ -112,6 +114,15 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind btnSave.setEnabled(hasChanged()); } }); + + cboMaxUsbSpeed.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + UsbSpeed selected = (UsbSpeed) cboMaxUsbSpeed.getSelectedItem(); + meta.setMaxUsbSpeed(selected); + btnSave.setEnabled(hasChanged()); + } + }); // listener for the save button btnSave.addActionListener(new ActionListener() { @@ -158,7 +169,7 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind /* setting the boxes to their initial value...value is read from the given metaData * @param: given VmwareMetaData */ - private void initializeComboBoxes(VmMetaData m) { + private void initializeComboBoxes(VmMetaData m) { try { SoundCardType SCT = m.getSoundCard(); cboSound.setSelectedItem(SCT); @@ -168,6 +179,8 @@ public class VirtDropDownConfigEditorWindow extends VirtDropDownConfigEditorWind cboHWVersion.setSelectedItem(HWV); EthernetDevType E0VD = m.getEthernetDevType(0); cboE0VirtDev.setSelectedItem(E0VD); + UsbSpeed usbSpeed = m.getMaxUsbSpeed(); + cboMaxUsbSpeed.setSelectedItem(usbSpeed); } catch (IllegalArgumentException e) { // TODO improve user message Gui.showMessageBox("Sie haben beim letzten Konfigurieren \n" diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java index a73bb60e..ba707bf4 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java @@ -26,6 +26,7 @@ import org.openslx.util.vm.VmMetaData.DDAcceleration; import org.openslx.util.vm.VmMetaData.EthernetDevType; import org.openslx.util.vm.VmMetaData.HWVersion; import org.openslx.util.vm.VmMetaData.SoundCardType; +import org.openslx.util.vm.VmMetaData.UsbSpeed; @SuppressWarnings("serial") public class VirtDropDownConfigEditorWindowLayout extends JDialog { @@ -40,6 +41,7 @@ public class VirtDropDownConfigEditorWindowLayout extends JDialog { protected final JComboBox cbo3DAcceleration; protected final JComboBox cboHWVersion; protected final JComboBox cboE0VirtDev; + protected final JComboBox cboMaxUsbSpeed; protected VirtDropDownConfigEditorWindowLayout(Window modalParent) { super(modalParent, title, @@ -95,6 +97,13 @@ public class VirtDropDownConfigEditorWindowLayout extends JDialog { return item.displayName; } }); + + cboMaxUsbSpeed = new ComboBox<>(new ComboBoxRenderer() { + @Override + public String renderItem(UsbSpeed item) { + return item.displayName; + } + }); pnlEditor = new JEditorPane("text/plain", null); pnlScrollPane = new JScrollPane(pnlEditor, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, @@ -114,6 +123,9 @@ public class VirtDropDownConfigEditorWindowLayout extends JDialog { grid.add(new JLabel("Netzwerkkarte")).fill(true, false).expand(false, false); grid.add(cboE0VirtDev).fill(true, false).expand(true, false); grid.nextRow(); + grid.add(new JLabel("USB")).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(); @@ -167,4 +179,11 @@ public class VirtDropDownConfigEditorWindowLayout extends JDialog { cboE0VirtDev.addItem(i); } } + + // USB Speed + public void initializeUsbBox(List list) { + for (UsbSpeed i : list) { + cboMaxUsbSpeed.addItem(i); + } + } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java index e58653e7..38a61282 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/VmWrapper.java @@ -28,6 +28,7 @@ import org.openslx.util.vm.DiskImage; import org.openslx.util.vm.QemuMetaData; import org.openslx.util.vm.VboxMetaData; import org.openslx.util.vm.VmMetaData; +import org.openslx.util.vm.VmMetaData.UsbSpeed; import org.openslx.util.vm.VmwareMetaData; public class VmWrapper { @@ -47,7 +48,7 @@ public class VmWrapper { machineDescription = getFallbackVmx(diskImageInfo); } // Handle machine description to generate configuration file - VmMetaData vmMeta = VmMetaData.getInstance(MetaDataCache.getOperatingSystems(), + VmMetaData vmMeta = VmMetaData.getInstance(MetaDataCache.getOperatingSystems(), machineDescription, machineDescription.length); // Append disk & NAT @@ -86,7 +87,9 @@ public class VmWrapper { vmMeta.addFloppy(1, null, true); vmMeta.addCdrom(""); // ISO-Based with no disk in drive vmMeta.addCdrom(null); // Autodetect real drive - vmMeta.enableUsb(true); + if (vmMeta.getMaxUsbSpeed() != UsbSpeed.USB3_0) { + vmMeta.setMaxUsbSpeed(UsbSpeed.USB2_0); + } vmMeta.applySettingsForLocalEdit(); // Output vm -- cgit v1.2.3-55-g7522