Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Touchscreen style "swipe" behaviour on a Resource View? (Read 4648 times)
DamianC
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Joined: Aug 19th, 2015
Touchscreen style "swipe" behaviour on a Resource View?
Sep 10th, 2015 at 6:18am
Print Post  
Hi,

"For your consideration".

Specifically, we are looking for touchscreen style "swipe" behavior on a Resource View.

Firstly - I expect this is too "out there" to be considered, but I thought I would mention it because of its potential usefulness.

Secondly, you *might* already have some already existing solution for this. Even better.

===================================

Background. We have a Swing product - so it is primarily aimed at desktop use - using keyboard and mouse as the main input devices.

However, for some customers we run in the cloud and use Remote Desktop to access the program. This also means that iPads and other Touchscreen devices can use our product. It is not optimised for touchscreens, but it is very usable and worthwhile for certain use cases.

Swing is not optimised for Touchscreens - and one of the drawbacks is the difficulty in using scroll bars. We have *lots* of JTables in our product, which could be a usability problem for Touchscreens, but we have employed a single 60 lines of code to make it all work perfectly acceptably in many situations.

The problem is being able to "swipe" the screen to move a component (such as an AwtCalendar).

We use a DragScrollHandler (see code below - all 60 lines of it) that listens for mouse presses and drags, and moves the component in the viewport.

For each (say) JTable we add a single line of code as follows to make this work ...
JTable table = new JTable(tableData);
DragScrollHandler.createDragScrollHandlerFor(table);

The JTable then works exactly as expected on an iPad.

I know that the situation is more complex on a AwtCalendar (components within components), but we would find it extremely useful if it could be made to work.

So this is no more than a passing suggestion - but it is *possibly* not too difficult, and lots of cross platform developers might find it quite useful.

Thanks for listening.
-Damian


===================================
package ourpackage.utils;

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;

public class DragScrollHandler extends MouseAdapter {

private JComponent component;
private Point pressedPoint, draggedPoint;
private Rectangle visiRect;

@SuppressWarnings("LeakingThisInConstructor")
public DragScrollHandler(JComponent c) {
component = c;
c.addMouseListener(this);
c.addMouseMotionListener(this);
}

@SuppressWarnings("ResultOfObjectAllocationIgnored")
public static void createDragScrollHandlerFor(JComponent component) {
new DragScrollHandler(component);
}

public void dispose() {
component.removeMouseListener(this);
component.removeMouseMotionListener(this);
}

@Override
public void mousePressed(MouseEvent e) {
pressedPoint = e.getPoint();
draggedPoint = e.getPoint();
visiRect = component.getVisibleRect();
}

@Override
public void mouseDragged(MouseEvent e) {
draggedPoint = e.getPoint();
visiRect.x += (pressedPoint.x - draggedPoint.x);
visiRect.y += (pressedPoint.y - draggedPoint.y);
component.scrollRectToVisible(visiRect);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Rectangle newRect = component.getVisibleRect();
pressedPoint.x += newRect.x - visiRect.x;
pressedPoint.y += newRect.y - visiRect.y;
visiRect = newRect;
}
});
}
}


« Last Edit: Sep 11th, 2015 at 2:14am by DamianC »  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Touchscreen style "swipe" behaviour on a Resource View?
Reply #1 - Sep 11th, 2015 at 6:56am
Print Post  
Hi,

Thank you for the suggestion. This is something we will eventually add to the core control in the future. For now you can use the following version of DragScrollHandler, tailored to the AwtCalendar component:

Code
Select All
public class DragScrollHandler extends MouseAdapter {

    private AwtCalendar calendar;
    private Point pressedPoint;
    private int sx;
    private int sy;

    @SuppressWarnings("LeakingThisInConstructor")
    public DragScrollHandler(AwtCalendar c) {
        calendar = c;
        c.addMouseListener(this);
        c.addMouseMotionListener(this);
    }

    @SuppressWarnings("ResultOfObjectAllocationIgnored")
    public static void createDragScrollHandlerFor(AwtCalendar calendar) {
        new DragScrollHandler(calendar);
    }

    public void dispose() {
        calendar.removeMouseListener(this);
        calendar.removeMouseMotionListener(this);
    }

    @Override
    public void mousePressed(MouseEvent e) {
        pressedPoint = e.getPoint();
        sx = calendar.getScrollPosition().getX();
        sy = calendar.getScrollPosition().getY();
        e.consume();
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        Point draggedPoint = e.getPoint();
    	int dx = sx - (draggedPoint.x - pressedPoint.x) / 20;
    	int dy = sy - (draggedPoint.y - pressedPoint.y) / 20;

    	calendar.setScrollPosition(new com.mindfusion.common.Point(dx, dy));
    	e.consume();
    }
} 


Kind regards,
Meppy
  
Back to top
 
IP Logged
 
DamianC
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Joined: Aug 19th, 2015
Re: Touchscreen style "swipe" behaviour on a Resource View?
Reply #2 - Sep 11th, 2015 at 7:32am
Print Post  
BINGO! This works out of the box.

I can't test it on a touchscreen for a few days, but the mouse version does everything I hoped for, and I have a 99% confidence factor.

As always, the service is beyond the call of duty.

Many thanks,
-Damian
  
Back to top
 
IP Logged
 
DamianC
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Joined: Aug 19th, 2015
Re: Touchscreen style "swipe" behaviour on a Resource View?
Reply #3 - Sep 14th, 2015 at 6:04am
Print Post  
Hi all,

Just posting an updated utility here for others who may be interested.

The original utility had the drawback that Items could not be adjusted (because they relied on the same mouse drag handlers as this swipe utility).

I wanted it to change the item's dates if the item is dragged, and swipe the AwtCalendar if anything else is swiped.

The Javadoc describes how the updated utility is to be used.

This will not be 100% for all use cases - but it is working nicely for our use case.

HTH.
-Damian


========================
/*
* 14SEP15
*/
package our.product.api.utils;

import com.mindfusion.scheduling.awt.AwtCalendar;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.Map;

/**
*
* @author Damian
*/
public class JPlannerDragScrollHandler extends MouseAdapter {

private final AwtCalendar calendar;
private Point pressedPoint;
private int sx;
private int sy;
private final static Map<AwtCalendar,Boolean> isEnabledMap = new HashMap<>();

@SuppressWarnings("LeakingThisInConstructor")
private JPlannerDragScrollHandler(AwtCalendar c) {
calendar = c;
c.addMouseListener(this);
c.addMouseMotionListener(this);
}

@SuppressWarnings("ResultOfObjectAllocationIgnored")
public static void createDragScrollHandlerFor(AwtCalendar calendar) {
new JPlannerDragScrollHandler(calendar);
isEnabledMap.put(calendar, true); // assumes true
}

/**
* This swipe controller can be enabled or disabled as required. This is
* so that an AwtCalendar can have both swipe capability, and item
* adjustment (start & finish time) capability. Both these capabilities
* use mouse dragging, so this allows choice of which is in operation.
*
* The standard idiom is ...
*
* // Register scroll handler ...
* JPlannerDragScrollHandler.createDragScrollHandlerFor(awtCalendar);
*
* // Listen for item selection events and enable/disable as appropriate ...
* awtCalendar.addCalendarListener(new CalendarAdapter() {
* // probably other Overrides too ...
* @Override
* public void itemSelectionChanged(ItemSelectionEvent e) {
* if (e.getIsDeselected()) {
* JPlannerDragScrollHandler.setEnabled(calendar, true);
* } else if (e.getIsSelected()) {
* JPlannerDragScrollHandler.setEnabled(calendar, false);
* }
* }
* });
*
* @param calendar
* @param enabled
*/
public static void setEnabled(AwtCalendar calendar, boolean enabled) {
isEnabledMap.put(calendar, enabled);
}

public void dispose() {
calendar.removeMouseListener(this);
calendar.removeMouseMotionListener(this);
isEnabledMap.remove(calendar);
}

@Override
public void mousePressed(MouseEvent e) {
pressedPoint = e.getPoint();
sx = calendar.getScrollPosition().getX();
sy = calendar.getScrollPosition().getY();
e.consume();
}

@Override
public void mouseDragged(MouseEvent e) {
// is currently enabled ?
if (!isEnabledMap.get(calendar)) return;
Point draggedPoint = e.getPoint();
// Originally 20 JPlanner forum, but that is often too fast
     int dx = sx - (draggedPoint.x - pressedPoint.x) / 30;
     int dy = sy - (draggedPoint.y - pressedPoint.y) / 30;
     calendar.setScrollPosition(new com.mindfusion.common.Point(dx, dy));
     e.consume();
}
}
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint