001/**
002 * GUIPreferences -- A collection of preferences for the GUI program.
003 *
004 * Copyright (C) 2009-2015, by Joseph A. Huwaldt. All rights reserved.
005 *
006 * This library is free software; you can redistribute it and/or modify it under the terms
007 * of the GNU Lesser General Public License as published by the Free Software Foundation;
008 * either version 2.1 of the License, or (at your option) any later version.
009 *
010 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
012 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
013 *
014 * You should have received a copy of the GNU Lesser General Public License along with
015 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place -
016 * Suite 330, Boston, MA 02111-1307, USA. Or visit: http://www.gnu.org/licenses/lgpl.html
017 */
018package geomss.app;
019
020import jahuwaldt.swing.MainApp;
021import jahuwaldt.swing.QuitListener;
022import java.io.IOException;
023import java.util.Objects;
024import static java.util.Objects.requireNonNull;
025import java.util.ResourceBundle;
026import javax.swing.JOptionPane;
027
028/**
029 * This class serves as a collection of preferences for this program.
030 * 
031 * <p> Modified by: Joseph A. Huwaldt </p>
032 * 
033 * @author Joseph A. Huwaldt, Date: May 2, 2009
034 * @version November 23, 2015
035 */
036public class GUIPreferences extends AppPreferences {
037
038    //  A reference to the window containing the applicatin preferences.
039    //private PrefsDialog prefsDialog = null;
040    //  Reference to the main application object for this program.
041    private final MainApp app;
042
043    /**
044     * Construct the preferences object for this application. This constructor will locate
045     * the preference file and load in any available preferences for the application.
046     *
047     * @param app Reference to the main application.
048     */
049    public GUIPreferences(MainApp app) {
050        this.app = requireNonNull(app);
051
052        if (Objects.nonNull(app.getGUIApplication())) {
053            //  Register a quit listener so that we can save the preferences before the application quits.
054            app.getGUIApplication().addQuitListener(new QuitListener() {
055                @Override
056                public boolean quit() {
057                    //  Write out the preferences to a file if they have changed.
058                    try {
059                        if (prefsChanged) {
060                            writePreferences();
061                            prefsChanged = false;
062                        }
063
064                    } catch (IOException e) {
065                        e.printStackTrace();
066                        ResourceBundle resBundle = GUIPreferences.this.app.getResourceBundle();
067                        JOptionPane.showMessageDialog(null, resBundle.getString("writePrefsErrMsg")
068                                + e.getMessage() + "</html>",
069                                resBundle.getString("prefsFileErrTitle"), JOptionPane.ERROR_MESSAGE);
070                    }
071
072                    return false;
073                }
074            });
075        }
076    }
077
078    /**
079     * Method that displays a dialog that allows the user to change the application
080     * preferences. If the application is running in batch mode, this method does nothing.
081     */
082    @Override
083    public void showPreferenceDialog() {
084        /*      if (app.getGUIApplication() != null) {
085         if (prefsDialog != null)
086         prefsDialog.setVisible(true);
087                
088         else {
089         prefsDialog = new PrefsDialog();
090         AppUtilities.positionWindow( prefsDialog, prefsDialog.getWidth(), prefsDialog.getHeight() );
091         prefsDialog.setVisible(true);
092         }
093         }
094         */
095    }
096
097}