Example #1
0
 private void makeTray() {
   Display display = window.getShell().getDisplay();
   final Tray tray = display.getSystemTray();
   if (tray == null) {
     // no tray
   } else {
     final TrayItem item = new TrayItem(tray, SWT.NONE);
     item.setToolTipText(XdccBeeMessages.getString("Application_TITLE"));
     final Menu menu = new Menu(window.getShell(), SWT.POP_UP);
     MenuItem mi = new MenuItem(menu, SWT.PUSH);
     mi.setText(XdccBeeMessages.getString("Application_TRAY_OPEN"));
     mi.addListener(
         SWT.Selection,
         new Listener() {
           public void handleEvent(Event event) {
             window.getShell().setVisible(true);
             window.getShell().setMinimized(false);
           }
         });
     menu.setDefaultItem(mi);
     item.addListener(
         SWT.MenuDetect,
         new Listener() {
           public void handleEvent(Event event) {
             menu.setVisible(true);
           }
         });
     item.addListener(
         SWT.Selection,
         new Listener() {
           public void handleEvent(Event event) {
             menu.setVisible(true);
           }
         });
     item.setImage(Images.WINDOW_ICON_LARGE);
   }
 }
  /** *************************************************************** */
  private void creaContenidos() {
    display = new Display();
    shell = new Shell();

    // EN CASO DE NO RECUPERAR BIEN TOD0 EL CODIGO CNO browser.getText(); lo hacemos con el DOM
    // mediante JAVASCRIPT
    // System.out.println( (String)brw.evaluate("return document.forms[0].innerHTML;") );
    //
    // if ((Boolean)brw.evaluate("return raise('SelectFare', new SelectFareEventArgs(1, 1, 'G'));"))
    // System.out.println("raise() EJEC CORRECMT");;

    final String html =
        "<html><title>Snippet</title><body><p id='myid'>Best Friends</p><p id='myid2'>Cat and Dog</p></body></html>";
    // final String jsSelecValladolid = "var i=0; while(Stations[i]!=null){; i++;}";

    // Ej de jQuery que funciona: Devuelve el valor del listbox de "Origen Vuelo" selecionado
    final String jQueryRyan = "var orig=$(\"select[@id*='Origin1']\").val(); alert(orig);";
    // "$(\"select[@id*='Origin1']\")[posicion].attr('selected', 'true');";

    /** *** VARIABLES !!!VENTANA¡¡¡ **** */

    // SYSTEM TRAY
    Image image = null;
    try {
      // image = new Image(display, /*rutaActual*/"C:\\"+"fr.ico");
      image = new Image(display, rutaActual + "fr.ico");
    } catch (Exception e) {
      e.getMessage();
    }
    final Tray tray = display.getSystemTray();
    if (tray == null) {
      System.out.println("El system tray no está disponible");
    } else {
      final TrayItem item = new TrayItem(tray, SWT.NONE);
      item.setToolTipText("Ryanair Inspector v2");
      item.setImage(image);
      // Click simple en en icono
      item.addListener(
          SWT.Selection,
          new Listener() {
            public void handleEvent(Event event) {
              // System.out.println("selection");
            }
          });
      // Doble click en en icono
      item.addListener(
          SWT.DefaultSelection,
          new Listener() {
            public void handleEvent(Event event) {
              // System.out.println("default selection");
              // mio
              if (shell.getVisible()) shell.setVisible(false);
              else shell.setVisible(true);
              // shell.setMinimized(false);
              // shell.setMinimized(true);
            }
          });
    }

    // SHELL
    shell.setSize(1054, 727);
    // shell.setLayout(new FillLayout());
    shell.setText("Ryanair checker");
    shell.setImage(image);
    // Con esto al agrandar y empequeñecer se reorganizan los componentes
    // shell.setLayout(new FillLayout());

    // CREAMOS CONTENEDOR
    /** ************************************************************************ */
    compIzq = new Composite(shell, SWT.NONE);
    compIzq.setBounds(0, 0, 765, 691);
    final FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
    fillLayout.marginWidth = 200;
    fillLayout.marginHeight = 200;
    // comp.setLayout(fillLayout);
    // comp.setSize(200, 200);

    compDer = new Composite(shell, SWT.NONE);
    compDer.setBounds(771, 0, 267, 691);

    // CREAMOS CAJA TEXTO Y BOTON PARA HTML OBTENIDO
    /** ************************************************************************ */
    final Text txtGetHTML = new Text(compDer, SWT.MULTI);
    txtGetHTML.setBounds(0, 0, 251, 198);

    // RyanairInspector2.class.getResource("RyanairInspector2.class").getPath();
    // System.getProperty("user.dir")+"\\bin\\calculadora\\";
    txtGetHTML.setText(
        RyanairInspector2.class.getResource("RyanairInspector2.class").getPath()
            + "\n"
            + System.getProperty("user.dir"));

    final Button button = new Button(compDer, SWT.NONE);
    button.setText("button");

    // TABS
    /** ************************************************************************ */
    tabFolder = new TabFolder(compIzq, SWT.BORDER);
    itemT1 = new TabItem(tabFolder, SWT.NONE);
    itemT2 = new TabItem(tabFolder, SWT.NONE);
    itemT3 = new TabItem(tabFolder, SWT.NONE);
    itemT1.setText("Resultado");
    itemT2.setText("Debugger");
    itemT3.setText("Hilos");

    // TABLE CON DOS COLUMNAS
    /** ************************************************************************ */
    table = new Table(tabFolder, SWT.VIRTUAL);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    final TableColumn column1 = new TableColumn(table, SWT.NONE);
    column1.setText("Origen");
    column1.setWidth(200);
    final TableColumn column2 = new TableColumn(table, SWT.NONE);
    column2.setText("Destino");
    column2.setWidth(200);
    final TableColumn column3 = new TableColumn(table, SWT.NONE);
    column3.setText("Fecha");
    column3.setWidth(200);
    final TableColumn column4 = new TableColumn(table, SWT.NONE);
    column4.setText("Precio");
    column4.setWidth(150);

    /* Metemos elementos en la tabla
    TableItem fila = new TableItem(table, SWT.NONE);
    fila.setText(new String[] { "a", "b", "c", "d" });
    */

    // METEMOS EL TABLE EN LA TAB2
    itemT1.setControl(table);
    tabFolder.setBounds(0, 0, 700, 691);
    tabFolder.pack();

    // CREAMOS BROWSER
    /** ************************************************************************ */
    try {
    } catch (SWTError e) {
      System.out.println("Could not instantiate Browser: " + e.getMessage());
      return;
    }
    // CREAMOS BROWSER (2)
    /** ************************************************************************ */
    // FUNCIONA BIEN SIN TABS: browser = new Browser(compIzq, SWT.BORDER);

    // El Normal
    navegadores.add(new Navegador(tabFolder, SWT.BORDER));
    // El Mozilla (hay q ejecutar el xulrunner.exe --register-global)
    // browser = new Browser(tabFolder, SWT.MOZILLA);
    // browser.setSize(1000, 800);
    navegadores.get(0).setBounds(0, 0, 787, 691);
    // browser.setLocation(500, 900);
    /*final FillLayout fillLayoutB = new FillLayout(SWT.VERTICAL);
    fillLayoutB.marginWidth = 200;
    fillLayoutB.marginHeight = 200;
    browser.setLayout(fillLayoutB);
     */

    // METEMOS EL BROWSER EN LA TAB1
    itemT2.setControl(navegadores.get(0)); // prueba18-6-09
    // browser.setVisible(false);

    tabFolder.setBounds(0, 0, 766, 691);
    tabFolder.pack();

    navegadores.add(new Navegador(tabFolder, SWT.BORDER));
    navegadores.get(1).setBounds(0, 0, 787, 691);
    itemT3.setControl(navegadores.get(1));

    // CADA VEZ!!! QUE TERMINE DE CARGAR
    navegadores
        .get(0)
        .addProgressListener(
            new ProgressAdapter() {
              public void completed(ProgressEvent event) {
                if (!postSubmit(navegadores.get(0), table)) {
                  System.out.println(
                      "ERROR: Problema al ejecutar la gestion de los datos, finalizar la carga de la pagina.");
                }
              }
            });

    // CADA VEZ!!! QUE TERMINE DE CARGAR
    navegadores
        .get(1)
        .addProgressListener(
            new ProgressAdapter() {
              public void completed(ProgressEvent event) {
                if (!postSubmit(navegadores.get(1), table)) {
                  System.out.println(
                      "ERROR: Problema al ejecutar la gestion de los datos, finalizar la carga de la pagina.");
                }
              }
            });

    // BOTON OBTENER HTML
    /** ************************************************************************ */
    final Button btnGetHTML = new Button(compDer, SWT.PUSH);
    btnGetHTML.setBounds(0, 204, 151, 30);
    btnGetHTML.setText("Obtener codigo html");
    btnGetHTML.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {

            addBrowser();

            String result = navegadores.get(0).getText();
            txtGetHTML.setText(result);
          }
        });

    // CREAMOS CAJA TEXTO PARA EJECUTAR JS
    /** ************************************************************************ */
    /*final Text txtJS = new Text(compDer, SWT.MULTI);
    txtJS.setText("var newNode = document.createElement('P'); \r\n"+
    		"var text = document.createTextNode('At least when I am around');\r\n"+
    		"newNode.appendChild(text);\r\n"+
    		"document.getElementById('myid').appendChild(newNode);\r\n"+
    		"document.bgColor='yellow';\r\n"+
    		"\r\n"+
    		"document.getElementById('AvailabilitySearchInputFRSearchView_OneWay').checked = true;\r\n"+
    		"document.getElementById('AvailabilitySearchInputFRSearchView_ButtonSubmit').click();\r\n"+
    		"document.getElementById('AvailabilitySearchInputFRSearchView_DropDownListMarketOrigin1')[2].selected=true;\r\n"+
    		"Destination1");
    */

    // BOTON LANZAMOS RYANAIR
    /** ************************************************************************ */
    /*final Button btnCargarRyan = new Button(compDer, SWT.PUSH);
    btnCargarRyan.setText("Cargar RYANAIR");
    btnCargarRyan.addListener(SWT.Selection, new Listener() {
    	public void handleEvent(Event event) {
    		//boolean result = browser.execute(text.getText());
    		boolean result = browser.setUrl("http://www.bookryanair.com/SkySales/FRSearch.aspx?culture=ES-ES&pos=HEAD");
    		if (!result) {
    			// Script may fail or may not be supported on certain platforms.
    			System.out.println("Script was not executed.");
    		}
    	}
    });
    */

    // BOTON EJECUTAMOS JAVASCRIPT
    /** ************************************************************************ */
    final Button btnEjeJS = new Button(compDer, SWT.PUSH);
    btnEjeJS.setBounds(0, 266, 151, 30);
    btnEjeJS.setText("Ejecutar JAVASCRIPT");
    btnEjeJS.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {}
        });

    // image.dispose(); //con esto no funciona el shell.setImage(image)

  }