[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-2d-dev
Subject:    Question about coalescing COMPONENT_RESIZED events
From:       "Jeremy Wood" <mickleness () gmail ! com>
Date:       2024-04-26 2:52:48
Message-ID: em8e21e86b-ffb5-404c-a8c9-034885e75e26 () 505df37e ! com
[Download RAW message or body]

I'm looking for general feedback/advice.

Is there any reason not to put the following method in a Component?

@Override
protected AWTEvent coalesceEvents(AWTEvent existingEvent, AWTEvent 
newEvent) {
     if (newEvent.getID() == ComponentEvent.COMPONENT_RESIZED)
         return newEvent;
     return super.coalesceEvents(existingEvent, newEvent);
}

(That is: is this unsafe/unwise for some reason I'm not considering?)

As I understand it: when you resize a window every call to 
component#setBounds(..) generates a new ComponentEvent and posts it to 
the event queue. So suppose you resized a window so its height was 10, 
then 11, then 12, then 13, then 14: that would create 5 ComponentEvents 
and post them to the event queue.

So suppose you also have this listener:

myComponent.addComponentListener(new ComponentAdapter() {
     public void componentResized(ComponentEvent e) {
         System.out.println(e.getComponent().getHeight());
     }
});

Your output in this scenario may be 10, 11, 12, 13, 14 if you have a 
very responsive EDT. But it could also be 14, 14, 14, 14, 14. The only 
guarantee is that the last printed height of the 5 ComponentEvents will 
be 14.

So if the ComponentEvents come in all at once: there's no harm in 
coalescing them, right? (So now you may get anywhere from 1 to 5 
ComponentEvents, but each call to e.getComponent().getSize() will 
produce a different result.)

Regards,
  - Jeremy
[Attachment #3 (text/html)]

<html><head>

<style id="css_styles"> 
blockquote.cite { margin-left: 5px; margin-right: 0px; padding-left: 10px; \
padding-right:0px; border-left: 1px solid #cccccc } blockquote.cite2 {margin-left: \
5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid \
#cccccc; margin-top: 3px; padding-top: 0px; } a img { border: 0px; }
table { border-collapse: collapse; }
li[style='text-align: center;'], li[style='text-align: center; '], \
li[style='text-align: right;'], li[style='text-align: right; '] {  \
list-style-position: inside;} body { font-family: Helvetica; font-size: 9pt; }
.quote { margin-left: 1em; margin-right: 1em; border-left: 5px #ebebeb solid; \
padding-left: 0.3em; }

 </style>
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: \
after-white-space;"><div>I'm looking for general feedback/advice.</div><div><br \
/></div>Is there any reason not to put the following method in a Component?<div><br \
/></div><div>@Override</div><div>protected AWTEvent coalesceEvents(AWTEvent \
existingEvent, AWTEvent newEvent) {</div><div>      if (newEvent.getID() == \
ComponentEvent.COMPONENT_RESIZED)</div><div>            return newEvent;</div><div>   \
return super.coalesceEvents(existingEvent, newEvent);</div><div>}</div><div><br \
/></div><div>(That is: is this unsafe/unwise for some reason I'm not \
considering?)</div><div><br /></div><div>As I understand it: when you resize a window \
every call to component#setBounds(..) generates a new ComponentEvent and posts it to \
the event queue. So suppose you resized a window so its height was 10, then 11, then \
12, then 13, then 14: that would create 5 ComponentEvents and post them to the event \
queue.</div><div><br /></div><div>So suppose you also have this \
listener:</div><div><br /></div><div>myComponent.addComponentListener(new \
ComponentAdapter() {</div><div>      public void componentResized(ComponentEvent e) \
{</div><div>            System.out.println(e.getComponent().getHeight());</div><div>  \
}</div><div>});</div><div><br /></div><div>Your output in this scenario may be 10, \
11, 12, 13, 14 if you have a very responsive EDT. But it could also be 14, 14, 14, \
14, 14. The only guarantee is that the last printed height of the 5 ComponentEvents \
will be 14.</div><div><br /></div><div>So if the ComponentEvents come in all at once: \
there's no harm in coalescing them, right? (So now you may get anywhere from 1 to 5 \
ComponentEvents, but each call to e.getComponent().getSize() will produce a different \
result.)</div><div><br /></div><div>Regards,</div><div>  - Jeremy</div></body></html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic