diff --git a/readline/bin/pad/prac1/Line.class b/readline/bin/pad/prac1/Line.class new file mode 100644 index 0000000..52d14f9 --- /dev/null +++ b/readline/bin/pad/prac1/Line.class diff --git a/readline/src/pad/prac1/Line.java b/readline/src/pad/prac1/Line.java new file mode 100644 index 0000000..fd56a66 --- /dev/null +++ b/readline/src/pad/prac1/Line.java @@ -0,0 +1,92 @@ +package pad.prac1; + +public class Line +{ + /* + * MODE DEFINITIONS + */ + + public static final int INSERT = 0; + public static final int OVERWRITE = 1; + + private String line; + private int cursorPosition; + private int writeMode; + + public Line() + { + line = ""; + writeMode = INSERT; + cursorPosition = 1; + } + + public int length() + { + return line.length(); + } + + public int getCursorPosition() + { + return cursorPosition; + } + + public void setCursorPosition(int pos) + { + cursorPosition = pos; + } + + public int getMode() + { + return writeMode; + } + + public void toggleMode() + { + writeMode = 1 - writeMode; + } + + public void removeCharAt(int pos) + { + if(pos >= 0) + { + if(pos == 0) + { + line = line.substring(1); + } + else if(pos == line.length()-1) + { + line = line.substring(0, line.length()-1); + } + else + { + line = line.substring(0, pos).concat(line.substring(pos+1,line.length())); + } + } + } + + public void insertCharAt(char c, int pos) + { + if(pos == 0) + { + String s = ""; + s += c; + line = s + line; + } + else if(pos == line.length()) + { + line += c; + } + else + { + String s = ""; + s += c; + line = line.substring(0, pos).concat(s).concat(line.substring(pos,line.length())); + } + } + + public String toString() + { + return line; + } + +}