|
RE: Apache Batik: msg#00011lang.jruby.user
Hello, Is it best to never use include_package? Yemi Bedu P&R Fasteners 325 Pierce St Somerset, NJ 08873 732-302-3600 -----Original Message----- From: jruby-user-admin@xxxxxxxxxxxxxxxxxxxxx [mailto:jruby-user-admin@xxxxxxxxxxxxxxxxxxxxx] On Behalf Of Thomas E Enebo Sent: Tuesday, February 07, 2006 10:32 AM To: jruby-user@xxxxxxxxxxxxxxxxxxxxx Subject: Re: [Jruby-user] Apache Batik Or more specifically (windows/cygwin -- change export to set for CMD): export CLASSPATH="c:/opt/batik-1.6/lib/batik-swing.jar;c:/opt/batik-1.6/lib/bat ik-svggen.jar;c:/opt/batik-1.6/lib/batik-dom.jar;c:/opt/batik-1.6/lib/ba tik-gui-util.jar;c:/opt/batik-1.6/lib/batik-svg-dom.jar;c:/opt/batik-1.6 /lib/batik-gvt.jar;c:/opt/batik-1.6/lib/batik-ext.jar;c:/opt/batik-1.6/l ib/batik-awt-util.jar;c:/opt/batik-1.6/lib/batik-util.jar;c:/opt/batik-1 .6/lib/batik-css.jar;c:/opt/batik-1.6/lib/batik-xml.jar;c:/opt/batik-1.6 /lib/batik-bridge.jar;c:/opt/batik-1.6/lib/batik-script.jar;c:/opt/batik -1.6/lib/batik-parser.jar;c:/opt/postgresql/postgresql-8.1-404.jdbc3.jar ;." Assumming batik is install in c:/opt/batik-1.6. include_class is faster and more flexible than include_package: 1. include_class can be done in top-level of ruby (rather than only in a non-toplevel namespace) 2. include_package does a class.for_name everytime ruby encounters an unknown constant in the namespace it is included in. This can really degrade performance. I reiterate the tip to use include_class instead of include_package. -Tom PS - Here is some icky code I wrote using batik and Java2D. It is incomplete but it shows some Java integration in it: --dbrenderer.rb-- require 'java' include_class 'java.awt.BasicStroke' include_class 'java.awt.Color' include_class 'java.awt.Font' include_class 'java.awt.Rectangle' include_class 'java.awt.font.TextLayout' include_class 'java.awt.geom.Line2D' include_class 'java.awt.geom.Point2D' include_class 'java.awt.geom.RoundRectangle2D' include_class 'javax.swing.JFrame' include_class 'org.apache.batik.dom.svg.SVGDOMImplementation' include_class 'org.apache.batik.svggen.SVGGraphics2D' include_class 'org.apache.batik.swing.JSVGCanvas' class TableRenderer PADDING = 5 # returns bounds of item rendered def render(m, table, loc) bounds = m.render_string(table.name, loc) x, y = bounds.x + loc.x - PADDING, bounds.y + loc.y - PADDING width = bounds.width + 2 * PADDING line_height = bounds.height + 2 * PADDING r = m.render_round_rectangle(x, y, width, 2 * line_height + 2 * PADDING) m.render_line(x, y + line_height, x + width, y + line_height) r end end class SchemaRenderer PADDING = 50 def initialize @stored_bounds = {} end def render(m, schema, loc) schema.sort.each do |table| b = m.render(table, loc) @stored_bounds[table.name] = b x, y = loc.x + b.width + PADDING, loc.y x, y = 20, loc.y + b.height + PADDING if x > m.width loc = Point2D::Double.new(x, y) end r = get_bounds m.width, m.height = r.width, m.height r end def get_bounds width, height = 0, 0 @stored_bounds.values.each do |b| width = b.x + b.width if b.x + b.width > width height = b.y + b.height if b.y + b.height > height end Rectangle.new(0, 0, width + PADDING, height + PADDING) end end class RenderManager THIN_STROKE = BasicStroke.new(1, BasicStroke::CAP_ROUND, BasicStroke::JOIN_ROUND, 0) THICK_STROKE = BasicStroke.new(3, BasicStroke::CAP_ROUND, BasicStroke::JOIN_ROUND, 0) FONT = Font.decode("Courier-PLAIN-18") attr_reader :g attr_accessor :height, :width def initialize(frame_width=600, frame_height=600) impl = SVGDOMImplementation.getDOMImplementation @doc = impl.createDocument SVGDOMImplementation::SVG_NAMESPACE_URI, "svg", nil @width, @height = frame_width, frame_height @g = SVGGraphics2D.new @doc @g.setPaint(Color.black) @renderers = {} end def set_renderer(type, renderer) @renderers[type] = renderer end def render(renderable, loc = Point2D::Double.new(20, 60)) renderer = @renderers[renderable.class] if renderer.nil? puts "Unable to find renderer for renderable" return end renderer.render(self, renderable, loc) end def render_round_rectangle(x, y, width, height) @g.setStroke(THICK_STROKE) r = RoundRectangle2D::Double.new(x, y, width, height, 10, 10) @g.draw(r) r end def render_string(string, loc) layout = TextLayout.new string, FONT, @g.getFontRenderContext layout.draw @g, loc.x, loc.y layout.bounds end def render_line(x1, y1, x2, y2) @g.setStroke(THIN_STROKE) @g.draw(Line2D::Double.new(x1, y1, x2, y2)) end def finish @g.getRoot @doc.getDocumentElement canvas = JSVGCanvas.new f = JFrame.new f.getContentPane.add canvas canvas.setSVGDocument @doc canvas.setSize(@width, @height) f.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE) f.setSize @width, @height f.setVisible true end end -- On Tue, 07 Feb 2006, Charles O Nutter defenestrated me: > What you probably need to do is actually put the Batik jar files in > the CLASSPATH variable, as in: > > set CLASSPATH=someJar1.jar;someJar2.jar .... etc > > or on a UNIX environment: > > export CLASSPATH=someJar1.jar:someJar2.jar ... etc > > Pointing the classpath at the base directory containing the .java > files does not help because the files have not been compiled. The > compiled files, with a .class extension, are required to execute the > code. Those files are generally contained in the jar files, and so you > need to point your CLASSPATH at the jar files directly. > > If you continue to have issues, please let us know. Sending your > current CLASSPATH might also help. JRuby should be able to load > classes and packages in your classpath sucessfully; it's just a matter > of getting the classpath set right. > > - Charlie > > On 2/7/06, Mark Wong-VanHaren <markwvh@xxxxxxxxx> wrote: > > Hi, folks- > > > > I am attempting to use JRuby to control Apache Batik. > > (The Rasterizer, specifically.) > > > > I am utterly Java-ignorant. The problem I'm encountering > > may well be very simple, just due to my complete Java ignorance. > > Maybe someone more clueful can steer me right? > > > > The JRE (1.5.0_06) works fine; I can run the Batik-rasterizer JAR with it. > > Also, JRuby (0.8.2) works fine; it successfully runs the JRuby sample scripts. > > No problems there. > > > > What I'm ignorant about is how to do is to make JRuby recognize > > Java classes/projects which are *not* part of the standard Java distro. > > > > My jruby script: > > ====== > > require 'java' > > module Foo > > include_package 'org.apache.batik.apps.rasterizer' > > converter = Main.new # Main is a class in Rasterizer > > end > > ====== > > > > Running this (using bin/jruby.rb) produces the following error: > > ===== > > /home/enebo/release/jruby/src/builtin/javasupport.rb:409:in > > `const_missing': uninitialized constant Main at Bobo (NameError) > > from /home/enebo/release/jruby/src/builtin/javasupport.rb:409:in > > `const_missing' > > from svg_rasterizer.rb:4 > > from :0 > > ===== > > > > I presume that means that JRuby doesn't know where to find > > "org.apache.batik.apps.rasterizer"? > > > > For rasterizer, I have both the JAR file and all the .java files. > > > > For the .java files, I set the environment variable CLASSPATH > > to the dir just above "org", hoping that would help it find it, but no luck. > > > > For the .jar file, I've put it everywhere I could think of: in the > > present working directory, in /usr/lib, and I-don't-remember-where-else, > > with the same results. > > > > I would be greatly indebted to anyone who might point me > > in the right direction. > > > > Thanks! > > -Mark > > mark wong-vanharen > > markwvh at gmail dot com > > > > > > ------------------------------------------------------- > > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files > > for problems? Stop! Download the new AJAX search engine that makes > > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > > http://sel.as-us.falkag.net/sel?cmdlnk&kid3432&bid#0486&dat1642 > > _______________________________________________ > > Jruby-user mailing list > > Jruby-user@xxxxxxxxxxxxxxxxxxxxx > > https://lists.sourceforge.net/lists/listinfo/jruby-user > > > > > -- > Charles Oliver Nutter @ headius.blogspot.com > JRuby Developer @ jruby.sourceforge.net > Application Architect @ www.ventera.com > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642 > _______________________________________________ > Jruby-user mailing list > Jruby-user@xxxxxxxxxxxxxxxxxxxxx > https://lists.sourceforge.net/lists/listinfo/jruby-user -- + http://www.tc.umn.edu/~enebo +---- mailto:enebo@xxxxxxx ----+ | Thomas E Enebo, Protagonist | "Luck favors the prepared | | | mind." -Louis Pasteur | ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=k&kid3432&bid#0486&dat1642 _______________________________________________ Jruby-user mailing list Jruby-user@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/jruby-user ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642 |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Apache Batik: 00011, Thomas E Enebo |
|---|---|
| Next by Date: | Re: Apache Batik: 00011, Thomas E Enebo |
| Previous by Thread: | Re: Apache Batiki: 00011, Charles O Nutter |
| Next by Thread: | Re: Apache Batik: 00011, Thomas E Enebo |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |