now using JavaFX instead of Swing
This commit is contained in:
parent
83e0196c50
commit
3177714fc5
22 changed files with 518 additions and 686 deletions
111
src/com/coder/client/gui/editor/EditorWindow.java
Normal file
111
src/com/coder/client/gui/editor/EditorWindow.java
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
package com.coder.client.gui.editor;
|
||||
|
||||
import java.io.IOException;
|
||||
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.gui.GuiWindow;
|
||||
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.scene.control.Button;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TreeItem;
|
||||
import javafx.scene.control.TreeView;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Callback;
|
||||
|
||||
public class EditorWindow extends GuiWindow {
|
||||
|
||||
private HashSet<EditorWindowListener> listsners = new HashSet<EditorWindowListener>();
|
||||
|
||||
@FXML private TreeView<String> fileTreeView;
|
||||
@FXML private TextArea editTextArea;
|
||||
@FXML private PropertySheet propertySheet;
|
||||
@FXML private Button compileButton;
|
||||
@FXML private Button runButton;
|
||||
|
||||
public EditorWindow() throws IOException{
|
||||
super(EditorWindow.class.getResource("EditorWindow.fxml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
||||
setupPropertySheet();
|
||||
setupFileTreeView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void willShow(){
|
||||
|
||||
}
|
||||
|
||||
@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(EditorWindowListener listener) {
|
||||
this.listsners.add(listener);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue