Add custom design file ordering + separator

This commit is contained in:
SiboVG 2023-01-01 05:16:48 +01:00
parent 7859cd1ed4
commit b4b4b20748

View File

@ -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.
* <p>
* 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<JMenuItem> 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);
}
}
}