io.github.palexdev.mfxcomponents.behaviors.MFXButtonBehaviorBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of materialfx-all Show documentation
Show all versions of materialfx-all Show documentation
Material Design/Modern components for JavaFX, now packed as a single Jar
package io.github.palexdev.mfxcomponents.behaviors;
import io.github.palexdev.mfxcomponents.controls.base.MFXButtonBase;
import io.github.palexdev.mfxcore.behavior.BehaviorBase;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import java.util.function.Consumer;
/**
* Generic base behavior for all buttons extending from {@link MFXButtonBase}.
*/
public class MFXButtonBehaviorBase> extends BehaviorBase {
//================================================================================
// Constructors
//================================================================================
public MFXButtonBehaviorBase(B button) {
super(button);
}
//================================================================================
// Overridden Methods
//================================================================================
/**
* Responsible for acquiring the focus.
*/
@Override
public void mousePressed(MouseEvent e, Consumer callback) {
getNode().requestFocus();
super.mousePressed(e, callback);
}
/**
* Responsible for calling {@link MFXButtonBase#fire()} if the clicked mouse button was {@link MouseButton#PRIMARY}.
*/
@Override
public void mouseClicked(MouseEvent e, Consumer callback) {
if (e.getButton() == MouseButton.PRIMARY) getNode().fire();
super.mouseClicked(e, callback);
}
/**
* Responsible for calling {@link MFXButtonBase#fire()} if the pressed key was {@link KeyCode#ENTER}.
*/
@Override
public void keyPressed(KeyEvent e, Consumer callback) {
if (e.getCode() == KeyCode.ENTER) getNode().fire();
super.keyPressed(e, callback);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy