From 114b9b8ed0f7ea285083c70d24f53ad8962aecd7 Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Fri, 28 Jan 2011 06:19:23 +0000 Subject: [PATCH] images can be selected --- .../fbreader/fbreader/FBView.java | 8 ++-- .../text/view/ZLTextElementAreaVector.java | 29 +++++++------- .../text/view/ZLTextElementRegion.java | 10 ++++- .../text/view/ZLTextHyperlinkRegion.java | 6 --- .../zlibrary/text/view/ZLTextImageRegion.java | 38 +++++++++++++++++++ 5 files changed, 66 insertions(+), 25 deletions(-) create mode 100644 src/org/geometerplus/zlibrary/text/view/ZLTextImageRegion.java diff --git a/src/org/geometerplus/fbreader/fbreader/FBView.java b/src/org/geometerplus/fbreader/fbreader/FBView.java index f1b4c5e10..44f1c7e34 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBView.java +++ b/src/org/geometerplus/fbreader/fbreader/FBView.java @@ -177,7 +177,7 @@ public final class FBView extends ZLTextView { } } - final ZLTextElementRegion region = findRegion(x, y, 10, ZLTextHyperlinkRegion.Filter); + final ZLTextElementRegion region = findRegion(x, y, 10, ZLTextElementRegion.ImageOrHyperlinkFilter); if (region != null) { selectRegion(region); myReader.repaintView(); @@ -352,7 +352,7 @@ public final class FBView extends ZLTextView { if (myReader.DictionaryTappingActionOption.getValue() != FBReaderApp.DictionaryTappingAction.doNothing) { - final ZLTextElementRegion region = findRegion(x, y, 10, ZLTextElementRegion.Filter); + final ZLTextElementRegion region = findRegion(x, y, 10, ZLTextElementRegion.AnyRegionFilter); if (region != null) { selectRegion(region); myReader.repaintView(); @@ -370,7 +370,7 @@ public final class FBView extends ZLTextView { if (myReader.DictionaryTappingActionOption.getValue() != FBReaderApp.DictionaryTappingAction.doNothing) { - final ZLTextElementRegion region = findRegion(x, y, 10, ZLTextElementRegion.Filter); + final ZLTextElementRegion region = findRegion(x, y, 10, ZLTextElementRegion.AnyRegionFilter); if (region != null) { selectRegion(region); myReader.repaintView(); @@ -406,7 +406,7 @@ public final class FBView extends ZLTextView { ZLTextElementRegion region = currentRegion(); final ZLTextElementRegion.Filter filter = region instanceof ZLTextWordRegion || myReader.NavigateAllWordsOption.getValue() - ? ZLTextElementRegion.Filter : ZLTextHyperlinkRegion.Filter; + ? ZLTextElementRegion.AnyRegionFilter : ZLTextElementRegion.ImageOrHyperlinkFilter; region = nextRegion(direction, filter); if (region != null) { selectRegion(region); diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextElementAreaVector.java b/src/org/geometerplus/zlibrary/text/view/ZLTextElementAreaVector.java index c10f59cad..7bbb563e5 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextElementAreaVector.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextElementAreaVector.java @@ -37,20 +37,7 @@ final class ZLTextElementAreaVector extends ArrayList { @Override public boolean add(ZLTextElementArea area) { final ZLTextHyperlink hyperlink = area.Style.Hyperlink; - if (hyperlink.Id == null) { - if (area.Element instanceof ZLTextWord && ((ZLTextWord)area.Element).isAWord()) { - if (!(myCurrentElementRegion instanceof ZLTextWordRegion) || - ((ZLTextWordRegion)myCurrentElementRegion).Word != area.Element) { - myCurrentElementRegion = - new ZLTextWordRegion((ZLTextWord)area.Element, this, size()); - ElementRegions.add(myCurrentElementRegion); - } else { - myCurrentElementRegion.extend(); - } - } else { - myCurrentElementRegion = null; - } - } else { + if (hyperlink.Id != null) { if (!(myCurrentElementRegion instanceof ZLTextHyperlinkRegion) || ((ZLTextHyperlinkRegion)myCurrentElementRegion).Hyperlink != hyperlink) { myCurrentElementRegion = new ZLTextHyperlinkRegion(hyperlink, this, size()); @@ -58,6 +45,20 @@ final class ZLTextElementAreaVector extends ArrayList { } else { myCurrentElementRegion.extend(); } + } else if (area.Element instanceof ZLTextImageElement) { + ElementRegions.add(new ZLTextImageRegion((ZLTextImageElement)area.Element, this, size())); + myCurrentElementRegion = null; + } else if (area.Element instanceof ZLTextWord && ((ZLTextWord)area.Element).isAWord()) { + if (!(myCurrentElementRegion instanceof ZLTextWordRegion) || + ((ZLTextWordRegion)myCurrentElementRegion).Word != area.Element) { + myCurrentElementRegion = + new ZLTextWordRegion((ZLTextWord)area.Element, this, size()); + ElementRegions.add(myCurrentElementRegion); + } else { + myCurrentElementRegion.extend(); + } + } else { + myCurrentElementRegion = null; } return super.add(area); } diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextElementRegion.java b/src/org/geometerplus/zlibrary/text/view/ZLTextElementRegion.java index a0462970a..7371a134e 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextElementRegion.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextElementRegion.java @@ -28,12 +28,20 @@ public abstract class ZLTextElementRegion { boolean accepts(ZLTextElementRegion region); } - public static Filter Filter = new Filter() { + public static Filter AnyRegionFilter = new Filter() { public boolean accepts(ZLTextElementRegion region) { return true; } }; + public static Filter ImageOrHyperlinkFilter = new Filter() { + public boolean accepts(ZLTextElementRegion region) { + return + region instanceof ZLTextImageRegion || + region instanceof ZLTextHyperlinkRegion; + } + }; + private final List myList; private final int myFromIndex; private int myToIndex; diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextHyperlinkRegion.java b/src/org/geometerplus/zlibrary/text/view/ZLTextHyperlinkRegion.java index 26e8a8a00..5ef53b908 100644 --- a/src/org/geometerplus/zlibrary/text/view/ZLTextHyperlinkRegion.java +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextHyperlinkRegion.java @@ -22,12 +22,6 @@ package org.geometerplus.zlibrary.text.view; import java.util.List; public class ZLTextHyperlinkRegion extends ZLTextElementRegion { - public static Filter Filter = new Filter() { - public boolean accepts(ZLTextElementRegion region) { - return region instanceof ZLTextHyperlinkRegion; - } - }; - public final ZLTextHyperlink Hyperlink; ZLTextHyperlinkRegion(ZLTextHyperlink hyperlink, List list, int fromIndex) { diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextImageRegion.java b/src/org/geometerplus/zlibrary/text/view/ZLTextImageRegion.java new file mode 100644 index 000000000..7c76a08fc --- /dev/null +++ b/src/org/geometerplus/zlibrary/text/view/ZLTextImageRegion.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2009-2011 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +package org.geometerplus.zlibrary.text.view; + +import java.util.List; + +public class ZLTextImageRegion extends ZLTextElementRegion { + public final ZLTextImageElement ImageElement; + + ZLTextImageRegion(ZLTextImageElement imageElement, List list, int fromIndex) { + super(list, fromIndex); + ImageElement = imageElement; + } + + public boolean equals(Object other) { + if (!(other instanceof ZLTextImageRegion)) { + return false; + } + return ImageElement == ((ZLTextImageRegion)other).ImageElement; + } +}