zoom with CTRL + mouse wheel
[Logo]
ICEsoft.org Forums: ICEfaces, ICEmobile, ICEpdf
[Search] Search   [Recent Topics] Recent Topics   [Groups] Home Page | www.icefaces.org  [Register] Register  [Login] Login 
zoom with CTRL + mouse wheel  XML
Forum Index -> ICEpdf General
Author Message
wkrugiolka

Joined: 10/02/2010 00:00:00
Messages: 2
Offline


Hi

Is it posiible tu turn on zooming when move wheel mouse with CTRL button pressed?

I embedded ICEpdf in Eclipse RCP application and i can add shell listener with MouseWheel event but when i click on the generated PDF view i lost control on zooming and only can scroll PDF document.

Is it possible to add listener for JPanel to zoomin zoomout a document on CTRL + MouseWheel?

I tried to add viewerComponentPanel.addMouseWheelListener() but it doesn't work :-(
Same with viewerComponentPanel.addMouseListener() :-(

Any help would be usefull...


Regards, Wojtas
patrick.corless

Joined: 26/10/2004 00:00:00
Messages: 1097
Offline


It is possible but you will have to do some work to the Viewer RI.

There are currently two wheel mouse listeners:

org.icepdf.ri.common.MouseWheelCurrentPageListener.java
- handles wheel mouse logic for detecting when the current page has changed during a scroll


org.icepdf.ri.common.MouseWheelListenerPageChanger.java
- changes the page for the single page views, not hooked up for the page column views.

You can trace where these listeners are added and removed to see how the following logic could be applied.

I would suggest you create a new MouseWheelListener class that has access to the SwingController. The listener needs to know when the ctrl key is down during a MouseWheelEvent.

Code:
if ((mouseEvent.getModifiers() & InputEvent.CTRL_MASK)
 == InputEvent.CTRL_MASK)


One you have the correct conditions you can get the direction of the wheel movement and the amount of movement.

Code:
 mouseEvent.getScrollAmount();
 mouseEvent.getWheelRotation();


Once you have all the information you can ask the SwingController to zoom in on the current mouse location.

Code:
controller.getDocumentViewController().setZoomXX();


Finally the scrollpane used by the page view will scroll the page view by default. When you pick up on the ctr-wheel event you can get access to the scrollPane and disable the wheel during the zoom.

[Email]
wkrugiolka

Joined: 10/02/2010 00:00:00
Messages: 2
Offline


Thanks for your reply!
It works almost perfectly, but i've got one more problem.
Taht's what i did in my code:

Code:
 controller.getDocumentViewController().getViewContainer()
 		.addMouseWheelListener(new MouseWheelListener() {
 
 			@Override
 			public void mouseWheelMoved(MouseWheelEvent e) {
 				if ((e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
 					if (e.getWheelRotation() > 0) {
 						controller.zoomOut();
 					} else {
 						controller.zoomIn();
 					}
 				}
 			}
 		});
 


but when i have multipage document and try to zoom out the page zoom and scroll down, so i removed scroll listener by adding a code before adding my listener:

Code:
 controller.getDocumentViewController().getViewContainer().removeMouseWheelListener(controller
 .getDocumentViewController().getViewContainer().getMouseWheelListeners()[0]);
 


and it works almost perfect, but when i zoom out a document and its smaller than the view it scrolls next page anyway and when i zoom in it scrolls previous page. Do i have to turn off some other listeners?

And what if i don't want to disable scroll but only turn it off when the ctrl key is down? you wrote:

patrick.corless wrote:

Finally the scrollpane used by the page view will scroll the page view by default. When you pick up on the ctr-wheel event you can get access to the scrollPane and disable the wheel during the zoom.
 


but how to do this and how to set scroll size? for example i want to scroll for 10 points down on mouse wheel dowm - i cant find methods for that :-(

Regards, Wojtas
patrick.corless

Joined: 26/10/2004 00:00:00
Messages: 1097
Offline


I managed to get this working in my work plan. Not a lot of code but I touched more then a few classes. I have to do some paper work before checking this in but I think you'll be happy with it. I'll post the revision number in svn so you can do a diff of the changes. Other wise it won't be available until the next official release.

As for the scrollbar policy you'll have to get an instance of the JScrollpane used by the viewer and call getters for both the horizontal and Vertical Srollbars(). Once you get the JScrollBar reference you can set the block increment and the scroll rate of the viewer.
[Email]
patrick.corless

Joined: 26/10/2004 00:00:00
Messages: 1097
Offline


Codes checked in rev. 20693.

You can sink up with the public repository in the morning and it should be there using the link, http://sventon.icefaces.org/svn/repobrowser.svn?path=%2ficepdf&revision=20693&name=repo
[Email]
 
Forum Index -> ICEpdf General
Go to:   
Powered by JForum 2.1.7ice © JForum Team