Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Snippet234, synchronized table scroll problem on OSx
Snippet234, synchronized table scroll problem on OSx [message #483080] Sun, 30 August 2009 23:36 Go to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
Hi,

This snippet


http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet234.java?view=co

The problem is that we can pixel scroll the table but that will not be
detected because the scroll appears to be by item as vbar.getSelection()
indicates. If you drag the thumb pixel by pixel, the second table will only
jump every $itemHeight$ pixels.

Also the left table snippet does not react on mouse scroll in osx snippet167
uses an alternative listener which does react on mouse scroll.

Is there a way to get this going neatly on OSx? Blocking the pixel scrolling
capabilities could be one solution. Is that possible?

Regards,

Wim Jongman
Re: Snippet234, synchronized table scroll problem on OSx [message #483206 is a reply to message #483080] Mon, 31 August 2009 14:56 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
Hi,

This can probably be made to work by putting each of the Tables into a
ScrolledComposite, and scrolling the ScrolledComposites with setOrigin()
since this is pixel-based. For an example that does something like this see
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet296.java?view=co .
Note that I just added a listener to this snippet that makes using the
scroll wheel work, but snippet changes sometimes take a while to replicate
on the eclipse.org servers, so if the scroll wheel does not work for you
then add the following to the snippet:

/*
* The following listener scrolls the Tree one item at a time
* in response to MouseWheel events.
*/
tree.addListener(SWT.MouseWheel, new Listener() {
public void handleEvent(Event event) {
Point origin = sc.getOrigin();
if (event.count < 0) {
origin.y = Math.min(origin.y + tree.getItemHeight(),
tree.getSize().y);
} else {
origin.y = Math.max(origin.y - tree.getItemHeight(), 0);
}
sc.setOrigin(origin);
}
});

HTH,
Grant


"Wim Jongman" <wim.jongman@gmail.com> wrote in message
news:h7f2em$2r8$1@build.eclipse.org...
> Hi,
>
> This snippet
>
>
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet234.java?view=co
>
> The problem is that we can pixel scroll the table but that will not be
> detected because the scroll appears to be by item as vbar.getSelection()
> indicates. If you drag the thumb pixel by pixel, the second table will
only
> jump every $itemHeight$ pixels.
>
> Also the left table snippet does not react on mouse scroll in osx
snippet167
> uses an alternative listener which does react on mouse scroll.
>
> Is there a way to get this going neatly on OSx? Blocking the pixel
scrolling
> capabilities could be one solution. Is that possible?
>
> Regards,
>
> Wim Jongman
Re: Snippet234, synchronized table scroll problem on OSx [message #483269 is a reply to message #483206] Mon, 31 August 2009 19:50 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
Hi Grant,

Great idea. Thanks for the pointer. I have two side by side synched trees
which work perfectly on Windows but look terrible on the Mac. I think I can
transform the two trees as you suggested. I will post back the result.

--

Best regards,

Wim Jongman
Posted with Salvo, the Eclipse based newsreader


> Hi,
>
> This can probably be made to work by putting each of the Tables into a
> ScrolledComposite, and scrolling the ScrolledComposites with setOrigin()
> since this is pixel-based. For an example that does something like this see
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet296.java?view=co

> Note that I just added a listener to this snippet that makes using the
> scroll wheel work, but snippet changes sometimes take a while to replicate
> on the eclipse.org servers, so if the scroll wheel does not work for you
> then add the following to the snippet:
>
> /*
> * The following listener scrolls the Tree one item at a time
> * in response to MouseWheel events.
> */
> tree.addListener(SWT.MouseWheel, new Listener() {
> public void handleEvent(Event event) {
> Point origin = sc.getOrigin();
> if (event.count < 0) {
> origin.y = Math.min(origin.y + tree.getItemHeight(),
> tree.getSize().y);
> } else {
> origin.y = Math.max(origin.y - tree.getItemHeight(), 0);
> }
> sc.setOrigin(origin);
> }
> });
>
> HTH,
> Grant
>
>
> "Wim Jongman" <wim.jongman@gmail.com> wrote in message
> news:h7f2em$2r8$1@build.eclipse.org...
>> Hi,
>>
>> This snippet
>>
>>
>>
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet234.java?view=co
>>
>> The problem is that we can pixel scroll the table but that will not be
>> detected because the scroll appears to be by item as vbar.getSelection()
>> indicates. If you drag the thumb pixel by pixel, the second table will
> only
>> jump every $itemHeight$ pixels.
>>
>> Also the left table snippet does not react on mouse scroll in osx
> snippet167
>> uses an alternative listener which does react on mouse scroll.
>>
>> Is there a way to get this going neatly on OSx? Blocking the pixel
> scrolling
>> capabilities could be one solution. Is that possible?
>>
>> Regards,
>>
>> Wim Jongman
Re: Snippet234, synchronized table scroll problem on OSx [message #484335 is a reply to message #483206] Sun, 06 September 2009 21:49 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
Hi Grant,

I have a huge problem getting this to work in combination with the
SWT.VIRTUAL style and a jface lazytree contentprovider. I tried SWT.VIRTUAL
in combination with an SWT.SetData event listener which works great. However,
when I wrap a TreeViewer around the tree, I get a lot of errors.

Any ideas on this or should I try the JFACE newsgroup.

Here is your snippet with the SWT.VIRTUAL and with a gridlayout for sizing.
Please note that the SWT.NO_SCROLL eliminates the need for the expand
listeners.

Thanks,

Wim


/*********************************************************** ********************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation

************************************************************ *******************/
package org.eclipse.swt.snippets;

/*
* ScrolledComposite snippet: use a ScrolledComposite to scroll a virtual Tree
vertically
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

public class Snippet296Virtual {

public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10, 10, 300, 300);
shell.setLayout(new GridLayout(1, true));
final ScrolledComposite sc = new ScrolledComposite(shell, SWT.VERTICAL);
sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// sc.setBounds (10, 10, 280, 200);

final Tree tree = new Tree(sc, SWT.VIRTUAL | SWT.NO_SCROLL);
tree.addListener(SWT.SetData, new Listener() {

public void handleEvent(Event event) {
TreeItem item = (TreeItem) event.item;
System.out.println(tree.indexOf(item));
TreeItem parentItem = item.getParentItem();
String text = null;
if (parentItem == null) {
text = "node " + tree.indexOf(item);
} else {
text = parentItem.getText() + " - "
+ parentItem.indexOf(item);
}
item.setText(text);
System.out.println(text);
item.setItemCount(10);
}
});

tree.setItemCount(100);
sc.setContent(tree);
sc.setExpandHorizontal(true);
//sc.setExpandVertical(true);
final int clientWidth = shell.getClientArea().width;
System.out.println("clientwidth " + clientWidth);
int prefHeight = tree.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
System.out.println("prefHeight " + prefHeight);
tree.setSize(clientWidth, prefHeight);

/*
* The following listener ensures that a newly-selected item in the Tree
* is always visible.
*/
tree.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
TreeItem[] selectedItems = tree.getSelection();
if (selectedItems.length > 0) {
Rectangle itemRect = selectedItems[0].getBounds();
Rectangle area = sc.getClientArea();
Point origin = sc.getOrigin();
if (itemRect.x < origin.x
|| itemRect.y < origin.y
|| itemRect.x + itemRect.width > origin.x
+ area.width
|| itemRect.y + itemRect.height > origin.y
+ area.height) {
sc.setOrigin(itemRect.x, itemRect.y);
}
}
}
});
/*
* The following listener scrolls the Tree one item at a time in
* response to MouseWheel events.
*/
tree.addListener(SWT.MouseWheel, new Listener() {
public void handleEvent(Event event) {
Point origin = sc.getOrigin();
if (event.count < 0) {
origin.y = Math.min(origin.y + tree.getItemHeight(), tree
.getSize().y);
} else {
origin.y = Math.max(origin.y - tree.getItemHeight(), 0);
}
sc.setOrigin(origin);
}
});

Button downButton = new Button(shell, SWT.PUSH);
downButton.setBounds(10, 220, 120, 30);
downButton.setText("Down 10px");
downButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
sc.setOrigin(0, sc.getOrigin().y + 10);
}
});
Button upButton = new Button(shell, SWT.PUSH);
upButton.setBounds(140, 220, 120, 30);
upButton.setText("Up 10px");
upButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
sc.setOrigin(0, sc.getOrigin().y - 10);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}


> Hi,
>
> This can probably be made to work by putting each of the Tables into a
> ScrolledComposite, and scrolling the ScrolledComposites with setOrigin()
> since this is pixel-based. For an example that does something like this see
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet296.java?view=co

> Note that I just added a listener to this snippet that makes using the
> scroll wheel work, but snippet changes sometimes take a while to replicate
> on the eclipse.org servers, so if the scroll wheel does not work for you
> then add the following to the snippet:
>
> /*
> * The following listener scrolls the Tree one item at a time
> * in response to MouseWheel events.
> */
> tree.addListener(SWT.MouseWheel, new Listener() {
> public void handleEvent(Event event) {
> Point origin = sc.getOrigin();
> if (event.count < 0) {
> origin.y = Math.min(origin.y + tree.getItemHeight(),
> tree.getSize().y);
> } else {
> origin.y = Math.max(origin.y - tree.getItemHeight(), 0);
> }
> sc.setOrigin(origin);
> }
> });
>
> HTH,
> Grant
>
>
> "Wim Jongman" <wim.jongman@gmail.com> wrote in message
> news:h7f2em$2r8$1@build.eclipse.org...
>> Hi,
>>
>> This snippet
>>
>>
>>
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet234.java?view=co
>>
>> The problem is that we can pixel scroll the table but that will not be
>> detected because the scroll appears to be by item as vbar.getSelection()
>> indicates. If you drag the thumb pixel by pixel, the second table will
> only
>> jump every $itemHeight$ pixels.
>>
>> Also the left table snippet does not react on mouse scroll in osx
> snippet167
>> uses an alternative listener which does react on mouse scroll.
>>
>> Is there a way to get this going neatly on OSx? Blocking the pixel
> scrolling
>> capabilities could be one solution. Is that possible?
>>
>> Regards,
>>
>> Wim Jongman
Re: Snippet234, synchronized table scroll problem on OSx [message #484852 is a reply to message #484335] Wed, 09 September 2009 13:55 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
Hi,

It looks like the snippet you posted is the swt-only one that doesn't show
errors, so I'm not sure what the problem is that you're seeing. That being
said, if the introduction of a TreeViewer is what makes errors start
happening then the eclipse.platform.jface newsgroup could be a better place
to post the jface snippet.

Grant


"Wim Jongman" <wim.jongman@gmail.com> wrote in message
news:h81apk$41b$1@build.eclipse.org...
> Hi Grant,
>
> I have a huge problem getting this to work in combination with the
> SWT.VIRTUAL style and a jface lazytree contentprovider. I tried
SWT.VIRTUAL
> in combination with an SWT.SetData event listener which works great.
However,
> when I wrap a TreeViewer around the tree, I get a lot of errors.
>
> Any ideas on this or should I try the JFACE newsgroup.
>
> Here is your snippet with the SWT.VIRTUAL and with a gridlayout for
sizing.
> Please note that the SWT.NO_SCROLL eliminates the need for the expand
> listeners.
>
> Thanks,
>
> Wim
>
>
>
/*********************************************************** ****************
****
> * Copyright (c) 2000, 2008 IBM Corporation and others.
> * All rights reserved. This program and the accompanying materials
> * are made available under the terms of the Eclipse Public License v1.0
> * which accompanies this distribution, and is available at
> * http://www.eclipse.org/legal/epl-v10.html
> *
> * Contributors:
> * IBM Corporation - initial API and implementation
>
>
************************************************************ ****************
***/
> package org.eclipse.swt.snippets;
>
> /*
> * ScrolledComposite snippet: use a ScrolledComposite to scroll a virtual
Tree
> vertically
> *
> * For a list of all SWT example snippets see
> * http://www.eclipse.org/swt/snippets/
> */
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.ScrolledComposite;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.graphics.Point;
> import org.eclipse.swt.graphics.Rectangle;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Event;
> import org.eclipse.swt.widgets.Listener;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Tree;
> import org.eclipse.swt.widgets.TreeItem;
>
> public class Snippet296Virtual {
>
> public static void main(String[] args) {
> final Display display = new Display();
> Shell shell = new Shell(display);
> shell.setBounds(10, 10, 300, 300);
> shell.setLayout(new GridLayout(1, true));
> final ScrolledComposite sc = new ScrolledComposite(shell, SWT.VERTICAL);
> sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
> // sc.setBounds (10, 10, 280, 200);
>
> final Tree tree = new Tree(sc, SWT.VIRTUAL | SWT.NO_SCROLL);
> tree.addListener(SWT.SetData, new Listener() {
>
> public void handleEvent(Event event) {
> TreeItem item = (TreeItem) event.item;
> System.out.println(tree.indexOf(item));
> TreeItem parentItem = item.getParentItem();
> String text = null;
> if (parentItem == null) {
> text = "node " + tree.indexOf(item);
> } else {
> text = parentItem.getText() + " - "
> + parentItem.indexOf(item);
> }
> item.setText(text);
> System.out.println(text);
> item.setItemCount(10);
> }
> });
>
> tree.setItemCount(100);
> sc.setContent(tree);
> sc.setExpandHorizontal(true);
> //sc.setExpandVertical(true);
> final int clientWidth = shell.getClientArea().width;
> System.out.println("clientwidth " + clientWidth);
> int prefHeight = tree.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
> System.out.println("prefHeight " + prefHeight);
> tree.setSize(clientWidth, prefHeight);
>
> /*
> * The following listener ensures that a newly-selected item in the Tree
> * is always visible.
> */
> tree.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> TreeItem[] selectedItems = tree.getSelection();
> if (selectedItems.length > 0) {
> Rectangle itemRect = selectedItems[0].getBounds();
> Rectangle area = sc.getClientArea();
> Point origin = sc.getOrigin();
> if (itemRect.x < origin.x
> || itemRect.y < origin.y
> || itemRect.x + itemRect.width > origin.x
> + area.width
> || itemRect.y + itemRect.height > origin.y
> + area.height) {
> sc.setOrigin(itemRect.x, itemRect.y);
> }
> }
> }
> });
> /*
> * The following listener scrolls the Tree one item at a time in
> * response to MouseWheel events.
> */
> tree.addListener(SWT.MouseWheel, new Listener() {
> public void handleEvent(Event event) {
> Point origin = sc.getOrigin();
> if (event.count < 0) {
> origin.y = Math.min(origin.y + tree.getItemHeight(), tree
> .getSize().y);
> } else {
> origin.y = Math.max(origin.y - tree.getItemHeight(), 0);
> }
> sc.setOrigin(origin);
> }
> });
>
> Button downButton = new Button(shell, SWT.PUSH);
> downButton.setBounds(10, 220, 120, 30);
> downButton.setText("Down 10px");
> downButton.addListener(SWT.Selection, new Listener() {
> public void handleEvent(Event event) {
> sc.setOrigin(0, sc.getOrigin().y + 10);
> }
> });
> Button upButton = new Button(shell, SWT.PUSH);
> upButton.setBounds(140, 220, 120, 30);
> upButton.setText("Up 10px");
> upButton.addListener(SWT.Selection, new Listener() {
> public void handleEvent(Event event) {
> sc.setOrigin(0, sc.getOrigin().y - 10);
> }
> });
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> }
>
>
> > Hi,
> >
> > This can probably be made to work by putting each of the Tables into a
> > ScrolledComposite, and scrolling the ScrolledComposites with setOrigin()
> > since this is pixel-based. For an example that does something like this
see
> >
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet296.java?view=co
>
> > Note that I just added a listener to this snippet that makes using the
> > scroll wheel work, but snippet changes sometimes take a while to
replicate
> > on the eclipse.org servers, so if the scroll wheel does not work for you
> > then add the following to the snippet:
> >
> > /*
> > * The following listener scrolls the Tree one item at a time
> > * in response to MouseWheel events.
> > */
> > tree.addListener(SWT.MouseWheel, new Listener() {
> > public void handleEvent(Event event) {
> > Point origin = sc.getOrigin();
> > if (event.count < 0) {
> > origin.y = Math.min(origin.y + tree.getItemHeight(),
> > tree.getSize().y);
> > } else {
> > origin.y = Math.max(origin.y - tree.getItemHeight(), 0);
> > }
> > sc.setOrigin(origin);
> > }
> > });
> >
> > HTH,
> > Grant
> >
> >
> > "Wim Jongman" <wim.jongman@gmail.com> wrote in message
> > news:h7f2em$2r8$1@build.eclipse.org...
> >> Hi,
> >>
> >> This snippet
> >>
> >>
> >>
> >
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet234.java?view=co
> >>
> >> The problem is that we can pixel scroll the table but that will not be
> >> detected because the scroll appears to be by item as
vbar.getSelection()
> >> indicates. If you drag the thumb pixel by pixel, the second table will
> > only
> >> jump every $itemHeight$ pixels.
> >>
> >> Also the left table snippet does not react on mouse scroll in osx
> > snippet167
> >> uses an alternative listener which does react on mouse scroll.
> >>
> >> Is there a way to get this going neatly on OSx? Blocking the pixel
> > scrolling
> >> capabilities could be one solution. Is that possible?
> >>
> >> Regards,
> >>
> >> Wim Jongman
Previous Topic:COMPOSITE WITH EMBEDDED STYLE
Next Topic:Reduce spaces between composite
Goto Forum:
  


Current Time: Fri Aug 23 15:12:15 GMT 2019

Powered by FUDForum. Page generated in 0.02968 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top