ide/src/wombat/gui/text/sta/SharedTextArea.java
protected synchronized void processLocal(String line) {
		NDL.suppress(true);
		
		try {
			String[] parts = line.split(",");
			String lineMsgType = parts[0];
			String[] args = Arrays.copyOfRange(parts, 1, parts.length); 
			
			// Text has been inserted into the remote document.
			if ("insert".equals(lineMsgType)) {
				
				int off = Integer.parseInt(args[0]);
				String str = new String(Base64.decode(args[2]), "UTF-8");
				code.getDocument().insertString(off, str, null);
				
			}
			
			// Text has been removed from the remote document.
			else if ("remove".equals(lineMsgType)) {
				
				int off = Integer.parseInt(args[0]);
				int len = Integer.parseInt(args[1]);
				code.getDocument().remove(off, len);
				
			}
			
			// Someone has decided to say hello, send them our document
			else if ("hello".equals(lineMsgType)) {
				
				String str = Base64.encodeBytes(code.getText().getBytes("UTF-8"));
				CT.send(makeMessage("sync", str));
				
			}
			
			// We have a sync request, honor it
			else if ("sync".equals(lineMsgType)) {
				
				try {
					String str = new String(Base64.decode(args[0]), "UTF-8");
					code.setText(str);
				} catch(Exception e) {
					ErrorManager.logError("Unable to sync documents: " + e);
					e.printStackTrace();
				}
				
			}
			
			// Someone wants to check to see if we're in sync
			else if ("check-sync".equals(lineMsgType)) {
				
				try {
					int usHash = code.getText().hashCode();
					int themHash = Integer.parseInt(args[0]);
					
					if (usHash != themHash) {
						String str = Base64.encodeBytes(code.getText().getBytes("UTF-8"));
						CT.send(makeMessage("sync", str));
					}
					
				} catch(Exception e) {
					ErrorManager.logError("Unable to check sync status: " + e);
					e.printStackTrace();
				}
				
			}
			
		} catch(BadLocationException ex) {
			ErrorManager.logError("Unable to process local line (BadLocation): " + ex);
			ex.printStackTrace();
		} catch (UnsupportedEncodingException ex) {
			ErrorManager.logError("Unable to process local line (UnsupportedEncoding): " + ex);
			ex.printStackTrace();
		} catch (IOException ex) {
			ErrorManager.logError("Unable to process local line (IO): " + ex);
			ex.printStackTrace();
		}
		
		NDL.suppress(false);
	}
/**
	 * Process a received line.
	 * @param line The new line input.
	 * @param onServer If we're doing something on the host, versus on a join'er.
	 * @return Any response to be sent back.
	 */
Process a received line.
@param line The new line input.
@param onServer If we're doing something on the host, versus on a join'er.
@return Any response to be sent back.
Process a received line . @param line The new line input . @param onServer If we ' re doing something on the host versus on a join ' er . @return Any response to be sent back .
protected synchronized void processLocal(String line) {
		NDL.suppress(true);
		try {
			String[] parts = line.split(",");
			String lineMsgType = parts[0];
			String[] args = Arrays.copyOfRange(parts, 1, parts.length); 
			if ("insert".equals(lineMsgType)) {
				int off = Integer.parseInt(args[0]);
				String str = new String(Base64.decode(args[2]), "UTF-8");
				code.getDocument().insertString(off, str, null);
			}
			else if ("remove".equals(lineMsgType)) {
				int off = Integer.parseInt(args[0]);
				int len = Integer.parseInt(args[1]);
				code.getDocument().remove(off, len);
			}
			else if ("hello".equals(lineMsgType)) {
				String str = Base64.encodeBytes(code.getText().getBytes("UTF-8"));
				CT.send(makeMessage("sync", str));
			}
			else if ("sync".equals(lineMsgType)) {
				try {
					String str = new String(Base64.decode(args[0]), "UTF-8");
					code.setText(str);
				} catch(Exception e) {
					ErrorManager.logError("Unable to sync documents: " + e);
					e.printStackTrace();
				}
			}
			else if ("check-sync".equals(lineMsgType)) {
				try {
					int usHash = code.getText().hashCode();
					int themHash = Integer.parseInt(args[0]);
					if (usHash != themHash) {
						String str = Base64.encodeBytes(code.getText().getBytes("UTF-8"));
						CT.send(makeMessage("sync", str));
					}
				} catch(Exception e) {
					ErrorManager.logError("Unable to check sync status: " + e);
					e.printStackTrace();
				}
			}
		} catch(BadLocationException ex) {
			ErrorManager.logError("Unable to process local line (BadLocation): " + ex);
			ex.printStackTrace();
		} catch (UnsupportedEncodingException ex) {
			ErrorManager.logError("Unable to process local line (UnsupportedEncoding): " + ex);
			ex.printStackTrace();
		} catch (IOException ex) {
			ErrorManager.logError("Unable to process local line (IO): " + ex);
			ex.printStackTrace();
		}
		NDL.suppress(false);
	}
protected synchronized void processLocal ( String line ) { NDL . suppress ( true ) ; try { String [ ] parts = line . split ( "," ) ; String lineMsgType = parts [ 0 ] ; String [ ] args = Arrays . copyOfRange ( parts , 1 , parts . length ) ; if ( "insert" . equals ( lineMsgType ) ) { int off = Integer . parseInt ( args [ 0 ] ) ; String str = new String ( Base64 . decode ( args [ 2 ] ) , "UTF-8" ) ; code . getDocument ( ) . insertString ( off , str , null ) ; } else if ( "remove" . equals ( lineMsgType ) ) { int off = Integer . parseInt ( args [ 0 ] ) ; int len = Integer . parseInt ( args [ 1 ] ) ; code . getDocument ( ) . remove ( off , len ) ; } else if ( "hello" . equals ( lineMsgType ) ) { String str = Base64 . encodeBytes ( code . getText ( ) . getBytes ( "UTF-8" ) ) ; CT . send ( makeMessage ( "sync" , str ) ) ; } else if ( "sync" . equals ( lineMsgType ) ) { try { String str = new String ( Base64 . decode ( args [ 0 ] ) , "UTF-8" ) ; code . setText ( str ) ; } catch ( Exception e ) { ErrorManager . logError ( "Unable to sync documents: " + e ) ; e . printStackTrace ( ) ; } } else if ( "check-sync" . equals ( lineMsgType ) ) { try { int usHash = code . getText ( ) . hashCode ( ) ; int themHash = Integer . parseInt ( args [ 0 ] ) ; if ( usHash != themHash ) { String str = Base64 . encodeBytes ( code . getText ( ) . getBytes ( "UTF-8" ) ) ; CT . send ( makeMessage ( "sync" , str ) ) ; } } catch ( Exception e ) { ErrorManager . logError ( "Unable to check sync status: " + e ) ; e . printStackTrace ( ) ; } } } catch ( BadLocationException ex ) { ErrorManager . logError ( "Unable to process local line (BadLocation): " + ex ) ; ex . printStackTrace ( ) ; } catch ( UnsupportedEncodingException ex ) { ErrorManager . logError ( "Unable to process local line (UnsupportedEncoding): " + ex ) ; ex . printStackTrace ( ) ; } catch ( IOException ex ) { ErrorManager . logError ( "Unable to process local line (IO): " + ex ) ; ex . printStackTrace ( ) ; } NDL . suppress ( false ) ; }
Process a received line.
Process a received line .
// Text has been inserted into the remote document. // Text has been removed from the remote document. // Someone has decided to say hello, send them our document // We have a sync request, honor it // Someone wants to check to see if we're in sync