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 radioToSat = new HashMap<>(); private static String title = "Satellitenserver wählen"; protected SatelliteListWindowLayout(Window modalParent, List 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(); } }