Unable to reference String variable within mouseAdapter class
Hi
I am writing a java bean for use with an Oracle form. The bean colours a text item on the screen on mouse rollover. I would to suppress the colour change based on the value of a property set in the form. To implement this I have included a check on String in the mouseEntered method.
I would like the default behaviour to be rollover enabled. However if I don't set the property from the Oracle form my String value is set to "false"
When the property is set from the Oracle form the setProperty method is invoked
How can I set the default value?
Full code to follow
package pjcs.rolloverBackground;
//package totem.forms.extensions;
import java.awt.*;
import java.awt.event.*;
import java.util.StringTokenizer;
import oracle.forms.handler.IHandler;
import oracle.forms.properties.ID;
import oracle.forms.ui.VTextField;
public class rolloverBackground extends VTextField
{
public static final ID propEnabled = ID.registerProperty("ENABLED");
public static final ID activeColor = ID.registerProperty("ACTIVE_COLOUR");
//private rolloverBackground this_item;
String pEnabled = "YES";
private Color pActiveColor;
private Color pNormalColor;
private boolean m_debug = true;
private boolean m_debugAll;
private final String CLASSNAME = this.getClass().getName();
private int iMode = 0 ;
private int iInc = 20 ;
public rolloverBackground()
{
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void jbInit() throws Exception
{
System.out.println("jb init 3 "+pEnabled);
addMouseListener(new RolloverButtonMouseAdapter());
}
/**
* Private class to handle user mouse actions and to switch images whenthe
* user moves the mouse into and out of the button object.
*/
class RolloverButtonMouseAdapter extends MouseAdapter
{
/**
* User moved the mouse over the button, swap to the on image.
*/
public void mouseEntered(MouseEvent me)
{
//System.out.println("mouse entered"+this_item.getProperty(propEnabled).toString());
System.out.println("mouse entered "+pEnabled);
if (pEnabled.equals("YES"))
{
System.out.println("mouse entered 1" );
pNormalColor = getBackground();
if (iMode == 1)
{
System.out.println("mouse entered 2.1 imode is 1 " );
setBackground(pActiveColor);
}
else if (iMode == 0)
{
System.out.println("mouse entered 2.2 imode is 0 " );
setBackground(getHighlight(getBackground()));
}
}
}
/**
* User moved the mouse out of the button, swap to the off image.
*/
public void mouseExited(MouseEvent me)
{
// Change cursor back
if (pEnabled.equals("YES"))
{
setBackground(pNormalColor);
}
}
}
/*
* set the properties of the bean
*/
public boolean setProperty(ID property, Object value)
{
if (property == propEnabled)
{
pEnabled = value.toString();
return true;
}
else if (property == activeColor)
{
String s= value.toString();
int iR, iG, iB, ipos=-1 ;
ipos = s.indexOf(",") ;
if(ipos>-1)
{
System.out.println("SETHIGHLIGHT color:"+value.toString());
StringTokenizer st = new StringTokenizer(s,",");
iR = Integer.parseInt(st.nextToken()) ;
iG = Integer.parseInt(st.nextToken()) ;
iB = Integer.parseInt(st.nextToken()) ;
pActiveColor = new Color(iR,iG,iB) ;
iMode = 1 ;
}
else
{
System.out.println("SETHIGHLIGHT:"+value.toString());
if(s.indexOf("-")>-1) iInc = Integer.parseInt(s.substring(1)) * -1 ;
else iInc = Integer.parseInt(s.substring(1)) ;
iMode = 0 ;
}
return true;
}
else
{
return super.setProperty(property, value);
}
}
private Color getHighlight(Color c)
{
System.out.println("inc="+iInc);
int r,g,b ;
int iMax = ( iInc < 0 ? 0 : 255 ) ;
r = c.getRed() ;
g = c.getGreen();
b = c.getBlue() ;
r = (r+iInc >= iMax ? r+iInc : iMax) ;
g = (g+iInc >= iMax ? g+iInc : iMax) ;
b = (b+iInc >= iMax ? b+iInc : iMax) ;
return new Color(r,g,b);
}
}