new support classes added
This commit is contained in:
parent
9764f546da
commit
83e0196c50
21 changed files with 798 additions and 9 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry excluding="com/coder/client/gui/GUIManager.java|com/coder/client/Main.java" kind="src" path="src"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/ZUtil"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/ZUtil"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/CoderServer"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/CoderServer"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-8-openjdk-i386"/>
|
||||||
|
<classpathentry kind="lib" path="lib/controlsfx-8.20.9.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,12 @@
|
||||||
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
|
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
|
||||||
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
|
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
|
||||||
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
|
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
|
||||||
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||||
|
<listEntry value="/CoderClient"/>
|
||||||
|
</listAttribute>
|
||||||
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||||
|
<listEntry value="4"/>
|
||||||
|
</listAttribute>
|
||||||
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
|
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
|
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
|
||||||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
|
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
|
||||||
|
|
|
||||||
BIN
lib/controlsfx-8.20.9.jar
Normal file
BIN
lib/controlsfx-8.20.9.jar
Normal file
Binary file not shown.
|
|
@ -7,10 +7,12 @@ import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import com.coder.client.LoginDialog.LoginDialogAction;
|
|
||||||
import com.coder.server.CoderServer;
|
import com.coder.server.CoderServer;
|
||||||
import com.coder.server.message.CoderMessage;
|
import com.coder.server.message.CoderMessage;
|
||||||
|
import com.coder.server.message.ConfigData;
|
||||||
import com.coder.server.message.ProjectListData;
|
import com.coder.server.message.ProjectListData;
|
||||||
|
import com.coder.server.message.ProjectListReqMsg;
|
||||||
|
import com.coder.server.message.ProjectRspMsg;
|
||||||
|
|
||||||
import zutil.log.CompactLogFormatter;
|
import zutil.log.CompactLogFormatter;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
|
@ -23,6 +25,7 @@ public class CoderClient extends Thread{
|
||||||
private int port;
|
private int port;
|
||||||
private Session session;
|
private Session session;
|
||||||
private ProjectEditorWindow projectEditorWindow;
|
private ProjectEditorWindow projectEditorWindow;
|
||||||
|
private ProjectSelectDialog projectSelectDialog;
|
||||||
private String username = null;
|
private String username = null;
|
||||||
private char[] password = null;
|
private char[] password = null;
|
||||||
private int connectionRetriesLimit = DEFAULT_CONNECTION_RETRIES; //if zero, try forever
|
private int connectionRetriesLimit = DEFAULT_CONNECTION_RETRIES; //if zero, try forever
|
||||||
|
|
@ -32,6 +35,7 @@ public class CoderClient extends Thread{
|
||||||
this.port = port;
|
this.port = port;
|
||||||
|
|
||||||
this.projectEditorWindow = new ProjectEditorWindow("CoderClient");
|
this.projectEditorWindow = new ProjectEditorWindow("CoderClient");
|
||||||
|
this.projectSelectDialog = new ProjectSelectDialog(null);
|
||||||
|
|
||||||
LogUtil.setGlobalLevel(Level.INFO);
|
LogUtil.setGlobalLevel(Level.INFO);
|
||||||
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
||||||
|
|
@ -79,7 +83,7 @@ public class CoderClient extends Thread{
|
||||||
LoginDialog loginDialog = new LoginDialog(username, null);
|
LoginDialog loginDialog = new LoginDialog(username, null);
|
||||||
loginDialog.setVisible(true); //blocking
|
loginDialog.setVisible(true); //blocking
|
||||||
loginDialog.dispose();
|
loginDialog.dispose();
|
||||||
if(loginDialog.getAction() == LoginDialogAction.CANCEL){
|
if(loginDialog.getAction() == LoginDialog.LoginDialogAction.CANCEL){
|
||||||
logger.fine("Login dialog closed or canceled by the user. terminating.");
|
logger.fine("Login dialog closed or canceled by the user. terminating.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -106,13 +110,46 @@ public class CoderClient extends Thread{
|
||||||
session.addCoderMessageReceivedListener(new CoderMessageReceivedListener() {
|
session.addCoderMessageReceivedListener(new CoderMessageReceivedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void projectListRspReceived(Map<String, ProjectListData> projectListRsp) {
|
public void projectListRspReceived(Map<String, ProjectListData> projectListRsp) {
|
||||||
//TODO
|
for(String projectName : projectListRsp.keySet()){
|
||||||
|
ProjectListData projectData = projectListRsp.get(projectName);
|
||||||
|
projectSelectDialog.addProjectToList(projectName, projectData.type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void projectTypeRspReceived(Map<String, ConfigData> projectTypeRsp) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void projectRspReceived(ProjectRspMsg projectRspMsg) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//start receiving traffic from the server
|
//start receiving traffic from the server
|
||||||
session.start();
|
session.start();
|
||||||
|
|
||||||
|
//clear the current local project list
|
||||||
|
this.projectSelectDialog.clearProjectList();
|
||||||
|
|
||||||
|
//request a new project list from the server
|
||||||
|
CoderMessage msg = new CoderMessage();
|
||||||
|
msg.ProjectListReq = new ProjectListReqMsg();
|
||||||
|
try {
|
||||||
|
session.send(msg);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.log(Level.SEVERE, "Unable to send ProjectListReqMsg", e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//show the project selector dialog
|
||||||
|
this.projectSelectDialog.setVisible(true); //blocking
|
||||||
|
if(this.projectSelectDialog.getAction() == ProjectSelectDialog.ProjectSelectDialogAction.CANCEL){
|
||||||
|
logger.fine("Project select dialog closed or canceled by the user. terminating.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
String selectedProjectName = this.projectSelectDialog.getSelecteProjectName();
|
||||||
|
logger.info("Project \"" +selectedProjectName+ "\" was selected.");
|
||||||
|
|
||||||
//add a listener to forward messages from the editor GUI to the server
|
//add a listener to forward messages from the editor GUI to the server
|
||||||
this.projectEditorWindow.addMessageSentListener(new GUIMessageSentListener(){
|
this.projectEditorWindow.addMessageSentListener(new GUIMessageSentListener(){
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -152,15 +189,15 @@ public class CoderClient extends Thread{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPassword(char[] password) {
|
public void setPassword(char[] password) {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUsername(String username) {
|
public void setUsername(String username) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRetryConnectForever(boolean tryForever) {
|
public void setRetryConnectForever(boolean tryForever) {
|
||||||
if(tryForever){
|
if(tryForever){
|
||||||
this.connectionRetriesLimit = 0;
|
this.connectionRetriesLimit = 0;
|
||||||
}else{
|
}else{
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,15 @@ package com.coder.client;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.coder.server.message.ConfigData;
|
||||||
import com.coder.server.message.ProjectListData;
|
import com.coder.server.message.ProjectListData;
|
||||||
|
import com.coder.server.message.ProjectRspMsg;
|
||||||
|
|
||||||
public interface CoderMessageReceivedListener {
|
public interface CoderMessageReceivedListener {
|
||||||
|
|
||||||
|
//project messages
|
||||||
|
void projectTypeRspReceived(Map<String,ConfigData> projectTypeRsp);
|
||||||
void projectListRspReceived(Map<String, ProjectListData> projectListRsp);
|
void projectListRspReceived(Map<String, ProjectListData> projectListRsp);
|
||||||
|
void projectRspReceived(ProjectRspMsg projectRspMsg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
src/com/coder/client/LoginCridentials.java
Normal file
21
src/com/coder/client/LoginCridentials.java
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.coder.client;
|
||||||
|
|
||||||
|
public class LoginCridentials {
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
private char[] password;
|
||||||
|
|
||||||
|
public LoginCridentials(String username, char[] password){
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername(){
|
||||||
|
return this.username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public char[] getPassword(){
|
||||||
|
return this.password;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
69
src/com/coder/client/Main.java
Normal file
69
src/com/coder/client/Main.java
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.coder.client;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import com.coder.client.gui.EditorWindowController;
|
||||||
|
import com.coder.client.gui.GUIManager;
|
||||||
|
import com.coder.server.CoderServer;
|
||||||
|
|
||||||
|
import zutil.log.LogUtil;
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class Main extends Application {
|
||||||
|
public static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Application.launch(Main.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage mainStage) throws Exception {
|
||||||
|
|
||||||
|
//parse program arguments
|
||||||
|
Map<String, String> params = this.getParameters().getNamed();
|
||||||
|
String username = null;
|
||||||
|
char[] password = null;
|
||||||
|
boolean reconnectForever = false;
|
||||||
|
for(String key : params.keySet()){
|
||||||
|
String value = params.get(key);
|
||||||
|
if(key.equals("username")){
|
||||||
|
username = value;
|
||||||
|
}else if(key.equals("password")){
|
||||||
|
password = value.toCharArray();
|
||||||
|
}else if(key.equals("retry-connect-forever")){
|
||||||
|
reconnectForever = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//load FXML resources
|
||||||
|
GUIManager guiManager = new GUIManager(mainStage);
|
||||||
|
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/coder/client/gui/EditorWindowGUI.fxml"));
|
||||||
|
Scene scene = new Scene((Parent)loader.load());
|
||||||
|
EditorWindowController editorController = loader.<EditorWindowController>getController();
|
||||||
|
editorController.setScene(scene);
|
||||||
|
guiManager.setEditWindow(editorController);
|
||||||
|
|
||||||
|
|
||||||
|
mainStage.setTitle("CoderClient");
|
||||||
|
|
||||||
|
//create a client instance
|
||||||
|
int port = CoderServer.SERVER_PORT;
|
||||||
|
CoderClient client = new CoderClient("127.0.0.1", port, guiManager);
|
||||||
|
if(username != null){
|
||||||
|
client.setUsername(username);
|
||||||
|
if(password != null){
|
||||||
|
client.setPassword(password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
client.setRetryConnectForever(reconnectForever);
|
||||||
|
client.start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
58
src/com/coder/client/ProjectSelectDialog.java
Normal file
58
src/com/coder/client/ProjectSelectDialog.java
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.coder.client;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Frame;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.KeyListener;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JPasswordField;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.border.LineBorder;
|
||||||
|
|
||||||
|
public class ProjectSelectDialog extends JDialog {
|
||||||
|
private static final long serialVersionUID = 3664648491769811261L;
|
||||||
|
|
||||||
|
public static enum ProjectSelectDialogAction{
|
||||||
|
PROJECT_SELECTED,
|
||||||
|
CANCEL
|
||||||
|
}
|
||||||
|
private ProjectSelectDialogAction action = ProjectSelectDialogAction.CANCEL;
|
||||||
|
|
||||||
|
public ProjectSelectDialog(Frame parent) {
|
||||||
|
super(parent, "Select Project", true);
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
|
||||||
|
//pack the dialog
|
||||||
|
pack();
|
||||||
|
|
||||||
|
setLocationRelativeTo(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelecteProjectName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProjectSelectDialogAction getAction() {
|
||||||
|
return this.action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearProjectList() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addProjectToList(String projectName, String type) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -216,6 +216,18 @@ public class Session extends Thread {
|
||||||
listener.projectListRspReceived(msg.ProjectListRsp);
|
listener.projectListRspReceived(msg.ProjectListRsp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(msg.ProjectRsp != null){
|
||||||
|
logger.fine("The message contains a ProjectRspMsg");
|
||||||
|
for(CoderMessageReceivedListener listener : messageReceivedlisteners){
|
||||||
|
listener.projectRspReceived(msg.ProjectRsp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(msg.ProjectTypeRsp != null){
|
||||||
|
logger.fine("The message contains a ProjectTypeRsp");
|
||||||
|
for(CoderMessageReceivedListener listener : messageReceivedlisteners){
|
||||||
|
listener.projectTypeRspReceived(msg.ProjectTypeRsp);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
84
src/com/coder/client/file/ProjectDirectory.java
Normal file
84
src/com/coder/client/file/ProjectDirectory.java
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.coder.client.file;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ProjectDirectory extends ProjectFileObject {
|
||||||
|
private LinkedList<ProjectFileObject> objectList;
|
||||||
|
|
||||||
|
public ProjectDirectory(String name){
|
||||||
|
super(name);
|
||||||
|
this.objectList = new LinkedList<ProjectFileObject>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProjectFileObject> getAll(){
|
||||||
|
return objectList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsFile(String fileName){
|
||||||
|
for(ProjectFileObject fileObject : objectList){
|
||||||
|
if(fileObject instanceof ProjectFile){
|
||||||
|
if(fileObject.getName().equals(fileName)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFile(ProjectFile file){
|
||||||
|
this.objectList.add(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteFile(String fileName){
|
||||||
|
for(ProjectFileObject fileObject : objectList){
|
||||||
|
if(fileObject instanceof ProjectFile){
|
||||||
|
if(fileObject.getName().equals(fileName)){
|
||||||
|
this.objectList.remove(fileObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsDirectory(String dirName){
|
||||||
|
for(ProjectFileObject fileObject : objectList){
|
||||||
|
if(fileObject instanceof ProjectDirectory){
|
||||||
|
if(fileObject.getName().equals(dirName)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDirectory(String dirName){
|
||||||
|
ProjectDirectory dir = new ProjectDirectory(dirName);
|
||||||
|
this.objectList.add(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteDirectory(String dirName){
|
||||||
|
for(ProjectFileObject fileObject : objectList){
|
||||||
|
if(fileObject instanceof ProjectDirectory){
|
||||||
|
if(fileObject.getName().equals(dirName)){
|
||||||
|
this.objectList.remove(fileObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProjectDirectory getDirectory(String dirName) {
|
||||||
|
for(ProjectFileObject fileObject : objectList){
|
||||||
|
if(fileObject instanceof ProjectDirectory){
|
||||||
|
if(fileObject.getName().equals(dirName)){
|
||||||
|
return (ProjectDirectory) fileObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return this.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
src/com/coder/client/file/ProjectFile.java
Normal file
15
src/com/coder/client/file/ProjectFile.java
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.coder.client.file;
|
||||||
|
|
||||||
|
public class ProjectFile extends ProjectFileObject{
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
public ProjectFile(String name, String filePath) {
|
||||||
|
super(name);
|
||||||
|
this.filePath = filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return this.getName() + " ("+filePath+")";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
14
src/com/coder/client/file/ProjectFileObject.java
Normal file
14
src/com/coder/client/file/ProjectFileObject.java
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.coder.client.file;
|
||||||
|
|
||||||
|
public abstract class ProjectFileObject{
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public ProjectFileObject(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
124
src/com/coder/client/file/ProjectFileTree.java
Normal file
124
src/com/coder/client/file/ProjectFileTree.java
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
package com.coder.client.file;
|
||||||
|
|
||||||
|
public class ProjectFileTree {
|
||||||
|
private ProjectDirectory root;
|
||||||
|
|
||||||
|
public ProjectFileTree(){
|
||||||
|
this.root = new ProjectDirectory("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printFileTree(){
|
||||||
|
if(root != null){
|
||||||
|
printDirectoryContent(root, 0);
|
||||||
|
}else{
|
||||||
|
System.out.println("File tree not set");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printDirectoryContent(ProjectDirectory dir, int indentation){
|
||||||
|
for(ProjectFileObject obj : dir.getAll()){
|
||||||
|
if(obj instanceof ProjectDirectory){
|
||||||
|
printIndentation(indentation);
|
||||||
|
System.out.println("DIR:"+obj);
|
||||||
|
printDirectoryContent((ProjectDirectory) obj, indentation+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(ProjectFileObject obj : dir.getAll()){
|
||||||
|
if(obj instanceof ProjectFile){
|
||||||
|
printIndentation(indentation);
|
||||||
|
System.out.println("FILE:"+obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printIndentation(int indentation){
|
||||||
|
for(int i = 0; i < indentation; ++i){
|
||||||
|
System.out.print(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean parseFileList(String[] filePaths){
|
||||||
|
ProjectDirectory root = new ProjectDirectory("/");
|
||||||
|
for(String filePath : filePaths){
|
||||||
|
if(filePath.endsWith("/")){
|
||||||
|
System.out.println("SEVERE: file path is not pointing to a file: " + filePath);
|
||||||
|
this.root = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String[] tmp;
|
||||||
|
if(filePath.startsWith("/")){
|
||||||
|
tmp = filePath.substring(1, filePath.length()).split("/");
|
||||||
|
}else{
|
||||||
|
tmp = filePath.split("/");
|
||||||
|
}
|
||||||
|
int i;
|
||||||
|
ProjectDirectory tmpRoot = root;
|
||||||
|
for(i = 0; i < tmp.length-1; ++i){
|
||||||
|
String directoryName = tmp[i];
|
||||||
|
if(directoryName.isEmpty()){
|
||||||
|
System.out.println("SEVERE: a directory name cannot be empty");
|
||||||
|
this.root = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(tmpRoot.containsDirectory(directoryName) == false){
|
||||||
|
tmpRoot.addDirectory(directoryName);
|
||||||
|
}else{
|
||||||
|
//directory already exist
|
||||||
|
}
|
||||||
|
tmpRoot = tmpRoot.getDirectory(directoryName);
|
||||||
|
}
|
||||||
|
String fileName = tmp[i];
|
||||||
|
if(tmpRoot.containsDirectory(fileName)){
|
||||||
|
//logger.sever("File list contains a directory and file with the same name");
|
||||||
|
System.out.println("SEVERE: File list contains a directory and file with the same name");
|
||||||
|
this.root = null;
|
||||||
|
return false;
|
||||||
|
}else if(tmpRoot.containsFile(fileName) == false){
|
||||||
|
ProjectFile file = new ProjectFile(fileName, filePath);
|
||||||
|
tmpRoot.addFile(file);
|
||||||
|
}else{
|
||||||
|
//file already exists
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateCurrentFileList(root, this.root);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCurrentFileList(ProjectDirectory sourceRoot, ProjectDirectory targetRoot){
|
||||||
|
|
||||||
|
//remove files in target that does not exist in source
|
||||||
|
for(ProjectFileObject targetFileObject : targetRoot.getAll()){
|
||||||
|
String fileObjectName = targetFileObject.getName();
|
||||||
|
if(targetFileObject instanceof ProjectFile){ //target file is a file
|
||||||
|
if(sourceRoot.containsFile(fileObjectName) == false){
|
||||||
|
targetRoot.deleteFile(fileObjectName);
|
||||||
|
targetFileObject = null;
|
||||||
|
}
|
||||||
|
}else if(targetFileObject instanceof ProjectDirectory){ //target file is a directory
|
||||||
|
if(sourceRoot.containsDirectory(fileObjectName) == false){
|
||||||
|
targetRoot.deleteDirectory(fileObjectName);
|
||||||
|
targetFileObject = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//add files to target that exist in source
|
||||||
|
for(ProjectFileObject sourceFileObject : sourceRoot.getAll()){
|
||||||
|
String fileObjectName = sourceFileObject.getName();
|
||||||
|
if(sourceFileObject instanceof ProjectFile){ //source file is a file
|
||||||
|
if(targetRoot.containsFile(fileObjectName) == false){
|
||||||
|
ProjectFile file = (ProjectFile)sourceFileObject;
|
||||||
|
targetRoot.addFile(file);
|
||||||
|
}
|
||||||
|
}else if(sourceFileObject instanceof ProjectDirectory){ //source file is a directory
|
||||||
|
if(targetRoot.containsDirectory(fileObjectName) == false){
|
||||||
|
targetRoot.addDirectory(fileObjectName);
|
||||||
|
}
|
||||||
|
//recursive
|
||||||
|
ProjectDirectory dir = (ProjectDirectory)sourceFileObject;
|
||||||
|
updateCurrentFileList(dir, targetRoot.getDirectory(fileObjectName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
37
src/com/coder/client/file/ProjectFileTreeTest.java
Normal file
37
src/com/coder/client/file/ProjectFileTreeTest.java
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.coder.client.file;
|
||||||
|
|
||||||
|
public class ProjectFileTreeTest {
|
||||||
|
ProjectFileTree tree = new ProjectFileTree();
|
||||||
|
|
||||||
|
public ProjectFileTreeTest(){
|
||||||
|
tree.printFileTree();
|
||||||
|
|
||||||
|
tree.parseFileList(new String[]{"/test"});
|
||||||
|
tree.printFileTree();
|
||||||
|
|
||||||
|
tree.parseFileList(new String[]{"/test", "/test/test"});
|
||||||
|
tree.printFileTree();
|
||||||
|
|
||||||
|
tree.parseFileList(new String[]{"/test/test/"});
|
||||||
|
tree.printFileTree();
|
||||||
|
|
||||||
|
tree.parseFileList(new String[]{"/test/"});
|
||||||
|
tree.printFileTree();
|
||||||
|
|
||||||
|
tree.parseFileList(new String[]{"/"});
|
||||||
|
tree.printFileTree();
|
||||||
|
|
||||||
|
tree.parseFileList(new String[]{"//"});
|
||||||
|
tree.printFileTree();
|
||||||
|
|
||||||
|
tree.parseFileList(new String[]{"//test"});
|
||||||
|
tree.printFileTree();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
new ProjectFileTreeTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
5
src/com/coder/client/gui/Controller.java
Normal file
5
src/com/coder/client/gui/Controller.java
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.coder.client.gui;
|
||||||
|
|
||||||
|
public class Controller {
|
||||||
|
|
||||||
|
}
|
||||||
32
src/com/coder/client/gui/EditorWindow.java
Normal file
32
src/com/coder/client/gui/EditorWindow.java
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.coder.client.gui;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class EditorWindow extends Application {
|
||||||
|
|
||||||
|
public EditorWindow(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) throws Exception {
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("EditorWindowGUI.fxml"));
|
||||||
|
|
||||||
|
EditorWindowController editorController = loader.<EditorWindowController>getController();
|
||||||
|
|
||||||
|
Scene editorScene = new Scene((Parent)loader.load());
|
||||||
|
|
||||||
|
stage.setTitle("CoderClient");
|
||||||
|
stage.setScene(editorScene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Application.launch(EditorWindow.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
113
src/com/coder/client/gui/EditorWindowController.java
Normal file
113
src/com/coder/client/gui/EditorWindowController.java
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
package com.coder.client.gui;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import org.controlsfx.control.PropertySheet;
|
||||||
|
import org.controlsfx.property.editor.PropertyEditor;
|
||||||
|
|
||||||
|
import com.coder.client.GUIMessageSentListener;
|
||||||
|
import com.coder.client.property.CheckBoxProperty;
|
||||||
|
import com.coder.client.property.CoderClientProperty;
|
||||||
|
import com.coder.client.property.ComboBoxProperty;
|
||||||
|
import com.coder.server.message.CoderMessage;
|
||||||
|
|
||||||
|
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.TextArea;
|
||||||
|
import javafx.scene.control.TreeItem;
|
||||||
|
import javafx.scene.control.TreeView;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
|
||||||
|
public class EditorWindowController extends Controller implements Initializable {
|
||||||
|
|
||||||
|
private HashSet<GUIMessageSentListener> GUIMessageSentListeners = new HashSet<GUIMessageSentListener>();
|
||||||
|
|
||||||
|
@FXML private TreeView<String> fileTreeView;
|
||||||
|
@FXML private TextArea editTextArea;
|
||||||
|
@FXML private PropertySheet propertySheet;
|
||||||
|
@FXML private Button compileButton;
|
||||||
|
@FXML private Button runButton;
|
||||||
|
|
||||||
|
public EditorWindowController(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
||||||
|
|
||||||
|
setupPropertySheet();
|
||||||
|
setupFileTreeView();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
protected void handleRun(ActionEvent event){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
protected void handleCompile(ActionEvent event){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupFileTreeView(){
|
||||||
|
fileTreeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<String>>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends TreeItem<String>> item, TreeItem<String> oldValue, TreeItem<String> newValue) {
|
||||||
|
if(newValue != fileTreeView.getRoot()){
|
||||||
|
System.out.println("INFO: item " + newValue + " selected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
TreeItem<String> root = new TreeItem<String>("root");
|
||||||
|
root.setExpanded(true);
|
||||||
|
fileTreeView.setRoot(root);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupPropertySheet(){
|
||||||
|
//handle custom ProperySheet.Item's editor
|
||||||
|
propertySheet.setPropertyEditorFactory(new Callback<PropertySheet.Item, PropertyEditor<?>>(){
|
||||||
|
@Override
|
||||||
|
public PropertyEditor<?> call(PropertySheet.Item param) {
|
||||||
|
//only support internal types
|
||||||
|
if(param instanceof CoderClientProperty){
|
||||||
|
return ((CoderClientProperty<?>)param).getEditor();
|
||||||
|
}
|
||||||
|
//not a internal property type
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
propertySheet.getItems().clear();
|
||||||
|
|
||||||
|
ArrayList<String> boards = new ArrayList<String>();
|
||||||
|
boards.add("UNO");
|
||||||
|
boards.add("Mega");
|
||||||
|
ComboBoxProperty p1 = new ComboBoxProperty("Port", null, boards);
|
||||||
|
propertySheet.getItems().add(p1);
|
||||||
|
|
||||||
|
CheckBoxProperty p2 = new CheckBoxProperty("Melt?", false);
|
||||||
|
propertySheet.getItems().add(p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMessageSentListener(GUIMessageSentListener listener) {
|
||||||
|
this.GUIMessageSentListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessage(CoderMessage msg){
|
||||||
|
for(GUIMessageSentListener listener : GUIMessageSentListeners){
|
||||||
|
listener.sendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
47
src/com/coder/client/gui/EditorWindowGUI.fxml
Normal file
47
src/com/coder/client/gui/EditorWindowGUI.fxml
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import org.controlsfx.control.*?>
|
||||||
|
<?import javafx.geometry.*?>
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<SplitPane dividerPositions="0.26588628762541805, 0.7391304347826086" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.coder.client.gui.EditorWindowController">
|
||||||
|
<items>
|
||||||
|
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" SplitPane.resizableWithParent="false">
|
||||||
|
<children>
|
||||||
|
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" prefHeight="398.0" prefWidth="156.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<content>
|
||||||
|
<TreeView fx:id="fileTreeView" prefHeight="398.0" prefWidth="156.0" />
|
||||||
|
</content>
|
||||||
|
</ScrollPane>
|
||||||
|
</children></AnchorPane>
|
||||||
|
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
|
||||||
|
<children>
|
||||||
|
<ScrollPane fitToHeight="true" fitToWidth="true" prefHeight="398.0" prefWidth="271.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<content>
|
||||||
|
<TextArea fx:id="editTextArea" prefHeight="398.0" prefWidth="271.0" />
|
||||||
|
</content>
|
||||||
|
</ScrollPane>
|
||||||
|
</children></AnchorPane>
|
||||||
|
<AnchorPane prefHeight="200.0" prefWidth="200.0" SplitPane.resizableWithParent="false">
|
||||||
|
<children>
|
||||||
|
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<content>
|
||||||
|
<PropertySheet fx:id="propertySheet" modeSwitcherVisible="false" searchBoxVisible="false" />
|
||||||
|
</content>
|
||||||
|
</ScrollPane>
|
||||||
|
<HBox alignment="CENTER" maxHeight="50.0" prefHeight="50.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
||||||
|
<children>
|
||||||
|
<Button fx:id="compileButton" mnemonicParsing="false" onAction="#handleCompile" text="Compile">
|
||||||
|
<HBox.margin>
|
||||||
|
<Insets right="15.0" />
|
||||||
|
</HBox.margin>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="runButton" mnemonicParsing="false" onAction="#handleRun" text="Run" />
|
||||||
|
</children>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
</items>
|
||||||
|
</SplitPane>
|
||||||
27
src/com/coder/client/property/CheckBoxProperty.java
Normal file
27
src/com/coder/client/property/CheckBoxProperty.java
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.coder.client.property;
|
||||||
|
|
||||||
|
import org.controlsfx.property.editor.Editors;
|
||||||
|
import org.controlsfx.property.editor.PropertyEditor;
|
||||||
|
|
||||||
|
public class CheckBoxProperty extends CoderClientProperty<Boolean> {
|
||||||
|
|
||||||
|
public CheckBoxProperty(String name, boolean defaultValue){
|
||||||
|
super(name, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> getType() {
|
||||||
|
return Boolean.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PropertyEditor<?> getEditor() {
|
||||||
|
return Editors.createCheckEditor(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
51
src/com/coder/client/property/CoderClientProperty.java
Normal file
51
src/com/coder/client/property/CoderClientProperty.java
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.coder.client.property;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.controlsfx.control.PropertySheet;
|
||||||
|
import org.controlsfx.property.editor.PropertyEditor;
|
||||||
|
|
||||||
|
public abstract class CoderClientProperty<T> implements PropertySheet.Item {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private T value;
|
||||||
|
|
||||||
|
public CoderClientProperty(String name, T defaultValue){
|
||||||
|
this.name = name;
|
||||||
|
this.value = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEditable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void setValue(Object value) {
|
||||||
|
this.value = (T)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Class<? extends PropertyEditor<?>>> getPropertyEditorClass() {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCategory() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract PropertyEditor<?> getEditor();
|
||||||
|
|
||||||
|
}
|
||||||
31
src/com/coder/client/property/ComboBoxProperty.java
Normal file
31
src/com/coder/client/property/ComboBoxProperty.java
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.coder.client.property;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.controlsfx.property.editor.Editors;
|
||||||
|
import org.controlsfx.property.editor.PropertyEditor;
|
||||||
|
|
||||||
|
public class ComboBoxProperty extends CoderClientProperty<String> {
|
||||||
|
private Collection<String> valueAlternatives;
|
||||||
|
|
||||||
|
public ComboBoxProperty(String name, String defaultValue, Collection<String> valueAlternatives){
|
||||||
|
super(name, defaultValue);
|
||||||
|
this.valueAlternatives = valueAlternatives;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> getType() {
|
||||||
|
return valueAlternatives.getClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PropertyEditor<?> getEditor() {
|
||||||
|
return Editors.createChoiceEditor(this, valueAlternatives);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue