public void selectionChange(CL_SelectionUtilities selection)
// Action is enabled if at least 2 chord symbols are selected
setEnabled(selection.getSelectedChordSymbols().size() >= 2);
public void actionPerformed(ActionEvent e)
// Get current selection context: at least 2 chord symbols because of our selectionChange() implementation
CL_SelectionUtilities selection = cap.getSelection();
// Compute and show user possible reharmonizations
// Return the user-selected reharmonization, or null
List<CLI_ChordSymbol> newChordSymbols= getReharmonizedChordSymbols(selection.getSelectedChordSymbols());
if (newChordSymbols != null)
// Start an undoable action which will collect the individual undoable edits
ChordLeadSheet cls = selection.getChordLeadSheet();
JJazzUndoManagerFinder.getDefault().get(cls).startCEdit(undoText);
// Remove existing chord symbols
for (CLI_ChordSymbol cliCs : selection.getSelectedChordSymbols())
cls.removeItem(cliCs); // Generate one or more undoable edits
// Replace with the new chord symbols
for (CLI_ChordSymbol cliCs : newChordSymbols)
cls.addItem(cliCs); // Generate one or more undoable edits
// End the undoable action: action can now be undone by user via the undo/redo UI
JJazzUndoManagerFinder.getDefault().get(cls).endCEdit(undoText);