summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/SatelliteListWindowLayout.java
blob: 2e28a4b977b96e0fc6870271c767b89e3141143b (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
package org.openslx.dozmod.gui.window.layout;

import java.awt.BorderLayout;
import java.awt.Window;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import org.openslx.bwlp.thrift.iface.Satellite;
import org.openslx.dozmod.gui.helper.GridManager;

@SuppressWarnings("serial")
public class SatelliteListWindowLayout extends JDialog {

	protected final JButton btnCancel;
	protected final JButton btnContinue;
	protected final JTextField txtCustomAddress;
	protected final JRadioButton rdoCusomAddress;
	protected final Map<JRadioButton, Satellite> radioToSat = new HashMap<>();

	private static String title = "Satellitenserver wählen";

	protected SatelliteListWindowLayout(Window modalParent, List<Satellite> satList) {
		super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL
				: ModalityType.MODELESS);
		JPanel radioPanel = new JPanel();
		radioPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
		GridManager selectionPanelGrid = new GridManager(radioPanel, 2);
		ButtonGroup btnGroup = new ButtonGroup();

		// --------------- radio buttons sat selection --------------------------------------
		if (satList != null && !satList.isEmpty()) {
			selectionPanelGrid.add(new JLabel("Vorgegebene Server"), 2);
			selectionPanelGrid.nextRow();
			// create the radioButtons, add them to the map, button group and the selection grid.
			for (Satellite sat : satList) {
				JRadioButton radioButton = new JRadioButton(sat.getDisplayName());
				radioButton.setEnabled(sat.addressList != null && !sat.addressList.isEmpty());
				radioToSat.put(radioButton, sat);
				btnGroup.add(radioButton);
				selectionPanelGrid.add(radioButton, 2).fill(true, false).expand(true, false);
				selectionPanelGrid.nextRow();
			}
		}
		// --------------- end radio buttons for sat selection ------------------------------------

		// --------------- custom ip button and field --------------------------------------
		selectionPanelGrid.add(new JLabel("Server-Adresse selbst eingeben"), 2);
		selectionPanelGrid.nextRow();
		rdoCusomAddress = new JRadioButton("");
		btnGroup.add(rdoCusomAddress);
		txtCustomAddress = new JTextField("");
		selectionPanelGrid.add(rdoCusomAddress).fill(true, false).expand(false, false);
		selectionPanelGrid.add(txtCustomAddress).fill(true, false).expand(true, false);
		selectionPanelGrid.nextRow();
		// --------------- end custom ip field --------------------------------
		selectionPanelGrid.finish(false);

		// --------------- button panel --------------------------------------
		JPanel buttonPane = new JPanel();
		buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
		buttonPane.setBorder(BorderFactory.createEmptyBorder(1, 3, 3, 3));
		btnCancel = new JButton("Abbrechen");
		buttonPane.add(btnCancel);
		buttonPane.add(Box.createHorizontalGlue());
		btnContinue = new JButton("Weiter");
		buttonPane.add(btnContinue);
		// --------------- end button panel ----------------------------------

		// pack it all
		getContentPane().add(radioPanel, BorderLayout.CENTER);
		getContentPane().add(buttonPane, BorderLayout.PAGE_END);
		pack();
	}
}