1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 09:49:19 +02:00

more interesting sample application

git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@122 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Nikolay Pultsin 2007-11-13 15:55:54 +00:00
parent 21bd36a26c
commit 356ada3740
4 changed files with 29 additions and 14 deletions

View file

@ -5,7 +5,7 @@ import org.zlibrary.core.library.ZLibrary;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
ZLibrary.init(); ZLibrary.init();
ZLibrary.run(new SampleApplication()); ZLibrary.run(new SampleApplication(args[0]));
ZLibrary.shutdown(); ZLibrary.shutdown();
} }
} }

View file

@ -4,9 +4,11 @@ import org.zlibrary.core.application.*;
public class SampleApplication extends ZLApplication { public class SampleApplication extends ZLApplication {
public SampleApplication() { public SampleApplication(String fileName) {
super("Sample"); super("Sample");
setView(new SampleView(this, getContext())); SampleView view = new SampleView(this, getContext());
view.setModel(fileName);
setView(view);
} }
public ZLKeyBindings keyBindings() { public ZLKeyBindings keyBindings() {

View file

@ -9,26 +9,39 @@ import org.zlibrary.text.model.entry.*;
import org.zlibrary.text.view.impl.*; import org.zlibrary.text.view.impl.*;
import org.fbreader.bookmodel.*;
import org.fbreader.formats.fb2.*;
class SampleView extends ZLView { class SampleView extends ZLView {
SampleView(SampleApplication application, ZLPaintContext context) { private BookModel myModel;
super(application, context);
void setModel(String fileName) {
myModel = new FB2Reader(fileName).read();
} }
public void paint() { SampleView(SampleApplication application, ZLPaintContext context) {
ZLPaintContext context = getContext(); super(application, context);
/*
ZLModelFactory modelFactory = new ZLModelFactory(); ZLModelFactory modelFactory = new ZLModelFactory();
ZLTextModel model = modelFactory.createPlainModel(); myModel = modelFactory.createPlainModel();
ZLTextParagraph paragraph = modelFactory.createParagraph(); ZLTextParagraph paragraph = modelFactory.createParagraph();
ZLTextEntry entry; ZLTextEntry entry;
entry = modelFactory.createTextEntry("First paragraph: Some text here "); entry = modelFactory.createTextEntry("First paragraph: Some text here ");
paragraph.addEntry(entry); paragraph.addEntry(entry);
model.addParagraphInternal(paragraph); myModel.addParagraphInternal(paragraph);
paragraph = modelFactory.createParagraph(); paragraph = modelFactory.createParagraph();
entry = modelFactory.createTextEntry(" Second paragraph: "); entry = modelFactory.createTextEntry(" Second paragraph: ");
paragraph.addEntry(entry); paragraph.addEntry(entry);
model.addParagraphInternal(paragraph); myModel.addParagraphInternal(paragraph);
*/
}
public void paint() {
ZLPaintContext context = getContext();
ZLTextModel model = myModel.getBookModel();
int paragraphs = model.getParagraphsNumber(); int paragraphs = model.getParagraphsNumber();
int h = 0; int h = 0;
int dh = context.stringHeight(); int dh = context.stringHeight();

View file

@ -4,17 +4,17 @@ package org.zlibrary.text.view.impl;
public class ZLTextWord extends ZLTextElement { public class ZLTextWord extends ZLTextElement {
public String myData; public String myData;
public short mySize; //public short mySize;
public short myLength; public short myLength;
public int myParagraphOffset; //public int myParagraphOffset;
/*Temporarily made public to avoid implementing ZLTextElementPool with all its messy allocators, wtf is it?*/ /*Temporarily made public to avoid implementing ZLTextElementPool with all its messy allocators, wtf is it?*/
public ZLTextWord(String data, short size, int paragraphOffset) { public ZLTextWord(String data, short size, int paragraphOffset) {
myData = data; myData = data;
mySize = size; //mySize = size;
myLength = (short) data.length(); myLength = (short) data.length();
myParagraphOffset = paragraphOffset; //myParagraphOffset = paragraphOffset;
} }
/* public Kind getKind() { /* public Kind getKind() {