FileDocCategorySizeDatePackage
CommentShape.javaAPI DocApache Poi 3.0.15132Mon Jan 01 18:59:10 GMT 2007org.apache.poi.hssf.model

CommentShape

public class CommentShape extends TextboxShape
Represents a cell comment. This class converts highlevel model data from HSSFComment to low-level records.
author
Yegor Kozlov

Fields Summary
private NoteRecord
note
Constructors Summary
public CommentShape(HSSFComment hssfShape, int shapeId)
Creates the low-level records for a comment.

param
hssfShape The highlevel shape.
param
shapeId The shape id to use for this shape.

        super(hssfShape, shapeId);

        note = createNoteRecord(hssfShape, shapeId);

        ObjRecord obj = getObjRecord();
        List records = obj.getSubRecords();
        int cmoIdx = 0;
        for (int i = 0; i < records.size(); i++) {
            Object r = records.get(i);

            if (r instanceof CommonObjectDataSubRecord){
                //modify autofill attribute inherited from <code>TextObjectRecord</code>
                CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord)r;
                cmo.setAutofill(false);
                cmoIdx = i;
            }
        }
        //add NoteStructure sub record
        //we don't know it's format, for now the record data is empty
        NoteStructureSubRecord u = new NoteStructureSubRecord();
        obj.addSubRecord(cmoIdx+1, u);
    
Methods Summary
protected intaddStandardOptions(org.apache.poi.hssf.usermodel.HSSFShape shape, org.apache.poi.ddf.EscherOptRecord opt)
Sets standard escher options for a comment. This method is responsible for setting default background, shading and other comment properties.

param
shape The highlevel shape.
param
opt The escher records holding the proerties
return
number of escher options added

        super.addStandardOptions(shape, opt);

        //remove unnecessary properties inherited from TextboxShape
        java.util.List props = opt.getEscherProperties();
        for ( Iterator iterator = props.iterator(); iterator.hasNext(); ) {
            EscherProperty prop = (EscherProperty) iterator.next();
            switch (prop.getId()){
                case EscherProperties.TEXT__TEXTLEFT:
                case EscherProperties.TEXT__TEXTRIGHT:
                case EscherProperties.TEXT__TEXTTOP:
                case EscherProperties.TEXT__TEXTBOTTOM:
                case EscherProperties.GROUPSHAPE__PRINT:
                case EscherProperties.FILL__FILLBACKCOLOR:
                case EscherProperties.LINESTYLE__COLOR:
                    iterator.remove();
                    break;
            }
        }

        HSSFComment comment = (HSSFComment)shape;
        opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.GROUPSHAPE__PRINT, comment.isVisible() ? 0x000A0000 : 0x000A0002) );
        opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x00030003 ) );
        opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.SHADOWSTYLE__COLOR, 0x00000000 ) );
        opt.sortProperties();
        return opt.getEscherProperties().size();   // # options added
    
private org.apache.poi.hssf.record.NoteRecordcreateNoteRecord(org.apache.poi.hssf.usermodel.HSSFComment shape, int shapeId)
Creates the low level NoteRecord which holds the comment attributes.

        NoteRecord note = new NoteRecord();
        note.setColumn(shape.getColumn());
        note.setRow((short)shape.getRow());
        note.setFlags(shape.isVisible() ? NoteRecord.NOTE_VISIBLE : NoteRecord.NOTE_HIDDEN);
        note.setShapeId((short)shapeId);
        note.setAuthor(shape.getAuthor() == null ? "" : shape.getAuthor());
        return note;
    
public org.apache.poi.hssf.record.NoteRecordgetNoteRecord()
Return the NoteRecord holding the comment attributes

return
NoteRecord holding the comment attributes

        return note;