PageRenderTime 96ms CodeModel.GetById 34ms app.highlight 43ms RepoModel.GetById 5ms app.codeStats 1ms

/.metadata/.plugins/org.eclipse.core.resources/.history/1/10db908d77a3001e1dff9ae635b3e1ee

https://bitbucket.org/fixpoint/connexion
#! | 88 lines | 71 code | 17 blank | 0 comment | 0 complexity | 5ef29fd35d9dd30efbf8708f9f6a510b MD5 | raw file
 1package info.reflectionsofmind.connexion.transport.dummy.gui;
 2
 3import info.reflectionsofmind.connexion.platform.control.ITransportConfigurer;
 4import info.reflectionsofmind.connexion.platform.control.control.IConnectControl;
 5import info.reflectionsofmind.connexion.platform.control.control.IHostControl;
 6import info.reflectionsofmind.connexion.platform.gui.IOkCancelListener;
 7import info.reflectionsofmind.connexion.platform.gui.OkCancelPanel;
 8import info.reflectionsofmind.connexion.transport.IConnectionParameters;
 9import info.reflectionsofmind.connexion.transport.dummy.DummyConnectionParameters;
10
11import java.awt.Window;
12
13import javax.swing.JDialog;
14import javax.swing.JLabel;
15import javax.swing.JSpinner;
16import javax.swing.SpinnerNumberModel;
17
18import net.miginfocom.swing.MigLayout;
19
20public class DummyTransportConfigurer implements ITransportConfigurer
21{
22	@Override
23	public IConnectionParameters execute(IConnectControl hostControl)
24	{
25		// TODO Auto-generated method stub
26		return null;
27	}
28	
29	@Override
30	public IConnectionParameters execute(IHostControl hostControl)
31	{
32		return execute((Window)hostControl);
33	}
34	
35	public DummyConnectionParameters execute(final Window window)
36	{
37		final AddDummyTransportDialog dialog = new AddDummyTransportDialog(window);
38		dialog.setVisible(true);
39
40		if (dialog.getNumberOfPlayers() != null)
41		{
42			return new DummyConnectionParameters(dialog.getNumberOfPlayers());
43		}
44		else
45		{
46			return null;
47		}
48	}
49
50	private final class AddDummyTransportDialog extends JDialog implements IOkCancelListener
51	{
52		private Integer numberOfPlayers = null;
53		private final JSpinner spinner;
54
55		public AddDummyTransportDialog(final Window owner)
56		{
57			super(owner, "Add dummy transport", ModalityType.APPLICATION_MODAL);
58			setLayout(new MigLayout("", "[][]", "[]"));
59
60			add(new JLabel("Number of dummy players"));
61
62			this.spinner = new JSpinner(new SpinnerNumberModel(3, 1, 10, 1));
63			add(this.spinner, "wrap");
64
65			add(new OkCancelPanel(this, "Add", "Cancel"), "span, al right");
66
67			setResizable(false);
68			pack();
69			setLocationRelativeTo(null);
70		}
71
72		public void onCancel()
73		{
74			dispose();
75		}
76
77		public void onOk()
78		{
79			this.numberOfPlayers = (Integer) this.spinner.getModel().getValue();
80			dispose();
81		}
82
83		public Integer getNumberOfPlayers()
84		{
85			return this.numberOfPlayers;
86		}
87	}
88}