001: /*
002: * :tabSize=8:indentSize=8:noTabs=false:
003: * :folding=explicit:collapseFolds=1:
004: *
005: * MacOSPlugin.java - Main class Mac OS Plugin
006: * Copyright (C) 2001, 2002 Kris Kopicki
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package macos;
024:
025: //{{{ Imports
026: import java.util.Vector;
027: import javax.swing.*;
028: import org.gjt.sp.jedit.*;
029: import org.gjt.sp.jedit.gui.*;
030: import org.gjt.sp.jedit.msg.*;
031: import org.gjt.sp.util.Log;
032: import macos.menu.*;
033: import macos.script.*;
034: import com.apple.cocoa.application.*;
035: import com.apple.eawt.Application;
036:
037: //}}}
038:
039: public class MacOSPlugin extends EBPlugin {
040: //{{{ Variables
041: static boolean started = false;
042: private boolean osok;
043: private Delegate delegate;
044:
045: //}}}
046:
047: //{{{ start() method
048: public void start() {
049: if (osok = osok()) {
050: delegate = new Delegate();
051: NSApplication app = NSApplication.sharedApplication();
052:
053: Macros.registerHandler(new AppleScriptHandler());
054: Application app2 = new Application();
055: app2.addApplicationListener(delegate);
056: app2.setEnabledPreferencesMenu(true);
057: app2.setEnabledAboutMenu(true);
058:
059: app.setDelegate(delegate);
060: //app.setServicesProvider(delegate);
061: }
062: } //}}}
063:
064: //{{{ handleMessage() method
065: public void handleMessage(EBMessage message) {
066: if (osok) {
067: // Set type/creator codes for files
068: if (message instanceof BufferUpdate)
069: delegate.handleFileCodes((BufferUpdate) message);
070: else if (message instanceof PropertiesChanged) {
071: boolean b = jEdit
072: .getBooleanProperty(
073: "MacOSPlugin.useSelection",
074: jEdit
075: .getBooleanProperty("MacOSPlugin.default.useSelection"));
076: if (b)
077: jEdit.setColorProperty("view.selectionColor",
078: UIManager.getColor("textHighlight"));
079: }
080: // This is necessary to have a file opened from the Finder
081: // before jEdit is running set as the currently active
082: // buffer.
083: else if (!started && message instanceof ViewUpdate)
084: delegate.handleOpenFile((ViewUpdate) message);
085: }
086: }//}}}
087:
088: //{{{ osok() method
089: private boolean osok() {
090: final String osname = jEdit
091: .getProperty("MacOSPlugin.depend.os.name");
092: final String mrjversion = jEdit
093: .getProperty("MacOSPlugin.depend.mrj.version");
094:
095: if (!System.getProperty("os.name").equals(osname)) {
096: // According to Slava this is better
097: Log.log(Log.ERROR, this , jEdit
098: .getProperty("MacOSPlugin.dialog.osname.message"));
099: return false;
100: }
101: if (MiscUtilities.compareStrings(System
102: .getProperty("mrj.version"), mrjversion, false) < 0) {
103: SwingUtilities.invokeLater(new Runnable() {
104: public void run() {
105: GUIUtilities.error(null,
106: "MacOSPlugin.dialog.mrjversion",
107: new Object[] { mrjversion });
108: }
109: });
110: return false;
111: }
112:
113: return true;
114: }//}}}
115: }
|