Commit 51739da3 authored by Simon Barner's avatar Simon Barner
Browse files

Prevent crash by not disposing color that is owned by SWTResourceManager.

refs 2709
parent c8d03f7b
......@@ -34,51 +34,35 @@ import org.fortiss.af3.operatorpanel.simulator.ExecutableOperatorPanelSpecificat
/* package */class OPVCColorDisplay extends
OPVCOutputControlBase<OPColorDisplay, Label, OPColorReaction> {
/** The background color. */
private Color background;
/** The last reaction activated. */
private OPColorReaction lastReaction = null;
/** Constructor. */
public OPVCColorDisplay(OPColorDisplay item, Composite parent) {
super(item, parent);
background = getColor(0, 0, 0);
}
/** {@inheritDoc} */
@Override
protected Label createControl(Composite parent) {
Label label = new Label(parent, SWT.BORDER);
label.setBackground(background);
label.setBackground(getColor(SWT.COLOR_BLACK));
return label;
}
/** {@inheritDoc} */
@Override
public void dispose() {
background.dispose();
super.dispose();
}
/** {@inheritDoc} */
@Override
public void updateDisplayInternal(ExecutableOperatorPanelSpecification simulation,
OPColorReaction reaction) {
if(reaction != lastReaction) {
lastReaction = reaction;
Color background;
if(reaction != null) {
switchColor(reaction.getRed(), reaction.getGreen(), reaction.getBlue());
background = getColor(reaction.getRed(), reaction.getGreen(), reaction.getBlue());
} else {
switchColor(0, 0, 0);
background = getColor(SWT.COLOR_BLACK);
}
control.setBackground(background);
}
}
/** Switches the color. */
private void switchColor(int red, int green, int blue) {
background.dispose();
background = getColor(red, green, blue);
control.setBackground(background);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment