Inserts for Custom Synth Appearance

I implement a custom Look and Feel using Synth for my application - mainly providing custom versions of SynthStyle, SynthPainter and SynthStyleFactory.

I do not use any XML, i.e. everything is done through the Java API. All in all, this works great.

The best way to set appropriate inserts, however, is a bit more complicated. I see various options:

  • Override getInsets for SynthStyle to return specific attachments for each region.
  • Apply border to components using SynthStyle.installDefaults
  • Set all the inserts to (0,0,0,0) and compensate in the drawing methods.
  • Creating New ComponentUI Delegates

What will be the best approach and why?

+4
source share
1 answer

Have you come to this decision? Here is my opinion on things ...

Overriding getInsets() looks like a nice solution if you have a simple style with few contexts. This should help maintain the integrity of the attachments in your GUI with only one point of change.

Applying an empty border to components for this purpose seems a bit hacky. If you need to apply a custom border to a component, you can accidentally delete an empty border if you do not override the setBorder() methods to use a composite border.

Setting all inputs to 0 is not necessary, since they start from 0 already ... I would be very scared by the thought of rewriting drawing methods! This is usually done to add finishing touches to the components, and not to redefine all their boundaries.

I am not quite sure how the creation of the new ComponentUI will help, since it mainly concerns calibration and drawing (for example, above).

First I will try option 1, as it will have a global impact on your application, and then it will begin to develop those exceptions and contexts that you want to insert into it.

+1
source

Source: https://habr.com/ru/post/1314964/


All Articles