Initial commit
[debian/openrocket] / src / net / sf / openrocket / gui / configdialog / EllipticalFinSetConfig.java
1 package net.sf.openrocket.gui.configdialog;
2
3
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6
7 import javax.swing.JButton;
8 import javax.swing.JComboBox;
9 import javax.swing.JLabel;
10 import javax.swing.JPanel;
11 import javax.swing.JSeparator;
12 import javax.swing.JSpinner;
13 import javax.swing.SwingConstants;
14 import javax.swing.SwingUtilities;
15
16 import net.miginfocom.swing.MigLayout;
17 import net.sf.openrocket.gui.BasicSlider;
18 import net.sf.openrocket.gui.SpinnerEditor;
19 import net.sf.openrocket.gui.UnitSelector;
20 import net.sf.openrocket.gui.adaptors.DoubleModel;
21 import net.sf.openrocket.gui.adaptors.EnumModel;
22 import net.sf.openrocket.gui.adaptors.IntegerModel;
23 import net.sf.openrocket.material.Material;
24 import net.sf.openrocket.rocketcomponent.FinSet;
25 import net.sf.openrocket.rocketcomponent.FreeformFinSet;
26 import net.sf.openrocket.rocketcomponent.RocketComponent;
27 import net.sf.openrocket.unit.UnitGroup;
28
29 public class EllipticalFinSetConfig extends FinSetConfig {
30
31         public EllipticalFinSetConfig(final RocketComponent component) {
32                 super(component);
33
34                 DoubleModel m;
35                 JSpinner spin;
36                 JComboBox combo;
37                 
38                 JPanel mainPanel = new JPanel(new MigLayout());
39                 
40                 
41                 
42                 JPanel panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]",""));
43                 
44                 ////  Number of fins
45                 panel.add(new JLabel("Number of fins:"));
46                 
47                 IntegerModel im = new IntegerModel(component,"FinCount",1,8);
48                 
49                 spin = new JSpinner(im.getSpinnerModel());
50                 spin.setEditor(new SpinnerEditor(spin));
51                 panel.add(spin,"growx, wrap");
52                 
53                 
54                 ////  Base rotation
55                 panel.add(new JLabel("Rotation:"));
56                 
57                 m = new DoubleModel(component, "BaseRotation", UnitGroup.UNITS_ANGLE,-Math.PI,Math.PI);
58                 
59                 spin = new JSpinner(m.getSpinnerModel());
60                 spin.setEditor(new SpinnerEditor(spin));
61                 panel.add(spin,"growx");
62                 
63                 panel.add(new UnitSelector(m),"growx");
64                 panel.add(new BasicSlider(m.getSliderModel(-Math.PI,Math.PI)),"w 100lp, wrap");
65                 
66                 
67                 ////  Root chord
68                 panel.add(new JLabel("Root chord:"));
69                 
70                 m  = new DoubleModel(component,"Length",UnitGroup.UNITS_LENGTH,0);
71                 
72                 spin = new JSpinner(m.getSpinnerModel());
73                 spin.setEditor(new SpinnerEditor(spin));
74                 panel.add(spin,"growx");
75                 
76                 panel.add(new UnitSelector(m),"growx");
77                 panel.add(new BasicSlider(m.getSliderModel(0,0.05,0.2)),"w 100lp, wrap");
78
79
80                 ////  Height
81                 panel.add(new JLabel("Height:"));
82                 
83                 m = new DoubleModel(component,"Height",UnitGroup.UNITS_LENGTH,0);
84                 
85                 spin = new JSpinner(m.getSpinnerModel());
86                 spin.setEditor(new SpinnerEditor(spin));
87                 panel.add(spin,"growx");
88                 
89                 panel.add(new UnitSelector(m),"growx");
90                 panel.add(new BasicSlider(m.getSliderModel(0,0.05,0.2)),"w 100lp, wrap");
91         
92                 
93                 ////  Position
94                 
95                 panel.add(new JLabel("Position relative to:"));
96
97                 combo = new JComboBox(
98                                 new EnumModel<RocketComponent.Position>(component, "RelativePosition",
99                                                 new RocketComponent.Position[] {
100                                                 RocketComponent.Position.TOP,
101                                                 RocketComponent.Position.MIDDLE,
102                                                 RocketComponent.Position.BOTTOM,
103                                                 RocketComponent.Position.ABSOLUTE
104                                 }));
105                 panel.add(combo,"spanx, growx, wrap");
106                 
107                 panel.add(new JLabel("plus"),"right");
108
109                 m = new DoubleModel(component,"PositionValue",UnitGroup.UNITS_LENGTH);
110                 spin = new JSpinner(m.getSpinnerModel());
111                 spin.setEditor(new SpinnerEditor(spin));
112                 panel.add(spin,"growx");
113                 
114                 panel.add(new UnitSelector(m),"growx");
115                 panel.add(new BasicSlider(m.getSliderModel(
116                                 new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE),
117                                 new DoubleModel(component.getParent(), "Length"))),
118                                 "w 100lp, wrap");
119
120
121                 
122                 //// Right portion
123                 mainPanel.add(panel,"aligny 20%");
124                 
125                 mainPanel.add(new JSeparator(SwingConstants.VERTICAL),"growy");
126                 
127                 
128                 
129                 panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]",""));
130
131
132                 ////  Cross section
133                 panel.add(new JLabel("Fin cross section:"),"span, split");
134                 combo = new JComboBox(
135                                 new EnumModel<FinSet.CrossSection>(component,"CrossSection"));
136                 panel.add(combo,"growx, wrap unrel");
137                 
138
139                 ////  Thickness
140                 panel.add(new JLabel("Thickness:"));
141                 
142                 m = new DoubleModel(component,"Thickness",UnitGroup.UNITS_LENGTH,0);
143                 
144                 spin = new JSpinner(m.getSpinnerModel());
145                 spin.setEditor(new SpinnerEditor(spin));
146                 panel.add(spin,"growx");
147                 
148                 panel.add(new UnitSelector(m),"growx");
149                 panel.add(new BasicSlider(m.getSliderModel(0,0.01)),"w 100lp, wrap 30lp");
150                 
151                 
152
153                 //// Material
154                 materialPanel(panel, Material.Type.BULK);
155                 
156                 
157                 
158                 //// Convert button
159                 
160                 JButton button = new JButton("Convert to freeform fin set");
161                 button.addActionListener(new ActionListener() {
162                         @Override
163                         public void actionPerformed(ActionEvent e) {
164                                 // Do change in future for overall safety
165                                 SwingUtilities.invokeLater(new Runnable() {
166                                         @Override
167                                         public void run() {
168                                                 FreeformFinSet freeform = new FreeformFinSet((FinSet)component);
169                                                 RocketComponent parent = component.getParent();
170                                                 int index = parent.getChildPosition(component);
171                                                 
172                                                 ComponentConfigDialog.addUndoPosition("Convert fin set");
173                                                 parent.removeChild(index);
174                                                 parent.addChild(freeform, index);
175                                                 ComponentConfigDialog.showDialog(freeform);
176                                         }
177                                 });
178
179                                 ComponentConfigDialog.hideDialog();
180                         }
181                 });
182                 panel.add(button,"span, growx, gaptop paragraph");
183                 
184                 
185                 
186                 mainPanel.add(panel,"aligny 20%");
187                 
188                 addFinSetButtons();
189
190
191                 tabbedPane.insertTab("General", null, mainPanel, "General properties", 0);
192                 tabbedPane.setSelectedIndex(0);
193         }
194
195 }