Examples of MTComponent


Examples of org.mt4j.components.MTComponent

        if (userData1 instanceof IPhysicsComponent  && userData2 instanceof IPhysicsComponent) { //Check for ball/star collision
          IPhysicsComponent physObj1 = (IPhysicsComponent) userData1;
          IPhysicsComponent physObj2 = (IPhysicsComponent) userData2;
//          System.out.println("Collided: " + mt4jObj1 + " with " + mt4jObj2);
          if (physObj1 instanceof MTComponent && physObj2 instanceof MTComponent) {
            MTComponent comp1 = (MTComponent) physObj1;
            MTComponent comp2 = (MTComponent) physObj2;

            //Check if one of the components is the BALL
            MTComponent ball = isHit("ball", comp1, comp2);
            final MTComponent theBall = ball;
           
            //Check if one of the components is the GOAL
            MTComponent goal1 = isHit("goal1", comp1, comp2);
            MTComponent goal2 = isHit("goal2", comp1, comp2);
           
            //Check if a puck was involved
            MTComponent bluePuck = isHit("blue", comp1, comp2);
            MTComponent redPuck = isHit("red", comp1, comp2);
           
            //Check if a border was hit
            MTComponent border = null;
            if (comp1.getName() != null && comp1.getName().startsWith("border")){
              border = comp1;
            }else if (comp2.getName() != null && comp2.getName().startsWith("border")){
              border = comp2;
            }
View Full Code Here

Examples of org.mt4j.components.MTComponent

    }
  }
  */
 
  private MTComponent isHit(String componentName, MTComponent comp1, MTComponent comp2){
    MTComponent hitComp = null;
    if (comp1.getName() != null && comp1.getName().equalsIgnoreCase(componentName)){
      hitComp = comp1;
    }else if (comp2.getName() != null && comp2.getName().equalsIgnoreCase(componentName)){
      hitComp = comp2;
    }
View Full Code Here

Examples of org.mt4j.components.MTComponent

       || node instanceof SVGSVGElement
       || node instanceof SVGOMSVGElement
      ){
//        SVGOMGElement gElem = (SVGOMGElement)node;
        SVGElement gElem = (SVGElement)node;
        MTComponent group = new MTComponent(pa);
        group.setName(gElem.getTagName());

//        Element viewPort = gElem.getViewportElement();
//        logger.debug("Viewport " + viewPort.getNodeName());

        //Set the <g> group to composite, meaning that it will
        //be returned at picking, when one of the children gets picked
        group.setComposite(true);

        group.setLocalMatrix(currentLocalTransformMatrix);
       
        //IF its <svg> element get the transform
        //(to honor the viewBox and the width/height attributes
        if (node instanceof SVGOMSVGElement ){
          SVGOMSVGElement svgGom = ((SVGOMSVGElement)node);
          Element viewPort = svgGom.getViewportElement();
          if (viewPort != null)
            logger.debug("Viewport " + viewPort.getNodeName());
         
//          SVGMatrix mat = svgGom.getScreenCTM();
         
          SVGAnimatedLength widthA = svgGom.getWidth();
          SVGAnimatedLength heightA = svgGom.getHeight();
         
          SVGLength w = widthA.getBaseVal();
          float width = w.getValue();
         
          SVGLength h = heightA.getBaseVal();
          float height = h.getValue();
         
          logger.debug("-> SVG Width: " + width + " Height: " + height);
         
         
          SVGMatrix mat = svgGom.getCTM();
          /*
          logger.debug("mat: " + mat.toString());
          logger.debug(mat.getA());
          logger.debug(mat.getB());
          logger.debug(mat.getC());
          logger.debug(mat.getD());
          logger.debug(mat.getE());
          logger.debug(mat.getF());
          SVGRect bbox = svgGom.getBBox();
          logger.debug("BBOx: X:" + bbox.getX() + " Y:" + bbox.getY() + " Width:" + bbox.getWidth() + " Height:" + bbox.getHeight());
          */
         
          //Hack, because if no width/height is specified default of 1.0
          //is assumed by batik -> things may get scaled too small
          if ( !(width == 1 && height == 1) ){
            currentLocalTransformMatrix = new Matrix(mat.getA(), mat.getC(),   0, mat.getE(),
                                   mat.getB(), mat.getD(),   0, mat.getF(),
                                   0,       0,       1,       0,
                                   0,       0,       0,       1
            );
            //logger.debug("Matrix: " + currentLocalTransformMatrix);
            group.setLocalMatrix(currentLocalTransformMatrix);
          }
        }

        //Make the group pickable and manipulatable
        group.setPickable(true);
       
        group.registerInputProcessor(new DragProcessor(pa));
        group.setGestureAllowance(DragProcessor.class, true);
        group.addGestureListener(DragProcessor.class, (IGestureEventListener)defaultDragAction);
       
        group.registerInputProcessor(new RotateProcessor(pa));
        group.addGestureListener(RotateProcessor.class, defaultRotateAction);
       
        group.registerInputProcessor(new ScaleProcessor(pa));
        group.addGestureListener(ScaleProcessor.class,  defaultScaleAction);
       
        ArrayList<MTComponent> groupChildren = new ArrayList<MTComponent>();
        //Traverse the children and add them to a new arraylist
        traverseChildren(gElem, groupChildren);
       
        MTComponent[] childComps = (MTComponent[])groupChildren.toArray(new MTComponent[groupChildren.size()]);
        //Add the children to the group
        group.addChildren(childComps);
        //Add the group to the arraylist of the parent
        comps.add(group);
      }else{//If NOT GROUP
        if (node instanceof SVGGraphicsElement){
          SVGGraphicsElement svgGfxElem = (SVGGraphicsElement)node;
          //IF node isnt a group node just add it to the passed in comps arraylist
          try{
            //Create a component from the graphicsnode and add it to the parents arraylist
            MTComponent liveComponent = handleGraphicsNode(svgGfxElem);
            if (liveComponent != null){
              comps.add(liveComponent);
            }
          }catch(Exception e){
            logger.error("Error handling svg node: " + svgGfxElem.getTagName());
View Full Code Here

Examples of org.mt4j.components.MTComponent

 
  /**
   * Adds the to scene.
   */
  public void addToScene(){
    MTComponent cursorTraceContainer = null;
    MTCanvas canvas = scene.getCanvas();
   
    /*
    //Re-use cursor trace group which is always on top for this menu
    MTComponent[] children = canvas.getChildren();
View Full Code Here

Examples of org.mt4j.components.MTComponent

 
  /**
   * Removes the from scene.
   */
  public void removeFromScene(){
    MTComponent cursorTraceContainer = null;
    MTCanvas canvas = scene.getCanvas();
   
    /*
    //Re-use cursor trace group which is always on top for this menu
    MTComponent[] children = canvas.getChildren();
View Full Code Here

Examples of org.mt4j.components.MTComponent

   * @param gfxElem the gfx elem
   *
   * @return the mT base component
   */
  private MTComponent handleGraphicsNode(SVGGraphicsElement gfxElem){
      MTComponent returnComp = null;
//      logger.debug("Handle Element: " + gfxElem.getTagName());
     
      //Print all css properties and values
//      logger.debug("Style Css Text: " + style.getCssText());
     
      // SVG Defaults \\
      float fillR       = 255;
      float fillG       = 255;
      float fillB       = 255;
      boolean noFill     = false;
      float strokeR     = 0;
      float strokeG     = 0;
      float strokeB     = 0;
      float strokeWidth   = 1.0f;
      boolean noStroke     = false;
      float strokeOpacity   = 1;
      float fillOpacity     = 1;
      int windingRule     = GLU.GLU_TESS_WINDING_NONZERO;
      // SVG Defaults \\
     
     
      // Opacity, not as a style attribute but a separate
      // as group opacity doesnt get computed right, so we
      // mannually track it on a stack
      float opacity = opacityStack.peek().floatValue();
      //logger.debug("INHERITED OPACITY: " + opacity);
     
     
      // FILL-RULE \\
      Value fillRuleValue = CSSUtilities.getComputedStyle(gfxElem, SVGCSSEngine.FILL_RULE_INDEX);
      String fillRule = fillRuleValue.getStringValue();
      if (fillRule.equalsIgnoreCase("nonzero")){
        windingRule = GLU.GLU_TESS_WINDING_NONZERO;
      }else if (fillRule.equalsIgnoreCase("evenodd")){
        windingRule = GLU.GLU_TESS_WINDING_ODD;
      }else{
        windingRule = GLU.GLU_TESS_WINDING_NONZERO;
      }
      //logger.debug("fillRule: " + fillRule);
     
     
      // Fill Opacity \\
      Value fillOpacValue = CSSUtilities.getComputedStyle(gfxElem, SVGCSSEngine.FILL_OPACITY_INDEX);
      float computedfillOpac = PaintServer.convertOpacity(fillOpacValue);
      fillOpacity = computedfillOpac;
      //Multiplicate inherited opacity with this components opacities
      fillOpacity   *= opacity;
      //Save for eventual lineargradient creation later that needs the not interpolated value
      float originalFillOpacity = fillOpacity;
      //logger.debug("fill opacity unnormalized: " + fillOpacity);
     
     
      // Fill java.awt.Color \\
      Value fillIndexValue = CSSUtilities.getComputedStyle(gfxElem, SVGCSSEngine.FILL_INDEX);
      Object fill = SVGLoader.getFillOrStroke(gfxElem, fillIndexValue, fillOpacity, ctx);
      SVGOMLinearGradientElement linearGradient = null;
      SVGOMRadialGradientElement radialGradient = null;
      if (fill instanceof java.awt.Color) {
        java.awt.Color color = (Color) fill;
        fillR = color.getRed();
        fillG = color.getGreen();
        fillB = color.getBlue();
        fillOpacity = color.getAlpha();
        noFill = false;
        //logger.debug("Fill: " + color +  " a=" + fillOpacity);
      }else if (fill instanceof SVGOMLinearGradientElement) {
            //TODO cache gradients so dass man nicht immer neu den gleichen
            //machen muss!
        linearGradient = (SVGOMLinearGradientElement) fill;
        noFill = false;
      }else if (fill instanceof SVGOMRadialGradientElement) {
      //TODO!! //FIXME TEST
        radialGradient = (SVGOMRadialGradientElement)fill;
        noFill = false;
      }else{
        noFill = true;
      }
     
     
      // Stroke Opacity \\
      Value strokeOpacValue = CSSUtilities.getComputedStyle(gfxElem, SVGCSSEngine.STROKE_OPACITY_INDEX);
      float computedStrokeOpacity = PaintServer.convertOpacity(strokeOpacValue);
      strokeOpacity = computedStrokeOpacity;
      // Multiplicate inherited opacity with this components group opacities
      strokeOpacity *= opacity;
     
     
      // Stroke java.awt.Color \\
      Value strokeIndexValue = CSSUtilities.getComputedStyle(gfxElem, SVGCSSEngine.STROKE_INDEX);
      Object stroke = SVGLoader.getFillOrStroke(gfxElem, strokeIndexValue, strokeOpacity, ctx);
      if (stroke instanceof java.awt.Color) {
        java.awt.Color color = (Color) stroke;
        strokeR = color.getRed();
        strokeG = color.getGreen();
        strokeB = color.getBlue();
        strokeOpacity = color.getAlpha();
        noStroke = false;
      }else{
        noStroke = true;
        strokeR = fillR;
        strokeG = fillG;
        strokeB = fillB;
      }
     
     
      // Stroke Width \\
      Stroke s = PaintServer.convertStroke(gfxElem);
      if (s != null){
        if (s instanceof BasicStroke) {
          BasicStroke basicStroke = (BasicStroke) s;
          strokeWidth = basicStroke.getLineWidth();
        }
      }else{
        strokeWidth = 0.0f;
        noStroke = true;
      }
     
     /*
     logger.debug("Fill COL: " + fillR + " " + fillG + " " + fillB + " " fillopacity);
     logger.debug("STROKE COL: " + strokeR + " " + strokeG + " " + strokeB + " " strokeOpacity);
     */
     
      // CHECK WHAT KIND OF GRAPHICS ELEMENT IT IS AND CREATE IT \\
      if (gfxElem instanceof SVGOMPathElement){
        SVGOMPathElement pathElem = (SVGOMPathElement)gfxElem;
       
        //FIXME handle clip-paths in the future
        if (isUnderClipPath(pathElem)){
          logger.error("Discarding clip-path path element. Not implemented.");
          return null;
        }
       
        //Create the shape
        AbstractShape pathComp = getLivePathComponent(pathElem, noFill, windingRule);
       
        try{
          pathComp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = pathComp;
      }else if (gfxElem instanceof SVGOMPolygonElement){
        SVGOMPolygonElement polygonElem = (SVGOMPolygonElement)gfxElem;
       
        //Create the shape
        AbstractShape comp = getLivePolygonComponent(polygonElem, noFill, windingRule);
               
        try{
          comp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMPolylineElement){
        SVGOMPolylineElement polyLineElem = (SVGOMPolylineElement)gfxElem;
       
        //Create Vertex[] from points
        SVGPointList pointList = polyLineElem.getPoints();
        Vertex[] vertices = new Vertex[pointList.getNumberOfItems()];
        for (int i = 0; i < pointList.getNumberOfItems(); i++) {
        SVGPoint p = pointList.getItem(i);
        vertices[i] = new Vertex(p.getX(), p.getY(),0);
        }
       
        //Create the shape
        AbstractShape comp = createPoly(vertices);
       
        try{
          comp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMRectElement){
        SVGOMRectElement rectElem = (SVGOMRectElement)gfxElem;
        if (isUnderClipPath(rectElem)){
          logger.error("discarding clip-path Rect");
          return null;
        }
       
        float x     = rectElem.getX().getBaseVal().getValue();
        float y     = rectElem.getY().getBaseVal().getValue();
        float width   = rectElem.getWidth().getBaseVal().getValue();
        float height   = rectElem.getHeight().getBaseVal().getValue();
        float rx     = rectElem.getRx().getBaseVal().getValue();
        float ry     = rectElem.getRy().getBaseVal().getValue();
       
        AbstractShape comp;
        //Create a normal rectangle or a round rectangle
        if (rx != 0.0f || ry != 0.0f){
          if (rx > width/2 )
            rx = width/2;
          if (ry > height/2 )
            ry = height/2;
          comp = new MTRoundRectangle(x,y,0, width,height,rx, ry, pa);
        }else{
          comp = new MTRectangle(x,y, width,height, pa);
        }
       
        try{
          comp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMEllipseElement){
        SVGOMEllipseElement ellipseElem = (SVGOMEllipseElement)gfxElem;
        float cx = ellipseElem.getCx().getBaseVal().getValue();
        float cy = ellipseElem.getCy().getBaseVal().getValue();
        float r  = ellipseElem.getRx().getBaseVal().getValue();
        float r2 = ellipseElem.getRy().getBaseVal().getValue();
       
        Vertex middlePoint = new Vertex(cx,cy,0);
        //Apply transformation, transform centerpoint and the radii
        try{
          middlePoint.transform(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
       
        //somehow the circle radii need to be doubled
        //or else theyre too small => processing bug?
//        r*=2;
//        r2*=2;
        MTEllipse comp = new MTEllipse(pa, middlePoint, r, r2);
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMCircleElement){
        SVGOMCircleElement circleElem = (SVGOMCircleElement)gfxElem;
        float cx = circleElem.getCx().getBaseVal().getValue();
        float cy = circleElem.getCy().getBaseVal().getValue();
        float r = circleElem.getR().getBaseVal().getValue();
        float r2 = circleElem.getR().getBaseVal().getValue();
       
        Vertex middlePoint = new Vertex(cx,cy,0);
        //Apply transformation, transform centerpoint and the radii
        try{
          middlePoint.transform(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
       
        //somehow the circle radii need to be doubled
        //or else theyre too small => processing bug?
//        r*=2;
//        r2*=2;
        MTEllipse comp = new MTEllipse(pa, middlePoint, r, r2);
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMLineElement){
        SVGOMLineElement line = (SVGOMLineElement)gfxElem;
        float x1 = line.getX1().getBaseVal().getValue();
        float y1 = line.getY1().getBaseVal().getValue();
        float x2 = line.getX2().getBaseVal().getValue();
        float y2 = line.getY2().getBaseVal().getValue();
        //logger.debug("Line x1: " + x1 + ",y1:" + y1 + ",x2:" + x2 + ",y2:" + y2);
       
        MTLine comp = new MTLine(pa, x1,y1 ,x2,y2);
      
        try{
          comp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMClipPathElement){
      }else if (gfxElem instanceof SVGOMDefsElement){
      }else if (gfxElem instanceof SVGOMMaskElement){
      }else if (gfxElem instanceof SVGOMSwitchElement){
      }else if (gfxElem instanceof SVGOMFlowRootElement){
      }else if (gfxElem instanceof SVGURIReferenceGraphicsElement){
      }else if (gfxElem instanceof BindableElement){
      }else if (gfxElem instanceof SVGOMForeignObjectElement){
      }else if (gfxElem instanceof SVGOMToBeImplementedElement){
      }
     
      //Do the finishing touch of the svg graphics element
      if (returnComp != null){
        returnComp.setName(gfxElem.getTagName());
       
        //Set style infos
        if (returnComp instanceof AbstractVisibleComponent){
          AbstractVisibleComponent comp = (AbstractVisibleComponent)returnComp;
          //Set Fill
View Full Code Here

Examples of org.mt4j.components.MTComponent

    this.addGestureListener(RotateProcessor.class, new DefaultRotateAction());
    this.registerInputProcessor(new ScaleProcessor(applet));
    this.addGestureListener(ScaleProcessor.class, new DefaultScaleAction());
   
    SVGLoader loader = new SVGLoader(applet);
    MTComponent svg = loader.loadSvg(fileName);
    this.addChild(svg);
   
   
    //so lange MTSvg noch nicht an einem vater h�ngt und transform=identity, ist die world width die
    //parent relative width (und local width?)
View Full Code Here

Examples of org.mt4j.components.MTComponent

  private void setPickableRecursive(MTComponent current, boolean pickable){
    if (!current.equals(this))
        current.setPickable(pickable);
    MTComponent[] children = current.getChildren();
    for (int i = 0; i < children.length; i++) {
      MTComponent child = children[i];
      setPickableRecursive(child, pickable);
    }
  }
View Full Code Here

Examples of org.mt4j.components.MTComponent

    //Add a scene to the mt application
    this.scene = new DummyScene(app, "Dummy Scene");
    app.addScene(scene);
   
    //Set up components
    parent = new MTComponent(app);
    getCanvas().addChild(parent);
  }
View Full Code Here

Examples of org.mt4j.components.MTComponent

    newTextFieldSvg.translate(new Vector3D(10,5,0));

    newTextFieldSvg.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
          if (arg0.getSource() instanceof MTComponent){
            MTComponent clickedComp = (MTComponent)arg0.getSource();

            switch (arg0.getID()) {
            case TapEvent.BUTTON_CLICKED:
              //should always be keyboard
              MTComponent parent = clickedComp.getParent();
              if (parent instanceof MTTextKeyboard){
                MTTextKeyboard keyboard = (MTTextKeyboard)parent;

                //Remove old Textfield from keyboard if there is any
                if (textInputListener != null){
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.