rubeus 0.0.5-java → 0.0.6-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ require 'java'
2
+ require 'rubygems'
3
+ require 'rubeus'
4
+
5
+ def setup_derby
6
+ return if ENV_JAVA['java.class.path'].split(File::PATH_SEPARATOR).any?{|path| /derby[\-\.\d]*\.jar$/ =~ path}
7
+ if ENV_JAVA["java.specification.version"] == "1.6"
8
+ begin
9
+ require File.join(ENV_JAVA['java.home'], 'db', 'lib', 'derby.jar')
10
+ return
11
+ rescue LoadError
12
+ # ignore error if not installed JavaDB
13
+ # Apple's JDK doesn't include Apache Derby
14
+ end
15
+ end
16
+ puts "JavaDB is not installed."
17
+ puts "Please add derby.jar to your CLASSPATH."
18
+ end
19
+
20
+ setup_derby
21
+
22
+ class JdbcExample
23
+ include Rubeus::Jdbc
24
+
25
+ def initialize
26
+ # Register Driver
27
+ Java::OrgApacheDerbyJdbc::EmbeddedDriver
28
+ end
29
+
30
+ def test
31
+ DriverManager.connect("jdbc:derby:test;create = true", "", "") do |con|
32
+ con.statement do |stmt|
33
+ # Drop table TEST if exists
34
+ begin
35
+ stmt.execute_update("DROP TABLE TEST")
36
+ rescue
37
+ # ignore error if table not exist
38
+ end
39
+
40
+ # Setup table and data
41
+ stmt.execute_update("CREATE TABLE TEST(id int, data char(10))")
42
+ stmt.execute_update("INSERT INTO TEST VALUES(1, 'first')")
43
+ stmt.execute_update("INSERT INTO TEST VALUES(2, 'second')")
44
+
45
+ # Query
46
+ stmt.query("SELECT * FROM TEST") do |rs|
47
+ rs.each do |rsNext|
48
+ print "|", rsNext.getInt("ID"), "|", rsNext.getString("DATA"), "|\n"
49
+ end
50
+ end
51
+
52
+ # Query by each_array
53
+ stmt.query("SELECT * FROM TEST") do |rs|
54
+ rs.each_array do |rsNext|
55
+ print "|", rsNext[0], "|", rsNext[1], "|\n"
56
+ end
57
+ end
58
+
59
+ # Connection#query by each_hash
60
+ con.query("SELECT * FROM TEST") do |rs|
61
+ rs.each_hash do |rsNext|
62
+ print "|", rsNext["ID"], "|", rsNext["DATA"], "|\n"
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ JdbcExample.new.test
@@ -24,8 +24,24 @@ class NyancoDispLabel < javax.swing.JLabel
24
24
  include DD
25
25
  def drop(e)
26
26
  e.accept_drop java.awt.dnd.DnDConstants::ACTION_COPY_OR_MOVE
27
+
28
+ # Supported Flavors
27
29
  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
+ string_flavor = java.awt.datatransfer.DataFlavor.stringFlavor
31
+ uri_flavor = java.awt.datatransfer.DataFlavor.new("text/uri-list;class=java.lang.String")
32
+
33
+ if e.transferable.isDataFlavorSupported(java_file_list_flavor)
34
+ image_path = e.transferable.get_transfer_data(java_file_list_flavor)[0].absolute_path
35
+ elsif e.transferable.isDataFlavorSupported(string_flavor)
36
+ image_path = java.net.URL.new(e.transferable.get_transfer_data(string_flavor).split("\r\n")[0])
37
+ elsif e.transferable.isDataFlavorSupported(uri_flavor)
38
+ image_path = java.net.URL.new(e.transferable.get_transfer_data(uri_flavor).split("\r\n")[0])
39
+ else
40
+ # Unsupported data
41
+ end
42
+
43
+ if image_path
44
+ self.icon = javax.swing.ImageIcon.new(image_path)
45
+ end
30
46
  end
31
47
  end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'rubeus'
3
+
4
+ Rubeus::Swing.irb
5
+
6
+ JFrame.new do |frame|
7
+ label = JLabel.new
8
+
9
+ t = Timer.new(500) do
10
+ label.text = Time.now.to_s
11
+ end
12
+ t.start
13
+
14
+ frame.title = "Rubeus Timer Example"
15
+ frame.size = "250 x 50"
16
+ frame.visible = true
17
+ end
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'rubeus'
3
+
4
+ class JTabbedPaneExample
5
+ include Rubeus::Swing
6
+
7
+ def initialize
8
+ JFrame.new(:title => 'JTabbedPane Example') do |f|
9
+ tp = JTabbedPane.new(:LEFT, :SCROLL_TAB_LAYOUT) do |tp|
10
+ # tab #1
11
+ JSplitPane.new(:HORIZONTAL_SPLIT) do
12
+ JButton.new("button") do
13
+ javax.swing.JOptionPane.showMessageDialog(f, "button pushed!")
14
+ tp.set_selected_index(1)
15
+ end
16
+ JLabel.new("<- Push this button.")
17
+ end
18
+
19
+ # tab #2
20
+ JPanel.new do |p|
21
+ p.layout = BoxLayout.new(:Y_AXIS)
22
+ JLabel.new("Notepad")
23
+ JTextArea.new
24
+ end
25
+
26
+ # tab #3
27
+ jl = JLabel.new("This is a JTabbedPane Example.")
28
+
29
+ # tab settings
30
+ tp.set_titles(['First tab', 'Second Tab'])
31
+ tp.set_icons(['', '', 'nyanco_viewer/nekobean_s.png'])
32
+ tp.set_tips((1..3).to_a.map { |num| "tip#{num}" })
33
+ end
34
+
35
+ f.visible = true
36
+ end
37
+ end
38
+ end
39
+
40
+ JTabbedPaneExample.new
@@ -4,10 +4,10 @@ gem "activesupport", ">=2.0.2"
4
4
  require "active_support/core_ext/string"
5
5
 
6
6
  module Rubeus
7
- VERSION = "0.0.5"
7
+ VERSION = "0.0.6"
8
8
  autoload :Awt, "rubeus/awt"
9
9
  autoload :Swing, "rubeus/swing"
10
- # autoload :Jdbc, "rubeus/jdbc"
10
+ autoload :Jdbc, "rubeus/jdbc"
11
11
  end
12
12
 
13
13
  unless File.basename($PROGRAM_NAME) == 'gem' and ARGV.first == 'build'
@@ -54,7 +54,7 @@ module Rubeus::Awt
54
54
  return object
55
55
  end
56
56
 
57
- def constianer?
57
+ def container?
58
58
  Context.container_class_names.include?(self.java_class.name)
59
59
  end
60
60
 
@@ -67,7 +67,7 @@ module Rubeus::Awt
67
67
  end
68
68
 
69
69
  def process_block_for_new(object, &block)
70
- if self.constianer?
70
+ if self.container?
71
71
  self.add_new_component_to(object, &block)
72
72
  elsif object.respond_to?(:listen)
73
73
  object.listen(*self.default_event_type, &block)
@@ -1,5 +1,6 @@
1
1
  module Rubeus::Extensions
2
2
  module Java
3
3
  autoload :Awt, 'rubeus/extensions/java/awt'
4
+ autoload :Sql, 'rubeus/extensions/java/sql'
4
5
  end
5
6
  end
@@ -1,3 +1,5 @@
1
+ Rubeus::Jdbc.depend_on("Statement")
2
+
1
3
  module Rubeus::Extensions::Java::Sql
2
4
  module Connection
3
5
  include Rubeus::Jdbc::CloseableResource
@@ -1,9 +1,16 @@
1
+ Rubeus::Jdbc.depend_on("Connection")
2
+
1
3
  module Rubeus::Extensions::Java::Sql
2
4
  module DriverManager
3
- extend Rubeus::Jdbc::CloseableResource
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ base.extend Rubeus::Jdbc::CloseableResource
8
+ end
4
9
 
5
- def connect(url, user, password, &block)
6
- with_close(get_connection(url, user, password), &block)
10
+ module ClassMethods
11
+ def connect(url, user, password, &block)
12
+ with_close(get_connection(url, user, password), &block)
13
+ end
7
14
  end
8
15
  end
9
16
  end
@@ -1,3 +1,5 @@
1
+ Rubeus::Jdbc.depend_on("ResultSetMetaData")
2
+
1
3
  module Rubeus::Extensions::Java::Sql
2
4
  module ResultSet
3
5
  include Enumerable
@@ -18,6 +18,10 @@ module Rubeus::Extensions::Java::Sql
18
18
  dest
19
19
  end
20
20
  end
21
+
22
+ def column_index(i)
23
+ i
24
+ end
21
25
 
22
26
  private
23
27
  def build_columns
@@ -1,3 +1,5 @@
1
+ Rubeus::Jdbc.depend_on("ResultSet")
2
+
1
3
  module Rubeus::Extensions::Java::Sql
2
4
  module Statement
3
5
  include Rubeus::Jdbc::CloseableResource
@@ -0,0 +1,62 @@
1
+ Rubeus::Swing.depend_on("JComponent")
2
+
3
+ module Rubeus::Extensions::Javax::Swing
4
+ module JTabbedPane
5
+ def self.included(base)
6
+ base.perform_as_container
7
+ base.extend(ClassMethods)
8
+ base.instance_eval do
9
+ alias :new_without_rubeus :new
10
+ alias :new :new_with_rubeus
11
+ end
12
+ end
13
+
14
+ module ClassMethods
15
+ def new_with_rubeus(*args, &block)
16
+ # Convert to constant value if symbol is designated
17
+ new_args = args.map do |arg|
18
+ if arg.is_a?(Symbol)
19
+ const_get(arg)
20
+ else
21
+ arg
22
+ end
23
+ end
24
+
25
+ new_without_rubeus(*new_args, &block)
26
+ end
27
+ end
28
+
29
+ # set_title_at utility
30
+ def set_titles(arr)
31
+ tab_setting(arr, :set_title_at)
32
+ end
33
+
34
+ # set_icon_at utility
35
+ def set_icons(arr)
36
+ tab_setting(arr, :set_image_icon_at)
37
+ end
38
+
39
+ # alias for set_icon_at set image_path_string instread
40
+ def set_image_icon_at(index, image_path)
41
+ if image_path && java.io.File.new(image_path).exists
42
+ image_icon = javax.swing.ImageIcon.new(image_path)
43
+ set_icon_at(index, image_icon)
44
+ end
45
+ end
46
+
47
+ # set_tool_tip_text_at utility
48
+ def set_tips(arr)
49
+ tab_setting(arr, :set_tool_tip_text_at)
50
+ end
51
+
52
+ private
53
+ def tab_setting(arr, method_name)
54
+ self.tab_count.times do |i|
55
+ if arr.length > i
56
+ self.send(method_name, i, arr[i])
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
@@ -45,7 +45,7 @@ module Rubeus::Extensions::Javax::Swing::Table
45
45
  return new_without_rubeus(data, column_names)
46
46
  end
47
47
  elsif (args.length == 2) and (args.first.class.name == 'REXML::Document' and args.last.is_a?(Hash))
48
- result = new_without_rubeus
48
+ result = new_without_rubeus(vectorize_if_array(args.last[:column_paths]), 0)
49
49
  result.load_from_xml(*args)
50
50
  return result
51
51
  end
@@ -83,7 +83,13 @@ module Rubeus::Extensions::Javax::Swing::Table
83
83
  end
84
84
  self.row_count = 0
85
85
  rexml_doc.elements.each(row_path) do |row|
86
- add_row(col_paths.map{|col_path| row.elements[col_path].text})
86
+ values = col_paths.map do |col_path|
87
+ element = row.elements[col_path]
88
+ element ? element.text :
89
+ options[:ignore_unexist_column] ? nil :
90
+ (raise ArgumentError, "column '#{col_path}' not found.")
91
+ end
92
+ add_row(values)
87
93
  end
88
94
  end
89
95
  end
@@ -0,0 +1,26 @@
1
+ module Rubeus::Extensions::Javax::Swing
2
+ module Timer
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ base.instance_eval do
6
+ alias :new_without_rubeus :new
7
+ alias :new :new_with_rubeus
8
+ end
9
+ end
10
+
11
+ module ClassMethods
12
+ def new_with_rubeus(interval, &block)
13
+ # Create ActionListener implement class
14
+ mod = Module.new do
15
+ define_method("actionPerformed", &block)
16
+ end
17
+
18
+ obj = Object.new
19
+ obj.extend(mod)
20
+
21
+ # Use original constructor
22
+ new_without_rubeus(interval, obj)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,17 @@
1
+ require "rubeus/component_loader"
2
+
1
3
  module Rubeus
2
- module Jdbc
3
- autoload :CloseableResource, 'rubeus/jdbc/closeable_resource'
4
- autoload :Column, 'rubeus/jdbc/column'
4
+ Jdbc = ComponentLoader.new("java.sql") do
5
+ class_to_package.update(
6
+ # $JAVA_HOME/lib/classlistにないものリスト
7
+ 'Connection' => 'java.sql',
8
+ 'DriverManager' => 'java.sql',
9
+ 'ResultSet' => 'java.sql',
10
+ 'ResultSetMetaData' => 'java.sql',
11
+ 'Statement' => 'java.sql'
12
+ )
5
13
  end
6
14
  end
15
+
16
+ require "rubeus/jdbc/closeable_resource"
17
+ require "rubeus/jdbc/column"
@@ -9,7 +9,7 @@ module Rubeus::Jdbc
9
9
  :column_label , # String # 印刷や表示に使用する、指定された列の推奨タイトルを取得します。
10
10
  :column_name , # String # 指定された列の名前を取得します。
11
11
  :column_type , # int # 指定された列の SQL 型を取得します。
12
- :column_typeName , # String # 指定された列のデータベース固有の型名を取得します。
12
+ :column_type_name , # String # 指定された列のデータベース固有の型名を取得します。
13
13
  :precision , # int # 指定された列の 10 進桁数を取得します。
14
14
  :scale , # int # 指定された列の小数点以下の桁数を取得します。
15
15
  :schema_name , # String # 指定された列のテーブルのスキーマを取得します。
@@ -18,7 +18,7 @@ module Rubeus::Jdbc
18
18
  :case_sensitive , # boolean # 列の大文字と小文字が区別されるかどうかを示します。
19
19
  :currency , # boolean # 指定された列がキャッシュの値かどうかを示します。
20
20
  :definitely_writable, # boolean # 指定された列の書き込みが必ず成功するかどうかを示します。
21
- :nullable , # int # 指定された列に NULL をセットできるかどうかを示します。
21
+ :is_nullable , # int # 指定された列に NULL をセットできるかどうかを示します。
22
22
  :read_only , # boolean # 指定された列が絶対的に書き込み可能でないかどうかを示します。
23
23
  :searchable , # boolean # 指定された列を where 節で使用できるかどうかを示します。
24
24
  :signed , # boolean # 指定された列の値が符号付き数値かどうかを示します。
metadata CHANGED
@@ -5,9 +5,9 @@ executables:
5
5
  - jirb_rubeus
6
6
  - jirb_rubeus.bat
7
7
  version: !ruby/object:Gem::Version
8
- version: 0.0.5
8
+ version: 0.0.6
9
9
  post_install_message:
10
- date: 2008-07-28 15:00:00 +00:00
10
+ date: 2008-08-31 15:00:00 +00:00
11
11
  files:
12
12
  - bin/jirb_rubeus
13
13
  - bin/jirb_rubeus.bat
@@ -41,15 +41,20 @@ files:
41
41
  - lib/rubeus/extensions/javax/swing/j_panel.rb
42
42
  - lib/rubeus/extensions/javax/swing/j_scroll_pane.rb
43
43
  - lib/rubeus/extensions/javax/swing/j_split_pane.rb
44
+ - lib/rubeus/extensions/javax/swing/j_tabbed_pane.rb
44
45
  - lib/rubeus/extensions/javax/swing/j_table.rb
45
46
  - lib/rubeus/extensions/javax/swing/j_text_field.rb
46
47
  - lib/rubeus/extensions/javax/swing/j_window.rb
48
+ - lib/rubeus/extensions/javax/swing/timer.rb
47
49
  - lib/rubeus/extensions/javax/swing/table/default_table_model.rb
48
50
  - lib/rubeus/jdbc/closeable_resource.rb
49
51
  - lib/rubeus/jdbc/column.rb
52
+ - examples/jdbc_example.rb
50
53
  - examples/notepad.rb
51
54
  - examples/rubeus_swing_example01.rb
52
55
  - examples/rubeus_swing_example01_with_class.rb
56
+ - examples/rubeus_swing_example02.rb
57
+ - examples/rubeus_swing_example03.rb
53
58
  - examples/nyanco_viewer/nyanco_disp_label.rb
54
59
  - examples/nyanco_viewer/nyanco_viewer_rubeus.rb
55
60
  - examples/notepad.rtf