// I think this is what you want.
// Expansion / contraction is the same as applying a scaling transform.

import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;


public class Scaler extends JPanel {
  double R_CENTER_X = 50;
  double R_CENTER_Y = 50;
  double E_CENTER_X = 150;
  double E_CENTER_Y = 150;
  double WIDTH = 10;
  double HEIGHT = 20;

  Shape rect = new Rectangle2D.Double(0,0,WIDTH,HEIGHT);
  Shape ellipse = new Ellipse2D.Double(0,0,WIDTH,HEIGHT);
  AffineTransform rectTrans =
AffineTransform.getTranslateInstance(R_CENTER_X, R_CENTER_Y);
  AffineTransform ellipseTrans =
AffineTransform.getTranslateInstance(E_CENTER_X, E_CENTER_Y);

  public void init() {
    // put the center of the rect and ellipse at the origin
    AffineTransform trans =
AffineTransform.getTranslateInstance(-WIDTH/2, -HEIGHT/2);
    rect = trans.createTransformedShape(rect);
    ellipse = trans.createTransformedShape(ellipse);
    setBackground(Color.black);
  }

  public void scale(Graphics2D g, double scaleFactor) {
    AffineTransform trans =
AffineTransform.getScaleInstance(scaleFactor, scaleFactor);
    rectTrans.concatenate(trans);
    ellipseTrans.concatenate(trans);
    Shape shape = rectTrans.createTransformedShape(rect);
    g.draw(shape);
    shape = ellipseTrans.createTransformedShape(ellipse);
    g.draw(shape);
  }

  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.white);
    scale(g2, 1);
    g2.setColor(Color.blue);
    scale(g2, 2);
    g2.setColor(Color.green);
    scale(g2, 3);
    g2.setColor(Color.red);
    scale(g2, .5);
  }

  public static void main(String[ ] args) {
    JFrame frame = new JFrame("scale test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Scaler scaler = new Scaler();
    scaler.init();
    frame.getContentPane().add(scaler);
    frame.setSize(new Dimension(300,300));
    frame.setVisible(true);
  }

}

===========================================================================
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