Oracle Forms – Javabean

 

Buttons with HTML labels

 

Home page

 

 

1.    Purpose

 

 

This is a Javabean component that allow to display buttons with HTML labels

 

 

 

 

 

2.    The Javabean

 

 

package oracle.forms.fd;

 

import java.awt.*;

import java.awt.event.*;

 

import java.util.StringTokenizer;

import javax.swing.JButton;

import oracle.forms.ui.CustomEvent;

import oracle.forms.ui.VBean;

import oracle.forms.ui.VButton;

import oracle.ewt.button.PushButton;

import oracle.forms.handler.IHandler;

import oracle.forms.properties.ID;

import oracle.forms.properties.Property;

 

/**

 * A javabean to display buttons with HTML labels

 *

 * @author Francois Degrelle

 * @version 1.0

 */

 

public class HtmlButton  extends VBean implements ActionListener

{

  public final static ID SetLabel      = ID.registerProperty("SETLABEL"); 

  public final static ID SetBG         = ID.registerProperty("SETBACKGROUND");   

  public final static ID WBP           = ID.registerProperty("BUTTONPRESSED");   

  private IHandler  m_handler; 

  protected JButton b1  ;

 

  public HtmlButton()

  {

      super();

     b1 = new JButton("");

     b1.setActionCommand("push");

     b1.addActionListener(this);

     add(b1) ;

 

  }

     

  public void actionPerformed(ActionEvent e) {

        CustomEvent ce = new CustomEvent(m_handler, WBP);

        dispatchCustomEvent(ce);

    }

   

  public void init(IHandler handler)

  {

    m_handler = handler;

    super.init(handler);

  }     

 

 

  public boolean setProperty(ID property, Object value)

  {

    if (property == SetLabel)

    {

      String label = value.toString().trim();

      b1.setLabel(label);

      return true;

    }

    else if (property == SetBG)

    {

      String color = value.toString().trim();

      int r=-1, g=-1, b=-1, c=0 ;

      StringTokenizer st = new StringTokenizer(color,",");

      while (st.hasMoreTokens()) {

               c = new Integer((String)st.nextToken()).intValue()  ;

               if( (c <0) || (c > 255) ) c = 0 ;

               if( r == -1 ) r = c ;

               else if( g == -1 ) g = c ;

               else if( b == -1 ) b = c ;

             }

      b1.setBackground( new Color(r, g, b)) ;

      return true;

    }

    else

    {

     return super.setProperty(property, value);

    }

  }

 

}

 

 

 

3.    Forms configuration

 

Ř      Copy the htmlbutton.jar file in the /forms/java directory

 

Ř      Edit the /forms/server/formsweb.cfg file to add the jar file to the archive_jini variable

 

archive_jini=f90all_jinit.jar,……,htmlbutton.jar

 

 

 

4.    How to implement this bean in your own form

 

Ř      Open your form

 

Ř      Add a Javabean component to any block

 

Ř      Set its Implementation class property to : oracle.forms.fd.HtmlButton

 

 

 

5.    The properties that can be sent to the bean

 

 

 

Ř      The background color of the button

 

Set_Custom_Property( 'BLOC3.BEAN_ITEM',1, 'SETBACKGROUND','rgb_color' ) ;

 

 

Ř      The label

 

Set_Custom_Property( ‘BLOCK.BEAN_ITEM’, ‘SETLABEL’, ‘the_label’ ) ;

 

 

 

 

6.    The sample dialog

 

Ř      Download the htmlbutton.zip file

 

Ř      Unzip the htmlbutton.zip file

 

Ř      Copy the bigalert.jar file in your /forms/java/ directory

 

Ř      Edit your /forms/server/formsweb.cfg file

 

Ř      Open the HTML_BUTTON.fmb module (Oracle Forms 9.0.2)

 

Ř      Compile all and run the module

 

 

 

This dialog allows to enter the title, the question and the option list of the alert box

 

The code that set the button properies is located in the When-New-Form-Instance trigger

 

Declare

      LC$ButLabel   Varchar2(256) ;

Begin

 

  -- Set the background color --

  Set_Custom_Property( 'BLOC3.BEAN',1, 'SETBACKGROUND','143,161,253' ) ;

 

  -- Set the label --

  LC$ButLabel := '<html><center>'

  || '<font size=5 color=#ff0000>Co<font size=5 color=#00ff00>lo<font size=5 color=#0000ff>red</u></b></font>'

  || '<br><font size=3 color=#ffff00><b>HTML B</b><i>utton</i></font>'  ;

 

  Set_Custom_Property( 'BLOC3.BEAN',1, 'SETLABEL', LC$ButLabel ) ;

  

End ;