tags:

views:

45

answers:

2

Hi all,

I have a large component (say width=4000px, height=200px) and would like to be able to see it entirely even on a small screen. I don't see any easy way to do a wrapping component, my idea is the following : given a factor (for example 4), the component would be of size 1000x800, by wrapping the child to 4 lines. The size requests would be translated in reverse to reshape the child, and so on. On painting, the component would call the paint(Graphics) of the child 4 times with a correct Graphics argument that would map the wrapped space to the child's space.
However, I can't see how to handle all the events : should I set eventlisteners for every children-generated event (PropertyChange) and for every parent-generated event (Mouse, Key, Resize, ....) ? This seems quite a lot of mapping, and I'd be happy to ear of an easier way of doing that...
I haven't looked too much at the JViewport implementation, but maybe this could help me don't you think?

thanks for your suggestions!

Frederic.

+1  A: 

You're approaching this the wrong way. It's the contents of the component, not the component itself you should be thinking about. If you want it to be 1000x800, make it that size. If the component has content - e.g. text or other components - calculate their positions appropriately. (You probably won't be able to use the standard layouts, and may end up writing your own). You'll probablky need to recalculate the layout if the component's width changes.

Don't call paint 4 times. If you've calculated the layout of the component, it's children or text, correctly then paint should just work.

In response to the comment: wrapping a histogram, in the sense of inserting arbitrary line breaks, is not likely to be useful. With graphical components the 'breaker' won't know exactly where to insert the breaks; you will also lose any information attached to the Y axis. Much better solutions would be to simply shrink the histogram in the horizontal direction until it fits the screen width, or to draw four histograms one under the other, duplicating the Y axis information for each. Alternatively allow horizontal scrolling over the whole histogram; or change the axes so the histogram is drawn horizontally. If none of the above work, perhaps because you have many hundreds of histogram bars, maybe a more interactive approach where you amalgamate some of your histogram bars together to give an overview, and allow the user to 'drill down' into the plot to get at the more detailed information.

If the issue is that you can't modify the original component, and it draws a fixed size image, then your best bet may be to call 'paint(Graphics)' on it four times with appropriate transforms and clipRects on the Graphics to draw the four parts 'stacked'. But frankly you may be as well off throwing away the original component. Histograms are not that hard to draw, and there are plenty of free plotting packages to help you. And be very rude to the designer of the original component if you meet them.

DJClayworth
you seem to suggest to re-design the child component, but the problem is that this component is an histogram of some activity, and has an image of 4000x200px that id draws in its paintcomponent(). That's why I was looking for some more generic way of putting it in 4 lines without touching it...
Goulou
Before I answer this comment, it's usually best to do this by editing the original question rather than adding an explanatory comment.
DJClayworth
If you're saying that you have a component you can't modify that draws a 4000x200 image, and won't allow a size change, then find who designed that component and have very sharp words with them.
DJClayworth
A: 

You don't mention scrolling. Put it on it's own pane and then put that pane into a scrolling panel.

Kelly French