1 package com.billkuker.rocketry.motorsim.visual;
\r
3 import java.awt.BasicStroke;
\r
4 import java.awt.Color;
\r
5 import java.awt.Graphics;
\r
6 import java.awt.Graphics2D;
\r
7 import java.awt.Rectangle;
\r
8 import java.awt.Shape;
\r
9 import java.beans.PropertyChangeEvent;
\r
10 import java.beans.PropertyChangeListener;
\r
12 import javax.measure.unit.SI;
\r
13 import javax.swing.JFrame;
\r
14 import javax.swing.JPanel;
\r
15 import javax.swing.WindowConstants;
\r
17 import org.jscience.physics.amount.Amount;
\r
19 import com.billkuker.rocketry.motorsim.ConvergentDivergentNozzle;
\r
20 import com.billkuker.rocketry.motorsim.MotorPart;
\r
21 import com.billkuker.rocketry.motorsim.Nozzle;
\r
23 public class NozzlePanel extends JPanel {
\r
24 private static final long serialVersionUID = 1L;
\r
25 private Nozzle nozzle;
\r
26 public NozzlePanel(Nozzle n){
\r
29 if ( n instanceof MotorPart ){
\r
30 ((MotorPart)n).addPropertyChangeListener(new PropertyChangeListener(){
\r
32 public void propertyChange(PropertyChangeEvent evt) {
\r
39 public void paint(Graphics g){
\r
41 Graphics2D g2d = (Graphics2D)g;
\r
42 g2d.translate(10, 10);
\r
44 g2d.setColor(Color.black);
\r
47 Shape a = nozzle.nozzleShape(Amount.valueOf(30, SI.MILLIMETER));
\r
49 Rectangle bounds = a.getBounds();
\r
50 double max = bounds.getWidth();
\r
51 if ( bounds.getHeight() > max )
\r
52 max = bounds.getHeight();
\r
54 g2d.scale(200 / max, 200 / max);
\r
55 g2d.translate(-bounds.getX(), -bounds.getY());
\r
57 g2d.setStroke(new BasicStroke(4*(float)max/200f));
\r
62 public void showAsWindow(){
\r
63 JFrame f = new JFrame();
\r
65 f.setContentPane(this);
\r
66 f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
\r
70 public static void main(String args[]) throws Exception{
\r
71 ConvergentDivergentNozzle n = new ConvergentDivergentNozzle();
\r
72 n.setThroatDiameter(Amount.valueOf(5, SI.MILLIMETER));
\r
73 n.setExitDiameter(Amount.valueOf(9, SI.MILLIMETER));
\r
74 new Editor(n).show();
\r
75 new NozzlePanel(n).show();
\r