public void updateSubfactionChoice() { FactionRecord old = (FactionRecord)cbSubfaction.getSelectedItem(); cbSubfaction.removeActionListener(this); cbSubfaction.removeAllItems(); FactionRecord selectedFaction = (FactionRecord)cbFaction.getSelectedItem(); if (selectedFaction != null) { ArrayList<FactionRecord> recs = new ArrayList<>(); for (FactionRecord fRec : RATGenerator.getInstance().getFactionList()) { if (fRec.getKey().startsWith(selectedFaction.getKey() + ".") && fRec.isActiveInYear(ratGenYear)) { recs.add(fRec); } } Collections.sort(recs, factionSorter); cbSubfaction.addItem(null); //No specific subcommand. for (FactionRecord fRec : recs) { cbSubfaction.addItem(fRec); } } cbSubfaction.setSelectedItem(old); updateRatingChoice(); cbSubfaction.addActionListener(this); }
@Override public void actionPerformed(ActionEvent ev) { if (ev.getSource().equals(cbFaction)) { updateSubfactionChoice(); } else if (ev.getSource().equals(cbSubfaction)) { updateRatingChoice(); } else if (ev.getSource().equals(chkShowMinor)) { updateFactionChoice(); } else if (ev.getSource().equals(cbUnitType)) { if (panUnitTypeOptions != null) { panUnitTypeOptions.optionsChanged(); } } else if (ev.getActionCommand().equals("ratGenInitialized")) { updateFactionChoice(); RATGenerator.getInstance().removeListener(this); RATGenerator.getInstance().loadYear(ratGenYear); } }