/*
* Copyright (C) 2007-2010 Geometer Plus <contact@geometerplus.com>
*
* 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.*;
import org.geometerplus.zlibrary.core.application.ZLApplication;
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
import org.geometerplus.zlibrary.text.model.*;
import org.geometerplus.zlibrary.text.hyphenation.*;
import org.geometerplus.zlibrary.text.view.style.ZLTextStyleCollection;
public abstract class ZLTextView extends ZLTextViewBase {
public interface ScrollingMode {
int NO_OVERLAPPING = 0;
int KEEP_LINES = 1;
int SCROLL_LINES = 2;
int SCROLL_PERCENTAGE = 3;
};
private ZLTextModel myModel;
private final ZLTextSelectionModel mySelectionModel;
private interface SizeUnit {
int PIXEL_UNIT = 0;
int LINE_UNIT = 1;
};
private int myScrollingMode;
private int myOverlappingValue;
private ZLTextPage myPreviousPage = new ZLTextPage();
ZLTextPage myCurrentPage = new ZLTextPage();
private ZLTextPage myNextPage = new ZLTextPage();
private final HashMap<ZLTextLineInfo,ZLTextLineInfo> myLineInfoCache = new HashMap<ZLTextLineInfo,ZLTextLineInfo>();
public ZLTextView(ZLPaintContext context) {
super(context);
mySelectionModel = new ZLTextSelectionModel(this);
}
public synchronized void setModel(ZLTextModel model) {
ZLTextParagraphCursorCache.clear();
mySelectionModel.clear();
myModel = model;
myCurrentPage.reset();
myPreviousPage.reset();
myNextPage.reset();
setScrollingActive(false);
if (myModel != null) {
final int paragraphsNumber = myModel.getParagraphsNumber();
if (paragraphsNumber > 0) {
myCurrentPage.moveStartCursor(ZLTextParagraphCursor.cursor(myModel, 0));
}
}
}
public ZLTextModel getModel() {
return myModel;
}
public ZLTextWordCursor getStartCursor() {
if (myCurrentPage.StartCursor.isNull()) {
preparePaintInfo(myCurrentPage);
}
return myCurrentPage.StartCursor;
}
public ZLTextWordCursor getEndCursor() {
if (myCurrentPage.EndCursor.isNull()) {
preparePaintInfo(myCurrentPage);
}
return myCurrentPage.EndCursor;
}
private synchronized void gotoMark(ZLTextMark mark) {
if (mark == null) {
return;
}
myPreviousPage.reset();
myNextPage.reset();
boolean doRepaint = false;
if (myCurrentPage.StartCursor.isNull()) {
doRepaint = true;
preparePaintInfo(myCurrentPage);
}
if (myCurrentPage.StartCursor.isNull()) {
return;
}
if ((myCurrentPage.StartCursor.getParagraphIndex() != mark.ParagraphIndex) || (myCurrentPage.StartCursor.getMark().compareTo(mark) > 0)) {
doRepaint = true;
gotoPosition(mark.ParagraphIndex, 0, 0);
preparePaintInfo(myCurrentPage);
}
if (myCurrentPage.EndCursor.isNull()) {
preparePaintInfo(myCurrentPage);
}
while (mark.compareTo(myCurrentPage.EndCursor.getMark()) > 0) {
doRepaint = true;
scrollPage(true, ScrollingMode.NO_OVERLAPPING, 0);
preparePaintInfo(myCurrentPage);
}
if (doRepaint) {
if (myCurrentPage.StartCursor.isNull()) {
preparePaintInfo(myCurrentPage);
}
ZLApplication.Instance().repaintView();
}
}
public synchronized int search(final String text, boolean ignoreCase, boolean wholeText, boolean backward, boolean thisSectionOnly) {
if (text.length() == 0) {
return 0;
}
int startIndex = 0;
int endIndex = myModel.getParagraphsNumber();
if (thisSectionOnly) {
// TODO: implement
}
int count = myModel.search(text, startIndex, endIndex, ignoreCase);
myPreviousPage.reset();
myNextPage.reset();
if (!myCurrentPage.StartCursor.isNull()) {
rebuildPaintInfo();
if (count > 0) {
ZLTextMark mark = myCurrentPage.StartCursor.getMark();
gotoMark(wholeText ?
(backward ? myModel.getLastMark() : myModel.getFirstMark()) :
(backward ? myModel.getPreviousMark(mark) : myModel.getNextMark(mark)));
}
ZLApplication.Instance().repaintView();
}
return count;
}
public boolean canFindNext() {
final ZLTextWordCursor end = myCurrentPage.EndCursor;
return !end.isNull() && (myModel != null) && (myModel.getNextMark(end.getMark()) != null);
}
public synchronized void findNext() {
final ZLTextWordCursor end = myCurrentPage.EndCursor;
if (!end.isNull()) {
gotoMark(myModel.getNextMark(end.getMark()));
}
}
public boolean canFindPrevious() {
final ZLTextWordCursor start = myCurrentPage.StartCursor;
return !start.isNull() && (myModel != null) && (myModel.getPreviousMark(start.getMark()) != null);
}
public synchronized void findPrevious() {
final ZLTextWordCursor start = myCurrentPage.StartCursor;
if (!start.isNull()) {
gotoMark(myModel.getPreviousMark(start.getMark()));
}
}
public void clearFindResults() {
if (!findResultsAreEmpty()) {
myModel.removeAllMarks();
rebuildPaintInfo();
ZLApplication.Instance().repaintView();
}
}
public boolean findResultsAreEmpty() {
return (myModel == null) || myModel.getMarks().isEmpty();
}
private volatile boolean myScrollingIsActive;
protected boolean isScrollingActive() {
return myScrollingIsActive;
}
protected void setScrollingActive(boolean active) {
myScrollingIsActive = active;
}
public final synchronized void startAutoScrolling(int viewPage) {
if (isScrollingActive()) {
return;
}
setScrollingActive(true);
ZLApplication.Instance().startViewAutoScrolling(viewPage);
}
public synchronized void onScrollingFinished(int viewPage) {
setScrollingActive(false);
switch (viewPage) {
case PAGE_CENTRAL:
break;
case PAGE_LEFT:
case PAGE_TOP:
{
ZLTextPage swap = myNextPage;
myNextPage = myCurrentPage;
myCurrentPage = myPreviousPage;
myPreviousPage = swap;
myPreviousPage.reset();
if (myCurrentPage.PaintState == PaintStateEnum.NOTHING_TO_PAINT) {
preparePaintInfo(myNextPage);
myCurrentPage.EndCursor.setCursor(myNextPage.StartCursor);
myCurrentPage.PaintState = PaintStateEnum.END_IS_KNOWN;
} else if (!myCurrentPage.EndCursor.isNull() &&
!myNextPage.StartCursor.isNull() &&
!myCurrentPage.EndCursor.samePositionAs(myNextPage.StartCursor)) {
myNextPage.reset();
myNextPage.StartCursor.setCursor(myCurrentPage.EndCursor);
myNextPage.PaintState = PaintStateEnum.START_IS_KNOWN;
}
break;
}
case PAGE_RIGHT:
case PAGE_BOTTOM:
{
ZLTextPage swap = myPreviousPage;
myPreviousPage = myCurrentPage;
myCurrentPage = myNextPage;
myNextPage = swap;
myNextPage.reset();
if (myCurrentPage.PaintState == PaintStateEnum.NOTHING_TO_PAINT) {
preparePaintInfo(myPreviousPage);
myCurrentPage.StartCursor.setCursor(myPreviousPage.EndCursor);
myCurrentPage.PaintState = PaintStateEnum.START_IS_KNOWN;
}
break;
}
}
}
public synchronized void paint(int viewPage) {
Context.clear(getBackgroundColor());
if ((myModel == null) || (myModel.getParagraphsNumber() == 0)) {
return;
}
ZLTextPage page;
switch (viewPage) {
default:
case PAGE_CENTRAL:
page = myCurrentPage;
break;
case PAGE_TOP:
case PAGE_LEFT:
page = myPreviousPage;
if (myPreviousPage.PaintState == PaintStateEnum.NOTHING_TO_PAINT) {
preparePaintInfo(myCurrentPage);
myPreviousPage.EndCursor.setCursor(myCurrentPage.StartCursor);
myPrevious
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
android 开源项目 FBReaderJ (602个子文件)
configure.ac 234B
BookDownloaderInterface.aidl 928B
Makefile.am 991B
AUTHORS 263B
linebreakdata.c 52KB
linebreak.c 26KB
linebreakdef.c 5KB
ChangeLog 12KB
ChangeLog 4KB
CHANGES 591B
configure 656KB
DeflatingDecompressor.cpp 2KB
LineBreaker.cpp 1KB
ModelReader.cpp 95B
litres.ru.crt 956B
doxygen.css 6KB
tabs.css 2KB
depcomp 17KB
Doxyfile 49KB
xhtml-symbol.ent 14KB
xhtml-lat1.ent 11KB
xhtml-special.ent 4KB
MiniHelp.ru.fb2 3KB
MiniHelp.vi.fb2 3KB
MiniHelp.it.fb2 3KB
MiniHelp.fr.fb2 3KB
MiniHelp.de.fb2 3KB
MiniHelp.hu.fb2 2KB
MiniHelp.zh.fb2 2KB
MiniHelp.en.fb2 2KB
Makefile.gcc 4KB
tab_r.gif 3KB
tab_l.gif 706B
tab_b.gif 35B
config.guess 43KB
linebreakdef.h 5KB
linebreak.h 3KB
HowToBuild 806B
linebreak_8c.html 46KB
linebreakdef_8h.html 37KB
linebreakdef_8h_source.html 24KB
linebreakdef_8h-source.html 24KB
linebreak_8h.html 23KB
linebreakdef_8c.html 18KB
globals.html 15KB
linebreak_8h-source.html 11KB
linebreak_8h_source.html 11KB
globals_eval.html 9KB
structLineBreakProperties.html 5KB
structLineBreakPropertiesLang.html 5KB
globals_func.html 4KB
structLineBreakPropertiesIndex.html 4KB
globals_vars.html 3KB
linebreakdata_8c.html 3KB
functions.html 3KB
globals_defs.html 3KB
functions_vars.html 3KB
files.html 2KB
globals_type.html 2KB
classes.html 2KB
annotated.html 2KB
globals_enum.html 2KB
index.html 1KB
Makefile.in 21KB
config.h.in 1KB
install-sh 13KB
ZLTextView.java 46KB
SQLiteBooksDatabase.java 35KB
OPDSXMLReader.java 24KB
ZLXMLParser.java 24KB
NetworkLibrary.java 17KB
PluckerBookReader.java 17KB
NetworkBookActions.java 15KB
NetworkCatalogActions.java 15KB
NetworkOPDSFeedReader.java 15KB
ZLHtmlParser.java 14KB
LitResAuthenticationManager.java 13KB
ZLAndroidWidget.java 12KB
BookmarksActivity.java 12KB
BookReader.java 12KB
Library.java 12KB
BookDownloaderService.java 11KB
NetworkView.java 11KB
OPDSLinkXMLReader.java 11KB
NetworkBookInfoActivity.java 11KB
FBReader.java 10KB
FB2Reader.java 10KB
LitResXMLReader.java 10KB
LibraryTabActivity.java 10KB
ATOMDateConstruct.java 9KB
HtmlReader.java 9KB
ZLTextPlainModel.java 9KB
NetworkBaseActivity.java 9KB
RegisterUserDialog.java 9KB
ZLApplication.java 9KB
Book.java 9KB
FBReader.java 9KB
OEBBookReader.java 8KB
NetworkLibraryActivity.java 8KB
CustomCatalogDialog.java 8KB
共 602 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
- zhoushuangcheng2012-10-04文件很全面 都是看的累.
- 北极冰淇淋2014-06-08还可以,能用
- l253219372011-10-18在window下不知道 如何编辑成功
yiyinianhua
- 粉丝: 1
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功