837 | | * Suppose you have several non-ProObject, non-Immutable objects that you need to keep in sync. Imagine you have three |
| 837 | * Suppose you have several non-ProObject, non-Immutable objects that you need to keep in sync. Suppose also that they cannot update their "things" automatically using the pro lib, because they may be part of the JDK. See the following example that is taken directly from the source code along with its javadoc(ignore the logic of the method for the time being): |
| 838 | |
| 839 | {{{ |
| 840 | |
| 841 | /** |
| 842 | * Manages the layout of the contained elements. We can not point the object |
| 843 | * it actually manages, so its value type is {@link Void}. It layouts buttons |
| 844 | * according to the bounds of the menu. Buttons are horizontally |
| 845 | * oriented and are aligned as if they are all at the beginning of the menu. |
| 846 | * |
| 847 | * The setup methods are actually related to the object, but we do not have |
| 848 | * object level setuppers. |
| 849 | * |
| 850 | * @return property. |
| 851 | */ |
| 852 | protected Prop<Void> locationSync() { |
| 853 | class locationSync extends ResourceProperty<Void> { |
| 854 | |
| 855 | @Override |
| 856 | protected Void create() { |
| 857 | return null; |
| 858 | } |
| 859 | |
| 860 | @Override |
| 861 | protected void destroy(Void resource) { |
| 862 | // do nothing? |
| 863 | |
| 864 | } |
| 865 | |
| 866 | @Override |
| 867 | protected void setup(Void resource) { |
| 868 | |
| 869 | ImmPoint lastHud = bounds().get() |
| 870 | .getPoint(Position.BOTTOM_LEFT); |
| 871 | |
| 872 | ImmPoint lastHalo = bounds().get().getPoint( |
| 873 | Position.BOTTOM_LEFT); |
| 874 | |
| 875 | // halo buttons |
| 876 | for (HaloButton b : buttons().get()) { |
| 877 | if (b.visible().get()) { |
| 878 | ImmRect haloBounds = new ImmRect(ImmPoint.ZERO, b |
| 879 | .size().get()).align(Position.BOTTOM_LEFT, |
| 880 | lastHalo); |
| 881 | b.swingComponent().get().setLocation( |
| 882 | haloBounds.getLocation().toPoint()); |
| 883 | lastHalo = haloBounds.getPoint(Position.BOTTOM_RIGHT); |
| 884 | lastHud = syncHud(b, lastHud); |
| 885 | } |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | } |
| 890 | return getBean().makeProp(locationSync.class); |
| 891 | } |
| 892 | |
| 893 | }}} |
| 894 | |
| 895 | * We have several buttons that need to be positioned at specified locations inside a rectangle. In order to do this we should set the location of every button, one by one upon updating the rectangle. The rectangle itself is kept in the bounds() property. The line "b.swingComponent().get().setLocation(haloBounds.getLocation().toPoint());" gets the JButton out of the HaloButton and sets its location. Since the JButton is not a ProObject but is depending on the bounds() property, we should manually set its location. This is just an example of using solely the setUp method of a resource property. Since this method depends on the bounds()'s property everything in it is reinvoked upon changing the bounds. |