This library provides native-like UI/UX for applications used by over 15 million developers worldwide. We’ve made possible the one feature users have been waiting for since 2010: native 2-finger navigation gestures on macOS (Google: JBR-4083).
Video Demo: https://bit.ly/swing-fluid-swipe-demo.
Enhance your Java AWT/Swing applications with fluid-swipe gesture support, bridging the gap between native applications and AWT/Swing interfaces. This project aims to provide a consistent and enjoyable user experience through animated feedback, mimicking the fluid-swipe gestures prevalent in macOS applications.
The Java Development Kit (JDK) lacks support for fluid-swipe gestures, which are an essential part of user interaction in many macOS applications such as Safari and Xcode. This project addresses that limitation by enabling these gestures in AWT/Swing applications.
To integrate swing-fluid-swipe, add the dependency to your build tool:
Maven:
<dependency>
<groupId>eu.giulianogorgone</groupId>
<artifactId>fluidswipe-core</artifactId>
<version>1.2.0</version>
</dependency>
Gradle:
implementation("eu.giulianogorgone:fluidswipe-core:1.2.0")
Start event monitoring with:
FluidSwipe.startEventMonitoring();
To stop monitoring:
FluidSwipe.stopEventMonitoring();
Implement gesture listeners in components to handle fluid-swipe events seamlessly:
import javax.swing.*;
public class NavigableComponent extends JComponent implements FluidSwipeVetoer {
protected void configGestures() {
FluidSwipe.addListenerTo(this, new FluidSwipeAdapter() {
@Override
public void fluidSwipeEnded(final FluidSwipeEvent e) {
if (e.getGestureState() == FluidSwipeEvent.State.SUCCESS) {
if (contentDirection == FluidSwipeEvent.Direction.LEFT_TO_RIGHT)
this.navigateBack();
else this.navigateForward();
}
}
});
}
@Override
public boolean permitFluidSwipeGesture(final FluidSwipeEvent e) {
return (e.getLogicalGestureDirection() == FluidSwipeEvent.Direction.LEFT_TO_RIGHT)
? this.canNavigateBack() : this.canNavigateForward();
}
}
A runnable sample is available here.
Ensure the following settings are configured for trackpads and mice to support fluid-swipe gestures:
FluidSwipeVetoer interface, enabling the capability to veto incoming fluid-swipe events.Implement a coexistence mechanism for scroll and fluid-swipe gestures to ensure both functionalities work harmoniously:
public class FluidSwipeAwareJScrollPane extends JScrollPane implements FluidSwipeVetoer {
@Override
public boolean permitFluidSwipeGesture(FluidSwipeEvent e) {
final FluidSwipeEvent.Direction contentDirection = e.getLogicalGestureDirection();
if (horizontalScrollBar == null || getHorizontalScrollBarPolicy() == HORIZONTAL_SCROLLBAR_NEVER) return true;
return (contentDirection == FluidSwipeEvent.Direction.RIGHT_TO_LEFT && (horizontalScrollBar.getValue() + horizontalScrollBar.getModel().getExtent()) == horizontalScrollBar.getMaximum())
|| (contentDirection == FluidSwipeEvent.Direction.LEFT_TO_RIGHT && horizontalScrollBar.getValue() == horizontalScrollBar.getMinimum());
}
}
Starting with version 1.2.0, this logic is applied by default to JScrollPane components.
For contributed improvements or issues, please provide detailed information about reproducibility and your environment:
Maintain professionalism by following appropriate conduct in all communications. Any inappropriate content will be reported.
Planned features include ensuring functionality for Magic Mouse and expanding support for additional platforms.
No comments yet.
Sign in to be the first to comment.