Skip to content
Snippets Groups Projects
Commit 368e7874 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

Font awesome support

parent 42dec364
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,15 @@ ...@@ -11,6 +11,15 @@
<artifactId>fxui</artifactId> <artifactId>fxui</artifactId>
<!--
<repositories>
<repository>
<id>bintray</id>
<url>https://dl.bintray.com/jerady/maven</url>
</repository>
</repositories>
-->
<dependencies> <dependencies>
<dependency> <dependency>
...@@ -37,6 +46,21 @@ ...@@ -37,6 +46,21 @@
<version>14.0.2</version> <version>14.0.2</version>
</dependency> </dependency>
<!--
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-fontawesome</artifactId>
<version>4.7.0-11</version>
</dependency>
-->
<!-- https://mvnrepository.com/artifact/de.jensd/fontawesomefx-controls -->
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx-fontawesome</artifactId>
<version>4.7.0-9.1.2</version>
</dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
...@@ -66,6 +90,24 @@ ...@@ -66,6 +90,24 @@
</dependency> </dependency>
</dependencies> </dependencies>
<profiles>
<profile>
<id>fontawesome</id>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>de.jensd.fx.glyphs.fontawesome.demo.FontAwesomeIconsDemoApp</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
...@@ -79,7 +121,7 @@ ...@@ -79,7 +121,7 @@
<groupId>org.openjfx</groupId> <groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId> <artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version> <version>0.0.4</version>
<configuration> <configuration>
<options> <options>
<!-- <!--
<option>dash dash enable-preview</option> <option>dash dash enable-preview</option>
......
...@@ -15,8 +15,11 @@ import java.nio.file.Paths; ...@@ -15,8 +15,11 @@ import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Predicate;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import todolist.core.TodoItem; import todolist.core.TodoItem;
...@@ -136,6 +139,34 @@ public class TodoController { ...@@ -136,6 +139,34 @@ public class TodoController {
for (Button button : selectionButtons) { for (Button button : selectionButtons) {
button.setDisable(disable); button.setDisable(disable);
} }
double rowLayoutY = getRowLayoutY(todoListView, listCell -> isSelected(todoListView, listCell), 0);
System.out.println(rowLayoutY);
}
private boolean isSelected(ListView<?> listView, ListCell<?> listCell) {
return isSelected(listView, listCell.getItem());
}
private boolean isSelected(ListView<?> listView, Object item) {
return todoListView.getSelectionModel().getSelectedItems().contains(item);
}
@SuppressWarnings("unchecked")
private <T> double getRowLayoutY(ListView<T> listView, Predicate<ListCell<T>> test, int num) {
for (Node child : listView.lookupAll(".list-cell")) {
if (child instanceof ListCell) {
ListCell<T> listCell = (ListCell<T>) child;
if (test.test(listCell) && num-- == 0) {
double dy = 0;
Node node = listCell;
while (node != todoListView) {
dy += node.getLayoutY();
node = node.getParent();
}
return dy;
}
}
}
return -1;
} }
@FXML @FXML
......
...@@ -4,21 +4,38 @@ ...@@ -4,21 +4,38 @@
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.control.TextField?> <?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ListView?> <?import javafx.scene.control.ListView?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<VBox xmlns:fx="http://javafx.com/fxml/1" fx:controller="todolist.ui.TodoController"> <VBox xmlns:fx="http://javafx.com/fxml/1" fx:controller="todolist.ui.TodoController">
<fx:define> <fx:define>
<String fx:id="userTodoListPath" fx:value="todolist.json"/> <String fx:id="userTodoListPath" fx:value="todolist.json"/>
<String fx:id="sampleTodoListResource" fx:value="sample-todolist.json"/> <String fx:id="sampleTodoListResource" fx:value="sample-todolist.json"/>
</fx:define> </fx:define>
<HBox> <HBox>
<Button fx:id="newTodoItemButton" text="New Item" onAction="#handleNewTodoItemAction"/> <Button fx:id="newTodoItemButton" onAction="#handleNewTodoItemAction">
<graphic>
<FontAwesomeIconView glyphName="PLUS" size="18px" glyphStyle="-fx-fill: green" />
</graphic>
<tooltip>
<Tooltip text="New Item"/>
</tooltip>
</Button>
<TextField fx:id="newTodoItemText" promptText="Skriv inn tekst her" onAction="#handleNewTodoItemAction"/> <TextField fx:id="newTodoItemText" promptText="Skriv inn tekst her" onAction="#handleNewTodoItemAction"/>
</HBox> </HBox>
<ListView fx:id="todoListView"> <ListView fx:id="todoListView">
</ListView> </ListView>
<HBox> <HBox>
<Button fx:id="deleteTodoItemButton" text="Delete Item" onAction="#handleDeleteItemAction"/> <Button fx:id="deleteTodoItemButton" onAction="#handleDeleteItemAction">
<graphic>
<FontAwesomeIconView glyphName="TIMES_CIRCLE_ALT" size="18px" glyphStyle="-fx-fill: red" />
</graphic>
<tooltip>
<Tooltip text="Delete Item"/>
</tooltip>
</Button>
</HBox> </HBox>
</VBox> </VBox>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment