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

org.epics.gpclient.javafx.tools.EventLogViewer 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 javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ListView;
import javafx.scene.layout.HBox;
public final class EventLogViewer extends HBox {
    
    @FXML
    private ListView eventList;
    @FXML
    private ValueViewer valueViewer;
    @FXML
    private EventViewer eventViewer;
    
    private Log eventLog = new Log(new Runnable() {
        @Override
        public void run() {
            onNewEvent();
        }
        
    });

    public EventLogViewer() {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("EventLogViewer.fxml"));

        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
        
        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
        
        eventList.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {

            @Override
            public void changed(ObservableValue observable, Event oldValue, Event newValue) {
                eventViewer.setEvent(newValue);
                valueViewer.setValue(newValue.getValue(), newValue.isConnected());
            }
        });
    }
    
    public Log eventLog() {
        return eventLog;
    }
    
    private void onNewEvent() {
        eventList.getItems().add(0, eventLog.getEvents().get(eventLog.getEvents().size() - 1));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy