-
Bug
-
Resolution: Fixed
-
P2
-
1.0
-
1.0.k
-
sparc
-
generic
-
Not verified
drawButton(g, getButtonFromKey(evt.key), true);
g.dispose();
break;
case Event.LOST_FOCUS:
getParent().postEvent(new Event(this, ESCAPED, null));
break;
default:
return super.handleEvent( evt );
}
return true;
}
private int asc;
private int selectedButton;
private boolean buttonDown;
private boolean entered;
public String value;
static private int cellSize = 30;
static private int nButton = 14;
static private int buttonX[] = { 1, cellSize+1, cellSize*2+1, 1, cellSize+1, cellSize*2+1, 1, cellSize+1, cellSize*2+1, 1, cellSize+1, cellSize*2+1, cellSize*3+1, cellSize*3+1 };
static private int buttonY[] = { 1, 1, 1, cellSize+1, cellSize+1, cellSize+1, cellSize*2+1, cellSize*2+1, cellSize*2+1, cellSize*3+1, cellSize*3+1, cellSize*3+1, cellSize*3+1, 1 };
static private char buttonTitle1[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'C', '.', 'A', 'E' };
static int paintAll = 0;
static int paintSelected = 1;
};
Run the following program and then click on the window. A
numeric keypad should appear. On Mr. Coffee, the keypad
generates continual repaints.
The program works fine under Win95. Under Solaris,
the numeric keypad does not display at all.
import java.awt.*;
import java.applet.*;
public class mousepos extends Applet
{
public static void main (String args[])
{
MyFrame myFrame = new MyFrame();
myFrame.show();
}
public void init()
{
MyFrame myFrame = new MyFrame();
myFrame.show();
}
}
class MyFrame extends Frame
{
public MyFrame()
{
super("Secondary Window Placement");
GroupBox g = new GroupBox("Mouse Position Testcase");
setLayout(null);
g.reshape( 10, 10, 100, 100 );
add("center", g );
resize(283,190);
}
public boolean handleEvent( Event evt )
{
switch (evt.id)
{
case Event.MOUSE_UP:
NumericPad np = new NumericPad( this, evt.x, evt.y );
System.out.println( "GroupBox: The mouse up position is x = " + evt.x + ", y = " + evt.y );
break;
}
return super.handleEvent( evt );
}
}
/**************************************************************************
*
* Class: GroupBox
*
* Purpose: Draw a 3d border around a collection of controls or a single
* component. The name of the group box is drawn in the upper
* right hand corner using the group boxes current font and
* foreground color.
*
* Example: GroupBox checkBoxes = new GroupBox("Group Box Title");
* checkBoxes.setLayout(new FlowLayout());
* checkBoxes.add(new Checkbox("option1"));
* checkBoxes.add(new Checkbox("option2"));
* checkBoxes.add(new Checkbox("option3"));
*
**************************************************************************/
class GroupBox extends Panel
{
/**************************************************************************
*
* Public
*
**************************************************************************/
/**************************************************************************
*
* GroupBox
*
**************************************************************************/
public GroupBox(String name)
{
// call the super class ctor
super();
setLayout(null);
grpName = name;
}
/**************************************************************************
*
* setGroupName
*
**************************************************************************/
public void setGroupName(String newName)
{
grpName = newName;
}
/**************************************************************************
*
* groupName
*
**************************************************************************/
public String groupName()
{
return grpName;
}
/**************************************************************************
*
* paint
*
**************************************************************************/
public void paint(Graphics g)
{
FontMetrics fm = g.getFontMetrics();
int asc = fm.getAscent();
int stringWidth = fm.stringWidth( " " + grpName + " " );
int stringHeight = fm.getHeight();
Rectangle r = bounds();
g.setColor( Color.white );
g.drawLine( 1, r.height-3, 1, asc/2 );
g.drawLine( 1, asc/2, r.width-3, asc/2 );
g.drawLine( r.width-1, asc/2-1, r.width-1, r.height-1 );
g.drawLine( r.width-1, r.height-1, 0, r.height-1 );
g.setColor( Color.gray );
g.drawLine( r.width-2, asc/2-1, r.width-2, r.height-2 );
g.drawLine( r.width-2, r.height-2, 0, r.height-2 );
g.drawLine( 0, r.height-2, 0, asc/2-1 );
g.drawLine( 0, asc/2-1, r.width-2, asc/2-1 );
g.setColor( this.getBackground() );
g.fillRect( 10, 0, stringWidth, stringHeight );
g.setColor( Color.black );
g.drawString( " " + grpName + " ", 10, asc );
}
/**************************************************************************
*
* insets
*
* Overridden so that the layout manager makes room for the 3d border
* and the group box text.
*
**************************************************************************/
public Insets insets( )
{
Graphics g = this.getGraphics();
FontMetrics fm = g.getFontMetrics();
int stringHeight = fm.getHeight();
Insets i = super.insets();
return new Insets( stringHeight + i.top, 5 + i.left, 3 + i.bottom, 5 + i.right );
}
// debug
public boolean handleEvent( Event evt )
{
switch (evt.id)
{
case Event.MOUSE_UP:
System.out.println( "GroupBox: The mouse up position is x = " + evt.x + ", y = " + evt.y );
break;
}
return super.handleEvent( evt );
}
/**************************************************************************
*
* Private
*
**************************************************************************/
private
String grpName;
}
/**
* This is a NumericPad class that is used to record a numeric value or
* Anestesia specific alpha numeric code. The NumericPad is a basic Window
* that displays a set a buttons for the user the click on. The NumericPad
* buttons include 0 - 9, C(to clear the existing value), .(decimal point),
* A/#(to switch between alpha and numeric) and E(the enter key). When the
* NumericPad is switched to the alpha mode, the 1 - 9 buttons are replaced
* by another set of buttons that represent Anestesia specific mnemonic
* codes. The NumericPad also generates the ENTERED, ESCAPED and MODIFIED
* events that can be handled at its parent level.
*
* @version 1.0, July 1996
* @author George Clement
*/
class NumericPad extends Window
{
/* Base for all NumericPad events */
private static final int NUMERICPAD_EVENT = 5000;
/**
* The Entered event.
*/
public final static int ENTERED = 1 + NUMERICPAD_EVENT;
/**
* The Escaped event.
*/
public final static int ESCAPED = 2 + NUMERICPAD_EVENT;
/**
* The Modified event.
*/
public final static int MODIFIED = 3 + NUMERICPAD_EVENT;
/**
* Create a Numeric object.
*
* @param parentWin The parent window of the NumericPad.
* @param x The x location of the NumericPad with respect to its parent.
* @param y The y location of the NumericPad with respect to its parent.
*/
public NumericPad(Component parentWin, int x, int y)
{
super(GetFrame(parentWin));
/* initialize object variables */
selectedButton = -1;
buttonDown = false;
entered = false;
value = new String();
setBackground(Color.lightGray);
Component curParent = parentWin;
/* Calculate the absolute location of the parent window. */
while (curParent != null)
{
x += curParent.location().x;
y += curParent.location().y;
if (curParent instanceof Frame)
{
break;
}
curParent = curParent.getParent();
}
this.addNotify();
reshape(x, y, cellSize*4+2, cellSize*4+2);
System.out.println( "The translated coordinates are: x = " + x + " y = " + y );
setLayout(null);
show();
requestFocus();
}
/**
* Query the Numeric pad to see if an enter was keyed on the NumericPad.
* @return Returns a true if enter was keyed, false otherwise.
*/
public boolean isEntered()
{
return entered;
}
/**
* Shows the NumericPad. Calls the super.show and also disables
* its parent window which make it behave like a model window.
*/
public void show()
{
super.show();
Component parentFrame = GetFrame(this);
// if (parentFrame != null) {
// parentFrame.disable();
// }
}
/**
* Dispose the NumericPad. Calls the super.dispose and also enable
* its parent window. Called when the NumericPad is destroyed to
* give back the control to its parent window.
*/
public void dispose()
{
Component parentFrame = GetFrame(this);
// if (parentFrame != null) {
// parentFrame.enable();
// }
super.dispose();
}
/**
* Gets the parent Frame window of a given component.
*/
private static Frame GetFrame (Component curComp)
{
Component curParent = curComp;
Frame theFrame = null;
while (curParent != null) {
if (curParent instanceof Frame) {
theFrame = (Frame) curParent;
break;
}
curParent = curParent.getParent();
}
return theFrame;
}
/**
* Paints the NumericPad object. Paints all the buttons or the one
* that is currently selected.
* @param g The almighty Graphics object.
* @param howToPaint The kind of paint that needs to performed.
*/
public void paint(Graphics g, int howToPaint)
{
FontMetrics fm = g.getFontMetrics();
asc = fm.getAscent();
setForeground(Color.black);
g.drawRect(0, 0, cellSize*4+1, cellSize*4+1);
if (howToPaint == paintAll) {
for (int i=0; i<nButton; i++) {
drawButton(g, i, false);
}
}
else {
drawButton(g, selectedButton, buttonDown);
}
}
/**
* Paints the NumericPad object. This basically routes paint request to
* private paint method.
* @param g The almighty Graphics object.
*/
public void paint(Graphics g)
{
paint( g, paintAll );
}
/**
* Draws a button on the Numeric pad. The look-and-feel of a button
* is achived by drawing a rectangle with top and left edges in dark
* shade and bottom and right edges in light shade. The depression of
* the button itself is simulated by drawing the same rectangle with
* the shades of the edges inverted.
* @param g The almighty Graphics object.
* @param id The index of the button that neds to be drawn.
* @param pressed The flag that specifies if the button needs to
* be drawn depressed.
*/
private void drawButton(Graphics g, int id, boolean pressed)
{
String text = new String();
int x = buttonX[id];
int y = buttonY[id];
char c = buttonTitle1[id];
int cellWidth = cellSize-1;
int cellHeight = cellSize-1;
if (id == 13)
cellHeight = cellSize*3-1;
if (pressed)
g.setColor( Color.black );
else
g.setColor( Color.white );
g.drawLine( x, y, x, y+cellHeight );
g.drawLine( x+cellWidth, y, x, y );
if (pressed)
g.setColor( Color.white );
else
g.setColor( Color.black );
g.drawLine( x, y+cellHeight, x+cellWidth, y+cellHeight );
g.drawLine( x+cellWidth, y+cellHeight, x+cellWidth, y );
g.drawString( ""+c, x+7, y+asc+3);
}
/**
* Calculates the button index for a given x-y location on the
* NumericPad.
* @param x The x coordinate of the location.
* @param y The y coordinate of the location.
* @return Returns the index of the button.
*/
private int getButtonFromLocation(int x, int y)
{
int id = (x / cellSize) + (y / cellSize)*3;
if (x > cellSize*3) {
if (y > cellSize*3)
id = 12;
else
id = 13;
}
return id;
}
/**
* Calculates the button index the corresponds to a given key value.
* @param key The ascii key value.
* @return Returns the index of the button.
*/
private int getButtonFromKey(int key)
{
if (key==10) return 13;
key = (char)Character.toUpperCase((char)key);
for (int i=0; i<14; i++)
if (buttonTitle1[i]==key) return i;
return -1;
}
/**
* Handles all input events for the numeric pad.
* @param evt The awt generated event.
* @return Return true to indicate the event has been processed.
*/
public boolean handleEvent( Event evt )
{
Graphics g;
switch (evt.id)
{
// case Event.LOST_FOCUS:
// getParent().postEvent(new Event(this, ESCAPED, null));
// System.out.println("Lost Focus");
// return true;
case Event.MOUSE_DOWN:
// if (true || (evt.modifiers & Event.META_MASK) != 0)
selectedButton = getButtonFromLocation(evt.x, evt.y);
buttonDown = true;
g = getGraphics();
paint(g, paintSelected);
g.dispose();
break;
case Event.MOUSE_UP:
if (selectedButton == -1) break;
buttonDown = false;
if (selectedButton == getButtonFromLocation(evt.x, evt.y)) {
g = getGraphics();
paint(g, paintSelected);
g.dispose();
if (selectedButton>=0 && selectedButton<=12)
postEvent(new Event(this, evt.when,
Event.KEY_RELEASE, 0, 0,
(int)buttonTitle1[selectedButton],
evt.modifiers, null));
else
postEvent(new Event(this, evt.when, Event.KEY_RELEASE, 0, 0, 10, evt.modifiers, null));
}
selectedButton = -1;
break;
case Event.MOUSE_DRAG:
if (selectedButton == -1) break;
if (selectedButton == getButtonFromLocation(evt.x, evt.y)) {
if (buttonDown==false) {
buttonDown = true;
g = getGraphics();
paint(g, paintSelected);
g.dispose();
}
}
else {
if (buttonDown==true) {
buttonDown = false;
g = getGraphics();
paint(g, paintSelected);
g.dispose();
}
}
break;
case Event.KEY_ACTION:
case Event.KEY_ACTION_RELEASE:
case Event.KEY_RELEASE:
// If the enter key was pressed...
switch (evt.key) {
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
case '.':
value = value + (char)evt.key;
break;
case 'C':
case 'c':
value = "";
break;
case 'A':
case 'a':
break;
case 10:
entered = true;
break;
case 27:
getParent().postEvent(new Event(this, ESCAPED, null));
return true;
default:
return super.handleEvent( evt );
};
g = getGraphics();
drawButton(g, getButtonFromKey(evt.key), false);
g.dispose();
if (entered==true)
getParent().postEvent(new Event(this, ENTERED, null));
else
getParent().postEvent(new Event(this, MODIFIED, null));
break;
case Event.KEY_PRESS:
// If the enter key was pressed...
switch (evt.key) {
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
case '.':
case 'C':
case 'c':
case 'A':
case 'a':
case 10:
break;
default:
return super.handleEvent( evt );
};
g = getGraphics();
g.dispose();
break;
case Event.LOST_FOCUS:
getParent().postEvent(new Event(this, ESCAPED, null));
break;
default:
return super.handleEvent( evt );
}
return true;
}
private int asc;
private int selectedButton;
private boolean buttonDown;
private boolean entered;
public String value;
static private int cellSize = 30;
static private int nButton = 14;
static private int buttonX[] = { 1, cellSize+1, cellSize*2+1, 1, cellSize+1, cellSize*2+1, 1, cellSize+1, cellSize*2+1, 1, cellSize+1, cellSize*2+1, cellSize*3+1, cellSize*3+1 };
static private int buttonY[] = { 1, 1, 1, cellSize+1, cellSize+1, cellSize+1, cellSize*2+1, cellSize*2+1, cellSize*2+1, cellSize*3+1, cellSize*3+1, cellSize*3+1, cellSize*3+1, 1 };
static private char buttonTitle1[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'C', '.', 'A', 'E' };
static int paintAll = 0;
static int paintSelected = 1;
};
Run the following program and then click on the window. A
numeric keypad should appear. On Mr. Coffee, the keypad
generates continual repaints.
The program works fine under Win95. Under Solaris,
the numeric keypad does not display at all.
import java.awt.*;
import java.applet.*;
public class mousepos extends Applet
{
public static void main (String args[])
{
MyFrame myFrame = new MyFrame();
myFrame.show();
}
public void init()
{
MyFrame myFrame = new MyFrame();
myFrame.show();
}
}
class MyFrame extends Frame
{
public MyFrame()
{
super("Secondary Window Placement");
GroupBox g = new GroupBox("Mouse Position Testcase");
setLayout(null);
g.reshape( 10, 10, 100, 100 );
add("center", g );
resize(283,190);
}
public boolean handleEvent( Event evt )
{
switch (evt.id)
{
case Event.MOUSE_UP:
NumericPad np = new NumericPad( this, evt.x, evt.y );
System.out.println( "GroupBox: The mouse up position is x = " + evt.x + ", y = " + evt.y );
break;
}
return super.handleEvent( evt );
}
}
/**************************************************************************
*
* Class: GroupBox
*
* Purpose: Draw a 3d border around a collection of controls or a single
* component. The name of the group box is drawn in the upper
* right hand corner using the group boxes current font and
* foreground color.
*
* Example: GroupBox checkBoxes = new GroupBox("Group Box Title");
* checkBoxes.setLayout(new FlowLayout());
* checkBoxes.add(new Checkbox("option1"));
* checkBoxes.add(new Checkbox("option2"));
* checkBoxes.add(new Checkbox("option3"));
*
**************************************************************************/
class GroupBox extends Panel
{
/**************************************************************************
*
* Public
*
**************************************************************************/
/**************************************************************************
*
* GroupBox
*
**************************************************************************/
public GroupBox(String name)
{
// call the super class ctor
super();
setLayout(null);
grpName = name;
}
/**************************************************************************
*
* setGroupName
*
**************************************************************************/
public void setGroupName(String newName)
{
grpName = newName;
}
/**************************************************************************
*
* groupName
*
**************************************************************************/
public String groupName()
{
return grpName;
}
/**************************************************************************
*
* paint
*
**************************************************************************/
public void paint(Graphics g)
{
FontMetrics fm = g.getFontMetrics();
int asc = fm.getAscent();
int stringWidth = fm.stringWidth( " " + grpName + " " );
int stringHeight = fm.getHeight();
Rectangle r = bounds();
g.setColor( Color.white );
g.drawLine( 1, r.height-3, 1, asc/2 );
g.drawLine( 1, asc/2, r.width-3, asc/2 );
g.drawLine( r.width-1, asc/2-1, r.width-1, r.height-1 );
g.drawLine( r.width-1, r.height-1, 0, r.height-1 );
g.setColor( Color.gray );
g.drawLine( r.width-2, asc/2-1, r.width-2, r.height-2 );
g.drawLine( r.width-2, r.height-2, 0, r.height-2 );
g.drawLine( 0, r.height-2, 0, asc/2-1 );
g.drawLine( 0, asc/2-1, r.width-2, asc/2-1 );
g.setColor( this.getBackground() );
g.fillRect( 10, 0, stringWidth, stringHeight );
g.setColor( Color.black );
g.drawString( " " + grpName + " ", 10, asc );
}
/**************************************************************************
*
* insets
*
* Overridden so that the layout manager makes room for the 3d border
* and the group box text.
*
**************************************************************************/
public Insets insets( )
{
Graphics g = this.getGraphics();
FontMetrics fm = g.getFontMetrics();
int stringHeight = fm.getHeight();
Insets i = super.insets();
return new Insets( stringHeight + i.top, 5 + i.left, 3 + i.bottom, 5 + i.right );
}
// debug
public boolean handleEvent( Event evt )
{
switch (evt.id)
{
case Event.MOUSE_UP:
System.out.println( "GroupBox: The mouse up position is x = " + evt.x + ", y = " + evt.y );
break;
}
return super.handleEvent( evt );
}
/**************************************************************************
*
* Private
*
**************************************************************************/
private
String grpName;
}
/**
* This is a NumericPad class that is used to record a numeric value or
* Anestesia specific alpha numeric code. The NumericPad is a basic Window
* that displays a set a buttons for the user the click on. The NumericPad
* buttons include 0 - 9, C(to clear the existing value), .(decimal point),
* A/#(to switch between alpha and numeric) and E(the enter key). When the
* NumericPad is switched to the alpha mode, the 1 - 9 buttons are replaced
* by another set of buttons that represent Anestesia specific mnemonic
* codes. The NumericPad also generates the ENTERED, ESCAPED and MODIFIED
* events that can be handled at its parent level.
*
* @version 1.0, July 1996
* @author George Clement
*/
class NumericPad extends Window
{
/* Base for all NumericPad events */
private static final int NUMERICPAD_EVENT = 5000;
/**
* The Entered event.
*/
public final static int ENTERED = 1 + NUMERICPAD_EVENT;
/**
* The Escaped event.
*/
public final static int ESCAPED = 2 + NUMERICPAD_EVENT;
/**
* The Modified event.
*/
public final static int MODIFIED = 3 + NUMERICPAD_EVENT;
/**
* Create a Numeric object.
*
* @param parentWin The parent window of the NumericPad.
* @param x The x location of the NumericPad with respect to its parent.
* @param y The y location of the NumericPad with respect to its parent.
*/
public NumericPad(Component parentWin, int x, int y)
{
super(GetFrame(parentWin));
/* initialize object variables */
selectedButton = -1;
buttonDown = false;
entered = false;
value = new String();
setBackground(Color.lightGray);
Component curParent = parentWin;
/* Calculate the absolute location of the parent window. */
while (curParent != null)
{
x += curParent.location().x;
y += curParent.location().y;
if (curParent instanceof Frame)
{
break;
}
curParent = curParent.getParent();
}
this.addNotify();
reshape(x, y, cellSize*4+2, cellSize*4+2);
System.out.println( "The translated coordinates are: x = " + x + " y = " + y );
setLayout(null);
show();
requestFocus();
}
/**
* Query the Numeric pad to see if an enter was keyed on the NumericPad.
* @return Returns a true if enter was keyed, false otherwise.
*/
public boolean isEntered()
{
return entered;
}
/**
* Shows the NumericPad. Calls the super.show and also disables
* its parent window which make it behave like a model window.
*/
public void show()
{
super.show();
Component parentFrame = GetFrame(this);
// if (parentFrame != null) {
// parentFrame.disable();
// }
}
/**
* Dispose the NumericPad. Calls the super.dispose and also enable
* its parent window. Called when the NumericPad is destroyed to
* give back the control to its parent window.
*/
public void dispose()
{
Component parentFrame = GetFrame(this);
// if (parentFrame != null) {
// parentFrame.enable();
// }
super.dispose();
}
/**
* Gets the parent Frame window of a given component.
*/
private static Frame GetFrame (Component curComp)
{
Component curParent = curComp;
Frame theFrame = null;
while (curParent != null) {
if (curParent instanceof Frame) {
theFrame = (Frame) curParent;
break;
}
curParent = curParent.getParent();
}
return theFrame;
}
/**
* Paints the NumericPad object. Paints all the buttons or the one
* that is currently selected.
* @param g The almighty Graphics object.
* @param howToPaint The kind of paint that needs to performed.
*/
public void paint(Graphics g, int howToPaint)
{
FontMetrics fm = g.getFontMetrics();
asc = fm.getAscent();
setForeground(Color.black);
g.drawRect(0, 0, cellSize*4+1, cellSize*4+1);
if (howToPaint == paintAll) {
for (int i=0; i<nButton; i++) {
drawButton(g, i, false);
}
}
else {
drawButton(g, selectedButton, buttonDown);
}
}
/**
* Paints the NumericPad object. This basically routes paint request to
* private paint method.
* @param g The almighty Graphics object.
*/
public void paint(Graphics g)
{
paint( g, paintAll );
}
/**
* Draws a button on the Numeric pad. The look-and-feel of a button
* is achived by drawing a rectangle with top and left edges in dark
* shade and bottom and right edges in light shade. The depression of
* the button itself is simulated by drawing the same rectangle with
* the shades of the edges inverted.
* @param g The almighty Graphics object.
* @param id The index of the button that neds to be drawn.
* @param pressed The flag that specifies if the button needs to
* be drawn depressed.
*/
private void drawButton(Graphics g, int id, boolean pressed)
{
String text = new String();
int x = buttonX[id];
int y = buttonY[id];
char c = buttonTitle1[id];
int cellWidth = cellSize-1;
int cellHeight = cellSize-1;
if (id == 13)
cellHeight = cellSize*3-1;
if (pressed)
g.setColor( Color.black );
else
g.setColor( Color.white );
g.drawLine( x, y, x, y+cellHeight );
g.drawLine( x+cellWidth, y, x, y );
if (pressed)
g.setColor( Color.white );
else
g.setColor( Color.black );
g.drawLine( x, y+cellHeight, x+cellWidth, y+cellHeight );
g.drawLine( x+cellWidth, y+cellHeight, x+cellWidth, y );
g.drawString( ""+c, x+7, y+asc+3);
}
/**
* Calculates the button index for a given x-y location on the
* NumericPad.
* @param x The x coordinate of the location.
* @param y The y coordinate of the location.
* @return Returns the index of the button.
*/
private int getButtonFromLocation(int x, int y)
{
int id = (x / cellSize) + (y / cellSize)*3;
if (x > cellSize*3) {
if (y > cellSize*3)
id = 12;
else
id = 13;
}
return id;
}
/**
* Calculates the button index the corresponds to a given key value.
* @param key The ascii key value.
* @return Returns the index of the button.
*/
private int getButtonFromKey(int key)
{
if (key==10) return 13;
key = (char)Character.toUpperCase((char)key);
for (int i=0; i<14; i++)
if (buttonTitle1[i]==key) return i;
return -1;
}
/**
* Handles all input events for the numeric pad.
* @param evt The awt generated event.
* @return Return true to indicate the event has been processed.
*/
public boolean handleEvent( Event evt )
{
Graphics g;
switch (evt.id)
{
// case Event.LOST_FOCUS:
// getParent().postEvent(new Event(this, ESCAPED, null));
// System.out.println("Lost Focus");
// return true;
case Event.MOUSE_DOWN:
// if (true || (evt.modifiers & Event.META_MASK) != 0)
selectedButton = getButtonFromLocation(evt.x, evt.y);
buttonDown = true;
g = getGraphics();
paint(g, paintSelected);
g.dispose();
break;
case Event.MOUSE_UP:
if (selectedButton == -1) break;
buttonDown = false;
if (selectedButton == getButtonFromLocation(evt.x, evt.y)) {
g = getGraphics();
paint(g, paintSelected);
g.dispose();
if (selectedButton>=0 && selectedButton<=12)
postEvent(new Event(this, evt.when,
Event.KEY_RELEASE, 0, 0,
(int)buttonTitle1[selectedButton],
evt.modifiers, null));
else
postEvent(new Event(this, evt.when, Event.KEY_RELEASE, 0, 0, 10, evt.modifiers, null));
}
selectedButton = -1;
break;
case Event.MOUSE_DRAG:
if (selectedButton == -1) break;
if (selectedButton == getButtonFromLocation(evt.x, evt.y)) {
if (buttonDown==false) {
buttonDown = true;
g = getGraphics();
paint(g, paintSelected);
g.dispose();
}
}
else {
if (buttonDown==true) {
buttonDown = false;
g = getGraphics();
paint(g, paintSelected);
g.dispose();
}
}
break;
case Event.KEY_ACTION:
case Event.KEY_ACTION_RELEASE:
case Event.KEY_RELEASE:
// If the enter key was pressed...
switch (evt.key) {
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
case '.':
value = value + (char)evt.key;
break;
case 'C':
case 'c':
value = "";
break;
case 'A':
case 'a':
break;
case 10:
entered = true;
break;
case 27:
getParent().postEvent(new Event(this, ESCAPED, null));
return true;
default:
return super.handleEvent( evt );
};
g = getGraphics();
drawButton(g, getButtonFromKey(evt.key), false);
g.dispose();
if (entered==true)
getParent().postEvent(new Event(this, ENTERED, null));
else
getParent().postEvent(new Event(this, MODIFIED, null));
break;
case Event.KEY_PRESS:
// If the enter key was pressed...
switch (evt.key) {
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
case '.':
case 'C':
case 'c':
case 'A':
case 'a':
case 10:
break;
default:
return super.handleEvent( evt );
};
g = getGraphics();