diff --git a/swing/src/net/sf/openrocket/gui/main/ExampleDesignFileAction.java b/swing/src/net/sf/openrocket/gui/main/ExampleDesignFileAction.java index 6fc0f39a2..712164a1d 100644 --- a/swing/src/net/sf/openrocket/gui/main/ExampleDesignFileAction.java +++ b/swing/src/net/sf/openrocket/gui/main/ExampleDesignFileAction.java @@ -1,6 +1,8 @@ package net.sf.openrocket.gui.main; import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.List; import javax.swing.AbstractAction; import javax.swing.Action; @@ -18,6 +20,35 @@ public final class ExampleDesignFileAction extends JMenu { */ private final BasicFrame parent; + /** + * Order in which the example files should be displayed in the menu. + * A null items means there should be a separator. + *

+ * NOTE: update this list if you add a new example file, or update the name of an existing one!!. + */ + private static final String[] exampleFileOrder = { + // Examples of basic rockets + "A simple model rocket", + "A staged rocket", + "A three-stage rocket", + "A trial TARC payload rocket", + "A tube fin rocket", + null, + // Examples demonstrating complex rocket features + "Airstart timing", + "Chute release deployment", + "Dual recovery deployment", + "Motor cluster", + "Parallel booster staging", + "Pods--airframes and winglets", + "Pods--powered with recovery deployment", + null, + // Examples demonstrating customized functionality + "Presets", + "Simulation extensions ", + "Simulation extensions and scripting" + }; + /** * Constructor. * @@ -38,11 +69,37 @@ public final class ExampleDesignFileAction extends JMenu { private void updateMenu() { removeAll(); ExampleDesignFile[] examples = ExampleDesignFile.getExampleDesigns(); + List itemList = new ArrayList<>(); + + // First create the menu items for (ExampleDesignFile file : examples) { Action action = createAction(file); action.putValue(Action.NAME, file.toString()); JMenuItem menuItem = new JMenuItem(action); - add(menuItem); + itemList.add(menuItem); + } + + // Then add them according to their order + for (String s : exampleFileOrder) { + if (s == null) { + addSeparator(); + } else { + for (JMenuItem item : itemList) { + if (item.getText().equals(s)) { + add(item); + itemList.remove(item); + break; + } + } + } + } + + // Add the remaining (unordered) items to the end + if (itemList.size() > 0) { + addSeparator(); + for (JMenuItem item : itemList) { + add(item); + } } }