Merge pull request #1828 from SiboVG/issue-1818
[#1818] Update extension menu 'copy extension' after extension change
This commit is contained in:
commit
f723508491
@ -60,6 +60,8 @@ class SimulationOptionsPanel extends JPanel {
|
|||||||
final Simulation simulation;
|
final Simulation simulation;
|
||||||
|
|
||||||
private JPanel currentExtensions;
|
private JPanel currentExtensions;
|
||||||
|
final JPopupMenu extensionMenu;
|
||||||
|
JMenu extensionMenuCopyExtension;
|
||||||
|
|
||||||
SimulationOptionsPanel(OpenRocketDocument document, final Simulation simulation) {
|
SimulationOptionsPanel(OpenRocketDocument document, final Simulation simulation) {
|
||||||
super(new MigLayout("fill"));
|
super(new MigLayout("fill"));
|
||||||
@ -195,10 +197,10 @@ class SimulationOptionsPanel extends JPanel {
|
|||||||
|
|
||||||
|
|
||||||
final JButton addExtension = new SelectColorButton(trans.get("simedtdlg.SimExt.add"));
|
final JButton addExtension = new SelectColorButton(trans.get("simedtdlg.SimExt.add"));
|
||||||
final JPopupMenu menu = getExtensionMenu();
|
this.extensionMenu = getExtensionMenu();
|
||||||
addExtension.addActionListener(new ActionListener() {
|
addExtension.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent ev) {
|
public void actionPerformed(ActionEvent ev) {
|
||||||
menu.show(addExtension, 5, addExtension.getBounds().height);
|
extensionMenu.show(addExtension, 5, addExtension.getBounds().height);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sub.add(addExtension, "growx, wrap 0");
|
sub.add(addExtension, "growx, wrap 0");
|
||||||
@ -218,6 +220,7 @@ class SimulationOptionsPanel extends JPanel {
|
|||||||
|
|
||||||
JPopupMenu basemenu = new JPopupMenu();
|
JPopupMenu basemenu = new JPopupMenu();
|
||||||
|
|
||||||
|
//// Use code / Launch conditions
|
||||||
for (final SimulationExtensionProvider provider : extensions) {
|
for (final SimulationExtensionProvider provider : extensions) {
|
||||||
List<String> ids = provider.getIds();
|
List<String> ids = provider.getIds();
|
||||||
for (final String id : ids) {
|
for (final String id : ids) {
|
||||||
@ -243,9 +246,30 @@ class SimulationOptionsPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JMenu copyMenu = null;
|
//// Copy extension
|
||||||
|
updateExtensionMenuCopyExtension(basemenu);
|
||||||
|
|
||||||
|
return basemenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the contents of the "Copy extension" menu item in the extension menu.
|
||||||
|
* @param extensionMenu extension menu to add the "Copy extension" menu item to
|
||||||
|
*/
|
||||||
|
private void updateExtensionMenuCopyExtension(JPopupMenu extensionMenu) {
|
||||||
|
if (extensionMenu == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.extensionMenuCopyExtension != null) {
|
||||||
|
extensionMenu.remove(this.extensionMenuCopyExtension);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.extensionMenuCopyExtension = null;
|
||||||
for (Simulation sim : document.getSimulations()) {
|
for (Simulation sim : document.getSimulations()) {
|
||||||
if (!sim.getSimulationExtensions().isEmpty()) {
|
if (sim.getSimulationExtensions().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
JMenu menu = new JMenu(sim.getName());
|
JMenu menu = new JMenu(sim.getName());
|
||||||
for (final SimulationExtension ext : sim.getSimulationExtensions()) {
|
for (final SimulationExtension ext : sim.getSimulationExtensions()) {
|
||||||
JMenuItem item = new JMenuItem(ext.getName());
|
JMenuItem item = new JMenuItem(ext.getName());
|
||||||
@ -265,17 +289,14 @@ class SimulationOptionsPanel extends JPanel {
|
|||||||
menu.add(item);
|
menu.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copyMenu == null) {
|
if (this.extensionMenuCopyExtension == null) {
|
||||||
copyMenu = new JMenu(trans.get("simedtdlg.SimExt.copyExtension"));
|
this.extensionMenuCopyExtension = new JMenu(trans.get("simedtdlg.SimExt.copyExtension"));
|
||||||
}
|
}
|
||||||
copyMenu.add(menu);
|
this.extensionMenuCopyExtension.add(menu);
|
||||||
}
|
}
|
||||||
|
if (this.extensionMenuCopyExtension != null) {
|
||||||
|
extensionMenu.add(this.extensionMenuCopyExtension);
|
||||||
}
|
}
|
||||||
if (copyMenu != null) {
|
|
||||||
basemenu.add(copyMenu);
|
|
||||||
}
|
|
||||||
|
|
||||||
return basemenu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JComponent findMenu(MenuElement menu, List<String> menuItems) {
|
private JComponent findMenu(MenuElement menu, List<String> menuItems) {
|
||||||
@ -314,6 +335,9 @@ class SimulationOptionsPanel extends JPanel {
|
|||||||
currentExtensions.add(new SimulationExtensionPanel(e), "growx, wrap");
|
currentExtensions.add(new SimulationExtensionPanel(e), "growx, wrap");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateExtensionMenuCopyExtension(this.extensionMenu);
|
||||||
|
|
||||||
// Both needed:
|
// Both needed:
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
this.repaint();
|
this.repaint();
|
||||||
@ -337,6 +361,7 @@ class SimulationOptionsPanel extends JPanel {
|
|||||||
|
|
||||||
this.add(new JPanel(), "spanx, split, growx, right");
|
this.add(new JPanel(), "spanx, split, growx, right");
|
||||||
|
|
||||||
|
// Configure
|
||||||
if (findConfigurator(extension) != null) {
|
if (findConfigurator(extension) != null) {
|
||||||
button = new SelectColorButton(Icons.CONFIGURE);
|
button = new SelectColorButton(Icons.CONFIGURE);
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
@ -350,6 +375,7 @@ class SimulationOptionsPanel extends JPanel {
|
|||||||
this.add(button, "right");
|
this.add(button, "right");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Help
|
||||||
if (extension.getDescription() != null) {
|
if (extension.getDescription() != null) {
|
||||||
button = new SelectColorButton(Icons.HELP);
|
button = new SelectColorButton(Icons.HELP);
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
@ -377,6 +403,7 @@ class SimulationOptionsPanel extends JPanel {
|
|||||||
this.add(button, "right");
|
this.add(button, "right");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete
|
||||||
button = new SelectColorButton(Icons.EDIT_DELETE);
|
button = new SelectColorButton(Icons.EDIT_DELETE);
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user