|
|
|
|
Re: How to change the color of editPart objects [message #1732047 is a reply to message #1732025] |
Thu, 12 May 2016 08:34 |
Tito Tito Messages: 4 Registered: May 2016 |
Junior Member |
|
|
This is the refreshVisuals(). i'm implementing my model reduction technique on an existing
open source plugin tool called jUCMNav,. Therefore, non of the code below is mine except
the last two lines where i call my doColor() after checking my command is ON
[HINT: pathnode, startPoint, EndPoint , etc are model element types].
attached two snapshots, "beforeSelection" is when i execute my command is the my target
paths are colored with their objects. "Afterselection" snapshot you can see some objects(with x shape) are reset to black_ this happens when i click on these objects
if i do one simple change/edit on the editor, the objects are colored normally to green.
the issue is that when just click/deselect objects and not doing any editing, the objects are reset to black and never changed until an edit occurs.
-could it be some kind of select/deselect notifier that's called when selecting/deselecting objects? cuz i noticed that a rectangle appears bordering the target object once it is selected (it is shown in "AfterSelection" snapshot)
here is the refreshVisuals() code
public void refreshVisuals() {
PathNodeFigure nodeFigure = getNodeFigure();
PathNode node = getNode();
if (node instanceof StartPoint) {// If it's a startpoint, update it's type
switch (((StartPoint) node).getFailureKind().getValue()) {
case FailureKind.NONE:
((StartPointFigure) nodeFigure).setType(0, ((StartPoint) node).isLocal());
break;
case FailureKind.FAILURE:
((StartPointFigure) nodeFigure).setType(1, ((StartPoint) node).isLocal());
break;
case FailureKind.ABORT:
((StartPointFigure) nodeFigure).setType(2, ((StartPoint) node).isLocal());
break;
default:
break;
}
}
if(node instanceof EndPoint) {
((EndPointFigure)nodeFigure).setType(((EndPoint) node).isLocal());
}
// inform and forks/joins how many branches they must display.
if (node instanceof AndFork) {
((AndForkJoinFigure) nodeFigure).setBranchCount(((PathNode) getModel()).getSucc().size());
} else if (node instanceof AndJoin) {
((AndForkJoinFigure) nodeFigure).setBranchCount(((PathNode) getModel()).getPred().size());
}
boolean scenariosActive = ScenarioUtils.getActiveScenario(node) != null && ScenarioUtils.getTraversalHitCount(node) > 0;
nodeFigure.setTraversed(scenariosActive);
// Set tool tip or hit count.
if (ScenarioUtils.getActiveScenario(node) != null) {
String hits = Integer.toString(ScenarioUtils.getTraversalHitCount(node));
//nodeFigure.setToolTip(new Label(Messages.getString("PathNodeEditPart.Hits") + hits)); //$NON-NLS-1$
Metadata metaHitCount = MetadataHelper.getMetaDataObj(node, METADATA_HITS);
if (metaHitCount != null) {
metaHitCount.setValue(hits);
} else {
MetadataHelper.addMetaData(diagram.getUrndefinition().getUrnspec(), node, METADATA_HITS, hits);
}
UrnMetadata.setToolTip(node, nodeFigure);
} else
UrnMetadata.setToolTip(node, nodeFigure);
// check if path node is used as a border for a pointcut expression
nodeFigure.setIsPointcutBorder(PointcutBorderDetector.detectPointcutBorder(node));
// refresh node connection decorations
// must not continue or will cause infinite loops
if (refreshDecorations())
return;
// position the figure
Dimension dim = nodeFigure.getPreferredSize().getCopy();
Point location = new Point(node.getX() - (dim.width / 2), node.getY() - (dim.height / 2)); // The
// position of the current figure
Rectangle bounds = new Rectangle(location, dim);
figure.setBounds(bounds);
// rotate it if necessary.
// note: you can't have andjoin rotate from previous for andjoin because it would cause infinite loops with connection router.
if (!(node instanceof AndJoin || node instanceof AndFork) && nodeFigure instanceof IRotateable && ((PathNode) getModel()).getPred().size() > 0) {
rotateFromPrevious(nodeFigure);
} else if ((node instanceof AndJoin || node instanceof AndFork || node instanceof FailurePoint || node instanceof Stub) && nodeFigure instanceof IRotateable && ((PathNode) getModel()).getSucc().size() > 0) {
rotateFromNext(nodeFigure);
}
// hide empty points when not in view all elements mode.
if (getModel() instanceof EmptyPoint) {
//((IFigure) getFigure().getChildren().get(0)).setVisible(((UCMConnectionOnBottomRootEditPart) getRoot()).getMode() == 0);
((IFigure) getFigure().getChildren().get(0)).setVisible(GeneralPreferencePage.getUcmEmptyPointVisible());
}
// should we offset it so that it doesn't overlap another element?
if (getModel() instanceof EndPoint) {
((EndPointFigure) nodeFigure).setOffset((((EndPoint) getModel()).getSucc().size() > 0));
}
// notify parent container of changed position & location
// if this line is removed, the XYLayoutManager used by the parent
// container
// (the Figure of the ShapesDiagramEditPart), will not know the bounds
// of this figure
// and will not draw it correctly.
if (getParent() != null)
((GraphicalEditPart) getParent()).setLayoutConstraint(this, figure, bounds);
// if (((UCMConnectionOnBottomRootEditPart)
// getRoot()).isStrategyView()){
//
// nodeFigure.setForegroundColor(
// new Color(Display.getCurrent(),StringConverter.asRGB("75,75,75")));
// } else{
// if (ScenarioUtils.getActiveScenario(getNode())!=null &&
// ScenarioUtils.getTraversalHitCount(getNode())>0) {
// nodeFigure.setColor(PathNodeFigure.RED);
// }
// else {
// nodeFigure.setColor(PathNodeFigure.BLACK);
// }
// nodeFigure.setForegroundColor(
// new Color(Display.getCurrent(),StringConverter.asRGB("0,0,0"))); //$NON-NLS-1$
// }
if(ColorUtils.ReduceON)
ColorUtils.doColor();
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03541 seconds