omadawn / njord

Java iRule Editor
2 stars 1 forks source link

Save window geometry between sessions #146

Closed omadawn closed 12 years ago

omadawn commented 12 years ago

There's a cool hack here: http://codeidol.com/java/swing/Windows,-Dialogs,-and-Frames/Save-Window-Settings/

He has you implement a new class and then talk to it. I have the class created. I need to do two things one registering to the global toolkit Toolkit tk = Toolkit.getDefaultToolkit( ); tk.addAWTEventListener(WindowSaver.getInstance( ), AWTEvent.WINDOW_EVENT_MASK);

which might need to be done on both the windowsaver and the main code but I'm not sure.

And b adding a save geometry call to windowsaver in my quit event. I'm not going to add this actual Quit item but simply modify what I'm already doing on shutdown. menu.add(new AbstractAction("Quit") { public void actionPerformed(ActionEvent evt) { try { WindowSaver.saveSettings( ); System.exit(0); } catch (Exception ex) { System.out.println(ex); }

             }
         });
omadawn commented 12 years ago

Why is this hard. The article above is implemented and works... mostly. but it's awkward. For example if you maximize, quit and open the window opens at the same geometry that it used to be. NOT maximized. Which means that you actuallly loose one little line around the edge of the screen which A) looks pretty silly and B) WILL cause a problem later I can guarantee it.

Investigating some other solutions. One option: Swing Application Framework http://java.sun.com/developer/technicalArticles/javase/swingappfr/

Another article similar to the first(main body of the taks) but without doing annoying things like not telling you what libraries you need to import. http://www.onyxbits.de/content/blog/patrick/saving-preferences-jtoolbar-location-and-window-geometry

It looks like a pretty similar mechanism though so I'm not sure it won't have the same 'full screen' issue.

omadawn commented 12 years ago

Done, and done correctly.