View Javadoc

1   package nl.tudelft.goal.ut2004.visualizer.panels.connection;
2   
3   import java.awt.event.ActionEvent;
4   import java.awt.event.ActionListener;
5   import java.net.URI;
6   
7   import javax.swing.JButton;
8   import javax.swing.JLabel;
9   import javax.swing.JPanel;
10  
11  import cz.cuni.amis.utils.flag.Flag;
12  import cz.cuni.amis.utils.flag.FlagListener;
13  
14  public class ConnectedPanel extends JPanel {
15  
16  	private final JLabel connectionStatus;
17  	private final JButton disconnectButton;
18  
19  	public ConnectedPanel(Flag<URI> uriFlag, final IDisconnect disconnect) {
20  		this.connectionStatus = new JLabel("Connected to: " + uriFlag.getFlag());
21  		this.disconnectButton = new JButton("Disconnect");
22  		
23  		add(connectionStatus);
24  		add(disconnectButton);
25  
26  		uriFlag.addListener(new FlagListener<URI>() {
27  
28  			@Override
29  			public void flagChanged(URI changedValue) {
30  				connectionStatus.setText("Connected to: " + changedValue);
31  			}
32  		});
33  
34  		this.disconnectButton.addActionListener(new ActionListener() {
35  
36  			@Override
37  			public void actionPerformed(ActionEvent arg0) {
38  				disconnect.disconnect();
39  
40  			}
41  		});
42  	}
43  }