/*  Copyright (C) 2015 JabRef contributors.
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package osx.macadapter;

import java.io.File;
import java.util.List;

import net.sf.jabref.JabRefFrame;

import com.apple.eawt.*;
import com.apple.eawt.AppEvent.AboutEvent;
import com.apple.eawt.AppEvent.OpenFilesEvent;
import com.apple.eawt.AppEvent.PreferencesEvent;
import com.apple.eawt.AppEvent.QuitEvent;

public class MacAdapter implements PreferencesHandler, AboutHandler, QuitHandler, OpenFilesHandler {

	private JabRefFrame parentFrame;
	
	public MacAdapter(JabRefFrame inputFrame) {
		parentFrame = inputFrame;
		Application.getApplication().setOpenFileHandler(this);
		Application.getApplication().setAboutHandler(this);
		Application.getApplication().setPreferencesHandler(this);
		Application.getApplication().setQuitHandler(this);
	}
	
	@Override
	// The OSXAdapter calls this method when a ".bib" file has been double-clicked from the Finder.	
	public void openFiles(OpenFilesEvent event) {
		List<File> files = event.getFiles();
		
		for (int i=0; i<files.size(); i++) {
			parentFrame.openAction(files.get(i).getAbsolutePath());
		}
	} 

	@Override
	public void handleQuitRequestWith(QuitEvent evt, QuitResponse resp) {
		if (parentFrame.quit())
			resp.performQuit();
		else
			resp.cancelQuit();
	}

	@Override
	public void handleAbout(AboutEvent arg0) {
		parentFrame.about();
	}

	@Override
	public void handlePreferences(PreferencesEvent arg0) {
		parentFrame.preferences();
	} 	
}

@@ -1210,16 +1210,23 @@
 entFrame
+ = null
 ;%0A%09%0A%09pub
@@ -1679,16 +1679,46 @@
 vent) %7B%0A
+%09%09if (parentFrame != null) %7B%0A%09
 %09%09List%3CF
@@ -1753,16 +1753,17 @@
 );%0A%09%09%0A%09%09
+%09
 for (int
@@ -1789,18 +1789,18 @@
 ); i++) 
-%7B
 %0A
+%09
 %09%09%09paren
@@ -1937,24 +1937,54 @@
 nse resp) %7B%0A
+%09%09if (parentFrame != null) %7B%0A%09
 %09%09if (parent
@@ -1997,16 +1997,17 @@
 quit())%0A
+%09
 %09%09%09resp.
@@ -2027,13 +2027,15 @@
 ;%0A%09%09
+%09
 else%0A
+%09
 %09%09%09r
@@ -2048,24 +2048,28 @@
 ncelQuit();%0A
+%09%09%7D%0A
 %09%7D%0A%0A%09@Overri
@@ -2107,32 +2107,60 @@
 utEvent arg0) %7B%0A
+%09%09if (parentFrame != null)%0A%09
 %09%09parentFrame.ab
@@ -2233,24 +2233,52 @@
 ent arg0) %7B%0A
+%09%09if (parentFrame != null)%0A%09
 %09%09parentFram

Check for null object for case of wrong input in inputFrame