Commit a6257bf9734e7705e43a03a9655d5d07364245e5
1 parent
25fd54b0
git-svn-id: svn://imanolbarba.net/PAD@6 c2ee353e-ed0d-4329-bf56-03aec153487f
Showing
2 changed files
with
92 additions
and
0 deletions
readline/bin/pad/prac1/Line.class
0 → 100644
No preview for this file type
readline/src/pad/prac1/Line.java
0 → 100644
1 | +package pad.prac1; | ||
2 | + | ||
3 | +public class Line | ||
4 | +{ | ||
5 | + /* | ||
6 | + * MODE DEFINITIONS | ||
7 | + */ | ||
8 | + | ||
9 | + public static final int INSERT = 0; | ||
10 | + public static final int OVERWRITE = 1; | ||
11 | + | ||
12 | + private String line; | ||
13 | + private int cursorPosition; | ||
14 | + private int writeMode; | ||
15 | + | ||
16 | + public Line() | ||
17 | + { | ||
18 | + line = ""; | ||
19 | + writeMode = INSERT; | ||
20 | + cursorPosition = 1; | ||
21 | + } | ||
22 | + | ||
23 | + public int length() | ||
24 | + { | ||
25 | + return line.length(); | ||
26 | + } | ||
27 | + | ||
28 | + public int getCursorPosition() | ||
29 | + { | ||
30 | + return cursorPosition; | ||
31 | + } | ||
32 | + | ||
33 | + public void setCursorPosition(int pos) | ||
34 | + { | ||
35 | + cursorPosition = pos; | ||
36 | + } | ||
37 | + | ||
38 | + public int getMode() | ||
39 | + { | ||
40 | + return writeMode; | ||
41 | + } | ||
42 | + | ||
43 | + public void toggleMode() | ||
44 | + { | ||
45 | + writeMode = 1 - writeMode; | ||
46 | + } | ||
47 | + | ||
48 | + public void removeCharAt(int pos) | ||
49 | + { | ||
50 | + if(pos >= 0) | ||
51 | + { | ||
52 | + if(pos == 0) | ||
53 | + { | ||
54 | + line = line.substring(1); | ||
55 | + } | ||
56 | + else if(pos == line.length()-1) | ||
57 | + { | ||
58 | + line = line.substring(0, line.length()-1); | ||
59 | + } | ||
60 | + else | ||
61 | + { | ||
62 | + line = line.substring(0, pos).concat(line.substring(pos+1,line.length())); | ||
63 | + } | ||
64 | + } | ||
65 | + } | ||
66 | + | ||
67 | + public void insertCharAt(char c, int pos) | ||
68 | + { | ||
69 | + if(pos == 0) | ||
70 | + { | ||
71 | + String s = ""; | ||
72 | + s += c; | ||
73 | + line = s + line; | ||
74 | + } | ||
75 | + else if(pos == line.length()) | ||
76 | + { | ||
77 | + line += c; | ||
78 | + } | ||
79 | + else | ||
80 | + { | ||
81 | + String s = ""; | ||
82 | + s += c; | ||
83 | + line = line.substring(0, pos).concat(s).concat(line.substring(pos,line.length())); | ||
84 | + } | ||
85 | + } | ||
86 | + | ||
87 | + public String toString() | ||
88 | + { | ||
89 | + return line; | ||
90 | + } | ||
91 | + | ||
92 | +} |