[jsword-devel] BibleDesktop Enhancements

Neil Short neshort at yahoo.com
Tue Jul 22 19:46:32 MST 2008



======
If not us, who? And if not now, when?
Ronald Reagan


--- On Mon, 7/21/08, Adam Thomas <adam-thomas at cox.net> wrote:

....
> size and position. Is there already a persistence mechanism
> in BD, or should
> I use a generic .properties file?
> 

I recommend placing some file like ".bibledesktoprc
in the user's default home directory.

String homeDirectory = System.getProperty("user.home");


so, when the main window is started with something like...



public static void main(String[] args) {
		Dimension screenSize, framesize;
		int x, y;
		String homeDirectory = System.getProperty("user.home");
		JFrame frame = new JFrame("Foo");
				// these are the defaults.
                                // They can be reset from preferences
		screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		framesize = 
                      new Dimension((int)(screenSize.getWidth() * 0.33),
		        (int)(screenSize.getHeight() * 0.75));
		y = (int)(screenSize.height - framesize.height) * 3 / 4;
		if (y < 0)
			y = 0;
		x = (int)(screenSize.width - framesize.width);
		if (x < 0)
			x = 0;
		// end of defaults section

		BDWindowPreferences myprefs = 
                    new BDWindowPreferences(screenSize, framesize, x, y);
                           // BDWindowPreferences() will need to be
                           // written. I might volunteer.
		try {// set window placement preferences according to
                        // personal preferences
			ObjectInputStream in =
			        new ObjectInputStream(
                                  new FileInputStream(
                                   homeDirectory + "//.bibledesktoprc"));
			myprefs = (BDWindowPreferences) in.readObject();
			if (screenSize.equals(myprefs.getScreensize())) {
				x = myprefs.getX();
				y = myprefs.getY();
				framesize = myprefs.getWindowsize();
			}
		} catch (ClassNotFoundException e) {
			System.out.println(
                            "This is not a BDWindowPreferences file."+ 
                               "\nGoing with defaults.");
		}
		catch (IOException e) {
			System.out.println(
                          "We'll stick with the default window size.");
			try {
			    ObjectOutputStream outfile = 
                               new ObjectOutputStream(
				 new FileOutputStream(homeDirectory + 
                                    "//.bibledesktoprc"));
				
				outfile.writeObject(myprefs);
				outfile.close();
			} catch (IOException e2) {
				System.out.println("Save failed.");
				System.out.println("Error = "+e2);
			}
		}
		
		frame.getContentPane().add(
                    new FOOBAR_Panel(arg1, arg2 /*etc*/);


		frame.pack();



		frame.setSize(framesize);
		frame.setLocation(x, y);
		frame.show();
	}


      



More information about the jsword-devel mailing list