mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
a refactoring: soul is extracted
This commit is contained in:
parent
8badfdeeb9
commit
95d78d3c6d
9 changed files with 186 additions and 154 deletions
|
@ -33,7 +33,8 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
import org.geometerplus.zlibrary.core.xml.ZLXMLReaderAdapter;
|
import org.geometerplus.zlibrary.core.xml.ZLXMLReaderAdapter;
|
||||||
import org.geometerplus.zlibrary.core.xml.ZLStringMap;
|
import org.geometerplus.zlibrary.core.xml.ZLStringMap;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.text.view.ZLTextWordRegion;
|
import org.geometerplus.zlibrary.text.view.ZLTextRegion;
|
||||||
|
import org.geometerplus.zlibrary.text.view.ZLTextWord;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
|
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
|
||||||
|
|
||||||
|
@ -178,8 +179,8 @@ public abstract class DictionaryUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openWordInDictionary(Activity activity, ZLTextWordRegion region) {
|
public static void openWordInDictionary(Activity activity, ZLTextWord word, ZLTextRegion region) {
|
||||||
final String text = region.Word.toString();
|
final String text = word.toString();
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int end = text.length();
|
int end = text.length();
|
||||||
for (; start < end && !Character.isLetterOrDigit(text.charAt(start)); ++start);
|
for (; start < end && !Character.isLetterOrDigit(text.charAt(start)); ++start);
|
||||||
|
|
|
@ -48,10 +48,15 @@ class ProcessHyperlinkAction extends FBAndroidAction {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
final ZLTextRegion region = Reader.getTextView().getSelectedRegion();
|
final ZLTextRegion region = Reader.getTextView().getSelectedRegion();
|
||||||
if (region instanceof ZLTextHyperlinkRegion) {
|
if (region == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ZLTextRegion.Soul soul = region.getSoul();
|
||||||
|
if (soul instanceof ZLTextHyperlinkRegionSoul) {
|
||||||
Reader.getTextView().hideSelectedRegionBorder();
|
Reader.getTextView().hideSelectedRegionBorder();
|
||||||
Reader.getViewWidget().repaint();
|
Reader.getViewWidget().repaint();
|
||||||
final ZLTextHyperlink hyperlink = ((ZLTextHyperlinkRegion)region).Hyperlink;
|
final ZLTextHyperlink hyperlink = ((ZLTextHyperlinkRegionSoul)soul).Hyperlink;
|
||||||
switch (hyperlink.Type) {
|
switch (hyperlink.Type) {
|
||||||
case FBHyperlinkType.EXTERNAL:
|
case FBHyperlinkType.EXTERNAL:
|
||||||
if (hyperlink.Id.startsWith(ACTION_LINK_PREFIX)) {
|
if (hyperlink.Id.startsWith(ACTION_LINK_PREFIX)) {
|
||||||
|
@ -65,10 +70,10 @@ class ProcessHyperlinkAction extends FBAndroidAction {
|
||||||
Reader.tryOpenFootnote(hyperlink.Id);
|
Reader.tryOpenFootnote(hyperlink.Id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (region instanceof ZLTextImageRegion) {
|
} else if (soul instanceof ZLTextImageRegionSoul) {
|
||||||
Reader.getTextView().hideSelectedRegionBorder();
|
Reader.getTextView().hideSelectedRegionBorder();
|
||||||
Reader.getViewWidget().repaint();
|
Reader.getViewWidget().repaint();
|
||||||
final String uriString = ((ZLTextImageRegion)region).ImageElement.URI;
|
final String uriString = ((ZLTextImageRegionSoul)soul).ImageElement.URI;
|
||||||
if (uriString != null) {
|
if (uriString != null) {
|
||||||
try {
|
try {
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
|
@ -83,9 +88,9 @@ class ProcessHyperlinkAction extends FBAndroidAction {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (region instanceof ZLTextWordRegion) {
|
} else if (soul instanceof ZLTextWordRegionSoul) {
|
||||||
DictionaryUtil.openWordInDictionary(
|
DictionaryUtil.openWordInDictionary(
|
||||||
BaseActivity, (ZLTextWordRegion)region
|
BaseActivity, ((ZLTextWordRegionSoul)soul).Word, region
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,8 +210,10 @@ public final class FBView extends ZLTextView {
|
||||||
}
|
}
|
||||||
|
|
||||||
final ZLTextRegion region = findRegion(x, y, MAX_SELECTION_DISTANCE, ZLTextRegion.AnyRegionFilter);
|
final ZLTextRegion region = findRegion(x, y, MAX_SELECTION_DISTANCE, ZLTextRegion.AnyRegionFilter);
|
||||||
|
if (region != null) {
|
||||||
|
final ZLTextRegion.Soul soul = region.getSoul();
|
||||||
boolean doSelectRegion = false;
|
boolean doSelectRegion = false;
|
||||||
if (region instanceof ZLTextWordRegion) {
|
if (soul instanceof ZLTextWordRegionSoul) {
|
||||||
switch (myReader.WordTappingActionOption.getValue()) {
|
switch (myReader.WordTappingActionOption.getValue()) {
|
||||||
case startSelecting:
|
case startSelecting:
|
||||||
myReader.doAction(ActionCode.SELECTION_HIDE_PANEL);
|
myReader.doAction(ActionCode.SELECTION_HIDE_PANEL);
|
||||||
|
@ -226,11 +228,11 @@ public final class FBView extends ZLTextView {
|
||||||
doSelectRegion = true;
|
doSelectRegion = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (region instanceof ZLTextImageRegion) {
|
} else if (soul instanceof ZLTextImageRegionSoul) {
|
||||||
doSelectRegion =
|
doSelectRegion =
|
||||||
myReader.ImageTappingActionOption.getValue() !=
|
myReader.ImageTappingActionOption.getValue() !=
|
||||||
FBReaderApp.ImageTappingAction.doNothing;
|
FBReaderApp.ImageTappingAction.doNothing;
|
||||||
} else if (region instanceof ZLTextHyperlinkRegion) {
|
} else if (soul instanceof ZLTextHyperlinkRegionSoul) {
|
||||||
doSelectRegion = true;
|
doSelectRegion = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,6 +242,7 @@ public final class FBView extends ZLTextView {
|
||||||
myReader.getViewWidget().repaint();
|
myReader.getViewWidget().repaint();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -255,19 +258,26 @@ public final class FBView extends ZLTextView {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ZLTextRegion selectedRegion = getSelectedRegion();
|
ZLTextRegion region = getSelectedRegion();
|
||||||
if (selectedRegion instanceof ZLTextHyperlinkRegion ||
|
if (region != null) {
|
||||||
selectedRegion instanceof ZLTextWordRegion) {
|
ZLTextRegion.Soul soul = region.getSoul();
|
||||||
|
if (soul instanceof ZLTextHyperlinkRegionSoul ||
|
||||||
|
soul instanceof ZLTextWordRegionSoul) {
|
||||||
if (myReader.WordTappingActionOption.getValue() !=
|
if (myReader.WordTappingActionOption.getValue() !=
|
||||||
FBReaderApp.WordTappingAction.doNothing) {
|
FBReaderApp.WordTappingAction.doNothing) {
|
||||||
final ZLTextRegion region = findRegion(x, y, MAX_SELECTION_DISTANCE, ZLTextRegion.AnyRegionFilter);
|
region = findRegion(x, y, MAX_SELECTION_DISTANCE, ZLTextRegion.AnyRegionFilter);
|
||||||
if (region instanceof ZLTextHyperlinkRegion || region instanceof ZLTextWordRegion) {
|
if (region != null) {
|
||||||
|
soul = region.getSoul();
|
||||||
|
if (soul instanceof ZLTextHyperlinkRegionSoul
|
||||||
|
|| soul instanceof ZLTextWordRegionSoul) {
|
||||||
selectRegion(region);
|
selectRegion(region);
|
||||||
myReader.getViewWidget().reset();
|
myReader.getViewWidget().reset();
|
||||||
myReader.getViewWidget().repaint();
|
myReader.getViewWidget().repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,13 +292,16 @@ public final class FBView extends ZLTextView {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean doRunAction = false;
|
|
||||||
final ZLTextRegion region = getSelectedRegion();
|
final ZLTextRegion region = getSelectedRegion();
|
||||||
if (region instanceof ZLTextWordRegion) {
|
if (region != null) {
|
||||||
|
final ZLTextRegion.Soul soul = region.getSoul();
|
||||||
|
|
||||||
|
boolean doRunAction = false;
|
||||||
|
if (soul instanceof ZLTextWordRegionSoul) {
|
||||||
doRunAction =
|
doRunAction =
|
||||||
myReader.WordTappingActionOption.getValue() ==
|
myReader.WordTappingActionOption.getValue() ==
|
||||||
FBReaderApp.WordTappingAction.openDictionary;
|
FBReaderApp.WordTappingAction.openDictionary;
|
||||||
} else if (region instanceof ZLTextImageRegion) {
|
} else if (soul instanceof ZLTextImageRegionSoul) {
|
||||||
doRunAction =
|
doRunAction =
|
||||||
myReader.ImageTappingActionOption.getValue() ==
|
myReader.ImageTappingActionOption.getValue() ==
|
||||||
FBReaderApp.ImageTappingAction.openImageView;
|
FBReaderApp.ImageTappingAction.openImageView;
|
||||||
|
@ -298,6 +311,7 @@ public final class FBView extends ZLTextView {
|
||||||
myReader.doAction(ActionCode.PROCESS_HYPERLINK);
|
myReader.doAction(ActionCode.PROCESS_HYPERLINK);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -311,9 +325,10 @@ public final class FBView extends ZLTextView {
|
||||||
(diffY > 0 ? Direction.down : Direction.up) :
|
(diffY > 0 ? Direction.down : Direction.up) :
|
||||||
(diffX > 0 ? Direction.leftToRight : Direction.rightToLeft);
|
(diffX > 0 ? Direction.leftToRight : Direction.rightToLeft);
|
||||||
|
|
||||||
ZLTextRegion region = currentRegion();
|
ZLTextRegion region = getSelectedRegion();
|
||||||
final ZLTextRegion.Filter filter =
|
final ZLTextRegion.Filter filter =
|
||||||
region instanceof ZLTextWordRegion || myReader.NavigateAllWordsOption.getValue()
|
(region != null && region.getSoul() instanceof ZLTextWordRegionSoul)
|
||||||
|
|| myReader.NavigateAllWordsOption.getValue()
|
||||||
? ZLTextRegion.AnyRegionFilter : ZLTextRegion.ImageOrHyperlinkFilter;
|
? ZLTextRegion.AnyRegionFilter : ZLTextRegion.ImageOrHyperlinkFilter;
|
||||||
region = nextRegion(direction, filter);
|
region = nextRegion(direction, filter);
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
|
|
|
@ -19,47 +19,43 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.view;
|
package org.geometerplus.zlibrary.text.view;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
|
|
||||||
final class ZLTextElementAreaVector extends ArrayList<ZLTextElementArea> {
|
final class ZLTextElementAreaVector extends ArrayList<ZLTextElementArea> {
|
||||||
private static final long serialVersionUID = -7880472347947563506L;
|
private static final long serialVersionUID = -7880472347947563506L;
|
||||||
|
|
||||||
final ArrayList<ZLTextRegion> ElementRegions = new ArrayList<ZLTextRegion>();
|
private final ArrayList<ZLTextRegion> myElementRegions = new ArrayList<ZLTextRegion>();
|
||||||
private ZLTextRegion myCurrentElementRegion;
|
private ZLTextRegion myCurrentElementRegion;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
ElementRegions.clear();
|
myElementRegions.clear();
|
||||||
myCurrentElementRegion = null;
|
myCurrentElementRegion = null;
|
||||||
super.clear();
|
super.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean add(ZLTextElementArea area) {
|
public boolean add(ZLTextElementArea area) {
|
||||||
|
if (myCurrentElementRegion != null
|
||||||
|
&& myCurrentElementRegion.getSoul().accepts(area)) {
|
||||||
|
myCurrentElementRegion.extend();
|
||||||
|
} else {
|
||||||
|
ZLTextRegion.Soul soul = null;
|
||||||
final ZLTextHyperlink hyperlink = area.Style.Hyperlink;
|
final ZLTextHyperlink hyperlink = area.Style.Hyperlink;
|
||||||
if (hyperlink.Id != null) {
|
if (hyperlink.Id != null) {
|
||||||
if (!(myCurrentElementRegion instanceof ZLTextHyperlinkRegion) ||
|
soul = new ZLTextHyperlinkRegionSoul(hyperlink);
|
||||||
((ZLTextHyperlinkRegion)myCurrentElementRegion).Hyperlink != hyperlink) {
|
|
||||||
myCurrentElementRegion = new ZLTextHyperlinkRegion(hyperlink, this, size());
|
|
||||||
ElementRegions.add(myCurrentElementRegion);
|
|
||||||
} else {
|
|
||||||
myCurrentElementRegion.extend();
|
|
||||||
}
|
|
||||||
} else if (area.Element instanceof ZLTextImageElement) {
|
} else if (area.Element instanceof ZLTextImageElement) {
|
||||||
ElementRegions.add(new ZLTextImageRegion((ZLTextImageElement)area.Element, this, size()));
|
soul = new ZLTextImageRegionSoul((ZLTextImageElement)area.Element);
|
||||||
myCurrentElementRegion = null;
|
|
||||||
} else if (area.Element instanceof ZLTextWord && ((ZLTextWord)area.Element).isAWord()) {
|
} else if (area.Element instanceof ZLTextWord && ((ZLTextWord)area.Element).isAWord()) {
|
||||||
if (!(myCurrentElementRegion instanceof ZLTextWordRegion) ||
|
soul = new ZLTextWordRegionSoul((ZLTextWord)area.Element);
|
||||||
((ZLTextWordRegion)myCurrentElementRegion).Word != area.Element) {
|
|
||||||
myCurrentElementRegion =
|
|
||||||
new ZLTextWordRegion((ZLTextWord)area.Element, this, size());
|
|
||||||
ElementRegions.add(myCurrentElementRegion);
|
|
||||||
} else {
|
|
||||||
myCurrentElementRegion.extend();
|
|
||||||
}
|
}
|
||||||
|
if (soul != null) {
|
||||||
|
myCurrentElementRegion = new ZLTextRegion(soul, this, size());
|
||||||
|
myElementRegions.add(myCurrentElementRegion);
|
||||||
} else {
|
} else {
|
||||||
myCurrentElementRegion = null;
|
myCurrentElementRegion = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return super.add(area);
|
return super.add(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,4 +79,20 @@ final class ZLTextElementAreaVector extends ArrayList<ZLTextElementArea> {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<ZLTextRegion> elementRegions() {
|
||||||
|
return Collections.unmodifiableList(myElementRegions);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZLTextRegion getRegion(ZLTextRegion.Soul soul) {
|
||||||
|
if (soul == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (ZLTextRegion region : myElementRegions) {
|
||||||
|
if (soul.equals(region.getSoul())) {
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,21 +19,23 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.view;
|
package org.geometerplus.zlibrary.text.view;
|
||||||
|
|
||||||
import java.util.List;
|
public class ZLTextHyperlinkRegionSoul extends ZLTextRegion.Soul {
|
||||||
|
|
||||||
public class ZLTextHyperlinkRegion extends ZLTextRegion {
|
|
||||||
public final ZLTextHyperlink Hyperlink;
|
public final ZLTextHyperlink Hyperlink;
|
||||||
|
|
||||||
ZLTextHyperlinkRegion(ZLTextHyperlink hyperlink, List<ZLTextElementArea> list, int fromIndex) {
|
ZLTextHyperlinkRegionSoul(ZLTextHyperlink hyperlink) {
|
||||||
super(list, fromIndex);
|
|
||||||
Hyperlink = hyperlink;
|
Hyperlink = hyperlink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean accepts(ZLTextElementArea area) {
|
||||||
|
return Hyperlink == area.Style.Hyperlink;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (!(other instanceof ZLTextHyperlinkRegion)) {
|
if (!(other instanceof ZLTextHyperlinkRegionSoul)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return Hyperlink == ((ZLTextHyperlinkRegion)other).Hyperlink;
|
return Hyperlink == ((ZLTextHyperlinkRegionSoul)other).Hyperlink;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,21 +19,23 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.view;
|
package org.geometerplus.zlibrary.text.view;
|
||||||
|
|
||||||
import java.util.List;
|
public class ZLTextImageRegionSoul extends ZLTextRegion.Soul {
|
||||||
|
|
||||||
public class ZLTextImageRegion extends ZLTextRegion {
|
|
||||||
public final ZLTextImageElement ImageElement;
|
public final ZLTextImageElement ImageElement;
|
||||||
|
|
||||||
ZLTextImageRegion(ZLTextImageElement imageElement, List<ZLTextElementArea> list, int fromIndex) {
|
ZLTextImageRegionSoul(ZLTextImageElement imageElement) {
|
||||||
super(list, fromIndex);
|
|
||||||
ImageElement = imageElement;
|
ImageElement = imageElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean accepts(ZLTextElementArea area) {
|
||||||
|
return ImageElement == area.Element;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (!(other instanceof ZLTextImageRegion)) {
|
if (!(other instanceof ZLTextImageRegionSoul)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ImageElement == ((ZLTextImageRegion)other).ImageElement;
|
return ImageElement == ((ZLTextImageRegionSoul)other).ImageElement;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -23,7 +23,14 @@ import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
||||||
|
|
||||||
public abstract class ZLTextRegion implements Comparable<ZLTextRegion> {
|
public final class ZLTextRegion implements Comparable<ZLTextRegion> {
|
||||||
|
public static abstract class Soul {
|
||||||
|
abstract boolean accepts(ZLTextElementArea area);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract boolean equals(Object other);
|
||||||
|
}
|
||||||
|
|
||||||
public static interface Filter {
|
public static interface Filter {
|
||||||
boolean accepts(ZLTextRegion region);
|
boolean accepts(ZLTextRegion region);
|
||||||
}
|
}
|
||||||
|
@ -36,24 +43,27 @@ public abstract class ZLTextRegion implements Comparable<ZLTextRegion> {
|
||||||
|
|
||||||
public static Filter HyperlinkFilter = new Filter() {
|
public static Filter HyperlinkFilter = new Filter() {
|
||||||
public boolean accepts(ZLTextRegion region) {
|
public boolean accepts(ZLTextRegion region) {
|
||||||
return region instanceof ZLTextHyperlinkRegion;
|
return region.getSoul() instanceof ZLTextHyperlinkRegionSoul;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Filter ImageOrHyperlinkFilter = new Filter() {
|
public static Filter ImageOrHyperlinkFilter = new Filter() {
|
||||||
public boolean accepts(ZLTextRegion region) {
|
public boolean accepts(ZLTextRegion region) {
|
||||||
|
final Soul soul = region.getSoul();
|
||||||
return
|
return
|
||||||
region instanceof ZLTextImageRegion ||
|
soul instanceof ZLTextImageRegionSoul ||
|
||||||
region instanceof ZLTextHyperlinkRegion;
|
soul instanceof ZLTextHyperlinkRegionSoul;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final Soul mySoul;
|
||||||
private final List<ZLTextElementArea> myList;
|
private final List<ZLTextElementArea> myList;
|
||||||
private final int myFromIndex;
|
private final int myFromIndex;
|
||||||
private int myToIndex;
|
private int myToIndex;
|
||||||
private ZLTextHorizontalConvexHull myHull;
|
private ZLTextHorizontalConvexHull myHull;
|
||||||
|
|
||||||
ZLTextRegion(List<ZLTextElementArea> list, int fromIndex) {
|
ZLTextRegion(Soul soul, List<ZLTextElementArea> list, int fromIndex) {
|
||||||
|
mySoul = soul;
|
||||||
myList = list;
|
myList = list;
|
||||||
myFromIndex = fromIndex;
|
myFromIndex = fromIndex;
|
||||||
myToIndex = fromIndex + 1;
|
myToIndex = fromIndex + 1;
|
||||||
|
@ -64,6 +74,10 @@ public abstract class ZLTextRegion implements Comparable<ZLTextRegion> {
|
||||||
myHull = null;
|
myHull = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Soul getSoul() {
|
||||||
|
return mySoul;
|
||||||
|
}
|
||||||
|
|
||||||
private List<ZLTextElementArea> textAreas() {
|
private List<ZLTextElementArea> textAreas() {
|
||||||
return myList.subList(myFromIndex, myToIndex);
|
return myList.subList(myFromIndex, myToIndex);
|
||||||
}
|
}
|
||||||
|
@ -141,9 +155,6 @@ public abstract class ZLTextRegion implements Comparable<ZLTextRegion> {
|
||||||
return other == null || other.isExactlyUnder(this);
|
return other == null || other.isExactlyUnder(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract boolean equals(Object other);
|
|
||||||
|
|
||||||
public int compareTo(ZLTextRegion other) {
|
public int compareTo(ZLTextRegion other) {
|
||||||
if (myFromIndex != other.myFromIndex) {
|
if (myFromIndex != other.myFromIndex) {
|
||||||
return myFromIndex < other.myFromIndex ? -1 : 1;
|
return myFromIndex < other.myFromIndex ? -1 : 1;
|
||||||
|
|
|
@ -430,7 +430,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ZLTextRegion selectedElementRegion = getCurrentElementRegion(page);
|
final ZLTextRegion selectedElementRegion = getSelectedRegion(page);
|
||||||
if (selectedElementRegion != null && myHighlightSelectedRegion) {
|
if (selectedElementRegion != null && myHighlightSelectedRegion) {
|
||||||
selectedElementRegion.draw(context);
|
selectedElementRegion.draw(context);
|
||||||
}
|
}
|
||||||
|
@ -1348,7 +1348,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZLTextRegion mySelectedRegion;
|
private ZLTextRegion.Soul mySelectedRegionSoul;
|
||||||
private ZLTextSelection mySelection;
|
private ZLTextSelection mySelection;
|
||||||
private boolean myHighlightSelectedRegion = true;
|
private boolean myHighlightSelectedRegion = true;
|
||||||
|
|
||||||
|
@ -1357,17 +1357,12 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
Application.getViewWidget().reset();
|
Application.getViewWidget().reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZLTextRegion getCurrentElementRegion(ZLTextPage page) {
|
private ZLTextRegion getSelectedRegion(ZLTextPage page) {
|
||||||
final ArrayList<ZLTextRegion> elementRegions = page.TextElementMap.ElementRegions;
|
return page.TextElementMap.getRegion(mySelectedRegionSoul);
|
||||||
final int index = elementRegions.indexOf(mySelectedRegion);
|
|
||||||
if (index == -1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return elementRegions.get(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZLTextRegion getSelectedRegion() {
|
public ZLTextRegion getSelectedRegion() {
|
||||||
return getCurrentElementRegion(myCurrentPage);
|
return getSelectedRegion(myCurrentPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ZLTextRegion findRegion(int x, int y, ZLTextRegion.Filter filter) {
|
protected ZLTextRegion findRegion(int x, int y, ZLTextRegion.Filter filter) {
|
||||||
|
@ -1377,7 +1372,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
protected ZLTextRegion findRegion(int x, int y, int maxDistance, ZLTextRegion.Filter filter) {
|
protected ZLTextRegion findRegion(int x, int y, int maxDistance, ZLTextRegion.Filter filter) {
|
||||||
ZLTextRegion bestRegion = null;
|
ZLTextRegion bestRegion = null;
|
||||||
int distance = maxDistance + 1;
|
int distance = maxDistance + 1;
|
||||||
for (ZLTextRegion region : myCurrentPage.TextElementMap.ElementRegions) {
|
for (ZLTextRegion region : myCurrentPage.TextElementMap.elementRegions()) {
|
||||||
if (filter.accepts(region)) {
|
if (filter.accepts(region)) {
|
||||||
final int d = region.distanceTo(x, y);
|
final int d = region.distanceTo(x, y);
|
||||||
if (d < distance) {
|
if (d < distance) {
|
||||||
|
@ -1390,10 +1385,11 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void selectRegion(ZLTextRegion region) {
|
protected void selectRegion(ZLTextRegion region) {
|
||||||
if (region == null || !region.equals(mySelectedRegion)) {
|
final ZLTextRegion.Soul soul = region != null ? region.getSoul() : null;
|
||||||
|
if (soul == null || !soul.equals(mySelectedRegionSoul)) {
|
||||||
myHighlightSelectedRegion = true;
|
myHighlightSelectedRegion = true;
|
||||||
}
|
}
|
||||||
mySelectedRegion = region;
|
mySelectedRegionSoul = soul;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean initSelection(int x, int y) {
|
protected boolean initSelection(int x, int y) {
|
||||||
|
@ -1464,32 +1460,18 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetRegionPointer() {
|
public void resetRegionPointer() {
|
||||||
mySelectedRegion = null;
|
mySelectedRegionSoul = null;
|
||||||
myHighlightSelectedRegion = true;
|
myHighlightSelectedRegion = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ZLTextRegion currentRegion() {
|
|
||||||
if (mySelectedRegion == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final ArrayList<ZLTextRegion> elementRegions =
|
|
||||||
myCurrentPage.TextElementMap.ElementRegions;
|
|
||||||
if (elementRegions.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final int index = elementRegions.indexOf(mySelectedRegion);
|
|
||||||
return index >= 0 ? elementRegions.get(index) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ZLTextRegion nextRegion(Direction direction, ZLTextRegion.Filter filter) {
|
protected ZLTextRegion nextRegion(Direction direction, ZLTextRegion.Filter filter) {
|
||||||
final ArrayList<ZLTextRegion> elementRegions =
|
final List<ZLTextRegion> elementRegions = myCurrentPage.TextElementMap.elementRegions();
|
||||||
myCurrentPage.TextElementMap.ElementRegions;
|
|
||||||
if (elementRegions.isEmpty()) {
|
if (elementRegions.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = elementRegions.indexOf(mySelectedRegion);
|
final ZLTextRegion selectedRegion = getSelectedRegion();
|
||||||
mySelectedRegion = index >= 0 ? elementRegions.get(index) : null;
|
int index = selectedRegion != null ? elementRegions.indexOf(selectedRegion) : -1;
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case rightToLeft:
|
case rightToLeft:
|
||||||
|
@ -1516,7 +1498,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
case rightToLeft:
|
case rightToLeft:
|
||||||
for (; index >= 0; --index) {
|
for (; index >= 0; --index) {
|
||||||
final ZLTextRegion candidate = elementRegions.get(index);
|
final ZLTextRegion candidate = elementRegions.get(index);
|
||||||
if (filter.accepts(candidate) && candidate.isAtLeftOf(mySelectedRegion)) {
|
if (filter.accepts(candidate) && candidate.isAtLeftOf(selectedRegion)) {
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1524,7 +1506,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
case leftToRight:
|
case leftToRight:
|
||||||
for (; index < elementRegions.size(); ++index) {
|
for (; index < elementRegions.size(); ++index) {
|
||||||
final ZLTextRegion candidate = elementRegions.get(index);
|
final ZLTextRegion candidate = elementRegions.get(index);
|
||||||
if (filter.accepts(candidate) && candidate.isAtRightOf(mySelectedRegion)) {
|
if (filter.accepts(candidate) && candidate.isAtRightOf(selectedRegion)) {
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1537,10 +1519,10 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
if (!filter.accepts(candidate)) {
|
if (!filter.accepts(candidate)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (candidate.isExactlyUnder(mySelectedRegion)) {
|
if (candidate.isExactlyUnder(selectedRegion)) {
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
if (firstCandidate == null && candidate.isUnder(mySelectedRegion)) {
|
if (firstCandidate == null && candidate.isUnder(selectedRegion)) {
|
||||||
firstCandidate = candidate;
|
firstCandidate = candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1556,10 +1538,10 @@ public abstract class ZLTextView extends ZLTextViewBase {
|
||||||
if (!filter.accepts(candidate)) {
|
if (!filter.accepts(candidate)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (candidate.isExactlyOver(mySelectedRegion)) {
|
if (candidate.isExactlyOver(selectedRegion)) {
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
if (firstCandidate == null && candidate.isOver(mySelectedRegion)) {
|
if (firstCandidate == null && candidate.isOver(selectedRegion)) {
|
||||||
firstCandidate = candidate;
|
firstCandidate = candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,21 +19,23 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.view;
|
package org.geometerplus.zlibrary.text.view;
|
||||||
|
|
||||||
import java.util.List;
|
public class ZLTextWordRegionSoul extends ZLTextRegion.Soul {
|
||||||
|
|
||||||
public class ZLTextWordRegion extends ZLTextRegion {
|
|
||||||
public final ZLTextWord Word;
|
public final ZLTextWord Word;
|
||||||
|
|
||||||
ZLTextWordRegion(ZLTextWord word, List<ZLTextElementArea> list, int fromIndex) {
|
ZLTextWordRegionSoul(ZLTextWord word) {
|
||||||
super(list, fromIndex);
|
|
||||||
Word = word;
|
Word = word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean accepts(ZLTextElementArea area) {
|
||||||
|
return Word == area.Element;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (!(other instanceof ZLTextWordRegion)) {
|
if (!(other instanceof ZLTextWordRegionSoul)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return Word == ((ZLTextWordRegion)other).Word;
|
return Word == ((ZLTextWordRegionSoul)other).Word;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue