mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
ZLTextHighlighting converted to class, implements Comparable
This commit is contained in:
parent
23c5b45eb9
commit
3265f97512
4 changed files with 34 additions and 18 deletions
|
@ -21,14 +21,18 @@ package org.geometerplus.zlibrary.text.view;
|
|||
|
||||
import org.geometerplus.zlibrary.core.util.ZLColor;
|
||||
|
||||
interface ZLTextHighlighting {
|
||||
boolean clear();
|
||||
public abstract class ZLTextHighlighting implements Comparable<ZLTextHighlighting> {
|
||||
public abstract boolean isEmpty();
|
||||
|
||||
boolean isEmpty();
|
||||
ZLTextPosition getStartPosition();
|
||||
ZLTextPosition getEndPosition();
|
||||
ZLTextElementArea getStartArea(ZLTextPage page);
|
||||
ZLTextElementArea getEndArea(ZLTextPage page);
|
||||
public abstract ZLTextPosition getStartPosition();
|
||||
public abstract ZLTextPosition getEndPosition();
|
||||
public abstract ZLTextElementArea getStartArea(ZLTextPage page);
|
||||
public abstract ZLTextElementArea getEndArea(ZLTextPage page);
|
||||
|
||||
ZLColor getBackgroundColor();
|
||||
public abstract ZLColor getBackgroundColor();
|
||||
|
||||
public int compareTo(ZLTextHighlighting highlighting) {
|
||||
final int cmp = getStartPosition().compareTo(highlighting.getStartPosition());
|
||||
return cmp != 0 ? cmp : getEndPosition().compareTo(highlighting.getEndPosition());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.geometerplus.zlibrary.text.view;
|
|||
|
||||
import org.geometerplus.zlibrary.core.util.ZLColor;
|
||||
|
||||
class ZLTextManualHighlighting implements ZLTextHighlighting {
|
||||
class ZLTextManualHighlighting extends ZLTextHighlighting {
|
||||
private final ZLTextView myView;
|
||||
private ZLTextPosition myStartPosition;
|
||||
private ZLTextPosition myEndPosition;
|
||||
|
@ -44,26 +44,32 @@ class ZLTextManualHighlighting implements ZLTextHighlighting {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return myStartPosition == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLTextPosition getStartPosition() {
|
||||
return myStartPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLTextPosition getEndPosition() {
|
||||
return myEndPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLTextElementArea getStartArea(ZLTextPage page) {
|
||||
return page.TextElementMap.getFirstAfter(myStartPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLTextElementArea getEndArea(ZLTextPage page) {
|
||||
return page.TextElementMap.getLastBefore(myEndPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLColor getBackgroundColor() {
|
||||
return myView.getHighlightingBackgroundColor();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.geometerplus.zlibrary.text.view;
|
|||
|
||||
import org.geometerplus.zlibrary.core.util.ZLColor;
|
||||
|
||||
class ZLTextSelection implements ZLTextHighlighting {
|
||||
class ZLTextSelection extends ZLTextHighlighting {
|
||||
static class Point {
|
||||
int X;
|
||||
int Y;
|
||||
|
@ -47,6 +47,7 @@ class ZLTextSelection implements ZLTextHighlighting {
|
|||
myView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return myLeftMostRegionSoul == null;
|
||||
}
|
||||
|
@ -164,13 +165,13 @@ class ZLTextSelection implements ZLTextHighlighting {
|
|||
}
|
||||
|
||||
if (myCursorInMovement == ZLTextSelectionCursor.Right) {
|
||||
if (hasAPartAfterPage(page)) {
|
||||
if (hasPartAfterPage(page)) {
|
||||
myView.scrollPage(true, ZLTextView.ScrollingMode.SCROLL_LINES, 1);
|
||||
myView.Application.getViewWidget().reset();
|
||||
myView.preparePaintInfo();
|
||||
}
|
||||
} else {
|
||||
if (hasAPartBeforePage(page)) {
|
||||
if (hasPartBeforePage(page)) {
|
||||
myView.scrollPage(false, ZLTextView.ScrollingMode.SCROLL_LINES, 1);
|
||||
myView.Application.getViewWidget().reset();
|
||||
myView.preparePaintInfo();
|
||||
|
@ -185,6 +186,7 @@ class ZLTextSelection implements ZLTextHighlighting {
|
|||
&& myRightMostRegionSoul.compareTo(area) >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLTextPosition getStartPosition() {
|
||||
if (isEmpty()) {
|
||||
return null;
|
||||
|
@ -196,6 +198,7 @@ class ZLTextSelection implements ZLTextHighlighting {
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLTextPosition getEndPosition() {
|
||||
if (isEmpty()) {
|
||||
return null;
|
||||
|
@ -207,6 +210,7 @@ class ZLTextSelection implements ZLTextHighlighting {
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLTextElementArea getStartArea(ZLTextPage page) {
|
||||
if (isEmpty()) {
|
||||
return null;
|
||||
|
@ -223,6 +227,7 @@ class ZLTextSelection implements ZLTextHighlighting {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLTextElementArea getEndArea(ZLTextPage page) {
|
||||
if (isEmpty()) {
|
||||
return null;
|
||||
|
@ -239,7 +244,7 @@ class ZLTextSelection implements ZLTextHighlighting {
|
|||
return null;
|
||||
}
|
||||
|
||||
boolean hasAPartBeforePage(ZLTextPage page) {
|
||||
boolean hasPartBeforePage(ZLTextPage page) {
|
||||
if (isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -251,7 +256,7 @@ class ZLTextSelection implements ZLTextHighlighting {
|
|||
return cmp < 0 || (cmp == 0 && !firstPageArea.isFirstInElement());
|
||||
}
|
||||
|
||||
boolean hasAPartAfterPage(ZLTextPage page) {
|
||||
boolean hasPartAfterPage(ZLTextPage page) {
|
||||
if (isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -263,6 +268,7 @@ class ZLTextSelection implements ZLTextHighlighting {
|
|||
return cmp > 0 || (cmp == 0 && !lastPageArea.isLastInElement());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZLColor getBackgroundColor() {
|
||||
return myView.getSelectionBackgroundColor();
|
||||
}
|
||||
|
|
|
@ -292,7 +292,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
}
|
||||
|
||||
if (cursor == ZLTextSelectionCursor.Left) {
|
||||
if (mySelection.hasAPartBeforePage(page)) {
|
||||
if (mySelection.hasPartBeforePage(page)) {
|
||||
return null;
|
||||
}
|
||||
final ZLTextElementArea selectionStartArea = mySelection.getStartArea(page);
|
||||
|
@ -300,7 +300,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
return new ZLTextSelection.Point(selectionStartArea.XStart, selectionStartArea.YEnd);
|
||||
}
|
||||
} else {
|
||||
if (mySelection.hasAPartAfterPage(page)) {
|
||||
if (mySelection.hasPartAfterPage(page)) {
|
||||
return null;
|
||||
}
|
||||
final ZLTextElementArea selectionEndArea = mySelection.getEndArea(page);
|
||||
|
@ -1542,7 +1542,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
if (selectionStartArea != null) {
|
||||
return selectionStartArea.YStart;
|
||||
}
|
||||
if (mySelection.hasAPartBeforePage(myCurrentPage)) {
|
||||
if (mySelection.hasPartBeforePage(myCurrentPage)) {
|
||||
final ZLTextElementArea firstArea = myCurrentPage.TextElementMap.getFirstArea();
|
||||
return firstArea != null ? firstArea.YStart : 0;
|
||||
} else {
|
||||
|
@ -1559,7 +1559,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
|||
if (selectionEndArea != null) {
|
||||
return selectionEndArea.YEnd;
|
||||
}
|
||||
if (mySelection.hasAPartAfterPage(myCurrentPage)) {
|
||||
if (mySelection.hasPartAfterPage(myCurrentPage)) {
|
||||
final ZLTextElementArea lastArea = myCurrentPage.TextElementMap.getLastArea();
|
||||
return lastArea != null ? lastArea.YEnd : 0;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue