redcar-javamateview 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/LICENSE +34 -0
  2. data/README +58 -0
  3. data/Rakefile +94 -0
  4. data/lib/javamateview.rb +41 -0
  5. data/lib/javamateview/example.rb +334 -0
  6. data/lib/javamateview/jar/java-mateview.jar +0 -0
  7. data/lib/javamateview/jcodings.jar +0 -0
  8. data/lib/javamateview/jdom.jar +0 -0
  9. data/lib/javamateview/joni.jar +0 -0
  10. data/spec/onig/match_spec.rb +50 -0
  11. data/spec/parsing/dynamic_parsing_spec.rb +172 -0
  12. data/spec/parsing/static_parsing_spec.rb +476 -0
  13. data/spec/spec_helper.rb +33 -0
  14. data/src/com/redcareditor/mate/Bundle.java +81 -0
  15. data/src/com/redcareditor/mate/DoublePattern.java +89 -0
  16. data/src/com/redcareditor/mate/Grammar.java +129 -0
  17. data/src/com/redcareditor/mate/IAnnotationAreaListener.java +7 -0
  18. data/src/com/redcareditor/mate/IGrammarListener.java +5 -0
  19. data/src/com/redcareditor/mate/IncludePattern.java +10 -0
  20. data/src/com/redcareditor/mate/LineNumberRulerColumn.java +922 -0
  21. data/src/com/redcareditor/mate/Marker.java +22 -0
  22. data/src/com/redcareditor/mate/MateText.java +697 -0
  23. data/src/com/redcareditor/mate/ParseThunk.java +71 -0
  24. data/src/com/redcareditor/mate/Parser.java +627 -0
  25. data/src/com/redcareditor/mate/ParserScheduler.java +237 -0
  26. data/src/com/redcareditor/mate/Pattern.java +152 -0
  27. data/src/com/redcareditor/mate/RangeSet.java +91 -0
  28. data/src/com/redcareditor/mate/Scanner.java +178 -0
  29. data/src/com/redcareditor/mate/Scope.java +534 -0
  30. data/src/com/redcareditor/mate/ScopeMatcher.java +162 -0
  31. data/src/com/redcareditor/mate/SharedTextColors.java +110 -0
  32. data/src/com/redcareditor/mate/SinglePattern.java +20 -0
  33. data/src/com/redcareditor/mate/WhitespaceCharacterPainter.java +395 -0
  34. data/src/com/redcareditor/mate/colouring/Colourer.java +16 -0
  35. data/src/com/redcareditor/mate/colouring/swt/MarginPaintListener.java +62 -0
  36. data/src/com/redcareditor/mate/colouring/swt/SwtColourer.java +501 -0
  37. data/src/com/redcareditor/mate/document/MateDocument.java +15 -0
  38. data/src/com/redcareditor/mate/document/MateTextFactory.java +9 -0
  39. data/src/com/redcareditor/mate/document/MateTextLocation.java +8 -0
  40. data/src/com/redcareditor/mate/document/MateTextLocationComparator.java +17 -0
  41. data/src/com/redcareditor/mate/document/MateTextRange.java +18 -0
  42. data/src/com/redcareditor/mate/document/swt/SwtMateDocument.java +143 -0
  43. data/src/com/redcareditor/mate/document/swt/SwtMateTextLocation.java +88 -0
  44. data/src/com/redcareditor/mate/document/swt/SwtMateTextRange.java +92 -0
  45. data/src/com/redcareditor/mate/document/swt/SwtScopePositionUpdater.java +90 -0
  46. data/src/com/redcareditor/mate/undo/MateTextUndoManager.java +11 -0
  47. data/src/com/redcareditor/mate/undo/swt/SwtMateTextUndoManager.java +166 -0
  48. data/src/com/redcareditor/onig/Match.java +212 -0
  49. data/src/com/redcareditor/onig/NullMatch.java +57 -0
  50. data/src/com/redcareditor/onig/NullRx.java +29 -0
  51. data/src/com/redcareditor/onig/Range.java +45 -0
  52. data/src/com/redcareditor/onig/Rx.java +167 -0
  53. data/src/com/redcareditor/plist/Dict.java +119 -0
  54. data/src/com/redcareditor/plist/PlistNode.java +52 -0
  55. data/src/com/redcareditor/plist/PlistPropertyLoader.java +44 -0
  56. data/src/com/redcareditor/theme/ScopeSelector.java +39 -0
  57. data/src/com/redcareditor/theme/Theme.java +122 -0
  58. data/src/com/redcareditor/theme/ThemeManager.java +41 -0
  59. data/src/com/redcareditor/theme/ThemeSetting.java +78 -0
  60. data/src/com/redcareditor/util/FileUtility.java +64 -0
  61. data/src/com/redcareditor/util/SingleLineFormatter.java +11 -0
  62. data/src/com/redcareditor/util/swt/ColourUtil.java +56 -0
  63. data/src/ruby/java-mateview.rb +68 -0
  64. data/test/com/redcareditor/mate/BundleTest.java +33 -0
  65. data/test/com/redcareditor/mate/EmptyRangeSetTest.java +27 -0
  66. data/test/com/redcareditor/mate/FilledRangeSetTest.java +82 -0
  67. data/test/com/redcareditor/mate/GrammarTest.java +158 -0
  68. data/test/com/redcareditor/mate/MateTextTest.java +35 -0
  69. data/test/com/redcareditor/mate/ScopeMatcherMatchingTest.java +55 -0
  70. data/test/com/redcareditor/mate/ScopeMatcherRankingTest.java +40 -0
  71. data/test/com/redcareditor/onig/RxTest.java +54 -0
  72. data/test/com/redcareditor/plist/DictTest.java +33 -0
  73. data/test/com/redcareditor/theme/RailsCastThemeTest.java +37 -0
  74. data/test/com/redcareditor/theme/ScopeSelectorTest.java +38 -0
  75. data/test/com/redcareditor/theme/ThemeManagerTest.java +29 -0
  76. data/test/com/redcareditor/util/swt/ColourUtilTest.java +17 -0
  77. metadata +134 -0
data/LICENSE ADDED
@@ -0,0 +1,34 @@
1
+
2
+ ### Licenses for specific files
3
+
4
+ jarjar-1.0.jar is distributed under the Apache License, version 2. For more details, see http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ junit-4.7.jar is distributed under the Common Public License - v 1.0. For more details, see https://github.com/KentBeck/junit/blob/master/LICENSE
7
+
8
+ ### All other files
9
+
10
+ Unless specified in the file itself, the contents of all other files in this
11
+ repository are provided to you under the following license (MIT):
12
+
13
+ Copyright (c) Daniel Lucraft 2011.
14
+
15
+ Permission is hereby granted, free of charge, to any person obtaining
16
+ a copy of this software and associated documentation files (the
17
+ 'Software'), to deal in the Software without restriction, including
18
+ without limitation the rights to use, copy, modify, merge, publish,
19
+ distribute, sublicense, and/or sell copies of the Software, and to
20
+ permit persons to whom the Software is furnished to do so, subject to
21
+ the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be
24
+ included in all copies or substantial portions of the Software.
25
+
26
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
27
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
29
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
30
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
+
34
+
data/README ADDED
@@ -0,0 +1,58 @@
1
+
2
+ JavaMateView
3
+ ============
4
+
5
+ Requirements
6
+ ------------
7
+
8
+ * > jruby-1.3.1 installed and set up on your path
9
+ * rspec gem installed via gem install rspec
10
+ * make sure that JAVA_HOME points to a 1.6 type JDK (this is especially true on OSX Leopard)
11
+
12
+
13
+ Running the Ant-based unit-tests
14
+ --------------------------------
15
+ ant
16
+ or
17
+ rake java:test
18
+
19
+
20
+ Running the RSpec parsing specs
21
+ -------------------------------
22
+
23
+ Compile the java code and run the specs:
24
+
25
+ rake jruby:test
26
+
27
+ If you want to run it manually, without compiling:
28
+ On OSX:
29
+
30
+ jruby -J-XstartOnFirstThread -S spec spec
31
+
32
+ On Linux:
33
+
34
+ jruby -S spec spec/
35
+
36
+
37
+ Contributing
38
+ ------------
39
+
40
+ Just so you know: You're free to use whatever IDE or editor to code on java-mateview.
41
+ You can use the rake tasks to compile your code and run the tests easily.
42
+
43
+ If you do however use the Eclipse IDE you also get the Eclipse project settings right away
44
+ when checking out the repository.
45
+ Alas, there are platform dependent libraries this project relies on, you need to do one little
46
+ thing to be on the way to code in eclipse (The rake + ant files do this in their own way).
47
+
48
+
49
+ Eclipse Setup
50
+ -------------
51
+
52
+ * Clone the repository so you have your own version to work with.
53
+ * Import the project.
54
+ * Set up a variable to point to the lib/{your platform here}/swt.jar
55
+ - Go to: Window -> Preferences -> Java -> Build Path -> Classpath Variables
56
+ - Choose "new" -> File
57
+ - Name the variable SWT_JAR and point it to the lib/{platform}/swt.jar in the java-mateview folder.
58
+
@@ -0,0 +1,94 @@
1
+ require 'rake/clean'
2
+ require 'net/http'
3
+
4
+ jruby_command = case Config::CONFIG["host_os"]
5
+ when /darwin/i
6
+ 'jruby -J-XstartOnFirstThread '
7
+ else
8
+ 'jruby '
9
+ end
10
+
11
+ task :default => 'jruby:test'
12
+
13
+ namespace :java do
14
+ desc "Rebuild the java class files"
15
+ task :compile do
16
+ puts "Compiling java files to *.class files"
17
+ sh %+ant compile+
18
+ end
19
+
20
+ desc "Run jUnit tests against freshly compiled java classes"
21
+ task :test do
22
+ puts "Running JUnit Tets"
23
+ sh %+ant test+
24
+ end
25
+
26
+ desc "Run Benchmarks"
27
+ task :benchmark do
28
+ puts "Compiling java files to *.class files"
29
+ sh %+ant compile-bench+
30
+ runner = 'ch.mollusca.benchmarking.BenchmarkRunner'
31
+ classes = ['com.redcareditor.mate.GrammarBenchmark']
32
+ classpath = '.:bench/:bin/:lib/joni.jar:lib/jdom.jar:lib/jcodings.jar'
33
+ classes.each do |clazz|
34
+ sh "java -cp #{classpath} #{runner} #{clazz}"
35
+ end
36
+ end
37
+ end
38
+
39
+ namespace :jruby do
40
+ desc "Run ruby tests against a freshly compiled build"
41
+ task :test => ['java:test'] do
42
+ puts "Running RSpec Tests"
43
+ sh %+#{jruby_command} -S spec spec/+
44
+ end
45
+ end
46
+
47
+
48
+ namespace :build do
49
+ desc "Fetch the swt jars from the gem"
50
+ task :prepare do
51
+ require 'rubygems'
52
+ require 'java'
53
+ gem 'swt'
54
+ require 'swt/jar'
55
+ swt_jar_dir = File.dirname(Swt.jar_path)
56
+
57
+
58
+ mkdir_p File.expand_path("../lib/swt_jars", __FILE__)
59
+ %w(linux linux64 osx osx64 win32).each do |platform|
60
+ dir = File.expand_path("../lib/swt_jars/#{platform}", __FILE__)
61
+ mkdir_p dir
62
+ from = swt_jar_dir + "/swt_#{platform}.jar"
63
+ to = dir + "/swt.jar"
64
+ cp from, to
65
+ end
66
+
67
+ mkdir_p File.expand_path("../lib/jface_jars", __FILE__)
68
+
69
+ Dir[swt_jar_dir + "/jface/org.ecl*.jar"].each do |from, to|
70
+ to = File.expand_path("../lib/jface_jars/#{File.basename(from)}", __FILE__)
71
+ cp from, to
72
+ end
73
+ end
74
+
75
+ desc "Get jruby-complete to build release jar"
76
+ task :get_jruby do
77
+ jruby_complete = "jruby-complete-#{JRUBY_VERSION}.jar"
78
+ location = "http://dist.codehaus.org/jruby/#{JRUBY_VERSION}/#{jruby_complete}"
79
+ local_path = "lib/#{jruby_complete}"
80
+ unless File.exists?(local_path)
81
+ puts "Getting required #{jruby_complete}"
82
+ response = Net::HTTP.get(URI.parse(location))
83
+ File.open(local_path, "wb") { |file| file.write(response) }
84
+ else
85
+ puts "Already have required #{jruby_complete}, skipping download"
86
+ end
87
+ end
88
+
89
+ desc "Build the release *.jar"
90
+ task :release => [:get_jruby] do
91
+ puts "Building release *.jar"
92
+
93
+ end
94
+ end
@@ -0,0 +1,41 @@
1
+
2
+ require 'javamateview/joni'
3
+ require 'javamateview/jcodings'
4
+ require 'javamateview/jdom'
5
+
6
+ require 'javamateview/jar/java-mateview'
7
+
8
+ module JavaMateView
9
+ import com.redcareditor.mate.Bundle
10
+ import com.redcareditor.mate.Grammar
11
+ import com.redcareditor.mate.MateText
12
+ import com.redcareditor.mate.Parser
13
+ import com.redcareditor.mate.ParserScheduler
14
+ import com.redcareditor.mate.Pattern
15
+ import com.redcareditor.mate.Scope
16
+ import com.redcareditor.mate.ScopeMatcher
17
+ import com.redcareditor.theme.Theme
18
+ import com.redcareditor.theme.ThemeManager
19
+
20
+ class MateText
21
+ def set_root_scope_by_content_name(grammar_name, name)
22
+ scope = JavaMateView::Scope.new(self, "re")
23
+ bs = JavaMateView::Bundle.bundles
24
+ ruby = bs.detect {|b| b.name == grammar_name}
25
+ ps = ruby.grammars.first.patterns
26
+ dps = ps.select {|pt| pt.is_a?(Java::ComRedcareditorMate::DoublePattern) }
27
+ rps = dps.detect {|pt| pt.contentName == name }
28
+ scope.pattern = rps
29
+ scope.isOpen = true
30
+ self.parser.root = scope
31
+ end
32
+
33
+ def delay_parsing
34
+ parser.parserScheduler.deactivate
35
+ yield
36
+ parser.parserScheduler.reactivate
37
+ end
38
+ end
39
+ end
40
+
41
+
@@ -0,0 +1,334 @@
1
+
2
+ Dir[File.dirname(__FILE__) + "/*.jar"].each {|fn| require fn }
3
+ require File.join(File.dirname(__FILE__), *%w(.. src ruby java-mateview))
4
+
5
+ class MateExample < Jface::ApplicationWindow
6
+ attr_reader :mate_text, :contents
7
+
8
+ def initialize
9
+ super(nil)
10
+ end
11
+
12
+ # this is another way of making a listener
13
+ class MyListener
14
+ include com.redcareditor.mate.IGrammarListener
15
+
16
+ def grammarChanged(new_name)
17
+ puts "listened for #{new_name} in #{self}"
18
+ end
19
+ end
20
+
21
+ def createContents(parent)
22
+ @contents = Swt::Widgets::Composite.new(parent, Swt::SWT::NONE)
23
+ @contents.layout = Swt::Layout::FillLayout.new
24
+ @mate_text = JavaMateView::MateText.new(@contents, false)
25
+
26
+ @mate_text.add_grammar_listener do |new_name|
27
+ puts "listened for #{new_name} in #{self}"
28
+ end
29
+ @mate_text.set_grammar_by_name "Ruby"
30
+ @mate_text.set_theme_by_name "Mac Classic"
31
+ @mate_text.set_font "Monaco", 15
32
+ return @contents
33
+ end
34
+
35
+ def initializeBounds
36
+ shell.set_size(500,400)
37
+ end
38
+
39
+ def createMenuManager
40
+ main_menu = Jface::MenuManager.new
41
+
42
+ file_menu = Jface::MenuManager.new("Tests")
43
+ main_menu.add file_menu
44
+
45
+ replace1_action = ReplaceContents1.new
46
+ replace1_action.window = self
47
+ replace1_action.text = "Contents RUBY"
48
+ file_menu.add replace1_action
49
+
50
+ replace2_action = ReplaceContents2.new
51
+ replace2_action.window = self
52
+ replace2_action.text = "Contents HTML"
53
+ file_menu.add replace2_action
54
+
55
+ replace3_action = ReplaceContents3.new
56
+ replace3_action.window = self
57
+ replace3_action.text = "Contents long-lined JavaScript (slow)"
58
+ file_menu.add replace3_action
59
+
60
+ set_ruby_action = SetRuby.new
61
+ set_ruby_action.window = self
62
+ set_ruby_action.text = "Set Ruby Grammar"
63
+ file_menu.add set_ruby_action
64
+
65
+ set_html_action = SetHTML.new
66
+ set_html_action.window = self
67
+ set_html_action.text = "Set HTML Grammar"
68
+ file_menu.add set_html_action
69
+
70
+ set_java_script_action = SetJavaScript.new
71
+ set_java_script_action.window = self
72
+ set_java_script_action.text = "Set JavaScript Grammar"
73
+ file_menu.add set_java_script_action
74
+
75
+ set_mc_action = SetMacClassic.new
76
+ set_mc_action.window = self
77
+ set_mc_action.text = "Set Mac Classic"
78
+ file_menu.add set_mc_action
79
+
80
+ set_twilight_action = SetTwilight.new
81
+ set_twilight_action.window = self
82
+ set_twilight_action.text = "Set Twilight"
83
+ file_menu.add set_twilight_action
84
+
85
+ set_scopes_action = PrintScopeTree.new
86
+ set_scopes_action.window = self
87
+ set_scopes_action.text = "Print Scope Tree"
88
+ file_menu.add set_scopes_action
89
+
90
+ set_block_selection = SetBlockSelection.new
91
+ set_block_selection.window = self
92
+ set_block_selection.text = "Set Block Selection"
93
+ file_menu.add set_block_selection
94
+
95
+ set_block_selection = SetNotBlockSelection.new
96
+ set_block_selection.window = self
97
+ set_block_selection.text = "Set Not Block Selection"
98
+ file_menu.add set_block_selection
99
+
100
+ always_parse_all = AlwaysParseAll.new
101
+ always_parse_all.window = self
102
+ always_parse_all.text = "Always Parse All"
103
+ file_menu.add always_parse_all
104
+
105
+ toggle_invisibles = ToggleInvisibles.new
106
+ toggle_invisibles.window = self
107
+ toggle_invisibles.text = "Show/Hide Invisibles"
108
+ file_menu.add toggle_invisibles
109
+
110
+ toggle_word_wrap = ToggleWordWrap.new
111
+ toggle_word_wrap.window = self
112
+ toggle_word_wrap.text = "Toggle Word Wrap"
113
+ file_menu.add toggle_word_wrap
114
+
115
+ remove_annotations = RemoveAnnotations.new
116
+ remove_annotations.window = self
117
+ remove_annotations.text = "Remove Annotations"
118
+ file_menu.add remove_annotations
119
+
120
+ add_annotations = AddAnnotations.new
121
+ add_annotations.window = self
122
+ add_annotations.text = "Add Annotations"
123
+ file_menu.add add_annotations
124
+
125
+ return main_menu
126
+ end
127
+
128
+ class AddAnnotations < Jface::Action
129
+ attr_accessor :window
130
+
131
+ class AnnotationListener
132
+ def initialize(mt)
133
+ @mt = mt
134
+ end
135
+
136
+ def method_missing(event, *args)
137
+ p [event, args]
138
+ end
139
+ end
140
+
141
+ def run
142
+ mt = @window.mate_text
143
+ mt.add_annotation_type(
144
+ "error.type",
145
+ File.dirname(__FILE__) + "/example/little-star.png",
146
+ Swt::Graphics::RGB.new(200, 0, 0));
147
+ mt.add_annotation_type(
148
+ "happy.type",
149
+ File.dirname(__FILE__) + "/example/little-smiley.png",
150
+ Swt::Graphics::RGB.new(0, 0, 200));
151
+ mt.add_annotation("error.type", 1, "Learn how to spell \"text!\"", 5, 5);
152
+ mt.add_annotation("happy.type", 1, "Learn how to spell \"text!\"", 50, 5);
153
+ mt.add_annotation_listener(AnnotationListener.new(@window.mate_text))
154
+ p [:online, 0, mt.annotations_on_line(0).to_a]
155
+ p [:online, 1, mt.annotations_on_line(1).to_a]
156
+ p [:online, 2, mt.annotations_on_line(2).to_a]
157
+ p [:online, 3, mt.annotations_on_line(3).to_a]
158
+ p [:online, 4, mt.annotations_on_line(4).to_a]
159
+ end
160
+ end
161
+
162
+ class RemoveAnnotations < Jface::Action
163
+ attr_accessor :window
164
+
165
+ def run
166
+ @window.mate_text.annotations.each {|a| @window.mate_text.removeAnnotation(a) }
167
+ end
168
+ end
169
+
170
+ class ToggleWordWrap < Jface::Action
171
+ attr_accessor :window
172
+
173
+ def run
174
+ mt = @window.mate_text
175
+ mt.set_word_wrap(!mt.get_word_wrap)
176
+ end
177
+ end
178
+
179
+ class ToggleInvisibles < Jface::Action
180
+ attr_accessor :window
181
+
182
+ def run
183
+ @window.mate_text.showInvisibles(!@window.mate_text.showing_invisibles)
184
+ end
185
+ end
186
+
187
+ class AlwaysParseAll < Jface::Action
188
+ attr_accessor :window
189
+
190
+ def run
191
+ @window.mate_text.parser.parserScheduler.alwaysParseAll = true;
192
+ end
193
+ end
194
+
195
+ class SetBlockSelection < Jface::Action
196
+ attr_accessor :window
197
+
198
+ def run
199
+ @window.mate_text.get_text_widget.set_block_selection(true)
200
+ end
201
+ end
202
+
203
+ class SetNotBlockSelection < Jface::Action
204
+ attr_accessor :window
205
+
206
+ def run
207
+ @window.mate_text.get_text_widget.set_block_selection(false)
208
+ end
209
+ end
210
+
211
+ class SetMacClassic < Jface::Action
212
+ attr_accessor :window
213
+
214
+ def run
215
+ @window.mate_text.set_theme_by_name("Mac Classic")
216
+ end
217
+ end
218
+
219
+ class PrintScopeTree < Jface::Action
220
+ attr_accessor :window
221
+
222
+ def run
223
+ puts @window.mate_text.parser.root.pretty(0)
224
+ end
225
+ end
226
+
227
+ class SetTwilight < Jface::Action
228
+ attr_accessor :window
229
+
230
+ def run
231
+ @window.mate_text.set_theme_by_name("Twilight")
232
+ end
233
+ end
234
+
235
+ class SetRuby < Jface::Action
236
+ attr_accessor :window
237
+
238
+ def run
239
+ @window.mate_text.set_grammar_by_name("Ruby")
240
+ end
241
+ end
242
+
243
+ class SetHTML < Jface::Action
244
+ attr_accessor :window
245
+
246
+ def run
247
+ @window.mate_text.set_grammar_by_name("HTML")
248
+ end
249
+ end
250
+
251
+ class SetJavaScript < Jface::Action
252
+ attr_accessor :window
253
+
254
+ def run
255
+ @window.mate_text.set_grammar_by_name("JavaScript")
256
+ end
257
+ end
258
+
259
+ class ReplaceContents1 < Jface::Action
260
+ attr_accessor :window
261
+
262
+ def run
263
+ s = Time.now
264
+ ##until Time.now - s > 120
265
+ @window.mate_text.getMateDocument.set(File.read(File.dirname(__FILE__) + "/test_big_ruby_file.rb")*3)
266
+ #@window.mate_text.getMateDocument.set("def foo")
267
+ #end
268
+ puts "parse took #{Time.now - s}s"
269
+ puts "num scopes: #{@window.mate_text.parser.root.count_descendants}"
270
+ end
271
+
272
+ def source
273
+ foo=<<-RUBY
274
+ class ExitAction < Jface::Action
275
+ attr_accessor :window
276
+
277
+ def run
278
+ window.close
279
+ end
280
+ end
281
+
282
+ RUBY
283
+ end
284
+ end
285
+
286
+ class ReplaceContents2 < Jface::Action
287
+ attr_accessor :window
288
+
289
+ def run
290
+ @window.mate_text.getMateDocument.set(source*50)
291
+ end
292
+
293
+ def source
294
+ foo=<<-HTML
295
+ <div class="nav">
296
+ <ul>
297
+ <li>Foo</li>
298
+ <li>Bar</li>
299
+ <li>Baz</li>
300
+ </ul>
301
+ </div>
302
+
303
+ HTML
304
+ end
305
+ end
306
+
307
+ class ReplaceContents3 < Jface::Action
308
+ attr_accessor :window
309
+
310
+ def run
311
+ src = File.read("lib/example/jquery-142min.js")
312
+ s = Time.now
313
+ @window.mate_text.getMateDocument.set(src)
314
+ puts "parse took #{Time.now - s}s"
315
+ puts "num scopes: #{@window.mate_text.parser.root.count_descendants}"
316
+ end
317
+ end
318
+
319
+ def self.run
320
+ JavaMateView::Bundle.load_bundles("input/")
321
+ p JavaMateView::Bundle.bundles.to_a.map {|b| b.name }
322
+ JavaMateView::ThemeManager.load_themes("input/")
323
+ p JavaMateView::ThemeManager.themes.to_a.map {|t| t.name }
324
+
325
+ window = MateExample.new
326
+ window.block_on_open = true
327
+ window.addMenuBar
328
+ window.open
329
+ Swt::Widgets::Display.getCurrent.dispose
330
+ end
331
+ end
332
+
333
+ MateExample.run
334
+