[ 
https://issues.apache.org/jira/browse/ODFTOOLKIT-394?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14185085#comment-14185085
 ] 

Ian Cunningham commented on ODFTOOLKIT-394:
-------------------------------------------

I spent some time tracing what is going on here.
Does anyone understand how the StyleHandler under the Simple Paragraph class 
was supposed to work?

When a the Paragraph.setStyleName function is called the default automatic 
style that was assigned to the new paragraph just created has its name changed 
to the value supplied to setStyleName. The style class in the handler is not 
replaced.

So when the document is saved the text paragraph does have the name desired but 
it refers to the automatic style and so is rendered with its properties.

I hacked the setStyleName function as below
        public void setStyleName(String styleName) {
//              mStyleHandler.getStyleElementForWrite()
//                              .setStyleNameAttribute(styleName);
                if (isHeading()) {
                        mHeadingElement.setStyleName(styleName);
                } else {
                        mParagraphElement.setStyleName(styleName);
                }       
        }

This makes the function work but completely overrides the StyleHandler.
How do we progress?

> Paragraph styles cannot be set
> ------------------------------
>
>                 Key: ODFTOOLKIT-394
>                 URL: https://issues.apache.org/jira/browse/ODFTOOLKIT-394
>             Project: ODF Toolkit
>          Issue Type: Bug
>          Components: simple api
>    Affects Versions: 0.6.1-incubating
>            Reporter: StanB123
>            Priority: Minor
>
> The setStyleName method on the Paragraph class in the SimpleAPI doesn't 
> appear to do anything. In my case I have been trying to set a style that was 
> preconfigured in a template. I have just checked, and a style that was set in 
> code appears to do the same.
> Here's a short snippet.
> {code}
> public static void main(String[] args) throws Exception {
>     TextDocument odt = TextDocument.newTextDocument();
>     OdfOfficeStyles s = odt.getOrCreateDocumentStyles();
>     OdfStyle veryRed = s.newStyle("Very_red", OdfStyleFamily.Paragraph);
>     veryRed.setProperty(OdfParagraphProperties.BackgroundColor, "#ff0000");
>     
>     // Create a paragraph
>     Paragraph p1 = odt.addParagraph("Blah.");
>     
>     // I think these two lines are supposed to be equivalent, however,
>     // when you comment out the first one, the style is lost.
>     p1.getOdfElement().setStyleName("Very_red");
>     p1.setStyleName("Very_red");
>     
>     // Save the file
>     odt.save("result.odt");
> }
> {code}
> I looked into how to fix this, and I think it might be as simple as changing 
> a few lines in Paragraph's constructor. But I don't really feel comfortable 
> doing it seeing as I have only been using this library for a few days.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to