mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
ZLTextModel refactoring: no interfaces for entries, final public fields instead of getters (in progress)
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@393 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
64df86aa98
commit
731f7eee31
19 changed files with 78 additions and 110 deletions
|
@ -2,9 +2,10 @@ package org.zlibrary.text.model;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.zlibrary.text.model.entry.ZLTextParagraphEntry;
|
||||
|
||||
public interface ZLTextParagraph {
|
||||
interface Entry {
|
||||
}
|
||||
|
||||
enum Kind {
|
||||
TEXT_PARAGRAPH,
|
||||
TREE_PARAGRAPH,
|
||||
|
@ -18,6 +19,6 @@ public interface ZLTextParagraph {
|
|||
Kind getKind();
|
||||
int getEntryNumber();
|
||||
int getTextLength();
|
||||
List<ZLTextParagraphEntry> getEntries();
|
||||
void addEntry(ZLTextParagraphEntry entry);
|
||||
List<Entry> getEntries();
|
||||
void addEntry(Entry entry);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package org.zlibrary.text.model.entry;
|
||||
|
||||
import org.zlibrary.core.image.ZLImage;
|
||||
import org.zlibrary.text.model.ZLTextParagraph;
|
||||
|
||||
public interface ZLImageEntry extends ZLTextParagraphEntry {
|
||||
public interface ZLImageEntry extends ZLTextParagraph.Entry {
|
||||
String getId();
|
||||
short getVOffset();
|
||||
ZLImage getImage();
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package org.zlibrary.text.model.entry;
|
||||
|
||||
public interface ZLTextControlEntry extends ZLTextParagraphEntry {
|
||||
byte getKind();
|
||||
boolean isStart();
|
||||
boolean isHyperlink();
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package org.zlibrary.text.model.entry;
|
||||
|
||||
public interface ZLTextEntry extends ZLTextParagraphEntry {
|
||||
import org.zlibrary.text.model.ZLTextParagraph;
|
||||
|
||||
public interface ZLTextEntry extends ZLTextParagraph.Entry {
|
||||
char[] getData();
|
||||
int getDataOffset();
|
||||
int getDataLength();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.zlibrary.text.model.entry;
|
||||
|
||||
public interface ZLTextFixedHSpaceEntry extends ZLTextParagraphEntry {
|
||||
import org.zlibrary.text.model.ZLTextParagraph;
|
||||
|
||||
public interface ZLTextFixedHSpaceEntry extends ZLTextParagraph.Entry {
|
||||
byte length();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.zlibrary.text.model.entry;
|
||||
|
||||
public interface ZLTextForcedControlEntry extends ZLTextParagraphEntry{
|
||||
import org.zlibrary.text.model.ZLTextParagraph;
|
||||
|
||||
public interface ZLTextForcedControlEntry extends ZLTextParagraph.Entry {
|
||||
boolean isLeftIndentSupported();
|
||||
short getLeftIndent();
|
||||
void setLeftIndent(short leftIndent);
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package org.zlibrary.text.model.entry;
|
||||
|
||||
public interface ZLTextHyperlinkControlEntry extends ZLTextControlEntry {
|
||||
String getLabel();
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package org.zlibrary.text.model.entry;
|
||||
|
||||
public interface ZLTextParagraphEntry {
|
||||
}
|
|
@ -1,16 +1,14 @@
|
|||
package org.zlibrary.text.model.impl;
|
||||
|
||||
import org.zlibrary.text.model.entry.ZLTextParagraphEntry;
|
||||
|
||||
class EntryPool {
|
||||
private static final ZLTextParagraphEntry[] ourStartEntries = new ZLTextParagraphEntry[256];
|
||||
private static final ZLTextParagraphEntry[] ourEndEntries = new ZLTextParagraphEntry[256];
|
||||
private static final ZLTextControlEntry[] ourStartEntries = new ZLTextControlEntry[256];
|
||||
private static final ZLTextControlEntry[] ourEndEntries = new ZLTextControlEntry[256];
|
||||
|
||||
public static ZLTextParagraphEntry getControlEntry(byte kind, boolean isStart) {
|
||||
ZLTextParagraphEntry[] entries = isStart ? ourStartEntries : ourEndEntries;
|
||||
ZLTextParagraphEntry entry = entries[kind & 0xFF];
|
||||
public static ZLTextControlEntry getControlEntry(byte kind, boolean isStart) {
|
||||
ZLTextControlEntry[] entries = isStart ? ourStartEntries : ourEndEntries;
|
||||
ZLTextControlEntry entry = entries[kind & 0xFF];
|
||||
if (entry == null) {
|
||||
entry = new ZLTextControlEntryImpl(kind, isStart);
|
||||
entry = new ZLTextControlEntry(kind, isStart);
|
||||
entries[kind & 0xFF] = entry;
|
||||
}
|
||||
return entry;
|
||||
|
|
|
@ -5,11 +5,9 @@ import org.zlibrary.text.model.ZLTextParagraph;
|
|||
import org.zlibrary.text.model.ZLTextPlainModel;
|
||||
import org.zlibrary.text.model.ZLTextTreeModel;
|
||||
import org.zlibrary.text.model.ZLTextTreeParagraph;
|
||||
import org.zlibrary.text.model.entry.ZLTextControlEntry;
|
||||
import org.zlibrary.text.model.entry.ZLTextEntry;
|
||||
import org.zlibrary.text.model.entry.ZLTextFixedHSpaceEntry;
|
||||
import org.zlibrary.text.model.entry.ZLTextForcedControlEntry;
|
||||
import org.zlibrary.text.model.entry.ZLTextHyperlinkControlEntry;
|
||||
|
||||
|
||||
public class ZLModelFactory {
|
||||
|
@ -40,7 +38,7 @@ public class ZLModelFactory {
|
|||
|
||||
//entries
|
||||
public ZLTextControlEntry createControlEntry(byte kind, boolean isStart) {
|
||||
return new ZLTextControlEntryImpl(kind, isStart);
|
||||
return new ZLTextControlEntry(kind, isStart);
|
||||
}
|
||||
|
||||
public ZLTextEntry createTextEntry(String text) {
|
||||
|
@ -49,7 +47,7 @@ public class ZLModelFactory {
|
|||
}
|
||||
|
||||
public ZLTextHyperlinkControlEntry createHyperlinkControlEntry(byte kind, String label) {
|
||||
return new ZLTextHyperlinkControlEntryImpl(kind, label);
|
||||
return new ZLTextHyperlinkControlEntry(kind, label);
|
||||
}
|
||||
|
||||
public ZLTextFixedHSpaceEntry createFixedHSpaceEntry(byte lenght) {
|
||||
|
|
17
src/org/zlibrary/text/model/impl/ZLTextControlEntry.java
Normal file
17
src/org/zlibrary/text/model/impl/ZLTextControlEntry.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package org.zlibrary.text.model.impl;
|
||||
|
||||
import org.zlibrary.text.model.ZLTextParagraph;
|
||||
|
||||
public class ZLTextControlEntry implements ZLTextParagraph.Entry {
|
||||
public final byte Kind;
|
||||
public final boolean IsStart;
|
||||
|
||||
ZLTextControlEntry(byte kind, boolean isStart) {
|
||||
Kind = kind;
|
||||
IsStart = isStart;
|
||||
}
|
||||
|
||||
public boolean isHyperlink() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package org.zlibrary.text.model.impl;
|
||||
|
||||
import org.zlibrary.text.model.entry.ZLTextControlEntry;
|
||||
|
||||
class ZLTextControlEntryImpl implements ZLTextControlEntry {
|
||||
private final byte myKind;
|
||||
private final boolean myIsStart;
|
||||
|
||||
ZLTextControlEntryImpl(byte kind, boolean isStart) {
|
||||
myKind = kind;
|
||||
myIsStart = isStart;
|
||||
}
|
||||
|
||||
public final byte getKind() {
|
||||
return myKind;
|
||||
}
|
||||
|
||||
public final boolean isStart() {
|
||||
return myIsStart;
|
||||
}
|
||||
|
||||
public boolean isHyperlink() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.zlibrary.text.model.impl;
|
||||
|
||||
public final class ZLTextHyperlinkControlEntry extends ZLTextControlEntry {
|
||||
private final String Label;
|
||||
|
||||
ZLTextHyperlinkControlEntry(byte kind, String label) {
|
||||
super(kind, true);
|
||||
Label = label;
|
||||
}
|
||||
|
||||
public boolean isHyperlink() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package org.zlibrary.text.model.impl;
|
||||
|
||||
import org.zlibrary.text.model.entry.ZLTextHyperlinkControlEntry;
|
||||
|
||||
class ZLTextHyperlinkControlEntryImpl extends ZLTextControlEntryImpl implements ZLTextHyperlinkControlEntry {
|
||||
private final String myLabel;
|
||||
|
||||
ZLTextHyperlinkControlEntryImpl(byte kind, String label) {
|
||||
super(kind, true);
|
||||
myLabel = label;
|
||||
}
|
||||
|
||||
public final String getLabel() {
|
||||
return myLabel;
|
||||
}
|
||||
|
||||
public boolean isHyperlink() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ import org.zlibrary.core.image.ZLImage;
|
|||
import org.zlibrary.text.model.ZLTextModel;
|
||||
import org.zlibrary.text.model.ZLTextParagraph;
|
||||
import org.zlibrary.text.model.entry.ZLTextForcedControlEntry;
|
||||
import org.zlibrary.text.model.entry.ZLTextParagraphEntry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
@ -81,7 +80,7 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
}
|
||||
|
||||
public void addHyperlinkControl(byte textKind, String label) {
|
||||
getLastParagraph().addEntry(new ZLTextHyperlinkControlEntryImpl(textKind, label));
|
||||
getLastParagraph().addEntry(new ZLTextHyperlinkControlEntry(textKind, label));
|
||||
}
|
||||
|
||||
public void addImage(String id, Map<String, ZLImage> imageMap, short vOffset) {
|
||||
|
@ -96,18 +95,18 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
StringBuilder sb = new StringBuilder();
|
||||
for (ZLTextParagraph paragraph: myParagraphs) {
|
||||
sb.append("[PARAGRAPH]\n");
|
||||
for (ZLTextParagraphEntry entry: paragraph.getEntries()) {
|
||||
for (ZLTextParagraph.Entry entry: paragraph.getEntries()) {
|
||||
if (entry instanceof ZLTextEntryImpl) {
|
||||
ZLTextEntryImpl textEntry = (ZLTextEntryImpl)entry;
|
||||
sb.append("[TEXT]");
|
||||
sb.append(textEntry.getData(), textEntry.getDataOffset(), textEntry.getDataLength());
|
||||
sb.append("[/TEXT]");
|
||||
} else if (entry instanceof ZLTextControlEntryImpl) {
|
||||
ZLTextControlEntryImpl entryControl = (ZLTextControlEntryImpl)entry;
|
||||
if (entryControl.isStart())
|
||||
sb.append("[CONTROL "+entryControl.getKind()+"]");
|
||||
} else if (entry instanceof ZLTextControlEntry) {
|
||||
ZLTextControlEntry controlEntry = (ZLTextControlEntry)entry;
|
||||
if (controlEntry.IsStart)
|
||||
sb.append("[CONTROL "+controlEntry.Kind+"]");
|
||||
else
|
||||
sb.append("[/CONTROL "+entryControl.getKind()+"]");
|
||||
sb.append("[/CONTROL "+controlEntry.Kind+"]");
|
||||
}
|
||||
}
|
||||
sb.append("[/PARAGRAPH]\n");
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.zlibrary.text.model.impl;
|
||||
|
||||
import org.zlibrary.text.model.ZLTextParagraph;
|
||||
import org.zlibrary.text.model.entry.ZLTextParagraphEntry;
|
||||
import org.zlibrary.text.model.impl.ZLTextEntryImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -9,12 +8,12 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
|
||||
class ZLTextParagraphImpl implements ZLTextParagraph {
|
||||
private final ArrayList<ZLTextParagraphEntry> myEntries = new ArrayList<ZLTextParagraphEntry>();
|
||||
private final ArrayList<ZLTextParagraph.Entry> myEntries = new ArrayList<ZLTextParagraph.Entry>();
|
||||
|
||||
ZLTextParagraphImpl() {
|
||||
}
|
||||
|
||||
public List<ZLTextParagraphEntry> getEntries() {
|
||||
public List<ZLTextParagraph.Entry> getEntries() {
|
||||
return Collections.unmodifiableList(myEntries);
|
||||
}
|
||||
|
||||
|
@ -28,7 +27,7 @@ class ZLTextParagraphImpl implements ZLTextParagraph {
|
|||
|
||||
public int getTextLength() {
|
||||
int size = 0;
|
||||
for (ZLTextParagraphEntry entry: myEntries) {
|
||||
for (ZLTextParagraph.Entry entry: myEntries) {
|
||||
if (entry instanceof ZLTextEntryImpl) {
|
||||
size += ((ZLTextEntryImpl)entry).getDataLength();
|
||||
}
|
||||
|
@ -36,7 +35,7 @@ class ZLTextParagraphImpl implements ZLTextParagraph {
|
|||
return size;
|
||||
}
|
||||
|
||||
public void addEntry(ZLTextParagraphEntry entry) {
|
||||
public void addEntry(ZLTextParagraph.Entry entry) {
|
||||
myEntries.add(entry);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,24 @@
|
|||
package org.zlibrary.text.view.impl;
|
||||
|
||||
import org.zlibrary.text.model.entry.ZLTextControlEntry;
|
||||
import org.zlibrary.text.model.impl.ZLTextControlEntry;
|
||||
|
||||
final class ZLTextControlElement extends ZLTextElement {
|
||||
private final ZLTextControlEntry myEntry;
|
||||
|
||||
/*package*/ ZLTextControlElement(ZLTextControlEntry entry) {
|
||||
ZLTextControlElement(ZLTextControlEntry entry) {
|
||||
// System.out.println(entry.getKind() + " " + entry.isStart());
|
||||
myEntry = entry;
|
||||
}
|
||||
|
||||
/* public Kind getKind() {
|
||||
return Kind.CONTROL_ELEMENT;
|
||||
}*/
|
||||
|
||||
public ZLTextControlEntry getEntry() {
|
||||
return myEntry;
|
||||
}
|
||||
|
||||
public byte getTextKind() {
|
||||
return getEntry().getKind();
|
||||
return myEntry.Kind;
|
||||
}
|
||||
|
||||
public boolean isStart() {
|
||||
return myEntry.isStart();
|
||||
return myEntry.IsStart;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.zlibrary.text.view.impl;
|
|||
import org.zlibrary.text.model.ZLTextModel;
|
||||
import org.zlibrary.text.model.ZLTextParagraph;
|
||||
import org.zlibrary.text.model.entry.*;
|
||||
import org.zlibrary.text.model.impl.*;
|
||||
|
||||
import org.zlibrary.core.image.ZLImage;
|
||||
|
||||
|
@ -21,11 +22,11 @@ public abstract class ZLTextParagraphCursor {
|
|||
//myOffset = 0;
|
||||
}
|
||||
|
||||
/*Why do we need ZLTextParagraphEntry interface?*/
|
||||
/*Why do we need ZLTextParagraph.Entry interface?*/
|
||||
|
||||
public void fill() {
|
||||
List <ZLTextParagraphEntry> entries = myParagraph.getEntries();
|
||||
for (ZLTextParagraphEntry entry : entries) {
|
||||
List <ZLTextParagraph.Entry> entries = myParagraph.getEntries();
|
||||
for (ZLTextParagraph.Entry entry : entries) {
|
||||
if (entry instanceof ZLTextEntry) {
|
||||
processTextEntry((ZLTextEntry) entry);
|
||||
} else if (entry instanceof ZLTextControlEntry) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.test.zlibrary.model;
|
||||
|
||||
import org.zlibrary.text.model.entry.ZLTextControlEntry;
|
||||
import org.zlibrary.text.model.entry.ZLTextParagraphEntry;
|
||||
import org.zlibrary.text.model.impl.ZLTextControlEntry;
|
||||
import org.zlibrary.text.model.impl.ZLModelFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
@ -13,8 +12,8 @@ public class TestTextControlEntry extends TestCase {
|
|||
boolean start = true;
|
||||
byte kind = (byte)0;
|
||||
ZLTextControlEntry entry = factory.createControlEntry(kind, start);
|
||||
assertEquals(entry.isHyperlink(), false);
|
||||
assertEquals(entry.getKind(), kind);
|
||||
assertEquals(entry.isStart(), start);
|
||||
//assertEquals(entry.isHyperlink(), false);
|
||||
assertEquals(entry.Kind, kind);
|
||||
assertEquals(entry.IsStart, start);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue