// Set size of the panel.
valueEntryPanel.setSize(valueEntryPanel.getPreferredSize());
// Add a listener to propagate changes in the VEP to the value gem.
valueEntryPanel.addValueEditorListener(new ValueEditorAdapter() {
public void valueCommitted(ValueEditorEvent evt) {
ValueNode oldValue = evt.getOldValue();
ValueNode newValue = ((ValueEntryPanel)evt.getSource()).getValueNode();
if (!oldValue.sameValue(newValue)) {
valueGem.changeValue(newValue);
}
}
});
// Add a listener so that a change in the size of the VEP will trigger a change the size of the displayed gem.
valueEntryPanel.addComponentListener(new ComponentAdapter() {
// change the size of the displayed value gem if the VEP is resized
public void componentResized(ComponentEvent e) {
tableTop.getDisplayedGem(valueGem).sizeChanged();
}
// Re-position displayed gem if the VEP moves
// This will happen if the VEP size changes (as a result of a type change), and its size is clamped to the parent's bounds.
// eg. stick a new VEP on the right edge of the TableTop, and change its type to String.
public void componentMoved(ComponentEvent e) {
Point vepLocation = valueEntryPanel.getLocation();
int newX = vepLocation.x - DisplayConstants.BEVEL_WIDTH_X - 1;
int newY = vepLocation.y - DisplayConstants.BEVEL_WIDTH_Y - 1;
Point newPoint = new Point(newX, newY);
tableTop.getDisplayedGem(valueGem).setLocation(newPoint);
}
});
// Set the vep's context for type switching.
valueEntryPanel.setContext(new ValueEditorContext() {
public TypeExpr getLeastConstrainedTypeExpr() {
return tableTop.getGemGraph().getLeastConstrainedValueType(valueGem, tableTop.getTypeCheckInfo());
}
});
// Set it up so that VEP commits are handled as user edits.
valueEntryPanel.addValueEditorListener(new ValueEditorAdapter() {
public void valueCommitted(ValueEditorEvent evt) {
tableTop.handleValueGemCommitted(valueGem, evt.getOldValue(), valueEntryPanel.getValueNode());
}
});
}