KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > macos > MacOSPlugin


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
23 package macos;
24
25 //{{{ Imports
26
import java.util.Vector JavaDoc;
27 import javax.swing.*;
28 import org.gjt.sp.jedit.*;
29 import org.gjt.sp.jedit.gui.*;
30 import org.gjt.sp.jedit.msg.*;
31 import org.gjt.sp.util.Log;
32 import macos.menu.*;
33 import macos.script.*;
34 import com.apple.cocoa.application.*;
35 import com.apple.eawt.Application;
36 //}}}
37

38 public 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             app2.setEnabledAboutMenu(true);
59             
60             app.setDelegate(delegate);
61             //app.setServicesProvider(delegate);
62
}
63     } //}}}
64

65     //{{{ handleMessage() method
66
public void handleMessage(EBMessage message)
67     {
68         if (osok)
69         {
70             // Set type/creator codes for files
71
if (message instanceof BufferUpdate)
72                 delegate.handleFileCodes((BufferUpdate)message);
73             else if (message instanceof PropertiesChanged)
74             {
75                 boolean b = jEdit.getBooleanProperty("MacOSPlugin.useSelection",
76                     jEdit.getBooleanProperty("MacOSPlugin.default.useSelection"));
77                 if (b)
78                     jEdit.setColorProperty("view.selectionColor",
79                         UIManager.getColor("textHighlight"));
80             }
81             // This is necessary to have a file opened from the Finder
82
// before jEdit is running set as the currently active
83
// buffer.
84
else if (!started && message instanceof ViewUpdate)
85                 delegate.handleOpenFile((ViewUpdate)message);
86         }
87     }//}}}
88

89     //{{{ osok() method
90
private boolean osok()
91     {
92         final String JavaDoc osname = jEdit.getProperty("MacOSPlugin.depend.os.name");
93         final String JavaDoc mrjversion = jEdit.getProperty("MacOSPlugin.depend.mrj.version");
94         
95         if (!System.getProperty("os.name").equals(osname))
96         {
97             // According to Slava this is better
98
Log.log(Log.ERROR,this,jEdit.getProperty("MacOSPlugin.dialog.osname.message"));
99             return false;
100         }
101         if (MiscUtilities.compareStrings(
102             System.getProperty("mrj.version"),mrjversion,false) < 0)
103         {
104             SwingUtilities.invokeLater( new Runnable JavaDoc() { public void run() {
105                 GUIUtilities.error(null,"MacOSPlugin.dialog.mrjversion",new Object JavaDoc[] {mrjversion});
106             }});
107             return false;
108         }
109
110         return true;
111     }//}}}
112
}
113
Popular Tags