protected HeaderFooter() {
//
}
-
+
/**
* @return the internal text representation (combining center, left and right parts).
* Possibly empty string if no header or footer is set. Never <code>null</code>.
*/
- protected abstract String getRawText();
-
+ protected abstract String getRawText();
+
private String[] splitParts() {
String text = getRawText();
// default values
String _center = "";
String _right = "";
+// FIXME: replace outer goto. just eww.
+ outer:
while (text.length() > 1) {
if (text.charAt(0) != '&') {
// Mimics the behaviour of Excel, which would put it in the center.
}
int pos = text.length();
switch (text.charAt(1)) {
- case 'L':
- if (text.contains("&C")) {
- pos = Math.min(pos, text.indexOf("&C"));
- }
- if (text.contains("&R")) {
- pos = Math.min(pos, text.indexOf("&R"));
- }
- _left = text.substring(2, pos);
- text = text.substring(pos);
- return new String[] { _left, _center, _right, };
- case 'C':
- if (text.contains("&L")) {
- pos = Math.min(pos, text.indexOf("&L"));
- }
- if (text.contains("&R")) {
- pos = Math.min(pos, text.indexOf("&R"));
- }
- _center = text.substring(2, pos);
- text = text.substring(pos);
- return new String[] { _left, _center, _right, };
- case 'R':
- if (text.contains("&C")) {
- pos = Math.min(pos, text.indexOf("&C"));
- }
- if (text.contains("&L")) {
- pos = Math.min(pos, text.indexOf("&L"));
- }
- _right = text.substring(2, pos);
- text = text.substring(pos);
- return new String[] { _left, _center, _right, };
- default:
- // Mimics the behaviour of Excel, which would put it in the center.
- _center = text;
- break;
+ case 'L':
+ if (text.contains("&C")) {
+ pos = Math.min(pos, text.indexOf("&C"));
+ }
+ if (text.contains("&R")) {
+ pos = Math.min(pos, text.indexOf("&R"));
+ }
+ _left = text.substring(2, pos);
+ text = text.substring(pos);
+ break;
+ case 'C':
+ if (text.contains("&L")) {
+ pos = Math.min(pos, text.indexOf("&L"));
+ }
+ if (text.contains("&R")) {
+ pos = Math.min(pos, text.indexOf("&R"));
+ }
+ _center = text.substring(2, pos);
+ text = text.substring(pos);
+ break;
+ case 'R':
+ if (text.contains("&C")) {
+ pos = Math.min(pos, text.indexOf("&C"));
+ }
+ if (text.contains("&L")) {
+ pos = Math.min(pos, text.indexOf("&L"));
+ }
+ _right = text.substring(2, pos);
+ text = text.substring(pos);
+ break;
+ default:
+ // Mimics the behaviour of Excel, which would put it in the center.
+ _center = text;
+ break outer;
}
}
- return null;
+ return new String[] { _left, _center, _right, };
}
/**
* @param newLeft The string to set as the left side.
*/
public final void setLeft(String newLeft) {
- updatePart(0, newLeft);
+ updatePart(0, newLeft);
}
/**
* @param newCenter The string to set as the center.
*/
public final void setCenter(String newCenter) {
- updatePart(1, newCenter);
+ updatePart(1, newCenter);
}
/**
* @param newRight The string to set as the right side.
*/
public final void setRight(String newRight) {
- updatePart(2, newRight);
+ updatePart(2, newRight);
}
-
+
private void updatePart(int partIndex, String newValue) {
String[] parts = splitParts();
parts[partIndex] = newValue == null ? "" : newValue;
String _left = parts[0];
String _center = parts[1];
String _right = parts[2];
-
+
if (_center.length() < 1 && _left.length() < 1 && _right.length() < 1) {
setHeaderFooterText("");
return;
UNDERLINE_FIELD ("&U", true),
DOUBLE_UNDERLINE_FIELD ("&E", true),
;
-
+
private final String _representation;
private final boolean _occursInPairs;
private MarkupTag(String sequence, boolean occursInPairs) {
return _occursInPairs;
}
}
-}
+}
\ No newline at end of file