Example #1
0
  public void draw(DrawModel d) {
    view.detach();
    rotation.removeAllChildren();
    drawModel = d;
    if (drawModel.getPicture() == null) return;
    Integer i = 0;
    for (VisualShape v : drawModel.getPicture()) {
      TransformGroup shapeGroup = new TransformGroup();
      rotation.addChild(shapeGroup);
      BranchGroup faces = v.getFaces2(BranchGroup.class);
      BranchGroup edges = v.getEdges2(BranchGroup.class);
      BranchGroup text = v.getText2(BranchGroup.class);
      if (faces == null && edges == null) continue;
      i++;
      if (faces != null) {
        faces.detach();
        rotation.addChild(faces);
        faces.setPickable(true);
        faces.setUserData(v);
        faces.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        faces.setName(i.toString());
      }
      if (edges != null) {
        edges.detach();
        rotation.addChild(edges);
        edges.setPickable(true);
        edges.setUserData(v);
        edges.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        edges.setName(i.toString());
      }

      if (text != null) {
        text.detach();
        rotation.addChild(text);
        text.setPickable(false);
        if (text instanceof BranchGroup) {
          BranchGroup bg = (BranchGroup) text;
          for (int j = 0; j < bg.numChildren(); j++) {
            Node child = bg.getChild(j);
            if (child instanceof TransformGroup) {
              TransformGroup tg = (TransformGroup) child;
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
              textLabels.add(tg);
            }
          }
        }

        //        		edges.setUserData(v);
        //        		edges.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        //         		edges.setName(i.toString());
      }
    }
    root.addChild(view);
  }
Example #2
0
  public void showCategory(String categoryName) {
    if (displayedMenuItems.numChildren() != 0) displayedMenuItems.removeAllChildren();

    BranchGroup category = menuBranches.get(categoryName);
    displayedMenuItems.addChild(category);
    Enumeration<MenuItem> children = category.getAllChildren();
    while (children.hasMoreElements()) {
      MenuItem child = (MenuItem) children.nextElement();
      child.armBehavior();
    }
  }
Example #3
0
 public void createMenuItems(Node<MenuData.MenuItemData> tree, String category) {
   if (tree.data == null) {
     // ROOT
     BranchGroup catBrGr = new BranchGroup();
     catBrGr.setCapability(BranchGroup.ALLOW_DETACH);
     menuBranches.put("root", catBrGr);
     menuItems.put("root", new ArrayList<MenuItem>());
     for (Node<MenuData.MenuItemData> child : tree.children) {
       createMenuItems(child, "root");
     }
     System.out.println("placing menu items for root");
     placeMenuItems(catBrGr.getAllChildren(), catBrGr.numChildren(), DEFAULT_GAP);
     return;
   }
   if (tree.data.type == MenuItemType.CATEGORY) {
     // create category
     System.out.println("created category " + tree.data.name);
     BranchGroup catBrGr = new BranchGroup();
     catBrGr.setCapability(BranchGroup.ALLOW_DETACH);
     menuBranches.put(tree.data.name, catBrGr);
     menuItems.put(tree.data.name, new ArrayList<MenuItem>());
     //			ModelObject model = null;
     //			try {
     //				model = ModelFactory.loadModel(tree.data.modelFileName, tree.data.modelType);
     //			} catch (Exception e) {
     //				// TODO Auto-generated catch block
     //				e.printStackTrace();
     //			}
     BottleObject model = new BottleObject();
     MenuItem ciao;
     if (tree.data.offset == null) {
       ciao = createMenuItem(tree.data.name, tree.data.name, model, true, tree.data.glassColor);
     } else {
       System.out.println("adding offset and scaling");
       ciao =
           createMenuItem(
               tree.data.name,
               tree.data.name,
               model,
               true,
               tree.data.glassColor,
               tree.data.scaling,
               tree.data.offset);
     }
     menuBranches.get(category).addChild(ciao);
     menuItems.get(category).add(ciao);
     // continue walking
     if (tree.children == null) return;
     for (Node<MenuData.MenuItemData> child : tree.children) {
       createMenuItems(child, tree.data.name);
     }
     ArrowObject arrObj = new ArrowObject();
     Transform3D arrAdj = new Transform3D();
     arrAdj.rotX(Math.PI / 2);
     arrAdj.rotY(Math.PI / 2);
     arrAdj.rotZ(Math.PI / 2);
     arrObj.transGroup.setTransform(arrAdj);
     MenuItem back = createMenuItem(category, "Back", arrObj, true, null);
     menuBranches.get(tree.data.name).addChild(back);
     System.out.println("placing menu items for category: " + tree.data.name);
     placeMenuItems(catBrGr.getAllChildren(), catBrGr.numChildren(), DEFAULT_GAP);
   } else { // tree.data.type == MenuItemType.ITEM
     // create item
     System.out.println("created item " + tree.data.name);
     //			ModelObject model = null;
     //			try {
     //				model = ModelFactory.loadModel(tree.data.modelFileName, tree.data.modelType);
     //			} catch (Exception e) {
     //				// TODO Auto-generated catch block
     //				e.printStackTrace();
     //			}
     BottleObject model = new BottleObject();
     MenuItem ciao;
     if (tree.data.offset == null)
       ciao = createMenuItem(tree.data.name, tree.data.name, model, false, tree.data.glassColor);
     else
       ciao =
           createMenuItem(
               tree.data.name,
               tree.data.name,
               model,
               false,
               tree.data.glassColor,
               tree.data.scaling,
               tree.data.offset);
     menuBranches.get(category).addChild(ciao);
     menuItems.get(category).add(ciao);
   }
 }