120 lines
3.2 KiB
Java
120 lines
3.2 KiB
Java
package org.hwo.pulscounter.ui;
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.FlowLayout;
|
|
|
|
import javax.swing.DefaultListModel;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.border.EmptyBorder;
|
|
|
|
import java.awt.GridBagLayout;
|
|
|
|
import javax.swing.JList;
|
|
|
|
import org.hwo.beacon.Beacon;
|
|
import org.hwo.beacon.Beacon.BeaconSender;
|
|
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.Dialog.ModalExclusionType;
|
|
import java.awt.Dialog.ModalityType;
|
|
|
|
public class NetworkSelectorDialog extends JDialog {
|
|
|
|
private final JPanel contentPanel = new JPanel();
|
|
private BeaconSender selectedSender;
|
|
|
|
private Beacon beacon;
|
|
private JList lSenders;
|
|
|
|
/**
|
|
* Create the dialog.
|
|
*/
|
|
public NetworkSelectorDialog(Beacon beacon) {
|
|
setTitle("Netzwerk Anschluss w\u00E4hlen...");
|
|
setModalityType(ModalityType.APPLICATION_MODAL);
|
|
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
|
|
setModal(true);
|
|
setBounds(100, 100, 450, 300);
|
|
getContentPane().setLayout(new BorderLayout());
|
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
|
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
|
gbl_contentPanel.columnWidths = new int[]{0, 0};
|
|
gbl_contentPanel.rowHeights = new int[]{0, 0};
|
|
gbl_contentPanel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
gbl_contentPanel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
contentPanel.setLayout(gbl_contentPanel);
|
|
{
|
|
lSenders = new JList();
|
|
GridBagConstraints gbc_lSenders = new GridBagConstraints();
|
|
gbc_lSenders.fill = GridBagConstraints.BOTH;
|
|
gbc_lSenders.gridx = 0;
|
|
gbc_lSenders.gridy = 0;
|
|
contentPanel.add(lSenders, gbc_lSenders);
|
|
}
|
|
{
|
|
JPanel buttonPane = new JPanel();
|
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
|
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
|
{
|
|
JButton okButton = new JButton("OK");
|
|
okButton.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
if (lSenders.getSelectedValue() != null) {
|
|
selectedSender = (BeaconSender)lSenders.getSelectedValue();
|
|
setVisible(false);
|
|
}
|
|
|
|
}
|
|
});
|
|
okButton.setActionCommand("OK");
|
|
buttonPane.add(okButton);
|
|
getRootPane().setDefaultButton(okButton);
|
|
}
|
|
{
|
|
JButton cancelButton = new JButton("Cancel");
|
|
cancelButton.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
selectedSender = null;
|
|
setVisible(false);
|
|
}
|
|
});
|
|
cancelButton.setActionCommand("Cancel");
|
|
buttonPane.add(cancelButton);
|
|
}
|
|
}
|
|
|
|
this.beacon = beacon;
|
|
|
|
this.initialize();
|
|
}
|
|
|
|
private void initialize()
|
|
{
|
|
DefaultListModel lm = new DefaultListModel();
|
|
|
|
for (BeaconSender sender: this.beacon.getBeaconSenders().values())
|
|
{
|
|
lm.addElement(sender);
|
|
}
|
|
lSenders.setModel(lm);
|
|
}
|
|
|
|
public static BeaconSender show(Beacon beacon)
|
|
{
|
|
NetworkSelectorDialog dlg = new NetworkSelectorDialog(beacon);
|
|
dlg.setVisible(true);
|
|
return dlg.getSelectedSender();
|
|
}
|
|
|
|
public BeaconSender getSelectedSender() {
|
|
return selectedSender;
|
|
}
|
|
|
|
|
|
}
|