ObjectWeb Consortium
Search ObjectWeb Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | enhydra List | September 2000 Index

<--  Date Index  --> <--  Thread Index  -->

Re: AW: Enhydra: Dynamic graphics in your page : SOLUTION


Le lun, 25 sep 2000, vous avez écrit :

Hi, 


Here is why I succeed to provide dynamic images directly in my pages. My 
example
is based on the model handleXXX where XXX is the name of the event provided in
the URL parameter like it's used in the GolfShop Demo.

First, in your HTML, you'll write something like :

<IMG SRC="http://www.agisphere.com/myapp/Page.po?display=diagramme";>

You call a PO of your application which will display a "diagramme".

To implement this, you first need to add in your BasePO the following lines :

   private static String DISPLAY  = "display";
   private static String DISPLAY_METHOD_PREFIX  = "display";
...

in the method handleEvent ( cf the GolfShop Demo ) :

        String display = "";
        try {
            display = request.getParameter( DISPLAY );
        } catch ( HttpPresentationException e ) {}       

        if ( display != null && !display.equals("") )
            {
        
                    writeDebugMsg( "---- On est rentre dans le display de 
l'image");
                    Image img = getImageFromDisplay( display );
                        
                    writeDebugMsg( "image recuperee = " + img);
                    
                    GifEncoder gif = new GifEncoder( img, 
(OutputStream)response.getOutputStream() );               
                    gif.encode();

                    response.setContentType( "image/gif" );
                    response.flush();           
                   
                    writeDebugMsg("tt");
        
                return;
            }

 /**
     * If an event parameter is defined then this invokes the method that
     * handles that event.
     */   
    public Image getImageFromDisplay(String display) 
        throws HttpPresentationException, InvocationTargetException
        {            
            try {
                Class thisPO = this.getClass();
                Method method = thisPO.getMethod(toMethodName( 
DISPLAY_METHOD_PREFIX, display ), null);      
                Image theImage = (Image)method.invoke(this, null);
                return theImage;
            } catch(InvocationTargetException ex) {
                // Rethrow the originating exception if as it should be 
propagated as is
                // It could be a page redirect exception, etc.
                if (ex.getTargetException() instanceof Exception) {
                    throw new HttpPresentationException("Erreur lors de 
l'invocation de la méthode: " + ex.getTargetException());
                } else if (ex.getTargetException() instanceof Error) {
                    throw (Error)ex.getTargetException();
                } else { throw ex; }
            } catch(NoSuchMethodException ex) {
                //The method to handle the event does not exist.
                throw new HttpPresentationException("NO EVENT HANDLER FOUND 
FOR DISPLAY: " + display, ex);           
            } catch(IllegalAccessException ex) {
                //The method to handle the event does not exist.
                throw new HttpPresentationException("ILLEGAL ACCESS TO 
DISPLAY HANDLER (is it public?): " + display, ex);           
            } 
        }

 /**
     * This sets the first letter of the event parameter value in order
     * to adhere to Java method naming conventions.
     * 
     * @param String event the incoming name of the event
     * @return String the properly capitalized name
     */   
    private String toMethodName(String prefix, String event) 
        {
            StringBuffer methodName = new StringBuffer( prefix );
            methodName.append(Character.toUpperCase(event.charAt(0)));
      
            if (event.length() > 1) {
                methodName.append(event.substring(1));
            }
            
            return methodName.toString();   
        }      


Fine !

Now, it's very easy to provide the image like in my page, I added a method
displayXXX where XXX is the parameter value for "display". For example :

  public Image displayDiagramme()
    {   
        try {
            this.missionSelected = myComms.request.getParameter( 
"missionSelect" );
            this.weekSelected = myComms.request.getParameter( "weekSelect" );
        } catch(HttpPresentationException e){ 
            writeDebugMsg( "Erreur lors de la récupération des paramètres" );
            return null;
        }

        writeDebugMsg("fvaeoladvlma");

        ajouteLogTimestamp( "Avant de créer l'image");    

        BufferedImage bi = new BufferedImage( 
650,100,BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = bi.createGraphics();

        ajouteLogTimestamp( "Avant de créer l'image");  
        g2d.draw(new Rectangle(20,20,60,60));

        return (Image)bi;
    }    


You should notice that in BasePO.java, I'm using a GIFEncoder which is not a
part of the JDK nor Enhydra. Indeed, the problem is to put the image in the
OutputStream. This depends of the format of the image ( GIF, JPEG, PNG, ... )
and there are plenty of APIs. Maybe you'll prefer another one. Tell me your
arguments !

Hope it helps !






> Hi!
> 
> did some dynamic image creation a while back using plain servlets.
> Maybe the follwoing snippet helps:
> 
> (Note: this is just a snippet, not sure if it will run exactly like this, 
> but it should get the idea across, and give some pointers
> which api calls to look at.
> It displays the value of the get-paramter named text in a box.)
> 
> HTH
> 
> -markus
> 
> P.S. Let me know if you succeed.
> ------------------------------------------------------------------
> 
> import java.awt.image.*;
> import java.awt.*;
> import com.sun.image.codec.jpeg.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.io.*;
> import java.util.*;
> 
> public class GraphServlet extends HttpServlet {
> //Initialize global variables
> 
>   public void init(ServletConfig config) throws ServletException {
>     super.init(config);
>     
> GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
>   }
> //Process the HTTP Get request
> 
>   public void doGet(HttpServletRequest request, HttpServletResponse 
> response) throws ServletException, IOException {
>     response.setContentType("image/jpeg");
>     int w = 300;
>     int h = 100;
>     int pix[] = new int[w * h];
>     BufferedImage mImage =  new BufferedImage(w, h, 
> BufferedImage.TYPE_INT_RGB);
>     Graphics2D mGraphics = mImage.createGraphics();
>     mGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
> RenderingHints.VALUE_ANTIALIAS_ON);
>     mGraphics.setRenderingHint(RenderingHints.KEY_RENDERING, 
> RenderingHints.VALUE_RENDER_QUALITY);
>     mGraphics.setColor(Color.white);
>     mGraphics.fillRect(0, 0, w, h);
>     mGraphics.setColor(Color.black);
>     mGraphics.setFont(new Font("Frutiger Italic", Font.PLAIN, 36));
>     
> mGraphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
> 0.5f));
>     mGraphics.drawString(request.getParameter("text"), 0, h - 10);
>     JPEGImageEncoder encoder =
>       JPEGCodec.createJPEGEncoder(response.getOutputStream());
>     JPEGEncodeParam param =
>       encoder.getDefaultJPEGEncodeParam(mImage);
>     param.setQuality(0.75f,true);
>     encoder.encode(mImage,param);
>     // mEnc.encode();
>     st.disconnect();
>   }
> //Get Servlet information
> 
>   public String getServletInfo() {
>     return "graph.GraphServlet Information";
>   }
> }
> 
> -------------------------------------
> 
> > -----Ursprüngliche Nachricht-----
> > Von: owner-enhydra@xxxxxxxxxxx [mailto:owner-enhydra@xxxxxxxxxxx]Im
> > Auftrag von Laurent Roméo
> > Gesendet: Montag, 25. September 2000 17:23
> > An: enhydra@xxxxxxxxxxx
> > Betreff: Re: Enhydra: Dynamic graphics in your page
> >
> >
> > Le lun, 25 sep 2000, vous avez écrit :
> > > Laurent,
> > >     I am doing something similar in my application.  It involves 
> > > displaying a
> > > large stack of images in a jpeg format.  (30 -40 images @ 40 KB each)
> > >
> > > This is done in a few steps.
> > >
> > > 1.  Create a temporary folder that is accessible via apache based on 
> > > the name of
> > > the session (24 characters of giberish )
> >
> > NO !!!
> >
> > It is exactly what I want to avoid....
> >
> > I'm currently working, I'll tell you if I succeed.
> >
> > > 2.  Convert the images from raw data to jpegs named img0, img1, img2 ...
> > > 3.  Have a PO that calls an applet to view these images.  (I use an 
> > > applet
> > > because it is necessary to be able to adjust contrast on my images... 
> > > to locate
> > > the images, i just change a parameter in the PO that calls the applet.)
> > > 4.  The applet then downloads the 40 or so jpegs via http from
> > > myserver.com/output/<sessionname>/imgN.jpg into a vector.
> > > 5.  Then the applet is used to flip through the images
> > > 6.  I haven't done this part yet, but: On stop() or destroy() the 
> > > applet calls
> > > its loader with the event being "done", at which point the po calls 
> > > some code to
> > > remove that temporary file with the 40 jpegs in it.
> > >
> > >     The biggest problem with the design (i think) is the temporary 
> > > folder.  If
> > > the applet fails to send over that it is done, i end up with a bunch of 
> > > files
> > > cluttering up my server.  This means possibly using some sort of timer 
> > > to delete
> > > them.
> > >
> > > I am also interested in hearing any ideas on how else one might create 
> > > and
> > > display dynamic images in Enhydra.
> > >
> > > Regards,
> > > Ben
> > >
> > >
> > >
> > > "Laurent Roméo" wrote:
> > >
> > > > Hi,
> > > >
> > > > I would like to do one thing, but before diving inside all the APIs, 
> > > > I would
> > > > like to test if anybody has already experienced it...
> > > >
> > > > My problem is to generate a dynamic graphic from a template one. That 
> > > > could be
> > > > the case if you want to display chart or every kind of statistics.
> > > >
> > > > I want to integrate it in my page using a tag like :
> > > >
> > > > <img src="http://www.mydomain.com/app/Dynamicgraphics.po>
> > > >
> > > > Doing so, it could be possible to integrate this graphics inside my 
> > > > page where
> > > > I put every kind of comments.
> > > >
> > > > My idea is to use an API like Java2D ( maybe another one is better), 
> > > > and to
> > > > return a MIME TPYE appropriated.
> > > >
> > > > Any examples ?
> > > >
> > > > --
> > > >
> > > >   Cordialement,
> > > >
> > > > Laurent ROMEO
> > > > -------------
> > > >
> > > > Directeur R&D
> > > > AGISphere S.A.
> > > >
> > > > http://www.agisphere.com/
> > > >
> > > > laurent.romeo@xxxxxxxxxxxxx
> > > >
> > > > 01.47.45.99.92
> > > > 06.88.08.49.50
> > > >
> > > > -----------------------------------------------------------------------------
> > > > To unsubscribe from this mailing list, send email to 
> > > > majordomo@xxxxxxxxxxx
> > > > with the text "unsubscribe enhydra" in the body of the email.
> > > > If you have other questions regarding this mailing list, send email to
> > > > the list admin at owner-enhydra@xxxxxxxxxxxx
> > >
> > > -----------------------------------------------------------------------------
> > > To unsubscribe from this mailing list, send email to 
> > > majordomo@xxxxxxxxxxx
> > > with the text "unsubscribe enhydra" in the body of the email.
> > > If you have other questions regarding this mailing list, send email to
> > > the list admin at owner-enhydra@xxxxxxxxxxxx
> > --
> >
> >   Cordialement,
> >
> > Laurent ROMEO
> > -------------
> >
> > Directeur R&D
> > AGISphere S.A.
> >
> > http://www.agisphere.com/
> >
> > laurent.romeo@xxxxxxxxxxxxx
> >
> > 01.47.45.99.92
> > 06.88.08.49.50
> >
> > -----------------------------------------------------------------------------
> > To unsubscribe from this mailing list, send email to majordomo@xxxxxxxxxxx
> > with the text "unsubscribe enhydra" in the body of the email.
> > If you have other questions regarding this mailing list, send email to
> > the list admin at owner-enhydra@xxxxxxxxxxxx
> >
> 
> -----------------------------------------------------------------------------
> To unsubscribe from this mailing list, send email to majordomo@xxxxxxxxxxx
> with the text "unsubscribe enhydra" in the body of the email.
> If you have other questions regarding this mailing list, send email to
> the list admin at owner-enhydra@xxxxxxxxxxxx
-- 

  Cordialement,

Laurent ROMEO
-------------

Directeur R&D
AGISphere S.A.

http://www.agisphere.com/

laurent.romeo@xxxxxxxxxxxxx

01.47.45.99.92
06.88.08.49.50

-----------------------------------------------------------------------------
To unsubscribe from this mailing list, send email to majordomo@xxxxxxxxxxx
with the text "unsubscribe enhydra" in the body of the email.
If you have other questions regarding this mailing list, send email to
the list admin at owner-enhydra@xxxxxxxxxxxx




<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 1999-2005, ObjectWeb Consortium | contact | webmaster.