Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mouse event handling and exception throwing in UIUtil #187

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public EnhancedPasswordField() {

StackPane rightWrapper = new StackPane(rightIcon);
rightWrapper.getStyleClass().add("right-icon-wrapper");
rightWrapper.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> {
if (UIUtil.clickOnNode(event)) {
rightWrapper.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
if (UIUtil.isClickOnNode(event)) {
setShowPassword(!isShowPassword());
event.consume();
}
Expand Down
17 changes: 11 additions & 6 deletions gemsfx/src/main/java/com/dlsc/gemsfx/util/UIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ public static void copyToClipboard(String copyContent) {
* @return {@code true} if the event is a single stable primary button click, {@code false} otherwise.
* @throws NullPointerException if the event is null.
*/
public static boolean clickOnNode(MouseEvent event) {
return clickOnNode(event, false);
public static boolean isClickOnNode(MouseEvent event) {
return isClickOnNode(event, false);
}

/**
* Determines if the given mouse event is a primary button click
* Determines if the given mouse clicked event is a primary button click
* that hasn't moved since it was pressed.
*
* <p>This method checks if the mouse event satisfies the following conditions:
Expand All @@ -222,12 +222,17 @@ public static boolean clickOnNode(MouseEvent event) {
* <li>If {@code isSingleClick} is {@code true}, the event must be a single click.</li>
* </ul>
*
* @param event The mouse event to check. Must not be null.
* @param event The mouse event to check. Must not be null.
* @param isSingleClick {@code true} if the event must be a single click, {@code false} otherwise.
* @return {@code true} if the event is a stable primary button click, {@code false} otherwise.
* @throws NullPointerException if the event is null.
*
* @throws IllegalArgumentException if the event is not a mouse clicked event.
*/
public static boolean clickOnNode(MouseEvent event, boolean isSingleClick) {
public static boolean isClickOnNode(MouseEvent event, boolean isSingleClick) {
if (event.getEventType() != MouseEvent.MOUSE_CLICKED) {
throw new IllegalArgumentException("The event must be a mouse clicked event.");
// return false;
}
return event.getButton() == MouseButton.PRIMARY && event.isStillSincePress() && (!isSingleClick || event.getClickCount() == 1);
}

Expand Down
Loading