aboutsummaryrefslogtreecommitdiffstats
path: root/src/org
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2009-05-07 21:51:39 +0000
committerKenny Root <kenny@the-b.org>2009-05-07 21:51:39 +0000
commit194c7f8fedab38a944a984730706203c1166be55 (patch)
treeb077e6b8f978d82c47f1979f8c79612eb17e3962 /src/org
parent86b62b61ddb646c6ab99b4d07555a7b3266f5329 (diff)
downloadconnectbot-194c7f8fedab38a944a984730706203c1166be55.tar.gz
connectbot-194c7f8fedab38a944a984730706203c1166be55.tar.bz2
connectbot-194c7f8fedab38a944a984730706203c1166be55.zip
* Add unit tests for SelectionArea
* Reduce knowledge of SelectionArea * Call to HostBeanTest's parent.setUp() git-svn-id: https://connectbot.googlecode.com/svn/trunk/connectbot@226 df292f66-193f-0410-a5fc-6d59da041ff2
Diffstat (limited to 'src/org')
-rw-r--r--src/org/connectbot/ConsoleActivity.java8
-rw-r--r--src/org/connectbot/bean/SelectionArea.java71
-rw-r--r--src/org/connectbot/service/TerminalBridge.java20
3 files changed, 49 insertions, 50 deletions
diff --git a/src/org/connectbot/ConsoleActivity.java b/src/org/connectbot/ConsoleActivity.java
index c02a75a..9ac1c3f 100644
--- a/src/org/connectbot/ConsoleActivity.java
+++ b/src/org/connectbot/ConsoleActivity.java
@@ -495,8 +495,8 @@ public class ConsoleActivity extends Activity {
case MotionEvent.ACTION_DOWN:
// recording starting area
if (area.isSelectingOrigin()) {
- area.setTop(row);
- area.setLeft(col);
+ area.setRow(row);
+ area.setColumn(col);
lastTouchRow = row;
lastTouchCol = col;
copySource.redraw();
@@ -513,8 +513,8 @@ public class ConsoleActivity extends Activity {
area.finishSelectingOrigin();
// update selected area
- area.setBottom(row);
- area.setRight(col);
+ area.setRow(row);
+ area.setColumn(col);
lastTouchRow = row;
lastTouchCol = col;
copySource.redraw();
diff --git a/src/org/connectbot/bean/SelectionArea.java b/src/org/connectbot/bean/SelectionArea.java
index 0024494..6175fd0 100644
--- a/src/org/connectbot/bean/SelectionArea.java
+++ b/src/org/connectbot/bean/SelectionArea.java
@@ -69,66 +69,76 @@ public class SelectionArea {
selectingOrigin = false;
}
- public void setTop(int top) {
- this.top = bottom = checkBounds(top, maxRows);
+ public void decrementRow() {
+ if (selectingOrigin)
+ setTop(top - 1);
+ else
+ setBottom(bottom - 1);
}
- public void decrementTop() {
- setTop(--top);
+ public void incrementRow() {
+ if (selectingOrigin)
+ setTop(top + 1);
+ else
+ setBottom(bottom + 1);
}
- public void incrementTop() {
- setTop(++top);
+ public void setRow(int row) {
+ if (selectingOrigin)
+ setTop(row);
+ else
+ setBottom(row);
+ }
+
+ private void setTop(int top) {
+ this.top = bottom = checkBounds(top, maxRows);
}
public int getTop() {
return Math.min(top, bottom);
}
- public void setBottom(int bottom) {
+ private void setBottom(int bottom) {
this.bottom = checkBounds(bottom, maxRows);
}
- public void decrementBottom() {
- setBottom(--bottom);
- }
-
- public void incrementBottom() {
- setBottom(++bottom);
- }
-
public int getBottom() {
return Math.max(top, bottom);
}
- public void setLeft(int left) {
- this.left = right = checkBounds(left, maxColumns);
+ public void decrementColumn() {
+ if (selectingOrigin)
+ setLeft(left - 1);
+ else
+ setRight(right - 1);
}
- public void decrementLeft() {
- setLeft(--left);
+ public void incrementColumn() {
+ if (selectingOrigin)
+ setLeft(left + 1);
+ else
+ setRight(right + 1);
}
- public void incrementLeft() {
- setLeft(++left);
+ public void setColumn(int column) {
+ if (selectingOrigin)
+ setLeft(column);
+ else
+ setRight(column);
+ }
+
+ private void setLeft(int left) {
+ this.left = right = checkBounds(left, maxColumns);
}
public int getLeft() {
return Math.min(left, right);
}
- public void setRight(int right) {
+ private void setRight(int right) {
this.right = checkBounds(right, maxColumns);
}
- public void decrementRight() {
- setRight(--right);
- }
-
- public void incrementRight() {
- setRight(++right);
- }
-
public int getRight() {
return Math.max(left, right);
}
@@ -166,6 +176,7 @@ public class SelectionArea {
return buffer.toString();
}
+ @Override
public String toString() {
StringBuilder buffer = new StringBuilder();
diff --git a/src/org/connectbot/service/TerminalBridge.java b/src/org/connectbot/service/TerminalBridge.java
index fff216e..6963a75 100644
--- a/src/org/connectbot/service/TerminalBridge.java
+++ b/src/org/connectbot/service/TerminalBridge.java
@@ -1022,10 +1022,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
case KeyEvent.KEYCODE_DPAD_LEFT:
if (selectingForCopy) {
- if (selectionArea.isSelectingOrigin())
- selectionArea.decrementLeft();
- else
- selectionArea.decrementRight();
+ selectionArea.decrementColumn();
redraw();
} else {
((vt320) buffer).keyPressed(vt320.KEY_LEFT, ' ',
@@ -1037,10 +1034,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
case KeyEvent.KEYCODE_DPAD_UP:
if (selectingForCopy) {
- if (selectionArea.isSelectingOrigin())
- selectionArea.decrementTop();
- else
- selectionArea.decrementBottom();
+ selectionArea.decrementRow();
redraw();
} else {
((vt320) buffer).keyPressed(vt320.KEY_UP, ' ',
@@ -1052,10 +1046,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
case KeyEvent.KEYCODE_DPAD_DOWN:
if (selectingForCopy) {
- if (selectionArea.isSelectingOrigin())
- selectionArea.incrementTop();
- else
- selectionArea.incrementBottom();
+ selectionArea.incrementRow();
redraw();
} else {
((vt320) buffer).keyPressed(vt320.KEY_DOWN, ' ',
@@ -1067,10 +1058,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (selectingForCopy) {
- if (selectionArea.isSelectingOrigin())
- selectionArea.incrementLeft();
- else
- selectionArea.incrementRight();
+ selectionArea.incrementColumn();
redraw();
} else {
((vt320) buffer).keyPressed(vt320.KEY_RIGHT, ' ',