Package org.mt4j.components.visibleComponents.widgets.keyboard

Examples of org.mt4j.components.visibleComponents.widgets.keyboard.MTKeyboard


    keyboardButton.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent ae) {
        switch (ae.getID()) {
        case TapEvent.BUTTON_CLICKED:
          //Flickr Keyboard
              MTKeyboard keyb = new MTKeyboard(app);
              keyb.setFillColor(new MTColor(30, 30, 30, 210));
              keyb.setStrokeColor(new MTColor(0,0,0,255));
             
              final MTTextArea t = new MTTextArea(app, FontManager.getInstance().createFont(app, "arial.ttf", 50,
                  new MTColor(0,0,0,255), //Fill color
              new MTColor(0,0,0,255))); //Stroke color
              t.setExpandDirection(ExpandDirection.UP);
          t.setStrokeColor(new MTColor(0,0 , 0, 255));
          t.setFillColor(new MTColor(205,200,177, 255));
          t.unregisterAllInputProcessors();
          t.setEnableCaret(true);
          t.snapToKeyboard(keyb);
          keyb.addTextInputListener(t);
             
              //Flickr Button for the keyboard
              MTSvgButton flickrButton = new MTSvgButton( "advanced" + MTApplication.separator +  "flickrMT" + MTApplication.separator + "data" + MTApplication.separator
              + "Flickr_Logo.svg", app);
              flickrButton.scale(0.4f, 0.4f, 1, new Vector3D(0,0,0), TransformSpace.LOCAL);
              flickrButton.translate(new Vector3D(0, 15,0));
              flickrButton.setBoundsPickingBehaviour(AbstractShape.BOUNDS_ONLY_CHECK);
             
              //Add actionlistener to flickr button
              flickrButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
              if (arg0.getSource() instanceof MTComponent){
                //MTBaseComponent clickedComp = (MTBaseComponent)arg0.getSource();
                switch (arg0.getID()) {
                case TapEvent.BUTTON_CLICKED:
                  //Get current search parameters
                      SearchParameters sp = new SearchParameters();
                      //sp.setSafeSearch("213on");
                      /*
                      DateFormat dateFormat = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss");
                      java.util.Date date = new java.util.Date ();
                      String dateStr = dateFormat.format (date);
                      System.out.println("Date: " + dateStr);
                      try{
                        Date date2 = dateFormat.parse (dateStr);
                        sp.setInterestingnessDate(date2);
                      }catch(ParseException pe){
                        pe.printStackTrace();
                      }
                      */
                     
                      //sp.setMachineTags(new String[]{"geo:locality=\"san francisco\""});
                      sp.setText(t.getText());
                      //sp.setTags(new String[]{t.getText()});
                      sp.setSort(SearchParameters.RELEVANCE);
                     
                      System.out.println("Flickr search for: \"" + t.getText() + "\"");
                     
                      //Load flickr api key from file
                      String flickrApiKey = "";
                      String flickrSecret = "";
                      Properties properties = new Properties();
                      try {
                        InputStream in = null;
                        try {
                          in = new FileInputStream( "examples" + MTApplication.separator + "advanced" + MTApplication.separator + "flickrMT" + MTApplication.separator + "data" + MTApplication.separator + "FlickrApiKey.txt");
                    } catch (Exception e) {
                      System.err.println(e.getLocalizedMessage());
                    }
                   
                        if (in == null){
                          try {
                            in = Thread.currentThread().getContextClassLoader().getResourceAsStream("advanced" + MTApplication.separator + "flickrMT" + MTApplication.separator + "data" + MTApplication.separator + "FlickrApiKey.txt");
                      } catch (Exception e) {
                        System.err.println(e.getLocalizedMessage());
                      }
                        }
                        properties.load(in);

                        flickrApiKey = properties.getProperty("FlickrApiKey", " ");
                        flickrSecret = properties.getProperty("FlickrSecret", " ");
                    } catch (Exception e) {
                      System.err.println("Error while loading FlickrApiKey.txt file.");
                      e.printStackTrace();
                     
                    }
                     
                      //Create flickr loader thread
                      final FlickrMTFotoLoader flickrLoader = new FlickrMTFotoLoader(app, flickrApiKey, flickrSecret, sp, 300);
                      flickrLoader.setFotoLoadCount(5);
                      //Define action when loader thread finished
                      flickrLoader.addProgressFinishedListener(new IMTEventListener(){
                    public void processMTEvent(MTEvent mtEvent) {
                      //Add the loaded fotos in the main drawing thread to
                      //avoid threading problems
                      registerPreDrawAction(new IPreDrawAction(){
                        public void processAction() {
                          MTImage[] fotos = flickrLoader.getMtFotos();
                          for (int i = 0; i < fotos.length; i++) {
                            MTImage card = fotos[i];
                            card.setUseDirectGL(true);
                            card.setDisplayCloseButton(true);
                            card.setPositionGlobal(new Vector3D(ToolsMath.getRandom(10, MT4jSettings.getInstance().getWindowWidth()-100), ToolsMath.getRandom(10, MT4jSettings.getInstance().getWindowHeight()-50),0 )  );
                            card.scale(0.6f, 0.6f, 0.6f, card.getCenterPointLocal(), TransformSpace.LOCAL);
                            card.addGestureListener(DragProcessor.class, new InertiaDragAction());
                            lassoProcessor.addClusterable(card); //make fotos lasso-able
                            pictureLayer.addChild(card);
                          }
                          progressBar.setVisible(false);
                        }
                       
                        public boolean isLoop() {
                          return false;
                        }
                      });
                    }
                      });
                      progressBar.setProgressInfoProvider(flickrLoader);
                      progressBar.setVisible(true);
                      //Run the thread
                      flickrLoader.start();
                      //Clear textarea
                      t.clear();
                  break;
                default:
                  break;
                }
              }
            }
          });
          keyb.addChild(flickrButton);
//              getCanvas().addChild(0, keyb);
          getCanvas().addChild(keyb);
          keyb.setPositionGlobal(new Vector3D(app.width/2f, app.height/2f,0));
          break;
        default:
          break;
        }
      }
View Full Code Here

TOP

Related Classes of org.mt4j.components.visibleComponents.widgets.keyboard.MTKeyboard

Copyright © 2018 www.massapicom. 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.