+++ /dev/null
-package com.billkuker.rocketry.motorsim.visual;\r
-\r
-import java.awt.BorderLayout;\r
-import java.awt.FlowLayout;\r
-import java.awt.event.ActionEvent;\r
-import java.awt.event.ActionListener;\r
-import java.beans.PropertyVetoException;\r
-import java.io.IOException;\r
-\r
-import javax.measure.unit.SI;\r
-import javax.swing.ButtonGroup;\r
-import javax.swing.JButton;\r
-import javax.swing.JFrame;\r
-import javax.swing.JPanel;\r
-import javax.swing.JRadioButton;\r
-import javax.swing.JTabbedPane;\r
-import javax.swing.UIManager;\r
-\r
-import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;\r
-import org.fife.ui.rsyntaxtextarea.SyntaxConstants;\r
-import org.jscience.physics.amount.Amount;\r
-\r
-import com.billkuker.rocketry.motorsim.Burn;\r
-import com.billkuker.rocketry.motorsim.ConvergentDivergentNozzle;\r
-import com.billkuker.rocketry.motorsim.CylindricalChamber;\r
-import com.billkuker.rocketry.motorsim.Motor;\r
-import com.billkuker.rocketry.motorsim.RocketScience.UnitPreference;\r
-import com.billkuker.rocketry.motorsim.fuel.KNSU;\r
-import com.billkuker.rocketry.motorsim.grain.CoredCylindricalGrain;\r
-import com.billkuker.rocketry.motorsim.grain.MultiGrain;\r
-import com.billkuker.rocketry.motorsim.io.MotorIO;\r
-import com.billkuker.rocketry.motorsim.motors.example.CSlot;\r
-import com.billkuker.rocketry.motorsim.motors.example.EndBurner;\r
-\r
-public class CrappyEditor extends JFrame {\r
- private static final long serialVersionUID = 1L;\r
- JTabbedPane tabs;\r
-\r
- public CrappyEditor() {\r
- setTitle("MotorSim v0.3");\r
- setSize(1024, 768);\r
- setDefaultCloseOperation(DISPOSE_ON_CLOSE);\r
-\r
- try {\r
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
- } catch (Exception e1) {\r
- e1.printStackTrace();\r
- }\r
- tabs = new JTabbedPane();\r
- setContentPane(tabs);\r
- tabs.addTab("Edit", new Editor(defaultMotor()));\r
-\r
- }\r
-\r
- private class Editor extends JPanel {\r
- private static final long serialVersionUID = 1L;\r
- RSyntaxTextArea text = new RSyntaxTextArea();\r
-\r
- Editor(Motor m) {\r
- setLayout(new BorderLayout());\r
- add(text, BorderLayout.CENTER);\r
- JPanel buttons = new JPanel(new FlowLayout());\r
-\r
- buttons.add(new JButton("Burn!") {\r
- private static final long serialVersionUID = 1L;\r
- {\r
- addActionListener(new ActionListener() {\r
- public void actionPerformed(ActionEvent arg0) {\r
- burn();\r
- }\r
- });\r
- }\r
- });\r
-\r
-\r
- JRadioButton s, n;\r
- buttons.add(s = new JRadioButton("SI"));\r
- buttons.add(n = new JRadioButton("NonSI"));\r
- ButtonGroup g = new ButtonGroup();\r
- g.add(s);\r
- g.add(n);\r
- s.setSelected(true);\r
- s.addActionListener(new ActionListener() {\r
- public void actionPerformed(ActionEvent arg0) {\r
- UnitPreference.preference = UnitPreference.SI;\r
- }\r
- });\r
- n.addActionListener(new ActionListener() {\r
- public void actionPerformed(ActionEvent arg0) {\r
- UnitPreference.preference = UnitPreference.NONSI;\r
- }\r
- });\r
- \r
- buttons.add(new JButton("End Burner Example") {\r
- private static final long serialVersionUID = 1L;\r
- {\r
- addActionListener(new ActionListener() {\r
- public void actionPerformed(ActionEvent arg0) {\r
- tabs.addTab(getText(), new BurnPanel(new Burn(new EndBurner())));\r
- }\r
- });\r
- }\r
- });\r
- \r
- buttons.add(new JButton("C-Slot Example") {\r
- private static final long serialVersionUID = 1L;\r
- {\r
- addActionListener(new ActionListener() {\r
- public void actionPerformed(ActionEvent arg0) {\r
- tabs.addTab(getText(), new BurnPanel(new Burn(new CSlot())));\r
- }\r
- });\r
- }\r
- });\r
- \r
- add(buttons, BorderLayout.SOUTH);\r
- text.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);\r
-\r
- try {\r
- text.setText(MotorIO.writeMotor(m));\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- }\r
-\r
- }\r
-\r
- private void burn() {\r
- try {\r
- Motor m = MotorIO.readMotor(text.getText());\r
- Burn b = new Burn(m);\r
- tabs.addTab(m.getName() + " Output", new BurnPanel(b));\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
-\r
- private Motor defaultMotor() {\r
- Motor m = new Motor();\r
- m.setName("Example Motor");\r
- m.setFuel(new KNSU());\r
-\r
- CylindricalChamber c = new CylindricalChamber();\r
- c.setLength(Amount.valueOf(200, SI.MILLIMETER));\r
- c.setID(Amount.valueOf(25, SI.MILLIMETER));\r
- m.setChamber(c);\r
-\r
- CoredCylindricalGrain g = new CoredCylindricalGrain();\r
- try {\r
- g.setLength(Amount.valueOf(70, SI.MILLIMETER));\r
- g.setOD(Amount.valueOf(23.5, SI.MILLIMETER));\r
- g.setID(Amount.valueOf(7.9375, SI.MILLIMETER));\r
- } catch (PropertyVetoException v) {\r
- throw new Error(v);\r
- }\r
-\r
- m.setGrain(new MultiGrain(g, 2));\r
-\r
-\r
- ConvergentDivergentNozzle n = new ConvergentDivergentNozzle();\r
- n.setThroatDiameter(Amount.valueOf(7.962, SI.MILLIMETER));\r
- n.setExitDiameter(Amount.valueOf(13.79, SI.MILLIMETER));\r
- n.setEfficiency(.85);\r
- m.setNozzle(n);\r
-\r
- return m;\r
- }\r
- \r
-\r
- public static void main(String args[]) {\r
- new CrappyEditor().setVisible(true);\r
- }\r
-}\r