org.epics.gpclient.javafx.tools.Toolbox Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gpclient-javafx Show documentation
Show all versions of gpclient-javafx Show documentation
Java FX support for the EPICS Generic Purpose Client.
/**
* Copyright information and license terms for this software can be
* found in the file LICENSE.TXT included with the distribution.
*/
package org.epics.gpclient.javafx.tools;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
public final class Toolbox extends VBox {
private static class Tool {
private final String toolName;
private final Class extends Parent> toolClass;
public Tool(String toolName, Class extends Parent> toolClass) {
this.toolName = toolName;
this.toolClass = toolClass;
}
public String getToolName() {
return toolName;
}
public Class extends Parent> getToolClass() {
return toolClass;
}
public void open() {
JavaFXLaunchUtil.open("Diirt - " + getToolName(), toolClass);
}
}
private static final List tools = Arrays.asList(
new Tool("Probe", Probe.class));
private static class ToolButton extends Button {
private final Tool tool;
public ToolButton(Tool tool) {
this.tool = tool;
setText("Open " + tool.getToolName() + "...");
addEventHandler(ActionEvent.ACTION, (e) -> this.tool.open());
setMaxWidth(Double.MAX_VALUE);
}
}
public Toolbox() {
System.out.println(getClass().getResource("Toolbox.fxml"));
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("Toolbox.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
for (Tool tool : tools) {
getChildren().add(new ToolButton(tool));
}
}
public static void main(String[] args) {
JavaFXLaunchUtil.launch("Diirt - Toolbox", Toolbox.class, args);
}
}