[Date Prev][Date Next][Index][Thread]
[SGT Mail Archive]
[SGT Main Page]
RE: Creating bitmaps of SGT plots
*************************************************
Message from the sgt mail list.
*************************************************
Thanks again Bob,
The tip about "headless" looks very useful, I'll try that out! I'm sure
that's the simplest way of achieving what I want, thanks.
> You could, if you wanted, write your own class which extends Graphics2D
> and performs all of the operations by manipulating an array of ints
> (each representing a pixel) which can later be converted to an Image.
> But that would be a stunningly huge job -- years of work to do it right.
I didn't quite mean that - rather I meant that, at some point, SGT must be
using Graphics2D to paint stuff onto a Component (or JComponent). Surely it
would be possible simply to get it to paint onto the graphics context of an
Image instead? With the method you gave me (which is quick and neat to
implement) SGT is painting onto a Component, then your method copies the
graphics onto an Image. I just thought we could cut out the middle man and
paint directly to an Image. I wasn't thinking of constructing a bitmap
completely from scratch by manipulating a set of ints.
Regards, Jon
> -----Original Message-----
> From: Bob Simons [mailto:Bob.Simons@noaa.gov]
> Sent: 14 February 2006 16:26
> To: Jon Blower
> Subject: Re: Creating bitmaps of SGT plots
>
>
>
> Jon Blower wrote:
> > *************************************************
> > Message from the sgt mail list.
> > *************************************************
> >
> > Thanks Bob, that's helpful. It's pretty similar to the way I'd hacked
> > together. Unfortunately it still suffers from the disadvantage that
there
> > needs to be an X server running even for "invisible" drawing of the
> > components. This is tricky in my particular setup.
> >
> > I was wondering if someone could point me in the direction of the bits
of
> > code that do the actual construction of the bitmap picture that is
painted
> > on to the components in question? Then I could just adapt these bits of
> > code to paint directly onto an Image. I'm most interested in plotting
2-D
> > grids of data (i.e. SGTGrids).
>
> All SGT calls to draw things ultimately resolve down to the standard
> methods of the Java Graphics and Graphics2D classes. Even painting
> directly to an Image relies on getting the Graphics/Graphics2D object
> from the Image and then calling those methods. Actually, that is what
> SGT does when you pass it the Graphics2D object from an Image.
>
> You could, if you wanted, write your own class which extends Graphics2D
> and performs all of the operations by manipulating an array of ints
> (each representing a pixel) which can later be converted to an Image.
> But that would be a stunningly huge job -- years of work to do it right.
> Getting "headless" to work certainly must be an easier task.
>
> I don't think you need to run an X11 server. Instead, you need to run
> your program "headless". For me to get this to work on a Linux computer
> running Apache and Tomcat (which serves my JSP program), I had to put
> "export JAVA_OPTS=-Djava.awt.headless=true" in
> <TomcatRoot>/bin/startup.sh . Other seemingly reasonable things (e.g.,
> putting
> System.setProperty("java.awt.headless", "true");
> in the constructor for my main class) don't work because of the nature
> of how Tomcat works. See the java.exe documentation for "headless"
> information. It took me a long time to figure this out.
>
> Also, I vaguely remember that some things related to "headless" on
> Linux/Unix changed with Java 1.4 or 1.5. See the change logs as
> java.sun.com or Google to find that info. I certainly recommend 1.5 for
> lots of reasons.
>
> It is unfortunate that Java makes these "headless" operations difficult.
>
> Good luck.
>
> >
> > Thanks,
> > Jon
> >
> >
> >>-----Original Message-----
> >>From: Bob Simons [mailto:Bob.Simons@noaa.gov]
> >>Sent: 13 February 2006 16:21
> >>To: sgt@noaa.gov
> >>Subject: Re: Creating bitmaps of SGT plots
> >>
> >>*************************************************
> >>Message from the sgt mail list.
> >>*************************************************
> >>
> >>I have modified SGT to work as part of a server program and generate
> >>BufferedImages. I hacked the SGT code a little to make this possible.
> >>Here are my notes. I am sorry they are a little terse. I hope they are
> >>helpful.
> >>
> >> To allow using the system in a non-GUI way:
> >> In sgt.Layer.computeScale, I changed
> >> Rectangle bnds = getBounds();
> >> to
> >> Rectangle bnds = pbnds;
> >> In sgt.Pane, I added
> >> class field:
> >> Rectangle bounds;
> >> to constructor:
> >> bounds = new Rectangle(0,0, size.width, size.height);
> >> new method:
> >> public Rectangle getBounds() {
> >> return bounds;
> >> }
> >> In sgt.dm.Collection:
> >> change variable "enum" to "en" to allow use with Java 1.5
> >> Note about SGT coordinates (at different levels):
> >> Graph - uses "user" coordinates (e.g., lat and lon)
> >> Layer - uses "physical" coordinates (doubles, 0,0 at lower left)
> >> JPane - uses "device" coordinates (ints, 0,0 at upper left)
> >> To actually use SGT to draw on a Java Image object,
> >> 1) make a BufferedImage
> >> Get its graphic2D object.
> >> 2) set up SGT
> >> * Create a JPane object
> >> * For each thing plotted:
> >> Create a Graph, placed on a Layer, added to the JPane
> >> 3) call jPane.draw(graphics2D) to actually draw
> >> the graphs you have set up to the buffered image
> >>
> >>
> >>Jon Blower wrote:
> >>
> >>>*************************************************
> >>>Message from the sgt mail list.
> >>>*************************************************
> >>>
> >>>Dear all,
> >>>
> >>>I've been trying to use SGT to create graphics on the fly for a web
> >>>application. I don't want to use a Java applet: I want to create a
> >
> > bitmap
> >
> >>>picture (jpg, gif or png) on the server, then serve this to the client
> >
> > in a
> >
> >>>web page. I note that a very similar thread has been started on this
> >>>mailing list by Leonard Scardino, but there have been no replies.
> >>>
> >>>I have discovered a rather clunky way of achieving this, which involves
> >>>creating the relevant SGT component (e.g. a JPlotLayout) and grabbing
> >
> > its
> >
> >>>graphics using ScreenImage.createImage(JComponent com, String filename)
> >>>(http://www.discoverteenergy.com/files/ScreenImage.java). This works,
> >
> > but
> >
> >>>it has the disadvantage that the graphics are generated in an X server
> >>>off-screen, then grabbed. This means that I need to run an X server on
> >
> > my
> >
> >>>web server, which is not ideal for various local reasons.
> >>>
> >>>It must be possible to draw the graphics in the graphics context of a
> >>>BufferedImage object instead of on a Swing or AWT component. Can this
> >
> > be
> >
> >>>done? I'd be happy to hack away at the SGT code if necessary but I'd
> >
> > like
> >
> >>>some pointers on where to start in the code.
> >>>
> >>>Thanks in advance for any help,
> >>>Jon
> >>>
> >>>--------------------------------------------------------------
> >>>Dr Jon Blower Tel: +44 118 378 5213 (direct line)
> >>>Technical Director Tel: +44 118 378 8741 (ESSC)
> >>>Reading e-Science Centre Fax: +44 118 378 6413
> >>>ESSC Email: jdb@mail.nerc-essc.ac.uk
> >>>University of Reading
> >>>3 Earley Gate
> >>>Reading RG6 6AL, UK
> >>>--------------------------------------------------------------
> >>>
> >>>
> >>>
> >>>
> >>>*************************************************
> >>>To remove yourself from this mailing list,
> >>>send mail to <epic-majordomo@noaa.gov> with
> >>>"unsubscribe sgt" in the message body.
> >>>==========
> >>
> >>
> >>Sincerely,
> >>
> >>Bob Simons
> >>Satellite Data Product Manager
> >>Environmental Research Division
> >>NOAA Southwest Fisheries Science Center
> >>1352 Lighthouse Ave
> >>Pacific Grove, CA 93950-2079
> >>(831)658-3205
> >>bob.simons@noaa.gov
> >><>< <>< <>< <>< <>< <>< <>< <>< <><
> >>
> >>*************************************************
> >>To remove yourself from this mailing list,
> >>send mail to <epic-majordomo@noaa.gov> with
> >>"unsubscribe sgt" in the message body.
> >>==========
> >
> >
> >
> > *************************************************
> > To remove yourself from this mailing list,
> > send mail to <epic-majordomo@noaa.gov> with
> > "unsubscribe sgt" in the message body.
> > ==========
>
> --
> Sincerely,
>
> Bob Simons
> Satellite Data Product Manager
> Environmental Research Division
> NOAA Southwest Fisheries Science Center
> 1352 Lighthouse Ave
> Pacific Grove, CA 93950-2079
> (831)658-3205
> bob.simons@noaa.gov
> <>< <>< <>< <>< <>< <>< <>< <>< <><
*************************************************
To remove yourself from this mailing list,
send mail to <epic-majordomo@noaa.gov> with
"unsubscribe sgt" in the message body.
==========
Privacy Notice,
External Links Disclaimer.