Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 159447 Details for
Bug 281246
Draw2d Enhancement - Labeled Polylines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Enhancement to initial patch
patch (text/plain), 9.93 KB, created by
Pascal Gélinas
on 2010-02-18 11:03:34 EST
(
hide
)
Description:
Enhancement to initial patch
Filename:
MIME Type:
Creator:
Pascal Gélinas
Created:
2010-02-18 11:03:34 EST
Size:
9.93 KB
patch
obsolete
>--- src/org/eclipse/draw2d/PolylineLabelDecoration.java 2010-02-18 10:24:22.000000000 -0500 >+++ src/org/eclipse/draw2d/PolylineLabelDecoration.java 2010-02-18 10:57:07.000000000 -0500 >@@ -6,32 +6,40 @@ > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * Manuel Selva - initial API and implementation >+ * Manuel Selva - initial API and implementation >+ * Pascal Gélinas - Enhancement and bug fixes (bug 281246) > *******************************************************************************/ >-package org.eclipse.draw2d; > >-import org.eclipse.swt.graphics.Image; >+package com.nuecho.plugin.robot.editor.callflow.figures; > >+import org.eclipse.draw2d.AbstractBackground; >+import org.eclipse.draw2d.ColorConstants; >+import org.eclipse.draw2d.Graphics; >+import org.eclipse.draw2d.Label; >+import org.eclipse.draw2d.PolylineConnection; >+import org.eclipse.draw2d.RotatableDecoration; > import org.eclipse.draw2d.geometry.Dimension; > import org.eclipse.draw2d.geometry.Point; > import org.eclipse.draw2d.geometry.Rectangle; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; > > /** >- * A decorative label Figure intended to be placed on a {@link PolylineConnection}. >- * >- * @since 3.5 >+ * A decorative label Figure intended to be placed on a >+ * {@link PolylineConnection}. > */ >-public class PolylineLabelDecoration extends Label implements >- RotatableDecoration { >- >+public class PolylineLabelDecoration extends Label implements RotatableDecoration { > private double angle; > private Point location = new Point(); > private Point refPoint = new Point(); >+ private Rectangle boundingBox; >+ private String subStringText; >+ private int heightDiff; > > public PolylineLabelDecoration() { > super(); > } >- >+ > public PolylineLabelDecoration(Image i) { > super(i); > } >@@ -44,8 +52,79 @@ > super(s, i); > } > >+ /** >+ * The bounds are defined (in this case) as the bounding box of the text. >+ */ >+ @Override > public Rectangle getBounds() { > if (bounds == null) { >+ heightDiff = 0; >+ Point topLeft = getGraphicsOrigin(); >+ Point textLocation = getTextLocation(); >+ Dimension textSize = getSubStringTextSize(); >+ double radians = Math.toRadians(angle); >+ >+ translate(topLeft, textLocation.x, radians); >+ >+ Point bottomLeft = topLeft.getCopy(); >+ translate(bottomLeft, textSize.height, radians); >+ >+ Point topRight = topLeft.getCopy(); >+ translate(topRight, textSize.width, radians); >+ >+ Point bottomRight = bottomLeft.getCopy(); >+ translate(bottomRight, textSize.width, radians); >+ >+ // The four points represent a rectangle that contains only the text. However, its coordinate is at an angle >+ // with the absolute coordinate, so it cannot be set as the bounds. Need to compute the bounds by searching >+ // for the leftmost x, rightmost x, highest y and lowest y >+ int xLeft = topLeft.x; >+ int xRight = topLeft.x; >+ int yTop = topLeft.y; >+ int yBottom = topLeft.y; >+ Point[] array = {bottomLeft, topRight, bottomRight }; >+ for (Point point : array) { >+ if (point.x < xLeft) { >+ xLeft = point.x; >+ } else if (point.x > xRight) { >+ xRight = point.x; >+ } >+ >+ // Don't forget that (0,0) is the top left point of the screen! >+ if (point.y < yTop) { >+ yTop = point.y; >+ } else if (point.y > yBottom) { >+ yBottom = point.y; >+ } >+ } >+ Rectangle rectangle = new Rectangle(xLeft, yTop, xRight - xLeft, yBottom - yTop); >+ if (rectangle.height < textSize.height) { >+ heightDiff = textSize.height - rectangle.height; >+ rectangle.height = textSize.height; >+ } >+ // If the rectangle's width is small, then it means that it is nearly vertical. For proper behavior, it must >+ // be at least the textSize's height. >+ if (rectangle.width < textSize.height) { >+ rectangle.width = textSize.height; >+ } >+ bounds = rectangle; >+ } >+ return super.getBounds(); >+ } >+ >+ /** >+ * Translate a point using polar coordinate. >+ */ >+ private void translate(Point pointToTranslate, int radius, double radians) { >+ pointToTranslate.translate((int) (radius * Math.cos(radians)), (int) (radius * Math.sin(radians))); >+ } >+ >+ /** >+ * Find the bounding box that enclose the two reference points ( >+ * {@link #refPoint} and {@link #location}). >+ */ >+ private Rectangle getBoundingBox() { >+ if (boundingBox == null) { > int xDiff = refPoint.x - location.x; > int yDiff = refPoint.y - location.y; > int x, y, width, height; >@@ -63,16 +142,63 @@ > height = -yDiff; > y = refPoint.y; > } >- bounds = new Rectangle(x, y, width, height); >+ boundingBox = new Rectangle(x, y, width, height); > } >- return bounds; >+ return boundingBox; > } > >+ @Override > public void setLocation(Point p) { >+ boundingBox = null; > bounds = null; >+ invalidate(); > location.setLocation(p); > } > >+ @Override >+ public void invalidate() { >+ subStringText = null; >+ super.invalidate(); >+ } >+ >+ /** >+ * A custom calculation of the substring text that takes into account the >+ * angle is necessary. >+ */ >+ @Override >+ public String getSubStringText() { >+ if (subStringText != null) { >+ return subStringText; >+ } >+ >+ String text = getText(); >+ subStringText = text; >+ double radians = Math.toRadians(angle); >+ double maxTextWidth = Math.abs(getBoundingBox().width / Math.cos(radians)); >+ if ((maxTextWidth * Math.sin(radians) > getBoundingBox().height && getBoundingBox().height > 0) >+ || maxTextWidth == 0.0) { >+ maxTextWidth = Math.abs(getBoundingBox().height / Math.sin(radians)); >+ } >+ int widthShrink = (int) (getTextSize().width - maxTextWidth); >+ if (widthShrink <= 0) { >+ return subStringText; >+ } >+ >+ Dimension effectiveSize = getTextSize().getExpanded(-widthShrink, 0); >+ Font currentFont = getFont(); >+ int dotsWidth = getTextUtilities().getTextExtents(getTruncationString(), currentFont).width; >+ >+ if (effectiveSize.width < dotsWidth) { >+ effectiveSize.width = dotsWidth; >+ } >+ >+ int subStringLength = getTextUtilities().getLargestSubstringConfinedTo( text, >+ currentFont, >+ effectiveSize.width - dotsWidth); >+ subStringText = new String(text.substring(0, subStringLength) + getTruncationString()); >+ return subStringText; >+ } >+ > public void setReferencePoint(Point ref) { > Point pt = Point.SINGLETON; > refPoint.setLocation(ref); >@@ -82,14 +208,16 @@ > } > > private void setRotation(double angle) { >+ boundingBox = null; > bounds = null; >+ invalidate(); > this.angle = Math.toDegrees(angle); > } > >+ @Override > protected Point getIconLocation() { >- double linkLength = Math.sqrt(bounds.width * bounds.width >- + bounds.height * bounds.height); >- int y = 0;//-getIconSize().height; >+ Rectangle boundingBox = getBoundingBox(); >+ double linkLength = Math.sqrt(boundingBox.width * boundingBox.width + boundingBox.height * boundingBox.height); > int x; > switch (getTextAlignment()) { > case LEFT: >@@ -104,14 +232,16 @@ > if (x < 0) { > x = 0; > } >- return new Point(x, y); >+ return new Point(x, 0); > } >- >+ >+ @Override > protected Point getTextLocation() { > Dimension textDimension = getTextSize(); >- double linkLength = Math.sqrt((bounds.width + getIconSize().width) * 2 >- + (bounds.height + getIconSize().height) * 2); >- int y = -textDimension.height; >+ double linkLength = Math.sqrt((getBoundingBox().width + getIconSize().width) >+ * 2 >+ + (getBoundingBox().height + getIconSize().height) >+ * 2); > int x; > switch (getTextAlignment()) { > case LEFT: >@@ -123,38 +253,63 @@ > default: > x = (int) (linkLength / 2 - textDimension.width / 2); > } >- if (x < getIconSize().width + 5) { >- x = getIconSize().width + 5; >+ if (x < getIconSize().width + 5) { >+ x = getIconSize().width + 5; > } >- return new Point(x, y); >+ return new Point(x, 0); > } > >- protected void paintFigure(Graphics graphics) { >+ private Point getGraphicsOrigin() { >+ Point origin = getBoundingBox().getTopLeft(); >+ if (angle < 0) { >+ origin.translate(0, getBoundingBox().height); >+ } >+ if (angle < -90.0 || angle > 90.0) { >+ origin.translate(getBoundingBox().width, 0); >+ translate(origin, -getTextSize().height, Math.toRadians(angle) - Math.PI / 2); >+ // FIXME pgelinas: magic number... this is more a workaround than an actual fix. The topLeft corner seems to >+ // be misplaced... >+ translate(origin, -13, Math.toRadians(angle)); >+ } else { >+ translate(origin, -getTextSize().height, Math.toRadians(angle) + Math.PI / 2); >+ } >+ return origin; >+ } > >+ @Override >+ protected void paintFigure(Graphics graphics) { > // Draws the text > graphics.pushState(); > graphics.setClip(graphics.getClip(new Rectangle()).expand(50, 50)); >- graphics.translate(bounds.x, bounds.y); >- if (angle < 0) { >- graphics.translate(0, getBounds().height); >+ graphics.translate(bounds.getTopLeft()); >+ >+ if ((angle > 90 && angle < 180) || (angle < 0 && angle >= -90)) { >+ graphics.translate(0, bounds.height - heightDiff); > } >- graphics.rotate((float) angle); > >- if (isOpaque()) >- graphics.fillRectangle(getBounds()); >- if (getBorder() instanceof AbstractBackground) >- ((AbstractBackground) getBorder()).paintBackground(this, graphics, >- NO_INSETS); >- if (getIcon() != null) >+ if (angle < -90.0 || angle > 90.0) { >+ graphics.rotate((float) angle + 180); >+ } else { >+ graphics.rotate((float) angle); >+ } >+ >+ if (isOpaque()) { >+ graphics.fillRectangle(getBoundingBox()); >+ } >+ if (getBorder() instanceof AbstractBackground) { >+ ((AbstractBackground) getBorder()).paintBackground(this, graphics, NO_INSETS); >+ } >+ if (getIcon() != null) { > graphics.drawImage(getIcon(), getIconLocation()); >+ } > if (!isEnabled()) { > graphics.translate(1, 1); > graphics.setForegroundColor(ColorConstants.buttonLightest); >- graphics.drawText(getSubStringText(), getTextLocation()); >+ graphics.drawText(getSubStringText(), new Point()); > graphics.translate(-1, -1); > graphics.setForegroundColor(ColorConstants.buttonDarker); > } >- graphics.drawText(getSubStringText(), getTextLocation()); >+ graphics.drawText(getSubStringText(), new Point()); > graphics.popState(); > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 281246
:
139889
| 159447 |
227462