-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.java
More file actions
104 lines (95 loc) · 3.02 KB
/
Copy pathConsole.java
File metadata and controls
104 lines (95 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package labpad;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author epicur
*/
public class Console implements Observer {
static final int ESCAPE = 27;
static final int CARRIAGE_RETURN = 13;
static final int BACKSPACE = 127;
static final int FLETXA_DRETA = 300;
static final int FLETXA_ESQUERRA = 301;
static final int CLIC_DRET = 302;
static final int CLIC_ESQUERRA = 303;
static final int RODA_AMUNT = 304;
static final int RODA_AVALL = 305;
static final int INSERTAR = 306;
static final int FIN = 307;
static final int INICI = 308;
static final int SUPRIMIR = 309;
Line linia;
public Console() {
}
static class Command {
int i, pos;
Command(int i, int pos) {
this.i = i;
this.pos = pos;
}
}
@Override
public void update(Observable ob, Object o) {
char car;
Command com = (Command) o;
switch (com.i) {
case CARRIAGE_RETURN:
System.exit(0);
break;
case BACKSPACE:
System.out.print("\u001B\u005b\u0044\u001B\u005b\u0050");
break;
case FLETXA_DRETA:
System.out.print("\u001B\u005b\u0043");
break;
case FLETXA_ESQUERRA:
System.out.print("\u001B\u005b\u0044");
break;
case RODA_AMUNT:
System.out.print("\u001B\u005b\u0043");
break;
case RODA_AVALL:
System.out.print("\u001B\u005b\u0044");
break;
case CLIC_DRET:
if (com.pos > 0) {
System.out.print("\u001B\u005b" + com.pos + "\u0043");
} else if (com.pos < 0) {
System.out.print("\u001B\u005b" + (com.pos*-1) + "\u0044");
}
break;
case CLIC_ESQUERRA:
break;
case INSERTAR:
break;
case INICI:
System.out.print("\u001B\u005b" + com.pos + "\u0044");
break;
case FIN:
System.out.print("\u001B\u005b" + com.pos + "\u0043");
break;
case SUPRIMIR:
System.out.print("\u001B\u005b\u0050");
break;
default:
if (com.pos == 0) {
car = (char) com.i;
System.out.print(Character.toString(car));
break;
} else {
car = (char) com.i;
System.out.print("\u001B\u005b\u0040");
System.out.print(Character.toString(car));
break;
}
}
}
}