PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/jars/MacOS/macos/MacOSPlugin.java

#
Java | 112 lines | 68 code | 10 blank | 34 comment | 11 complexity | 3ae431d82ef2c4f6879dbc49b54ad55a MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package macos;
  23. //{{{ Imports
  24. import java.util.Vector;
  25. import javax.swing.*;
  26. import org.gjt.sp.jedit.*;
  27. import org.gjt.sp.jedit.gui.*;
  28. import org.gjt.sp.jedit.msg.*;
  29. import org.gjt.sp.util.Log;
  30. import macos.menu.*;
  31. import macos.script.*;
  32. import com.apple.cocoa.application.*;
  33. import com.apple.eawt.Application;
  34. //}}}
  35. public class MacOSPlugin extends EBPlugin
  36. {
  37. //{{{ Variables
  38. static boolean started = false;
  39. private boolean osok;
  40. private Delegate delegate;
  41. //}}}
  42. //{{{ start() method
  43. public void start()
  44. {
  45. if(osok = osok())
  46. {
  47. delegate = new Delegate();
  48. NSApplication app = NSApplication.sharedApplication();
  49. Macros.registerHandler(new AppleScriptHandler());
  50. Application app2 = new Application();
  51. app2.addApplicationListener(delegate);
  52. app2.setEnabledPreferencesMenu(true);
  53. app2.setEnabledAboutMenu(true);
  54. app.setDelegate(delegate);
  55. //app.setServicesProvider(delegate);
  56. }
  57. } //}}}
  58. //{{{ handleMessage() method
  59. public void handleMessage(EBMessage message)
  60. {
  61. if (osok)
  62. {
  63. // Set type/creator codes for files
  64. if (message instanceof BufferUpdate)
  65. delegate.handleFileCodes((BufferUpdate)message);
  66. else if (message instanceof PropertiesChanged)
  67. {
  68. boolean b = jEdit.getBooleanProperty("MacOSPlugin.useSelection",
  69. jEdit.getBooleanProperty("MacOSPlugin.default.useSelection"));
  70. if (b)
  71. jEdit.setColorProperty("view.selectionColor",
  72. UIManager.getColor("textHighlight"));
  73. }
  74. // This is necessary to have a file opened from the Finder
  75. // before jEdit is running set as the currently active
  76. // buffer.
  77. else if (!started && message instanceof ViewUpdate)
  78. delegate.handleOpenFile((ViewUpdate)message);
  79. }
  80. }//}}}
  81. //{{{ osok() method
  82. private boolean osok()
  83. {
  84. final String osname = jEdit.getProperty("MacOSPlugin.depend.os.name");
  85. final String mrjversion = jEdit.getProperty("MacOSPlugin.depend.mrj.version");
  86. if (!System.getProperty("os.name").equals(osname))
  87. {
  88. // According to Slava this is better
  89. Log.log(Log.ERROR,this,jEdit.getProperty("MacOSPlugin.dialog.osname.message"));
  90. return false;
  91. }
  92. if (MiscUtilities.compareStrings(
  93. System.getProperty("mrj.version"),mrjversion,false) < 0)
  94. {
  95. SwingUtilities.invokeLater( new Runnable() { public void run() {
  96. GUIUtilities.error(null,"MacOSPlugin.dialog.mrjversion",new Object[] {mrjversion});
  97. }});
  98. return false;
  99. }
  100. return true;
  101. }//}}}
  102. }