Esempio n. 1
0
  synchronized void openBookInternal(Book book, Bookmark bookmark) {
    if (book == null) {
      book = Library.Instance().getRecentBook();
      if (book == null || !book.File.exists()) {
        book = Book.getByFile(Library.getHelpFile());
      }
      if (book == null) {
        return;
      }
    }
    if (Model != null) {
      if (bookmark == null & book.File.getPath().equals(Model.Book.File.getPath())) {
        return;
      }
    }

    if (book != null) {
      onViewChanged();

      if (Model != null) {
        Model.Book.storePosition(BookTextView.getStartCursor());
      }
      BookTextView.setModel(null);
      FootnoteView.setModel(null);
      clearTextCaches();

      Model = null;
      System.gc();
      System.gc();
      try {
        Model = BookModel.createModel(book);
        ZLTextHyphenator.Instance().load(book.getLanguage());
        BookTextView.setModel(Model.getTextModel());
        BookTextView.gotoPosition(book.getStoredPosition());
        if (bookmark == null) {
          setView(BookTextView);
        } else {
          gotoBookmark(bookmark);
        }
        Library.Instance().addBookToRecentList(book);
        final StringBuilder title = new StringBuilder(book.getTitle());
        if (!book.authors().isEmpty()) {
          boolean first = true;
          for (Author a : book.authors()) {
            title.append(first ? " (" : ", ");
            title.append(a.DisplayName);
            first = false;
          }
          title.append(")");
        }
        setTitle(title.toString());
      } catch (BookReadingException e) {
        processException(e);
      }
    }
    getViewWidget().reset();
    getViewWidget().repaint();
  }
 @Override
 protected void setExistingFlag(Collection<Book> books, boolean flag) {
   if (books.isEmpty()) {
     return;
   }
   final StringBuilder bookSet = new StringBuilder("(");
   boolean first = true;
   for (Book b : books) {
     if (first) {
       first = false;
     } else {
       bookSet.append(",");
     }
     bookSet.append(b.getId());
   }
   bookSet.append(")");
   myDatabase.execSQL(
       "UPDATE Books SET `exists` = " + (flag ? 1 : 0) + " WHERE book_id IN " + bookSet);
 }
Esempio n. 3
0
  private String createBookmarkText(ZLTextWordCursor cursor) {
    cursor = new ZLTextWordCursor(cursor);

    final StringBuilder builder = new StringBuilder();
    final StringBuilder sentenceBuilder = new StringBuilder();
    final StringBuilder phraseBuilder = new StringBuilder();

    int wordCounter = 0;
    int sentenceCounter = 0;
    int storedWordCounter = 0;
    boolean lineIsNonEmpty = false;
    boolean appendLineBreak = false;
    mainLoop:
    while ((wordCounter < 20) && (sentenceCounter < 3)) {
      while (cursor.isEndOfParagraph()) {
        if (!cursor.nextParagraph()) {
          break mainLoop;
        }
        if ((builder.length() > 0) && cursor.getParagraphCursor().isEndOfSection()) {
          break mainLoop;
        }
        if (phraseBuilder.length() > 0) {
          sentenceBuilder.append(phraseBuilder);
          phraseBuilder.delete(0, phraseBuilder.length());
        }
        if (sentenceBuilder.length() > 0) {
          if (appendLineBreak) {
            builder.append("\n");
          }
          builder.append(sentenceBuilder);
          sentenceBuilder.delete(0, sentenceBuilder.length());
          ++sentenceCounter;
          storedWordCounter = wordCounter;
        }
        lineIsNonEmpty = false;
        if (builder.length() > 0) {
          appendLineBreak = true;
        }
      }
      final ZLTextElement element = cursor.getElement();
      if (element instanceof ZLTextWord) {
        final ZLTextWord word = (ZLTextWord) element;
        if (lineIsNonEmpty) {
          phraseBuilder.append(" ");
        }
        phraseBuilder.append(word.Data, word.Offset, word.Length);
        ++wordCounter;
        lineIsNonEmpty = true;
        switch (word.Data[word.Offset + word.Length - 1]) {
          case ',':
          case ':':
          case ';':
          case ')':
            sentenceBuilder.append(phraseBuilder);
            phraseBuilder.delete(0, phraseBuilder.length());
            break;
          case '.':
          case '!':
          case '?':
            ++sentenceCounter;
            if (appendLineBreak) {
              builder.append("\n");
              appendLineBreak = false;
            }
            sentenceBuilder.append(phraseBuilder);
            phraseBuilder.delete(0, phraseBuilder.length());
            builder.append(sentenceBuilder);
            sentenceBuilder.delete(0, sentenceBuilder.length());
            storedWordCounter = wordCounter;
            break;
        }
      }
      cursor.nextWord();
    }
    if (storedWordCounter < 4) {
      if (sentenceBuilder.length() == 0) {
        sentenceBuilder.append(phraseBuilder);
      }
      if (appendLineBreak) {
        builder.append("\n");
      }
      builder.append(sentenceBuilder);
    }
    return builder.toString();
  }