super(string);
this.elementClass = elementClass;
}
public void actionPerformed(ActionEvent e) {
final StatefulDisplayElement newElement;
Record record = selectedElement.getRecord();
final Point location = new Point(selectedElement.getLocation());
selectedElement.disconnect();
selectedElement.getLayoutAllocation().deallocate();
selectedElement.getParent().remove(selectedElement);
try {
newElement = (StatefulDisplayElement) elementClass
.newInstance();
} catch (InstantiationException ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE,
null, ex);
return;
} catch (IllegalAccessException ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE,
null, ex);
return;
}
// final FormattedField newElement = new FormattedField();
newElement.setFieldName(record.getName());
newElement.setRecord(record);
addField(newElement);
// queue up request to set location so it happens after addField
SwingUtilities.invokeLater(new Runnable() {
public void run() {
newElement.setLocation(location);
}
});
record.addStateReceiver(newElement);
}