简体   繁体   English

自定义Synth外观和感觉的插图

[英]Insets for custom Synth look and feel

I'm implementing a custom Look & Feel using Synth for my application - basically providing custom versions of SynthStyle, SynthPainter and SynthStyleFactory. 我正在为我的应用程序使用Synth实现自定义外观 - 基本上提供SynthStyle,SynthPainter和SynthStyleFactory的自定义版本。

I am not using any XML, ie everything is done through the Java API. 没有使用任何XML,即一切都是通过Java API完成的。 In general this is working just fine. 总的来说,这工作正常。

The best way to set appropriate insets is however proving a little tricky. 然而,设置适当插图的最佳方法有点棘手。 I can see various options: 我可以看到各种选择:

  • Override getInsets for SynthStyle to return specific insets for each Region 覆盖SynthStyle的getInsets以返回每个Region的特定insets
  • Apply a border to components using SynthStyle.installDefaults 使用SynthStyle.installDefaults为组件应用边框
  • Set all insets to (0,0,0,0) and compensate in the painting methods 将所有插入设置为(0,0,0,0)并在绘制方法中进行补偿
  • Create new ComponentUI delegates 创建新的ComponentUI委托

What would be the best approach and why? 什么是最好的方法,为什么?

Did you come to a decision on this yet? 你有没有做出决定呢? Here's my opinion on things... 这是我对事物的看法......

Overriding getInsets() looks like a nice solution if you have a simple style with a small number of contexts. 如果你有一个带有少量上下文的简单样式,则覆盖getInsets()看起来是一个很好的解决方案。 It should help keep insets consistent throughout your GUI with only one point of change needed. 它应该有助于在整个GUI中保持一致,只需要一个更改点。

Applying an empty border to components seems a little hackish for this purpose. 对组件应用空边框似乎有点hackish为此目的。 If you need to apply a custom border to a component then you might inadvertently remove the empty border unless you override the setBorder() methods to use a compound border. 如果需要将自定义边框应用于组件,则可能会无意中删除空边框,除非您覆盖setBorder()方法以使用复合边框。

Setting all insets to 0 is unnecessary since they start at 0 already... I would be very scared at the thought of rewriting paint methods! 将所有插入设置为0是不必要的,因为它们已经从0开始...我会非常害怕重写绘制方法的想法! That's generally done for adding finishing touches to components, not re-defining their entire boundaries. 这通常用于为组件添加最后润色,而不是重新定义它们的整个边界。

I'm not entirely sure how creating a new ComponentUI would help, since that's mainly to do with sizing and painting (like the above). 我不完全确定如何创建新的ComponentUI会有所帮助,因为这主要与尺寸和绘画有关(如上所述)。

I would try out option 1 first since it will have a global effect on your application, and then start working out what exceptions and contexts you want to put into it. 我会首先尝试选项1,因为它会对您的应用程序产生全局影响,然后开始计算您想要添加的异常和上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM