Menu

Adding graphic objects

Developers
prince
2010-05-17
2013-04-26
  • prince

    prince - 2010-05-17

    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 ?

     
  • Codist Monk

    Codist Monk - 2010-05-17

    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.

     
  • Codist Monk

    Codist Monk - 2010-05-17

    meaning each new component will be drawn before the others (hence appearing to be on top)

    Oops, that doesn't make sense.

    It seems JLayeredPane uses another kind of ordering.

     
  • prince

    prince - 2010-07-31

    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.

     
  • Codist Monk

    Codist Monk - 2010-08-01

    Do we really need this line here ?

    No, you can change it.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.