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.StyledLabel;
19 import net.sf.openrocket.gui.components.UnitSelector;
20 import net.sf.openrocket.gui.components.StyledLabel.Style;
21 import net.sf.openrocket.rocketcomponent.FinSet;
22 import net.sf.openrocket.rocketcomponent.FreeformFinSet;
23 import net.sf.openrocket.rocketcomponent.RocketComponent;
24 import net.sf.openrocket.unit.UnitGroup;
27 public abstract class FinSetConfig extends RocketComponentConfig {
29 private JButton split = null;
31 public FinSetConfig(RocketComponent component) {
34 tabbedPane.insertTab("Fin tabs", null, finTabPanel(), "Through-the-wall fin tabs", 0);
39 protected void addFinSetButtons() {
43 if (!(component instanceof FreeformFinSet)) {
44 convert = new JButton("Convert to freeform");
45 convert.setToolTipText("Convert this fin set into a freeform fin set");
46 convert.addActionListener(new ActionListener() {
48 public void actionPerformed(ActionEvent e) {
49 // Do change in future for overall safety
50 SwingUtilities.invokeLater(new Runnable() {
53 ComponentConfigDialog.addUndoPosition("Convert fin set");
54 RocketComponent freeform =
55 FreeformFinSet.convertFinSet((FinSet)component);
56 ComponentConfigDialog.showDialog(freeform);
60 ComponentConfigDialog.hideDialog();
65 split = new JButton("Split fins");
66 split.setToolTipText("Split the fin set into separate fins");
67 split.addActionListener(new ActionListener() {
69 public void actionPerformed(ActionEvent e) {
70 // Do change in future for overall safety
71 SwingUtilities.invokeLater(new Runnable() {
74 RocketComponent parent = component.getParent();
75 int index = parent.getChildPosition(component);
76 int count = ((FinSet)component).getFinCount();
77 double base = ((FinSet)component).getBaseRotation();
81 ComponentConfigDialog.addUndoPosition("Split fin set");
82 parent.removeChild(index);
83 for (int i=0; i<count; i++) {
84 FinSet copy = (FinSet)component.copy();
86 copy.setBaseRotation(base + i*2*Math.PI/count);
87 copy.setName(copy.getName() + " #" + (i+1));
88 parent.addChild(copy, index+i);
93 ComponentConfigDialog.hideDialog();
96 split.setEnabled(((FinSet)component).getFinCount() > 1);
101 addButtons(split,convert);
105 public JPanel finTabPanel() {
106 JPanel panel = new JPanel(
107 new MigLayout("align 50% 20%, fillx, gap rel unrel, ins 20lp 10% 20lp 10%",
108 "[150lp::][65lp::][30lp::][200lp::]",""));
109 // JPanel panel = new JPanel(new MigLayout("fillx, align 20% 20%, gap rel unrel",
110 // "[40lp][80lp::][30lp::][100lp::]",""));
112 panel.add(new StyledLabel("Through-the-wall fin tabs:", Style.BOLD),
119 DoubleModel length_2;
122 length = new DoubleModel(component, "Length", UnitGroup.UNITS_LENGTH, 0);
123 length2 = new DoubleModel(component, "Length", 0.5, UnitGroup.UNITS_LENGTH, 0);
124 length_2 = new DoubleModel(component, "Length", -0.5, UnitGroup.UNITS_LENGTH, 0);
127 label = new JLabel("Tab length:");
128 label.setToolTipText("The length of the fin tab.");
129 panel.add(label, "gapleft para, gapright 40lp, growx 1");
131 m = new DoubleModel(component, "TabLength", UnitGroup.UNITS_LENGTH, 0);
133 spin = new JSpinner(m.getSpinnerModel());
134 spin.setEditor(new SpinnerEditor(spin));
135 panel.add(spin,"growx 1");
137 panel.add(new UnitSelector(m),"growx 1");
138 panel.add(new BasicSlider(m.getSliderModel(DoubleModel.ZERO, length)),
139 "w 100lp, growx 5, wrap");
143 label = new JLabel("Tab height:");
144 label.setToolTipText("The spanwise height of the fin tab.");
145 panel.add(label, "gapleft para");
147 m = new DoubleModel(component, "TabHeight", UnitGroup.UNITS_LENGTH, 0);
149 spin = new JSpinner(m.getSpinnerModel());
150 spin.setEditor(new SpinnerEditor(spin));
151 panel.add(spin,"growx");
153 panel.add(new UnitSelector(m),"growx");
154 panel.add(new BasicSlider(m.getSliderModel(DoubleModel.ZERO, length2)),
155 "w 100lp, growx 5, wrap para");
159 label = new JLabel("Tab position:");
160 label.setToolTipText("The position of the fin tab.");
161 panel.add(label, "gapleft para");
163 m = new DoubleModel(component, "TabShift", UnitGroup.UNITS_LENGTH);
165 spin = new JSpinner(m.getSpinnerModel());
166 spin.setEditor(new SpinnerEditor(spin));
167 panel.add(spin,"growx");
169 panel.add(new UnitSelector(m),"growx");
170 panel.add(new BasicSlider(m.getSliderModel(length_2, length2)),"w 100lp, growx 5, wrap");
174 label = new JLabel("relative to");
175 panel.add(label, "right, gapright unrel");
177 EnumModel<FinSet.TabRelativePosition> em =
178 new EnumModel<FinSet.TabRelativePosition>(component, "TabRelativePosition");
180 panel.add(new JComboBox(em), "spanx 3, growx");
186 public void updateFields() {
187 super.updateFields();
189 split.setEnabled(((FinSet)component).getFinCount() > 1);