Skip to content

Instantly share code, notes, and snippets.

@james-d
james-d / application.css
Last active May 14, 2023 10:58
Example of using Bindings (extensively) for validation in JavaFX. Maybe a basis for thinking about a validation framework.
.root {
error-color: #ffa0a0 ;
}
.text-field:validation-error {
-fx-background-color: error-color ;
}
.label.error-instructions {
-fx-text-fill: error-color ;
}
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javafx.application.Application;
import javafx.beans.Observable;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
@james-d
james-d / Main.java
Created April 4, 2014 19:41
Example use of JavaBeanPropertyAdapters. Select a row, or rows, and then press "Increment"
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javafx.application.Application;
import javafx.beans.property.adapter.JavaBeanIntegerProperty;
import javafx.beans.property.adapter.JavaBeanIntegerPropertyBuilder;
import javafx.beans.property.adapter.JavaBeanStringPropertyBuilder;
@james-d
james-d / MP3Player.fxml
Last active March 7, 2017 21:42
Simple MP3 player that uses Tomas Mikula's excellent EasyBind library (https://github.com/TomasMikula/EasyBind). (You will need EasyBind v1.0.0 to run this.)
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="mp3player.MP3PlayerController">
@james-d
james-d / TreeTableViewWithStyledRoot.java
Last active March 9, 2021 03:25
TreeTableView example with styled root node view.
import java.io.File;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Comparator;
import java.util.Date;
import javafx.application.Application;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
@james-d
james-d / Investigator.java
Created May 11, 2014 01:15
Example of JPA entities that use JavaFX properties. These use a "super-lazy" idiom for instantiating the properties, and implement Externalizable to work around the lack of Serialization support in the FX property classes.
package edu.marshall.genomics.lims.entities;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
@james-d
james-d / Dao.java
Created May 11, 2014 01:21
Business model and data integration tier for the laboratory information management system. See also https://gist.github.com/james-d/e485ac525c71e20bb453
package edu.marshall.genomics.lims.data;
import java.util.List;
import edu.marshall.genomics.lims.entities.Investigator;
import edu.marshall.genomics.lims.entities.Project;
import edu.marshall.genomics.lims.entities.Sample;
public interface Dao {
public List<Investigator> getAllInvestigators() throws DaoException ;
@james-d
james-d / InvestigatorController.java
Last active March 12, 2018 12:33
Rest controllers for the Laboratory information management system. See also https://gist.github.com/james-d/ab72b487b7b12bb7a3bc
package edu.marshall.genomics.lims.web;
import java.util.List;
import javax.inject.Inject;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@james-d
james-d / DataAccessor.java
Created May 11, 2014 01:31
JavaFX client code for the Laboratory Information Management System demo. The key here is that the controller references a client-side data accessor, which uses a Jersey client to communicate with the web-based REST service.
package edu.marshall.genomics.lims.client;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
@james-d
james-d / Assignment.java
Last active October 11, 2015 22:05
Demo of creating TreeViews with dynamic connections between them. Not guaranteed to be memory-leak-free or efficient....
package connectedtrees;
public class Assignment {
private final Task task ;
private final Employee assignee ;
public Assignment(Task task, Employee assignee) {
this.task = task;
this.assignee = assignee;
}
public Task getTask() {