/**
 * The MIT License (MIT)
 * Copyright (c) 2016 Mark Bernard
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of 
 * this software and associated documentation files (the "Software"), to deal in the 
 * Software without restriction, including without limitation the rights to use, copy, 
 * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package io.github.markbernard.jnotepad;

import java.util.prefs.Preferences;

import javax.swing.JFrame;

/**
 * Class to save and load application state between executions.
 * 
 * @author Mark Bernard
 */
public class ApplicationPreferences {
    private static final String WINDOW_X = "window.x";
    private static final String WINDOW_Y = "window.y";
    private static final String WINDOW_WIDTH = "window.width";
    private static final String WINDOW_HEIGHT = "window.height";
    private static final String WINDOW_MAXIMIZED = "window.maximized";
    private static final String DOCUMENT_LINE_WRAP = "document.line.wrap";
    
    private static boolean documentLineWrap;
    
    /**
     * Load state from the user preferences store and apply that state to 
     * the provided application window. Use sensible defaults as required.
     * 
     * @param frame The application window.
     */
    public static void loadPrefs(JFrame frame) {
        Preferences prefs = Preferences.userNodeForPackage(ApplicationPreferences.class);
        
        frame.setBounds(prefs.getInt(WINDOW_X, 0),
                prefs.getInt(WINDOW_Y, 0),
                prefs.getInt(WINDOW_WIDTH, 800),
                prefs.getInt(WINDOW_HEIGHT, 600));
        if (prefs.getBoolean(WINDOW_MAXIMIZED, false)) {
            frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
        }
        documentLineWrap = prefs.getBoolean(DOCUMENT_LINE_WRAP, true);
    }

    /**
     * Read state from the provided application window and store it
     * to the user preferences store.
     * 
     * @param frame The main application window.
     */
    public static void savePrefs(JFrame frame) {
        Preferences prefs = Preferences.userNodeForPackage(ApplicationPreferences.class);
        
        if (frame.getExtendedState() == JFrame.MAXIMIZED_BOTH) {
            prefs.putBoolean(WINDOW_MAXIMIZED, true);
        } else {
            prefs.putBoolean(WINDOW_MAXIMIZED, false);
            prefs.putInt(WINDOW_X, frame.getX());
            prefs.putInt(WINDOW_Y, frame.getY());
            prefs.putInt(WINDOW_WIDTH, frame.getWidth());
            prefs.putInt(WINDOW_HEIGHT, frame.getHeight());
        }
        prefs.putBoolean(DOCUMENT_LINE_WRAP, documentLineWrap);
    }

    /**
     * @return the documentLineWrap
     */
    public static boolean isDocumentLineWrap() {
        return documentLineWrap;
    }

    /**
     * @param documentLineWrap the documentLineWrap to set
     */
    public static void setDocumentLineWrap(boolean documentLineWrap) {
        ApplicationPreferences.documentLineWrap = documentLineWrap;
    }
}

@@ -1696,138 +1696,13 @@
 d%22;%0A
-    private static final String DOCUMENT_LINE_WRAP = %22document.line.wrap%22;%0A    %0A    private static boolean documentLineWrap;%0A
     %0A
+
     
@@ -2387,79 +2387,8 @@
   %7D%0A
-        documentLineWrap = prefs.getBoolean(DOCUMENT_LINE_WRAP, true);%0A
     
@@ -3122,24 +3122,24 @@
 tHeight());%0A
+
         %7D%0A  
@@ -3140,434 +3140,8 @@
   %7D%0A
-        prefs.putBoolean(DOCUMENT_LINE_WRAP, documentLineWrap);%0A    %7D%0A%0A    /**%0A     * @return the documentLineWrap%0A     */%0A    public static boolean isDocumentLineWrap() %7B%0A        return documentLineWrap;%0A    %7D%0A%0A    /**%0A     * @param documentLineWrap the documentLineWrap to set%0A     */%0A    public static void setDocumentLineWrap(boolean documentLineWrap) %7B%0A        ApplicationPreferences.documentLineWrap = documentLineWrap;%0A
     

Fix line wrap