The idea is that each graphic object should be in its own layer.
So we used a JLayeredPane but ended up using only the index of the component in the container instead of the proper layering mechanism.
Calling add(component) is equivalent to add(component, -1) and should add the component at the end of the list, but it throws an exception instead.
Calling add(component, getComponentCount() - 1) adds the component at the end, but that means behind the other component.
Instead, we want a newly created component to appear in front of the others.
Calling add(component, 0) should be avoided because 0 is the position of the glass pane used to redispatch mouse events (the event coordinates are altered according to the zoom).
Thus, TOP_LAYER_POSITION is defined as 1, meaning each new component will be drawn before the others (hence appearing to be on top) but after the glass pane so that mouse events are handled properly when the zoom changes.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Constructor of GraphicObject calls function init() which contains following line:
this.getSlide().add(this, Slide.TOP_LAYER_POSITION);
Do we really need this line here ?
I prefer to add graphic object to slide separately, after creating the graphic object (and it seems me we really do each time after creating graphic object). I am going to implement clone() function for text graphic object and I don't need adding the new copy to slide in my case.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I see you are always adding new graphic object with index Slide.TOP_LAYER_POSITION, for example: Slide.this.add(graphicObject, TOP_LAYER_POSITION);
Is there a reason not to add a new graphic object at the end ?
The idea is that each graphic object should be in its own layer.
So we used a JLayeredPane but ended up using only the index of the component in the container instead of the proper layering mechanism.
Calling add(component) is equivalent to add(component, -1) and should add the component at the end of the list, but it throws an exception instead.
Calling add(component, getComponentCount() - 1) adds the component at the end, but that means behind the other component.
Instead, we want a newly created component to appear in front of the others.
Calling add(component, 0) should be avoided because 0 is the position of the glass pane used to redispatch mouse events (the event coordinates are altered according to the zoom).
Thus, TOP_LAYER_POSITION is defined as 1, meaning each new component will be drawn before the others (hence appearing to be on top) but after the glass pane so that mouse events are handled properly when the zoom changes.
Oops, that doesn't make sense.
It seems JLayeredPane uses another kind of ordering.
Constructor of GraphicObject calls function init() which contains following line:
this.getSlide().add(this, Slide.TOP_LAYER_POSITION);
Do we really need this line here ?
I prefer to add graphic object to slide separately, after creating the graphic object (and it seems me we really do each time after creating graphic object). I am going to implement clone() function for text graphic object and I don't need adding the new copy to slide in my case.
No, you can change it.