Oracle Forms – Javabean

 

A Jslider in your application

 

Home page

 

 

1.    Purpose

 

 

This bean allows to display a Jslider component in your Forms application.

 

 

 

 

 

 

 

2.    The Javabean

 

 

package oracle.forms.fd;

 

import java.awt.*;

import java.awt.event.*;

 

import java.util.StringTokenizer;

import javax.swing.JSlider;

 

import javax.swing.event.ChangeEvent;

import javax.swing.event.ChangeListener;

 

import oracle.forms.ui.CustomEvent;

import oracle.forms.ui.VBean;

import oracle.forms.handler.IHandler;

import oracle.forms.properties.ID;

 

/**

 * A javabean to display Sliders in Forms

 *

 * @author Francois Degrelle

 * @version 1.0

 */

 

public class Slider  extends VBean implements ChangeListener

{

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

  public final static ID SetFG         = ID.registerProperty("SETFGCOLOR");     

  public final static ID ValueChanged  = ID.registerProperty("VALUECHANGED");   

  public final static ID SetBounds     = ID.registerProperty("SETBOUNDS");     

  public final static ID SetValue      = ID.registerProperty("SETVALUE");         

  public final static ID GetValue      = ID.registerProperty("GETVALUE");       

  private IHandler  m_handler; 

 

  static int iValue = 0 ;             // current value variable

  protected JSlider slide  ;          // Slider pointer

  protected Color BGcolor, FGcolor  ; // Slider colors

 

  public Slider()

  {

    super();

    // create a new JSlider

    slide = new JSlider();

 

    slide.addChangeListener(this);

    slide.setPaintTrack(true);

    slide.setPaintTicks(true);

    slide.setPaintLabels(true);

 

    add(slide);

 

  }

     

  // Fires when the JSlider is modified

  public void stateChanged(ChangeEvent e) {

      JSlider source = (JSlider)e.getSource();

      if (!source.getValueIsAdjusting()) {

          iValue = (int)source.getValue();

          // Dispatch event

          CustomEvent ce = new CustomEvent(m_handler, ValueChanged);

          dispatchCustomEvent(ce);

 

      }

  }

 

   

  public void init(IHandler handler)

  {

    m_handler = handler;

    super.init(handler);

  }     

 

 

  public boolean setProperty(ID property, Object value)

  {

 

    if (property == SetBG) // Set the background color

    {

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

      System.out.println("BG="+color) ;

      int c=0, i=0, r=0, g=0, b=0 ;

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

      while (st.hasMoreTokens()) {

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

               if( i == 0)  r = c; 

               if( i == 1 ) g = c ;

               if( i == 2 ) b = c ;

               i++;

             }     

      BGcolor = new Color(r,g,b);

      slide.setBackground(BGcolor);

      return true;

    }

    else if (property == SetFG) // Set the foreground color

    {

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

      System.out.println("FG="+color) ;

      int c=0, i=0, r=0, g=0, b=0 ;

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

      while (st.hasMoreTokens()) {

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

               if( i == 0)  r = c; 

               if( i == 1 ) g = c ;

               if( i == 2 ) b = c ;

               i++ ;

             }     

      FGcolor = new Color(r,g,b);

      slide.setForeground(FGcolor);

      return true;

    }   

    else if (property == SetBounds) // Set the properties

    {

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

      int c=0, i=1 ;

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

      while (st.hasMoreTokens()) {

            if( i == 1)

            {

               if ( st.nextToken().equals("H"))

                 slide.setOrientation(JSlider.HORIZONTAL);

               else

                 slide.setOrientation(JSlider.VERTICAL);

            }

            else

            {

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

               if( i == 2)  slide.setMinimum(c); 

               if( i == 3 ) slide.setMaximum(c);

               if( i == 4 ) slide.setMajorTickSpacing(c);

               if( i == 5 ) slide.setMinorTickSpacing(c);              

            }

             i++;

      }

      return true;

    }

    else if (property == SetValue) // Set the current value

    {

      slide.setValue(new Integer((String)value).intValue() );

      return true;

    }

    else

    {

     return super.setProperty(property, value);

    }

 

  }

 

  /**

   * Get the current value

   **/

 

  public Object getProperty(ID pId)

  {

    if (pId == GetValue)

    {

      return "" + iValue ;

    }

    else

    {

      return super.getProperty(pId);

    }

  }

 

 

}

 

 

 

3.    Forms configuration

 

Ø      Copy the Slider.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,……, Slider.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.Slider

 

Ø      Eventually, set the Backgroud and/or the foreground color

 

 

 

5.    The properties that can be sent to the bean

 

 

 

Ø      The background color of the slider

 

Set_Custom_Property( BEAN_NAME, BEAN_NUMBER, 'SETBGCOLOR', 'rgb_color' ) ;

 

e.g.

 

Set_Custom_Property('BLK.ITEM_BEAN', 1, 'SETBGCOLOR', '255,0,255' ) ;

 

 

Information about the background property

 

If the background color of the bean is not setted, we use the canvas background color property.

If the canvas background color property is not setted, we have to know what colorscheme is currently in use

 

There is a package in the SLIDER.FMB module that store the RGB values for each colorscheme

 

  -- Colorscheme RGB values --

  GC$Teal      Varchar2(15) := '115,142,140' ;

  GC$Titanium  Varchar2(15) := '99,101,99' ;

  GC$Red       Varchar2(15) := '156,130,123' ; 

  GC$Khaki     Varchar2(15) := '140,142,123' ;       

  GC$Blue      Varchar2(15) := '90,117,148' ;

  GC$Olive     Varchar2(15) := '107,113,99' ; 

  GC$Purple    Varchar2(15) := '123,113,140' ;       

  GC$Blaf      Varchar2(15) := '247,247,231' ;

 

  -- Current colorscheme --

  GC$CurScheme Varchar2(15) := '' ;

 

In the case of the use of a colorscheme, you have to indicate it as soon as possible (in a When-New-Form-Instance trigger)

 

-- ColorScheme used ? --

PKG_SLIDER.GC$CurScheme := PKG_SLIDER.GC$Blaf ;

 

In this example, i used the blaf colorscheme

 

 

 

Ø      The foreground color of the slider

 

Set_Custom_Property( BEAN_NAME, BEAN_NUMBER, 'SETFGCOLOR', 'rgb_color' ) ;

 

e.g.

 

Set_Custom_Property('BLK.ITEM_BEAN', 1, 'SETFGCOLOR', '0,0,0' ) ;

 

 

 

Ø      The properties of the slider

 

Set_Custom_Property( BEAN_NAME, BEAN_NUMBER, 'SETBOUNDS', PROPERTIES ) ;

 

Where properties are:

 

Orientation : could be H for a horizontal slider or V for a vertical slider

Max Value : the maximum value for the slider

Min Value : the minimum value for the slider

MajorTick : distance betwwen each principal graduations

MinorTick : distance betwwen each secondary graduations

 

 

e.g.

 

Set_Custom_Property('BLK.ITEM_BEAN', 1, 'SETBOUNDS', ' H,0,10,2,1 ' ) ;

 

 

Ø      The current value of the slider

 

Set_Custom_Property( BEAN_NAME, BEAN_NUMBER, 'SETVALUE', 'value' ) ;

 

e.g.

 

Set_Custom_Property('BLK.ITEM_BEAN', 1, 'SETVALUE', '5' ) ;

 

 

 

6.    The properties that can be read from the bean

 

Ø      The current value of the slider

 

CHAR := Get_Custom_Property( BEAN_NAME, BEAN_NUMBER, 'GETVALUE' ) ;

 

e.g.

 

Value := Get_Custom_Property('BLK.ITEM_BEAN', 1, 'GETVALUE' ) ;

 

 

 

7.    The sample dialog

 

Ø      Download the jslider.zip file

 

Ø      Unzip the jslider.zip file

 

Ø      Copy the Slider.jar file in your /forms/java/ directory

 

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

 

Ø      Open the SLIDER.fmb module (Oracle Forms 10.1.2)

 

Ø      Open the JSLIDER.fmb module (Oracle Forms 9.0.2)

 

Ø      Open the COLOR_SLIDER.fmb module (Oracle Forms 9.0.2)

 

This dialog allows to choose a color from Red, Green and Blue Jsliders

 

 

Ø      Compile all and run the module

 

 

The settings of the slider properties are grouped in the PKG_SLIDER package

 

PACKAGE PKG_SLIDER IS

 

  -- Colorscheme RGB values --

  GC$Teal      Varchar2(15) := '115,142,140' ;

  GC$Titanium  Varchar2(15) := '99,101,99' ;

  GC$Red       Varchar2(15) := '156,130,123' ; 

  GC$Khaki     Varchar2(15) := '140,142,123' ;       

  GC$Blue      Varchar2(15) := '90,117,148' ;

  GC$Olive     Varchar2(15) := '107,113,99' ; 

  GC$Purple    Varchar2(15) := '123,113,140' ;       

  GC$Blaf      Varchar2(15) := '247,247,231' ;

 

  -- Current colorscheme --

  GC$CurScheme Varchar2(15) := '' ;

 

  PROCEDURE    Init_Slider

  (

     PC$Name       IN VARCHAR2,

     PN$Num        IN PLS_INTEGER,

     PC$Bounds     IN VARCHAR2

  ) ;

 

  PROCEDURE Set_Value

  (

     PC$Name       IN VARCHAR2,

     PN$Num        IN PLS_INTEGER,

     PN$Value      IN NUMBER

  ) ; 

 

 

END;

 

PACKAGE BODY PKG_SLIDER IS

 

PROCEDURE    Init_Slider

  (

     PC$Name       IN VARCHAR2,

     PN$Num        IN PLS_INTEGER,

     PC$Bounds     IN VARCHAR2

  )

Is

      LC$CVBColor   Varchar2(20) := Get_Canvas_Property( Get_Item_Property( PC$Name, ITEM_CANVAS ), BACKGROUND_COLOR ) ;

      LC$CVFColor   Varchar2(20) := Get_Canvas_Property( Get_Item_Property( PC$Name, ITEM_CANVAS ), FOREGROUND_COLOR ) ;  

      LC$BGColor    Varchar2(20) := Get_Item_Property(PC$Name, BACKGROUND_COLOR) ;

      LC$FGColor    Varchar2(20) := Get_Item_Property(PC$Name, FOREGROUND_COLOR) ;     

      LC$Color      Varchar2(15) ;

Begin

 

-- BackGround color --

If LC$BGColor is not null Then

  LC$Color := Translate( LC$BGColor, '0123456789gbr','0123456789,,' ) ;

  Set_Custom_Property( PC$Name, PN$Num, 'SETBGCOLOR', LC$Color ) ;    

Elsif LC$CVBColor is not null Then

  LC$Color := Translate( LC$CVBColor, '0123456789gbr','0123456789,,' ) ;   

  Set_Custom_Property( PC$Name, PN$Num, 'SETBGCOLOR', LC$Color ) ;

Else

      LC$Color := PKG_SLIDER.GC$CurScheme ;

      Set_Custom_Property( PC$Name, PN$Num, 'SETBGCOLOR', LC$Color ) ;

End if ;

 

-- ForeGround color --

If LC$FGColor is not null Then

  LC$Color := Translate( LC$FGColor, '0123456789gbr','0123456789,,' ) ;

  Set_Custom_Property( PC$Name, PN$Num, 'SETFGCOLOR', LC$Color ) ;

Elsif LC$CVFColor is not null Then

  LC$Color := Translate( LC$CVFColor, '0123456789gbr','0123456789,,' ) ;   

  Set_Custom_Property( PC$Name, PN$Num, 'SETBGCOLOR', LC$Color ) ; 

End if ;

 

-- Bounds --

Set_Custom_Property( PC$Name, PN$Num, 'SETBOUNDS', PC$Bounds ) ;

 

 

End ;

 

-------------------------------------------

--  Set the current value of the Slider  --

-------------------------------------------

PROCEDURE Set_Value

  (

     PC$Name       IN VARCHAR2,

     PN$Num        IN PLS_INTEGER,

     PN$Value      IN NUMBER

  )

IS

BEGIN

 

  -- Initial value --

  Set_Custom_Property( PC$Name, PN$Num, 'SETVALUE', To_Char(PN$Value) ) ;

 

End Set_Value;

 

END;

 

 

So, in the When-New-Form-Instance trigger, you can set the slider settings:

 

-- ColorScheme used ? --

PKG_SLIDER.GC$CurScheme := PKG_SLIDER.GC$Blaf ;

 

-- Init the slider properties --

PKG_SLIDER.Init_Slider ( 'BL1.BEAN_SLIDER', 1, 'H,0,10,2,1' ) ;

 

-- Set current the value --

PKG_SLIDER.Set_Value   ( 'BL1.BEAN_SLIDER', 1, 5 ) ;

 

 

And get the current value with the When-Custom-Item-Event trigger created on the bean item:

 

-- Get new value --

:BL1.VAL := Get_Custom_Property( 'BL1.BEAN_SLIDER', 1, 'GETVALUE') ;