Merge pull request #1940 from hcraigmiller/Rename-and-re-order-examples

Rename and re-order example designs
This commit is contained in:
Sibo Van Gool 2023-01-01 14:24:55 +01:00 committed by GitHub
commit ede9dfe700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 58 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,8 @@
package net.sf.openrocket.gui.main; package net.sf.openrocket.gui.main;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.Action; import javax.swing.Action;
@ -18,6 +20,35 @@ public final class ExampleDesignFileAction extends JMenu {
*/ */
private final BasicFrame parent; 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",
"Two-stage rocket",
"Three-stage rocket",
"TARC payload rocket",
"Tube fin rocket",
null,
// Examples demonstrating complex rocket features
"Airstart timing",
"Chute release",
"Dual parachute deployment",
"Clustered motors",
"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. * Constructor.
* *
@ -38,11 +69,37 @@ public final class ExampleDesignFileAction extends JMenu {
private void updateMenu() { private void updateMenu() {
removeAll(); removeAll();
ExampleDesignFile[] examples = ExampleDesignFile.getExampleDesigns(); ExampleDesignFile[] examples = ExampleDesignFile.getExampleDesigns();
List<JMenuItem> itemList = new ArrayList<>();
// First create the menu items
for (ExampleDesignFile file : examples) { for (ExampleDesignFile file : examples) {
Action action = createAction(file); Action action = createAction(file);
action.putValue(Action.NAME, file.toString()); action.putValue(Action.NAME, file.toString());
JMenuItem menuItem = new JMenuItem(action); 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);
}
} }
} }