home *** CD-ROM | disk | FTP | other *** search
- // VRML Generator
- // (c) Justin Couch
- //
- // From Chapter 13: Late Night VRML 2.0 and Java
- //
- // A silent class that does the consistency checking for adding nodes in the
- // correct spot. If an incorrect node is attempted to be added then an
- // appropriate error message is posted.
-
- package ui;
-
- import java.awt.*;
- import vrml.external.Browser;
- import ui.dialogs.*;
- import VrmlScene;
- import VrmlTypes;
- import ui.VrmlTree;
- import ui.tree.VrmlTreeNode;
- import geometry.*;
- import exceptions.NoSelectedNodeException;
-
- public class VrmlCheck
- {
- private VrmlTree screen_data;
- private VrmlScene vrml_data;
- private VrmlBaseDialog[] dialog_list;
- private GeneralWarnDialog gen_warn;
-
- public VrmlCheck(Browser b, Frame parent, VrmlTree screen, VrmlScene data)
- {
- screen_data = screen;
- vrml_data = data;
-
- // create the warning dialog
- gen_warn = new GeneralWarnDialog(parent);
-
- // now put the dialog list together.
- createDialogs(parent);
-
- // the temporary hack until the static getBrowser method is
- // properly implemented
- for(int i = 0; i < VrmlTypes.NumberOfTypes; i ++)
- if(dialog_list[i] != null)
- dialog_list[i].setBrowser(b);
- }
-
- private void createDialogs(Frame parent)
- {
- dialog_list = new VrmlBaseDialog[VrmlTypes.NumberOfTypes];
-
- dialog_list[VrmlTypes.Group] =
- new GroupDialog(parent, screen_data, vrml_data);
- dialog_list[VrmlTypes.Transform] =
- new TransformDialog(parent, screen_data, vrml_data);
-
- dialog_list[VrmlTypes.Shape] =
- new ShapeDialog(parent, screen_data, vrml_data);
- dialog_list[VrmlTypes.Box] =
- new BoxDialog(parent, screen_data, vrml_data);
- dialog_list[VrmlTypes.Cone] =
- new ConeDialog(parent, screen_data, vrml_data);
- dialog_list[VrmlTypes.Cylinder] =
- new CylinderDialog(parent, screen_data, vrml_data);
- dialog_list[VrmlTypes.Sphere] =
- new SphereDialog(parent, screen_data, vrml_data);
-
- dialog_list[VrmlTypes.Appearance] =
- new AppearanceDialog(parent, screen_data, vrml_data);
- dialog_list[VrmlTypes.Material] =
- new MaterialDialog(parent, screen_data, vrml_data);
- dialog_list[VrmlTypes.TextureTransform] =
- new TextureTransformDialog(parent, screen_data, vrml_data);
- dialog_list[VrmlTypes.ImageTexture] =
- new ImageTextureDialog(parent, screen_data, vrml_data);
- dialog_list[VrmlTypes.MovieTexture] =
- new MovieTextureDialog(parent, screen_data, vrml_data);
- }
-
- public void checkNode(int node_type)
- {
- VrmlObject parent;
-
- try
- {
- parent = screen_data.getVrmlParent();
- }
- catch(NoSelectedNodeException e)
- {
- gen_warn.show("You have not selected a node to add to");
- return;
- }
-
- if(node_type <= VrmlTypes.Switch)
- checkGroupingNode(node_type, parent);
- else if(node_type <= VrmlTypes.WorldInfo)
- checkCommonNode(node_type, parent);
- else if(node_type <= VrmlTypes.VisibilitySensor)
- checkSensorNode(node_type, parent);
- else if(node_type <= VrmlTypes.Text)
- checkGeometryNode(node_type, parent);
- else if(node_type <= VrmlTypes.TextureCoordinate)
- checkGeoPropertyNode(node_type, parent);
- else if(node_type <= VrmlTypes.TextureTransform)
- checkAppearanceNode(node_type, parent);
- else if(node_type <= VrmlTypes.ScalarInterpolator)
- checkInterpolatorNode(node_type, parent);
- else
- checkBindableNode(node_type, parent);
- }
-
- private void checkGroupingNode(int node_type, VrmlObject parent)
- {
- String node_name = null;
-
- if(!(parent instanceof GroupingNode) && !(parent == null))
- {
- gen_warn.show("Need a grouping node to add a group to");
- return;
- }
-
- switch(node_type)
- {
- // Grouping Nodes
- case VrmlTypes.Anchor:
- node_name = "Anchor";
- break;
- case VrmlTypes.BillBoard:
- node_name = "Billboard";
- break;
- case VrmlTypes.Collision:
- node_name = "Collision";
- break;
- case VrmlTypes.Group:
- dialog_list[VrmlTypes.Group].show();
- break;
- case VrmlTypes.Transform:
- dialog_list[VrmlTypes.Transform].show();
- break;
-
- // Special Groups
- case VrmlTypes.Inline:
- node_name = "Inline";
- break;
- case VrmlTypes.LOD:
- node_name = "LOD";
- break;
- case VrmlTypes.Switch:
- node_name = "Switch";
- break;
- default:
- }
- }
-
- private void checkCommonNode(int node_type, VrmlObject parent)
- {
- if(!(parent instanceof GroupingNode) && !(parent == null))
- {
- gen_warn.show("Need a grouping node to add to");
- return;
- }
-
- switch(node_type)
- {
- // Common Nodes
- case VrmlTypes.AudioClip:
- break;
- case VrmlTypes.DirectionalLight:
- break;
- case VrmlTypes.PointLight:
- break;
- case VrmlTypes.Script:
- break;
- case VrmlTypes.Shape:
- dialog_list[VrmlTypes.Shape].show();
- break;
- case VrmlTypes.Sound:
- break;
- case VrmlTypes.SpotLight:
- break;
- case VrmlTypes.WorldInfo:
- break;
- default:
- }
- }
-
- private void checkSensorNode(int node_type, VrmlObject parent)
- {
- String node_name = null;
-
- if(!(parent instanceof GroupingNode))
- {
- gen_warn.show("Need a grouping node to add a Sensor to");
- return;
- }
- switch(node_type)
- {
- case VrmlTypes.CylinderSensor:
- node_name = "CylinderSensor";
- break;
- case VrmlTypes.PlaneSensor:
- node_name = "PlaneSensor";
- break;
- case VrmlTypes.ProximitySensor:
- node_name = "ProximitySensor";
- break;
- case VrmlTypes.SphereSensor:
- node_name = "SphereSensor";
- break;
- case VrmlTypes.TimeSensor:
- node_name = "TimeSensor";
- break;
- case VrmlTypes.TouchSensor:
- node_name = "TouchSensor";
- break;
- case VrmlTypes.VisibilitySensor:
- node_name = "VisibilitySensor";
- break;
- default:
- }
- }
-
- private void checkGeometryNode(int node_type, VrmlObject parent)
- {
- String node_name = null;
-
- // this is not a correct test for the geometric properties below.
- // need to fix this.
- if(!(parent instanceof Shape))
- {
- gen_warn.show("You need a Shape for the parent of geometry nodes");
- return;
- }
-
- // now that we have established that the parent is a shape we need to
- // check if it already has geometry set
- if(((Shape)parent).hasGeometry())
- {
- gen_warn.show("This Shape already has a geometry node allocated");
- return;
- }
-
- switch(node_type)
- {
- // Geometry
- case VrmlTypes.Box:
- dialog_list[VrmlTypes.Box].show();
- break;
- case VrmlTypes.Cone:
- dialog_list[VrmlTypes.Cone].show();
- break;
- case VrmlTypes.Cylinder:
- dialog_list[VrmlTypes.Cylinder].show();
- break;
- case VrmlTypes.ElevationGrid:
- node_name = "ElevationGrid";
- break;
- case VrmlTypes.Extrusion:
- node_name = "Extrusion";
- break;
- case VrmlTypes.IndexedFaceSet:
- node_name = "IndexedFaceSet";
- break;
- case VrmlTypes.IndexedLineSet:
- node_name = "IndexedLineSet";
- break;
- case VrmlTypes.PointSet:
- node_name = "PointSet";
- break;
- case VrmlTypes.Sphere:
- dialog_list[VrmlTypes.Sphere].show();
- break;
- case VrmlTypes.Text:
- node_name = "Text";
- break;
-
- default:
- }
- }
-
- private void checkGeoPropertyNode(int node_type, VrmlObject parent)
- {
- String node_name = null;
-
- // this is not a correct test for the geometric properties below.
- // need to fix this.
- if(!(parent instanceof Geometry))
- {
- System.out.println("Error not a piece of geometry for a parent");
- return;
- }
-
- switch(node_type)
- {
- // Geometric Properties
- case VrmlTypes.Color:
- break;
- case VrmlTypes.Coordinate:
- break;
- case VrmlTypes.Normal:
- break;
- case VrmlTypes.TextureCoordinate:
- break;
- default:
- }
- }
-
- private void checkAppearanceNode(int node_type, VrmlObject parent)
- {
- String node_name = null;
-
- switch(node_type)
- {
- // Appearance
- case VrmlTypes.Appearance:
- if(!(parent instanceof Shape))
- {
- gen_warn.show("Error not a Shape for a parent");
- return;
- }
- if(((Shape)parent).hasAppearance())
- {
- gen_warn.show("This Shape already has an Appearance");
- return;
- }
- dialog_list[VrmlTypes.Appearance].show();
- break;
- case VrmlTypes.FontStyle:
- break;
- case VrmlTypes.ImageTexture:
- if(!(parent instanceof Appearance))
- {
- gen_warn.show("You need an Appearance for a parent");
- return;
- }
- if(((Appearance)parent).hasTexture())
- {
- gen_warn.show("This Shape already has a Texture");
- return;
- }
- dialog_list[VrmlTypes.ImageTexture].show();
- break;
- case VrmlTypes.Material:
- if(!(parent instanceof Appearance))
- {
- gen_warn.show("You need an Appearance for a parent");
- return;
- }
- if(((Appearance)parent).hasMaterial())
- {
- gen_warn.show("This Shape already has a Material");
- return;
- }
- dialog_list[VrmlTypes.Material].show();
- break;
- case VrmlTypes.MovieTexture:
- if(!(parent instanceof Appearance))
- {
- gen_warn.show("You need an Appearance for a parent");
- return;
- }
- if(((Appearance)parent).hasTexture())
- {
- gen_warn.show("This Shape already has a Texture");
- return;
- }
- dialog_list[VrmlTypes.MovieTexture].show();
- break;
- case VrmlTypes.PixelTexture:
- if(!(parent instanceof Appearance))
- {
- gen_warn.show("You need an Appearance for a parent");
- return;
- }
- if(((Appearance)parent).hasTexture())
- {
- gen_warn.show("This Shape already has a Texture");
- return;
- }
- break;
- case VrmlTypes.TextureTransform:
- if(!(parent instanceof Appearance))
- {
- System.out.println("You need an Appearance for a parent");
- return;
- }
- if(((Appearance)parent).hasTextureTransform())
- {
- gen_warn.show("This Appearance already has a TextureTransform");
- return;
- }
- dialog_list[VrmlTypes.TextureTransform].show();
- break;
- default:
- }
- }
-
- private void checkInterpolatorNode(int node_type, VrmlObject parent)
- {
- String node_name = null;
-
- switch(node_type)
- {
- case VrmlTypes.ColorInterpolator:
- node_name = "ColorInterpolator";
- break;
- case VrmlTypes.CoordinateInterpolator:
- node_name = "CoordinateInterpolator";
- break;
- case VrmlTypes.NormalInterpolator:
- node_name = "NormalInterpolator";
- break;
- case VrmlTypes.OrientationInterpolator:
- node_name = "OrientationInterpolator";
- break;
- case VrmlTypes.PositionInterpolator:
- node_name = "PositionInterpolator";
- break;
- case VrmlTypes.ScalarInterpolator:
- node_name = "ScalarInterpolator";
- break;
- default:
- }
- }
-
- private void checkBindableNode(int node_type, VrmlObject parent)
- {
- String node_name = null;
-
- switch(node_type)
- {
- // Bindable nodes
- case VrmlTypes.BackGround:
- node_name = "BackGround";
- break;
- case VrmlTypes.Fog:
- node_name = "Fog";
- break;
- case VrmlTypes.NavigationInfo:
- node_name = "NavigationInfo";
- break;
- case VrmlTypes.Viewpoint:
- node_name = "Viewpoint";
- break;
- default:
- }
- }
-
- public void deleteNode()
- {
- VrmlTreeNode current = screen_data.selected;
- VrmlTreeNode parent = screen_data.getParent();
-
- // a null parent indicates the root node. Inform the user of this.
- // at the moment there is no backing out from this operation. This
- // needs to be done.
-
- if(parent == null)
- gen_warn.show("This operation is about to delete the whole scene!");
-
- screen_data.removeNode(parent);
-
- if(parent == null)
- vrml_data.deleteAll();
- else
- vrml_data.deleteNode(parent.type,
- parent.vrmlNode,
- current.type,
- current.vrmlNode);
- }
- }
-