now using JavaFX instead of Swing
This commit is contained in:
parent
83e0196c50
commit
3177714fc5
22 changed files with 518 additions and 686 deletions
|
|
@ -1,5 +0,0 @@
|
|||
package com.coder.client.gui;
|
||||
|
||||
public class Controller {
|
||||
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
74
src/com/coder/client/gui/GuiWindow.java
Normal file
74
src/com/coder/client/gui/GuiWindow.java
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
package com.coder.client.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public abstract class GuiWindow implements Initializable{
|
||||
|
||||
private Scene scene;
|
||||
private Stage stage;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param fxmlFile The .fxml file to load for this GUI element
|
||||
* @throws IOException If unable to find or load the file
|
||||
*/
|
||||
public GuiWindow(URL fxmlFile) throws IOException{
|
||||
FXMLLoader loader = new FXMLLoader(fxmlFile);
|
||||
loader.setController(this);
|
||||
scene = new Scene((Parent)loader.load());
|
||||
}
|
||||
|
||||
/**
|
||||
* show on the given stage
|
||||
* @param stage The stage to show on
|
||||
*/
|
||||
public void showOnStage(Stage stage){
|
||||
stage.setScene(scene);
|
||||
this.stage = stage;
|
||||
willShow();
|
||||
stage.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* show a modal dialog
|
||||
* @param parent The dialogs parent
|
||||
*/
|
||||
public void showModal(Stage parent){
|
||||
Stage modalStage = new Stage();
|
||||
modalStage.initModality(Modality.WINDOW_MODAL);
|
||||
modalStage.initOwner(parent);
|
||||
modalStage.setScene(scene);
|
||||
this.stage = modalStage;
|
||||
willShow();
|
||||
modalStage.showAndWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* hide the stage
|
||||
*/
|
||||
public void close(){
|
||||
if(stage != null){
|
||||
stage.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called every time before showed on stage
|
||||
*/
|
||||
protected abstract void willShow();
|
||||
|
||||
/**
|
||||
* Will be called once when created
|
||||
*/
|
||||
public abstract void initialize(URL fxmlFileLocation, ResourceBundle resources);
|
||||
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
<?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">
|
||||
<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">
|
||||
<items>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" SplitPane.resizableWithParent="false">
|
||||
<children>
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.coder.client.gui;
|
||||
package com.coder.client.gui.editor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -8,7 +9,7 @@ import java.util.ResourceBundle;
|
|||
import org.controlsfx.control.PropertySheet;
|
||||
import org.controlsfx.property.editor.PropertyEditor;
|
||||
|
||||
import com.coder.client.GUIMessageSentListener;
|
||||
import com.coder.client.gui.GuiWindow;
|
||||
import com.coder.client.property.CheckBoxProperty;
|
||||
import com.coder.client.property.CoderClientProperty;
|
||||
import com.coder.client.property.ComboBoxProperty;
|
||||
|
|
@ -19,16 +20,16 @@ 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.stage.Stage;
|
||||
import javafx.util.Callback;
|
||||
|
||||
public class EditorWindowController extends Controller implements Initializable {
|
||||
public class EditorWindow extends GuiWindow {
|
||||
|
||||
private HashSet<GUIMessageSentListener> GUIMessageSentListeners = new HashSet<GUIMessageSentListener>();
|
||||
private HashSet<EditorWindowListener> listsners = new HashSet<EditorWindowListener>();
|
||||
|
||||
@FXML private TreeView<String> fileTreeView;
|
||||
@FXML private TextArea editTextArea;
|
||||
|
|
@ -36,15 +37,18 @@ public class EditorWindowController extends Controller implements Initializable
|
|||
@FXML private Button compileButton;
|
||||
@FXML private Button runButton;
|
||||
|
||||
public EditorWindowController(){
|
||||
super();
|
||||
public EditorWindow() throws IOException{
|
||||
super(EditorWindow.class.getResource("EditorWindow.fxml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
||||
|
||||
setupPropertySheet();
|
||||
setupFileTreeView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void willShow(){
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -100,14 +104,8 @@ public class EditorWindowController extends Controller implements Initializable
|
|||
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);
|
||||
}
|
||||
public void addMessageSentListener(EditorWindowListener listener) {
|
||||
this.listsners.add(listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.coder.client.gui.editor;
|
||||
|
||||
public interface EditorWindowListener {
|
||||
|
||||
}
|
||||
42
src/com/coder/client/gui/login/LoginDialog.fxml
Normal file
42
src/com/coder/client/gui/login/LoginDialog.fxml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
|
||||
<GridPane prefHeight="113.0" prefWidth="294.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints maxWidth="142.0" minWidth="10.0" prefWidth="76.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="228.0" minWidth="10.0" prefWidth="198.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label text="username" />
|
||||
<TextField fx:id="usernameTextField" onKeyPressed="#keyPressed" prefHeight="25.0" prefWidth="291.0" GridPane.columnIndex="1" />
|
||||
<Label text="password" GridPane.rowIndex="1" />
|
||||
<PasswordField fx:id="passwordPasswordField" onKeyPressed="#keyPressed" prefHeight="25.0" prefWidth="291.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
<HBox alignment="CENTER_RIGHT" prefHeight="69.0" prefWidth="218.0" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
||||
<children>
|
||||
<Button fx:id="loginButton" mnemonicParsing="false" onAction="#login" text="Login">
|
||||
<HBox.margin>
|
||||
<Insets right="10.0" />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
<Button fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel">
|
||||
<HBox.margin>
|
||||
<Insets />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
<padding>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
</padding>
|
||||
</GridPane>
|
||||
87
src/com/coder/client/gui/login/LoginDialog.java
Normal file
87
src/com/coder/client/gui/login/LoginDialog.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package com.coder.client.gui.login;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.PasswordField;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
|
||||
import com.coder.client.gui.GuiWindow;
|
||||
|
||||
public class LoginDialog extends GuiWindow {
|
||||
public static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
@FXML private TextField usernameTextField;
|
||||
@FXML private PasswordField passwordPasswordField;
|
||||
@FXML private Button cancelButton;
|
||||
@FXML private Button loginButton;
|
||||
private LoginDialogAction action;
|
||||
|
||||
public LoginDialog() throws IOException {
|
||||
super(LoginDialog.class.getResource("LoginDialog.fxml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void willShow(){
|
||||
action = LoginDialogAction.CANCEL;
|
||||
passwordPasswordField.setText("");
|
||||
if(!usernameTextField.getText().isEmpty()){
|
||||
passwordPasswordField.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void keyPressed(KeyEvent event) {
|
||||
if(event.getCode() == KeyCode.ENTER){
|
||||
logger.fine("User pressed the ENTER key");
|
||||
loginButton.fire();
|
||||
}else if(event.getCode() == KeyCode.ESCAPE){
|
||||
logger.fine("User pressed the ESCAPE key");
|
||||
cancelButton.fire();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void login(ActionEvent event){
|
||||
action = LoginDialogAction.LOGIN;
|
||||
this.close();
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void cancel(ActionEvent event){
|
||||
action = LoginDialogAction.CANCEL;
|
||||
this.close();
|
||||
}
|
||||
|
||||
public LoginDialogAction getAction(){
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setUsername(String username){
|
||||
usernameTextField.setText(username);
|
||||
}
|
||||
|
||||
public String getUsername(){
|
||||
return usernameTextField.getText();
|
||||
}
|
||||
|
||||
public char[] getPassword(){
|
||||
//TODO: fix this since is not safe since the password will be in a string
|
||||
return passwordPasswordField.getText().toCharArray();
|
||||
}
|
||||
|
||||
}
|
||||
6
src/com/coder/client/gui/login/LoginDialogAction.java
Normal file
6
src/com/coder/client/gui/login/LoginDialogAction.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package com.coder.client.gui.login;
|
||||
|
||||
public enum LoginDialogAction {
|
||||
LOGIN,
|
||||
CANCEL
|
||||
}
|
||||
51
src/com/coder/client/gui/project/SelectProjectDialog.fxml
Normal file
51
src/com/coder/client/gui/project/SelectProjectDialog.fxml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
|
||||
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="217.0" prefWidth="396.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER">
|
||||
<content>
|
||||
<ListView fx:id="projectListView" prefHeight="200.0" prefWidth="200.0" />
|
||||
</content>
|
||||
</ScrollPane>
|
||||
<GridPane prefHeight="77.0" prefWidth="396.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<HBox alignment="CENTER_RIGHT" prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="1">
|
||||
<children>
|
||||
<Button fx:id="cancelButton" mnemonicParsing="false" onAction="#cancel" text="Cancel">
|
||||
<HBox.margin>
|
||||
<Insets right="10.0" />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
<Button fx:id="openProjectButton" mnemonicParsing="false" onAction="#openProject" text="Open Project">
|
||||
<HBox.margin>
|
||||
<Insets right="10.0" />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
</children>
|
||||
</HBox>
|
||||
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0">
|
||||
<children>
|
||||
<Button fx:id="newProjectButton" mnemonicParsing="false" onAction="#newProject" text="New Project">
|
||||
<HBox.margin>
|
||||
<Insets left="10.0" />
|
||||
</HBox.margin>
|
||||
</Button>
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</VBox>
|
||||
95
src/com/coder/client/gui/project/SelectProjectDialog.java
Normal file
95
src/com/coder/client/gui/project/SelectProjectDialog.java
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
package com.coder.client.gui.project;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
|
||||
import com.coder.client.gui.GuiWindow;
|
||||
|
||||
public class SelectProjectDialog extends GuiWindow {
|
||||
public static final Logger logger = LogUtil.getLogger();
|
||||
private HashSet<SelectProjectDialogListener> listeners;
|
||||
|
||||
@FXML private ListView projectListView;
|
||||
@FXML private Button newProjectButton;
|
||||
@FXML private Button cancelButton;
|
||||
@FXML private Button openProjectButton;
|
||||
|
||||
public SelectProjectDialog() throws IOException {
|
||||
super(SelectProjectDialog.class.getResource("SelectProjectDialog.fxml"));
|
||||
listeners = new HashSet<SelectProjectDialogListener>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void willShow() {
|
||||
for(SelectProjectDialogListener listener : this.listeners){
|
||||
listener.willShow();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void keyPressed(KeyEvent event) {
|
||||
if(event.getCode() == KeyCode.ENTER){
|
||||
logger.fine("User pressed the ENTER key");
|
||||
openProjectButton.fire();
|
||||
}else if(event.getCode() == KeyCode.ESCAPE){
|
||||
logger.fine("User pressed the ESCAPE key");
|
||||
cancelButton.fire();
|
||||
}else if(event.getCode() == KeyCode.N && event.isControlDown()){ //CTRL+N
|
||||
logger.fine("User pressed CTRL+N");
|
||||
newProjectButton.fire();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void newProject(ActionEvent event){
|
||||
for(SelectProjectDialogListener listener : this.listeners){
|
||||
listener.newProject();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void cancel(ActionEvent event){
|
||||
for(SelectProjectDialogListener listener : this.listeners){
|
||||
listener.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void openProject(ActionEvent event){
|
||||
for(SelectProjectDialogListener listener : this.listeners){
|
||||
//TODO: get selected project in the list view
|
||||
String selectedProjectName = "project name";
|
||||
listener.openProject(selectedProjectName);
|
||||
}
|
||||
}
|
||||
|
||||
public void addSelectProjectDialogListener(SelectProjectDialogListener listener){
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
public void clearProjectList(){
|
||||
//TODO
|
||||
}
|
||||
|
||||
public void addProjectToList(String name, String type){
|
||||
//TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.coder.client.gui.project;
|
||||
|
||||
public interface SelectProjectDialogListener {
|
||||
|
||||
void newProject();
|
||||
|
||||
void cancel();
|
||||
|
||||
void openProject(String selectedProjectName);
|
||||
|
||||
void willShow();
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue