mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.15k stars 235 forks source link

Section painter improvements #593

Open mgarin opened 4 years ago

mgarin commented 4 years ago

I plan to improve SectionPainters API in next update. These painters are used in some complex components like JTree to paint some specific areas. For instance JTree has whole 5 section painters - rowPainter, nodePainter, selectionPainter, dropLocationPainter and selectorPainter.

They're used if specified in the style, here is the default tree style:

    <!-- Tree -->
    <style type="tree">
        <component>
            <opaque>true</opaque>
            <background>white</background>
            <foreground>black</foreground>
        </component>
        <ui>
            <selectionStyle>line</selectionStyle>
        </ui>
        <painter>
            <paintLines>true</paintLines>
            <dashedLines>true</dashedLines>
            <linesColor>gray</linesColor>
            <decorations>
                <decoration>
                    <BoundsShape />
                    <ColorBackground color="white" />
                </decoration>
            </decorations>

            <!-- Node background painter -->
            <nodePainter>
                <decorations>
                    <decoration states="enabled,unselected,hover" opacity="0.4">
                        <WebShape round="0" />
                        <GradientBackground>
                            <color>218,218,208</color>
                            <color>206,206,196</color>
                        </GradientBackground>
                    </decoration>
                </decorations>
            </nodePainter>

            <!-- Selection background painter -->
            <selectionPainter>
                <decorations>
                    <decoration opacity="0.75">
                        <WebShape round="0" />
                        <GradientBackground>
                            <color>218,218,208</color>
                            <color>206,206,196</color>
                        </GradientBackground>
                    </decoration>
                    <decoration states="focused" opacity="1" />
                    <decoration states="disabled" opacity="0.5" />
                </decorations>
            </selectionPainter>

            <!-- Tree drop location painter -->
            <dropLocationPainter>
                <decorations>
                    <decoration states="drop-on">
                        <WebShape round="0" />
                        <WebShadow type="inner" width="5" />
                        <LineBorder color="85,130,190" stroke="basic;1;round;round;0;4,5" />
                    </decoration>
                    <decoration states="drop-between" size="80,2">
                        <WebShape round="0" />
                        <LineBorder color="85,130,190" stroke="basic;1;round;round;0;4,5" />
                    </decoration>
                </decorations>
            </dropLocationPainter>

            <!-- Selector painter -->
            <selectorPainter>
                <decorations>
                    <decoration>
                        <WebShape round="0" />
                        <LineBorder color="gray" stroke="basic;1;round;round;0;3,3" />
                        <ColorBackground color="0,0,255,25" />
                    </decoration>
                </decorations>
            </selectorPainter>

        </painter>

        <!-- Label cell renderer -->
        <style type="label" id="renderer" padding="4,4,4,6" />

        <!-- Styled label cell renderer -->
        <style type="styledlabel" id="renderer" padding="4,4,4,6" />

        <!-- Text field cell editor -->
        <style type="textfield" id="editor" padding="0,3,0,2">
            <painter>
                <decorations overwrite="true">
                    <decoration>
                        <WebShape round="2" />
                        <LineBorder color="85,130,190" />
                        <ColorBackground color="white" />
                    </decoration>
                </decorations>
            </painter>

            <!-- Cell editor icon -->
            <style type="image" id="icon" padding="0,0,0,4" />

        </style>

    </style>

It uses 4 out of 5 available SectionPainters by default.

The improvement I'm going to make is basically a streamlined API for these section painters. Right now they are defined directly in parent Painter implementation, for instance in TreePainter for JTree. Each separate SectionPainter has it's own custom API and has to be approached differently because of that. There are also some internal issues with SectionPainter implementations performing a lot of unnecessary actions.

First thing that needs to be introduced is a Section interface that can be implemented for each separate section each component/painter can provide and which can then be used by a new streamlined API of SectionPainter.

Each Section implementation should be able to provide:

Also something like SectionParameters interface might be required to separate Section from actual data used for bounds/states calculation for each particular case.

Next all currently available section painters will be replaced with the new streamlined approach, both in the code and the style, for instance <nodePainter> will be replaced with:

            <!-- Node background painter -->
            <SectionPainter type="node">
                <decorations>
                    <decoration states="enabled,unselected,hover" opacity="0.4">
                        <WebShape round="0" />
                        <GradientBackground>
                            <color>218,218,208</color>
                            <color>206,206,196</color>
                        </GradientBackground>
                    </decoration>
                </decorations>
            </SectionPainter>

Where node type is the identifier of TreePainter section.

This is just an early stage idea, but I will be working on it in v1.2.12 update since it will allow me to improve quite a few things internally and also slightly improve UI performance.

mgarin commented 4 years ago

This will be coming in v1.2.13. Updated v1.2.12 will be focused on skins loading fixes and performance improvements.