Package Manejo

Source Code of Manejo.Movimiento

/*
* File:        Movimiento.java
*
*              Clase que ............
*
*     This file is a part of The Virtual Mouse, a program designed for
*              people with severe motor disabilities to whom it is impossible
*              to use a traditional mouse. This application gives these people
*              the control of the physical mouse via another type of device.
*
* Authors:     Isabel Gonz�lez
* Date:        28 de agosto de 2008
*
* Company:     Colegio P�blico de Educaci�n Especial Alborada, Zaragoza
*              DIIS, Universidad de Zaragoza
*
* License:     Copyright (C) 2008
*
*              This program is free software: you can redistribute it and/or modify
*              it under the terms of the GNU General Public License as published by
*              the Free Software Foundation, either version 3 of the License, or
*              (at your option) any later version.
*
*              This program is distributed in the hope that it will be useful,
*              but WITHOUT ANY WARRANTY; without even the implied warranty of
*              MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*              GNU General Public License for more details.
*
*              You should have received a copy of the GNU General Public License
*              along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*
*
*
*/


package Manejo;

import Funcion.Barrido;
import Funcion.Cargar;
import Tipos.MiBoton;
import Tipos.Tablero;
import java.util.ResourceBundle;
import java.util.concurrent.Semaphore;

// Clase est�tica que implementa las funciones que mueven el cursor
public class Movimiento {
   
   
    public static Thread th;
    // public static boolean moviendo = false;
   
    static boolean segundoMov = false;
   
    final int MOUSEEVENTF_MOVE = 0x0001;
    public static Tablero t = Tablero.getInstance();
   
   
    // Acci�n de parar el movimiento y recomenzar el barrido
    public static void parar() {
        Conexion.enviar(t.PARADA, 8);
        System.out.println("Envio parar");
        t.seleccionandoFila=true;
        t.enMovimiento=false;
        if ((Barrido.barriendo)&&(t.barrido==t.AUTOMATICO)) {
            Barrido.resetBarrido();
        }
        // si es manual
        else if ((t.barrido==t.MANUAL_FILAS)||(t.barrido== t.MANUAL_COLUMNAS)){
            t.activo=t.coleccion.get(0);
            t.activo.Select(true,true);
        }
        else if (t.barrido==t.MANUAL_FILAS_COLUMNAS){
            MovimientoTablero.barridoManualPorFilas(0);
        }
        else {
            System.out.println("Entra al else");
            t.activo=t.oldActivo;
            t.activo.Select(true,true);
//                t.activo.setOpaque(true); // probar
//                t.activo.setSelected(true);
//                t.activo.setBackground(t.colorB);
        }
    }
   
    // Acci�n de movimiento haciaArriba
    public static void haciaArriba() {
        //Conexion.enviar("m0");
        Conexion.enviar(t.MOVIMIENTO, 0);
        System.err.println("Envio hacia Arriba");
        comenzarMov();
    }
   
    // Acci�n de movimiento haciaAbajo
    public static void haciaAbajo() {
        //Conexion.enviar("m1");
        Conexion.enviar(t.MOVIMIENTO, 1);
        System.err.println("Envio hacia Abajo");
        comenzarMov();
    }
   
    // Acci�n de movimiento haciaIzquierda
    public static void haciaIzda() {
        //Conexion.enviar("m3");
        Conexion.enviar(t.MOVIMIENTO, 3);
        System.err.println("Envio hacia Izquierda");
        comenzarMov();
    }
   
    // Acci�n de movimiento haciaDerecha
    public static void haciaDcha() {
        //Conexion.enviar("m2");
        Conexion.enviar(t.MOVIMIENTO, 2);
        System.err.println("Envio haciaDcha");
        comenzarMov();
    }
   
    // Acci�n de movimiento haciaArribaIzquierda
    public static void haciaArribaIzda() {
        Conexion.enviar(t.MOVIMIENTO, 4);
        System.err.println("Envio Arriba Izquierda");
        comenzarMov();
    }
   
    // Acci�n de movimiento haciaArribaDerecha
    public static void haciaArribaDcha() {
        Conexion.enviar(t.MOVIMIENTO, 5);
        System.err.println("Envio Arriba Derecha");
        comenzarMov();
    }
   
    // Acci�n de movimiento haciaAbajoIzquierda
    public static void haciaAbajoIzda() {
        Conexion.enviar(t.MOVIMIENTO, 6);
        System.err.println("Envio Abajo Izquierda");
        comenzarMov();
    }
   
    // Acci�n de movimiento haciaAbajoDerecha
    public static void haciaAbajoDcha() {
        Conexion.enviar(t.MOVIMIENTO, 7);
        System.err.println("Abajo Derecha");
        comenzarMov();
    }
   
    // Parar el barrido y comenzar el movimiento seg�n tipo del Tablero
    public static void comenzarMov() {
          String s;
        if (Barrido.barriendo){
            // paro el barrido sin poner barriendo=false
            if (Barrido.tMov != null){
                if (Barrido.tMov.isAlive()){
                    Barrido.oFinThread = new Semaphore(0,true);
                    Barrido.tMov.parar=1;
                    try {
                       
                        Barrido.oFinThread.acquire();
                        System.out.println("Despues de wait");
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                    //oFinThread=null;
                    System.out.println("Parar barrido");
                    //t.tM.destroy();
                }
            }
        }
      
        if (t.primeraFase){
            s= "primera";
        }
        else s= "segunda";
       
        System.out.println("Despues de parar barrido estamos en fase: "+ s);   
        t.enMovimiento=true;
        if ((t.relacionVel==0))//&& (t.tipoMovimiento==t.NOMANTENIDOPULSAR)) // parada simple poner??
        {
            // activamos parar
            if (t.parada != null) {
                t.activo = t.parada;
                t.parada.Select(true,true);
            } else
                t.activo = new MiBoton("Parar");
           
            if (!t.BarridoPorFases())
                t.CambiarTitulo(ResourceBundle.getBundle("idiomas.fich_idiomas",t.Idiomas).getString("strParar"));
        }
//        else if ((t.relacionVel==0)&&(t.tipoMovimiento==t.NOMANTENIDOSOLTAR)){
//            // Solo para el movimiento compuesto al Soltar
//            t.moviendo = true;
//        }
       
        else if (t.relacionVel!=0)//Tablero.tipoParada == Tablero.P_DOBLE
        {
            // Doble
            if (!segundoMov){
                System.out.println("Primer mov");
                // activamos la accion barrida
                segundoMov = true;
                t.activo.Select(true,true);
            }
            else {
                System.out.println("Segundo mov");
                //Barrido.dejar=false;
                segundoMov = false;
                if (t.parada != null) {
                    t.activo = t.parada;
//                                    t.parada.setOpaque(true); // probar
//                                    t.parada.setSelected(true);
//                                    t.parada.setBackground(t.colorB);
                    t.parada.Select(true,true);
                    //t.activo = new MiBoton("Parar");
                } else{
                    t.activo = new MiBoton("Parar");
                    t.CambiarTitulo(ResourceBundle.getBundle("idiomas.fich_idiomas",t.Idiomas).getString("strParar"));
                }
            }
        }
       
       
        if (t.tipoTablero == t.T_SOLOBOTON) {
            Cargar.cambiarVista();
        }
     
        if (t.primeraFase){
            s= "primera";
        }
        else s= "segunda";
       
        System.out.println("Al salir estamos en fase: "+ s);   
    }
   
    // M�todo del thread que ejecuta el movimiento del cursor
    private static void moverMouse() {
//            Screen screenPpal = Screen.AllScreens[0];
//            System.Drawing.Rectangle bounds = screenPpal.Bounds;
//            System.Drawing.Point p;
//
//            int sleep = (Tablero.tipoParada == Tablero.P_DOBLE && !segundoMov?
//                            Tablero.speedCursor * Tablero.relacionVel:Tablero.speedCursor);
//
//            while (true)
//            {
//                    int flag = MOUSEEVENTF_MOVE;
//                    InputMouse.accionMouse(flag, InputMouse.dx, InputMouse.dy);
//                    Thread.Sleep(sleep);
//
//                    //InputMouse.GetCursorPos(out p);
//                    if (p.X == bounds.Width -1)
//                            InputMouse.SetCursorPos(0, p.Y);
//                    if (p.Y == bounds.Height -1)
//                            InputMouse.SetCursorPos(p.X, 0);
//                    if (p.X == 0)
//                            InputMouse.SetCursorPos(bounds.Width -1, p.Y);
//                    if (p.Y == 0)
//                            InputMouse.SetCursorPos(p.X, bounds.Height-1);
//            }
    }
}

TOP

Related Classes of Manejo.Movimiento

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.