PageRenderTime 30ms CodeModel.GetById 25ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/jars/MacOS/macos/MacOSPlugin.java

#
Java | 110 lines | 67 code | 10 blank | 33 comment | 11 complexity | a690488d4e7a00ba7775c08014869bc5 MD5 | raw file
  1/* 
  2 * :tabSize=8:indentSize=8:noTabs=false:
  3 * :folding=explicit:collapseFolds=1:
  4 *
  5 * MacOSPlugin.java - Main class Mac OS Plugin
  6 * Copyright (C) 2001, 2002 Kris Kopicki
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22
 23package macos;
 24
 25//{{{ Imports
 26import java.util.Vector;
 27import javax.swing.*;
 28import org.gjt.sp.jedit.*;
 29import org.gjt.sp.jedit.gui.*;
 30import org.gjt.sp.jedit.msg.*;
 31import org.gjt.sp.util.Log;
 32import macos.menu.*;
 33import macos.script.*;
 34import com.apple.cocoa.application.*;
 35import com.apple.eawt.Application;
 36//}}}
 37
 38public class MacOSPlugin extends EBPlugin
 39{
 40	//{{{ Variables
 41	static boolean started = false;
 42	private boolean osok;
 43	private Delegate delegate;
 44	//}}}
 45	
 46	//{{{ start() method
 47	public void start()
 48	{
 49		if(osok = osok())
 50		{
 51			delegate = new Delegate();
 52			NSApplication app = NSApplication.sharedApplication();
 53			
 54			Macros.registerHandler(new AppleScriptHandler());
 55			Application app2 = new Application();
 56			app2.addApplicationListener(delegate);
 57			app2.setEnabledPreferencesMenu(true);
 58			
 59			app.setDelegate(delegate);
 60			app.setServicesProvider(delegate);
 61		}
 62	} //}}}
 63	
 64	//{{{ handleMessage() method
 65	public void handleMessage(EBMessage message)
 66	{
 67		if (osok)
 68		{
 69			// Set type/creator codes for files
 70			if (message instanceof BufferUpdate)
 71				delegate.handleFileCodes((BufferUpdate)message);
 72			else if (message instanceof PropertiesChanged)
 73			{
 74				boolean b = jEdit.getBooleanProperty("MacOSPlugin.useSelection",
 75					jEdit.getBooleanProperty("MacOSPlugin.default.useSelection"));
 76				if (b)
 77					jEdit.setColorProperty("view.selectionColor",
 78						UIManager.getColor("textHighlight"));
 79			}
 80			// This is necessary to have a file opened from the Finder
 81			// before jEdit is running set as the currently active
 82			// buffer.
 83			else if (!started && message instanceof ViewUpdate)
 84				delegate.handleOpenFile((ViewUpdate)message);
 85		}
 86	}//}}}
 87	
 88	//{{{ osok() method
 89	private boolean osok()
 90	{
 91		final String osname = jEdit.getProperty("MacOSPlugin.depend.os.name");
 92		final String mrjversion = jEdit.getProperty("MacOSPlugin.depend.mrj.version");
 93		
 94		if (!System.getProperty("os.name").equals(osname))
 95		{
 96			// According to Slava this is better
 97			Log.log(Log.ERROR,this,jEdit.getProperty("MacOSPlugin.dialog.osname.message"));
 98			return false;
 99		}
100		if (System.getProperty("mrj.version").compareTo(mrjversion) < 0)
101		{
102			SwingUtilities.invokeLater( new Runnable() { public void run() {
103				GUIUtilities.error(null,"MacOSPlugin.dialog.mrjversion",new Object[] {mrjversion});
104			}});
105			return false;
106		}
107
108		return true;
109	}//}}}
110}