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