All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.epics.gpclient.javafx.tools.Toolbox Maven / Gradle / Ivy

The newest version!
/**
 * 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 toolClass;

        public Tool(String toolName, Class toolClass) {
            this.toolName = toolName;
            this.toolClass = toolClass;
        }

        public String getToolName() {
            return toolName;
        }

        public Class 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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy