Bean - Button

Vendredi 3 février 2006 5 03 /02 /Fév /2006 17:30

Purpose

This bean allows to display buttons with a html content.
The content can be text or image.


On the screenshot below, we can see a button with an image that comes from an internet url
(<img src="http://....">)


HtmlButton

The java code


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 content
 *
 * @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);
    }
  }
 
}


Forms configuration

  • Copy the htmlbutton.jar file in the /forms/java directory
  • Sign the htmlbutton.jar file with your own certificate
  • Edit the /forms/server/formsweb.cfg file to add the jar file to the archive_jinit variable
archive_jini=f90all_jinit.jar,……,htmlbutton.jar


Implementation Class property

    oracle.forms.fd.HtmlButton
 



Properties that can be set

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’ ) ;



The sample dialog

  • Download the htmlbutton.zip file
  • Unzip the htmlbutton.zip file
  • Copy the htmlbutton.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

      

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

 -------------------
  --  Text button  --
  -------------------
 -- 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 ) ;
 
  --------------------
  --  Image button  --
  --------------------
 -- Set the background color --
  Set_Custom_Property( 'BLOC3.BEAN2',1, 'SETBACKGROUND','255,255,255' ) ;
  LC$ButLabel := '<html><table border="1"><tr><td align="center" valign="center"><img src="
http://fdtool.free.fr/forms-pjc-bean/tmp/will.jpg" height="80" width="80" align="middle"></td></tr></table>' ;
  Set_Custom_Property( 'BLOC3.BEAN2',1, 'SETLABEL', LC$ButLabel ) ;





Par Oracle Forms community - Publié dans : Bean - Button
Send a comment - See the 1 comments
Jeudi 2 février 2006 4 02 /02 /Fév /2006 17:11

Purpose

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


JSlider bean

The java code


 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);
    }
  }
 

}


Forms configuration

  • Copy the Slider.jar file in the /forms/java directory
  • Sign the Slider.jar file with your own certificate
  • Edit the /forms/server/formsweb.cfg file to add the jar file to the archive_jinit variable
archive_jini=f90all_jinit.jar,……,Slider.jar


Implementation Class property

    oracle.forms.fd.Slider
 



Properties that can be set

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' ) ;


Properties that can be read


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' ) ;



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') ;
Par Oracle Forms community - Publié dans : Bean - Button
Send a comment - See the 0 comments
Créer un blog gratuit sur over-blog.com - Contact - C.G.U. - Rémunération en droits d'auteur - Signaler un abus - Articles les plus commentés