2015-10-20 14:26:58 +00:00
|
|
|
package com.coder.client.gui.editor;
|
2015-10-20 06:56:14 +00:00
|
|
|
|
2015-10-20 14:26:58 +00:00
|
|
|
import java.io.IOException;
|
2015-10-20 06:56:14 +00:00
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.ArrayList;
|
2015-11-11 16:13:01 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Properties;
|
2015-10-20 06:56:14 +00:00
|
|
|
import java.util.ResourceBundle;
|
2015-11-11 16:13:01 +01:00
|
|
|
import java.util.logging.Logger;
|
2015-10-20 06:56:14 +00:00
|
|
|
|
|
|
|
|
import org.controlsfx.control.PropertySheet;
|
|
|
|
|
import org.controlsfx.property.editor.PropertyEditor;
|
|
|
|
|
|
2015-11-11 16:13:01 +01:00
|
|
|
import zutil.log.LogUtil;
|
|
|
|
|
|
|
|
|
|
import com.coder.client.CoderClient;
|
2015-10-20 14:26:58 +00:00
|
|
|
import com.coder.client.gui.GuiWindow;
|
2015-10-20 06:56:14 +00:00
|
|
|
import com.coder.client.property.CheckBoxProperty;
|
|
|
|
|
import com.coder.client.property.CoderClientProperty;
|
|
|
|
|
import com.coder.client.property.ComboBoxProperty;
|
2015-11-11 16:13:01 +01:00
|
|
|
import com.coder.client.session.ProjectRspMsgListener;
|
|
|
|
|
import com.coder.client.session.ProjectTypeRspMsgListener;
|
|
|
|
|
import com.coder.client.session.SessionListener;
|
|
|
|
|
import com.coder.server.message.ProjectRspMsg;
|
|
|
|
|
import com.coder.server.message.ProjectTypeRspMsg;
|
2015-10-20 06:56:14 +00:00
|
|
|
|
|
|
|
|
import javafx.beans.value.ChangeListener;
|
|
|
|
|
import javafx.beans.value.ObservableValue;
|
|
|
|
|
import javafx.event.ActionEvent;
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
|
import javafx.scene.control.Button;
|
|
|
|
|
import javafx.scene.control.TextArea;
|
|
|
|
|
import javafx.scene.control.TreeItem;
|
|
|
|
|
import javafx.scene.control.TreeView;
|
|
|
|
|
import javafx.util.Callback;
|
|
|
|
|
|
2015-10-20 14:26:58 +00:00
|
|
|
public class EditorWindow extends GuiWindow {
|
2015-11-11 16:13:01 +01:00
|
|
|
public static final Logger logger = LogUtil.getLogger();
|
|
|
|
|
private CoderClient client;
|
|
|
|
|
|
2015-10-20 06:56:14 +00:00
|
|
|
@FXML private TreeView<String> fileTreeView;
|
|
|
|
|
@FXML private TextArea editTextArea;
|
|
|
|
|
@FXML private PropertySheet propertySheet;
|
|
|
|
|
@FXML private Button compileButton;
|
|
|
|
|
@FXML private Button runButton;
|
2015-11-05 14:42:40 +01:00
|
|
|
@FXML private Button exitButton;
|
|
|
|
|
@FXML private Button changeProjectButton;
|
2015-10-20 06:56:14 +00:00
|
|
|
|
2015-11-11 16:13:01 +01:00
|
|
|
public EditorWindow(CoderClient client) throws IOException{
|
2015-10-20 14:26:58 +00:00
|
|
|
super(EditorWindow.class.getResource("EditorWindow.fxml"));
|
2015-11-11 16:13:01 +01:00
|
|
|
this.client = client;
|
|
|
|
|
client.getSessionHandler().addMessageListener(new ProjectRspMsgListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void messageReceived(final ProjectRspMsg msg) {
|
|
|
|
|
logger.fine("a ProjectRspMsg received");
|
|
|
|
|
if(msg.error != null){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setProjectName(msg.name);
|
|
|
|
|
|
|
|
|
|
Properties projectConfig = msg.config;
|
|
|
|
|
String projectDescription = msg.description;
|
|
|
|
|
List<String> fileList = msg.fileList;
|
|
|
|
|
String projectType = msg.type;
|
|
|
|
|
//TODO: handle msg
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
client.getSessionHandler().addMessageListener(new ProjectTypeRspMsgListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void messageReceived(ProjectTypeRspMsg msg) {
|
|
|
|
|
//TODO: update the project properties
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-10-20 06:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
|
|
|
|
setupPropertySheet();
|
|
|
|
|
setupFileTreeView();
|
2015-10-20 14:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void willShow(){
|
2015-11-11 16:13:01 +01:00
|
|
|
|
2015-10-20 06:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@FXML
|
2015-11-11 16:13:01 +01:00
|
|
|
protected void run(ActionEvent event){
|
|
|
|
|
//TODO
|
2015-10-20 06:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@FXML
|
2015-11-11 16:13:01 +01:00
|
|
|
protected void compile(ActionEvent event){
|
|
|
|
|
//TODO
|
2015-10-20 06:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-23 13:44:11 +00:00
|
|
|
@FXML
|
2015-11-11 16:13:01 +01:00
|
|
|
protected void changeProject(ActionEvent event){
|
|
|
|
|
client.getProjectHandler().setProject(null);
|
|
|
|
|
client.getProjectHandler().selectProject();
|
2015-10-23 13:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-05 14:42:40 +01:00
|
|
|
@FXML
|
2015-11-11 16:13:01 +01:00
|
|
|
protected void exit(ActionEvent event){
|
|
|
|
|
client.exit();
|
2015-11-05 14:42:40 +01:00
|
|
|
}
|
|
|
|
|
|
2015-10-20 06:56:14 +00:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 16:13:45 +00:00
|
|
|
@Override
|
|
|
|
|
protected String getTitle() {
|
|
|
|
|
return "Coder Client";
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 16:13:01 +01:00
|
|
|
private void setErrorMessage(String msg) {
|
2015-10-23 13:44:11 +00:00
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 09:02:39 +01:00
|
|
|
public void setProjectName(String name) {
|
|
|
|
|
fileTreeView.getRoot().setValue(name);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 16:13:01 +01:00
|
|
|
@Override
|
|
|
|
|
protected String getDescriptiveName() {
|
|
|
|
|
return "Editor Window";
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-20 06:56:14 +00:00
|
|
|
}
|