Hi all,
a question re. the Java 2D API:

I would like to create a generic ZoomPanel, i.e. a Panel that would allow to 
display the objects contained in it using an adjustable zoom factor.
Ideally this Panel would be used much like a JScrollPanel, i.e.:

The JScrollPanel allows to wrap some content in a scrollable panel by just 
using:

1)    main.add(new JScrollPane(someContentPanel));
    
Ideally I would like to apply the Zoompanel in the exact same way, i.e.:

2)    main.add(new ZoomPanel(someContentPanel));

This would even allow to combine the two, e.g. like:
    
3)    main.add(new JScrollPane(new ZoomPanel(someContentPanel)));



Using Google and some API documentation I found misc. code snippets, which I 
condensed into the following: 
    
class ZoomPanel extends JPanel
{ 
    private double scalingFactor = 0.50;    
    
    ZoomPanel(final JComponent comp) {
        setLayout(new BorderLayout());
        add(comp, BorderLayout.CENTER);
    }
    /**
     * @return the scalingFactor
     */
    double getScalingFactor() {
        return this.scalingFactor;
    }
    /**
     * @param scalingFactor the scalingFactor to set
     */
    void setScalingFactor(double scalingFactor) {
        this.scalingFactor = scalingFactor;
    }
    @Override
    public Dimension getPreferredSize() {
        final Dimension size = getLayout().preferredLayoutSize(this);           
 
        return new Dimension((int)(size.width * this.scalingFactor), 
                     (int)(size.height * this.scalingFactor));
    }            
    @Override
    public boolean isOptimizedDrawingEnabled() { 
        return false; 
    }
    @Override
    public void paint(Graphics g) {
         Graphics2D g2 = (Graphics2D) g;
         java.awt.geom.AffineTransform backup = g2.getTransform();
         g2.scale(this.scalingFactor, this.scalingFactor);
         super.paint(g2);
         g2.setTransform(backup);
    }        
}


If applied as shown under 3) the above ZoomPanel does indeed display a zoomed 
copy of all children contained in "someContentPanel".
So, at first everything looks fine. However, if I move with the mouse over that 
panel, then certain children appear (i.e. are repainted) in their original size 
and location and obviously also the mouse positions are not properly translated 
and all clicks etc. go to wrong positions. So obviously the above is too simple 
(would have been too nice...) and does not cover every aspect that has to be 
taken care of in such a zoom panel

Has someone implemented something like this and could give me a list or at 
least a rough sketch, what all is still missing to achieve a generic panel? 
What needs to be overriden, added, replaced or whatever it takes to get this 
fully operational and usable?

Note: I do NOT know, what "someContentPanel" contains. As I said: I am trying 
to create a [b]generic[/b] panel that allows for arbitrary content.

Michael
[Message sent by forum member 'mmo18' (mmo18)]

http://forums.java.net/jive/thread.jspa?messageID=292502

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to