rubeus 0.0.4-java → 0.0.5-java
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/jirb_rubeus +73 -0
- data/bin/jirb_rubeus.bat +6 -0
- data/examples/nyanco_viewer/nyanco_disp_label.rb +31 -31
- data/examples/nyanco_viewer/nyanco_viewer_rubeus.rb +39 -38
- data/lib/rubeus.rb +5 -2
- data/lib/rubeus/component_loader.rb +6 -2
- data/lib/rubeus/extensions/javax/swing/j_split_pane.rb +30 -12
- data/lib/rubeus/extensions/javax/swing/j_table.rb +52 -0
- data/lib/rubeus/extensions/javax/swing/table/default_table_model.rb +90 -0
- data/lib/rubeus/swing.rb +2 -1
- metadata +12 -5
data/bin/jirb_rubeus
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
#
|
3
|
+
# IRB in swing
|
4
|
+
#
|
5
|
+
# Damian Steer (pldms@mac.com)
|
6
|
+
|
7
|
+
require "rubygems"
|
8
|
+
require "rubeus"
|
9
|
+
Rubeus::Swing.irb
|
10
|
+
|
11
|
+
require 'jruby'
|
12
|
+
require 'irb'
|
13
|
+
require 'irb/completion'
|
14
|
+
|
15
|
+
# import java.awt.Color
|
16
|
+
# import java.awt.Font
|
17
|
+
# import javax.swing.JFrame
|
18
|
+
# import java.awt.EventQueue
|
19
|
+
|
20
|
+
# Try to find preferred font family, use otherwise -- err -- otherwise
|
21
|
+
def find_font(otherwise, style, size, *families)
|
22
|
+
avail_families = java.awt.GraphicsEnvironment.local_graphics_environment.available_font_family_names
|
23
|
+
fontname = families.find(proc {otherwise}) { |name| avail_families.include? name }
|
24
|
+
Font.new(fontname, style, size)
|
25
|
+
end
|
26
|
+
|
27
|
+
text = javax.swing.JTextPane.new
|
28
|
+
text.font = find_font('Monospaced', Font::PLAIN, 14, 'Monaco', 'Andale Mono')
|
29
|
+
text.margin = java.awt.Insets.new(8,8,8,8)
|
30
|
+
text.caret_color = Color.new(0xa4, 0x00, 0x00)
|
31
|
+
text.background = Color.new(0xf2, 0xf2, 0xf2)
|
32
|
+
text.foreground = Color.new(0xa4, 0x00, 0x00)
|
33
|
+
|
34
|
+
pane = javax.swing.JScrollPane.new
|
35
|
+
pane.viewport_view = text
|
36
|
+
frame = JFrame.new('JRuby IRB Console (tab will autocomplete)')
|
37
|
+
frame.default_close_operation = JFrame::EXIT_ON_CLOSE
|
38
|
+
frame.set_size(700, 600)
|
39
|
+
frame.content_pane.add(pane)
|
40
|
+
tar = org.jruby.demo.TextAreaReadline.new(text,
|
41
|
+
" Welcome to the JRuby IRB Console [#{JRUBY_VERSION}] \n\n")
|
42
|
+
JRuby.objectspace = true # useful for code completion
|
43
|
+
tar.hook_into_runtime_with_streams(JRuby.runtime)
|
44
|
+
|
45
|
+
# We need to show the frame on EDT,
|
46
|
+
# to avoid deadlocks.
|
47
|
+
|
48
|
+
# Once JRUBY-2449 is fixed,
|
49
|
+
# the code will me simplifed.
|
50
|
+
class FrameBringer
|
51
|
+
include java.lang.Runnable
|
52
|
+
def initialize(frame)
|
53
|
+
@frame = frame
|
54
|
+
end
|
55
|
+
def run
|
56
|
+
@frame.visible = true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
EventQueue.invoke_later(FrameBringer.new(frame))
|
61
|
+
|
62
|
+
# From vanilla IRB
|
63
|
+
if __FILE__ == $0
|
64
|
+
IRB.start(__FILE__)
|
65
|
+
else
|
66
|
+
# check -e option
|
67
|
+
if /^-e$/ =~ $0
|
68
|
+
IRB.start(__FILE__)
|
69
|
+
else
|
70
|
+
IRB.setup(__FILE__)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
frame.dispose
|
data/bin/jirb_rubeus.bat
ADDED
@@ -1,31 +1,31 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# 2008/6/22 Junya Murabe (Lancard.com)
|
5
|
-
#
|
6
|
-
|
7
|
-
include Java
|
8
|
-
|
9
|
-
module DD
|
10
|
-
#implements interface
|
11
|
-
include java.awt.dnd.DropTargetListener
|
12
|
-
def dragEnter(e)
|
13
|
-
e.accept_drag java.awt.dnd.DnDConstants::ACTION_COPY
|
14
|
-
end
|
15
|
-
|
16
|
-
def dragExit(e); end
|
17
|
-
def dragOver(e); end
|
18
|
-
def drop(e); end
|
19
|
-
def dropActionChanged(e); end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
class NyancoDispLabel < javax.swing.JLabel
|
24
|
-
include DD
|
25
|
-
def drop(e)
|
26
|
-
e.accept_drop java.awt.dnd.DnDConstants::ACTION_COPY_OR_MOVE
|
27
|
-
java_file_list_flavor = java.awt.datatransfer.DataFlavor.javaFileListFlavor
|
28
|
-
image_path = e.transferable.get_transfer_data(java_file_list_flavor)[0].absolute_path
|
29
|
-
self.icon = javax.swing.ImageIcon.new(image_path)
|
30
|
-
end
|
31
|
-
end
|
1
|
+
# にゃんこびゅーあーから分離した
|
2
|
+
# ドラッグ&ドロップ対応の画像表示用ラベル
|
3
|
+
#
|
4
|
+
# 2008/6/22 Junya Murabe (Lancard.com)
|
5
|
+
#
|
6
|
+
|
7
|
+
include Java
|
8
|
+
|
9
|
+
module DD
|
10
|
+
#implements interface
|
11
|
+
include java.awt.dnd.DropTargetListener
|
12
|
+
def dragEnter(e)
|
13
|
+
e.accept_drag java.awt.dnd.DnDConstants::ACTION_COPY
|
14
|
+
end
|
15
|
+
|
16
|
+
def dragExit(e); end
|
17
|
+
def dragOver(e); end
|
18
|
+
def drop(e); end
|
19
|
+
def dropActionChanged(e); end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class NyancoDispLabel < javax.swing.JLabel
|
24
|
+
include DD
|
25
|
+
def drop(e)
|
26
|
+
e.accept_drop java.awt.dnd.DnDConstants::ACTION_COPY_OR_MOVE
|
27
|
+
java_file_list_flavor = java.awt.datatransfer.DataFlavor.javaFileListFlavor
|
28
|
+
image_path = e.transferable.get_transfer_data(java_file_list_flavor)[0].absolute_path
|
29
|
+
self.icon = javax.swing.ImageIcon.new(image_path)
|
30
|
+
end
|
31
|
+
end
|
@@ -1,39 +1,40 @@
|
|
1
|
-
#!/usr/bin/env jruby
|
2
|
-
#
|
3
|
-
# にゃんこびゅーあー Rubeus
|
4
|
-
#
|
5
|
-
# 2008/7/
|
6
|
-
#
|
7
|
-
|
8
|
-
include Java
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
#
|
3
|
+
# にゃんこびゅーあー Rubeus
|
4
|
+
#
|
5
|
+
# 2008/7/7 Junya Murabe (Lancard.com)
|
6
|
+
#
|
7
|
+
|
8
|
+
include Java
|
9
|
+
|
10
|
+
# $LOAD_PATH << File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
11
|
+
require 'rubygems'
|
12
|
+
|
13
|
+
require 'rubeus'
|
14
|
+
Rubeus::Swing.irb
|
15
|
+
require File.join(File.dirname(__FILE__), 'nyanco_disp_label')
|
16
|
+
|
17
|
+
JFrame.new('にゃんこびゅーあー Rubeus ' + Rubeus::VERSION) do |frame|
|
18
|
+
frame.set_size 400, 300
|
19
|
+
frame.default_close_operation = JFrame::EXIT_ON_CLOSE
|
18
20
|
frame.icon_image = ImageIcon.new(File.join(File.dirname(__FILE__), 'nekobean_s.png')).image
|
19
|
-
|
20
|
-
JPanel.new do |base_pane|
|
21
|
-
base_pane.layout =
|
22
|
-
JScrollPane.new do |sp|
|
23
|
-
layout =
|
24
|
-
layout.alignment =
|
25
|
-
sp.viewport.layout = layout
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
21
|
+
|
22
|
+
JPanel.new do |base_pane|
|
23
|
+
base_pane.layout = BorderLayout.new
|
24
|
+
JScrollPane.new do |sp|
|
25
|
+
layout = FlowLayout.new
|
26
|
+
layout.alignment = FlowLayout::LEFT
|
27
|
+
sp.viewport.layout = layout
|
28
|
+
|
29
|
+
lb = NyancoDispLabel.new
|
30
|
+
|
31
|
+
#ドラッグ&ドロップを有効に
|
32
|
+
[lb, sp].each do |dt|
|
33
|
+
DropTarget.new dt, lb
|
34
|
+
dt.tool_tip_text = 'にゃんこの画像をここにポイッ♪'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
frame.visible = true
|
40
|
+
end
|
data/lib/rubeus.rb
CHANGED
@@ -4,9 +4,12 @@ gem "activesupport", ">=2.0.2"
|
|
4
4
|
require "active_support/core_ext/string"
|
5
5
|
|
6
6
|
module Rubeus
|
7
|
-
VERSION = "0.0.
|
7
|
+
VERSION = "0.0.5"
|
8
8
|
autoload :Awt, "rubeus/awt"
|
9
9
|
autoload :Swing, "rubeus/swing"
|
10
10
|
# autoload :Jdbc, "rubeus/jdbc"
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
|
+
unless File.basename($PROGRAM_NAME) == 'gem' and ARGV.first == 'build'
|
14
|
+
require "rubeus/extensions"
|
15
|
+
end
|
@@ -126,8 +126,12 @@ module Rubeus
|
|
126
126
|
java_fqn = "#{@package_name}#{method.to_s}"
|
127
127
|
extension = Rubeus::Extensions.find_for(java_fqn)
|
128
128
|
if extension
|
129
|
-
|
130
|
-
|
129
|
+
@extension_applied ||= []
|
130
|
+
unless @extension_applied.include?(java_fqn)
|
131
|
+
JavaUtilities.extend_proxy(java_fqn) do
|
132
|
+
include extension
|
133
|
+
end
|
134
|
+
@extension_applied << java_fqn
|
131
135
|
end
|
132
136
|
end
|
133
137
|
result = method_missing_without_rubeus(method, *args)
|
@@ -1,15 +1,33 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Rubeus::Extensions::Javax::Swing
|
2
|
+
module JSplitPane
|
3
|
+
def self.included(base)
|
4
|
+
base.perform_as_container
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
base.instance_eval do
|
7
|
+
alias :new_without_rubeus :new
|
8
|
+
alias :new :new_with_rubeus
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def new_with_rubeus(new_orientation, *args, &block)
|
14
|
+
if new_orientation.is_a?(Symbol)
|
15
|
+
new_orientation = const_get(new_orientation)
|
16
|
+
end
|
17
|
+
new_without_rubeus(new_orientation, *args, &block)
|
18
|
+
end
|
3
19
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
(
|
12
|
-
|
13
|
-
|
20
|
+
def add_new_component_to(object, &block)
|
21
|
+
Rubeus::Awt::Nestable::Context.add_new_component_to(object, :append_component, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def append_component(component)
|
26
|
+
append_method =
|
27
|
+
(self.orientation == javax.swing.JSplitPane::VERTICAL_SPLIT) ?
|
28
|
+
(top_component ? :set_bottom_component : :set_top_component) :
|
29
|
+
(left_component ? :set_right_component : :set_left_component)
|
30
|
+
send(append_method, component)
|
31
|
+
end
|
14
32
|
end
|
15
33
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
Rubeus::Swing.depend_on('JComponent')
|
2
|
+
Rubeus::Swing.depend_on('DefaultTableModel')
|
3
|
+
require 'delegate'
|
4
|
+
|
5
|
+
module Rubeus::Extensions::Javax::Swing
|
6
|
+
module JTable
|
7
|
+
def self.included(base)
|
8
|
+
base.default_attributes = {
|
9
|
+
:preferred_size => [200, 150]
|
10
|
+
}
|
11
|
+
base.module_eval do
|
12
|
+
alias_method :get_model_without_rubeus, :get_model
|
13
|
+
alias_method :get_model, :get_model_with_rubeus
|
14
|
+
alias_method :model, :get_model
|
15
|
+
|
16
|
+
alias_method :set_model_without_rubeus, :set_model
|
17
|
+
alias_method :set_model, :set_model_with_rubeus
|
18
|
+
alias_method :model=, :set_model
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_model_with_rubeus
|
23
|
+
@model || get_model_without_rubeus
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_model_with_rubeus(model, *args)
|
27
|
+
unless model.is_a?(javax.swing.table.TableModel)
|
28
|
+
model = javax.swing.table.DefaultTableModel.new(model, *args)
|
29
|
+
end
|
30
|
+
delegator = DelegatableTableModel.new(model)
|
31
|
+
set_model_without_rubeus(@model = delegator)
|
32
|
+
end
|
33
|
+
|
34
|
+
class DelegatableTableModel
|
35
|
+
# include javax.swing.table.TableModel
|
36
|
+
|
37
|
+
attr_accessor :readonly
|
38
|
+
|
39
|
+
def initialize(source)
|
40
|
+
@source = source
|
41
|
+
end
|
42
|
+
|
43
|
+
def method_missing(method, *args, &block)
|
44
|
+
@source.__send__(method, *args, &block)
|
45
|
+
end
|
46
|
+
|
47
|
+
def isCellEditable(row, col)
|
48
|
+
!readonly
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
Rubeus::Swing.depend_on('AbstractTableModel')
|
2
|
+
|
3
|
+
module Rubeus::Extensions::Javax::Swing::Table
|
4
|
+
module DefaultTableModel
|
5
|
+
def self.included(base)
|
6
|
+
base.module_eval do
|
7
|
+
alias_method :add_row_without_rubeus, :add_row
|
8
|
+
alias_method :add_row, :add_row_with_rubeus
|
9
|
+
alias_method :insert_row_without_rubeus, :insert_row
|
10
|
+
alias_method :insert_row, :insert_row_with_rubeus
|
11
|
+
end
|
12
|
+
base.extend(ClassMethods)
|
13
|
+
base.instance_eval do
|
14
|
+
alias :new_without_rubeus :new
|
15
|
+
alias :new :new_with_rubeus
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
def vectorize_if_array(value)
|
21
|
+
value.is_a?(Array) ? java.util.Vector.new(value) : value
|
22
|
+
end
|
23
|
+
|
24
|
+
def new_with_rubeus(*args)
|
25
|
+
if args.length == 1
|
26
|
+
obj = args.first
|
27
|
+
if obj.is_a?(Array)
|
28
|
+
if obj.first.is_a?(Array)
|
29
|
+
data = vectorize_if_array(obj.map{|row| vectorize_if_array(row)})
|
30
|
+
column_names = vectorize_if_array((1..obj.first.size).entries)
|
31
|
+
return new_without_rubeus(data, column_names)
|
32
|
+
else
|
33
|
+
column_names = vectorize_if_array(obj)
|
34
|
+
return new_without_rubeus(column_names, 0)
|
35
|
+
end
|
36
|
+
elsif obj.is_a?(Hash)
|
37
|
+
options = obj
|
38
|
+
rows = options[:data] || options[:rows]
|
39
|
+
cols = options[:column_names] || options[:columns]
|
40
|
+
if rows.nil? or cols.nil?
|
41
|
+
raise ArgumentError, "DefaultTableModel needs (:data or :rows) and (:column_names or :columns) but options was #{options}"
|
42
|
+
end
|
43
|
+
data = vectorize_if_array(rows.map{|row| vectorize_if_array(row)})
|
44
|
+
column_names = vectorize_if_array(cols)
|
45
|
+
return new_without_rubeus(data, column_names)
|
46
|
+
end
|
47
|
+
elsif (args.length == 2) and (args.first.class.name == 'REXML::Document' and args.last.is_a?(Hash))
|
48
|
+
result = new_without_rubeus
|
49
|
+
result.load_from_xml(*args)
|
50
|
+
return result
|
51
|
+
end
|
52
|
+
return new_without_rubeus(*args)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def vectorize_if_array(value)
|
57
|
+
self.class.vectorize_if_array(value)
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_row_with_rubeus(row)
|
61
|
+
add_row_without_rubeus(vectorize_if_array(row))
|
62
|
+
end
|
63
|
+
|
64
|
+
def insert_row_with_rubeus(index, row)
|
65
|
+
insert_row_without_rubeus(index, vectorize_if_array(row))
|
66
|
+
end
|
67
|
+
|
68
|
+
def load_from_xml(rexml_doc, options = {:refresh_columns => false})
|
69
|
+
row_path = options[:row_path]
|
70
|
+
col_paths = options[:column_paths]
|
71
|
+
if row_path.nil?
|
72
|
+
raise ArgumentError, "require :row_path but options was #{options}"
|
73
|
+
end
|
74
|
+
unless col_paths
|
75
|
+
rexml_doc.elements.each(row_path) do |row|
|
76
|
+
col_paths = row.elements.map{|prop| prop.name}
|
77
|
+
break
|
78
|
+
end
|
79
|
+
end
|
80
|
+
if options[:refresh_columns]
|
81
|
+
self.column_count = 0
|
82
|
+
(options[:column_names] || col_paths).each{|col_name| add_column(col_name)}
|
83
|
+
end
|
84
|
+
self.row_count = 0
|
85
|
+
rexml_doc.elements.each(row_path) do |row|
|
86
|
+
add_row(col_paths.map{|col_path| row.elements[col_path].text})
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/rubeus/swing.rb
CHANGED
@@ -6,7 +6,8 @@ module Rubeus
|
|
6
6
|
class_to_package.update(
|
7
7
|
# $JAVA_HOME/lib/classlistにないものリスト
|
8
8
|
'JTextPane' => 'javax.swing',
|
9
|
-
'RTFEditorKit' => 'javax.swing.text.rtf'
|
9
|
+
'RTFEditorKit' => 'javax.swing.text.rtf',
|
10
|
+
'DefaultTableModel' => 'javax.swing.table'
|
10
11
|
)
|
11
12
|
class_to_package['DefaultStyledDocument'] ||= 'javax.swing.text' # Windowsにない
|
12
13
|
|
metadata
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
extensions: []
|
3
3
|
homepage: http://code.google.com/p/rubeus/
|
4
|
-
executables:
|
4
|
+
executables:
|
5
|
+
- jirb_rubeus
|
6
|
+
- jirb_rubeus.bat
|
5
7
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
8
|
+
version: 0.0.5
|
7
9
|
post_install_message:
|
8
|
-
date: 2008-07-
|
10
|
+
date: 2008-07-28 15:00:00 +00:00
|
9
11
|
files:
|
12
|
+
- bin/jirb_rubeus
|
13
|
+
- bin/jirb_rubeus.bat
|
10
14
|
- lib/rubeus.rb
|
11
15
|
- lib/rubeus/awt.rb
|
12
16
|
- lib/rubeus/component_loader.rb
|
@@ -37,8 +41,10 @@ files:
|
|
37
41
|
- lib/rubeus/extensions/javax/swing/j_panel.rb
|
38
42
|
- lib/rubeus/extensions/javax/swing/j_scroll_pane.rb
|
39
43
|
- lib/rubeus/extensions/javax/swing/j_split_pane.rb
|
44
|
+
- lib/rubeus/extensions/javax/swing/j_table.rb
|
40
45
|
- lib/rubeus/extensions/javax/swing/j_text_field.rb
|
41
46
|
- lib/rubeus/extensions/javax/swing/j_window.rb
|
47
|
+
- lib/rubeus/extensions/javax/swing/table/default_table_model.rb
|
42
48
|
- lib/rubeus/jdbc/closeable_resource.rb
|
43
49
|
- lib/rubeus/jdbc/column.rb
|
44
50
|
- examples/notepad.rb
|
@@ -48,7 +54,7 @@ files:
|
|
48
54
|
- examples/nyanco_viewer/nyanco_viewer_rubeus.rb
|
49
55
|
- examples/notepad.rtf
|
50
56
|
- examples/nyanco_viewer/nekobean_s.png
|
51
|
-
rubygems_version: 1.
|
57
|
+
rubygems_version: 1.2.0
|
52
58
|
rdoc_options: []
|
53
59
|
signing_key:
|
54
60
|
cert_chain: []
|
@@ -56,7 +62,7 @@ name: rubeus
|
|
56
62
|
has_rdoc: false
|
57
63
|
platform: java
|
58
64
|
summary: Rubeus provides you an easy access to Java objects from Ruby scripts on JRuby
|
59
|
-
default_executable:
|
65
|
+
default_executable: jirb_rubeus
|
60
66
|
bindir: bin
|
61
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
68
|
version:
|
@@ -76,6 +82,7 @@ specification_version: 2
|
|
76
82
|
test_files: []
|
77
83
|
dependencies:
|
78
84
|
- !ruby/object:Gem::Dependency
|
85
|
+
type: :runtime
|
79
86
|
name: activesupport
|
80
87
|
version_requirement:
|
81
88
|
version_requirements: !ruby/object:Gem::Requirement
|