import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
+import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
{
ok.setEnabled(false);
}
+ updateScoreModels(comboBox, tips);
}
/**
}
return false;
}
+
+ final JComboBox<String> comboBox = new JComboBox<String>();
+
+ final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
+
+ List<String> tips = new ArrayList<String>();
+
/**
* A rather elaborate helper method (blame Swing, not me) that builds a
* drop-down list of score models (by name) with descriptions as tooltips.
*/
protected JComboBox<String> buildModelOptionsList()
{
- final JComboBox<String> comboBox = new JComboBox<String>();
- ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
comboBox.setRenderer(renderer);
- final List<String> tips = new ArrayList<String>();
/*
* show tooltip on mouse over the combobox
* note the listener has to be on the components that make up
* the combobox, doesn't work if just on the combobox
*/
- MouseAdapter mouseListener = new MouseAdapter()
+ final MouseAdapter mouseListener = new MouseAdapter()
{
@Override
public void mouseEntered(MouseEvent e)
c.addMouseListener(mouseListener);
}
+ updateScoreModels(comboBox, tips);
+
+ /*
+ * set the list of tooltips on the combobox's renderer
+ */
+ renderer.setTooltips(tips);
+
+ return comboBox;
+ }
+
+ private void updateScoreModels(JComboBox comboBox, List<String> tips)
+ {
+ Object curSel = comboBox.getSelectedItem();
+ tips.clear();
+ DefaultComboBoxModel model = new DefaultComboBoxModel();
+
/*
* now we can actually add entries to the combobox,
* remembering their descriptions for tooltips
*/
ScoreModels scoreModels = ScoreModels.getInstance();
+ boolean selectedIsPresent = false;
for (ScoreModelI sm : scoreModels.getModels())
{
boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
if (sm.isDNA() && nucleotide || sm.isProtein() && !nucleotide)
{
- comboBox.addItem(sm.getName());
+ if (curSel != null && sm.getName().equals(curSel))
+ {
+ selectedIsPresent = true;
+ curSel = sm.getName();
+ }
+ model.addElement(sm.getName());
/*
* tooltip is description if provided, else text lookup with
}
tips.add(tooltip);
}
-
- /*
- * set the list of tooltips on the combobox's renderer
- */
- renderer.setTooltips(tips);
}
-
- return comboBox;
+ if (selectedIsPresent)
+ {
+ model.setSelectedItem(curSel);
+ }
+ // finally, update the model
+ comboBox.setModel(model);
}
/**