-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from JackOBrien/develop
Sprint 2
- Loading branch information
Showing
19 changed files
with
540 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.io.domain; | ||
|
||
|
||
import com.io.gui.UserInfo; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class ConnectionUpdate extends Packet { | ||
private ArrayList<UserInfo> userTable; | ||
|
||
public ConnectionUpdate(int userId, ArrayList<UserInfo> userTable){ | ||
super(userId, PacketType.CONNECTION_UPDATE); | ||
this.userTable = userTable; | ||
} | ||
|
||
public ArrayList<UserInfo> getUserList() { | ||
return userTable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.io.domain; | ||
|
||
public class FileTransfer extends Packet{ | ||
public FileTransfer(){ | ||
super(PacketType.FILE_TRANSFER.id()); | ||
public FileTransfer(int userId){ | ||
super(userId, PacketType.FILE_TRANSFER); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
package com.io.domain; | ||
|
||
public enum PacketType { | ||
DOCUMENT_EDIT(0), | ||
CURSOR_MOVE(1), | ||
LOGIN(2), | ||
FILE_TRANSFER(3); | ||
|
||
private int packetID; | ||
|
||
PacketType(int packetID){ | ||
this.packetID = packetID; | ||
} | ||
|
||
public int id() { | ||
return packetID; | ||
} | ||
DOCUMENT_EDIT, | ||
CURSOR_MOVE, | ||
LOGIN, | ||
FILE_TRANSFER, | ||
CONNECTION_UPDATE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.io.gui; | ||
|
||
|
||
import com.intellij.openapi.editor.Editor; | ||
import com.io.domain.ConnectionUpdate; | ||
import com.io.domain.Login; | ||
import com.io.domain.UserEdit; | ||
import com.io.net.Connector; | ||
import com.io.net.ConnectorEvent; | ||
|
||
import javax.swing.*; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
public class Client { | ||
|
||
public static final int INITIAL_USER_ID = -1; | ||
|
||
public static final String INITIAL_USER_NAME = "user"; | ||
|
||
public StartListening listening; //TODO: Make private | ||
|
||
public StartReceiving receiving; | ||
|
||
private String username; | ||
|
||
private int userId; | ||
|
||
private Connector connector; | ||
|
||
private UserListWindow userListWindow; | ||
|
||
public Client (final Editor editor) { | ||
|
||
listening = new StartListening(editor); | ||
receiving = new StartReceiving(editor, listening); | ||
|
||
userListWindow = new UserListWindow(editor.getProject()); | ||
|
||
try { | ||
connector = new Connector(); | ||
} catch(IOException ex) { | ||
System.out.println("Failed to connect to server"); | ||
return; | ||
} | ||
|
||
listening.addEventListener(new EditorEvent() { | ||
@Override | ||
public void sendChange(UserEdit userEdit) { | ||
userEdit.setUserId(userId); | ||
connector.sendUserEdit(userEdit); | ||
} | ||
}); | ||
|
||
connector.addEventListener(new ConnectorEvent() { | ||
@Override | ||
public void applyUserEdit(UserEdit userEdit) { | ||
userEdit.setUserId(userId); | ||
receiving.applyUserEditToDocument(editor, userEdit); | ||
} | ||
|
||
@Override | ||
public void applyUserId(Login login, Connector connector) { | ||
userId = login.getUserId(); | ||
username = login.getUsername(); | ||
userListWindow.addUser(new UserInfo(userId, username)); | ||
System.out.println(editor.getProject().getName() + ": User id is now " + userId); | ||
} | ||
|
||
@Override | ||
public void applyConnectionUpdate(ConnectionUpdate connectionUpdate) { | ||
ArrayList<UserInfo> users = connectionUpdate.getUserList(); | ||
|
||
System.out.println("Client received " + users.size()); | ||
|
||
for (UserInfo user : users) { | ||
userListWindow.addUser(user); | ||
} | ||
} | ||
}); | ||
|
||
(new Thread(connector)).start(); | ||
|
||
login(); | ||
} | ||
|
||
private void login() { | ||
username = JOptionPane.showInputDialog("Please enter a username"); | ||
|
||
Login login = new Login(INITIAL_USER_ID, username); | ||
connector.sendObject(login); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.io.gui; | ||
|
||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.LangDataKeys; | ||
import com.intellij.openapi.editor.Editor; | ||
import com.io.net.Server; | ||
|
||
public class StartIoServer extends AnAction { | ||
|
||
public void actionPerformed(AnActionEvent e) { | ||
|
||
final Editor editor = e.getData(LangDataKeys.EDITOR); | ||
new Server(editor); | ||
} | ||
} |
Oops, something went wrong.