From a6257bf9734e7705e43a03a9655d5d07364245e5 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Wed, 18 Sep 2013 02:23:21 +0000 Subject: [PATCH] git-svn-id: svn://imanolbarba.net/PAD@6 c2ee353e-ed0d-4329-bf56-03aec153487f --- readline/bin/pad/prac1/Line.class | Bin 0 -> 1995 bytes readline/src/pad/prac1/Line.java | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 0 deletions(-) create mode 100644 readline/bin/pad/prac1/Line.class create mode 100644 readline/src/pad/prac1/Line.java diff --git a/readline/bin/pad/prac1/Line.class b/readline/bin/pad/prac1/Line.class new file mode 100644 index 0000000..52d14f9 Binary files /dev/null and b/readline/bin/pad/prac1/Line.class differ 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; + } + +} -- libgit2 0.22.2