KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > macos > MacOSActions


1 /*
2  * :tabSize=8:indentSize=8:noTabs=false:
3  * :folding=explicit:collapseFolds=1:
4  *
5  * MacOSActions.java
6  * Copyright (C) 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.io.*;
27 import javax.swing.*;
28 import com.apple.cocoa.application.*;
29 import com.apple.cocoa.foundation.*;
30 import org.gjt.sp.jedit.*;
31 //}}}
32

33 public class MacOSActions
34 {
35     //{{{ showInFinder() method
36
public static void showInFinder(String JavaDoc path)
37     {
38         if (new File(path).exists())
39         {
40             //Remember to make this an option later
41
//NSApplication.sharedApplication().hide(jEdit.getPlugin("MacOSPlugin"));
42
NSWorkspace.sharedWorkspace().selectFile(path,path);
43         }
44     } //}}}
45

46     //{{{ runScript() method
47
public static void runScript(String JavaDoc path)
48     {
49         new ScriptRunner(path).start();
50         //SwingUtilities.invokeLater(new ScriptRunner(path));
51
} //}}}
52

53     //{{{ ScriptRunner class
54
static class ScriptRunner extends Thread JavaDoc
55     {
56         private String JavaDoc path;
57         
58         public ScriptRunner(String JavaDoc path)
59         {
60             this.path = path;
61         }
62         
63         public void run()
64         {
65             File file = new File(path);
66             
67             if (file.exists())
68             {
69                 try {
70                     BufferedReader reader = new BufferedReader(new FileReader(file));
71                     StringBuffer JavaDoc code = new StringBuffer JavaDoc();
72                     String JavaDoc line;
73                     
74                     while ((line = reader.readLine()) != null)
75                         code.append(line+"\n");
76                     
77                     NSAppleScript script = new NSAppleScript(code.toString());
78                     NSMutableDictionary compileErrInfo = new NSMutableDictionary();
79                     NSMutableDictionary execErrInfo = new NSMutableDictionary();
80                     if (script.compile(compileErrInfo))
81                     {
82                         if (script.execute(execErrInfo) == null)
83                         {
84                             JOptionPane.showMessageDialog(null,
85                                 execErrInfo.objectForKey("NSAppleScriptErrorBriefMessage"),
86                                 jEdit.getProperty("MacOSPlugin.dialog.script.title"),
87                                 JOptionPane.ERROR_MESSAGE);
88                         }
89                     }
90                     else
91                     {
92                         JOptionPane.showMessageDialog(null,
93                             compileErrInfo.objectForKey("NSAppleScriptErrorBriefMessage"),
94                             jEdit.getProperty("MacOSPlugin.dialog.script.title"),
95                             JOptionPane.ERROR_MESSAGE);
96                     }
97                 } catch (Exception JavaDoc ex) {}
98             }
99         }
100     } //}}}
101
}
102
Popular Tags