1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
| private static AnnotationHandler drawBoxText(WBox box, DrawPdfHandler drawHandler, float boxLeft, float boxTop, float boxWidth, float boxHeight, boolean setbackground) throws DocumentException, IOException {
StringBuilder boxText = new StringBuilder();
String boxTitle=null;
PdfContentByte cb = drawHandler.getDirectContent();
ColumnText ct = new ColumnText(cb);
ct.setSimpleColumn(boxLeft, boxTop, boxLeft+boxWidth, boxTop-boxHeight, 15, drawHandler.getDrawPreferences().textBoxAlign);
boolean newLine = false;
Assignment assignment = WXMLTools.getAssignment(box);
if ( assignment!=null ) {
Chunk chunk = new Chunk(assignment.getName());
if ( setbackground ) {
chunk.setBackground(BG_COLOR);
}
ct.addText(chunk);
boxTitle = chunk.getContent();
Phrase statusPhrase = getStatusPhrase( PdfWxmlMessagesConstants.STATUS_MSG, assignment , setbackground, drawHandler);
if ( statusPhrase!=null ) {
ct.addText(Chunk.NEWLINE);
ct.addText(statusPhrase);
appendText(boxText, statusPhrase, true);
}
newLine=true;
}
if (box.isImage()) {
if ( assignment!=null ) {
WImg wimage = box.getImage();
if ( wimage!=null ) {
AbstractRichImage richImage = wimage.getContent();
if ( richImage!=null ) {
Phrase statusPhrase = getStatusPhrase(PdfWxmlMessagesConstants.STATUS_IMAGE_MSG, richImage, setbackground, drawHandler);
if ( statusPhrase!=null ) {
if( newLine ) ct.addText(Chunk.NEWLINE);
ct.addText(statusPhrase);
appendText(boxText, statusPhrase, newLine);
}
}
}
wimage.getContent();
newLine = true;
}
}
else if ( box.isText() ) {
WText wtext = box.getText();
if ( drawHandler.getDrawPreferences().includeBoxTags ) {
//String boxTag = box.getTextTag();
String boxTag = box.getContentTag();
if ( boxTag!=null && boxTag.trim().length()>0 ) {
if ( newLine ) ct.addText(Chunk.NEWLINE);
Chunk tagChunk = new Chunk( "["+boxTag+"]" );
if ( setbackground ) {
tagChunk.setBackground(BG_COLOR);
}
ct.addText(tagChunk);
appendText(boxText, tagChunk, newLine);
newLine=true;
}
}
if ( drawHandler.getDrawPreferences().includeBoxStyles ) {
Set<WField> fields = wtext.getFields();
if ( fields!=null ) {
//Set<String> styles = new TreeSet<String>();
Set<String> originalStyles = new TreeSet<String>();
for( WField field: fields ) {
Set<WStyle> wstyles = field.getWStyles(WStyle.WType.paragraph);
if ( wstyles!=null ) {
for( WStyle wstyle : wstyles ) {
// styles.add(wstyle.getName() + "/" + wstyle.getOriginalName());
//styles.add(wstyle.getName());
originalStyles.add(wstyle.getOriginalName());
}
}
}
if ( originalStyles.size()>0 ) {
if ( newLine ) ct.addText(Chunk.NEWLINE);
Chunk stylesChunk = new Chunk( String.valueOf(originalStyles) );
if ( setbackground ) {
stylesChunk.setBackground(BG_COLOR);
}
ct.addText(stylesChunk);
appendText(boxText, stylesChunk, newLine);
newLine=true;
}
}
}
}
if ( drawHandler.getDrawPreferences().displaySizeBox ) {
if ( newLine ) ct.addText(Chunk.NEWLINE);
Unit adaptedPdfUnit = drawHandler.getPdfUnit();
Unit adaptedSizeBoxUnit = drawHandler.getDrawPreferences().sizeBoxUnit;
Chunk chunk = new Chunk("("+getSizeText(boxWidth, boxHeight, adaptedPdfUnit, adaptedSizeBoxUnit)
+ " "
+ PdfWxmlMessages
.getString(PdfWxmlMessagesConstants.UNIT_PREFIX
+ adaptedSizeBoxUnit) + ")");
if ( setbackground ) {
chunk.setBackground(BG_COLOR);
}
ct.addText(chunk);
appendText(boxText, chunk, newLine);
//LOG.info(chunk.getContent());
}
ct.go();
if ( boxText.length()==0 ) return null;
return new AnnotationHandler(boxTitle,boxText.toString());
}
private static void appendText(StringBuilder boxText, String content, boolean newline) {
if ( newline && boxText.length()!=0 ) boxText.append('\n');
boxText.append(content);
}
private static void appendText(StringBuilder boxText, Chunk chunk, boolean newline) {
appendText(boxText, chunk.getContent(), newline);
}
private static void appendText(StringBuilder boxText, Phrase phrase, boolean newline) {
appendText(boxText, phrase.getContent(), newline);
}
private static Phrase getStatusPhrase(String statusMsgKey, Instance instance, boolean background, DrawPdfHandler drawHandler) throws BadElementException, IOException {
Instance status = instance.getCurrentStatus();
Instance nextStatus = instance.getNextStatus();
boolean hasStatus=false;
Phrase phrase = null;
if ( status!=null ) {
phrase = new Phrase();
Instance color = null;
if ( !drawHandler.getDrawPreferences().paintStatusBackground || drawHandler.getDrawPreferences().statusBackgroundType!=StatusBGType.ASSIGNMENT) {
color = status.getProperty("color", ChildProperty.class).getChild();
if(color!= null){
String colorName = color.getName();
java.awt.Image img = ImageFactory.createColorImage( colorName, 12, 12 );
Image image = Image.getInstance(img, null);
Chunk imageChunk = new Chunk(image,0,0,true);
if (background ) {
imageChunk.setBackground(BG_COLOR);
}
phrase.add(imageChunk);
}
}
String statusName = status.getName();
//Chunk chunk = new Chunk("\u00A0"+statusName);
Chunk chunk = new Chunk((color!=null?"\u2002":"")+statusName);
if (background ) {
chunk.setBackground(BG_COLOR);
}
phrase.add(chunk);
hasStatus=true;
}
if ( nextStatus!=null ) {
if ( hasStatus ) {
Chunk chunk = new Chunk(", ");
if (background ) {
chunk.setBackground(BG_COLOR);
}
phrase.add(chunk);
}
else {
phrase=new Phrase();
}
String statusName = instance.getNextStatusAction();
if ( statusName==null ) {
statusName = StringTools.getStringCap(instance.getStatusProperty().getName());
}
else if ( instance instanceof IAffectable ) {
IAffectable affectable = (IAffectable)instance;
Instance userinst = affectable.getAffectationUser();
String user = userinst==null?null:affectable.getAffectationUser().getName();
Date date = affectable.getDueDate();
String dateString = DateFormatFactory.getInstance(DateFormatter.getDateFormatPattern(Format.LONG)).format(date);
if ( user==null ) {
statusName = PdfWxmlMessages.getFormattedString(statusMsgKey+ ".nouser",
statusName.toLowerCase(),
dateString);
}
else {
statusName = PdfWxmlMessages.getFormattedString(statusMsgKey,
statusName.toLowerCase(),
user,
dateString);
}
}
Chunk chunkStatus = new Chunk(statusName);
if (background ) {
chunkStatus.setBackground(BG_COLOR);
}
phrase.add(chunkStatus);
}
return phrase;
} |