Skip to content
Snippets Groups Projects
Commit 6e78ad9f authored by Lukas Ladenberger's avatar Lukas Ladenberger
Browse files

fixed some further bugs (checkbox and radiobutton behaviour)

parent b8e3728b
No related branches found
No related tags found
No related merge requests found
Showing
with 826 additions and 692 deletions
......@@ -17,6 +17,7 @@ public class ButtonGroupHelper {
private static HashMap<String, Collection<BControl>> map = new HashMap<String, Collection<BControl>>();
public ButtonGroupHelper() {
System.out.println("REGISTER");
}
public static Collection<BControl> getButtonGroup(String buttonGroupID) {
......@@ -38,4 +39,8 @@ public class ButtonGroupHelper {
map.remove(buttonGroupID);
}
public static void reset() {
map.clear();
}
}
......@@ -22,7 +22,7 @@ public class BAttributeButtonGroup extends AbstractAttribute {
@Override
public String getName() {
return "Button";
return "Group Name";
}
}
......@@ -42,4 +42,9 @@ public class CheckboxFigure extends AbstractBMotionFigure {
textLb.setForegroundColor(color);
}
public void setBtEnabled(Boolean bool) {
textLb.setEnabled(bool);
repaint();
}
}
......@@ -47,6 +47,11 @@ public class RadioButtonFigure extends AbstractBMotionFigure {
textLb.setForegroundColor(foregroundColor);
}
public void setBtEnabled(Boolean bool) {
textLb.setEnabled(bool);
repaint();
}
/*
* (non-Javadoc)
*
......
......@@ -11,6 +11,7 @@ import org.eclipse.swt.graphics.RGB;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.attribute.BAttributeButtonGroup;
import de.bmotionstudio.gef.editor.attribute.BAttributeChecked;
import de.bmotionstudio.gef.editor.attribute.BAttributeEnabled;
import de.bmotionstudio.gef.editor.attribute.BAttributeFalseValue;
import de.bmotionstudio.gef.editor.attribute.BAttributeText;
import de.bmotionstudio.gef.editor.attribute.BAttributeTextColor;
......@@ -42,6 +43,7 @@ public class BCheckbox extends BControl {
initAttribute(new BAttributeTextColor(new RGB(0, 0, 0)));
initAttribute(new BAttributeChecked(true));
initAttribute(new BAttributeValue(""));
initAttribute(new BAttributeEnabled(true));
initAttribute(new BAttributeButtonGroup(""));
initAttribute(new BAttributeTrueValue(""));
initAttribute(new BAttributeFalseValue(""));
......
......@@ -12,9 +12,9 @@ import org.eclipse.swt.graphics.RGB;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.ButtonGroupHelper;
import de.bmotionstudio.gef.editor.attribute.BAttributeBackgroundColor;
import de.bmotionstudio.gef.editor.attribute.BAttributeButtonGroup;
import de.bmotionstudio.gef.editor.attribute.BAttributeChecked;
import de.bmotionstudio.gef.editor.attribute.BAttributeEnabled;
import de.bmotionstudio.gef.editor.attribute.BAttributeText;
import de.bmotionstudio.gef.editor.attribute.BAttributeTextColor;
import de.bmotionstudio.gef.editor.attribute.BAttributeValue;
......@@ -46,11 +46,11 @@ public class BRadioButton extends BControl {
@Override
protected void initAttributes() {
initAttribute(new BAttributeText(DEFAULT_TEXT));
initAttribute(new BAttributeBackgroundColor(new RGB(192, 192, 192)));
initAttribute(new BAttributeTextColor(new RGB(0, 0, 0)));
initAttribute(new BAttributeChecked(true));
initAttribute(new BAttributeValue(""));
initAttribute(new BAttributeButtonGroup(""));
initAttribute(new BAttributeEnabled(true));
getAttribute(AttributeConstants.ATTRIBUTE_HEIGHT).setValue(21);
getAttribute(AttributeConstants.ATTRIBUTE_HEIGHT).setEditable(false);
}
......@@ -77,7 +77,7 @@ public class BRadioButton extends BControl {
AttributeConstants.ATTRIBUTE_VALUE).toString();
}
}
return null;
return "";
}
}
......@@ -14,6 +14,7 @@ import org.eclipse.draw2d.PositionConstants;
import de.be4.classicalb.core.parser.exceptions.BException;
import de.bmotionstudio.gef.editor.AttributeConstants;
import de.bmotionstudio.gef.editor.ButtonGroupHelper;
import de.bmotionstudio.gef.editor.IAddErrorListener;
import de.bmotionstudio.gef.editor.internal.Animation;
import de.bmotionstudio.gef.editor.scheduler.PredicateOperation;
......@@ -62,6 +63,7 @@ public class Visualization extends BControl {
this.errorListener = new ArrayList<IAddErrorListener>();
this.isRunning = false;
createRulers();
ButtonGroupHelper.reset();
}
@Override
......@@ -71,6 +73,7 @@ public class Visualization extends BControl {
populateVisualization(this);
createRulers();
this.errorListener = new ArrayList<IAddErrorListener>();
ButtonGroupHelper.reset();
// this.errorMessages = new ArrayList<ErrorMessage>();
// setAttributeValue(AttributeConstants.ATTRIBUTE_ID, "surface", false);
return this;
......
......@@ -63,6 +63,7 @@ public abstract class AppAbstractEditPart extends AbstractGraphicalEditPart
if (event.getPropertyName().equals(
ButtonModel.MOUSEOVER_PROPERTY))
getFigure().setCursor(cursorHover);
}
if (event.getPropertyName()
.equals(ButtonModel.PRESSED_PROPERTY)) {
AbstractBMotionFigure f = (AbstractBMotionFigure) getFigure();
......@@ -70,7 +71,6 @@ public abstract class AppAbstractEditPart extends AbstractGraphicalEditPart
executeEvent(AttributeConstants.EVENT_MOUSECLICK);
}
}
}
};
private String[] layoutAttributes = { BControl.PROPERTY_LAYOUT,
......
......@@ -8,6 +8,9 @@ package de.bmotionstudio.gef.editor.part;
import java.beans.PropertyChangeEvent;
import org.eclipse.draw2d.ButtonModel;
import org.eclipse.draw2d.ChangeEvent;
import org.eclipse.draw2d.ChangeListener;
import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
......@@ -24,11 +27,58 @@ import de.bmotionstudio.gef.editor.editpolicy.AppDeletePolicy;
import de.bmotionstudio.gef.editor.editpolicy.BMotionNodeEditPolicy;
import de.bmotionstudio.gef.editor.editpolicy.CustomDirectEditPolicy;
import de.bmotionstudio.gef.editor.editpolicy.RenamePolicy;
import de.bmotionstudio.gef.editor.figure.AbstractBMotionFigure;
import de.bmotionstudio.gef.editor.figure.CheckboxFigure;
import de.bmotionstudio.gef.editor.model.BControl;
public class BCheckboxPart extends AppAbstractEditPart {
private ChangeListener changeListener = new ChangeListener() {
@Override
public void handleStateChanged(ChangeEvent event) {
if (event.getPropertyName().equals(ButtonModel.PRESSED_PROPERTY)) {
BControl control = (BControl) getModel();
// Recheck observer after click
control.getVisualization().getAnimation().checkObserver();
if (Boolean.valueOf(control.getAttributeValue(
AttributeConstants.ATTRIBUTE_CHECKED).toString())) {
control.setAttributeValue(
AttributeConstants.ATTRIBUTE_CHECKED, false);
} else {
control.setAttributeValue(
AttributeConstants.ATTRIBUTE_CHECKED, true);
}
}
}
};
@Override
public void activate() {
super.activate();
if (isRunning()) {
if (getFigure() instanceof AbstractBMotionFigure)
((AbstractBMotionFigure) getFigure())
.addChangeListener(changeListener);
}
}
@Override
public void deactivate() {
if (isRunning()) {
if (getFigure() instanceof AbstractBMotionFigure)
((AbstractBMotionFigure) getFigure())
.removeChangeListener(changeListener);
}
super.deactivate();
}
@Override
protected IFigure createEditFigure() {
CheckboxFigure fig = new CheckboxFigure();
......@@ -71,6 +121,10 @@ public class BCheckboxPart extends AppAbstractEditPart {
.getDefault(), rgbText));
}
if (aID.equals(AttributeConstants.ATTRIBUTE_ENABLED))
((CheckboxFigure) figure).setBtEnabled(Boolean.valueOf(value
.toString()));
}
@Override
......
......@@ -7,7 +7,11 @@
package de.bmotionstudio.gef.editor.part;
import java.beans.PropertyChangeEvent;
import java.util.Collection;
import org.eclipse.draw2d.ButtonModel;
import org.eclipse.draw2d.ChangeEvent;
import org.eclipse.draw2d.ChangeListener;
import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
......@@ -24,11 +28,63 @@ import de.bmotionstudio.gef.editor.editpolicy.AppDeletePolicy;
import de.bmotionstudio.gef.editor.editpolicy.BMotionNodeEditPolicy;
import de.bmotionstudio.gef.editor.editpolicy.CustomDirectEditPolicy;
import de.bmotionstudio.gef.editor.editpolicy.RenamePolicy;
import de.bmotionstudio.gef.editor.figure.AbstractBMotionFigure;
import de.bmotionstudio.gef.editor.figure.RadioButtonFigure;
import de.bmotionstudio.gef.editor.model.BControl;
public class BRadioButtonPart extends AppAbstractEditPart {
private ChangeListener changeListener = new ChangeListener() {
@Override
public void handleStateChanged(ChangeEvent event) {
if (event.getPropertyName().equals(ButtonModel.PRESSED_PROPERTY)) {
BControl control = (BControl) getModel();
// Recheck observer after click
control.getVisualization().getAnimation().checkObserver();
// Set correct image of Radiobutton
String btgroupid = control.getAttributeValue(
AttributeConstants.ATTRIBUTE_BUTTONGROUP).toString();
if (!btgroupid.trim().equals("")) {
Collection<BControl> btGroup = ButtonGroupHelper
.getButtonGroup(btgroupid);
for (BControl c : btGroup) {
c.setAttributeValue(
AttributeConstants.ATTRIBUTE_CHECKED, false);
}
}
control.setAttributeValue(AttributeConstants.ATTRIBUTE_CHECKED,
true);
}
}
};
@Override
public void activate() {
super.activate();
if (isRunning()) {
if (getFigure() instanceof AbstractBMotionFigure)
((AbstractBMotionFigure) getFigure())
.addChangeListener(changeListener);
}
}
@Override
public void deactivate() {
if (isRunning()) {
if (getFigure() instanceof AbstractBMotionFigure)
((AbstractBMotionFigure) getFigure())
.removeChangeListener(changeListener);
}
super.deactivate();
}
@Override
protected IFigure createEditFigure() {
RadioButtonFigure fig = new RadioButtonFigure();
......@@ -78,6 +134,10 @@ public class BRadioButtonPart extends AppAbstractEditPart {
}
}
if (aID.equals(AttributeConstants.ATTRIBUTE_ENABLED))
((RadioButtonFigure) figure).setBtEnabled(Boolean.valueOf(value
.toString()));
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment