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.StyledLabel.Style;
20 import net.sf.openrocket.gui.components.UnitSelector;
21 import net.sf.openrocket.l10n.Translator;
22 import net.sf.openrocket.logging.LogHelper;
23 import net.sf.openrocket.rocketcomponent.FinSet;
24 import net.sf.openrocket.rocketcomponent.FreeformFinSet;
25 import net.sf.openrocket.rocketcomponent.RocketComponent;
26 import net.sf.openrocket.startup.Application;
27 import net.sf.openrocket.unit.UnitGroup;
30 public abstract class FinSetConfig extends RocketComponentConfig {
31 private static final LogHelper log = Application.getLogger();
32 private static final Translator trans = Application.getTranslator();
34 private JButton split = null;
36 public FinSetConfig(RocketComponent component) {
39 //// Fin tabs and Through-the-wall fin tabs
40 tabbedPane.insertTab(trans.get("FinSetConfig.tab.Fintabs"), null, finTabPanel(),
41 trans.get("FinSetConfig.tab.Through-the-wall"), 0);
46 protected void addFinSetButtons() {
47 JButton convert = null;
50 if (!(component instanceof FreeformFinSet)) {
51 //// Convert to freeform
52 convert = new JButton(trans.get("FinSetConfig.but.Converttofreeform"));
53 //// Convert this fin set into a freeform fin set
54 convert.setToolTipText(trans.get("FinSetConfig.but.Converttofreeform.ttip"));
55 convert.addActionListener(new ActionListener() {
57 public void actionPerformed(ActionEvent e) {
58 log.user("Converting " + component.getComponentName() + " into freeform fin set");
60 // Do change in future for overall safety
61 SwingUtilities.invokeLater(new Runnable() {
65 ComponentConfigDialog.addUndoPosition(trans.get("FinSetConfig.Convertfinset"));
66 RocketComponent freeform =
67 FreeformFinSet.convertFinSet((FinSet) component);
68 ComponentConfigDialog.showDialog(freeform);
72 ComponentConfigDialog.hideDialog();
78 split = new JButton(trans.get("FinSetConfig.but.Splitfins"));
79 //// Split the fin set into separate fins
80 split.setToolTipText(trans.get("FinSetConfig.but.Splitfins.ttip"));
81 split.addActionListener(new ActionListener() {
83 public void actionPerformed(ActionEvent e) {
84 log.user("Splitting " + component.getComponentName() + " into separate fins, fin count=" +
85 ((FinSet) component).getFinCount());
87 // Do change in future for overall safety
88 SwingUtilities.invokeLater(new Runnable() {
91 RocketComponent parent = component.getParent();
92 int index = parent.getChildPosition(component);
93 int count = ((FinSet) component).getFinCount();
94 double base = ((FinSet) component).getBaseRotation();
98 ComponentConfigDialog.addUndoPosition("Split fin set");
99 parent.removeChild(index);
100 for (int i = 0; i < count; i++) {
101 FinSet copy = (FinSet) component.copy();
103 copy.setBaseRotation(base + i * 2 * Math.PI / count);
104 copy.setName(copy.getName() + " #" + (i + 1));
105 parent.addChild(copy, index + i);
110 ComponentConfigDialog.hideDialog();
113 split.setEnabled(((FinSet) component).getFinCount() > 1);
118 addButtons(split, convert);
122 public JPanel finTabPanel() {
123 JPanel panel = new JPanel(
124 new MigLayout("align 50% 20%, fillx, gap rel unrel, ins 20lp 10% 20lp 10%",
125 "[150lp::][65lp::][30lp::][200lp::]", ""));
126 // JPanel panel = new JPanel(new MigLayout("fillx, align 20% 20%, gap rel unrel",
127 // "[40lp][80lp::][30lp::][100lp::]",""));
129 //// Through-the-wall fin tabs:
130 panel.add(new StyledLabel(trans.get("FinSetConfig.lbl.Through-the-wall"), Style.BOLD),
137 DoubleModel length_2;
140 length = new DoubleModel(component, "Length", UnitGroup.UNITS_LENGTH, 0);
141 length2 = new DoubleModel(component, "Length", 0.5, UnitGroup.UNITS_LENGTH, 0);
142 length_2 = new DoubleModel(component, "Length", -0.5, UnitGroup.UNITS_LENGTH, 0);
150 label = new JLabel(trans.get("FinSetConfig.lbl.Tablength"));
151 //// The length of the fin tab.
152 label.setToolTipText(trans.get("FinSetConfig.ttip.Tablength"));
153 panel.add(label, "gapleft para, gapright 40lp, growx 1");
155 m = new DoubleModel(component, "TabLength", UnitGroup.UNITS_LENGTH, 0);
157 spin = new JSpinner(m.getSpinnerModel());
158 spin.setEditor(new SpinnerEditor(spin));
159 panel.add(spin, "growx 1");
161 panel.add(new UnitSelector(m), "growx 1");
162 panel.add(new BasicSlider(m.getSliderModel(DoubleModel.ZERO, length)),
163 "w 100lp, growx 5, wrap");
168 label = new JLabel(trans.get("FinSetConfig.lbl.Tabheight"));
169 //// The spanwise height of the fin tab.
170 label.setToolTipText(trans.get("FinSetConfig.ttip.Tabheight"));
171 panel.add(label, "gapleft para");
173 m = new DoubleModel(component, "TabHeight", UnitGroup.UNITS_LENGTH, 0);
175 spin = new JSpinner(m.getSpinnerModel());
176 spin.setEditor(new SpinnerEditor(spin));
177 panel.add(spin, "growx");
179 panel.add(new UnitSelector(m), "growx");
180 panel.add(new BasicSlider(m.getSliderModel(DoubleModel.ZERO, length2)),
181 "w 100lp, growx 5, wrap para");
185 label = new JLabel(trans.get("FinSetConfig.lbl.Tabposition"));
186 //// The position of the fin tab.
187 label.setToolTipText(trans.get("FinSetConfig.ttip.Tabposition"));
188 panel.add(label, "gapleft para");
190 m = new DoubleModel(component, "TabShift", UnitGroup.UNITS_LENGTH);
192 spin = new JSpinner(m.getSpinnerModel());
193 spin.setEditor(new SpinnerEditor(spin));
194 panel.add(spin, "growx");
196 panel.add(new UnitSelector(m), "growx");
197 panel.add(new BasicSlider(m.getSliderModel(length_2, length2)), "w 100lp, growx 5, wrap");
201 label = new JLabel(trans.get("FinSetConfig.lbl.relativeto"));
202 panel.add(label, "right, gapright unrel");
204 EnumModel<FinSet.TabRelativePosition> em =
205 new EnumModel<FinSet.TabRelativePosition>(component, "TabRelativePosition");
207 panel.add(new JComboBox(em), "spanx 3, growx");
213 public void updateFields() {
214 super.updateFields();
216 split.setEnabled(((FinSet) component).getFinCount() > 1);