package be.iminds.ilabt.jfed.experimenter_gui.slice.ribbon_tabs;

import be.iminds.ilabt.jfed.ui.javafx.FXMLUtil;
import com.google.common.eventbus.EventBus;
import javafx.fxml.FXML;

/**
 * User: twalcari
 * Date: 7/1/2014
 * Time: 17:31
 */
public class TopologyViewerRibbonTab extends SliceRibbonTab {

    public TopologyViewerRibbonTab(EventBus eventBus) {
        FXMLUtil.injectFXML(this, aClass -> {
            if (aClass == GenericSliceRibbonComponentGroupController.class) {
                return new GenericSliceRibbonComponentGroupController(TopologyViewerRibbonTab.this, eventBus);
            } else if (aClass == AdvancedSliceRibbonComponentGroupController.class) {
                return new AdvancedSliceRibbonComponentGroupController(TopologyViewerRibbonTab.this, eventBus);
            }
            throw new RuntimeException("Unexpected class in ControllerFactory: " + aClass.getName());
        });

        setOnSelectionChanged(event -> {
            if (isSelected() && !getActiveExperimentViewController().isCanvasVisible()) {
                getActiveExperimentViewController().switchToModelView();
            }
        });
    }


    @FXML
    private void onAutoLayoutAction() {
        getActiveExperimentViewController().getModelSliceView().getCanvas().autoLayout();
    }

        /*
        Zoom section
     */

    @FXML
    public void onZoomInAction() {
        getActiveExperimentViewController().getModelSliceView().getCanvas().zoomIn();
    }

    @FXML
    public void onZoomOutAction() {
        getActiveExperimentViewController().getModelSliceView().getCanvas().zoomOut();
    }

    @FXML
    public void onResetZoomAction() {
        getActiveExperimentViewController().getModelSliceView().getCanvas().setZoom(1);
    }

}
