mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
renamed SampleAppliction -> FBReader
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@123 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
356ada3740
commit
ef9eb40af6
6 changed files with 74 additions and 92 deletions
18
src/org/fbreader/fbreader/FBReader.java
Normal file
18
src/org/fbreader/fbreader/FBReader.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package org.fbreader.fbreader;
|
||||||
|
|
||||||
|
import org.zlibrary.core.application.ZLApplication;
|
||||||
|
import org.zlibrary.core.application.ZLKeyBindings;
|
||||||
|
import org.zlibrary.text.view.ZLTextView;
|
||||||
|
|
||||||
|
public class FBReader extends ZLApplication {
|
||||||
|
public FBReader(String fileName) {
|
||||||
|
super("Sample");
|
||||||
|
ZLTextView view = new ZLTextView(this, getContext());
|
||||||
|
view.setModel(fileName);
|
||||||
|
setView(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZLKeyBindings keyBindings() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
package org.zlibrary.sampleview;
|
package org.fbreader.fbreader;
|
||||||
|
|
||||||
import org.zlibrary.core.library.ZLibrary;
|
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(args[0]));
|
ZLibrary.run(new FBReader(args[0]));
|
||||||
ZLibrary.shutdown();
|
ZLibrary.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,17 +0,0 @@
|
||||||
package org.zlibrary.sampleview;
|
|
||||||
|
|
||||||
import org.zlibrary.core.application.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class SampleApplication extends ZLApplication {
|
|
||||||
public SampleApplication(String fileName) {
|
|
||||||
super("Sample");
|
|
||||||
SampleView view = new SampleView(this, getContext());
|
|
||||||
view.setModel(fileName);
|
|
||||||
setView(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ZLKeyBindings keyBindings() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
package org.zlibrary.sampleview;
|
|
||||||
|
|
||||||
import org.zlibrary.core.view.ZLView;
|
|
||||||
import org.zlibrary.core.view.ZLPaintContext;
|
|
||||||
|
|
||||||
import org.zlibrary.text.model.*;
|
|
||||||
import org.zlibrary.text.model.impl.ZLModelFactory;
|
|
||||||
import org.zlibrary.text.model.entry.*;
|
|
||||||
|
|
||||||
import org.zlibrary.text.view.impl.*;
|
|
||||||
|
|
||||||
import org.fbreader.bookmodel.*;
|
|
||||||
import org.fbreader.formats.fb2.*;
|
|
||||||
|
|
||||||
class SampleView extends ZLView {
|
|
||||||
private BookModel myModel;
|
|
||||||
|
|
||||||
void setModel(String fileName) {
|
|
||||||
myModel = new FB2Reader(fileName).read();
|
|
||||||
}
|
|
||||||
|
|
||||||
SampleView(SampleApplication application, ZLPaintContext context) {
|
|
||||||
super(application, context);
|
|
||||||
|
|
||||||
/*
|
|
||||||
ZLModelFactory modelFactory = new ZLModelFactory();
|
|
||||||
myModel = modelFactory.createPlainModel();
|
|
||||||
ZLTextParagraph paragraph = modelFactory.createParagraph();
|
|
||||||
ZLTextEntry entry;
|
|
||||||
entry = modelFactory.createTextEntry("First paragraph: Some text here ");
|
|
||||||
paragraph.addEntry(entry);
|
|
||||||
myModel.addParagraphInternal(paragraph);
|
|
||||||
|
|
||||||
paragraph = modelFactory.createParagraph();
|
|
||||||
entry = modelFactory.createTextEntry(" Second paragraph: ");
|
|
||||||
paragraph.addEntry(entry);
|
|
||||||
myModel.addParagraphInternal(paragraph);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public void paint() {
|
|
||||||
ZLPaintContext context = getContext();
|
|
||||||
|
|
||||||
ZLTextModel model = myModel.getBookModel();
|
|
||||||
int paragraphs = model.getParagraphsNumber();
|
|
||||||
int h = 0;
|
|
||||||
int dh = context.stringHeight();
|
|
||||||
for (int i = 0; i < paragraphs; i++) {
|
|
||||||
ZLTextParagraphCursor cursor = ZLTextParagraphCursor.getCursor(model, i);
|
|
||||||
for (int j = 0; j < cursor.getParagraphLength(); j++) {
|
|
||||||
ZLTextElement element = cursor.getElement(j);
|
|
||||||
if (element instanceof ZLTextWord) {
|
|
||||||
String text = ((ZLTextWord) element).myData;
|
|
||||||
final int w = context.stringWidth(text);
|
|
||||||
h += dh;
|
|
||||||
context.drawString((context.getWidth() - w) / 2, h, text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
h += dh;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* String text = "42";
|
|
||||||
final int w = context.stringWidth(text);
|
|
||||||
context.drawString((context.getWidth() - w) / 2, context.stringHeight(), text);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public String caption() {
|
|
||||||
return "SampleView";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,57 @@
|
||||||
package org.zlibrary.text.view;
|
package org.zlibrary.text.view;
|
||||||
|
|
||||||
public interface ZLTextView {
|
import org.zlibrary.core.application.ZLApplication;
|
||||||
|
import org.zlibrary.core.view.ZLView;
|
||||||
|
import org.zlibrary.core.view.ZLPaintContext;
|
||||||
|
|
||||||
|
import org.zlibrary.text.model.*;
|
||||||
|
import org.zlibrary.text.model.impl.ZLModelFactory;
|
||||||
|
import org.zlibrary.text.model.entry.*;
|
||||||
|
|
||||||
|
import org.zlibrary.text.view.impl.*;
|
||||||
|
|
||||||
|
import org.fbreader.bookmodel.*;
|
||||||
|
import org.fbreader.formats.fb2.*;
|
||||||
|
|
||||||
|
public class ZLTextView extends ZLView {
|
||||||
|
private BookModel myModel;
|
||||||
|
|
||||||
|
public ZLTextView(ZLApplication application, ZLPaintContext context) {
|
||||||
|
super(application, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModel(String fileName) {
|
||||||
|
myModel = new FB2Reader(fileName).read();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paint() {
|
||||||
|
ZLPaintContext context = getContext();
|
||||||
|
|
||||||
|
ZLTextModel model = myModel.getBookModel();
|
||||||
|
int paragraphs = model.getParagraphsNumber();
|
||||||
|
int h = 0;
|
||||||
|
int dh = context.stringHeight();
|
||||||
|
for (int i = 0; i < paragraphs; i++) {
|
||||||
|
ZLTextParagraphCursor cursor = ZLTextParagraphCursor.getCursor(model, i);
|
||||||
|
for (int j = 0; j < cursor.getParagraphLength(); j++) {
|
||||||
|
ZLTextElement element = cursor.getElement(j);
|
||||||
|
if (element instanceof ZLTextWord) {
|
||||||
|
String text = ((ZLTextWord) element).myData;
|
||||||
|
final int w = context.stringWidth(text);
|
||||||
|
h += dh;
|
||||||
|
context.drawString((context.getWidth() - w) / 2, h, text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
h += dh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* String text = "42";
|
||||||
|
final int w = context.stringWidth(text);
|
||||||
|
context.drawString((context.getWidth() - w) / 2, context.stringHeight(), text);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
public String caption() {
|
||||||
|
return "SampleView";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.zlibrary.text.view.impl;
|
||||||
import org.zlibrary.text.model.*;
|
import org.zlibrary.text.model.*;
|
||||||
import org.zlibrary.text.view.ZLTextView;
|
import org.zlibrary.text.view.ZLTextView;
|
||||||
|
|
||||||
class ZLTextViewImpl implements ZLTextView {
|
class ZLTextViewImpl { //implements ZLTextView {
|
||||||
|
|
||||||
private ZLTextModel myModel;
|
private ZLTextModel myModel;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue