Examples of MTApplication


Examples of org.mt4j.MTApplication

   
    final Container content = this.getContentPane();
    this.setLayout(new BorderLayout());
       
    //Create our mt4j applet
        final MTApplication instance = new TestMTApplication();
        instance.frame = this; //Important for registering the Windows 7 Touch input
        instance.init();
       
        JPanel panel1 = new JPanel(new FlowLayout());
        content.add(panel1, BorderLayout.WEST);
      
        JButton e2 = new JButton("Clear");
        e2.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        if (instance.getCurrentScene() != null){
          instance.invokeLater(new Runnable() {
            public void run() {
              MTComponent[] ch = instance.getCurrentScene().getCanvas().getChildren();
              for (int i = 0; i < ch.length; i++) {
                MTComponent mtComponent = ch[i];
                if (!(mtComponent instanceof MTOverlayContainer)){
                  mtComponent.destroy()
                }
              }
            }
          });
         
        }
      }
    });
        panel1.add(e2); // Add components to the content
       
        //Add MT4j applet
        JPanel pane = new JPanel(new GridLayout(0,1));
        pane.add(instance);
        content.add(pane, BorderLayout.SOUTH);
       
        /////////MEnu
        //So that the menu will overlap the heavyweight opengl canvas
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
       
        //Create the menu bar.
        JMenuBar menuBar = new JMenuBar();

        //Build the first menu.
        JMenu menu = new JMenu("Add");
        menu.setMnemonic(KeyEvent.VK_A);
        menuBar.add(menu);

        JMenuItem addRectItem = new JMenuItem("MTRectangle", KeyEvent.VK_T);
        addRectItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        if (instance.getCurrentScene() != null){
          //If we want to modify the MT4j applet from the swing thread
          //we should wrap the actions into an invokeLater runnable which
          //will be executed the next time the mt4j thread runs.
          instance.invokeLater(new Runnable() {
            public void run() {
              MTRectangle r = new MTRectangle(0,0,ToolsMath.getRandom(50, 250),ToolsMath.getRandom(50, 250), instance);
              r.setFillColor(new MTColor(ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255)));
              r.addGestureListener(DragProcessor.class, new InertiaDragAction());
              instance.getCurrentScene().getCanvas().addChild(r);
              r.setPositionGlobal(new Vector3D(ToolsMath.getRandom(0, instance.width), ToolsMath.getRandom(0, instance.height)));
            }
          });
         
        }
      }
    });
        menu.add(addRectItem);
       
        JMenuItem addRoundRectItem = new JMenuItem("MTRoundRectangle", KeyEvent.VK_E);
        addRoundRectItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        if (instance.getCurrentScene() != null){
          //If we want to modify the MT4j applet from the swing thread
          //we should wrap the actions into an invokeLater runnable which
          //will be executed the next time the mt4j thread runs.
          instance.invokeLater(new Runnable() {
            public void run() {
              float arc = ToolsMath.getRandom(8, 25);
              MTRoundRectangle r = new MTRoundRectangle(0,0,0, ToolsMath.getRandom(50, 250),ToolsMath.getRandom(50, 250), arc, arc, instance);
              r.setFillColor(new MTColor(ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255)));
              r.addGestureListener(DragProcessor.class, new InertiaDragAction());
              instance.getCurrentScene().getCanvas().addChild(r);
              r.setPositionGlobal(new Vector3D(ToolsMath.getRandom(0, instance.width), ToolsMath.getRandom(0, instance.height)));
            }
          });
         
        }
      }
    });
        menu.add(addRoundRectItem);
       
        JMenuItem addEllItem = new JMenuItem("MTEllipse", KeyEvent.VK_E);
        addEllItem.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        if (instance.getCurrentScene() != null){
          //If we want to modify the MT4j applet from the swing thread
          //we should wrap the actions into an invokeLater runnable which
          //will be executed the next time the mt4j thread runs.
          instance.invokeLater(new Runnable() {
            public void run() {
              MTEllipse e = new MTEllipse(instance, new Vector3D(0,0), ToolsMath.getRandom(50, 150),ToolsMath.getRandom(50, 150));
              e.setFillColor(new MTColor(ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255),ToolsMath.getRandom(50,255)));
              e.addGestureListener(DragProcessor.class, new InertiaDragAction());
              instance.getCurrentScene().getCanvas().addChild(e);
              e.setPositionGlobal(new Vector3D(ToolsMath.getRandom(0, instance.width), ToolsMath.getRandom(0, instance.height)));
            }
          });
         
        }
View Full Code Here

Examples of org.mt4j.MTApplication

    }
   
    @Override
    protected void finalize() throws Throwable {
      if (this.p instanceof MTApplication ) {
      MTApplication mtApp = (MTApplication) this.p;
      mtApp.invokeLater(new Runnable() {
        public void run() {
          deleteTess();
        }
      });
    }else{
View Full Code Here

Examples of org.mt4j.MTApplication

 
  @Override
  protected void finalize() throws Throwable {
    logger.debug("Finalizing - " + this);
    if (this.pa instanceof MTApplication) {
      MTApplication mtApp = (MTApplication) this.pa;
      mtApp.invokeLater(new Runnable() {
        public void run() {
          destroy();
        }
      });
    }else{
View Full Code Here

Examples of org.mt4j.MTApplication

 
  @Override
  protected void finalize() throws Throwable {
    //System.out.println("Finalizing GLTEXTURE - " + this);
    if (this.app instanceof MTApplication) {
      MTApplication mtApp = (MTApplication) this.app;
      mtApp.invokeLater(new Runnable() {
        public void run() {
          destroy();
        }
      });
    }else{
View Full Code Here

Examples of org.mt4j.MTApplication

   
    //To avoid errors if this is created in non opengl thread so the gl texture wont be created correctly when setting setTexture
    this.setUseDirectGL(false);

    if (applet instanceof MTApplication) {
      MTApplication app = (MTApplication) applet;
     
      if (MT4jSettings.getInstance().isOpenGlMode()){
        if (app.isRenderThreadCurrent()){
          this.setUseDirectGL(true);
        }else{
          //IF we are useing OpenGL, set useDirectGL to true
          //(=>creates OpenGL texture, draws with pure OpenGL commands)
          //in our main thread.
          app.invokeLater(new Runnable() {
            public void run() {
              setUseDirectGL(true);
            }
          });
        }
View Full Code Here

Examples of org.mt4j.MTApplication

                    shape.setFillPaint(gradient);
                  }
                }
              //Per default use direct gl drawing and displaylists in OGL mode
              if (pa instanceof MTApplication) {
                MTApplication app = (MTApplication) pa;
                app.invokeLater(new InvokeLaterAction(shape));
              }
              }
              //IF shape has no or only 1 vertex return null
            }else if (shape.getVerticesLocal().length < 2){
              return null;
View Full Code Here

Examples of org.mt4j.MTApplication

        }else if(spreadMethod ==  MultipleGradientPaint.REFLECT){
          awtCycleMethod = CycleMethod.REFLECT;
        }

        if (pa instanceof MTApplication) {
          MTApplication app = (MTApplication) pa;

          //Calculate a bounding rectangle from the rotated shape
          BoundsZPlaneRectangle boundsZ = new BoundsZPlaneRectangle(shape, shape.getVerticesLocal());
          Vector3D[] boundsVecs = boundsZ.getVectorsLocal();
          float bBoxWidth  = boundsZ.getWidthXY(TransformSpace.LOCAL);//boundsVecs[1].x - boundsVecs[0].x;
          float bBoxHeight = boundsZ.getHeightXY(TransformSpace.LOCAL);//boundsVecs[2].y - boundsVecs[1].y;

          SwingTextureRenderer swingTex;
          final MTRectangle rectangle;

          //Trial to make the texture as big as the bigger side of the bounding rectangle of the shape
          //to allow for automatic texture stretching to fit when texture is applied
          int size = -1;
          if (coordSystemType == SVGUtilities.OBJECT_BOUNDING_BOX){
            if (bBoxWidth >= bBoxHeight){
              size = Math.round(bBoxWidth);
              r *= bBoxWidth;
            }else{
              size = Math.round(bBoxHeight);
              r *= bBoxHeight;
            }

            AffineTransform Mx = new AffineTransform();
            Rectangle2D bounds = new Rectangle(Math.round(boundsVecs[0].x), Math.round(boundsVecs[0].y), size, size);
            if (bounds != null) {
              //we dont translate the center and focal point
              //instead we create the gradient mask shape at that position
//            Mx.translate(bounds.getX(), bounds.getY());
              Mx.scale(bounds.getWidth(), bounds.getHeight());
            }
            Mx.concatenate(transform);
            transform = Mx;

            //Transform gradient vector points with gradientTransform
            transform.transform(c, c);
            transform.transform(f, f);

            GradientPanel gradPanel = new GradientPanel(size, size, r, offsets, colors, (float)c.getX(), (float)c.getY(), (float)f.getX(), (float)f.getY(), awtCycleMethod);
//          GradientPanel gradPanel = new GradientPanel(bBoxWidth, bBoxHeight, r, offsets, colors, (float)c.getX(), (float)c.getY(), (float)f.getX(), (float)f.getY());
            swingTex = new SwingTextureRenderer(app, gradPanel);
            swingTex.scheduleRefresh();
            rectangle = new MTRectangle(new Vertex(boundsVecs[0]), bBoxWidth, bBoxHeight, pa);
            rectangle.setName("Swing texture rendering");
            rectangle.setTexture(swingTex.getTextureToRenderTo());
            rectangle.setNoStroke(true);
            rectangle.setPickable(false);
            rectangle.setFillDrawMode(GL.GL_QUADS);

            //Use displaylist by default for gradientshape
            if (MT4jSettings.getInstance().isOpenGlMode()){
              app.invokeLater(new InvokeLaterAction(rectangle));
            }

            //FIXME REMOVE TEST
            /*//Draw the shape we draw in swing
          MTRectangle rectanglePaintedComp = new MTRectangle(new Vertex(boundsVecs[0]), size, size, pa);
          rectanglePaintedComp.setName("rectanglePaintedComp");
          rectanglePaintedComp.setTexture(swingTex.getTextureToRenderTo());
          rectanglePaintedComp.setFillColor(255, 255, 255, 150);
          shape.addChild(rectanglePaintedComp);
             */
          }else{
            //coordsystemtype = userSpaceOnUse!

            //FIXME Problem at userOnSpace with proportional length (%)
            //seems we have to take the width/height from the viewbox then!? and use bounding box code above? but we have to recalculate absoulte values then..

            //Since we draw the gradient at 0,0 we have to transform the gradient points to there
            AffineTransform Mx = new AffineTransform();
            Mx.translate(-boundsVecs[0].x, -boundsVecs[0].y);
            Mx.concatenate(transform);
            transform = Mx;

            //Transform gradient points with gradientTransform
            transform.transform(c, c);
            transform.transform(f, f);

//          GradientPanel gradPanel = new GradientPanel(size, size, r, offsets, colors, (float)c.getX(), (float)c.getY(), (float)f.getX(), (float)f.getY());
            GradientPanel gradPanel = new GradientPanel(bBoxWidth, bBoxHeight, r, offsets, colors, (float)c.getX(), (float)c.getY(), (float)f.getX(), (float)f.getY(), awtCycleMethod);
            swingTex = new SwingTextureRenderer(app, gradPanel);
            swingTex.scheduleRefresh();
            rectangle = new MTRectangle(new Vertex(boundsVecs[0]), bBoxWidth, bBoxHeight, pa);
            final GLTexture tex = swingTex.getTextureToRenderTo();
            rectangle.setName("Swing texture rendering");
            rectangle.setTexture(tex);
            rectangle.setNoStroke(true);
            rectangle.setPickable(false);

//          /*//
            if (MT4jSettings.getInstance().isOpenGlMode()){
              app.invokeLater(new InvokeLaterAction(rectangle));
            }
//          */
            //FIXME REMOVE TEST
            /*//Draw the shape we draw in swing
          MTRectangle rectanglePaintedComp = new MTRectangle(new Vertex(boundsVecs[0]), bBoxWidth, bBoxHeight, pa);
View Full Code Here

Examples of org.mt4j.MTApplication

////        appToDestroy.exit(); //probably calls System.exit() so further test wont get exectuted..
//      }
//    };
//    runTest(test);
   
    final MTApplication appToDestroy = getMTApplication();
    appToDestroy.invokeLater(new Runnable() {
     
      public void run() {
        Iscene[] scenes = appToDestroy.getScenes();
        for (int i = 0; i < scenes.length; i++) {
          Iscene iscene = scenes[i];
          if (!iscene.destroy()){
            iscene.getCanvas().destroy();
          }
View Full Code Here

Examples of org.mt4j.MTApplication

            }
            return false;
          }
        });
        if (app instanceof MTApplication) {
          MTApplication mtApp = (MTApplication) app;
          mtApp.invokeLater(new Runnable() {
            public void run() {
              MTMovieClip.this.addChild(slider);
            }
          });
        }else{
          this.addChild(slider);
        }
        slider.setVisible(true);
       
        //Create volume slider
        float volSliderWidth = this.getWidthXY(TransformSpace.LOCAL)/7f;
        float volSliderHeight = topBarHeight - 2*sliderYPadding;
        this.setAnchor(PositionAnchor.UPPER_LEFT);
        Vector3D movieUpperLeft = this.getPosition(TransformSpace.RELATIVE_TO_PARENT);
        volumeSlider = new MTSlider(movieUpperLeft.x + 1.5f, movieUpperLeft.y - volSliderHeight - 1.5f, volSliderWidth, volSliderHeight, 0, 1, app);
        volumeSlider.getOuterShape().setFillColor(new MTColor(0, 0, 0, 80));
        volumeSlider.getOuterShape().setStrokeColor(new MTColor(0, 0, 0, 80));
        volumeSlider.getKnob().setFillColor(new MTColor(100, 100, 100, 80));
        volumeSlider.getOuterShape().setStrokeColor(new MTColor(100, 100, 100, 80));
        if (app instanceof MTApplication) {
          MTApplication mtApp = (MTApplication) app;
          mtApp.invokeLater(new Runnable() {
            public void run() {
              MTMovieClip.this.addChild(volumeSlider);
            }
          });
        }else{
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.