Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / September 2005

Tip: Looking for answers? Try searching our database.

How to "save" a layout?

Thread view: 
Yukun Xing - 09 Sep 2005 03:40 GMT
The layout-manager helps you to put all the components where you want, and
give them the initial size.
But users could drag the frame of the components freely, so how could I
"save" the drag-result? I mean, when
the software is closed and then opened again, the layout should be the one
that has been adjusted by the
users----just like what Eclipse or other IDE does.
So what kind of layout should I need?(GridBagLayout may be preferred?) And
how to "save" it??
Thanks a lot!

Xing Yukun
From BeiHang University ,
Beijing, PR China
xingyukun@sei.buaa.edu.cn
tel: mobile: 82317640-606 13810938552
Andrew Thompson - 09 Sep 2005 04:07 GMT
> The layout-manager helps you to put all the components where you want, and
> give them the initial size.
> But users could drag the frame of the components freely, so how could I
> "save" the drag-result?

Their are a variety of strategies, depending on the
minimum Java version your software requires.

You might..
- serialise the GUI (relatively inefficient, and
problematic when the app. changes)
<http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html>
- store the important details as properties.
<http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html>
- create a Java bean to represent the important information
   and write it to disk as XML ('insert XML should not be
   used for this' argument here)
<http://java.sun.com/j2se/1.5.0/docs/api/java/beans/XMLEncoder.html>
<http://java.sun.com/j2se/1.5.0/docs/api/java/beans/XMLDecoder.html>

The best way would probably be the second.

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"We are about to attempt a crash landing.  Please extinguish all
cigarettes.."
Laurie Anderson  'From The Air'

Roedy Green - 09 Sep 2005 04:29 GMT
>The layout-manager helps you to put all the components where you want, and
>give them the initial size.

The users can only tweak so many things that affect layout, often just
the location and size of the total frame.  If you persist that,
everything else will more or less come out in the wash.

The outside frame can be reconstituted with setLocation setSize set
Bounds.

JSplitPane can be persisted with getDividerLocation
setDividerLocation.

the position of a JScrollPane could be persisted with
getHorizontalScrollBar().getValue()

The Preferences mechanism is great for this task:

here is how you would persist a JFileChooser state:

// ask user where to save.
// persisted in registry directory last used

Preferences userPrefs = Preferences.userRoot().node(
"/com/mindprod/mypackage" );

File suggestedFile = new File ( userPrefs.get( "SAVEDIR", "C:" ),
saveName );
...
     // save same directory for next time.
     // persisted in registry, directory last used
     userPrefs.put( "SAVEDIR",
fc.getCurrentDirectory().getAbsolutePath() );
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Andrew Thompson - 09 Sep 2005 05:04 GMT
> The Preferences mechanism is great for this task:

..and - Dang!  I knew I was forgetting one!

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"..When after all, it was you and me."
The Rolling Stones 'Sympathy For The Devil'

Yukun Xing - 10 Sep 2005 04:33 GMT
Thanks for your help, Mr Thompson and Mr Green(Or should I call you guys
Andrew and Roedy instead? You know, I often get
confused by  my Chinese-English).
I know the way about how to store the properties,  using property file or
xml file. But the problem is , how can I get the "properties"? There are 2
pictures in my msn-space:
http://spaces.msn.com/members/xingyukun1981
Their names are "Eclipse1" and "Eclipse2", in the view "technology" of my
album.
Let's presume Eclipse1 is the initial state, and after the user do some
dragging, the view comes to "Eclipse2". At this time ,we close Eclipse, then
open it again----yes, the perspective in front of us is "Eclpse2".
So how could that be done? Do I have to get the sizes of all the components
in the perspective?
Andrew Thompson - 10 Sep 2005 04:57 GMT
> Thanks for your help, Mr Thompson and Mr Green(Or should I call you guys
> Andrew and Roedy instead?

I prefer 'Andrew'.  Generally when people refer to me as
'Mr Thompson' it is because they are about to ( attempt
to ;) give me a severe criticism.    

>..You know, I often get
> confused by  my Chinese-English).

You are already way ahead of me.  
[ My chinese is horrid (none at all). ]

> http://spaces.msn.com/members/xingyukun1981

..and a picture paints a thousand words.   :-)

> So how could that be done? Do I have to get the sizes of all the components
> in the perspective?

No.  Only that which is 'changeable'.

In the case you showed, it might be the current
'split setting' of each of the splitpanes, as well
as the overall size and location of the application
(getBounds() -> Rectangle)

But it depends on just how much you intend to
restore.  Thus far we have covered the size/shape of
the UI, but that probably only has relevance to the
documents that were displayed in it at the time
it was closed.

Do you also intend to restore the 'opened documents'?
And, at an even finer level, do you intend to have the
caret appear on the line the user was editing/with
the text selection restored..?

How much, and what, you store depends on just how much
you intend to restore for the user.

Note that restoring *documents* and their state can become
very tricky when you have documents that may have been edited
(or deleted) by other programs.

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"I got a raw deal, so I'm lookin' for a steel.."
Tricky 'Black Steel'

Andrew Thompson - 10 Sep 2005 05:19 GMT
>> So how could that be done? Do I have to get the sizes of all the components
>> in the perspective?
>
> No.  Only that which is ..

*user*

> ..'changeable'.

Note that I am only referring to the things that
can be adjusted *by* *the* *user*, as opposed to
things that might be different due to a different
PLAF, screensize, or default font.
[ And if the PLAF is also changeable, you might
simply store the *name* of the PLAF. ]

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"..I pick up all the pieces and make an island.  Might even raise just a
little sand"
Jimi Hendrix 'Voodoo Chile (Slight Return)'

Roedy Green - 10 Sep 2005 12:04 GMT
>it is because they are about to ( attempt
>to ;) give me a severe criticism.

When people call for Mr. Green or Munroe Green, I get a chill.  Only
credit card companies and Revenue Canada (the Canadian IRS) call me
that.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 10 Sep 2005 11:56 GMT
>(Or should I call you guys
>Andrew and Roedy instead?

Every one who likes me calls me Roedy. Those that don't have other
names.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green - 10 Sep 2005 12:02 GMT
> There are 2
>pictures in my msn-space:

I looks as first glance that an MSN Space is just a website where you
can upload photos and perhaps some text.  If you have a java Applet or
JAWS apps, it is possible MS will let you serve it from that website,
but in any case, that website WON'T do the persisting. That will be
stored on the client site.

If you go the properties route, the persisted data will be in an
ordinary datafile. Your big program is finding a spot for it.

If you go the Preferences route, it will be stored in the Windows
registry or on Linux in a little database.

In either case you will need a signed applet to get permission to
leave persistent information on the client.

If you had a real website with a J2EE server on it, then you could
persist data on the server or via cookies.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.