Suivre ce blog
Editer l'article Administration Créer mon blog
10 décembre 2006 7 10 /12 /décembre /2006 15:39


Here is a Java bean that allows to capture the mouse events and display the properties and methods of the clicked component.
In this second chapter, the bean is able to etablish the correspondance between the Java components and the Forms module's items.
When the mouse enter an item, the background color is changed, then an event is sent to Forms to indicate which item is concerned. The message indicates the Forms item name.

This demonstrates that you can get events from every item with a single Bean component.

Right-click on a component to display its properties and methods.

The Java code


The implementation class of the Bean Item


The methods you can call

    * Enable/disable mouse event capture

Set_Custom_Property('BLOCK.ITEM', 1, 'SETEVENT', 'parameter');

where parameter is:

   event name,boolean

e.g. :

Set_Custom_Property('BL.BEAN', 1, 'SETEVENT', 'PRESS=FALSE' ) ;

event name can be one of the following:

  - MOVE (mouse move)
  - EXIT (mouse exit)
  - PRESS (mouse button pressed)
  - REL (mouse button released)
  - ENTER (mouse enter)
  - CLICK (mouse click)

   By default, the MOVE event is disabled.

    * Enable/disable all mouse events

Set_Custom_Property('BLOCK.ITEM', 1, 'ALLOWEVENT', 'true|false');

    * Set the highlight mode

The highlight mode is used to colorize the item background when the mouse entered in it.

Set_Custom_Property('BLOCK.ITEM', 1, 'SETHIGLIGHT, 'mode');
where mode can be:

   - a positive value to brighter the current item background color
   - a negative value to darker the current item background color
   - a valid r,g,b value
   - false (to avoid automatic coloration)


  -- darker --
  Set_Custom_Property('BL.BEAN', 1, 'SETHIGLIGHT', '-20' ) ;
  -- brighter --
  Set_Custom_Property('BL.BEAN', 1, 'SETHIGLIGHT', '20' ) ;
  -- special color --                                        
  Set_Custom_Property('BL.BEAN', 1, 'SETHIGLIGHT', '185,255,185' ) ;
  -- no highlight --                                        
  Set_Custom_Property('BL.BEAN', 1, 'SETHIGLIGHT', 'false' ) ;

    * Send the Forms item properties to the bean

Set_Custom_Property('BLOCK.ITEM', 1, 'SETPROP', 'properties');
where properties are:

   item name, X position on canvas, Y position on canvas


Set_Custom_Property( 'BL.BEAN', 1, 'SETPROP','BL.PBUTTON,40,30' ) ;

This last method is used to communicate the item coordinates to the Bean, so it can etablish the matching between the Java component and the Forms items.

It is used in the SetProperties() Forms procedure that scans the visible items of the form.

Note : the coordinates used by the java bean are pixel, so the Forms coordinate system must be set to pixel too.

If your coordinate system is different, here is a procedure that convert inches, points or centimeters to pixels:

   LC$Scoord VARCHAR2(100) := Get_Form_Property( Name_in('system.current_form'), COORDINATE_SYSTEM ) ;
   -- Convert to pixel --
   If LC$Scoord = 'INCHES' Then
      value := value * 0.0104 ;
   ElsIf LC$Scoord = 'POINTS' Then
      value := value * 1.333 ;
   ElsIf LC$Scoord = 'CENTIMETERS' Then
      value := value * 0.0263 ;
   End if ;
End ;

The event raised by the bean


This event is raised by the bean to inform Forms that a mouse event has occured.
4 properties are provided:

  - MSGEVENT : event raised (mouse enter, exit, click, move, press)
  - MSGTYPE : type of the component ( e.g. oracle.forms.ui.VButton for a PushButton)
  - MSGITEM : class name of the component
  - MSGCOORD : coordinates of the mouse pointer
  - MSGBTMOUSE : mouse button number

  IF (eventName='SENDMSG') THEN
      -- get the mouse message --
      eventValues := get_parameter_list(:system.custom_item_event_parameters);
      get_parameter_attr(eventValues,'MSGEVENT',eventValueType, LC$Event);
      get_parameter_attr(eventValues,'MSGTYPE',eventValueType, LC$Type);
      get_parameter_attr(eventValues,'MSGITEM',eventValueType, LC$Item);
      get_parameter_attr(eventValues,'MSGCOORD',eventValueType, LC$Coord);
      get_parameter_attr(eventValues,'MSGBTMOUSE',eventValueType, LC$Button);
      LC$Msg := LC$Event
             || ' object=' || LC$Type
             || ' item=' || LC$Item           
             || ' at ' || LC$Coord
             || ' mouse=' || LC$Button ;
      Message(LC$Msg, no_acknowledge) ;
      Synchronize ; 


This event is raised by the bean to inform Forms that the property and method information of the component has been sent.
In the sample dialog, this information is stored in a Text item, then displayed via the Edit_TextItem() Forms built-in.
It can be displayed by right-clicking on anywhere on the screen.

      -- get the component properties --     
      eventValues := get_parameter_list(:system.custom_item_event_parameters);
      get_parameter_attr(eventValues,'MSGPROPS',eventValueType, LC$Msg);
      :BL.PROPERTIES := Replace(LC$Msg, '/n', CHR(10));
      Set_Custom_Property('BL.BEAN', 1, 'ALLOWEVENT', 'false' ) ;
      edit_textitem ;
      Set_Custom_Property('BL.BEAN', 1, 'ALLOWEVENT', 'true' ) ;
   END IF;

The sample dialog

     . Download the mouseevent2.zip file
     . Unzip the file
     . copy the handlemouseevent2.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file to add this jar file
     . Open the MOUSEEVENT2.fmb module (Oracle Forms 10.1.2)
     . Compile all and run the module

Using the JInitiator:

Tom Casserly provides, here, an equivalent that runs correctly with JInitiator.

Download the JInititator compatible version

Partager cet article

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


Philippe 14/11/2012 08:49

Sorry, I forgot to mention that my problem is where/when to run the SETPROPERTIES procedure.  In this procedure, all blocks are scanned and the bean is intialized. What about the second bean
in the seconf canvas then ?

Oracle Forms community 15/11/2012 06:31

When you use the Set_Custom_Property() built-in, you pass the Bean Area name. That bean is located on one canvas. If you have 2 canvas, and 2 Beans (I suppose the canvas hold different block
item) you have to call the Set_Custom_Property() for the 2 Bean Areas.

Is it clear now ?

Philippe 13/11/2012 16:33

Hello François, Demo works ok but I have a lot of pain to implement the same behaviour with multiple blocks and canvas.  I always finish with 'reference to invalid item'.  Tried the
following : 1 bean per canvas (forms has 2 canvas), the last one try to focus on the first canvas,... Any idea ?

Oracle Forms community 13/11/2012 18:45

There is one bean per canvas. As an Item has a canvas name property set, you cannot have any issue. the bean 1 on canvas 1 handle items that are located on canvas 1. The bean 2 on canvas 2 handle
items that are located on canvas 2. Without more details I cannot understand what your issue is

Olaf Czekay 17/09/2010 13:15

Bad news. But thank you for your very quick answer.

Regards, Olaf

Olaf Czekay 16/09/2010 23:51

Hello Francois,

when running the Form MOUSEEVENT2 from another Form (e.g. with OPEN_FORM) more than once, then the background color is changed in _all_ instances of MOUSEEVENT2. Is there a way to get it work in
the active instance/window only?

Regards, Olaf

Oracle Forms community 17/09/2010 07:18

You are not the first one to say that. Someone else has encountered the same issue with another bean. It seems that this is a Forms issue with Java Beans, and I have no solution at this momment.

Olaf Czekay 15/07/2010 12:21

Ok, thank you.