Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Listener for SashForm
Listener for SashForm [message #441222] Thu, 12 August 2004 10:36 Go to next message
Christian Hauser is currently offline Christian Hauser
Messages: 189
Registered: July 2009
Senior Member
Hello all

I'm using org.eclipse.swt.custom.SashForm and would like to know how I
get informed when the sash is moved.

No matter what listener I add to SashForm (Control, Resize), I do not
get notified when I resize the sash.

I use such functionality to store the weights of the components of the
SashForm in a properties file. So that I can call SashForm#setWeights
the next time the application starts and the sash form looks the way the
user likes it.

Any hint on that is highly appreciated.

Thanks in advance,
Christian
Re: Listener for SashForm [message #441231 is a reply to message #441222] Thu, 12 August 2004 11:49 Go to previous messageGo to next message
Simone Gianni is currently offline Simone Gianni
Messages: 29
Registered: July 2009
Junior Member
I managed to do this adding a listener on the resize event of the
controls inside the sash form.

Hope this helps,
ciao,
Simone Gianni

Christian Hauser wrote:
> Hello all
>
> I'm using org.eclipse.swt.custom.SashForm and would like to know how I
> get informed when the sash is moved.
>
> No matter what listener I add to SashForm (Control, Resize), I do not
> get notified when I resize the sash.
>
> I use such functionality to store the weights of the components of the
> SashForm in a properties file. So that I can call SashForm#setWeights
> the next time the application starts and the sash form looks the way the
> user likes it.
>
> Any hint on that is highly appreciated.
>
> Thanks in advance,
> Christian
Re: Listener for SashForm [message #441234 is a reply to message #441231] Thu, 12 August 2004 12:00 Go to previous messageGo to next message
Christian Hauser is currently offline Christian Hauser
Messages: 189
Registered: July 2009
Senior Member
Ciao Simone

Thanks for your tip. It worked. I have only two composites in the
SashForm and added a resize listener to the first one.

Thanks a lot and have a nice day,
Christian


Simone Gianni wrote:

> I managed to do this adding a listener on the resize event of the
> controls inside the sash form.
>
> Hope this helps,
> ciao,
> Simone Gianni
>
> Christian Hauser wrote:
>
>> Hello all
>>
>> I'm using org.eclipse.swt.custom.SashForm and would like to know how I
>> get informed when the sash is moved.
>>
>> No matter what listener I add to SashForm (Control, Resize), I do not
>> get notified when I resize the sash.
>>
>> I use such functionality to store the weights of the components of the
>> SashForm in a properties file. So that I can call SashForm#setWeights
>> the next time the application starts and the sash form looks the way
>> the user likes it.
>>
>> Any hint on that is highly appreciated.
>>
>> Thanks in advance,
>> Christian
Re: Listener for SashForm [message #441235 is a reply to message #441222] Thu, 12 August 2004 12:00 Go to previous messageGo to next message
Steve Northover is currently offline Steve Northover
Messages: 1636
Registered: July 2009
Senior Member
Why not ask for the wieghts when you are about to save them?

"Christian Hauser" <christian.hauser@dvbern.ch> wrote in message
news:cffv4j$pk6$1@eclipse.org...
> Hello all
>
> I'm using org.eclipse.swt.custom.SashForm and would like to know how I
> get informed when the sash is moved.
>
> No matter what listener I add to SashForm (Control, Resize), I do not
> get notified when I resize the sash.
>
> I use such functionality to store the weights of the components of the
> SashForm in a properties file. So that I can call SashForm#setWeights
> the next time the application starts and the sash form looks the way the
> user likes it.
>
> Any hint on that is highly appreciated.
>
> Thanks in advance,
> Christian
Re: Listener for SashForm [message #441260 is a reply to message #441222] Thu, 12 August 2004 12:02 Go to previous messageGo to next message
Devon Berry is currently offline Devon Berry
Messages: 9
Registered: July 2009
Junior Member
Not elegant, but it will at least solve your problem: Add a control
listener to the composites that are on your sash form and store the weights
on the control resized event. Here's an example:

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

final SashForm sash = new SashForm(shell, SWT.VERTICAL);

Composite a = new Composite(sash, SWT.NONE);
a.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

Composite b = new Composite(sash, SWT.NONE);
b.setBackground(display.getSystemColor(SWT.COLOR_RED));

a.addControlListener(new ControlListener() {
public void controlResized(ControlEvent e) {
int[] weights = sash.getWeights();
// Store your weights here
System.out.println("Weights: " + weights[0] + " " + weights[1]);
}

public void controlMoved(ControlEvent e) {
}
});

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

Devon

"Christian Hauser" <christian.hauser@dvbern.ch> wrote in message
news:cffv4j$pk6$1@eclipse.org...
> Hello all
>
> I'm using org.eclipse.swt.custom.SashForm and would like to know how I
> get informed when the sash is moved.
>
> No matter what listener I add to SashForm (Control, Resize), I do not
> get notified when I resize the sash.
>
> I use such functionality to store the weights of the components of the
> SashForm in a properties file. So that I can call SashForm#setWeights
> the next time the application starts and the sash form looks the way the
> user likes it.
>
> Any hint on that is highly appreciated.
>
> Thanks in advance,
> Christian
Re: Listener for SashForm [message #441265 is a reply to message #441235] Thu, 12 August 2004 14:40 Go to previous messageGo to next message
Christian Hauser is currently offline Christian Hauser
Messages: 189
Registered: July 2009
Senior Member
Steve Northover wrote:

> Why not ask for the wieghts when you are about to save them?

Because at that time the SashForm is disposed or closed or at least the
components of the SashForm are disposed. Well, it didn't work that way,
maybe I should have tried harder...
Re: Listener for SashForm [message #441266 is a reply to message #441260] Thu, 12 August 2004 14:47 Go to previous messageGo to next message
Christian Hauser is currently offline Christian Hauser
Messages: 189
Registered: July 2009
Senior Member
Thanx Devon. I'll check that tomorrow (we have 8:41 p.m. here). However,
I need more than just the weights. I also want the composite a in your
example to be always at least 210 pixel wide.

I did not figure out how to do that with SashForm. Using a Sash (with a
selection listener) would work, I guess, however, I don't see how to it
using SashForm. My current implementation works by resizing both
composite a and b and then set the weights of the SashForm... I'll
improve my solution tomorrow using a ControlListener.

Thanks.

Devon Berry wrote:

> Not elegant, but it will at least solve your problem: Add a control
> listener to the composites that are on your sash form and store the weights
> on the control resized event. Here's an example:
>
> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
>
> final SashForm sash = new SashForm(shell, SWT.VERTICAL);
>
> Composite a = new Composite(sash, SWT.NONE);
> a.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
>
> Composite b = new Composite(sash, SWT.NONE);
> b.setBackground(display.getSystemColor(SWT.COLOR_RED));
>
> a.addControlListener(new ControlListener() {
> public void controlResized(ControlEvent e) {
> int[] weights = sash.getWeights();
> // Store your weights here
> System.out.println("Weights: " + weights[0] + " " + weights[1]);
> }
>
> public void controlMoved(ControlEvent e) {
> }
> });
>
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> Devon
>
> "Christian Hauser" <christian.hauser@dvbern.ch> wrote in message
> news:cffv4j$pk6$1@eclipse.org...
>
>>Hello all
>>
>>I'm using org.eclipse.swt.custom.SashForm and would like to know how I
>>get informed when the sash is moved.
>>
>>No matter what listener I add to SashForm (Control, Resize), I do not
>>get notified when I resize the sash.
>>
>>I use such functionality to store the weights of the components of the
>>SashForm in a properties file. So that I can call SashForm#setWeights
>>the next time the application starts and the sash form looks the way the
>>user likes it.
>>
>>Any hint on that is highly appreciated.
>>
>>Thanks in advance,
>> Christian
>
>
>
Re: Listener for SashForm [message #441401 is a reply to message #441265] Fri, 13 August 2004 12:50 Go to previous messageGo to next message
Steve Northover is currently offline Steve Northover
Messages: 1636
Registered: July 2009
Senior Member
Do you know when the application is exiting? If you are a stand alone SWT
app, then save the settings before calling shell.dispose(), or in SWT.Close
or before calling System.exit().

"Christian Hauser" <christian.hauser@dvbern.ch> wrote in message
news:cfgddd$hnk$1@eclipse.org...
> Steve Northover wrote:
>
> > Why not ask for the wieghts when you are about to save them?
>
> Because at that time the SashForm is disposed or closed or at least the
> components of the SashForm are disposed. Well, it didn't work that way,
> maybe I should have tried harder...
Re: Listener for SashForm [message #441408 is a reply to message #441401] Fri, 13 August 2004 14:19 Go to previous messageGo to next message
Christian Hauser is currently offline Christian Hauser
Messages: 189
Registered: July 2009
Senior Member
Steve Northover wrote:
> Do you know when the application is exiting? If you are a stand alone SWT
> app, then save the settings before calling shell.dispose(), or in SWT.Close
> or before calling System.exit().

I have to catch the close by listening for an SWT.Close event. However,
at that time all my components are disposed and I cannot get the data
that is inside or at what position the sash is and the like.
Re: Listener for SashForm [message #442525 is a reply to message #441408] Tue, 07 September 2004 10:33 Go to previous message
Steve Northover is currently offline Steve Northover
Messages: 1636
Registered: July 2009
Senior Member
That seems wrong. SWT.Close comes in before any components are disposed.
Can you post a snippet?

"Christian Hauser" <c.hauser@active.ch> wrote in message
news:cfj0jh$77v$1@eclipse.org...
> Steve Northover wrote:
> > Do you know when the application is exiting? If you are a stand alone
SWT
> > app, then save the settings before calling shell.dispose(), or in
SWT.Close
> > or before calling System.exit().
>
> I have to catch the close by listening for an SWT.Close event. However,
> at that time all my components are disposed and I cannot get the data
> that is inside or at what position the sash is and the like.
Previous Topic:[PocketPC] SWT and VGA resolution on PocketPCs
Next Topic:Scroll bar handling - how to get a reference to a visible scroll bar?
Goto Forum:
  


Current Time: Wed Aug 20 08:45:33 EDT 2014

Powered by FUDForum. Page generated in 0.02331 seconds