/** This class creates the components of the User Interface Panel. It
handles the events that include changes made to any of the input fields.
**/
class InterfacePanel extends Panel
{
Choice choice;
// Labels used in the Interface
Label choiceLabel,label,xcoor,ycoor,zcoor,distance,blob1,Xlabel,Ylabel,Zlabel,UDefLabel,Xlabel2,Ylabel2,Zlabel2,Ulabel3,blank1,blank2,blank3,blank4,blob2;
// Textfields used in the interface
TextField dxvalue,dyvalue,dzvalue,radius1,radius2,VtextFieldRes,XtextField,YtextField,ZtextField;
CheckboxGroup cbg;
Checkbox cb1,cb2;
PSPA mycontroller;
public InterfacePanel(PSPA panelControl)
{
super();
mycontroller = panelControl;
// Instantiate the components
Range();
PopupMenu();
UserDef();
//Add Components to the Applet
//Set the Layout Manager and constraints
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridbag);
c.fill = GridBagConstraints.BOTH;
// Add the title to the Applet
Label Title = new Label("BLOBBY MODEL EXAMPLE",Label.CENTER);
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(Title, c);
add(Title);
Label TSpace = new Label();
gridbag.setConstraints(TSpace, c);
add(TSpace);
// Add labels for titles of range control panel
c.gridwidth = 1;
c.weightx = 1.0;
Label Space = new Label();
gridbag.setConstraints(Space, c);
add(Space);
Label Space1 = new Label();
gridbag.setConstraints(Space1, c);
add(Space1);
gridbag.setConstraints(xcoor, c);
add(xcoor);
Label Space2 = new Label();
gridbag.setConstraints(Space2, c);
add(Space2);
gridbag.setConstraints(ycoor, c);
add(ycoor);
Label Space3 = new Label();
gridbag.setConstraints(Space3, c);
add(Space3);
c.gridwidth = GridBagConstraints.RELATIVE;
gridbag.setConstraints(zcoor, c);
add(zcoor);
Label Rlabel4 = new Label();
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(Rlabel4, c);
add(Rlabel4);
c.gridwidth = 1;
Label USpace = new Label();
gridbag.setConstraints(USpace, c);
add(USpace);
gridbag.setConstraints(distance, c);
add(distance);
c.weightx = 1.0;
gridbag.setConstraints(dxvalue, c);
add(dxvalue);
gridbag.setConstraints(blank1, c);
add(blank1);
gridbag.setConstraints(dyvalue, c);
add(dyvalue);
gridbag.setConstraints(blank2, c);
add(blank2);
c.gridwidth = GridBagConstraints.RELATIVE;
gridbag.setConstraints(dzvalue, c);
add(dzvalue);
Label distance1 = new Label();
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(distance1, c);
add(distance1);
c.gridwidth = 1;
Label VSpace = new Label();
gridbag.setConstraints(VSpace, c);
add(VSpace);
gridbag.setConstraints(blob1, c);
add(blob1);
gridbag.setConstraints(radius1, c);
add(radius1);
gridbag.setConstraints(blank3, c);
add(blank3);
gridbag.setConstraints(blank4, c);
add(blank4);
gridbag.setConstraints(blob2, c);
add(blob2);
gridbag.setConstraints(radius2, c);
add(radius2);
c.gridwidth = GridBagConstraints.RELATIVE;
Label Vlabel1 = new Label();
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(Vlabel1, c);
add(Vlabel1);
Label Vlabel2 = new Label();
gridbag.setConstraints(Vlabel2, c);
add(Vlabel2);
Ulabel3 = new Label("",Label.CENTER);
c.fill = GridBagConstraints.HORIZONTAL;
}
//Create the components for the UV range control
void Range()
{
xcoor = new Label("X-coordinate");
ycoor = new Label("Y-coordinate");
zcoor = new Label("Z-coordinate");
distance = new Label("Distance");
blob1 = new Label("Blob1's radius");
blob2 = new Label("Blob2's radius");
blank1 = new Label(" ");
blank2 = new Label(" ");
blank3 = new Label(" ");
blank4 = new Label(" ");
dxvalue = new TextField(3);
dxvalue.setEditable(true);
dyvalue = new TextField(3);
dyvalue.setEditable(true);
dzvalue = new TextField(3);
dzvalue.setEditable(true);
radius1 = new TextField(3);
radius1.setEditable(true);
radius2 = new TextField(3);
radius2.setEditable(true);
}
//Create the components for the Choice Menu of predefined surfaces
void PopupMenu()
{
cbg = new CheckboxGroup();
cb1 = new Checkbox("Pre-defined surfaces", cbg,
true);
cb2 = new Checkbox("User-defined surfaces", cbg,
false);
choice = new Choice();
addChoice(choice, "Sphere");
addChoice(choice, "Torus");
addChoice(choice, "Ellipsoid");
}
public void addChoice(Choice popup, String title)
{
popup.addItem(title);
}
//Create the components for the entry of user-defined surfaces
void UserDef()
{
//p2 = new Panel();
Xlabel = new Label("X-Coordinate");
Ylabel = new Label("Y-Coordinate");
Zlabel = new Label("Z-Coordinate");
XtextField = new TextField(30);
YtextField = new TextField(30);
ZtextField = new TextField(30);
}
// Interpret the various events and execute appropriate actions
public boolean action(Event e, Object arg)
{
double value = 0;
int res = 0;
// action for text fields
if (e.target instanceof TextField)
{
mycontroller.dx = Integer.parseInt(dxvalue.getText());
mycontroller.dy = Integer.parseInt(dyvalue.getText());
mycontroller.dz = Integer.parseInt(dzvalue.getText());
mycontroller.r1 = Integer.parseInt(radius1.getText());
mycontroller.r2 = Integer.parseInt(radius2.getText());
mycontroller.draw(e, 1);
}
return true;
}
}