Implemented SSDP client and is now using graphical list cells in ListViews

This commit is contained in:
Daniel Collin 2015-10-22 14:08:31 +00:00
parent 120dded24f
commit 34cf5865fe
16 changed files with 428 additions and 86 deletions

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="40.0" prefWidth="186.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="nameLabel" layoutX="52.0" layoutY="17.0" prefHeight="24.0" prefWidth="316.0" text="Project Name" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="0.0">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<Label fx:id="typeLabel" layoutX="30.0" layoutY="23.0" prefHeight="17.0" text="Project Type" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="30.0">
<padding>
<Insets right="15.0" />
</padding>
<font>
<Font name="System Bold Italic" size="12.0" />
</font>
</Label>
<Label fx:id="descriptionLabel" layoutX="114.0" layoutY="23.0" prefHeight="17.0" text="Description" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="117.0" AnchorPane.rightAnchor="5.0">
<font>
<Font name="System Italic" size="12.0" />
</font>
</Label>
</children>
</AnchorPane>

View file

@ -0,0 +1,42 @@
package com.coder.client.gui.selectProject;
import java.io.IOException;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
class ProjectListCell extends ListCell<ProjectListItem> {
@FXML private Label nameLabel;
@FXML private Label typeLabel;
@FXML private Label descriptionLabel;
private Node node;
public ProjectListCell() throws IOException{
FXMLLoader loader = new FXMLLoader(ProjectListCell.class.getResource("ProjectListCell.fxml"));
loader.setController(this);
this.node = (Node)loader.load();
}
@Override
protected void updateItem(ProjectListItem item, boolean empty){
super.updateItem(item, empty);
if(empty){
setText("");
setGraphic(null);
}else if(item != null){
setText("");
nameLabel.setText(item.getName());
typeLabel.setText(item.getType());
descriptionLabel.setText(item.getDescription());
setGraphic(node);
}else{
setText("NULL");
setGraphic(null);
}
}
}

View file

@ -1,18 +1,30 @@
package com.coder.client.gui.selectProject;
public class ProjectListItem {
private String projectName;
class ProjectListItem {
private String name;
private String type;
private String description;
public ProjectListItem(String projectName, String type, String description) {
this.projectName = projectName;
this.name = projectName;
this.type = type;
this.description = description;
}
public String getName(){
return this.name;
}
public String getType(){
return this.type;
}
public String getDescription(){
return this.description;
}
public String toString(){
return "ProjectName="+projectName+", type="+type+", description="+description;
return "PROJECT: ProjectName="+name+", type="+type+", description="+description;
}
}

View file

@ -6,12 +6,11 @@
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ScrollPane fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" prefHeight="164.0" prefWidth="396.0" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<ListView fx:id="projectListView" prefHeight="200.0" prefWidth="200.0" />
<ListView fx:id="projectListView" onKeyPressed="#keyPressed" onMouseClicked="#mouseClickedOnList" prefHeight="200.0" prefWidth="200.0" />
</content>
</ScrollPane>
<GridPane maxHeight="-Infinity" minHeight="-Infinity" prefHeight="50.0" prefWidth="396.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
@ -30,7 +29,7 @@
<Insets right="10.0" />
</HBox.margin>
</Button>
<Button fx:id="openProjectButton" mnemonicParsing="false" onAction="#openProject" text="Open Project">
<Button fx:id="openButton" defaultButton="true" disable="true" mnemonicParsing="false" onAction="#open" text="Open">
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>

View file

@ -4,10 +4,13 @@ import java.io.IOException;
import java.net.URL;
import java.util.HashSet;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import zutil.log.LogUtil;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
@ -17,6 +20,8 @@ import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.util.Callback;
import com.coder.client.gui.GuiWindow;
@ -30,7 +35,9 @@ public class SelectProjectDialog extends GuiWindow {
@FXML private ListView<ProjectListItem> projectListView;
@FXML private Button newProjectButton;
@FXML private Button cancelButton;
@FXML private Button openProjectButton;
@FXML private Button openButton;
private String projectName = null;
public SelectProjectDialog() throws IOException {
super(SelectProjectDialog.class.getResource("SelectProjectDialog.fxml"));
@ -42,6 +49,11 @@ public class SelectProjectDialog extends GuiWindow {
for(SelectProjectDialogListener listener : this.listeners){
listener.willShow();
}
if(this.projectName != null){
openButton.setDisable(false);
openButton.fire();
}
openButton.setDisable(true);
}
@Override
@ -51,32 +63,41 @@ public class SelectProjectDialog extends GuiWindow {
projectListView.setCellFactory(new Callback<ListView<ProjectListItem>, ListCell<ProjectListItem>>(){
@Override
public ListCell<ProjectListItem> call(ListView<ProjectListItem> arg0) {
System.out.println("cell factory");
ListCell<ProjectListItem> cell = new ListCell<ProjectListItem>(){
@Override
protected void updateItem(ProjectListItem item, boolean empty){
System.out.println("update item: " + item);
super.updateItem(item, empty);
if(empty){
setText("");
setGraphic(null);
}
if(item != null){
setText(item.toString());
//setGraphic(null);
}
}
};
return cell;
try {
return new ProjectListCell();
} catch (IOException e) {
logger.log(Level.SEVERE, "could not crate a ProjectListCell instance", e);
}
return null;
}
});
projectListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ProjectListItem>() {
@Override
public void changed(ObservableValue<? extends ProjectListItem> observable, ProjectListItem oldValue, ProjectListItem vewValue) {
if(observable.getValue() != null){
logger.fine("ProjectListItem [" + observable.getValue() + "] selected in the project list");
openButton.setDisable(false);
}else{
openButton.setDisable(true);
}
}
});
}
@FXML
protected void mouseClickedOnList(MouseEvent event){
if(event.getButton().equals(MouseButton.PRIMARY)){
if(event.getClickCount() == 2){ //if doublecklick
openButton.fire();
}
}
}
@FXML
protected void keyPressed(KeyEvent event) {
if(event.getCode() == KeyCode.ENTER){
logger.fine("User pressed the ENTER key");
openProjectButton.fire();
openButton.fire();
}else if(event.getCode() == KeyCode.ESCAPE){
logger.fine("User pressed the ESCAPE key");
cancelButton.fire();
@ -108,11 +129,15 @@ public class SelectProjectDialog extends GuiWindow {
}
@FXML
protected void openProject(ActionEvent event){
protected void open(ActionEvent event){
if(this.projectName == null){
ProjectListItem selectedItem = projectListView.getSelectionModel().getSelectedItem();
projectName = selectedItem.getName();
}
for(SelectProjectDialogListener listener : this.listeners){
//TODO: get selected project in the list view
String selectedProjectName = "project name";
listener.openProject(selectedProjectName);
if(projectName != null){
listener.open(projectName);
}
}
}
@ -133,7 +158,11 @@ public class SelectProjectDialog extends GuiWindow {
@Override
protected String getTitle() {
return "Select Project";
return "Open Project";
}
public void setProject(String project) {
this.projectName = project;
}
}

View file

@ -6,7 +6,7 @@ public interface SelectProjectDialogListener {
void cancel();
void openProject(String selectedProjectName);
void open(String selectedProjectName);
void willShow();