codice:
private class ScenarioListCellRenderer implements ListCellRenderer
{
@Override
public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
{
JPanel comp = new JPanel();
comp.setLayout (new GridBagLayout());
if (value instanceof Scenario) {
Scenario sc = (Scenario) value;
//Sel checkbox
JCheckBox sel = new JCheckBox();
sel.setSelected (isSelected);
comp.add (sel, Utilities.UI.getConstraints(0, 0, 1, 1, GridBagConstraints.NONE, 0, 0));
//Play/Stop
JButton play = Utilities.UI.getButton("Play Scenario", ICON_PLAY, "Play this scenarion on MLab", Actions.SCENARIO_PLAY, false, 20, 20, null);
play.setEnabled (!sc.running);
JButton stop = Utilities.UI.getButton("Stop Scenario", ICON_STOP, "Stop this scenarion on MLab", Actions.SCENARIO_STOP, false, 20, 20, null);
stop.setEnabled (sc.running);
comp.add (play, Utilities.UI.getConstraints(0, 1, 1, 1, GridBagConstraints.NONE, 0, 0));
comp.add (stop, Utilities.UI.getConstraints(0, 2, 1, 1, GridBagConstraints.NONE, 0, 0));
//Scenario name
JLabel name = new JLabel (sc.name);
name.setFont (FONT_SCENARIO_NAME);
name.setPreferredSize(new Dimension (300, name.getPreferredSize().height));
comp.add (name, Utilities.UI.getConstraints(0, 3, 1, 1, GridBagConstraints.HORIZONTAL, 0.8, 0));
//Fixed/Mobile
JCheckBox fixed = new JCheckBox (FIXED_SCENARIO);
fixed.setSelected (sc.fixed);
fixed.setFont (FONT_SCENARIO_NAME);
comp.add (fixed, Utilities.UI.getConstraints(0, 4, 1, 1, GridBagConstraints.NONE, 0, 0));
//Mobility pattern
JComboBox patterns = new JComboBox (new String[]{"Pattern 1", "Pattern 2", "Pattern 3", "Upload..."});
comp.add (patterns, Utilities.UI.getConstraints(0, 5, 1, 1, GridBagConstraints.HORIZONTAL, 0.6, 0));
}
return comp;
}
}