Go to the documentation of this file.00001 package org.ros.model.ros_package.diagram.edit.parts;
00002
00003 import org.eclipse.draw2d.ColorConstants;
00004 import org.eclipse.draw2d.FlowLayout;
00005 import org.eclipse.draw2d.Graphics;
00006 import org.eclipse.draw2d.IFigure;
00007 import org.eclipse.draw2d.LineBorder;
00008 import org.eclipse.draw2d.MarginBorder;
00009 import org.eclipse.draw2d.RectangleFigure;
00010 import org.eclipse.draw2d.ScalablePolygonShape;
00011 import org.eclipse.draw2d.Shape;
00012 import org.eclipse.draw2d.StackLayout;
00013 import org.eclipse.draw2d.geometry.Dimension;
00014 import org.eclipse.draw2d.geometry.Point;
00015 import org.eclipse.draw2d.geometry.Rectangle;
00016 import org.eclipse.gef.EditPart;
00017 import org.eclipse.gef.EditPolicy;
00018 import org.eclipse.gef.commands.Command;
00019 import org.eclipse.gef.editpolicies.LayoutEditPolicy;
00020 import org.eclipse.gef.requests.CreateRequest;
00021 import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart;
00022 import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
00023 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
00024 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.FlowLayoutEditPolicy;
00025 import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
00026 import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
00027 import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
00028 import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
00029 import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
00030 import org.eclipse.gmf.runtime.notation.View;
00031 import org.eclipse.swt.graphics.Color;
00032
00036 public class PublisherEditPart extends AbstractBorderItemEditPart {
00037
00041 public static final int VISUAL_ID = 3004;
00042
00046 protected IFigure contentPane;
00047
00051 protected IFigure primaryShape;
00052
00056 public PublisherEditPart(View view) {
00057 super(view);
00058 }
00059
00063 protected void createDefaultEditPolicies() {
00064 super.createDefaultEditPolicies();
00065 installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
00066 getPrimaryDragEditPolicy());
00067 installEditPolicy(
00068 EditPolicyRoles.SEMANTIC_ROLE,
00069 new org.ros.model.ros_package.diagram.edit.policies.PublisherItemSemanticEditPolicy());
00070 installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
00071
00072
00073 }
00074
00078 protected LayoutEditPolicy createLayoutEditPolicy() {
00079
00080 FlowLayoutEditPolicy lep = new FlowLayoutEditPolicy() {
00081
00082 protected Command createAddCommand(EditPart child, EditPart after) {
00083 return null;
00084 }
00085
00086 protected Command createMoveChildCommand(EditPart child,
00087 EditPart after) {
00088 return null;
00089 }
00090
00091 protected Command getCreateCommand(CreateRequest request) {
00092 return null;
00093 }
00094 };
00095 return lep;
00096 }
00097
00101 protected IFigure createNodeShape() {
00102 return primaryShape = new Publisher2Figure();
00103 }
00104
00108 public Publisher2Figure getPrimaryShape() {
00109 return (Publisher2Figure) primaryShape;
00110 }
00111
00115 protected boolean addFixedChild(EditPart childEditPart) {
00116 if (childEditPart instanceof org.ros.model.ros_package.diagram.edit.parts.PublisherNameEditPart) {
00117 ((org.ros.model.ros_package.diagram.edit.parts.PublisherNameEditPart) childEditPart)
00118 .setLabel(getPrimaryShape().getFigurePublisherNameFigure());
00119 return true;
00120 }
00121 return false;
00122 }
00123
00127 protected boolean removeFixedChild(EditPart childEditPart) {
00128 if (childEditPart instanceof org.ros.model.ros_package.diagram.edit.parts.PublisherNameEditPart) {
00129 return true;
00130 }
00131 return false;
00132 }
00133
00137 protected void addChildVisual(EditPart childEditPart, int index) {
00138 if (addFixedChild(childEditPart)) {
00139 return;
00140 }
00141 super.addChildVisual(childEditPart, -1);
00142 }
00143
00147 protected void removeChildVisual(EditPart childEditPart) {
00148 if (removeFixedChild(childEditPart)) {
00149 return;
00150 }
00151 super.removeChildVisual(childEditPart);
00152 }
00153
00157 protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
00158 return getContentPane();
00159 }
00160
00164 protected NodeFigure createNodePlate() {
00165 DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(80, 20);
00166
00167
00168 result.getBounds().setSize(result.getPreferredSize());
00169 return result;
00170 }
00171
00180 protected NodeFigure createNodeFigure() {
00181 NodeFigure figure = createNodePlate();
00182 figure.setLayoutManager(new StackLayout());
00183 IFigure shape = createNodeShape();
00184 figure.add(shape);
00185 contentPane = setupContentPane(shape);
00186 return figure;
00187 }
00188
00195 protected IFigure setupContentPane(IFigure nodeShape) {
00196 if (nodeShape.getLayoutManager() == null) {
00197 ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
00198 layout.setSpacing(5);
00199 nodeShape.setLayoutManager(layout);
00200 }
00201 return nodeShape;
00202 }
00203
00207 public IFigure getContentPane() {
00208 if (contentPane != null) {
00209 return contentPane;
00210 }
00211 return super.getContentPane();
00212 }
00213
00217 protected void setForegroundColor(Color color) {
00218 if (primaryShape != null) {
00219 primaryShape.setForegroundColor(color);
00220 }
00221 }
00222
00226 protected void setBackgroundColor(Color color) {
00227 if (primaryShape != null) {
00228 primaryShape.setBackgroundColor(color);
00229 }
00230 }
00231
00235 protected void setLineWidth(int width) {
00236 if (primaryShape instanceof Shape) {
00237 ((Shape) primaryShape).setLineWidth(width);
00238 }
00239 }
00240
00244 protected void setLineType(int style) {
00245 if (primaryShape instanceof Shape) {
00246 ((Shape) primaryShape).setLineStyle(style);
00247 }
00248 }
00249
00253 public EditPart getPrimaryChildEditPart() {
00254 return getChildBySemanticHint(org.ros.model.ros_package.diagram.part.RosVisualIDRegistry
00255 .getType(org.ros.model.ros_package.diagram.edit.parts.PublisherNameEditPart.VISUAL_ID));
00256 }
00257
00261 public class Publisher2Figure extends ScalablePolygonShape {
00262 public static final int BLUR_SHADOW_WIDTH = 5;
00263
00264 @Override
00265 public void paintFigure(Graphics graphics) {
00266 drawBlurredShadow(graphics);
00267 super.paintFigure(graphics);
00268 }
00269
00270 private void drawBlurredShadow(Graphics graphics) {
00271
00272 graphics.pushState();
00273
00274 int size = MapModeUtil.getMapMode(this).DPtoLP(BLUR_SHADOW_WIDTH);
00275 int step = MapModeUtil.getMapMode(this).DPtoLP(-1);
00276
00277 graphics.setForegroundColor(ColorConstants.gray);
00278 graphics.setLineWidth(MapModeUtil.getMapMode(this).DPtoLP(2));
00279 graphics.translate(size, size);
00280 graphics.setClip(graphics.getClip(new Rectangle(getBounds()))
00281 .expand(size, size));
00282 graphics.setAlpha(20);
00283 outlineShape(graphics);
00284 graphics.translate(step, step);
00285 graphics.setAlpha(30);
00286 outlineShape(graphics);
00287 graphics.translate(step, step);
00288 graphics.setAlpha(60);
00289 outlineShape(graphics);
00290 graphics.translate(step, step);
00291 graphics.setAlpha(100);
00292 outlineShape(graphics);
00293 graphics.translate(step, step);
00294 graphics.setAlpha(150);
00295 outlineShape(graphics);
00296
00297 graphics.popState();
00298 }
00302 private WrappingLabel fFigurePublisherNameFigure;
00303
00307 public Publisher2Figure() {
00308
00309 FlowLayout layoutThis = new FlowLayout();
00310 layoutThis.setStretchMinorAxis(false);
00311 layoutThis.setMinorAlignment(FlowLayout.ALIGN_CENTER);
00312
00313 layoutThis.setMajorAlignment(FlowLayout.ALIGN_CENTER);
00314 layoutThis.setMajorSpacing(5);
00315 layoutThis.setMinorSpacing(5);
00316 layoutThis.setHorizontal(false);
00317
00318 this.setLayoutManager(layoutThis);
00319
00320 this.addPoint(new Point(getMapMode().DPtoLP(0), getMapMode()
00321 .DPtoLP(0)));
00322 this.addPoint(new Point(getMapMode().DPtoLP(30), getMapMode()
00323 .DPtoLP(0)));
00324 this.addPoint(new Point(getMapMode().DPtoLP(40), getMapMode()
00325 .DPtoLP(20)));
00326 this.addPoint(new Point(getMapMode().DPtoLP(30), getMapMode()
00327 .DPtoLP(40)));
00328 this.addPoint(new Point(getMapMode().DPtoLP(0), getMapMode()
00329 .DPtoLP(40)));
00330 this.setFill(true);
00331 this.setForegroundColor(THIS_FORE);
00332 this.setBackgroundColor(THIS_BACK);
00333 this.setPreferredSize(new Dimension(getMapMode().DPtoLP(80),
00334 getMapMode().DPtoLP(20)));
00335
00336 this.setBorder(new MarginBorder(getMapMode().DPtoLP(2),
00337 getMapMode().DPtoLP(2), getMapMode().DPtoLP(2),
00338 getMapMode().DPtoLP(2)));
00339 createContents();
00340 }
00341
00345 private void createContents() {
00346
00347 fFigurePublisherNameFigure = new WrappingLabel();
00348
00349 fFigurePublisherNameFigure.setText("<...>");
00350
00351 this.add(fFigurePublisherNameFigure);
00352
00353 }
00354
00358 public WrappingLabel getFigurePublisherNameFigure() {
00359 return fFigurePublisherNameFigure;
00360 }
00361
00362 }
00363
00367 static final Color THIS_FORE = new Color(null, 211, 72, 54);
00368
00372 static final Color THIS_BACK = new Color(null, 211, 72, 54);
00373
00374 }