chrisw 2003/10/01 22:30:57
Modified: src/java/org/apache/tools/ant/gui Main.java MainFrame.java
Log:
Make size of main window persistent!
Obtained from: Jack Woehr
Submitted by: Christoph Wilhelms
Reviewed by: Christoph Wilhelms
Revision Changes Path
1.10 +3 -2 ant-antidote/src/java/org/apache/tools/ant/gui/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/ant-antidote/src/java/org/apache/tools/ant/gui/Main.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Main.java 28 Sep 2003 13:03:00 -0000 1.9
+++ Main.java 2 Oct 2003 05:30:57 -0000 1.10
@@ -100,7 +100,7 @@
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
AppContext context = new AppContext(f);
f.setContext(context);
-
+
/* Doing this in a block to limit scope of temps */
{
String propertiesFileName = settings.getPropertiesFile();
@@ -181,6 +181,7 @@
new AppStartupEvent(context));
f.pack();
+ f.restorePersistentSize();
f.setVisible(true);
// Send notice we are shutting down
1.5 +40 -2
ant-antidote/src/java/org/apache/tools/ant/gui/MainFrame.java
Index: MainFrame.java
===================================================================
RCS file:
/home/cvs/ant-antidote/src/java/org/apache/tools/ant/gui/MainFrame.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MainFrame.java 28 Sep 2003 13:02:59 -0000 1.4
+++ MainFrame.java 2 Oct 2003 05:30:57 -0000 1.5
@@ -55,7 +55,7 @@
package org.apache.tools.ant.gui;
import org.apache.tools.ant.gui.core.AppContext;
-//import org.apache.tools.ant.gui.core.ProjectManager;
+import org.apache.tools.ant.gui.core.PropertiesManager;
import org.apache.tools.ant.gui.event.ProjectClosedEvent;
import org.apache.tools.ant.gui.event.ProjectSelectedEvent;
@@ -63,6 +63,7 @@
import org.apache.tools.ant.gui.acs.ACSProjectElement;
import java.io.IOException;
+import java.awt.Dimension;
/**
* The main frame for the application
@@ -136,9 +137,46 @@
}
/**
+ * Save the window size for the next session
+ */
+ protected void persistSize () {
+ Dimension d = getSize();
+ PropertiesManager pm = _context.getPropertiesManager();
+ pm.setProperty("MainFrame.height", new Integer(new
Double(d.getHeight()).intValue()).toString());
+ pm.setProperty("MainFrame.width", new Integer(new
Double(d.getWidth()).intValue()).toString());
+ try {
+ _context.saveProperties();
+ }
+ catch (java.io.FileNotFoundException e) {
+ // log it?
+ }
+ catch (java.io.IOException e) {
+ // log it?
+ }
+ }
+
+ /**
+ * Restore the window size from the previous session
+ */
+ protected void restorePersistentSize () {
+ PropertiesManager pm = _context.getPropertiesManager();
+ try {
+ setSize(pm.get_int_property("MainFrame.width"),
pm.get_int_property("MainFrame.height"));
+ }
+ catch (PropertiesManager.NoSuchPropertyException e) {
+ // Just means that it's never been saved to persistent properties
yet.
+ }
+
+ catch (PropertiesManager.InvalidIntPropertyException e) {
+ // Should never occur unless user edited file and messed it up.
+ }
+ }
+
+ /**
* Intercept the window close event
*/
protected void processWindowEvent(java.awt.event.WindowEvent
windowEvent) {
+ persistSize(); // Save window size for next session
if (windowEvent.getID() ==
java.awt.event.WindowEvent.WINDOW_CLOSING) {
if (exitForm(windowEvent)) {
super.processWindowEvent(windowEvent);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]