summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtDropDownConfigEditorWindowLayout.java
blob: 24e41e787022d611e28c398eeb45ff84d73305d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
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);
		}
	}
}