You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Eliot Kimber <ek...@contrext.com> on 2018/08/01 21:26:19 UTC

How to Set Underline Color?

I'm implementing additional set and get methods for Run properties that I need (or might likely need) [it's not complete over the set of all run properties but it adds a lot more.]

The only one that has stymied me is underline color.

The underline color value is an RGB color string but the OOXML API doesn't seem to provide for it--I suspect it's a limitation in the class generation from the schema.

The CTUnderline API is:

        CTUnderline underline = (pr.getU() == null) ? pr.addNewU() : pr.getU();
        Object color = underline.getColor();

That is, underline.getColor() returns Object, not something more specialized.

In my tests, color is null (not a surprise).

So my question is: how do I set the color? Should I simply be constructing the XML or is there a better way?

Thanks,

Eliot
--
Eliot Kimber
http://contrext.com
 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: How to Set Underline Color?

Posted by Eliot Kimber <ek...@contrext.com>.
I have submitted a pull request with the name changes.

Cheers,

E.

--
Eliot Kimber
http://contrext.com
 

On 8/1/18, 9:35 PM, "Mark Murphy" <jm...@gmail.com> wrote:

    One more thing, I want to keep naming consistent. For Abstract classes it
    should be XWPFAbstract vs. AbstractXWPF. If you could rename your footnote
    and endnote classes that would be great. And any other place that XWPF
    exists, it goes first. This will keep things consistent with the rest of
    POI.
    
    On Wed, Aug 1, 2018 at 5:26 PM Eliot Kimber <ek...@contrext.com> wrote:
    
    > I'm implementing additional set and get methods for Run properties that I
    > need (or might likely need) [it's not complete over the set of all run
    > properties but it adds a lot more.]
    >
    > The only one that has stymied me is underline color.
    >
    > The underline color value is an RGB color string but the OOXML API doesn't
    > seem to provide for it--I suspect it's a limitation in the class generation
    > from the schema.
    >
    > The CTUnderline API is:
    >
    >         CTUnderline underline = (pr.getU() == null) ? pr.addNewU() :
    > pr.getU();
    >         Object color = underline.getColor();
    >
    > That is, underline.getColor() returns Object, not something more
    > specialized.
    >
    > In my tests, color is null (not a surprise).
    >
    > So my question is: how do I set the color? Should I simply be constructing
    > the XML or is there a better way?
    >
    > Thanks,
    >
    > Eliot
    > --
    > Eliot Kimber
    > http://contrext.com
    >
    >
    >
    >
    > ---------------------------------------------------------------------
    > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
    > For additional commands, e-mail: user-help@poi.apache.org
    >
    >
    



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: How to Set Underline Color?

Posted by Mark Murphy <jm...@gmail.com>.
One more thing, I want to keep naming consistent. For Abstract classes it
should be XWPFAbstract vs. AbstractXWPF. If you could rename your footnote
and endnote classes that would be great. And any other place that XWPF
exists, it goes first. This will keep things consistent with the rest of
POI.

On Wed, Aug 1, 2018 at 5:26 PM Eliot Kimber <ek...@contrext.com> wrote:

> I'm implementing additional set and get methods for Run properties that I
> need (or might likely need) [it's not complete over the set of all run
> properties but it adds a lot more.]
>
> The only one that has stymied me is underline color.
>
> The underline color value is an RGB color string but the OOXML API doesn't
> seem to provide for it--I suspect it's a limitation in the class generation
> from the schema.
>
> The CTUnderline API is:
>
>         CTUnderline underline = (pr.getU() == null) ? pr.addNewU() :
> pr.getU();
>         Object color = underline.getColor();
>
> That is, underline.getColor() returns Object, not something more
> specialized.
>
> In my tests, color is null (not a surprise).
>
> So my question is: how do I set the color? Should I simply be constructing
> the XML or is there a better way?
>
> Thanks,
>
> Eliot
> --
> Eliot Kimber
> http://contrext.com
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: How to Set Underline Color?

Posted by Mark Murphy <jm...@gmail.com>.
Crap, not "string" but "auto".

On Wed, Aug 1, 2018 at 10:30 PM Mark Murphy <jm...@gmail.com> wrote:

> Here's how I would do it:
>
>     public void setUnderlineColor(String color) {
>         CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
>         CTUnderline underline = (pr.getU() == null) ? pr.addNewU() :
> pr.getU();
>         SimpleValue svColor = null;
>         if (color.equals("string")) {
>             STHexColorAuto hexColor = STHexColorAuto.Factory.newInstance();
>             hexColor.set(STHexColorAuto.Enum.forString(color));
>             svColor = (SimpleValue) hexColor;
>         } else {
>             STHexColorRGB rgbColor = STHexColorRGB.Factory.newInstance();
>             rgbColor.setStringValue(color);
>             svColor = (SimpleValue) rgbColor;
>         }
>         underline.setColor(svColor);
>     }
>
> But see that code to get run properties? That is duplicated everywhere, I
> would incorporate it into a new private method named
> getRunProperties(boolean create) {} which would encapsulate that code and
> create a new CTRPr object if necessary when create is true. So I can then
> use it with getters by passing false, or setters by passing true. That can
> then be refactored into the other run property methods. Similarly I would
> have a private getUnderline(boolean create) {} so that I could use it in
> setUnderlineColor(), or setUnderlineThemeColor(), ...
>
> On Wed, Aug 1, 2018 at 5:26 PM Eliot Kimber <ek...@contrext.com> wrote:
>
>> I'm implementing additional set and get methods for Run properties that I
>> need (or might likely need) [it's not complete over the set of all run
>> properties but it adds a lot more.]
>>
>> The only one that has stymied me is underline color.
>>
>> The underline color value is an RGB color string but the OOXML API
>> doesn't seem to provide for it--I suspect it's a limitation in the class
>> generation from the schema.
>>
>> The CTUnderline API is:
>>
>>         CTUnderline underline = (pr.getU() == null) ? pr.addNewU() :
>> pr.getU();
>>         Object color = underline.getColor();
>>
>> That is, underline.getColor() returns Object, not something more
>> specialized.
>>
>> In my tests, color is null (not a surprise).
>>
>> So my question is: how do I set the color? Should I simply be
>> constructing the XML or is there a better way?
>>
>> Thanks,
>>
>> Eliot
>> --
>> Eliot Kimber
>> http://contrext.com
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>

Re: How to Set Underline Color?

Posted by Eliot Kimber <ek...@contrext.com>.
I have implemented Mark's requests as well as set/get for underline theme color and added to the pull request.

Cheers,

E.

--
Eliot Kimber
http://contrext.com
 

On 8/1/18, 9:30 PM, "Mark Murphy" <jm...@gmail.com> wrote:

    Here's how I would do it:
    
        public void setUnderlineColor(String color) {
            CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
            CTUnderline underline = (pr.getU() == null) ? pr.addNewU() :
    pr.getU();
            SimpleValue svColor = null;
            if (color.equals("string")) {
                STHexColorAuto hexColor = STHexColorAuto.Factory.newInstance();
                hexColor.set(STHexColorAuto.Enum.forString(color));
                svColor = (SimpleValue) hexColor;
            } else {
                STHexColorRGB rgbColor = STHexColorRGB.Factory.newInstance();
                rgbColor.setStringValue(color);
                svColor = (SimpleValue) rgbColor;
            }
            underline.setColor(svColor);
        }
    
    But see that code to get run properties? That is duplicated everywhere, I
    would incorporate it into a new private method named
    getRunProperties(boolean create) {} which would encapsulate that code and
    create a new CTRPr object if necessary when create is true. So I can then
    use it with getters by passing false, or setters by passing true. That can
    then be refactored into the other run property methods. Similarly I would
    have a private getUnderline(boolean create) {} so that I could use it in
    setUnderlineColor(), or setUnderlineThemeColor(), ...
    
    On Wed, Aug 1, 2018 at 5:26 PM Eliot Kimber <ek...@contrext.com> wrote:
    
    > I'm implementing additional set and get methods for Run properties that I
    > need (or might likely need) [it's not complete over the set of all run
    > properties but it adds a lot more.]
    >
    > The only one that has stymied me is underline color.
    >
    > The underline color value is an RGB color string but the OOXML API doesn't
    > seem to provide for it--I suspect it's a limitation in the class generation
    > from the schema.
    >
    > The CTUnderline API is:
    >
    >         CTUnderline underline = (pr.getU() == null) ? pr.addNewU() :
    > pr.getU();
    >         Object color = underline.getColor();
    >
    > That is, underline.getColor() returns Object, not something more
    > specialized.
    >
    > In my tests, color is null (not a surprise).
    >
    > So my question is: how do I set the color? Should I simply be constructing
    > the XML or is there a better way?
    >
    > Thanks,
    >
    > Eliot
    > --
    > Eliot Kimber
    > http://contrext.com
    >
    >
    >
    >
    > ---------------------------------------------------------------------
    > To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
    > For additional commands, e-mail: user-help@poi.apache.org
    >
    >
    



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: How to Set Underline Color?

Posted by Mark Murphy <jm...@gmail.com>.
Here's how I would do it:

    public void setUnderlineColor(String color) {
        CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
        CTUnderline underline = (pr.getU() == null) ? pr.addNewU() :
pr.getU();
        SimpleValue svColor = null;
        if (color.equals("string")) {
            STHexColorAuto hexColor = STHexColorAuto.Factory.newInstance();
            hexColor.set(STHexColorAuto.Enum.forString(color));
            svColor = (SimpleValue) hexColor;
        } else {
            STHexColorRGB rgbColor = STHexColorRGB.Factory.newInstance();
            rgbColor.setStringValue(color);
            svColor = (SimpleValue) rgbColor;
        }
        underline.setColor(svColor);
    }

But see that code to get run properties? That is duplicated everywhere, I
would incorporate it into a new private method named
getRunProperties(boolean create) {} which would encapsulate that code and
create a new CTRPr object if necessary when create is true. So I can then
use it with getters by passing false, or setters by passing true. That can
then be refactored into the other run property methods. Similarly I would
have a private getUnderline(boolean create) {} so that I could use it in
setUnderlineColor(), or setUnderlineThemeColor(), ...

On Wed, Aug 1, 2018 at 5:26 PM Eliot Kimber <ek...@contrext.com> wrote:

> I'm implementing additional set and get methods for Run properties that I
> need (or might likely need) [it's not complete over the set of all run
> properties but it adds a lot more.]
>
> The only one that has stymied me is underline color.
>
> The underline color value is an RGB color string but the OOXML API doesn't
> seem to provide for it--I suspect it's a limitation in the class generation
> from the schema.
>
> The CTUnderline API is:
>
>         CTUnderline underline = (pr.getU() == null) ? pr.addNewU() :
> pr.getU();
>         Object color = underline.getColor();
>
> That is, underline.getColor() returns Object, not something more
> specialized.
>
> In my tests, color is null (not a surprise).
>
> So my question is: how do I set the color? Should I simply be constructing
> the XML or is there a better way?
>
> Thanks,
>
> Eliot
> --
> Eliot Kimber
> http://contrext.com
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>