Add custom design file ordering + separator
This commit is contained in:
parent
7859cd1ed4
commit
b4b4b20748
@ -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",
|
||||||
|
"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.
|
* 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user