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

io.github.interacto.jfx.binding.MenuItemBinder Maven / Gradle / Ivy

The newest version!
/*
 * Interacto
 * Copyright (C) 2020 Arnaud Blouin
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see .
 */
package io.github.interacto.jfx.binding;

import io.github.interacto.command.Command;
import io.github.interacto.jfx.binding.api.LogLevel;
import io.github.interacto.jfx.instrument.JfxInstrument;
import io.github.interacto.jfx.interaction.help.HelpAnimation;
import io.github.interacto.jfx.interaction.library.MenuItemPressed;
import io.github.interacto.jfx.interaction.library.WidgetData;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import javafx.scene.control.Button;
import javafx.scene.control.MenuItem;

/**
 * The binding builder to create bindings between a menu item interaction and a given command.
 * @param  The type of the command to produce.
 * @author Arnaud Blouin
 */
class MenuItemBinder extends Binder> {
	MenuItemBinder(final JfxInstrument instrument, final BindingsObserver observer) {
		super(instrument, observer);
		interactionSupplier = MenuItemPressed::new;
	}

	MenuItemBinder(final BiConsumer, C> initCmd, final Predicate> checkConditions,
		final Function, C> cmdProducer, final List widgets, final Supplier interactionSupplier,
		final JfxInstrument instrument, final boolean async, final BiConsumer, C> onEnd,
		final List> additionalWidgets, final EnumSet logLevels, final HelpAnimation helpAnimation,
		final boolean withHelp, final DoubleProperty progressProp, final StringProperty msgProp, final Button cancel,
		final BiConsumer, C> hadNoEffectFct, final BiConsumer, C> hadEffectsFct,
		final BiConsumer, C> cannotExecFct, final BindingsObserver observer, final boolean consumeEvents) {
		super(initCmd, checkConditions, cmdProducer, widgets, interactionSupplier, instrument, async, onEnd, additionalWidgets, logLevels, helpAnimation,
			withHelp, progressProp, msgProp, cancel, hadNoEffectFct, hadEffectsFct, cannotExecFct, observer, consumeEvents);
	}

	@Override
	protected MenuItemBinder duplicate() {
		return new MenuItemBinder<>(initCmd, checkConditions, cmdProducer, widgets, interactionSupplier, instrument, async,
			onEnd, additionalWidgets, logLevels, helpAnimation, withHelp, progressProp, msgProp, cancel, hadNoEffectFct, hadEffectsFct,
			cannotExecFct, observer, consumeEvents);
	}

	@Override
	public JfxWidgetBinding> bind() {
		final JfxAnonMenuItemBinding binding = new JfxAnonMenuItemBinding<>(false, interactionSupplier.get(),
			initCmd, null, checkConditions, onEnd, cmdProducer, null, null, widgets, additionalWidgets,
			false, false, 0L, Collections.emptySet(), false, null, hadNoEffectFct, hadEffectsFct,
			cannotExecFct, consumeEvents);
		binding.setProgressBarProp(progressProp);
		binding.setProgressMsgProp(msgProp);
		binding.setCancelCmdButton(cancel);
		if(instrument != null) {
			instrument.addBinding(binding);
		}
		if(observer != null) {
			observer.observeBinding(binding);
		}
		return binding;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy