home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch12
/
ui
/
dialogs
/
MaterialDialog.java
< prev
next >
Wrap
Text File
|
1997-01-02
|
5KB
|
219 lines
// VRML Generator
// (c) Justin Couch
//
// From Chapter 13: Late Night VRML 2.0 and Java
//
// The Transform node dialog.
package ui.dialogs;
import java.awt.*;
import ui.dialogs.VrmlBaseDialog;
import geometry.Material;
import ui.VrmlTree;
import VrmlScene;
import VrmlTypes;
import exceptions.NoSelectedNodeException;
public class MaterialDialog extends VrmlBaseDialog
{
private TextField ambient;
private TextField diffuse_x, diffuse_y, diffuse_z;
private TextField emissive_x, emissive_y, emissive_z;
private TextField shininess;
private TextField spec_x, spec_y, spec_z;
private TextField transparency;
public MaterialDialog(Frame parent, VrmlTree tree, VrmlScene data)
{
super(parent, "Edit Group Node");
vrml_data = data;
screen_data = tree;
content_panel.setLayout(new GridLayout(8, 1));
// translation fields
Panel p1 = new Panel();
p1.setLayout(new BorderLayout(15, 10));
p1.add("West", new Label("Ambient Intensity", Label.LEFT));
ambient = new TextField("0.2", 4);
p1.add("East", ambient);
content_panel.add(p1);
// diffuse Colour
Panel p3 = new Panel();
p3.setLayout(new BorderLayout(15, 10));
p3.add("West", new Label("Diffuse Colour", Label.LEFT));
Panel p4 = new Panel();
p4.setLayout(new GridLayout(1, 6));
// the 3 components.
diffuse_x = new TextField("0.8", 4);
diffuse_y = new TextField("0.8", 4);
diffuse_z = new TextField("0.8", 4);
p4.add(new Label("R: ", Label.RIGHT));
p4.add(diffuse_x);
p4.add(new Label("G: ", Label.RIGHT));
p4.add(diffuse_y);
p4.add(new Label("B: ", Label.RIGHT));
p4.add(diffuse_z);
p3.add("East", p4);
content_panel.add(p3);
// Emissive Colour
Panel p5 = new Panel();
p5.setLayout(new BorderLayout(15, 10));
p5.add("West", new Label("Emissive Colour", Label.LEFT));
Panel p6 = new Panel();
p6.setLayout(new GridLayout(1, 6));
// the 4 components.
emissive_x = new TextField("0", 4);
emissive_y = new TextField("0", 4);
emissive_z = new TextField("0", 4);
p6.add(new Label("R: ", Label.RIGHT));
p6.add(emissive_x);
p6.add(new Label("G: ", Label.RIGHT));
p6.add(emissive_y);
p6.add(new Label("B: ", Label.RIGHT));
p6.add(emissive_z);
p5.add("East", p6);
content_panel.add(p5);
// specular Colour
Panel p7 = new Panel();
p7.setLayout(new BorderLayout(15, 10));
p7.add("West", new Label("Specular Colour", Label.LEFT));
Panel p8 = new Panel();
p8.setLayout(new GridLayout(1, 6));
// the 3 components.
spec_x = new TextField("0", 4);
spec_y = new TextField("0", 4);
spec_z = new TextField("0", 4);
p8.add(new Label("R: ", Label.RIGHT));
p8.add(spec_x);
p8.add(new Label("G: ", Label.RIGHT));
p8.add(spec_y);
p8.add(new Label("B: ", Label.RIGHT));
p8.add(spec_z);
p7.add("East", p8);
content_panel.add(p7);
// Shininess
Panel p9 = new Panel();
p9.setLayout(new BorderLayout(15, 10));
p9.add("West", new Label("Shininess", Label.LEFT));
shininess = new TextField("0.2", 4);
p9.add("East", shininess);
content_panel.add(p9);
// Transparency
Panel p10 = new Panel();
p10.setLayout(new BorderLayout(15, 10));
p10.add("West", new Label("Transparency", Label.LEFT));
transparency = new TextField("0", 4);
p10.add("East", transparency);
content_panel.add(p10);
pack();
}
// read all the information back out of the panel and pass it
// to the appropriate place.
public boolean applyInformation()
{
String str;
float diff_r, diff_g, diff_b;
float emis_r, emis_g, emis_b;
float spec_r, spec_g, spec_b;
float amb;
float shine;
float trans;
Material material;
// first get the basic node constructed
material = new Material(browser);
str = name.getText();
if(str.equals(""))
material.name = null;
else
material.name = new String(str);
// now we update the fields
// ambient intensity
amb = Float.valueOf(ambient.getText()).floatValue();
if(amb != 0.2f)
material.set_ambientIntensity(amb);
// diffuseColor
diff_r = Float.valueOf(diffuse_x.getText()).floatValue();
diff_g = Float.valueOf(diffuse_y.getText()).floatValue();
diff_b = Float.valueOf(diffuse_z.getText()).floatValue();
if((diff_r != 0.8f) || (diff_g != 0.8f) || (diff_b != 0.8f))
material.set_diffuseColor(diff_r, diff_g, diff_b);
// emissiveColor
emis_r = Float.valueOf(emissive_x.getText()).floatValue();
emis_g = Float.valueOf(emissive_y.getText()).floatValue();
emis_b = Float.valueOf(emissive_z.getText()).floatValue();
if((emis_r != 0) || (emis_g != 0) || (emis_b != 0))
material.set_emissiveColor(emis_r, emis_g, emis_b);
// shininess
shine = Float.valueOf(shininess.getText()).floatValue();
if(shine != 0.2f)
material.set_shininess(shine);
// specularColor
spec_r = Float.valueOf(spec_x.getText()).floatValue();
spec_g = Float.valueOf(spec_y.getText()).floatValue();
spec_b = Float.valueOf(spec_z.getText()).floatValue();
if((spec_r != 0) || (spec_g != 0) || (spec_b != 0))
material.set_specularColor(spec_r, spec_g, spec_b);
// transparency
shine = Float.valueOf(shininess.getText()).floatValue();
if(shine != 0)
material.set_shininess(shine);
try
{
vrml_data.addNode(VrmlTypes.Material, material);
}
catch (NoSelectedNodeException e)
{
System.out.println("No node selected");
}
return false;
}
}