nick 2005/11/07 15:03:06
Modified: src/scratchpad/src/org/apache/poi/hslf/model TextRun.java
src/scratchpad/src/org/apache/poi/hslf/record
DummyPositionSensitiveRecordWithChildren.java
DummyRecordWithChildren.java
EscherTextboxWrapper.java FontCollection.java
Notes.java RecordContainer.java Slide.java
SlideListWithText.java
Log:
Bit of refactoring - move child records into parent RecordContainer
class, so we can then have more generic child record modification code
Revision Changes Path
1.5 +24 -0
jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
Index: TextRun.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TextRun.java 7 Nov 2005 22:24:12 -0000 1.4
+++ TextRun.java 7 Nov 2005 23:03:05 -0000 1.5
@@ -135,6 +135,9 @@
throw new IllegalArgumentException("Supplied
RichTextRun wasn't from this TextRun");
}
+ // Ensure a StyleTextPropAtom is present, adding if required
+ ensureStyleAtomPresent();
+
// Update the text length for its Paragraph and Character
stylings
LinkedList pStyles = _styleAtom.getParagraphStyles();
LinkedList cStyles = _styleAtom.getCharacterStyles();
@@ -191,6 +194,27 @@
_rtRuns[0] = new RichTextRun(this,0,s.length());
}
+ /**
+ * Ensure a StyleTextPropAtom is present for this run,
+ * by adding if required
+ */
+ private synchronized void ensureStyleAtomPresent() {
+ if(_styleAtom != null) {
+ // All there
+ return;
+ }
+
+ // Create a new one
+ _styleAtom = new StyleTextPropAtom(0);
+
+ // Use the TextHeader atom to get at the parent
+ RecordContainer runAtomsParent = _headerAtom.getParentRecord();
+
+ // Add the new StyleTextPropAtom after the TextCharsAtom /
TextBytesAtom
+ Record addAfter = _byteAtom;
+ if(_byteAtom == null) { addAfter = _charAtom; }
+ runAtomsParent.addChildAfter(_styleAtom, addAfter);
+ }
// Accesser methods follow
1.2 +0 -6
jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java
Index: DummyPositionSensitiveRecordWithChildren.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DummyPositionSensitiveRecordWithChildren.java 9 Jun 2005 15:09:16
-0000 1.1
+++ DummyPositionSensitiveRecordWithChildren.java 7 Nov 2005 23:03:05
-0000 1.2
@@ -37,7 +37,6 @@
public class DummyPositionSensitiveRecordWithChildren extends
PositionDependentRecordContainer
{
- private Record[] _children;
private byte[] _header;
private long _type;
@@ -60,11 +59,6 @@
*/
public long getRecordType() { return _type; }
- /**
- * Return any children
- */
- public Record[] getChildRecords() { return _children; }
-
/**
* Write the contents of the record back, so it can be written
* to disk
1.2 +0 -6
jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java
Index: DummyRecordWithChildren.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DummyRecordWithChildren.java 28 May 2005 05:36:00 -0000 1.1
+++ DummyRecordWithChildren.java 7 Nov 2005 23:03:05 -0000 1.2
@@ -33,7 +33,6 @@
public class DummyRecordWithChildren extends RecordContainer
{
- private Record[] _children;
private byte[] _header;
private long _type;
@@ -55,11 +54,6 @@
*/
public long getRecordType() { return _type; }
- /**
- * Return any children
- */
- public Record[] getChildRecords() { return _children; }
-
/**
* Write the contents of the record back, so it can be written
* to disk
1.2 +0 -6
jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java
Index: EscherTextboxWrapper.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/EscherTextboxWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EscherTextboxWrapper.java 28 May 2005 05:36:00 -0000 1.1
+++ EscherTextboxWrapper.java 7 Nov 2005 23:03:05 -0000 1.2
@@ -37,7 +37,6 @@
public class EscherTextboxWrapper extends RecordContainer
{
private EscherTextboxRecord _escherRecord;
- private Record[] _children;
private long _type;
/**
@@ -63,11 +62,6 @@
*/
public long getRecordType() { return _type; }
- /**
- * Return any children
- */
- public Record[] getChildRecords() { return _children; }
-
/**
* Stores the data for the child records back into the Escher layer.
* Doesn't actually do the writing out, that's left to the Escher
1.2 +3 -5
jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java
Index: FontCollection.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FontCollection.java 2 Aug 2005 17:16:20 -0000 1.1
+++ FontCollection.java 7 Nov 2005 23:03:05 -0000 1.2
@@ -30,7 +30,6 @@
public class FontCollection extends RecordContainer {
private List fonts;
- private Record[] _children;
private byte[] _header;
protected FontCollection(byte[] source, int start, int len) {
@@ -48,14 +47,13 @@
}
+ /**
+ * Return the type, which is 2005
+ */
public long getRecordType() {
return RecordTypes.FontCollection.typeID;
}
- public Record[] getChildRecords() {
- return _children;
- }
-
/**
* Write the contents of the record back, so it can be written
* to disk
1.3 +0 -6
jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java
Index: Notes.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Notes.java 9 Jun 2005 15:09:16 -0000 1.2
+++ Notes.java 7 Nov 2005 23:03:05 -0000 1.3
@@ -32,7 +32,6 @@
public class Notes extends PositionDependentRecordContainer
{
- private Record[] _children;
private byte[] _header;
private static long _type = 1008l;
@@ -80,11 +79,6 @@
*/
public long getRecordType() { return _type; }
- /**
- * Return any children
- */
- public Record[] getChildRecords() { return _children; }
-
/**
* Write the contents of the record back, so it can be written
* to disk
1.3 +35 -0
jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java
Index: RecordContainer.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RecordContainer.java 2 Aug 2005 17:16:20 -0000 1.2
+++ RecordContainer.java 7 Nov 2005 23:03:05 -0000 1.3
@@ -34,6 +34,13 @@
public abstract class RecordContainer extends Record
{
+ protected Record[] _children;
+
+ /**
+ * Return any children
+ */
+ public Record[] getChildRecords() { return _children; }
+
/**
* We're not an atom
*/
@@ -49,6 +56,34 @@
r[r.length-1] = newChild;
return r;
}
+
+ /**
+ * Adds the given Child Record after the supplied record
+ * @param newChild
+ * @param after
+ */
+ public synchronized void addChildAfter(Record newChild, Record after) {
+ boolean added = false;
+ Record[] newChildren = new Record[_children.length+1];
+ for(int i=0; i<_children.length; i++) {
+ int newPos = i;
+ if(added) { newPos++; }
+
+ newChildren[newPos] = _children[i];
+ if(_children[i].equals(after)) {
+ // Found one to add after
+ added = true;
+ newPos++;
+ newChildren[newPos] = newChild;
+ }
+ }
+
+ if(added) {
+ _children = newChildren;
+ } else {
+ throw new IllegalArgumentException("Asked to add a new
child after another record, but that record wasn't one of our children!");
+ }
+ }
/**
* Write out our header, and our children.
1.3 +0 -6
jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java
Index: Slide.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Slide.java 9 Jun 2005 15:09:16 -0000 1.2
+++ Slide.java 7 Nov 2005 23:03:05 -0000 1.3
@@ -32,7 +32,6 @@
public class Slide extends PositionDependentRecordContainer
{
- private Record[] _children;
private byte[] _header;
private static long _type = 1006l;
@@ -80,11 +79,6 @@
*/
public long getRecordType() { return _type; }
- /**
- * Return any children
- */
- public Record[] getChildRecords() { return _children; }
-
/**
* Write the contents of the record back, so it can be written
* to disk
1.2 +0 -6
jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java
Index: SlideListWithText.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SlideListWithText.java 28 May 2005 05:36:00 -0000 1.1
+++ SlideListWithText.java 7 Nov 2005 23:03:05 -0000 1.2
@@ -49,7 +49,6 @@
// For now, pretend to be an atom
public class SlideListWithText extends RecordContainer
{
- private Record[] _children;
private byte[] _header;
private static long _type = 4080;
@@ -109,11 +108,6 @@
*/
public long getRecordType() { return _type; }
- /**
- * We're pretending to be an atom, so return null
- */
- public Record[] getChildRecords() { return _children; }
-
/**
* Write the contents of the record back, so it can be written
* to disk
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/