You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by jarnis <ja...@exedio.com> on 2012/03/08 16:06:59 UTC

Dynamically sized image

Hey Guys

I'm using an Image rendered with a DynamicImageResource (in this case a
JFreeChart chart, but it could have been anything). I would like the image
to fill the panel it is placed in which is sized relatively to the web page
it is on. For the rendering to work I have to know the width and height when
Image.getImageResource() is called, or at least inside my
DynamicImageResource.getImageData(Attributes atrbts) method. I have searched
for a while now, but I can't find a good way to get the image's dimensions
at runtime.

Am I using the classes wrong, or should I use a different kind of component?
I am open to alternative suggestions, as long as it produces a clean
solution (preferably, but not necessarily, without depending on
AJAX/js/jQuery directly).

Thanks in advance.

Jarnis Bertelsen
Developer
Exedio




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dynamically-sized-image-tp4456657p4456657.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Dynamically sized image

Posted by Dan Retzlaff <dr...@gmail.com>.
Nice, I share the vision. There's definitely room for something reusable
there. Keep us posted. :)

On Wed, Mar 21, 2012 at 9:03 AM, jarnis <ja...@exedio.com> wrote:

> Hey Dan, sorry for the late reply and thanks for your suggestion.
>
> If it is necessary with ajax for a good solution, I'm not fanatic in
> resisting it. I would prefer to wrap it in a reusable wicket component,
> thou, and I have not yet figured out to do this.
>
> It seems that depending on
> http://benalman.com/projects/jquery-resize-plugin/ Ben Alman's jQuery
> resize
> event  might save a bit of coding and avoid minding custom js code to the
> window's resize event.
>
> I have tried to use various WiQuery classes to implement it with no
> success.
> Just recently I became aware of the  AjaxLazyLoadPanel class, and my
> current
> idea is to override the protected void handleCallbackScript(final
> IHeaderResponse response, final String callbackScript) method to make a
> script that also provides the size for the first rendering cycle. I'm a bit
> stuck on how to construct the js callbackScript, thou.
>
> If someone has a pointer on how to get started on this I would appreciate
> it. Otherwise I will post the solution when I finally work one out. It may
> take a while as this is a "nice-to-have" feature in the current project I'm
> working on and I rarely have time to throw after it,
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Dynamically-sized-image-tp4456657p4492790.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Dynamically sized image

Posted by jarnis <ja...@exedio.com>.
Hey Dan, sorry for the late reply and thanks for your suggestion.

If it is necessary with ajax for a good solution, I'm not fanatic in
resisting it. I would prefer to wrap it in a reusable wicket component,
thou, and I have not yet figured out to do this.

It seems that depending on 
http://benalman.com/projects/jquery-resize-plugin/ Ben Alman's jQuery resize
event  might save a bit of coding and avoid minding custom js code to the
window's resize event. 

I have tried to use various WiQuery classes to implement it with no success.
Just recently I became aware of the  AjaxLazyLoadPanel class, and my current
idea is to override the protected void handleCallbackScript(final
IHeaderResponse response, final String callbackScript) method to make a
script that also provides the size for the first rendering cycle. I'm a bit
stuck on how to construct the js callbackScript, thou.

If someone has a pointer on how to get started on this I would appreciate
it. Otherwise I will post the solution when I finally work one out. It may
take a while as this is a "nice-to-have" feature in the current project I'm
working on and I rarely have time to throw after it,

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dynamically-sized-image-tp4456657p4492790.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Dynamically sized image

Posted by Dan Retzlaff <dr...@gmail.com>.
Hi Jarnis,

We have a similar challenge: we determine pageable views' itemsPerPage
based on available screen height. Since many of our pages have such views,
we include JavaScript in each page that stores the current known height,
and reports back any changes with jQuery (after a slight delay).

window.trackerHeight = <current known size>;
window.trackerTimeout = null;
var updateSize = function() {
$.ajax({url:'/XXX/height?h=' + $(window).height()});
};
$(window).resize(function() {
if(window.trackerHeight != $(window).height()) {
window.trackerHeight = $(window).height();
clearTimeout(window.trackerTimeout);
window.trackerTimeout = setTimeout(updateSize, 3000);
}
});
updateSize();

The "height" Wicket resource puts the value in the Session. The dynamically
sized component then just needs to know the number of height pixels to
reserve for other content, and uses up the remainder. And yes, this
reserved height, and the height-per-row are static finals in Java. :)

This works well for us, but may be overkill for you. It also violates your
no-AJAX and no-jQuery goals.

HTH,
Dan

On Thu, Mar 8, 2012 at 8:57 AM, jarnis <ja...@exedio.com> wrote:

>
> Martin Grigorov-4 wrote
> >
> > Maybe you do this with the WebClientInfo.
> >
> Using WebClientInfo does seem to offer a possible workaround. However, as I
> see it, there are a few drawbacks:
>
> It requires the Java code to know the percentage of the page that the
> panel's div is taking. Hard-coding this would be a bit against the purpose
> of wicket (as I understand it) as it would depend on the html/css not
> changing and thereby limit the freedom of the designers. It might be
> possible to get this info programatically however, I have not yet
> investigated this. In this case where I am both programmer and designer,
> the
> actual problem would not be that great.
>
> It seems the WebClientInfo is not updated when the browser window is
> resized. There may be a way to force this, I have not yet checked this
> throughly.
>
> If no better solution is possible, this can definitely be used. I would
> still like a solution that fit a little better with Wicket's spirit.
>
> In any case, thanks a lot for your suggestion, Martin
>
> Jarnis
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Dynamically-sized-image-tp4456657p4456981.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Dynamically sized image

Posted by jarnis <ja...@exedio.com>.
Martin Grigorov-4 wrote
> 
> Maybe you do this with the WebClientInfo.
> 
Using WebClientInfo does seem to offer a possible workaround. However, as I
see it, there are a few drawbacks:

It requires the Java code to know the percentage of the page that the
panel's div is taking. Hard-coding this would be a bit against the purpose
of wicket (as I understand it) as it would depend on the html/css not
changing and thereby limit the freedom of the designers. It might be
possible to get this info programatically however, I have not yet
investigated this. In this case where I am both programmer and designer, the
actual problem would not be that great.

It seems the WebClientInfo is not updated when the browser window is
resized. There may be a way to force this, I have not yet checked this
throughly.

If no better solution is possible, this can definitely be used. I would
still like a solution that fit a little better with Wicket's spirit.

In any case, thanks a lot for your suggestion, Martin

Jarnis 



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dynamically-sized-image-tp4456657p4456981.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Dynamically sized image

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Maybe you do this with the WebClientInfo.
See how http://www.wicket-library.com/wicket-examples/hellobrowser
extracts client info like browser dimensions.
You can use this information to calculate the size of the div and
respetivelly the image that you have to generate.

HTH

On Thu, Mar 8, 2012 at 5:06 PM, jarnis <ja...@exedio.com> wrote:
> Hey Guys
>
> I'm using an Image rendered with a DynamicImageResource (in this case a
> JFreeChart chart, but it could have been anything). I would like the image
> to fill the panel it is placed in which is sized relatively to the web page
> it is on. For the rendering to work I have to know the width and height when
> Image.getImageResource() is called, or at least inside my
> DynamicImageResource.getImageData(Attributes atrbts) method. I have searched
> for a while now, but I can't find a good way to get the image's dimensions
> at runtime.
>
> Am I using the classes wrong, or should I use a different kind of component?
> I am open to alternative suggestions, as long as it produces a clean
> solution (preferably, but not necessarily, without depending on
> AJAX/js/jQuery directly).
>
> Thanks in advance.
>
> Jarnis Bertelsen
> Developer
> Exedio
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dynamically-sized-image-tp4456657p4456657.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org