ide/src/wombat/gui/actions/Connect.java
public void actionPerformed(ActionEvent event) {
		// Are they going to host or join?
		final JDialog hostOptions = new JDialog(MainFrame.Singleton(), "Sharing...");
		hostOptions.setLayout(new GridLayout(4, 1));
		hostOptions.setModal(true);
		hostOptions.setLocationByPlatform(true);
		
		final JButton host = new JButton("Create a new shared document");
		final JButton join = new JButton("Join an existing shared document");
		final JButton disconnect = new JButton("Disconnect");
		final JButton cancel = new JButton("Cancel");
		
		disconnect.setEnabled(DocumentManager.isActiveShared());
			
		ActionListener al = new ActionListener() {
			@Override public void actionPerformed(ActionEvent e) {
				hostOptions.setVisible(false);
				
				if (e.getSource() == host) {
					
					try {
						DocumentManager.HostShared();
					} catch (Exception ex) {
						ex.printStackTrace();
						JOptionPane.showMessageDialog(MainFrame.Singleton(), "Cannot host server");
					}
					
				} else if (e.getSource() == join) {
					
					// Display a dialog asking for a name.
					String name = (String) JOptionPane.showInputDialog(
							MainFrame.Singleton(), 
							"Enter the name of the server to connect to:", 
							"Server",
							JOptionPane.QUESTION_MESSAGE);
					
					// If they didn't choose a name, just bail out.
					if (name == null) 
						return;
					
					// They gave us an IP and port
					if (name.contains(":")) {
						try {
							String[] parts = name.split(":");
							DocumentManager.JoinShared(InetAddress.getByName(parts[0]), Integer.parseInt(parts[1]));
						} catch(Exception ex) {
							ex.printStackTrace();
							JOptionPane.showMessageDialog(MainFrame.Singleton(), "Cannot connect to server");
						}
					}
					
					// Or they gave us an encoded string
					else {
						try {
							DocumentManager.JoinShared(SharedTextArea.decodeAddressHost(name), SharedTextArea.decodeAddressPort(name));
						} catch(Exception ex) {
							ex.printStackTrace();
							JOptionPane.showMessageDialog(MainFrame.Singleton(), "Cannot connect to server");
						}
					}
					
				} else if (e.getSource() == cancel) {
					
					// already hidden, just do nothing
				
				} else if (e.getSource() == disconnect) {
				
					DocumentManager.DisconnectShared();
				
				}
			}
		};
		
		host.addActionListener(al);
		join.addActionListener(al);
		disconnect.addActionListener(al);
		cancel.addActionListener(al);
		
		hostOptions.add(host);
		hostOptions.add(join);
		hostOptions.add(disconnect);
		hostOptions.add(cancel);
		
		hostOptions.pack();
		hostOptions.setVisible(true);
	}
/**
	 * Display the ConnectDialog to arrange sharing. 
	 * @param event Action parameters (ignored)
	 * @see ConnectDialog, ActionEvent
	 */
Display the ConnectDialog to arrange sharing.
@param event Action parameters (ignored)
@see ConnectDialog, ActionEvent
Display the ConnectDialog to arrange sharing . @param event Action parameters ( ignored ) @see ConnectDialog ActionEvent
public void actionPerformed(ActionEvent event) {
		final JDialog hostOptions = new JDialog(MainFrame.Singleton(), "Sharing...");
		hostOptions.setLayout(new GridLayout(4, 1));
		hostOptions.setModal(true);
		hostOptions.setLocationByPlatform(true);
		final JButton host = new JButton("Create a new shared document");
		final JButton join = new JButton("Join an existing shared document");
		final JButton disconnect = new JButton("Disconnect");
		final JButton cancel = new JButton("Cancel");
		disconnect.setEnabled(DocumentManager.isActiveShared());
		ActionListener al = new ActionListener() {
			@Override public void actionPerformed(ActionEvent e) {
				hostOptions.setVisible(false);
				if (e.getSource() == host) {
					try {
						DocumentManager.HostShared();
					} catch (Exception ex) {
						ex.printStackTrace();
						JOptionPane.showMessageDialog(MainFrame.Singleton(), "Cannot host server");
					}
				} else if (e.getSource() == join) {
					String name = (String) JOptionPane.showInputDialog(
							MainFrame.Singleton(), 
							"Enter the name of the server to connect to:", 
							"Server",
							JOptionPane.QUESTION_MESSAGE);
					if (name == null) 
						return;
					if (name.contains(":")) {
						try {
							String[] parts = name.split(":");
							DocumentManager.JoinShared(InetAddress.getByName(parts[0]), Integer.parseInt(parts[1]));
						} catch(Exception ex) {
							ex.printStackTrace();
							JOptionPane.showMessageDialog(MainFrame.Singleton(), "Cannot connect to server");
						}
					}
					else {
						try {
							DocumentManager.JoinShared(SharedTextArea.decodeAddressHost(name), SharedTextArea.decodeAddressPort(name));
						} catch(Exception ex) {
							ex.printStackTrace();
							JOptionPane.showMessageDialog(MainFrame.Singleton(), "Cannot connect to server");
						}
					}
				} else if (e.getSource() == cancel) {
				} else if (e.getSource() == disconnect) {
					DocumentManager.DisconnectShared();
				}
			}
		};
		host.addActionListener(al);
		join.addActionListener(al);
		disconnect.addActionListener(al);
		cancel.addActionListener(al);
		hostOptions.add(host);
		hostOptions.add(join);
		hostOptions.add(disconnect);
		hostOptions.add(cancel);
		hostOptions.pack();
		hostOptions.setVisible(true);
	}
public void actionPerformed ( ActionEvent event ) { final JDialog hostOptions = new JDialog ( MainFrame . Singleton ( ) , "Sharing..." ) ; hostOptions . setLayout ( new GridLayout ( 4 , 1 ) ) ; hostOptions . setModal ( true ) ; hostOptions . setLocationByPlatform ( true ) ; final JButton host = new JButton ( "Create a new shared document" ) ; final JButton join = new JButton ( "Join an existing shared document" ) ; final JButton disconnect = new JButton ( "Disconnect" ) ; final JButton cancel = new JButton ( "Cancel" ) ; disconnect . setEnabled ( DocumentManager . isActiveShared ( ) ) ; ActionListener al = new ActionListener ( ) { @ Override public void actionPerformed ( ActionEvent e ) { hostOptions . setVisible ( false ) ; if ( e . getSource ( ) == host ) { try { DocumentManager . HostShared ( ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; JOptionPane . showMessageDialog ( MainFrame . Singleton ( ) , "Cannot host server" ) ; } } else if ( e . getSource ( ) == join ) { String name = ( String ) JOptionPane . showInputDialog ( MainFrame . Singleton ( ) , "Enter the name of the server to connect to:" , "Server" , JOptionPane . QUESTION_MESSAGE ) ; if ( name == null ) return ; if ( name . contains ( ":" ) ) { try { String [ ] parts = name . split ( ":" ) ; DocumentManager . JoinShared ( InetAddress . getByName ( parts [ 0 ] ) , Integer . parseInt ( parts [ 1 ] ) ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; JOptionPane . showMessageDialog ( MainFrame . Singleton ( ) , "Cannot connect to server" ) ; } } else { try { DocumentManager . JoinShared ( SharedTextArea . decodeAddressHost ( name ) , SharedTextArea . decodeAddressPort ( name ) ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; JOptionPane . showMessageDialog ( MainFrame . Singleton ( ) , "Cannot connect to server" ) ; } } } else if ( e . getSource ( ) == cancel ) { } else if ( e . getSource ( ) == disconnect ) { DocumentManager . DisconnectShared ( ) ; } } } ; host . addActionListener ( al ) ; join . addActionListener ( al ) ; disconnect . addActionListener ( al ) ; cancel . addActionListener ( al ) ; hostOptions . add ( host ) ; hostOptions . add ( join ) ; hostOptions . add ( disconnect ) ; hostOptions . add ( cancel ) ; hostOptions . pack ( ) ; hostOptions . setVisible ( true ) ; }
Display the ConnectDialog to arrange sharing.
Display the ConnectDialog to arrange sharing .
// Are they going to host or join? // Display a dialog asking for a name. // If they didn't choose a name, just bail out. // They gave us an IP and port // Or they gave us an encoded string // already hidden, just do nothing