Overblog
Suivre ce blog
Editer l'article Administration Créer mon blog
4 avril 2006 2 04 /04 /avril /2006 14:48

Purpose

This is a JavaBean that allows to handle a "HTML Map" in a Forms application.

Map


The Java code

      MapComponent.java      zone.java


The Implementation Class property

      oracle.forms.fd.MapComponent


The properties you can set

Set a polygonal area

Set_Custom_Property('BL.BEAN',1, 'SETPOLYGON','name,url,coordinates_pairs');

e.g.
Set_Custom_Property('BL.BEAN',1, 'SETPOLYGON','Region1,url1,284,128,272,353,178,361,166,342,133');

Set a rectangular area

Set_Custom_Property('BL.BEAN',1, 'SETRECT','name,url,x,y,width,height');

name is the name that identify each area. this name is get from the GetProperty(NAME)
url is the area url (must be specified but not used in this version)

Set the background image

Set_Custom_Property('BL.BEAN',1, 'SETIMAGE','image_name' );

Image from JAR file:
Set_Custom_Property('BL.BEAN',1, 'SETIMAGE','/france.jpg' );

Image from client machine:
Set_Custom_Property('BL.BEAN',1, 'SETIMAGE','file:///d:/france.jpg' );

Image from internet url:
Set_Custom_Property('BL.BEAN',1, 'SETIMAGE','http://fdtool.free.fr/tmp/france.jpg' );


Set the selected area color


Set_Custom_Property('BL.BEAN',1, 'SETFONTCOLOR','r,g,b' );

Set_Custom_Property('BL.BEAN',1, 'SETFONTCOLOR','255,0,100' );


The properties you can get

The area selected (clicked)

Varchar2 := Get_Custom_Property('BL.BEAN',1, 'NAME');


The events you can raise

An area has been clicked

      ZONECLICKED



The sample dialog


     . Download the map.zip file
     . Unzip the file
     . copy the fjmap.jar file in the <ORACLE_HOME>/forms/java directory
            the jar file must be signed
     . Edit your /forms/server/formsweb.cfg file
     . Open the MAP.fmb module (Oracle Forms 9.0.2)
     . Compile all and run the module


Different display of the selected area


You can "tune" the display()
  function to change the display of the selected area:

Map


 /*************************************
  *  Show/Hide the selected map part  *
  ************************************/

 void display(int iNum, boolean b) {
  float fArea = 0.1f, fText = 0.9f;
  g2 = (Graphics2D) this.getGraphics();
  String sName="" ;
  if(g2 != null && iNum >= 0)
  {
    g2.setColor(Color.white);
    g2.clearRect((int)jp.getX(),(int)jp.getY(),(int)jp.getWidth(),(int)jp.getHeight());
    image.paintIcon(null,g2,0,0);
    if(b)
    {
      // draw the selected area
      g2.setComposite(AlphaComposite.SrcOver);
      AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, fArea);
      g2.setComposite(ac);

      g2.setColor(cFontColor);
      g2.fillPolygon(tz[iNum].p);
      ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, fText);
      g2.setComposite(ac);

      g2.setColor(Color.black);
      sName = tz[iNum].name ;
     
      Font font = new Font("Arial",Font.BOLD,14);
      FontRenderContext frc = g2.getFontRenderContext();
      TextLayout layout = new TextLayout(tz[iNum].name, font, frc);
      Rectangle2D bounds = layout.getBounds();
      // draw the text bouding box
      g2.drawRect((int)((tz[iNum].r.getX()+(tz[iNum].r.getWidth()/2))-2),
                  (int)((tz[iNum].r.getY()+(tz[iNum].r.getHeight()/2))-(int)bounds.getHeight()),
                  (int)(bounds.getWidth()+4),
                  (int)(bounds.getHeight()+4));
      g2.setColor(Color.white);
      g2.fillRect((int)((tz[iNum].r.getX()+(tz[iNum].r.getWidth()/2))-2),
                  (int)((tz[iNum].r.getY()+(tz[iNum].r.getHeight()/2))-(int)bounds.getHeight()),
                  (int)(bounds.getWidth()+4),
                  (int)(bounds.getHeight()+4));
      g2.setColor(cFontColor);     
      g2.setFont(font);
      g2.drawString(tz[iNum].name,
      (int)(tz[iNum].r.getX()+(tz[iNum].r.getWidth()/2)),
      (int)(tz[iNum].r.getY()+(tz[iNum].r.getHeight()/2)));
    }
  }
 }

Partager cet article

Published by Oracle Forms community - dans Bean - general
commenter cet article

commentaires