kz.greetgo.msoffice.docx.Run Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of greetgo.msoffice Show documentation
Show all versions of greetgo.msoffice Show documentation
greetgo library to generate or parse MS Office files
package kz.greetgo.msoffice.docx;
import kz.greetgo.msoffice.util.UtilOffice;
import java.awt.*;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
public class Run implements XmlWriter {
private List elements = new ArrayList();
private boolean bold = false;
private boolean italic = false;
private Underline underline = Underline.NONE;
private TextVertAlign textVertAlign = TextVertAlign.NORMAL;
private Highlight highlight = Highlight.NONE;
private Color color = null;
private Integer textSize;
private final String ownerPartName;
private final MSHelper msHelper;
Font font;
Run(String ownerPartName, MSHelper msHelper) {
this.ownerPartName = ownerPartName;
this.msHelper = msHelper;
}
public ImageElement createImage(InputSource inputSource) {
Relationship r = msHelper.createRelationshipForImage(ownerPartName, inputSource);
ImageElement ret = new ImageElement(r.getId());
elements.add(ret);
return ret;
}
@Override
public void write(PrintStream out) {
out.print("");
{
List options = new ArrayList();
{
if (isBold()) {
options.add(" ");
}
if (isItalic()) {
options.add(" ");
}
if (getUnderline() != null && getUnderline() != Underline.NONE) {
options.add(" ");
}
if (getTextVertAlign() != null && getTextVertAlign() != TextVertAlign.NORMAL) {
options.add(" ");
}
if (getHighlight() != null && getHighlight() != Highlight.NONE) {
options.add(" ");
}
if (getColor() != null) {
options.add(" ");
}
if (getTextSize() != null) {
options.add(" ");
options.add(" ");
}
}
if (options.size() > 0 || getFont() != null) {
out.print("");
for (String s : options) {
out.print(s);
}
if (getFont() != null) {
getFont().write(out);
}
out.print(" ");
}
}
for (RunElement e : elements) {
e.write(out);
}
out.print(" ");
}
public void addText(String text) {
elements.add(new RunText(text));
}
public void addTab() {
elements.add(new RunTab());
}
public void addBr() {
elements.add(new RunBr());
}
public void addPageBreak() {
elements.add(new PageBreak());
}
public void setBold(boolean bold) {
this.bold = bold;
}
public boolean isBold() {
return bold;
}
public void setUnderline(Underline underline) {
this.underline = underline;
}
public Underline getUnderline() {
return underline;
}
public void setItalic(boolean italic) {
this.italic = italic;
}
public boolean isItalic() {
return italic;
}
public void setTextVertAlign(TextVertAlign textVertAlign) {
this.textVertAlign = textVertAlign;
}
public TextVertAlign getTextVertAlign() {
return textVertAlign;
}
public void setHighlight(Highlight highlight) {
this.highlight = highlight;
}
public Highlight getHighlight() {
return highlight;
}
public void setColor(Color color) {
this.color = color;
}
public Color getColor() {
return color;
}
public void setTextSize(Integer textSize) {
this.textSize = textSize;
}
public Integer getTextSize() {
return textSize;
}
public void setFontName(String name) {
if (name == null) {
font = null;
return;
}
font = msHelper.getFont(name);
}
public Font getFont() {
return font;
}
private FieldAppender fieldAppender = null;
public FieldAppender field() {
if (fieldAppender == null) fieldAppender = new FieldAppender(elements);
return fieldAppender;
}
}