1 package com.billkuker.rocketry.motorsim.visual;
\r
3 import java.awt.BorderLayout;
\r
4 import java.awt.FlowLayout;
\r
5 import java.awt.event.ActionEvent;
\r
6 import java.awt.event.ActionListener;
\r
7 import java.beans.PropertyVetoException;
\r
8 import java.io.IOException;
\r
10 import javax.measure.unit.SI;
\r
11 import javax.swing.ButtonGroup;
\r
12 import javax.swing.JButton;
\r
13 import javax.swing.JFrame;
\r
14 import javax.swing.JPanel;
\r
15 import javax.swing.JRadioButton;
\r
16 import javax.swing.JTabbedPane;
\r
17 import javax.swing.UIManager;
\r
19 import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
\r
20 import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
\r
21 import org.jscience.physics.amount.Amount;
\r
23 import com.billkuker.rocketry.motorsim.Burn;
\r
24 import com.billkuker.rocketry.motorsim.ConvergentDivergentNozzle;
\r
25 import com.billkuker.rocketry.motorsim.CylindricalChamber;
\r
26 import com.billkuker.rocketry.motorsim.Motor;
\r
27 import com.billkuker.rocketry.motorsim.RocketScience.UnitPreference;
\r
28 import com.billkuker.rocketry.motorsim.fuel.KNSU;
\r
29 import com.billkuker.rocketry.motorsim.grain.CoredCylindricalGrain;
\r
30 import com.billkuker.rocketry.motorsim.grain.MultiGrain;
\r
31 import com.billkuker.rocketry.motorsim.grain.RotatedShapeGrain;
\r
32 import com.billkuker.rocketry.motorsim.io.MotorIO;
\r
34 public class CrappyEditor extends JFrame {
\r
35 JTabbedPane tabs = new JTabbedPane();
\r
37 public CrappyEditor() {
\r
38 setTitle("MotorSim v0.2");
\r
40 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
\r
41 setContentPane(tabs);
\r
44 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
\r
45 } catch (Exception e1) {
\r
46 e1.printStackTrace();
\r
49 tabs.addTab("Edit", new Editor(defaultMotor()));
\r
53 private class Editor extends JPanel {
\r
54 RSyntaxTextArea text = new RSyntaxTextArea();
\r
57 setLayout(new BorderLayout());
\r
58 add(text, BorderLayout.CENTER);
\r
59 JPanel buttons = new JPanel(new FlowLayout());
\r
60 buttons.add(new JButton("Burn!") {
\r
62 addActionListener(new ActionListener() {
\r
63 public void actionPerformed(ActionEvent arg0) {
\r
70 buttons.add(s = new JRadioButton("SI"));
\r
71 buttons.add(n = new JRadioButton("NonSI"));
\r
72 ButtonGroup g = new ButtonGroup();
\r
75 s.setSelected(true);
\r
76 s.addActionListener(new ActionListener() {
\r
77 public void actionPerformed(ActionEvent arg0) {
\r
78 UnitPreference.preference = UnitPreference.SI;
\r
81 n.addActionListener(new ActionListener() {
\r
82 public void actionPerformed(ActionEvent arg0) {
\r
83 UnitPreference.preference = UnitPreference.NONSI;
\r
86 add(buttons, BorderLayout.SOUTH);
\r
87 text.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
\r
90 text.setText(MotorIO.writeMotor(m));
\r
91 } catch (IOException e) {
\r
92 e.printStackTrace();
\r
97 private void burn() {
\r
99 Motor m = MotorIO.readMotor(text.getText());
\r
100 Burn b = new Burn(m);
\r
101 tabs.addTab(m.getName() + " Output", new BurnPanel(b));
\r
102 } catch (IOException e) {
\r
103 e.printStackTrace();
\r
108 private Motor defaultMotor() {
\r
109 Motor m = new Motor();
\r
111 m.setFuel(new KNSU());
\r
113 CylindricalChamber c = new CylindricalChamber();
\r
114 c.setLength(Amount.valueOf(200, SI.MILLIMETER));
\r
115 c.setID(Amount.valueOf(25, SI.MILLIMETER));
\r
118 CoredCylindricalGrain g = new CoredCylindricalGrain();
\r
120 g.setLength(Amount.valueOf(70, SI.MILLIMETER));
\r
121 g.setOD(Amount.valueOf(23.5, SI.MILLIMETER));
\r
122 g.setID(Amount.valueOf(7.9375, SI.MILLIMETER));
\r
123 } catch (PropertyVetoException v) {
\r
124 throw new Error(v);
\r
127 m.setGrain(new MultiGrain(g, 2));
\r
129 ConvergentDivergentNozzle n = new ConvergentDivergentNozzle();
\r
130 n.setThroatDiameter(Amount.valueOf(7.962, SI.MILLIMETER));
\r
131 n.setExitDiameter(Amount.valueOf(13.79, SI.MILLIMETER));
\r
132 n.setEfficiency(.85);
\r
138 public static void main(String args[]) {
\r
139 new CrappyEditor().show();
\r