1 package net.sf.openrocket.gui.configdialog;
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
6 import javax.swing.JButton;
7 import javax.swing.JComboBox;
8 import javax.swing.JLabel;
9 import javax.swing.JPanel;
10 import javax.swing.JSpinner;
11 import javax.swing.SwingUtilities;
13 import net.miginfocom.swing.MigLayout;
14 import net.sf.openrocket.gui.SpinnerEditor;
15 import net.sf.openrocket.gui.adaptors.DoubleModel;
16 import net.sf.openrocket.gui.adaptors.EnumModel;
17 import net.sf.openrocket.gui.components.BasicSlider;
18 import net.sf.openrocket.gui.components.UnitSelector;
19 import net.sf.openrocket.rocketcomponent.FinSet;
20 import net.sf.openrocket.rocketcomponent.FreeformFinSet;
21 import net.sf.openrocket.rocketcomponent.RocketComponent;
22 import net.sf.openrocket.unit.UnitGroup;
25 public abstract class FinSetConfig extends RocketComponentConfig {
27 private JButton split = null;
29 public FinSetConfig(RocketComponent component) {
32 tabbedPane.insertTab("Fin tabs", null, finTabPanel(), "Through-the-wall fin tabs", 0);
37 protected void addFinSetButtons() {
41 if (!(component instanceof FreeformFinSet)) {
42 convert = new JButton("Convert to freeform");
43 convert.setToolTipText("Convert this fin set into a freeform fin set");
44 convert.addActionListener(new ActionListener() {
46 public void actionPerformed(ActionEvent e) {
47 // Do change in future for overall safety
48 SwingUtilities.invokeLater(new Runnable() {
51 ComponentConfigDialog.addUndoPosition("Convert fin set");
52 RocketComponent freeform =
53 FreeformFinSet.convertFinSet((FinSet)component);
54 ComponentConfigDialog.showDialog(freeform);
58 ComponentConfigDialog.hideDialog();
63 split = new JButton("Split fins");
64 split.setToolTipText("Split the fin set into separate fins");
65 split.addActionListener(new ActionListener() {
67 public void actionPerformed(ActionEvent e) {
68 // Do change in future for overall safety
69 SwingUtilities.invokeLater(new Runnable() {
72 RocketComponent parent = component.getParent();
73 int index = parent.getChildPosition(component);
74 int count = ((FinSet)component).getFinCount();
75 double base = ((FinSet)component).getBaseRotation();
79 ComponentConfigDialog.addUndoPosition("Split fin set");
80 parent.removeChild(index);
81 for (int i=0; i<count; i++) {
82 FinSet copy = (FinSet)component.copy();
84 copy.setBaseRotation(base + i*2*Math.PI/count);
85 copy.setName(copy.getName() + " #" + (i+1));
86 parent.addChild(copy, index+i);
91 ComponentConfigDialog.hideDialog();
94 split.setEnabled(((FinSet)component).getFinCount() > 1);
99 addButtons(split,convert);
103 public JPanel finTabPanel() {
104 JPanel panel = new JPanel(
105 new MigLayout("align 50% 20%, fillx, gap rel unrel, ins 20lp 10% 20lp 10%",
106 "[150lp::][65lp::][30lp::][200lp::]",""));
107 // JPanel panel = new JPanel(new MigLayout("fillx, align 20% 20%, gap rel unrel",
108 // "[40lp][80lp::][30lp::][100lp::]",""));
110 panel.add(new JLabel("<html><b>Through-the-wall fin tabs:</b>"), "spanx, wrap 30lp");
116 DoubleModel length_2;
119 length = new DoubleModel(component, "Length", UnitGroup.UNITS_LENGTH, 0);
120 length2 = new DoubleModel(component, "Length", 0.5, UnitGroup.UNITS_LENGTH, 0);
121 length_2 = new DoubleModel(component, "Length", -0.5, UnitGroup.UNITS_LENGTH, 0);
124 label = new JLabel("Tab length:");
125 label.setToolTipText("The length of the fin tab.");
126 panel.add(label, "gapleft para, gapright 40lp, growx 1");
128 m = new DoubleModel(component, "TabLength", UnitGroup.UNITS_LENGTH, 0);
130 spin = new JSpinner(m.getSpinnerModel());
131 spin.setEditor(new SpinnerEditor(spin));
132 panel.add(spin,"growx 1");
134 panel.add(new UnitSelector(m),"growx 1");
135 panel.add(new BasicSlider(m.getSliderModel(DoubleModel.ZERO, length)),
136 "w 100lp, growx 5, wrap");
140 label = new JLabel("Tab height:");
141 label.setToolTipText("The spanwise height of the fin tab.");
142 panel.add(label, "gapleft para");
144 m = new DoubleModel(component, "TabHeight", UnitGroup.UNITS_LENGTH, 0);
146 spin = new JSpinner(m.getSpinnerModel());
147 spin.setEditor(new SpinnerEditor(spin));
148 panel.add(spin,"growx");
150 panel.add(new UnitSelector(m),"growx");
151 panel.add(new BasicSlider(m.getSliderModel(DoubleModel.ZERO, length2)),
152 "w 100lp, growx 5, wrap para");
156 label = new JLabel("Tab position:");
157 label.setToolTipText("The position of the fin tab.");
158 panel.add(label, "gapleft para");
160 m = new DoubleModel(component, "TabShift", UnitGroup.UNITS_LENGTH);
162 spin = new JSpinner(m.getSpinnerModel());
163 spin.setEditor(new SpinnerEditor(spin));
164 panel.add(spin,"growx");
166 panel.add(new UnitSelector(m),"growx");
167 panel.add(new BasicSlider(m.getSliderModel(length_2, length2)),"w 100lp, growx 5, wrap");
171 label = new JLabel("relative to");
172 panel.add(label, "right, gapright unrel");
174 EnumModel<FinSet.TabRelativePosition> em =
175 new EnumModel<FinSet.TabRelativePosition>(component, "TabRelativePosition");
177 panel.add(new JComboBox(em), "spanx 3, growx");
183 public void updateFields() {
184 super.updateFields();
186 split.setEnabled(((FinSet)component).getFinCount() > 1);