~blackborn/g15control-beyond/G15C

« back to all changes in this revision

Viewing changes to src/uk/org/dataforce/g15/plugins/buttonProgram/Mkeys.java

  • Committer: eragon
  • Date: 2008-06-10 09:07:42 UTC
  • Revision ID: eragon@black-desktop-20080610090742-1pzzyw4678o0ae48
10 jun 08 | BBorn
- cleanup
- Building a new swing theme for the G15

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * To change this template, choose Tools | Templates
3
 
 * and open the template in the editor.
4
 
 */
5
 
 
6
 
package uk.org.dataforce.g15.plugins.buttonProgram;
7
 
 
8
 
import java.util.Timer;
9
 
import java.util.TimerTask;
10
 
import uk.org.dataforce.g15.G15Wrapper;
11
 
 
12
 
/**
13
 
 *
14
 
 * @author black
15
 
 */
16
 
public class Mkeys {
17
 
        private static int keyPressed=0;
18
 
        private static Timer flickerTimer;
19
 
        private static Timer key123Timer;
20
 
        private static int mButton = 0;
21
 
        private static int flickerButton = 0;
22
 
        private static boolean flickerOn = false;
23
 
        private static G15Wrapper myScreen;
24
 
 
25
 
        public Mkeys( G15Wrapper newScreen ){
26
 
                myScreen = newScreen;
27
 
        }
28
 
 
29
 
        public static void resetMButton() {
30
 
                stopFlicker();
31
 
                stopKey123Timeout();
32
 
                                
33
 
                myScreen.setMXLight(0,false);
34
 
                if(mButton != 0)
35
 
                        myScreen.setMXLight(mButton, true);
36
 
        }
37
 
 
38
 
        public static void changeMButton( int newButton ) {
39
 
                if( flickerTimer != null){
40
 
                        changeFlickerMButton(newButton);
41
 
                        return;
42
 
                }               
43
 
                if(mButton != 0)
44
 
                        myScreen.setMXLight(mButton, false);
45
 
 
46
 
                boolean newOn = true;
47
 
                if (mButton == newButton) {
48
 
                        newOn = false;
49
 
                        mButton = 0;
50
 
                } else {
51
 
                        mButton = newButton;
52
 
                }
53
 
                
54
 
                if(mButton != 0)
55
 
                        myScreen.setMXLight(mButton, newOn);
56
 
        }
57
 
 
58
 
        public static void changeFlickerMButton( int newButton ) {
59
 
                myScreen.setMXLight(0,false);           
60
 
                flickerOn = true;
61
 
                flickerButton = newButton;
62
 
        }
63
 
 
64
 
        public static boolean checkKey123( int newButton ) {
65
 
                if( newButton==1 ){
66
 
                        keyPressed++;
67
 
                        startKey123Timeout();
68
 
                }
69
 
                else if( keyPressed==1 && newButton==2){
70
 
                        keyPressed++;
71
 
                }
72
 
                else if( keyPressed==2 && newButton==3){
73
 
                        keyPressed++;
74
 
                }
75
 
 
76
 
                if( keyPressed == 3 ){
77
 
                        stopKey123Timeout();
78
 
                        return true;
79
 
                }
80
 
                else
81
 
                        return false;
82
 
        }
83
 
 
84
 
        public static void startKey123Timeout(){
85
 
                key123Timer = new Timer();              
86
 
                key123Timer.schedule( new TimerTask(){  public void run() {
87
 
                                                                keyPressed = 0;
88
 
                                                        }
89
 
                                        }, 1000L );
90
 
        }
91
 
 
92
 
        public static void stopKey123Timeout(){
93
 
                if(key123Timer != null)
94
 
                        key123Timer.cancel();
95
 
        }
96
 
 
97
 
        public static void changeflickerMButton( int newButton ){
98
 
                flickerButton = newButton;
99
 
        }
100
 
 
101
 
        public static void startFlicker(){
102
 
                flickerTimer = new Timer();             
103
 
                flickerTimer.schedule( new TimerTask(){ public void run() {
104
 
                                                                myScreen.setMXLight(flickerButton,flickerOn);
105
 
                                                                flickerOn = !flickerOn;
106
 
                                                        }
107
 
                                        }, 0, 500L );
108
 
        }
109
 
 
110
 
        public static void stopFlicker(){
111
 
                if(flickerTimer != null)
112
 
                        flickerTimer.cancel();
113
 
                flickerTimer = null;
114
 
                flickerButton = 0;
115
 
        }
116
 
        
117
 
        public static int getButton(){
118
 
                return mButton;
119
 
        }       
120
 
        
121
 
        public static int getToggleButton(){
122
 
                return flickerButton;
123
 
        }
124
 
}
 
 
b'\\ No newline at end of file'