Swing Synth 皮肤:你可以覆盖样式吗?

发布于 2024-10-31 13:46:42 字数 1603 浏览 1 评论 0原文

我为 JLabel 定义了样式:

<style id="myLabel">
        <state>
          <opaque value="true"/>
          <color value="blue" type="BACKGROUND"/>
          <color value="red" type="FOREGROUND"/>
        </state>
      </style>
<bind style="myLabel" type="region" key="label"/> 

但是,我希望某些 JLabel(在某些 JPanel 中)的样式完全不同:

<style id="myUnrelatedPanel">
        <state>
          <opaque value="true"/>
          <color value="green" type="BACKGROUND"/>
          <color value="yellow" type="FOREGROUND"/>
        </state>
      </style>
<bind style="myLabel" type="name" key="_valueOfMyPanel.getName()_in_here"/> 

上面的方法不起作用,因为 JLabel 的样式正在强制执行。

嵌套样式似乎不起作用。编译器不会抱怨; Synth 选择锚定到“标签”的样式区域并将其应用于样式表中的所有标签。

以下摘自 Synth 上有限的 Java 文档,表明可以混合应用于区域和名称的样式,并且它们的值将被合并:

您可以绑定到个人,命名为 组件,无论它们是否 也绑定为区域。例如, 假设你想要“OK”并且 GUI 中的“取消”按钮已处理 与其他所有不同 按钮。首先,你会给出“OK” 和取消按钮名称,使用 component.setName() 方法。然后你 将定义三种样式:一种用于 一般按钮(区域 = “按钮”),一个为“确定”按钮(名称 =“确定”),还有一个用于“取消”按钮(名称 =“取消”)。最后,你会 像这样绑定这些样式:

 <bind style="styleButton" type="region" key="Button"> 
 <bind style="styleOK" type="name" key="OK"> 
 <bind style="styleCancel" type="name" key="Cancel">

当组件或区域绑定到 不止一种风格,这些风格是 合并

注意:正如样式可以绑定到 多个地区或名称、多个 样式可以绑定到一个区域或 姓名。这些多种风格被合并 用于区域或名称。优先级是 赋予稍后定义的样式 文件

,第一个样式中的定义似乎不能被第二个样式中的定义覆盖?

I have a style defined for a JLabel:

<style id="myLabel">
        <state>
          <opaque value="true"/>
          <color value="blue" type="BACKGROUND"/>
          <color value="red" type="FOREGROUND"/>
        </state>
      </style>
<bind style="myLabel" type="region" key="label"/> 

However, I want certain JLabels (in certain JPanels) to be styled completely differently:

<style id="myUnrelatedPanel">
        <state>
          <opaque value="true"/>
          <color value="green" type="BACKGROUND"/>
          <color value="yellow" type="FOREGROUND"/>
        </state>
      </style>
<bind style="myLabel" type="name" key="_valueOfMyPanel.getName()_in_here"/> 

The above does not work, because the style for the JLabel is being enforced.

Nesting styles does not appear to work. The compiler does not complain; Synth picks up the style region-anchored to 'label' and applies it to all labels within the stylesheet.

The following extract from the limited Java documentation on Synth suggests that it is possible to mix styles applied to Regions and Names, and that their values will be merged:

You can bind to individual, named
components, whether or not they are
also bound as regions. For example,
suppose you want to have the "OK" and
"Cancel" buttons in your GUI treated
differently than all the other
buttons. First, you would give the OK
and Cancel buttons names, using the
component.setName() method. Then, you
would define three styles: one for
buttons in general (region =
"Button"), one for the OK button (name
= "OK"), and one for the Cancel button (name = "Cancel"). Finally, you would
bind these styles like this:

 <bind style="styleButton" type="region" key="Button"> 
 <bind style="styleOK" type="name" key="OK"> 
 <bind style="styleCancel" type="name" key="Cancel">

When a component or region is bound to
more than one style, the styles are
merged

Note: Just as a style can be bound to
multiple regions or names, multiple
styles can be bound to a region or
name. These multiple styles are merged
for the region or name. Precedence is
given to styles defined later in the
file

However, it does not appear that a defined in the first Style can be overrided by a defined in the second style?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流殇 2024-11-07 13:46:42

我可以确认不可能覆盖以前使用的锚定类型(也就是说,您不能在区域键上设置 type="BACKGROUND" 颜色,然后在区域键上设置不同的 type="BACKGROUND" 颜色设置不同的类型,例如 TEXT_BACKGROUND 可以,因为 Synth 将两种样式合并为一个,但是,您无法在第二种样式中再次设置它

。但是,我们找到了一种解决方法,在 catch-all、key=".*" 样式中设置一组“默认”颜色,并在名称锚定样式中偏离这些颜色:

 <style id="backingStyle">
    <state>
        <opaque value="false"/>
        <font name="Arial" size="12"/>
        <color value="black" type="BACKGROUND"/>
        <color value="white" type="FOREGROUND"/>
    </state>
    </style>
    <bind style="backingStyle" type="region" key=".*"/>

 <style id="backingStyle">
    <state>
        <opaque value="false"/>
        <font name="Verdana" size="12"/>
        <color value="blue" type="BACKGROUND"/>
        <color value="green" type="FOREGROUND"/>
    </state>
    </style>
    <bind style="backingStyle" type="name" key="nameOfMyPanel"/>

I can confirm that it is not possible to override previously used, anchored types (that is to say, you can't set a type="BACKGROUND" colour on a region key, and then set a different type="BACKGROUND" colour on a named key. Setting a different type, such as TEXT_BACKGROUND would work, as Synth merges the two styles into one. Because BACKGROUND was set in the first Style, however, you cannot set it again in the Second style.

Very disappointing. I've found a workaround, however. Set a 'default' set of colours in the catch-all, key=".*" style, and deviate from these colours in name-anchored styles:

 <style id="backingStyle">
    <state>
        <opaque value="false"/>
        <font name="Arial" size="12"/>
        <color value="black" type="BACKGROUND"/>
        <color value="white" type="FOREGROUND"/>
    </state>
    </style>
    <bind style="backingStyle" type="region" key=".*"/>

and

 <style id="backingStyle">
    <state>
        <opaque value="false"/>
        <font name="Verdana" size="12"/>
        <color value="blue" type="BACKGROUND"/>
        <color value="green" type="FOREGROUND"/>
    </state>
    </style>
    <bind style="backingStyle" type="name" key="nameOfMyPanel"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文