Collection<GemEntity> drawingGems = calHelper.findGemsOfType("Cal.Experimental.Graphics.Drawing.Graphics -> Cal.Experimental.Graphics.Drawing.Graphics");
final JComboBox drawFnCombo = new JComboBox(new Vector<GemEntity>(drawingGems));
drawFnCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GemEntity gemEntity = (GemEntity) drawFnCombo.getSelectedItem();
currentDrawExpr = Expr.makeGemCall(gemEntity.getName());
repaint();
}
});
drawFnCombo.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = -2433581223714718290L;
@Override
public Component getListCellRendererComponent(
JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
GemEntity gemEntity = (GemEntity) value;
label.setText(gemEntity.getName().getQualifiedName());
return label;
}
});
// Set the initial drawing gem.
if (drawingGems.isEmpty()) {
throw new BusinessObjectsException("No drawing gems are available.");
}
GemEntity initialDrawGem = drawingGems.iterator().next();
currentDrawExpr = Expr.makeGemCall(initialDrawGem.getName());
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(drawFnCombo, BorderLayout.NORTH);
this.getContentPane().add(new DrawPanel());