From 560afb4885d271edd7e7101ed68898278df2862e Mon Sep 17 00:00:00 2001 From: Oleg_Zheleznov Date: Tue, 27 Sep 2016 12:58:15 +0300 Subject: [PATCH 01/32] Bug 3816 - Setting mark passings doesn't always refresh the panel Change-Id: I0551439d4a07a045196951a9029aa21ac64e3085 --- .../shared/charts/EditMarkPassingsPanel.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java index 115dd8de6f5..52155474cbb 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java @@ -192,10 +192,11 @@ public class EditMarkPassingsPanel extends AbsolutePanel implements Component() { @Override public void onFailure(Throwable caught) { @@ -204,7 +205,7 @@ public class EditMarkPassingsPanel extends AbsolutePanel implements Component(waypoint, time)); } }); } @@ -314,7 +315,21 @@ public class EditMarkPassingsPanel extends AbsolutePanel implements Component markPassing) { clearInfo(); competitor = competitorSelectionModel.getSelectedCompetitors().iterator().next(); // Get current mark passings @@ -326,6 +341,12 @@ public class EditMarkPassingsPanel extends AbsolutePanel implements Component result) { + //Sometimes getCompetitorMarkPassings returns result before actual calculation completed + //In this case we will not get new mark passing date, but we can get this info from GWT side + //If mark Passing was set then add it to received map + if (markPassing != null) { + result.put(markPassing.getA(), markPassing.getB()); + } List> newMarkPassings = new ArrayList<>(); for (WaypointDTO waypoint : currentWaypoints) { int index = currentWaypoints.indexOf(waypoint); From b434c59377ee989b0264e110571d0de67108a1d0 Mon Sep 17 00:00:00 2001 From: Alexander Ries Date: Thu, 29 Sep 2016 17:23:57 +0200 Subject: [PATCH 02/32] Added drawing with rotation of mark type STARTBOAT --- .../shared/racemap/CourseMarkOverlay.java | 78 ++++++--- .../gwt/ui/client/shared/racemap/RaceMap.java | 2 +- .../ui/shared/racemap/MarkVectorGraphics.java | 156 ++++++++---------- .../racemap/StartboatVectorGraphics.java | 17 ++ .../gwt/ui/client/svg/buoys/startboat.svg | 77 +++++++++ 5 files changed, 219 insertions(+), 111 deletions(-) create mode 100644 java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/StartboatVectorGraphics.java create mode 100644 java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/ui/client/svg/buoys/startboat.svg diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java index 268431605c6..217212e97b1 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java @@ -1,6 +1,7 @@ package com.sap.sailing.gwt.ui.client.shared.racemap; import java.util.HashMap; +import java.util.List; import java.util.Map; import com.google.gwt.canvas.dom.client.Context2d; @@ -9,11 +10,14 @@ import com.google.gwt.maps.client.MapWidget; import com.google.gwt.maps.client.base.LatLng; import com.google.gwt.maps.client.base.Point; import com.google.gwt.maps.client.base.Size; +import com.sap.sailing.domain.common.Bearing; import com.sap.sailing.domain.common.MarkType; import com.sap.sailing.domain.common.Position; +import com.sap.sailing.gwt.ui.shared.CoursePositionsDTO; import com.sap.sailing.gwt.ui.shared.MarkDTO; import com.sap.sailing.gwt.ui.shared.racemap.CanvasOverlayV3; import com.sap.sailing.gwt.ui.shared.racemap.MarkVectorGraphics; +import com.sap.sailing.gwt.ui.shared.racemap.StartboatVectorGraphics; import com.sap.sse.common.Util; /** @@ -24,6 +28,8 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { * The course mark to draw */ private final MarkDTO mark; + + private final CoursePositionsDTO coursePositionsDTO; private Position position; @@ -43,18 +49,23 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { private Boolean lastShowBuoyZone; private Boolean lastIsSelected; private Double lastBuoyZoneRadiusInMeter; - - public CourseMarkOverlay(MapWidget map, int zIndex, MarkDTO markDTO, CoordinateSystem coordinateSystem) { + + public CourseMarkOverlay(MapWidget map, int zIndex, MarkDTO markDTO, CoordinateSystem coordinateSystem, CoursePositionsDTO coursePositionsDTO) { super(map, zIndex, coordinateSystem); this.mark = markDTO; + this.coursePositionsDTO = coursePositionsDTO; this.position = markDTO.position; this.buoyZoneRadiusInMeter = 0.0; this.showBuoyZone = false; - markVectorGraphics = new MarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); - markScaleAndSizePerZoomCache = new HashMap>(); + if(markDTO.type != MarkType.STARTBOAT) { + this.markVectorGraphics = new MarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + } else { + this.markVectorGraphics = new StartboatVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + } + this.markScaleAndSizePerZoomCache = new HashMap>(); setCanvasSize(50, 50); } - + @Override protected void draw() { if (mapProjection != null && mark != null && position != null) { @@ -83,6 +94,7 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { Context2d context2d = getCanvas().getContext2d(); // draw the course mark markVectorGraphics.drawMarkToCanvas(context2d, isSelected, canvasWidth, canvasHeight, markSizeScaleFactor); + setRotation(); // draw the buoy zone if (showBuoyZone && isMarkWithBuoyZone(mark) && buoyZoneRadiusInPixel > MIN_BUOYZONE_RADIUS_IN_PX) { CssColor grayTransparentColor = CssColor.make("rgba(37,158,255,0.75)"); @@ -111,6 +123,15 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { } } + private void setRotation() { + if(mark.type == MarkType.STARTBOAT) { + Bearing startlineBearing = getStartlineBearing(); + if(startlineBearing != null) { + setCanvasRotation(startlineBearing.getDegrees()); + } + } + } + private boolean isMarkWithBuoyZone(MarkDTO mark) { return mark.type == null || mark.type == MarkType.BUOY || mark.type == MarkType.STARTBOAT || mark.type == MarkType.FINISHBOAT || mark.type == MarkType.LANDMARK; @@ -129,25 +150,40 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { lastHeight == null || lastHeight != height; } - public Util.Pair getMarkScaleAndSize(Position markPosition) { - double minMarkHeight = 20; - - // the original buoy vector graphics is too small (2.1m x 1.5m) for higher zoom levels - // therefore we scale the buoys with factor 2 by default - double buoyScaleFactor = 2.0; + public Util.Pair getMarkScaleAndSize(Position markPosition) { + double minMarkHeight = 20; - Size markSizeInPixel = calculateBoundingBox(mapProjection, markPosition, - markVectorGraphics.getMarkWidthInMeters() * buoyScaleFactor, markVectorGraphics.getMarkHeightInMeters() * buoyScaleFactor); - - double markHeightInPixel = markSizeInPixel.getHeight(); - if(markHeightInPixel < minMarkHeight) - markHeightInPixel = minMarkHeight; + // the original buoy vector graphics is too small (2.1m x 1.5m) for + // higher zoom levels + // therefore we scale the buoys with factor 2 by default + double buoyScaleFactor = 2.0; - // The coordinates of the canvas drawing methods are based on the 'centimeter' unit (1px = 1cm). - // To calculate the display real mark size the scale factor from canvas units to the real - double markSizeScaleFactor = markHeightInPixel / (markVectorGraphics.getMarkHeightInMeters() * 100); + Size markSizeInPixel = calculateBoundingBox(mapProjection, markPosition, + markVectorGraphics.getMarkWidthInMeters() * buoyScaleFactor, + markVectorGraphics.getMarkHeightInMeters() * buoyScaleFactor); - return new Util.Pair(markSizeScaleFactor, Size.newInstance(markHeightInPixel * 2.0, markHeightInPixel * 2.0)); + double markHeightInPixel = markSizeInPixel.getHeight(); + if (markHeightInPixel < minMarkHeight) + markHeightInPixel = minMarkHeight; + + // The coordinates of the canvas drawing methods are based on the + // 'centimeter' unit (1px = 1cm). + // To calculate the display real mark size the scale factor from + // canvas units to the real + double markSizeScaleFactor = markHeightInPixel / (markVectorGraphics.getMarkHeightInMeters() * 100); + + return new Util.Pair(markSizeScaleFactor, Size.newInstance(markHeightInPixel * 2.0, markHeightInPixel * 2.0)); + } + + private Bearing getStartlineBearing() { + Bearing result = null; + List startlinePositions = coursePositionsDTO.getStartMarkPositions(); + Position startboatPosition = startlinePositions.get(0); + Position pinendPosition = startlinePositions.get(1); + if(startboatPosition != null) { + result = startboatPosition.getBearingGreatCircle(pinendPosition); + } + return result; } private String getTitle() { diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/RaceMap.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/RaceMap.java index 031347fa9ff..8b4db588546 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/RaceMap.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/RaceMap.java @@ -1123,7 +1123,7 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe } CourseMarkOverlay courseMarkOverlay = courseMarkOverlays.get(markDTO.getName()); if (courseMarkOverlay == null) { - courseMarkOverlay = new CourseMarkOverlay(map, RaceMapOverlaysZIndexes.COURSEMARK_ZINDEX, markDTO, coordinateSystem); + courseMarkOverlay = new CourseMarkOverlay(map, RaceMapOverlaysZIndexes.COURSEMARK_ZINDEX, markDTO, coordinateSystem, courseDTO); courseMarkOverlay.setShowBuoyZone(settings.getHelpLinesSettings().isVisible(HelpLineTypes.BUOYZONE)); courseMarkOverlay.setBuoyZoneRadiusInMeter(settings.getBuoyZoneRadiusInMeters()); courseMarkOverlay.setSelected(isSelected); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java index dc9ea7cb03f..7297d018f81 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java @@ -22,8 +22,8 @@ public class MarkVectorGraphics { private static final double doublePi = 2 * Math.PI; - private double anchorPointX = 0.44; - private double anchorPointY = 1.67; + protected double anchorPointX = 0.44; + protected double anchorPointY = 1.67; private final static String DEFAULT_MARK_COLOR = "#f9ac00"; private final static String DEFAULT_MARK_BG_COLOR = "#f0f0f0"; @@ -77,8 +77,8 @@ public class MarkVectorGraphics { drawLandmark(ctx, isSelected, color); break; case STARTBOAT: - drawStartBoat(ctx, isSelected, color); - break; + drawStartboat(ctx, "#000000"); + break; case UMPIREBOAT: case CAMERABOAT: // umpire and camera boats are not course marks -> see TrackedAssetVectorGraphics @@ -519,6 +519,65 @@ public class MarkVectorGraphics { ctx.restore(); ctx.restore(); } + + private void drawStartboat(Context2d ctx, String color) { + ctx.beginPath(); + ctx.setFillStyle(color); + ctx.setStrokeStyle("#FFFFFF"); + ctx.setLineWidth(30.0); + ctx.setLineCap("butt"); + ctx.setLineJoin("miter"); + ctx.setMiterLimit(3.0); + ctx.moveTo(33,30.36); + ctx.quadraticCurveTo(103.47,18.96,194.65,18.55); + ctx.quadraticCurveTo(285.83,18.13,370.62,34.74); + ctx.quadraticCurveTo(455.42,51.34,520.29,87.99); + ctx.quadraticCurveTo(585.16,124.64,603,187.36); + ctx.quadraticCurveTo(584.67,244.84,520.84,277.54); + ctx.quadraticCurveTo(457,310.24,372.97,324.79); + ctx.quadraticCurveTo(288.94,339.34,197.37,339.08); + ctx.quadraticCurveTo(105.8,338.81,32,330.36); + ctx.lineTo(33,30.362205); + ctx.fill(); + ctx.stroke(); + + ctx.setFillStyle("#FFFFFF"); + ctx.beginPath(); + ctx.beginPath(); + ctx.setLineWidth(1.0); + ctx.setLineJoin("miter"); + ctx.setMiterLimit(4.0); + ctx.moveTo(81,78); + ctx.lineTo(349,78); + ctx.lineTo(349,291); + ctx.lineTo(81,291); + ctx.lineTo(81,78); + ctx.fill(); + ctx.stroke(); + + ctx.setFillStyle("#000000"); + ctx.beginPath(); + ctx.moveTo(337,186.36); + ctx.quadraticCurveTo(337,180.56,334.76,175.46); + ctx.quadraticCurveTo(332.52,170.36,328.65,166.56); + ctx.quadraticCurveTo(324.78,162.76,319.59,160.56); + ctx.quadraticCurveTo(314.4,158.36,308.5,158.36); + ctx.quadraticCurveTo(302.6,158.36,297.41,160.56); + ctx.quadraticCurveTo(292.22,162.76,288.35,166.56); + ctx.quadraticCurveTo(284.48,170.36,282.24,175.46); + ctx.quadraticCurveTo(280,180.56,280,186.36); + ctx.quadraticCurveTo(280,192.16,282.24,197.26); + ctx.quadraticCurveTo(284.48,202.36,288.35,206.16); + ctx.quadraticCurveTo(292.22,209.96,297.41,212.16); + ctx.quadraticCurveTo(302.6,214.36,308.5,214.36); + ctx.quadraticCurveTo(314.4,214.36,319.59,212.16); + ctx.quadraticCurveTo(324.78,209.96,328.65,206.16); + ctx.quadraticCurveTo(332.52,202.36,334.76,197.26); + ctx.quadraticCurveTo(337,192.16,337,186.36); + ctx.stroke(); + ctx.fill(); + ctx.beginPath(); + } protected void drawConicalBuoy(Context2d ctx, boolean isSelected, String color) { ctx.setStrokeStyle("rgba(0,0,0,0)"); @@ -593,87 +652,6 @@ public class MarkVectorGraphics { ctx.restore(); } - protected void drawStartBoat(Context2d ctx, boolean isSelected, String color2) { - ctx.setStrokeStyle("rgba(0,0,0,0)"); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - - ctx.beginPath(); - ctx.arc(49.7,12.8,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.7,11.3,3.37,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.6,10.6,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(4.98,0,0,10.8,-205,50.4); - ctx.beginPath(); - ctx.moveTo(50.8,9.84); - ctx.lineTo(48.5,9.84); - ctx.lineTo(48.5,1.44); - ctx.lineTo(50.8,1.9); - ctx.lineTo(50.8,9.84); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.transform(12.5,0,0,12.5,-570,22.2); - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(48.8,3.82); - ctx.lineTo(48.8,-1.32); - ctx.lineTo(57,1.05); - ctx.lineTo(48.8,3.82); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(48.5,4.16); - ctx.lineTo(48.5,-1.65); - ctx.lineTo(57.8,1.03); - ctx.lineTo(48.5,4.16); - ctx.closePath(); - ctx.moveTo(49,-0.994); - ctx.lineTo(49,3.47); - ctx.lineTo(56.2,1.07); - ctx.lineTo(49,-0.994); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - ctx.restore(); - } - protected void drawFinishBoat(Context2d ctx, boolean isSelected, String color2) { ctx.setStrokeStyle("rgba(0,0,0,0)"); @@ -755,12 +733,12 @@ public class MarkVectorGraphics { ctx.restore(); } - public double getMarkHeightInMeters() { - return markHeightInMeters; - } + public double getMarkHeightInMeters() { + return markHeightInMeters; + } public double getMarkWidthInMeters() { - return markWidthInMeters; + return markWidthInMeters; } public String getColor() { diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/StartboatVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/StartboatVectorGraphics.java new file mode 100644 index 00000000000..34889065c8e --- /dev/null +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/StartboatVectorGraphics.java @@ -0,0 +1,17 @@ +package com.sap.sailing.gwt.ui.shared.racemap; + +import com.sap.sailing.domain.common.MarkType; + +public class StartboatVectorGraphics extends MarkVectorGraphics { + + private final static double STARTBOAT_HEIGHT_IN_METERS = 6.2; + private final static double STARTBOAT_WIDTH_IN_METERS = 3.5; + + public StartboatVectorGraphics(MarkType type, String color, String shape, String pattern) { + super(type, color, shape, pattern); + this.anchorPointX = STARTBOAT_HEIGHT_IN_METERS/2; + this.anchorPointY = STARTBOAT_WIDTH_IN_METERS/2; + this.markHeightInMeters = STARTBOAT_HEIGHT_IN_METERS; + this.markWidthInMeters = STARTBOAT_WIDTH_IN_METERS; + } +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/ui/client/svg/buoys/startboat.svg b/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/ui/client/svg/buoys/startboat.svg new file mode 100644 index 00000000000..ebd344fd9f1 --- /dev/null +++ b/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/ui/client/svg/buoys/startboat.svg @@ -0,0 +1,77 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + From 2399e9bc4d32c3c0a14d7c81326d6e2e14fd81eb Mon Sep 17 00:00:00 2001 From: Alexander Tatarinovich Date: Wed, 12 Oct 2016 13:53:25 +0300 Subject: [PATCH 03/32] Bug 3868 - Enable User Management/SAPHeader in Spectator.html Change-Id: Ie47adc066460a9728ab15d6e3556dae0fc5afdd1 --- java/com.sap.sailing.gwt.ui/Spectator.css | 3 +++ .../gwt/ui/spectator/SpectatorEntryPoint.java | 22 ++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/Spectator.css b/java/com.sap.sailing.gwt.ui/Spectator.css index dc81d3c43ff..b3ed005ae22 100644 --- a/java/com.sap.sailing.gwt.ui/Spectator.css +++ b/java/com.sap.sailing.gwt.ui/Spectator.css @@ -23,6 +23,9 @@ top: -1000px; } +html { + font-size: 15px; +} body { background: url(images/spectatorview-bg.png) no-repeat left top #ebebeb; diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/spectator/SpectatorEntryPoint.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/spectator/SpectatorEntryPoint.java index 99188283aae..f0b15fb356e 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/spectator/SpectatorEntryPoint.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/spectator/SpectatorEntryPoint.java @@ -1,5 +1,6 @@ package com.sap.sailing.gwt.ui.spectator; +import com.google.gwt.dom.client.Style.Position; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.user.client.Window; @@ -8,9 +9,9 @@ import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.SimplePanel; +import com.sap.sailing.gwt.common.authentication.FixedSailingAuthentication; +import com.sap.sailing.gwt.common.authentication.SAPSailingHeaderWithAuthentication; import com.sap.sailing.gwt.ui.client.AbstractSailingEntryPoint; -import com.sap.sailing.gwt.ui.client.GlobalNavigationPanel; -import com.sap.sailing.gwt.ui.client.LogoAndTitlePanel; import com.sap.sailing.gwt.ui.client.RegattaRefresher; import com.sap.sailing.gwt.ui.client.shared.panels.SimpleWelcomeWidget; import com.sap.sailing.gwt.ui.client.shared.racemap.RaceMapSettings; @@ -66,12 +67,8 @@ public class SpectatorEntryPoint extends AbstractSailingEntryPoint implements Re && Window.Location.getParameter("embedded").equalsIgnoreCase("true"); if (!embedded) { String title = groupName != null ? groupName : getStringMessages().overview(); - LogoAndTitlePanel logoAndTitlePanel = new LogoAndTitlePanel(title, getStringMessages(), this, getUserService()); - logoAndTitlePanel.addStyleName("LogoAndTitlePanel"); - FlowPanel globalNavigationPanel = new GlobalNavigationPanel(getStringMessages(), true, null, null, /* event */ null, null); - logoAndTitlePanel.add(globalNavigationPanel); - - rootPanel.add(logoAndTitlePanel); + SAPSailingHeaderWithAuthentication header = getHeader(title); + rootPanel.add(header); } else { RootPanel.getBodyElement().getStyle().setPadding(0, Unit.PX); RootPanel.getBodyElement().getStyle().setPaddingTop(20, Unit.PX); @@ -108,6 +105,15 @@ public class SpectatorEntryPoint extends AbstractSailingEntryPoint implements Re fillRegattas(); } + private SAPSailingHeaderWithAuthentication getHeader(String title){ + SAPSailingHeaderWithAuthentication header = new SAPSailingHeaderWithAuthentication(title); + new FixedSailingAuthentication(getUserService(), header.getAuthenticationMenuView()); + header.getElement().getStyle().setPosition(Position.FIXED); + header.getElement().getStyle().setTop(0, Unit.PX); + header.getElement().getStyle().setWidth(100, Unit.PCT); + return header; + } + @Override public void fillRegattas() { From be7564ffb62c5ff684ec777a36914adf616a853b Mon Sep 17 00:00:00 2001 From: Alexander Ries Date: Tue, 18 Oct 2016 16:16:31 +0200 Subject: [PATCH 04/32] Added highlighting to marks of type STARTBOAT and FINISHBOAT --- .../shared/racemap/CourseMarkOverlay.java | 71 ++++++--- .../racemap/BoatMarkVectorGraphics.java | 138 ++++++++++++++++++ .../ui/shared/racemap/MarkVectorGraphics.java | 81 +++++----- .../racemap/StartboatVectorGraphics.java | 17 --- .../buoys/{startboat.svg => boat_mark.svg} | 0 5 files changed, 226 insertions(+), 81 deletions(-) create mode 100644 java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java delete mode 100644 java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/StartboatVectorGraphics.java rename java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/ui/client/svg/buoys/{startboat.svg => boat_mark.svg} (100%) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java index 217212e97b1..864a3ddf68e 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java @@ -1,8 +1,12 @@ package com.sap.sailing.gwt.ui.client.shared.racemap; +import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; import com.google.gwt.canvas.dom.client.Context2d; import com.google.gwt.canvas.dom.client.CssColor; @@ -12,12 +16,14 @@ import com.google.gwt.maps.client.base.Point; import com.google.gwt.maps.client.base.Size; import com.sap.sailing.domain.common.Bearing; import com.sap.sailing.domain.common.MarkType; +import com.sap.sailing.domain.common.PassingInstruction; import com.sap.sailing.domain.common.Position; import com.sap.sailing.gwt.ui.shared.CoursePositionsDTO; import com.sap.sailing.gwt.ui.shared.MarkDTO; +import com.sap.sailing.gwt.ui.shared.WaypointDTO; +import com.sap.sailing.gwt.ui.shared.racemap.BoatMarkVectorGraphics; import com.sap.sailing.gwt.ui.shared.racemap.CanvasOverlayV3; import com.sap.sailing.gwt.ui.shared.racemap.MarkVectorGraphics; -import com.sap.sailing.gwt.ui.shared.racemap.StartboatVectorGraphics; import com.sap.sse.common.Util; /** @@ -57,15 +63,15 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { this.position = markDTO.position; this.buoyZoneRadiusInMeter = 0.0; this.showBuoyZone = false; - if(markDTO.type != MarkType.STARTBOAT) { - this.markVectorGraphics = new MarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + if(markDTO.type == MarkType.STARTBOAT || markDTO.type == MarkType.FINISHBOAT) { + this.markVectorGraphics = new BoatMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); } else { - this.markVectorGraphics = new StartboatVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + this.markVectorGraphics = new MarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); } this.markScaleAndSizePerZoomCache = new HashMap>(); setCanvasSize(50, 50); } - + @Override protected void draw() { if (mapProjection != null && mark != null && position != null) { @@ -123,14 +129,32 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { } } - private void setRotation() { - if(mark.type == MarkType.STARTBOAT) { - Bearing startlineBearing = getStartlineBearing(); - if(startlineBearing != null) { - setCanvasRotation(startlineBearing.getDegrees()); - } - } - } + private void setRotation() { + if (mark.type == MarkType.STARTBOAT || mark.type == MarkType.FINISHBOAT) { + Bearing lineBearing; + List lineMarkPositions = new ArrayList(); + MarkDTO firstMark = null; + MarkDTO secondMark = null; + for (WaypointDTO currentWaypoint : coursePositionsDTO.course.waypoints) { + if (currentWaypoint.passingInstructions == PassingInstruction.Line) { + Iterator marks = currentWaypoint.controlPoint.getMarks().iterator(); + firstMark = marks.next(); + if (marks.hasNext()) { + secondMark = marks.next(); + if (mark.getIdAsString().equals(firstMark.getIdAsString()) + || mark.getIdAsString().equals(secondMark.getIdAsString())) { + lineMarkPositions.add(firstMark.position); + lineMarkPositions.add(secondMark.position); + } + } + } + } + lineBearing = getLineBearing(lineMarkPositions); + if (lineBearing != null) { + setCanvasRotation(lineBearing.getDegrees()); + } + } + } private boolean isMarkWithBuoyZone(MarkDTO mark) { return mark.type == null || mark.type == MarkType.BUOY || mark.type == MarkType.STARTBOAT || @@ -175,16 +199,17 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { return new Util.Pair(markSizeScaleFactor, Size.newInstance(markHeightInPixel * 2.0, markHeightInPixel * 2.0)); } - private Bearing getStartlineBearing() { - Bearing result = null; - List startlinePositions = coursePositionsDTO.getStartMarkPositions(); - Position startboatPosition = startlinePositions.get(0); - Position pinendPosition = startlinePositions.get(1); - if(startboatPosition != null) { - result = startboatPosition.getBearingGreatCircle(pinendPosition); - } - return result; - } + private Bearing getLineBearing(List markPositions) { + Bearing result = null; + if (markPositions.size() > 1) { + Position firstPosition = markPositions.get(0); + Position secondPosition = markPositions.get(1); + if (firstPosition != null) { + result = firstPosition.getBearingGreatCircle(secondPosition); + } + } + return result; + } private String getTitle() { return mark.getName(); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java new file mode 100644 index 00000000000..c2e635d5cf3 --- /dev/null +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java @@ -0,0 +1,138 @@ +package com.sap.sailing.gwt.ui.shared.racemap; + +import com.google.gwt.canvas.dom.client.CanvasGradient; +import com.google.gwt.canvas.dom.client.Context2d; +import com.sap.sailing.domain.common.MarkType; + +public class BoatMarkVectorGraphics extends MarkVectorGraphics { + + private final static double BOAT_MARK_HEIGHT_IN_METERS = 6.2; + private final static double BOAT_MARK_WIDTH_IN_METERS = 3.5; + + public BoatMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { + super(type, color, shape, pattern); + this.anchorPointX = BOAT_MARK_HEIGHT_IN_METERS / 2; + this.anchorPointY = BOAT_MARK_WIDTH_IN_METERS / 2; + this.markHeightInMeters = BOAT_MARK_HEIGHT_IN_METERS; + this.markWidthInMeters = BOAT_MARK_WIDTH_IN_METERS; + } + + @Override + protected void drawMarkSelection(Context2d ctx) { + ctx.save(); + + ctx.scale(3.5, 3.5); + ctx.translate(50, -130); + + CanvasGradient g1 = ctx.createLinearGradient(77.8, 188, 165, 219); + g1.addColorStop(0, "rgba(240, 240, 240, 1)"); + g1.addColorStop(1, "rgba(240, 240, 240, 0)"); + ctx.setFillStyle(g1); + ctx.beginPath(); + ctx.moveTo(170, 181); + ctx.translate(44.000168893718424, 180.79369636814624); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, 0.0016373311430805408, 0.5254904360229328, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-44.000168893718424, -180.79369636814624); + ctx.lineTo(44.2, 181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + CanvasGradient g2 = ctx.createLinearGradient(51, 203, 77.3, 302); + g2.addColorStop(0, "rgba(255, 255, 255, 1)"); + g2.addColorStop(1, "rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g2); + ctx.beginPath(); + ctx.moveTo(107, 290); + ctx.translate(43.79222318749837, 181.0010231680087); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, 1.0452923752792398, 1.5667663411841573, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-43.79222318749837, -181.0010231680087); + ctx.lineTo(44.2, 181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + CanvasGradient g3 = ctx.createLinearGradient(26.8, 197, -46.5, 269); + g3.addColorStop(0, "rgba(255, 255, 255, 1)"); + g3.addColorStop(1, "rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g3); + ctx.beginPath(); + ctx.moveTo(-18.3, 290); + ctx.translate(43.72636289026038, 180.32443158749652); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, 2.0854951576078884, 2.611791628699119, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-43.72636289026038, -180.32443158749652); + ctx.lineTo(44.2, 181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + CanvasGradient g4 = ctx.createLinearGradient(18.7, 172, -76.3, 140); + g4.addColorStop(0, "rgba(255, 255, 255, 1)"); + g4.addColorStop(1, "rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g4); + ctx.beginPath(); + ctx.moveTo(-81.8, 179); + ctx.translate(44.19920011832349, 178.55103503179944); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, 3.1380294320163484, 3.670248678643417, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-44.19920011832349, -178.55103503179944); + ctx.lineTo(44.2, 179); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + CanvasGradient g5 = ctx.createLinearGradient(37.9, 147, 13.6, 58.6); + g5.addColorStop(0, "rgba(255, 255, 255, 1)"); + g5.addColorStop(1, "rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g5); + ctx.beginPath(); + ctx.moveTo(-18.7, 71.8); + ctx.translate(44.160311222571984, 180.99973110315514); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, -2.0931154263055687, -1.5728622903484606, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-44.160311222571984, -180.99973110315514); + ctx.lineTo(44.199999999999996, 181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + CanvasGradient g6 = ctx.createLinearGradient(80.8, 139, 134, 91.9); + g6.addColorStop(0, "rgba(240, 240, 240, 1)"); + g6.addColorStop(1, "rgba(240, 240, 240, 0)"); + ctx.setFillStyle(g6); + ctx.beginPath(); + ctx.moveTo(108, 72.1); + ctx.translate(43.50304481630927, 180.3411325330301); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, -1.0334238189446499, -0.5175711746742696, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-43.50304481630927, -180.3411325330301); + ctx.lineTo(44.2, 181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + ctx.translate(-49.5, 17.2); + ctx.restore(); + } +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java index 7297d018f81..9a67e61fe78 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java @@ -48,47 +48,46 @@ public class MarkVectorGraphics { ctx.restore(); } - protected void drawMark(Context2d ctx, boolean isSelected, String color) { - final MarkType markType = type==null ? MarkType.BUOY : type; - switch(markType) { - case BUOY: - if(isSelected) { - drawMarkSelection(ctx); - } - if(shape != null) { - if(Shape.CYLINDER.name().equalsIgnoreCase(shape) && pattern != null && Pattern.CHECKERED.name().equalsIgnoreCase(pattern)) { - drawBuoyWithFinishFlag(ctx, isSelected, color); - } else if (Shape.CONICAL.name().equalsIgnoreCase(shape)) { - drawConicalBuoy(ctx, isSelected, color); - } else { - drawSimpleBuoy(ctx, isSelected, color); - } - } else { - drawSimpleBuoy(ctx, isSelected, color); - } - break; - case FINISHBOAT: - drawFinishBoat(ctx, isSelected, color); - break; - case LANDMARK: - if(isSelected) { - drawMarkSelection(ctx); - } - drawLandmark(ctx, isSelected, color); - break; - case STARTBOAT: - drawStartboat(ctx, "#000000"); - break; - case UMPIREBOAT: - case CAMERABOAT: - // umpire and camera boats are not course marks -> see TrackedAssetVectorGraphics - break; - default: - break; - } - } + protected void drawMark(Context2d ctx, boolean isSelected, String color) { + final MarkType markType = type == null ? MarkType.BUOY : type; + if (isSelected) { + drawMarkSelection(ctx); + } + switch (markType) { + case BUOY: + if (shape != null) { + if (Shape.CYLINDER.name().equalsIgnoreCase(shape) && pattern != null + && Pattern.CHECKERED.name().equalsIgnoreCase(pattern)) { + drawBuoyWithFinishFlag(ctx, isSelected, color); + } else if (Shape.CONICAL.name().equalsIgnoreCase(shape)) { + drawConicalBuoy(ctx, isSelected, color); + } else { + drawSimpleBuoy(ctx, isSelected, color); + } + } else { + drawSimpleBuoy(ctx, isSelected, color); + } + break; + case FINISHBOAT: + drawBoatmark(ctx, "#000000"); + break; + case LANDMARK: + drawLandmark(ctx, isSelected, color); + break; + case STARTBOAT: + drawBoatmark(ctx, "#000000"); + break; + case UMPIREBOAT: + case CAMERABOAT: + // umpire and camera boats are not course marks -> see + // TrackedAssetVectorGraphics + break; + default: + break; + } + } - private void drawMarkSelection(Context2d ctx) { + protected void drawMarkSelection(Context2d ctx) { ctx.save(); ctx.scale(1.2,1.2); @@ -520,7 +519,7 @@ public class MarkVectorGraphics { ctx.restore(); } - private void drawStartboat(Context2d ctx, String color) { + private void drawBoatmark(Context2d ctx, String color) { ctx.beginPath(); ctx.setFillStyle(color); ctx.setStrokeStyle("#FFFFFF"); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/StartboatVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/StartboatVectorGraphics.java deleted file mode 100644 index 34889065c8e..00000000000 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/StartboatVectorGraphics.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.sap.sailing.gwt.ui.shared.racemap; - -import com.sap.sailing.domain.common.MarkType; - -public class StartboatVectorGraphics extends MarkVectorGraphics { - - private final static double STARTBOAT_HEIGHT_IN_METERS = 6.2; - private final static double STARTBOAT_WIDTH_IN_METERS = 3.5; - - public StartboatVectorGraphics(MarkType type, String color, String shape, String pattern) { - super(type, color, shape, pattern); - this.anchorPointX = STARTBOAT_HEIGHT_IN_METERS/2; - this.anchorPointY = STARTBOAT_WIDTH_IN_METERS/2; - this.markHeightInMeters = STARTBOAT_HEIGHT_IN_METERS; - this.markWidthInMeters = STARTBOAT_WIDTH_IN_METERS; - } -} diff --git a/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/ui/client/svg/buoys/startboat.svg b/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/ui/client/svg/buoys/boat_mark.svg similarity index 100% rename from java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/ui/client/svg/buoys/startboat.svg rename to java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/ui/client/svg/buoys/boat_mark.svg From 85e36c720fd70dfa563be8d6998a225d5fca3366 Mon Sep 17 00:00:00 2001 From: Alexander Tatarinovich Date: Wed, 19 Oct 2016 15:29:57 +0300 Subject: [PATCH 05/32] bug3868: fix padding and overiding hider Change-Id: I41960781ba41ff478d220624f83f348e2c02f69f --- java/com.sap.sailing.gwt.ui/Spectator.css | 2 +- .../com/sap/sailing/gwt/ui/spectator/SpectatorEntryPoint.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/java/com.sap.sailing.gwt.ui/Spectator.css b/java/com.sap.sailing.gwt.ui/Spectator.css index b3ed005ae22..cb03382bfaf 100644 --- a/java/com.sap.sailing.gwt.ui/Spectator.css +++ b/java/com.sap.sailing.gwt.ui/Spectator.css @@ -51,7 +51,7 @@ table td,select,button { .contentOuterPanel { background: #dddcdc; - margin: 0 12px 0 12px; + margin: 0 12px 120px; padding: 12px; } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/spectator/SpectatorEntryPoint.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/spectator/SpectatorEntryPoint.java index f0b15fb356e..bd9a41092ee 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/spectator/SpectatorEntryPoint.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/spectator/SpectatorEntryPoint.java @@ -111,6 +111,7 @@ public class SpectatorEntryPoint extends AbstractSailingEntryPoint implements Re header.getElement().getStyle().setPosition(Position.FIXED); header.getElement().getStyle().setTop(0, Unit.PX); header.getElement().getStyle().setWidth(100, Unit.PCT); + header.getElement().getStyle().setZIndex(100); return header; } From 9dc23c149e3b2117c75e2cddf5bcf7836dbdf581 Mon Sep 17 00:00:00 2001 From: Alexander Ries Date: Thu, 20 Oct 2016 15:36:53 +0200 Subject: [PATCH 06/32] Deleted method for drawing finish boat --- .../ui/shared/racemap/MarkVectorGraphics.java | 81 ------------------- 1 file changed, 81 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java index a7c1519de48..7543ed4e61e 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java @@ -653,87 +653,6 @@ public class MarkVectorGraphics { ctx.restore(); } - protected void drawFinishBoat(Context2d ctx, boolean isSelected, String color2) { - ctx.setStrokeStyle("rgba(0,0,0,0)"); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - - ctx.beginPath(); - ctx.arc(49.7,12.8,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.7,11.3,3.37,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.6,10.6,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(4.98,0,0,10.8,-205,50.4); - ctx.beginPath(); - ctx.moveTo(50.8,9.84); - ctx.lineTo(48.5,9.84); - ctx.lineTo(48.5,1.44); - ctx.lineTo(50.8,1.9); - ctx.lineTo(50.8,9.84); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.transform(12.5,0,0,12.5,-570,22.2); - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(48.8,3.82); - ctx.lineTo(48.8,-1.32); - ctx.lineTo(57,1.05); - ctx.lineTo(48.8,3.82); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(48.5,4.16); - ctx.lineTo(48.5,-1.65); - ctx.lineTo(57.8,1.03); - ctx.lineTo(48.5,4.16); - ctx.closePath(); - ctx.moveTo(49,-0.994); - ctx.lineTo(49,3.47); - ctx.lineTo(56.2,1.07); - ctx.lineTo(49,-0.994); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - ctx.restore(); - } - public Distance getMarkHeight() { return markHeightInMeters; } From b47ef6bfff3a642b36c1aa4540e6b227f59964da Mon Sep 17 00:00:00 2001 From: Alexander Ries Date: Thu, 20 Oct 2016 15:53:57 +0200 Subject: [PATCH 07/32] Refined BoatMarkVectorGraphics scale subclassing for selection drawing --- .../racemap/BoatMarkVectorGraphics.java | 128 +----------------- .../ui/shared/racemap/MarkVectorGraphics.java | 10 +- 2 files changed, 15 insertions(+), 123 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java index dea5e2fd7fa..c9ee7ca5823 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java @@ -1,7 +1,5 @@ package com.sap.sailing.gwt.ui.shared.racemap; -import com.google.gwt.canvas.dom.client.CanvasGradient; -import com.google.gwt.canvas.dom.client.Context2d; import com.sap.sailing.domain.common.Distance; import com.sap.sailing.domain.common.MarkType; import com.sap.sailing.domain.common.impl.MeterDistance; @@ -10,131 +8,19 @@ public class BoatMarkVectorGraphics extends MarkVectorGraphics { private final static Distance BOAT_MARK_HEIGHT_IN_METERS = new MeterDistance(6.2); private final static Distance BOAT_MARK_WIDTH_IN_METERS = new MeterDistance(3.5); + private final static double BOAT_MARK_SELECTION_SCALE = 3.5; + private final static double BOAT_MARK_SELECTION_TRANSLATE_X = -10; + private final static double BOAT_MARK_SELECTION_TRANSLATE_Y = -30; public BoatMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { super(type, color, shape, pattern); this.anchorPointX = BOAT_MARK_HEIGHT_IN_METERS.getMeters() / 2; this.anchorPointY = BOAT_MARK_WIDTH_IN_METERS.getMeters() / 2; + this.markSelectionScaleX = BOAT_MARK_SELECTION_SCALE; + this.markSelectionScaleY = BOAT_MARK_SELECTION_SCALE; + this.markSelectionTranslateX = BOAT_MARK_SELECTION_TRANSLATE_X; + this.markSelectionTranslateY = BOAT_MARK_SELECTION_TRANSLATE_Y; this.markHeightInMeters = BOAT_MARK_HEIGHT_IN_METERS; this.markWidthInMeters = BOAT_MARK_WIDTH_IN_METERS; } - - @Override - protected void drawMarkSelection(Context2d ctx) { - ctx.save(); - - ctx.scale(3.5, 3.5); - ctx.translate(50, -130); - - CanvasGradient g1 = ctx.createLinearGradient(77.8, 188, 165, 219); - g1.addColorStop(0, "rgba(240, 240, 240, 1)"); - g1.addColorStop(1, "rgba(240, 240, 240, 0)"); - ctx.setFillStyle(g1); - ctx.beginPath(); - ctx.moveTo(170, 181); - ctx.translate(44.000168893718424, 180.79369636814624); - ctx.rotate(0); - ctx.scale(1, 1); - ctx.arc(0, 0, 126, 0.0016373311430805408, 0.5254904360229328, false); - ctx.scale(1, 1); - ctx.rotate(0); - ctx.translate(-44.000168893718424, -180.79369636814624); - ctx.lineTo(44.2, 181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - CanvasGradient g2 = ctx.createLinearGradient(51, 203, 77.3, 302); - g2.addColorStop(0, "rgba(255, 255, 255, 1)"); - g2.addColorStop(1, "rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g2); - ctx.beginPath(); - ctx.moveTo(107, 290); - ctx.translate(43.79222318749837, 181.0010231680087); - ctx.rotate(0); - ctx.scale(1, 1); - ctx.arc(0, 0, 126, 1.0452923752792398, 1.5667663411841573, false); - ctx.scale(1, 1); - ctx.rotate(0); - ctx.translate(-43.79222318749837, -181.0010231680087); - ctx.lineTo(44.2, 181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - CanvasGradient g3 = ctx.createLinearGradient(26.8, 197, -46.5, 269); - g3.addColorStop(0, "rgba(255, 255, 255, 1)"); - g3.addColorStop(1, "rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g3); - ctx.beginPath(); - ctx.moveTo(-18.3, 290); - ctx.translate(43.72636289026038, 180.32443158749652); - ctx.rotate(0); - ctx.scale(1, 1); - ctx.arc(0, 0, 126, 2.0854951576078884, 2.611791628699119, false); - ctx.scale(1, 1); - ctx.rotate(0); - ctx.translate(-43.72636289026038, -180.32443158749652); - ctx.lineTo(44.2, 181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - CanvasGradient g4 = ctx.createLinearGradient(18.7, 172, -76.3, 140); - g4.addColorStop(0, "rgba(255, 255, 255, 1)"); - g4.addColorStop(1, "rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g4); - ctx.beginPath(); - ctx.moveTo(-81.8, 179); - ctx.translate(44.19920011832349, 178.55103503179944); - ctx.rotate(0); - ctx.scale(1, 1); - ctx.arc(0, 0, 126, 3.1380294320163484, 3.670248678643417, false); - ctx.scale(1, 1); - ctx.rotate(0); - ctx.translate(-44.19920011832349, -178.55103503179944); - ctx.lineTo(44.2, 179); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - CanvasGradient g5 = ctx.createLinearGradient(37.9, 147, 13.6, 58.6); - g5.addColorStop(0, "rgba(255, 255, 255, 1)"); - g5.addColorStop(1, "rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g5); - ctx.beginPath(); - ctx.moveTo(-18.7, 71.8); - ctx.translate(44.160311222571984, 180.99973110315514); - ctx.rotate(0); - ctx.scale(1, 1); - ctx.arc(0, 0, 126, -2.0931154263055687, -1.5728622903484606, false); - ctx.scale(1, 1); - ctx.rotate(0); - ctx.translate(-44.160311222571984, -180.99973110315514); - ctx.lineTo(44.199999999999996, 181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - CanvasGradient g6 = ctx.createLinearGradient(80.8, 139, 134, 91.9); - g6.addColorStop(0, "rgba(240, 240, 240, 1)"); - g6.addColorStop(1, "rgba(240, 240, 240, 0)"); - ctx.setFillStyle(g6); - ctx.beginPath(); - ctx.moveTo(108, 72.1); - ctx.translate(43.50304481630927, 180.3411325330301); - ctx.rotate(0); - ctx.scale(1, 1); - ctx.arc(0, 0, 126, -1.0334238189446499, -0.5175711746742696, false); - ctx.scale(1, 1); - ctx.rotate(0); - ctx.translate(-43.50304481630927, -180.3411325330301); - ctx.lineTo(44.2, 181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - ctx.translate(-49.5, 17.2); - ctx.restore(); - } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java index 7543ed4e61e..61ef0b6e2ca 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java @@ -27,6 +27,12 @@ public class MarkVectorGraphics { protected double anchorPointX = 0.44; protected double anchorPointY = 1.67; + protected double markSelectionScaleX = 1.2; + protected double markSelectionScaleY = 1.2; + + protected double markSelectionTranslateX = -10; + protected double markSelectionTranslateY = -30; + private final static String DEFAULT_MARK_COLOR = "#f9ac00"; private final static String DEFAULT_MARK_BG_COLOR = "#f0f0f0"; @@ -92,8 +98,8 @@ public class MarkVectorGraphics { protected void drawMarkSelection(Context2d ctx) { ctx.save(); - ctx.scale(1.2,1.2); - ctx.translate(-10,-30); + ctx.scale(markSelectionScaleX, markSelectionScaleY); + ctx.translate(markSelectionTranslateX, markSelectionTranslateY); CanvasGradient g1=ctx.createLinearGradient(77.8,188,165,219); g1.addColorStop(0,"rgba(240, 240, 240, 1)"); From 7683145d0f568f2f6aa3b859acad3da4eaa74e25 Mon Sep 17 00:00:00 2001 From: Stsiapan_Tsybulski Date: Fri, 21 Oct 2016 16:59:44 +0300 Subject: [PATCH 08/32] UI thread is blocked while all calculations will not be finished --- .../domain/test/mock/MockedTrackedRace.java | 5 +++++ .../MarkPassingCalculator.java | 19 ++++++++++++++++++- .../domain/tracking/DynamicTrackedRace.java | 8 ++++++++ .../tracking/impl/DynamicTrackedRaceImpl.java | 10 ++++++++++ .../gwt/ui/test/MockedTrackedRace.java | 5 +++++ .../shared/charts/EditMarkPassingsPanel.java | 18 ++---------------- .../gwt/ui/server/SailingServiceImpl.java | 4 ++-- 7 files changed, 50 insertions(+), 19 deletions(-) diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRace.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRace.java index e0119115587..49dfbf08d37 100644 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRace.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRace.java @@ -1130,4 +1130,9 @@ public class MockedTrackedRace implements DynamicTrackedRace { public Iterable getAttachedRaceLogs() { return Collections.emptySet(); } + + @Override + public NavigableSet getUpdatedMarkPassings(Competitor competitor) { + return null; + } } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java index 32f29af56d5..4a5718ec0df 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java @@ -9,6 +9,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; +import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.logging.Level; import java.util.logging.Logger; @@ -60,6 +61,8 @@ public class MarkPassingCalculator { * started and then terminated again. */ private final Thread listenerThread; + + private Listen listenThread; /** * Synchronized using the {@link #listenerThread} as monitor object. @@ -76,7 +79,8 @@ public class MarkPassingCalculator { finder = new CandidateFinderImpl(race, executor); chooser = new CandidateChooserImpl(race); if (listen) { - listenerThread = new Thread(new Listen(race.getRace().getName()), "MarkPassingCalculator for race " + race.getRace().getName()); + listenThread = new Listen(race.getRace().getName()); + listenerThread = new Thread(listenThread, "MarkPassingCalculator for race " + race.getRace().getName()); } else { listenerThread = null; } @@ -131,6 +135,14 @@ public class MarkPassingCalculator { } } + public void lockListenForRead() { + listenThread.readWriteLock.readLock().lock(); + } + + public void unlockListenForRead() { + listenThread.readWriteLock.readLock().unlock(); + } + /** * Waits until an object is in the queue, then drains it entirely. After that the information is sorted depending on * whether it is a fix, an updated waypoint or an updated fixed markpassing. Finally, if suspended is @@ -142,9 +154,11 @@ public class MarkPassingCalculator { */ private class Listen implements Runnable { private final String raceName; + private final ReentrantReadWriteLock readWriteLock; public Listen(String raceName) { this.raceName = raceName; + readWriteLock = new ReentrantReadWriteLock(); } @Override @@ -167,6 +181,7 @@ public class MarkPassingCalculator { List allNewFixInsertions = new ArrayList<>(); try { allNewFixInsertions.add(listener.getQueue().take()); + readWriteLock.writeLock().lock(); } catch (InterruptedException e) { logger.log(Level.SEVERE, "MarkPassingCalculator for "+raceName+" threw exception " + e.getMessage() + " while waiting for new GPSFixes"); @@ -225,6 +240,8 @@ public class MarkPassingCalculator { } } catch (Exception e) { logger.log(Level.SEVERE, "Error while calculating markpassings for race "+raceName+": " + e.getMessage(), e); + } finally { + readWriteLock.writeLock().unlock(); } } } finally { diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java index d6ffbc50ecb..aa63cb5fe0f 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java @@ -1,5 +1,7 @@ package com.sap.sailing.domain.tracking; +import java.util.NavigableSet; + import com.sap.sailing.domain.abstractlog.race.CompetitorResult; import com.sap.sailing.domain.abstractlog.race.RaceLog; import com.sap.sailing.domain.abstractlog.race.RaceLogFinishPositioningConfirmedEvent; @@ -68,6 +70,12 @@ public interface DynamicTrackedRace extends TrackedRace { boolean recordWind(Wind wind, WindSource windSource, boolean applyFilter); void removeWind(Wind wind, WindSource windSource); + + /** + * Returns competitor's mark passings after all calculations + * @param competitor + */ + NavigableSet getUpdatedMarkPassings(Competitor competitor); /** * The raw, updating feed of a single competitor participating in this race diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java index dc1401183da..caceb53c252 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java @@ -1177,4 +1177,14 @@ DynamicTrackedRace, GPSTrackListener { }); notifyListeners(track); } + + @Override + public NavigableSet getUpdatedMarkPassings(Competitor competitor) { + markPassingCalculator.lockListenForRead(); + try { + return getMarkPassings(competitor); + } finally { + markPassingCalculator.unlockListenForRead(); + } + } } diff --git a/java/com.sap.sailing.gwt.ui.test/src/com/sap/sailing/gwt/ui/test/MockedTrackedRace.java b/java/com.sap.sailing.gwt.ui.test/src/com/sap/sailing/gwt/ui/test/MockedTrackedRace.java index b58478a3a82..70421632ba3 100644 --- a/java/com.sap.sailing.gwt.ui.test/src/com/sap/sailing/gwt/ui/test/MockedTrackedRace.java +++ b/java/com.sap.sailing.gwt.ui.test/src/com/sap/sailing/gwt/ui/test/MockedTrackedRace.java @@ -860,4 +860,9 @@ public class MockedTrackedRace implements DynamicTrackedRace { public Iterable getAttachedRaceLogs() { return Collections.emptySet(); } + + @Override + public NavigableSet getUpdatedMarkPassings(Competitor competitor) { + return null; + } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java index 52155474cbb..23d21e5155b 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java @@ -205,7 +205,7 @@ public class EditMarkPassingsPanel extends AbsolutePanel implements Component(waypoint, time)); + refillList(); } }); } @@ -315,21 +315,13 @@ public class EditMarkPassingsPanel extends AbsolutePanel implements Component markPassing) { + private void refillList() { clearInfo(); competitor = competitorSelectionModel.getSelectedCompetitors().iterator().next(); // Get current mark passings @@ -341,12 +333,6 @@ public class EditMarkPassingsPanel extends AbsolutePanel implements Component result) { - //Sometimes getCompetitorMarkPassings returns result before actual calculation completed - //In this case we will not get new mark passing date, but we can get this info from GWT side - //If mark Passing was set then add it to received map - if (markPassing != null) { - result.put(markPassing.getA(), markPassing.getB()); - } List> newMarkPassings = new ArrayList<>(); for (WaypointDTO waypoint : currentWaypoints) { int index = currentWaypoints.indexOf(waypoint); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java index cdcc7d02788..277a37a6ca9 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java @@ -5806,10 +5806,10 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S @Override public Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO) { Map result = new HashMap<>(); - final TrackedRace trackedRace = getExistingTrackedRace(race); + final DynamicTrackedRace trackedRace = (DynamicTrackedRace) getExistingTrackedRace(race); if (trackedRace != null) { Competitor competitor = getCompetitorByIdAsString(trackedRace.getRace().getCompetitors(), competitorDTO.getIdAsString()); - Set competitorMarkPassings = trackedRace.getMarkPassings(competitor); + Set competitorMarkPassings = trackedRace.getUpdatedMarkPassings(competitor); Iterable waypoints = trackedRace.getRace().getCourse().getWaypoints(); if (competitorMarkPassings != null) { for (MarkPassing markPassing : competitorMarkPassings) { From d7350239cb9f1c6534f6e1e6556df67767a32296 Mon Sep 17 00:00:00 2001 From: Stsiapan_Tsybulski Date: Mon, 24 Oct 2016 12:48:37 +0300 Subject: [PATCH 09/32] Code refactoring --- .../MarkPassingCalculator.java | 23 ++++++++++++------- .../domain/tracking/DynamicTrackedRace.java | 4 ++-- .../tracking/impl/DynamicTrackedRaceImpl.java | 4 ++-- .../sailing/gwt/ui/client/SailingService.java | 3 +++ .../gwt/ui/client/SailingServiceAsync.java | 3 +++ .../shared/charts/EditMarkPassingsPanel.java | 2 +- .../gwt/ui/server/SailingServiceImpl.java | 13 ++++++++++- 7 files changed, 38 insertions(+), 14 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java index 4a5718ec0df..ee0ea5dd310 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java @@ -9,6 +9,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; +import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.logging.Level; import java.util.logging.Logger; @@ -135,12 +136,18 @@ public class MarkPassingCalculator { } } - public void lockListenForRead() { - listenThread.readWriteLock.readLock().lock(); + /** + * It's used for locking the calculation thread for read. You will be blocked if there is a current calculation. + */ + public void lockForRead() { + listenThread.lock.readLock().lock(); } - public void unlockListenForRead() { - listenThread.readWriteLock.readLock().unlock(); + /** + * Unlocks the calculation thread for read. + */ + public void unlockForRead() { + listenThread.lock.readLock().unlock(); } /** @@ -154,11 +161,11 @@ public class MarkPassingCalculator { */ private class Listen implements Runnable { private final String raceName; - private final ReentrantReadWriteLock readWriteLock; + private final ReadWriteLock lock; public Listen(String raceName) { this.raceName = raceName; - readWriteLock = new ReentrantReadWriteLock(); + lock = new ReentrantReadWriteLock(); } @Override @@ -181,7 +188,7 @@ public class MarkPassingCalculator { List allNewFixInsertions = new ArrayList<>(); try { allNewFixInsertions.add(listener.getQueue().take()); - readWriteLock.writeLock().lock(); + lock.writeLock().lock(); } catch (InterruptedException e) { logger.log(Level.SEVERE, "MarkPassingCalculator for "+raceName+" threw exception " + e.getMessage() + " while waiting for new GPSFixes"); @@ -241,7 +248,7 @@ public class MarkPassingCalculator { } catch (Exception e) { logger.log(Level.SEVERE, "Error while calculating markpassings for race "+raceName+": " + e.getMessage(), e); } finally { - readWriteLock.writeLock().unlock(); + lock.writeLock().unlock(); } } } finally { diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java index aa63cb5fe0f..798de2d9960 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java @@ -72,8 +72,8 @@ public interface DynamicTrackedRace extends TrackedRace { void removeWind(Wind wind, WindSource windSource); /** - * Returns competitor's mark passings after all calculations - * @param competitor + * Returns competitor's mark passings after all calculations. The method uses a lock to block the thread until all + * calculations will be finished. */ NavigableSet getUpdatedMarkPassings(Competitor competitor); diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java index caceb53c252..ec3c755ff08 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java @@ -1180,11 +1180,11 @@ DynamicTrackedRace, GPSTrackListener { @Override public NavigableSet getUpdatedMarkPassings(Competitor competitor) { - markPassingCalculator.lockListenForRead(); + markPassingCalculator.lockForRead(); try { return getMarkPassings(competitor); } finally { - markPassingCalculator.unlockListenForRead(); + markPassingCalculator.unlockForRead(); } } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java index 2d11ab067f7..9563b7b3bdf 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java @@ -530,6 +530,9 @@ public interface SailingService extends RemoteService, FileStorageManagementGwtS Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO); + Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, + boolean waitForCalculations); + /** * Obtains fixed mark passings and mark passing suppressions from the race log identified by * leaderboardName, raceColumnDTO and fleet. The result contains diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java index 66e3855174a..c257c7cd74c 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java @@ -695,6 +695,9 @@ public interface SailingServiceAsync extends ServerInfoRetriever, FileStorageMan * the URL pointing to a Manage2Sail JSON document that contains the link to the XRR document */ void getRegattas(String manage2SailJsonUrl, AsyncCallback> asyncCallback); + + void getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, + boolean waitForCalculations, AsyncCallback> callback); void getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, AsyncCallback> callback); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java index 23d21e5155b..57575fd5695 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/EditMarkPassingsPanel.java @@ -325,7 +325,7 @@ public class EditMarkPassingsPanel extends AbsolutePanel implements Component>() { + sailingService.getCompetitorMarkPassings(raceIdentifier, competitor, true, new AsyncCallback>() { @Override public void onFailure(Throwable caught) { errorReporter.reportError(stringMessages.errorTryingToObtainMarkPassing(caught.getMessage())); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java index 277a37a6ca9..e22f8fbcb41 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java @@ -5805,11 +5805,22 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S @Override public Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO) { + return getCompetitorMarkPassings(race, competitorDTO, false); + } + + @Override + public Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, + boolean waitForCalculations) { Map result = new HashMap<>(); final DynamicTrackedRace trackedRace = (DynamicTrackedRace) getExistingTrackedRace(race); if (trackedRace != null) { Competitor competitor = getCompetitorByIdAsString(trackedRace.getRace().getCompetitors(), competitorDTO.getIdAsString()); - Set competitorMarkPassings = trackedRace.getUpdatedMarkPassings(competitor); + Set competitorMarkPassings; + if (waitForCalculations) { + competitorMarkPassings = trackedRace.getUpdatedMarkPassings(competitor); + } else { + competitorMarkPassings = trackedRace.getMarkPassings(competitor); + } Iterable waypoints = trackedRace.getRace().getCourse().getWaypoints(); if (competitorMarkPassings != null) { for (MarkPassing markPassing : competitorMarkPassings) { From 7e0a27f76746ac37a61fe5307042df0400fd2312 Mon Sep 17 00:00:00 2001 From: Stsiapan_Tsybulski Date: Mon, 24 Oct 2016 16:02:50 +0300 Subject: [PATCH 10/32] Method getUpdatedMarkPassings was moved to TrackedRace interface --- .../mock/MockedTrackedRaceWithStartTimeAndRanks.java | 5 +++++ .../sailing/domain/tracking/DynamicTrackedRace.java | 8 -------- .../com/sap/sailing/domain/tracking/TrackedRace.java | 6 ++++++ .../domain/tracking/impl/DynamicTrackedRaceImpl.java | 10 ---------- .../sailing/domain/tracking/impl/TrackedRaceImpl.java | 10 ++++++++++ .../sap/sailing/gwt/ui/server/SailingServiceImpl.java | 2 +- .../sailing/server/masterdata/DummyTrackedRace.java | 5 +++++ 7 files changed, 27 insertions(+), 19 deletions(-) diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRaceWithStartTimeAndRanks.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRaceWithStartTimeAndRanks.java index fefad810f2b..90a7d215fcd 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRaceWithStartTimeAndRanks.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRaceWithStartTimeAndRanks.java @@ -681,4 +681,9 @@ public class MockedTrackedRaceWithStartTimeAndRanks implements TrackedRace { public Iterable getAttachedRaceLogs() { return Collections.emptySet(); } + + @Override + public NavigableSet getUpdatedMarkPassings(Competitor competitor) { + return null; + } } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java index 798de2d9960..d6ffbc50ecb 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/DynamicTrackedRace.java @@ -1,7 +1,5 @@ package com.sap.sailing.domain.tracking; -import java.util.NavigableSet; - import com.sap.sailing.domain.abstractlog.race.CompetitorResult; import com.sap.sailing.domain.abstractlog.race.RaceLog; import com.sap.sailing.domain.abstractlog.race.RaceLogFinishPositioningConfirmedEvent; @@ -70,12 +68,6 @@ public interface DynamicTrackedRace extends TrackedRace { boolean recordWind(Wind wind, WindSource windSource, boolean applyFilter); void removeWind(Wind wind, WindSource windSource); - - /** - * Returns competitor's mark passings after all calculations. The method uses a lock to block the thread until all - * calculations will be finished. - */ - NavigableSet getUpdatedMarkPassings(Competitor competitor); /** * The raw, updating feed of a single competitor participating in this race diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRace.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRace.java index b9f36f9e1aa..650431ab494 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRace.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRace.java @@ -434,6 +434,12 @@ public interface TrackedRace extends Serializable, IsManagedByCache getMarkPassings(Competitor competitor); + + /** + * Returns competitor's mark passings after all calculations. The method uses a lock to block the thread until all + * calculations will be finished. + */ + NavigableSet getUpdatedMarkPassings(Competitor competitor); /** * This obtains the course's read lock before asking for the read lock for the markPassings structure. diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java index ec3c755ff08..dc1401183da 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java @@ -1177,14 +1177,4 @@ DynamicTrackedRace, GPSTrackListener { }); notifyListeners(track); } - - @Override - public NavigableSet getUpdatedMarkPassings(Competitor competitor) { - markPassingCalculator.lockForRead(); - try { - return getMarkPassings(competitor); - } finally { - markPassingCalculator.unlockForRead(); - } - } } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java index da48741957d..3c4264ef233 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java @@ -709,6 +709,16 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl public NavigableSet getMarkPassings(Competitor competitor) { return markPassingsForCompetitor.get(competitor); } + + @Override + public NavigableSet getUpdatedMarkPassings(Competitor competitor) { + markPassingCalculator.lockForRead(); + try { + return getMarkPassings(competitor); + } finally { + markPassingCalculator.unlockForRead(); + } + } protected NavigableSet getMarkPassingsInOrderAsNavigableSet(Waypoint waypoint) { return markPassingsForWaypoint.get(waypoint); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java index e22f8fbcb41..5d463d35864 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java @@ -5812,7 +5812,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S public Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, boolean waitForCalculations) { Map result = new HashMap<>(); - final DynamicTrackedRace trackedRace = (DynamicTrackedRace) getExistingTrackedRace(race); + final TrackedRace trackedRace = getExistingTrackedRace(race); if (trackedRace != null) { Competitor competitor = getCompetitorByIdAsString(trackedRace.getRace().getCompetitors(), competitorDTO.getIdAsString()); Set competitorMarkPassings; diff --git a/java/com.sap.sailing.server/src/com/sap/sailing/server/masterdata/DummyTrackedRace.java b/java/com.sap.sailing.server/src/com/sap/sailing/server/masterdata/DummyTrackedRace.java index c5be8205189..382602687ce 100755 --- a/java/com.sap.sailing.server/src/com/sap/sailing/server/masterdata/DummyTrackedRace.java +++ b/java/com.sap.sailing.server/src/com/sap/sailing/server/masterdata/DummyTrackedRace.java @@ -656,4 +656,9 @@ public class DummyTrackedRace extends TrackedRaceWithWindEssentials { public Iterable getAttachedRaceLogs() { return Collections.emptySet(); } + + @Override + public NavigableSet getUpdatedMarkPassings(Competitor competitor) { + return null; + } } From aced9e701cc04bf264384762be631e1e2d0a2973 Mon Sep 17 00:00:00 2001 From: Stsiapan_Tsybulski Date: Tue, 25 Oct 2016 11:18:59 +0300 Subject: [PATCH 11/32] LockUtil and Named lock classes are used now --- .../MarkPassingCalculator.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java index ee0ea5dd310..3ba5b0d7402 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java @@ -9,8 +9,6 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.logging.Level; import java.util.logging.Logger; @@ -28,6 +26,8 @@ import com.sap.sse.common.Util; import com.sap.sse.common.Util.Pair; import com.sap.sse.common.Util.Triple; import com.sap.sse.common.util.IntHolder; +import com.sap.sse.concurrent.LockUtil; +import com.sap.sse.concurrent.NamedReentrantReadWriteLock; import com.sap.sse.util.ThreadPoolUtil; /** @@ -140,14 +140,14 @@ public class MarkPassingCalculator { * It's used for locking the calculation thread for read. You will be blocked if there is a current calculation. */ public void lockForRead() { - listenThread.lock.readLock().lock(); + listenThread.lockRead(); } /** * Unlocks the calculation thread for read. */ public void unlockForRead() { - listenThread.lock.readLock().unlock(); + listenThread.unlockRead(); } /** @@ -161,11 +161,19 @@ public class MarkPassingCalculator { */ private class Listen implements Runnable { private final String raceName; - private final ReadWriteLock lock; + private final NamedReentrantReadWriteLock lock; public Listen(String raceName) { this.raceName = raceName; - lock = new ReentrantReadWriteLock(); + lock = new NamedReentrantReadWriteLock("lock for calculation thread (" + Listen.class.getSimpleName() + ")", /* fair */ false); + } + + public void lockRead() { + LockUtil.lockForRead(lock); + } + + public void unlockRead() { + LockUtil.unlockAfterRead(lock); } @Override @@ -188,7 +196,7 @@ public class MarkPassingCalculator { List allNewFixInsertions = new ArrayList<>(); try { allNewFixInsertions.add(listener.getQueue().take()); - lock.writeLock().lock(); + LockUtil.lockForWrite(lock); } catch (InterruptedException e) { logger.log(Level.SEVERE, "MarkPassingCalculator for "+raceName+" threw exception " + e.getMessage() + " while waiting for new GPSFixes"); @@ -248,7 +256,7 @@ public class MarkPassingCalculator { } catch (Exception e) { logger.log(Level.SEVERE, "Error while calculating markpassings for race "+raceName+": " + e.getMessage(), e); } finally { - lock.writeLock().unlock(); + LockUtil.unlockAfterWrite(lock); } } } finally { From 833aec46c1d1cc15872d3b068480a552a93b161e Mon Sep 17 00:00:00 2001 From: Stsiapan_Tsybulski Date: Tue, 25 Oct 2016 14:28:57 +0300 Subject: [PATCH 12/32] Javadoc was added --- .../markpassingcalculation/MarkPassingCalculator.java | 8 ++++++-- .../com/sap/sailing/gwt/ui/client/SailingService.java | 6 ++++++ .../sap/sailing/gwt/ui/client/SailingServiceAsync.java | 6 ++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java index 3ba5b0d7402..e99cf81b482 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java @@ -140,14 +140,18 @@ public class MarkPassingCalculator { * It's used for locking the calculation thread for read. You will be blocked if there is a current calculation. */ public void lockForRead() { - listenThread.lockRead(); + if (listenThread != null) { + listenThread.lockRead(); + } } /** * Unlocks the calculation thread for read. */ public void unlockForRead() { - listenThread.unlockRead(); + if (listenThread != null) { + listenThread.unlockRead(); + } } /** diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java index 9563b7b3bdf..4a5571b603b 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java @@ -528,6 +528,12 @@ public interface SailingService extends RemoteService, FileStorageManagementGwtS PolarSheetsXYDiagramData createXYDiagramForBoatClass(String itemText); + /** + * Returns mark passings for the competitor. It doesn't wait for the end of an active calculation which will update + * competitor's mark passings. If you want to wait the end of calculations then call + * {@code SailingService#getCompetitorMarkPassings(RegattaAndRaceIdentifier, CompetitorDTO, boolean)} with true flag + * of waitForCalculations parameter + */ Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO); Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java index c257c7cd74c..5de11d73344 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java @@ -696,6 +696,12 @@ public interface SailingServiceAsync extends ServerInfoRetriever, FileStorageMan */ void getRegattas(String manage2SailJsonUrl, AsyncCallback> asyncCallback); + /** + * Returns mark passings for the competitor. It doesn't wait for the end of an active calculation which will update + * competitor's mark passings. If you want to wait the end of calculations then call + * {@code SailingService#getCompetitorMarkPassings(RegattaAndRaceIdentifier, CompetitorDTO, boolean)} with true flag + * of waitForCalculations parameter + */ void getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, boolean waitForCalculations, AsyncCallback> callback); From 905b382b1b926876a4572a50f8b64ec6d8474b54 Mon Sep 17 00:00:00 2001 From: Stsiapan_Tsybulski Date: Thu, 27 Oct 2016 17:14:05 +0300 Subject: [PATCH 13/32] Javadoc's information was a little bit extended --- .../domain/markpassingcalculation/MarkPassingCalculator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java index e99cf81b482..ed1d2588052 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java @@ -137,7 +137,9 @@ public class MarkPassingCalculator { } /** - * It's used for locking the calculation thread for read. You will be blocked if there is a current calculation. + * It's used for locking the calculation thread for read. You will be blocked if the calculation is in progress. + * Make sure that you unlock the thread with the method {@link MarkPassingCalculator#unlockForRead()} once you don't + * need it any more. */ public void lockForRead() { if (listenThread != null) { From d1dfdaa7684b32efd5db5f012569f61354c8d3e8 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Fri, 28 Oct 2016 09:52:40 +0200 Subject: [PATCH 14/32] removed obsolete unused method from SailingService; enhanced Javadoc Change-Id: I4110ee1704c8ff0a6f6e5cf14fcf9ce0d7627c84 --- .../com/sap/sailing/gwt/ui/client/SailingService.java | 9 ++------- .../sap/sailing/gwt/ui/client/SailingServiceAsync.java | 10 +++------- .../sap/sailing/gwt/ui/server/SailingServiceImpl.java | 8 +------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java index 4a5571b603b..4b17e2bcd66 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java @@ -529,13 +529,8 @@ public interface SailingService extends RemoteService, FileStorageManagementGwtS PolarSheetsXYDiagramData createXYDiagramForBoatClass(String itemText); /** - * Returns mark passings for the competitor. It doesn't wait for the end of an active calculation which will update - * competitor's mark passings. If you want to wait the end of calculations then call - * {@code SailingService#getCompetitorMarkPassings(RegattaAndRaceIdentifier, CompetitorDTO, boolean)} with true flag - * of waitForCalculations parameter - */ - Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO); - + * @see SailingServiceAsync#getCompetitorMarkPassings(RegattaAndRaceIdentifier, CompetitorDTO, boolean, com.google.gwt.user.client.rpc.AsyncCallback) + */ Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, boolean waitForCalculations); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java index 5de11d73344..28533bf2032 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java @@ -697,17 +697,13 @@ public interface SailingServiceAsync extends ServerInfoRetriever, FileStorageMan void getRegattas(String manage2SailJsonUrl, AsyncCallback> asyncCallback); /** - * Returns mark passings for the competitor. It doesn't wait for the end of an active calculation which will update - * competitor's mark passings. If you want to wait the end of calculations then call - * {@code SailingService#getCompetitorMarkPassings(RegattaAndRaceIdentifier, CompetitorDTO, boolean)} with true flag - * of waitForCalculations parameter + * Returns mark passings for the competitor. Using the {@code waitForCalculations} parameter callers can control + * whether to obtain a snapshot immediately of wait for pending updates. Waiting may be desirable, e.g., when having + * submitted a fixed mark passing into a race log which triggers the re-calculations asynchronously. */ void getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, boolean waitForCalculations, AsyncCallback> callback); - void getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, - AsyncCallback> callback); - void getCompetitorRaceLogMarkPassingData(String leaderboardName, String raceColumnName, String fleetName, CompetitorDTO competitor, AsyncCallback> callback); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java index 365a85b5ab7..b4ad85c0c72 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java @@ -5805,13 +5805,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S } @Override - public Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO) { - return getCompetitorMarkPassings(race, competitorDTO, false); - } - - @Override - public Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, - boolean waitForCalculations) { + public Map getCompetitorMarkPassings(RegattaAndRaceIdentifier race, CompetitorDTO competitorDTO, boolean waitForCalculations) { Map result = new HashMap<>(); final TrackedRace trackedRace = getExistingTrackedRace(race); if (trackedRace != null) { From d1fd52301ed26e4def4c2f625e165f8e2f117f84 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Fri, 28 Oct 2016 09:55:18 +0200 Subject: [PATCH 15/32] adjusted locking method names to naming conventions Change-Id: I3d5a1dd86e809de1798ff30403d18835203105b2 --- .../markpassingcalculation/MarkPassingCalculator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java index ed1d2588052..0349bf6a9a3 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java @@ -143,7 +143,7 @@ public class MarkPassingCalculator { */ public void lockForRead() { if (listenThread != null) { - listenThread.lockRead(); + listenThread.lockForRead(); } } @@ -152,7 +152,7 @@ public class MarkPassingCalculator { */ public void unlockForRead() { if (listenThread != null) { - listenThread.unlockRead(); + listenThread.unlockAfterRead(); } } @@ -174,11 +174,11 @@ public class MarkPassingCalculator { lock = new NamedReentrantReadWriteLock("lock for calculation thread (" + Listen.class.getSimpleName() + ")", /* fair */ false); } - public void lockRead() { + public void lockForRead() { LockUtil.lockForRead(lock); } - public void unlockRead() { + public void unlockAfterRead() { LockUtil.unlockAfterRead(lock); } From 08300f7fe4e3b8670fd933fb8682b6b2d65c89ba Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Fri, 28 Oct 2016 10:27:23 +0200 Subject: [PATCH 16/32] made MarkPassingCalculator.listenThread final Change-Id: I3d5f7402b750ffe7d5e5740acc7197328c64fba8 --- .../domain/markpassingcalculation/MarkPassingCalculator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java index 0349bf6a9a3..1f92e7edbea 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java @@ -63,7 +63,7 @@ public class MarkPassingCalculator { */ private final Thread listenerThread; - private Listen listenThread; + private final Listen listenThread; /** * Synchronized using the {@link #listenerThread} as monitor object. @@ -84,6 +84,7 @@ public class MarkPassingCalculator { listenerThread = new Thread(listenThread, "MarkPassingCalculator for race " + race.getRace().getName()); } else { listenerThread = null; + listenThread = null; } Thread t = new Thread(() -> { final Set> tasks = new HashSet<>(); From 3489c9132bc460046a1c6c624058e48919bc43e2 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Fri, 28 Oct 2016 10:32:53 +0200 Subject: [PATCH 17/32] moved write-locking the MarkPassingCalculator.Listen out of the try-block; An InterruptedException would have lead to the lock not having been obtained. Yet, the finally clause would have tried to unlock, leading to non-symmetrical locking behavior which could lead to deadlocks. Change-Id: I2a89d5bb4f9ef5afe6fcf069a29fc2ccafe68ecc --- .../MarkPassingCalculator.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java index 1f92e7edbea..44f9b116a13 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java @@ -63,15 +63,15 @@ public class MarkPassingCalculator { */ private final Thread listenerThread; - private final Listen listenThread; + private final Listen listen; /** * Synchronized using the {@link #listenerThread} as monitor object. */ private boolean listenerThreadStarted; - public MarkPassingCalculator(DynamicTrackedRace race, boolean listen, boolean waitForInitialMarkPassingCalculation) { - if (listen) { + public MarkPassingCalculator(DynamicTrackedRace race, boolean doListen, boolean waitForInitialMarkPassingCalculation) { + if (doListen) { listener = new MarkPassingUpdateListener(race); } else { listener = null; @@ -79,12 +79,12 @@ public class MarkPassingCalculator { this.race = race; finder = new CandidateFinderImpl(race, executor); chooser = new CandidateChooserImpl(race); - if (listen) { - listenThread = new Listen(race.getRace().getName()); - listenerThread = new Thread(listenThread, "MarkPassingCalculator for race " + race.getRace().getName()); + if (doListen) { + listen = new Listen(race.getRace().getName()); + listenerThread = new Thread(listen, "MarkPassingCalculator for race " + race.getRace().getName()); } else { listenerThread = null; - listenThread = null; + listen = null; } Thread t = new Thread(() -> { final Set> tasks = new HashSet<>(); @@ -100,7 +100,7 @@ public class MarkPassingCalculator { } catch (Exception e) { logger.log(Level.SEVERE, "Error trying to compute initial set of mark passings for race "+race.getRace().getName(), e); } - if (listen) { + if (doListen) { listenerThread.setDaemon(true); listenerThread.start(); synchronized (listenerThread) { @@ -140,20 +140,22 @@ public class MarkPassingCalculator { /** * It's used for locking the calculation thread for read. You will be blocked if the calculation is in progress. * Make sure that you unlock the thread with the method {@link MarkPassingCalculator#unlockForRead()} once you don't - * need it any more. + * need it any more, using a {@code finally} clause to ensure unlocking even with abnormal termination. */ public void lockForRead() { - if (listenThread != null) { - listenThread.lockForRead(); + if (listen != null) { + listen.lockForRead(); } } /** * Unlocks the calculation thread for read. + * + * @see #lockForRead */ public void unlockForRead() { - if (listenThread != null) { - listenThread.unlockAfterRead(); + if (listen != null) { + listen.unlockAfterRead(); } } @@ -203,11 +205,11 @@ public class MarkPassingCalculator { List allNewFixInsertions = new ArrayList<>(); try { allNewFixInsertions.add(listener.getQueue().take()); - LockUtil.lockForWrite(lock); } catch (InterruptedException e) { logger.log(Level.SEVERE, "MarkPassingCalculator for "+raceName+" threw exception " + e.getMessage() + " while waiting for new GPSFixes"); } + LockUtil.lockForWrite(lock); listener.getQueue().drainTo(allNewFixInsertions); logger.fine("MPC for "+raceName+" received "+ allNewFixInsertions.size()+" new updates."); for (StorePositionUpdateStrategy fixInsertion : allNewFixInsertions) { From 3e163dd6b255e01d4b1ce2a81875a0449efe7be9 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Fri, 28 Oct 2016 10:41:56 +0200 Subject: [PATCH 18/32] unified getMarkPassings methods on TrackedRace Change-Id: Idd4d82766de52a719dae609f5e89f4ec48733fd5 --- .../sailing/domain/test/mock/MockedTrackedRace.java | 2 +- .../mock/MockedTrackedRaceWithStartTimeAndRanks.java | 2 +- .../MarkPassingCalculator.java | 7 +++++++ .../com/sap/sailing/domain/tracking/TrackedRace.java | 12 +++++++++--- .../domain/tracking/impl/TrackedRaceImpl.java | 12 ++++++++---- .../sap/sailing/gwt/ui/test/MockedTrackedRace.java | 2 +- .../sailing/gwt/ui/server/SailingServiceImpl.java | 2 +- .../sailing/server/masterdata/DummyTrackedRace.java | 2 +- 8 files changed, 29 insertions(+), 12 deletions(-) diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRace.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRace.java index 44f0fd3fde5..23b7ebb5e21 100644 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRace.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRace.java @@ -1129,7 +1129,7 @@ public class MockedTrackedRace implements DynamicTrackedRace { } @Override - public NavigableSet getUpdatedMarkPassings(Competitor competitor) { + public NavigableSet getMarkPassings(Competitor competitor, boolean waitForLatestUpdates) { return null; } diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRaceWithStartTimeAndRanks.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRaceWithStartTimeAndRanks.java index 75ccf497f77..9f596ddc595 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRaceWithStartTimeAndRanks.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRaceWithStartTimeAndRanks.java @@ -683,7 +683,7 @@ public class MockedTrackedRaceWithStartTimeAndRanks implements TrackedRace { } @Override - public NavigableSet getUpdatedMarkPassings(Competitor competitor) { + public NavigableSet getMarkPassings(Competitor competitor, boolean waitForLatestUpdates) { return null; } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java index 44f9b116a13..8539ef86d47 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/MarkPassingCalculator.java @@ -170,6 +170,13 @@ public class MarkPassingCalculator { */ private class Listen implements Runnable { private final String raceName; + + /** + * The write lock is being held by the thread running this {@link Runnable} after successfully having + * waited for the next update to be pushed to the {@link MarkPassingUpdateListener#getQueue() queue}, + * before draining the queue starts and until the processing of all events from the queue has completed. + * This way, trying to obtain the read lock will block until all pending updates have been processed. + */ private final NamedReentrantReadWriteLock lock; public Listen(String raceName) { diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRace.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRace.java index b21d9c3d34d..c9f4e7ec66d 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRace.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/TrackedRace.java @@ -45,6 +45,7 @@ import com.sap.sailing.domain.common.racelog.RacingProcedureType; import com.sap.sailing.domain.common.tracking.GPSFix; import com.sap.sailing.domain.common.tracking.GPSFixMoving; import com.sap.sailing.domain.common.tracking.SensorFix; +import com.sap.sailing.domain.markpassingcalculation.MarkPassingCalculator; import com.sap.sailing.domain.polars.NotEnoughDataHasBeenAddedException; import com.sap.sailing.domain.polars.PolarDataService; import com.sap.sailing.domain.racelog.tracking.GPSFixStore; @@ -437,10 +438,15 @@ public interface TrackedRace extends Serializable, IsManagedByCache getMarkPassings(Competitor competitor); /** - * Returns competitor's mark passings after all calculations. The method uses a lock to block the thread until all - * calculations will be finished. + * Returns competitor's mark passings. + * + * @param waitForLatestUpdates + * if any mark passing updates are pending because some calculations are currently going on and updates + * haven't all been processed yet then the call will block until these updates have been processed in + * case this parameter is set to {@code true}. For this the method uses a lock on the + * {@link MarkPassingCalculator }to block the thread until all calculations will be finished. */ - NavigableSet getUpdatedMarkPassings(Competitor competitor); + NavigableSet getMarkPassings(Competitor competitor, boolean waitForLatestUpdates); /** * This obtains the course's read lock before asking for the read lock for the markPassings structure. diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java index 76b06a6698e..4e7e50ed680 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java @@ -707,16 +707,20 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl @Override public NavigableSet getMarkPassings(Competitor competitor) { - return markPassingsForCompetitor.get(competitor); + return getMarkPassings(competitor, /* waitForLatestUpdates */ false); } @Override - public NavigableSet getUpdatedMarkPassings(Competitor competitor) { - markPassingCalculator.lockForRead(); + public NavigableSet getMarkPassings(Competitor competitor, boolean waitForLatestUpdates) { + if (waitForLatestUpdates && markPassingCalculator != null) { + markPassingCalculator.lockForRead(); + } try { return getMarkPassings(competitor); } finally { - markPassingCalculator.unlockForRead(); + if (waitForLatestUpdates && markPassingCalculator != null) { + markPassingCalculator.unlockForRead(); + } } } diff --git a/java/com.sap.sailing.gwt.ui.test/src/com/sap/sailing/gwt/ui/test/MockedTrackedRace.java b/java/com.sap.sailing.gwt.ui.test/src/com/sap/sailing/gwt/ui/test/MockedTrackedRace.java index d4687fc0db7..c948deb2535 100644 --- a/java/com.sap.sailing.gwt.ui.test/src/com/sap/sailing/gwt/ui/test/MockedTrackedRace.java +++ b/java/com.sap.sailing.gwt.ui.test/src/com/sap/sailing/gwt/ui/test/MockedTrackedRace.java @@ -862,7 +862,7 @@ public class MockedTrackedRace implements DynamicTrackedRace { } @Override - public NavigableSet getUpdatedMarkPassings(Competitor competitor) { + public NavigableSet getMarkPassings(Competitor competitor, boolean waitForLatestUpdates) { return null; } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java index b4ad85c0c72..b1d47eaef5c 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java @@ -5812,7 +5812,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S Competitor competitor = getCompetitorByIdAsString(trackedRace.getRace().getCompetitors(), competitorDTO.getIdAsString()); Set competitorMarkPassings; if (waitForCalculations) { - competitorMarkPassings = trackedRace.getUpdatedMarkPassings(competitor); + competitorMarkPassings = trackedRace.getMarkPassings(competitor, /* waitForLatestUpdates */ true); } else { competitorMarkPassings = trackedRace.getMarkPassings(competitor); } diff --git a/java/com.sap.sailing.server/src/com/sap/sailing/server/masterdata/DummyTrackedRace.java b/java/com.sap.sailing.server/src/com/sap/sailing/server/masterdata/DummyTrackedRace.java index c29bfd74f27..4bed05fb47a 100755 --- a/java/com.sap.sailing.server/src/com/sap/sailing/server/masterdata/DummyTrackedRace.java +++ b/java/com.sap.sailing.server/src/com/sap/sailing/server/masterdata/DummyTrackedRace.java @@ -664,7 +664,7 @@ public class DummyTrackedRace extends TrackedRaceWithWindEssentials { } @Override - public NavigableSet getUpdatedMarkPassings(Competitor competitor) { + public NavigableSet getMarkPassings(Competitor competitor, boolean waitForLatestUpdates) { return null; } From f7ed68aa3830a70b0990bc408799b9f00ac35938 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Fri, 28 Oct 2016 10:42:39 +0200 Subject: [PATCH 19/32] use harmonization of TrackedRace.getMarkPassings in SailingServiceImpl Change-Id: I52adbb6d7e77ea57c65c99aa912f394e7c64a6f2 --- .../com/sap/sailing/gwt/ui/server/SailingServiceImpl.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java index b1d47eaef5c..c9af96ba985 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java @@ -5811,11 +5811,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S if (trackedRace != null) { Competitor competitor = getCompetitorByIdAsString(trackedRace.getRace().getCompetitors(), competitorDTO.getIdAsString()); Set competitorMarkPassings; - if (waitForCalculations) { - competitorMarkPassings = trackedRace.getMarkPassings(competitor, /* waitForLatestUpdates */ true); - } else { - competitorMarkPassings = trackedRace.getMarkPassings(competitor); - } + competitorMarkPassings = trackedRace.getMarkPassings(competitor, waitForCalculations); Iterable waypoints = trackedRace.getRace().getCourse().getWaypoints(); if (competitorMarkPassings != null) { for (MarkPassing markPassing : competitorMarkPassings) { From fb40ccf6b5c2eb187d41c9eebaaa262785db51f2 Mon Sep 17 00:00:00 2001 From: Stsiapan_Tsybulski Date: Mon, 31 Oct 2016 09:40:00 +0300 Subject: [PATCH 20/32] Stackoverflow issue was fixed --- .../com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java index 4e7e50ed680..2d40b49208c 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java @@ -716,7 +716,7 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl markPassingCalculator.lockForRead(); } try { - return getMarkPassings(competitor); + return markPassingsForCompetitor.get(competitor); } finally { if (waitForLatestUpdates && markPassingCalculator != null) { markPassingCalculator.unlockForRead(); From 4f8bded03bb8dbc02f59530f4fd75bf2503d9f8a Mon Sep 17 00:00:00 2001 From: Alexander Tatarinovich Date: Tue, 1 Nov 2016 12:07:31 +0300 Subject: [PATCH 21/32] bug3868: fix size fleet markers and padding Change-Id: Ia8aa130c0162663823944ba3e8bc5714ea058310 --- java/com.sap.sailing.gwt.ui/Spectator.css | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/Spectator.css b/java/com.sap.sailing.gwt.ui/Spectator.css index cb03382bfaf..3e27b7f6304 100644 --- a/java/com.sap.sailing.gwt.ui/Spectator.css +++ b/java/com.sap.sailing.gwt.ui/Spectator.css @@ -162,6 +162,7 @@ input.magnifier { .mainPanel { width: 100%; margin-left: 13px; + margin-bottom: 120px; } .leaderboardGroupPanel-GroupName { @@ -209,8 +210,8 @@ input.magnifier { padding: 5px; display: block; float: left; - width: 8px; - height: 8px; + width: 18px; + height: 18px; border-radius: 4px; -moz-border-radius: 4px; -webkit-border-radius: 4px; From b5e528c370122b78ed920440a69da8ca742c3cec Mon Sep 17 00:00:00 2001 From: Alexander Ries Date: Tue, 1 Nov 2016 23:42:51 +0100 Subject: [PATCH 22/32] Implemented factory pattern for mark vector graphics --- .../shared/racemap/CourseMarkOverlay.java | 11 +- .../racemap/AbstractMarkVectorGraphics.java | 191 +++++ .../racemap/BoatMarkVectorGraphics.java | 72 +- .../racemap/BuoyMarkVectorGraphics.java | 349 +++++++++ .../racemap/LandMarkVectorGraphics.java | 77 ++ .../ui/shared/racemap/MarkVectorGraphics.java | 680 +----------------- .../racemap/MarkVectorGraphicsFactory.java | 29 + 7 files changed, 722 insertions(+), 687 deletions(-) create mode 100644 java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java create mode 100644 java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BuoyMarkVectorGraphics.java create mode 100644 java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/LandMarkVectorGraphics.java create mode 100644 java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java index c604ae8e306..980a9dd1ab5 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java @@ -21,9 +21,9 @@ import com.sap.sailing.domain.common.impl.MeterDistance; import com.sap.sailing.gwt.ui.shared.CoursePositionsDTO; import com.sap.sailing.gwt.ui.shared.MarkDTO; import com.sap.sailing.gwt.ui.shared.WaypointDTO; -import com.sap.sailing.gwt.ui.shared.racemap.BoatMarkVectorGraphics; import com.sap.sailing.gwt.ui.shared.racemap.CanvasOverlayV3; import com.sap.sailing.gwt.ui.shared.racemap.MarkVectorGraphics; +import com.sap.sailing.gwt.ui.shared.racemap.MarkVectorGraphicsFactory; import com.sap.sse.common.Util; /** @@ -55,6 +55,8 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { private Boolean lastShowBuoyZone; private Boolean lastIsSelected; private Distance lastBuoyZoneRadius; + + private MarkVectorGraphicsFactory markVectorGraphicsFactory; public CourseMarkOverlay(MapWidget map, int zIndex, MarkDTO markDTO, CoordinateSystem coordinateSystem, CoursePositionsDTO coursePositionsDTO) { super(map, zIndex, coordinateSystem); @@ -63,12 +65,9 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { this.position = markDTO.position; this.buoyZoneRadius = new MeterDistance(0.0); this.showBuoyZone = false; - if(markDTO.type == MarkType.STARTBOAT || markDTO.type == MarkType.FINISHBOAT) { - this.markVectorGraphics = new BoatMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); - } else { - this.markVectorGraphics = new MarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); - } this.markScaleAndSizePerZoomCache = new HashMap>(); + this.markVectorGraphicsFactory = new MarkVectorGraphicsFactory(); + this.markVectorGraphics = markVectorGraphicsFactory.getMarkVectorGraphics(markDTO.type, markDTO); setCanvasSize(50, 50); } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java new file mode 100644 index 00000000000..0c3df0a52ac --- /dev/null +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java @@ -0,0 +1,191 @@ +package com.sap.sailing.gwt.ui.shared.racemap; + +import com.google.gwt.canvas.dom.client.CanvasGradient; +import com.google.gwt.canvas.dom.client.Context2d; +import com.sap.sailing.domain.common.Distance; +import com.sap.sailing.domain.common.MarkType; +import com.sap.sailing.domain.common.impl.MeterDistance; + +/** + * A class for course mark graphics based on SVG graphics drawn to a HTML5 canvas + * The SVG files for the drawing can be found in the package com.sap.sailing.gwt.ui.svg.buoys + * A general description how to convert SVG files to 'drawing commands' can be found at http://wiki.sapsailing.com/wiki/howto/development/boatgraphicssvg + * @author Frank + * + */ +public abstract class AbstractMarkVectorGraphics implements MarkVectorGraphics { + protected Distance markHeightInMeters; + protected Distance markWidthInMeters; + + protected final String color; + protected final String shape; + protected final String pattern; + protected final MarkType type; + + protected static final double doublePi = 2 * Math.PI; + + protected double anchorPointX = 0.44; + protected double anchorPointY = 1.67; + + protected final static String DEFAULT_MARK_COLOR = "#f9ac00"; + protected final static String DEFAULT_MARK_BG_COLOR = "#f0f0f0"; + + public AbstractMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { + this.type = type; + this.color = color; + this.shape = shape; + this.pattern = pattern; + this.markHeightInMeters = new MeterDistance(2.1); + this.markWidthInMeters = new MeterDistance(1.5); + } + + public void drawMarkToCanvas(Context2d ctx, boolean isSelected, double width, double height, double scaleFactor) { + ctx.save(); + ctx.clearRect(0, 0, width, height); + ctx.translate(width / 2.0, height / 2.0); + ctx.scale(scaleFactor, scaleFactor); + ctx.translate(-anchorPointX * 100,- anchorPointY * 100); + String markColor = color != null ? color : DEFAULT_MARK_COLOR; + drawMark(ctx, isSelected, markColor); + ctx.restore(); + } + + public Distance getMarkHeight() { + return markHeightInMeters; + } + + public Distance getMarkWidth() { + return markWidthInMeters; + } + + protected void drawMark(Context2d ctx, boolean isSelected, String color) { + if (isSelected) { + drawMarkSelection(ctx); + } + this.drawMarkBody(ctx, isSelected, color); + } + + protected void drawMarkSelection(Context2d ctx) { + ctx.save(); + + this.setUpScaleAndTranslateForMarkSelection(ctx); + + CanvasGradient g1=ctx.createLinearGradient(77.8,188,165,219); + g1.addColorStop(0,"rgba(240, 240, 240, 1)"); + g1.addColorStop(1,"rgba(240, 240, 240, 0)"); + ctx.setFillStyle(g1); + ctx.beginPath(); + ctx.moveTo(170,181); + ctx.translate(44.000168893718424,180.79369636814624); + ctx.rotate(0); + ctx.scale(1,1); + ctx.arc(0,0,126,0.0016373311430805408,0.5254904360229328,false); + ctx.scale(1,1); + ctx.rotate(0); + ctx.translate(-44.000168893718424,-180.79369636814624); + ctx.lineTo(44.2,181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + CanvasGradient g2=ctx.createLinearGradient(51,203,77.3,302); + g2.addColorStop(0,"rgba(255, 255, 255, 1)"); + g2.addColorStop(1,"rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g2); + ctx.beginPath(); + ctx.moveTo(107,290); + ctx.translate(43.79222318749837,181.0010231680087); + ctx.rotate(0); + ctx.scale(1,1); + ctx.arc(0,0,126,1.0452923752792398,1.5667663411841573,false); + ctx.scale(1,1); + ctx.rotate(0); + ctx.translate(-43.79222318749837,-181.0010231680087); + ctx.lineTo(44.2,181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + CanvasGradient g3=ctx.createLinearGradient(26.8,197,-46.5,269); + g3.addColorStop(0,"rgba(255, 255, 255, 1)"); + g3.addColorStop(1,"rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g3); + ctx.beginPath(); + ctx.moveTo(-18.3,290); + ctx.translate(43.72636289026038,180.32443158749652); + ctx.rotate(0); + ctx.scale(1,1); + ctx.arc(0,0,126,2.0854951576078884,2.611791628699119,false); + ctx.scale(1,1); + ctx.rotate(0); + ctx.translate(-43.72636289026038,-180.32443158749652); + ctx.lineTo(44.2,181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + CanvasGradient g4=ctx.createLinearGradient(18.7,172,-76.3,140); + g4.addColorStop(0,"rgba(255, 255, 255, 1)"); + g4.addColorStop(1,"rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g4); + ctx.beginPath(); + ctx.moveTo(-81.8,179); + ctx.translate(44.19920011832349,178.55103503179944); + ctx.rotate(0); + ctx.scale(1,1); + ctx.arc(0,0,126,3.1380294320163484,3.670248678643417,false); + ctx.scale(1,1); + ctx.rotate(0); + ctx.translate(-44.19920011832349,-178.55103503179944); + ctx.lineTo(44.2,179); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + CanvasGradient g5=ctx.createLinearGradient(37.9,147,13.6,58.6); + g5.addColorStop(0,"rgba(255, 255, 255, 1)"); + g5.addColorStop(1,"rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g5); + ctx.beginPath(); + ctx.moveTo(-18.7,71.8); + ctx.translate(44.160311222571984,180.99973110315514); + ctx.rotate(0); + ctx.scale(1,1); + ctx.arc(0,0,126,-2.0931154263055687,-1.5728622903484606,false); + ctx.scale(1,1); + ctx.rotate(0); + ctx.translate(-44.160311222571984,-180.99973110315514); + ctx.lineTo(44.199999999999996,181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + CanvasGradient g6=ctx.createLinearGradient(80.8,139,134,91.9); + g6.addColorStop(0,"rgba(240, 240, 240, 1)"); + g6.addColorStop(1,"rgba(240, 240, 240, 0)"); + ctx.setFillStyle(g6); + ctx.beginPath(); + ctx.moveTo(108,72.1); + ctx.translate(43.50304481630927,180.3411325330301); + ctx.rotate(0); + ctx.scale(1,1); + ctx.arc(0,0,126,-1.0334238189446499,-0.5175711746742696,false); + ctx.scale(1,1); + ctx.rotate(0); + ctx.translate(-43.50304481630927,-180.3411325330301); + ctx.lineTo(44.2,181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + ctx.translate(-49.5,17.2); + ctx.restore(); + } + + protected void setUpScaleAndTranslateForMarkSelection(Context2d ctx) { + ctx.scale(1.2,1.2); + ctx.translate(-10,-30); + } + + protected abstract void drawMarkBody(Context2d ctx, boolean isSelected, String color); +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java index c9ee7ca5823..ca11b033594 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java @@ -1,10 +1,11 @@ package com.sap.sailing.gwt.ui.shared.racemap; +import com.google.gwt.canvas.dom.client.Context2d; import com.sap.sailing.domain.common.Distance; import com.sap.sailing.domain.common.MarkType; import com.sap.sailing.domain.common.impl.MeterDistance; -public class BoatMarkVectorGraphics extends MarkVectorGraphics { +public class BoatMarkVectorGraphics extends AbstractMarkVectorGraphics { private final static Distance BOAT_MARK_HEIGHT_IN_METERS = new MeterDistance(6.2); private final static Distance BOAT_MARK_WIDTH_IN_METERS = new MeterDistance(3.5); @@ -16,11 +17,72 @@ public class BoatMarkVectorGraphics extends MarkVectorGraphics { super(type, color, shape, pattern); this.anchorPointX = BOAT_MARK_HEIGHT_IN_METERS.getMeters() / 2; this.anchorPointY = BOAT_MARK_WIDTH_IN_METERS.getMeters() / 2; - this.markSelectionScaleX = BOAT_MARK_SELECTION_SCALE; - this.markSelectionScaleY = BOAT_MARK_SELECTION_SCALE; - this.markSelectionTranslateX = BOAT_MARK_SELECTION_TRANSLATE_X; - this.markSelectionTranslateY = BOAT_MARK_SELECTION_TRANSLATE_Y; this.markHeightInMeters = BOAT_MARK_HEIGHT_IN_METERS; this.markWidthInMeters = BOAT_MARK_WIDTH_IN_METERS; } + + protected void setUpScaleAndTranslateForMarkSelection(Context2d ctx) { + ctx.scale(BOAT_MARK_SELECTION_SCALE, BOAT_MARK_SELECTION_SCALE); + ctx.translate(BOAT_MARK_SELECTION_TRANSLATE_X, BOAT_MARK_SELECTION_TRANSLATE_Y); + } + + @Override + protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { + ctx.beginPath(); + ctx.setFillStyle("#000000"); + ctx.setStrokeStyle("#FFFFFF"); + ctx.setLineWidth(30.0); + ctx.setLineCap("butt"); + ctx.setLineJoin("miter"); + ctx.setMiterLimit(3.0); + ctx.moveTo(33,30.36); + ctx.quadraticCurveTo(103.47,18.96,194.65,18.55); + ctx.quadraticCurveTo(285.83,18.13,370.62,34.74); + ctx.quadraticCurveTo(455.42,51.34,520.29,87.99); + ctx.quadraticCurveTo(585.16,124.64,603,187.36); + ctx.quadraticCurveTo(584.67,244.84,520.84,277.54); + ctx.quadraticCurveTo(457,310.24,372.97,324.79); + ctx.quadraticCurveTo(288.94,339.34,197.37,339.08); + ctx.quadraticCurveTo(105.8,338.81,32,330.36); + ctx.lineTo(33,30.362205); + ctx.fill(); + ctx.stroke(); + + ctx.setFillStyle("#FFFFFF"); + ctx.beginPath(); + ctx.beginPath(); + ctx.setLineWidth(1.0); + ctx.setLineJoin("miter"); + ctx.setMiterLimit(4.0); + ctx.moveTo(81,78); + ctx.lineTo(349,78); + ctx.lineTo(349,291); + ctx.lineTo(81,291); + ctx.lineTo(81,78); + ctx.fill(); + ctx.stroke(); + + ctx.setFillStyle("#000000"); + ctx.beginPath(); + ctx.moveTo(337,186.36); + ctx.quadraticCurveTo(337,180.56,334.76,175.46); + ctx.quadraticCurveTo(332.52,170.36,328.65,166.56); + ctx.quadraticCurveTo(324.78,162.76,319.59,160.56); + ctx.quadraticCurveTo(314.4,158.36,308.5,158.36); + ctx.quadraticCurveTo(302.6,158.36,297.41,160.56); + ctx.quadraticCurveTo(292.22,162.76,288.35,166.56); + ctx.quadraticCurveTo(284.48,170.36,282.24,175.46); + ctx.quadraticCurveTo(280,180.56,280,186.36); + ctx.quadraticCurveTo(280,192.16,282.24,197.26); + ctx.quadraticCurveTo(284.48,202.36,288.35,206.16); + ctx.quadraticCurveTo(292.22,209.96,297.41,212.16); + ctx.quadraticCurveTo(302.6,214.36,308.5,214.36); + ctx.quadraticCurveTo(314.4,214.36,319.59,212.16); + ctx.quadraticCurveTo(324.78,209.96,328.65,206.16); + ctx.quadraticCurveTo(332.52,202.36,334.76,197.26); + ctx.quadraticCurveTo(337,192.16,337,186.36); + ctx.stroke(); + ctx.fill(); + ctx.beginPath(); + } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BuoyMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BuoyMarkVectorGraphics.java new file mode 100644 index 00000000000..ca9cd756777 --- /dev/null +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BuoyMarkVectorGraphics.java @@ -0,0 +1,349 @@ +package com.sap.sailing.gwt.ui.shared.racemap; + +import com.google.gwt.canvas.dom.client.Context2d; +import com.sap.sailing.domain.common.MarkType; + +public class BuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implements MarkVectorGraphics { + + public BuoyMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { + super(type, color, shape, pattern); + } + + @Override + protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { + if (shape != null) { + if (Shape.CYLINDER.name().equalsIgnoreCase(shape) && pattern != null + && Pattern.CHECKERED.name().equalsIgnoreCase(pattern)) { + drawBuoyWithFinishFlag(ctx, isSelected, color); + } else if (Shape.CONICAL.name().equalsIgnoreCase(shape)) { + drawConicalBuoy(ctx, isSelected, color); + } else { + drawSimpleBuoy(ctx, isSelected, color); + } + } else { + drawSimpleBuoy(ctx, isSelected, color); + } + } + + void drawSimpleBuoy(Context2d ctx, boolean isSelected, String color) { + ctx.setStrokeStyle("rgba(0,0,0,0)"); + + ctx.save(); + ctx.setFillStyle(color); + ctx.transform(12.5,0,0,12.5,-578,22.2); + + ctx.beginPath(); + ctx.arc(49.7,12.8,2.66,0,doublePi,false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.beginPath(); + ctx.arc(49.7,11.3,3.37,0,doublePi,false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.beginPath(); + ctx.arc(49.6,10.6,2.66,0,doublePi,false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.transform(4.98,0,0,10.8,-205,50.4); + ctx.beginPath(); + ctx.moveTo(50.8,9.84); + ctx.lineTo(48.5,9.84); + ctx.lineTo(48.5,1.44); + ctx.lineTo(50.8,1.9); + ctx.lineTo(50.8,9.84); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.transform(12.5,0,0,12.5,-570,22.2); + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(48.8,3.82); + ctx.lineTo(48.8,-1.32); + ctx.lineTo(57,1.05); + ctx.lineTo(48.8,3.82); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(48.5,4.16); + ctx.lineTo(48.5,-1.65); + ctx.lineTo(57.8,1.03); + ctx.lineTo(48.5,4.16); + ctx.closePath(); + ctx.moveTo(49,-0.994); + ctx.lineTo(49,3.47); + ctx.lineTo(56.2,1.07); + ctx.lineTo(49,-0.994); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + ctx.restore(); + } + + private void drawBuoyWithFinishFlag(Context2d ctx, boolean isSelected, String color) { + ctx.setStrokeStyle("rgba(0,0,0,0)"); + + ctx.save(); + ctx.setFillStyle(color); + ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.beginPath(); + ctx.arc(49.7,12.8,2.66,0,doublePi,false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.beginPath(); + ctx.arc(49.7,11.3,3.37,0,doublePi,false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.beginPath(); + ctx.arc(49.6,10.6,2.66,0,doublePi,false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.transform(4.98,0,0,10.8,-205,50.4); + ctx.beginPath(); + ctx.moveTo(50.8,9.84); + ctx.lineTo(48.5,9.84); + ctx.lineTo(48.5,1.44); + ctx.lineTo(50.8,1.9); + ctx.lineTo(50.8,9.84); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(36.9,-0.5); + ctx.lineTo(141.9,-0.5); + ctx.quadraticCurveTo(141.9,-0.5,141.9,-0.5); + ctx.lineTo(141.9,71.2); + ctx.quadraticCurveTo(141.9,71.2,141.9,71.2); + ctx.lineTo(36.9,71.2); + ctx.quadraticCurveTo(36.9,71.2,36.9,71.2); + ctx.lineTo(36.9,-0.5); + ctx.quadraticCurveTo(36.9,-0.5,36.9,-0.5); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(46,4.04); + ctx.lineTo(76.3,4.04); + ctx.quadraticCurveTo(76.3,4.04,76.3,4.04); + ctx.lineTo(76.3,34.34); + ctx.quadraticCurveTo(76.3,34.34,76.3,34.34); + ctx.lineTo(46,34.34); + ctx.quadraticCurveTo(46,34.34,46,34.34); + ctx.lineTo(46,4.04); + ctx.quadraticCurveTo(46,4.04,46,4.04); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(46.1,34.3); + ctx.lineTo(76.4,34.3); + ctx.quadraticCurveTo(76.4,34.3,76.4,34.3); + ctx.lineTo(76.4,64.6); + ctx.quadraticCurveTo(76.4,64.6,76.4,64.6); + ctx.lineTo(46.1,64.6); + ctx.quadraticCurveTo(46.1,64.6,46.1,64.6); + ctx.lineTo(46.1,34.3); + ctx.quadraticCurveTo(46.1,34.3,46.1,34.3); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(76,3.95); + ctx.lineTo(106.3,3.95); + ctx.quadraticCurveTo(106.3,3.95,106.3,3.95); + ctx.lineTo(106.3,34.25); + ctx.quadraticCurveTo(106.3,34.25,106.3,34.25); + ctx.lineTo(76,34.25); + ctx.quadraticCurveTo(76,34.25,76,34.25); + ctx.lineTo(76,3.95); + ctx.quadraticCurveTo(76,3.95,76,3.95); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(76.1,34.2); + ctx.lineTo(106.4,34.2); + ctx.quadraticCurveTo(106.4,34.2,106.4,34.2); + ctx.lineTo(106.4,64.5); + ctx.quadraticCurveTo(106.4,64.5,106.4,64.5); + ctx.lineTo(76.1,64.5); + ctx.quadraticCurveTo(76.1,64.5,76.1,64.5); + ctx.lineTo(76.1,34.2); + ctx.quadraticCurveTo(76.1,34.2,76.1,34.2); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(106,3.96); + ctx.lineTo(136.3,3.96); + ctx.quadraticCurveTo(136.3,3.96,136.3,3.96); + ctx.lineTo(136.3,34.26); + ctx.quadraticCurveTo(136.3,34.26,136.3,34.26); + ctx.lineTo(106,34.26); + ctx.quadraticCurveTo(106,34.26,106,34.26); + ctx.lineTo(106,3.96); + ctx.quadraticCurveTo(106,3.96,106,3.96); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(106,34.3); + ctx.lineTo(136.3,34.3); + ctx.quadraticCurveTo(136.3,34.3,136.3,34.3); + ctx.lineTo(136.3,64.6); + ctx.quadraticCurveTo(136.3,64.6,136.3,64.6); + ctx.lineTo(106,64.6); + ctx.quadraticCurveTo(106,64.6,106,64.6); + ctx.lineTo(106,34.3); + ctx.quadraticCurveTo(106,34.3,106,34.3); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + ctx.restore(); + } + + private void drawConicalBuoy(Context2d ctx, boolean isSelected, String color) { + ctx.setStrokeStyle("rgba(0,0,0,0)"); + + ctx.save(); + ctx.setFillStyle(color); + ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.beginPath(); + ctx.arc(49.7,12.8,2.66,0,doublePi,false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.beginPath(); + ctx.arc(49.7,11.3,3.37,0,doublePi,false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.beginPath(); + ctx.arc(49.6,10.6,2.66,0,doublePi,false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(36.9,98); + ctx.lineTo(47.5,98); + ctx.quadraticCurveTo(47.5,98,47.5,98); + ctx.lineTo(47.5,154.5); + ctx.quadraticCurveTo(47.5,154.5,47.5,154.5); + ctx.lineTo(36.9,154.5); + ctx.quadraticCurveTo(36.9,154.5,36.9,154.5); + ctx.lineTo(36.9,98); + ctx.quadraticCurveTo(36.9,98,36.9,98); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(43.6,0.372); + ctx.lineTo(87.3,102); + ctx.lineTo(-0.714,102); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(43.6,14.7); + ctx.lineTo(78.5,96.6); + ctx.lineTo(8.07,96.6); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + } +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/LandMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/LandMarkVectorGraphics.java new file mode 100644 index 00000000000..44a7fe10402 --- /dev/null +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/LandMarkVectorGraphics.java @@ -0,0 +1,77 @@ +package com.sap.sailing.gwt.ui.shared.racemap; + +import com.google.gwt.canvas.dom.client.Context2d; +import com.sap.sailing.domain.common.MarkType; + +public class LandMarkVectorGraphics extends AbstractMarkVectorGraphics implements MarkVectorGraphics { + + public LandMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { + super(type, color, shape, pattern); + } + + @Override + protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { + ctx.setStrokeStyle("rgba(0,0,0,0)"); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.transform(4.98,0,0,10.8,-205,50.4); + ctx.beginPath(); + ctx.moveTo(50.8,9.84); + ctx.lineTo(48.5,9.84); + ctx.lineTo(48.5,1.44); + ctx.lineTo(50.8,1.9); + ctx.lineTo(50.8,9.84); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.transform(12.5,0,0,12.5,-570,22.2); + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(48.8,3.82); + ctx.lineTo(48.8,-1.32); + ctx.lineTo(57,1.05); + ctx.lineTo(48.8,3.82); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(48.5,4.16); + ctx.lineTo(48.5,-1.65); + ctx.lineTo(57.8,1.03); + ctx.lineTo(48.5,4.16); + ctx.closePath(); + ctx.moveTo(49,-0.994); + ctx.lineTo(49,3.47); + ctx.lineTo(56.2,1.07); + ctx.lineTo(49,-0.994); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(83.9,209); + ctx.bezierCurveTo(83.9,209,68.6,183,43.0,183); + ctx.bezierCurveTo(12.3,183,7.1,209,7.1,209); + ctx.lineTo(7.1,157); + ctx.lineTo(83.9,157); + ctx.lineTo(83.9,209); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + ctx.restore(); + } +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java index 61ef0b6e2ca..bff8dea7ed9 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java @@ -1,685 +1,13 @@ package com.sap.sailing.gwt.ui.shared.racemap; -import com.google.gwt.canvas.dom.client.CanvasGradient; import com.google.gwt.canvas.dom.client.Context2d; import com.sap.sailing.domain.common.Distance; -import com.sap.sailing.domain.common.MarkType; -import com.sap.sailing.domain.common.impl.MeterDistance; -/** - * A class for course mark graphics based on SVG graphics drawn to a HTML5 canvas - * The SVG files for the drawing can be found in the package com.sap.sailing.gwt.ui.svg.buoys - * A general description how to convert SVG files to 'drawing commands' can be found at http://wiki.sapsailing.com/wiki/howto/development/boatgraphicssvg - * @author Frank - * - */ -public class MarkVectorGraphics { - protected Distance markHeightInMeters; - protected Distance markWidthInMeters; - - private final String color; - private final String shape; - private final String pattern; - private final MarkType type; - - private static final double doublePi = 2 * Math.PI; +public interface MarkVectorGraphics { - protected double anchorPointX = 0.44; - protected double anchorPointY = 1.67; - - protected double markSelectionScaleX = 1.2; - protected double markSelectionScaleY = 1.2; - - protected double markSelectionTranslateX = -10; - protected double markSelectionTranslateY = -30; - - private final static String DEFAULT_MARK_COLOR = "#f9ac00"; - private final static String DEFAULT_MARK_BG_COLOR = "#f0f0f0"; + public void drawMarkToCanvas(Context2d ctx, boolean isSelected, double width, double height, double scaleFactor); - public MarkVectorGraphics(MarkType type, String color, String shape, String pattern) { - this.type = type; - this.color = color; - this.shape = shape; - this.pattern = pattern; - this.markHeightInMeters = new MeterDistance(2.1); - this.markWidthInMeters = new MeterDistance(1.5); - } - - public void drawMarkToCanvas(Context2d ctx, boolean isSelected, double width, double height, double scaleFactor) { - ctx.save(); - ctx.clearRect(0, 0, width, height); - ctx.translate(width / 2.0, height / 2.0); - ctx.scale(scaleFactor, scaleFactor); - ctx.translate(-anchorPointX * 100,- anchorPointY * 100); - String markColor = color != null ? color : DEFAULT_MARK_COLOR; - drawMark(ctx, isSelected, markColor); - ctx.restore(); - } + public Distance getMarkHeight(); - protected void drawMark(Context2d ctx, boolean isSelected, String color) { - final MarkType markType = type == null ? MarkType.BUOY : type; - if (isSelected) { - drawMarkSelection(ctx); - } - switch (markType) { - case BUOY: - if (shape != null) { - if (Shape.CYLINDER.name().equalsIgnoreCase(shape) && pattern != null - && Pattern.CHECKERED.name().equalsIgnoreCase(pattern)) { - drawBuoyWithFinishFlag(ctx, isSelected, color); - } else if (Shape.CONICAL.name().equalsIgnoreCase(shape)) { - drawConicalBuoy(ctx, isSelected, color); - } else { - drawSimpleBuoy(ctx, isSelected, color); - } - } else { - drawSimpleBuoy(ctx, isSelected, color); - } - break; - case FINISHBOAT: - drawBoatmark(ctx, "#000000"); - break; - case LANDMARK: - drawLandmark(ctx, isSelected, color); - break; - case STARTBOAT: - drawBoatmark(ctx, "#000000"); - break; - case UMPIREBOAT: - case CAMERABOAT: - // umpire and camera boats are not course marks -> see - // TrackedAssetVectorGraphics - break; - default: - break; - } - } - - protected void drawMarkSelection(Context2d ctx) { - ctx.save(); - - ctx.scale(markSelectionScaleX, markSelectionScaleY); - ctx.translate(markSelectionTranslateX, markSelectionTranslateY); - - CanvasGradient g1=ctx.createLinearGradient(77.8,188,165,219); - g1.addColorStop(0,"rgba(240, 240, 240, 1)"); - g1.addColorStop(1,"rgba(240, 240, 240, 0)"); - ctx.setFillStyle(g1); - ctx.beginPath(); - ctx.moveTo(170,181); - ctx.translate(44.000168893718424,180.79369636814624); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,0.0016373311430805408,0.5254904360229328,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-44.000168893718424,-180.79369636814624); - ctx.lineTo(44.2,181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - CanvasGradient g2=ctx.createLinearGradient(51,203,77.3,302); - g2.addColorStop(0,"rgba(255, 255, 255, 1)"); - g2.addColorStop(1,"rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g2); - ctx.beginPath(); - ctx.moveTo(107,290); - ctx.translate(43.79222318749837,181.0010231680087); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,1.0452923752792398,1.5667663411841573,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-43.79222318749837,-181.0010231680087); - ctx.lineTo(44.2,181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - CanvasGradient g3=ctx.createLinearGradient(26.8,197,-46.5,269); - g3.addColorStop(0,"rgba(255, 255, 255, 1)"); - g3.addColorStop(1,"rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g3); - ctx.beginPath(); - ctx.moveTo(-18.3,290); - ctx.translate(43.72636289026038,180.32443158749652); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,2.0854951576078884,2.611791628699119,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-43.72636289026038,-180.32443158749652); - ctx.lineTo(44.2,181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - CanvasGradient g4=ctx.createLinearGradient(18.7,172,-76.3,140); - g4.addColorStop(0,"rgba(255, 255, 255, 1)"); - g4.addColorStop(1,"rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g4); - ctx.beginPath(); - ctx.moveTo(-81.8,179); - ctx.translate(44.19920011832349,178.55103503179944); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,3.1380294320163484,3.670248678643417,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-44.19920011832349,-178.55103503179944); - ctx.lineTo(44.2,179); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - CanvasGradient g5=ctx.createLinearGradient(37.9,147,13.6,58.6); - g5.addColorStop(0,"rgba(255, 255, 255, 1)"); - g5.addColorStop(1,"rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g5); - ctx.beginPath(); - ctx.moveTo(-18.7,71.8); - ctx.translate(44.160311222571984,180.99973110315514); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,-2.0931154263055687,-1.5728622903484606,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-44.160311222571984,-180.99973110315514); - ctx.lineTo(44.199999999999996,181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - CanvasGradient g6=ctx.createLinearGradient(80.8,139,134,91.9); - g6.addColorStop(0,"rgba(240, 240, 240, 1)"); - g6.addColorStop(1,"rgba(240, 240, 240, 0)"); - ctx.setFillStyle(g6); - ctx.beginPath(); - ctx.moveTo(108,72.1); - ctx.translate(43.50304481630927,180.3411325330301); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,-1.0334238189446499,-0.5175711746742696,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-43.50304481630927,-180.3411325330301); - ctx.lineTo(44.2,181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - - ctx.translate(-49.5,17.2); - ctx.restore(); - } - - void drawSimpleBuoy(Context2d ctx, boolean isSelected, String color) { - ctx.setStrokeStyle("rgba(0,0,0,0)"); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - - ctx.beginPath(); - ctx.arc(49.7,12.8,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.7,11.3,3.37,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.6,10.6,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(4.98,0,0,10.8,-205,50.4); - ctx.beginPath(); - ctx.moveTo(50.8,9.84); - ctx.lineTo(48.5,9.84); - ctx.lineTo(48.5,1.44); - ctx.lineTo(50.8,1.9); - ctx.lineTo(50.8,9.84); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.transform(12.5,0,0,12.5,-570,22.2); - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(48.8,3.82); - ctx.lineTo(48.8,-1.32); - ctx.lineTo(57,1.05); - ctx.lineTo(48.8,3.82); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(48.5,4.16); - ctx.lineTo(48.5,-1.65); - ctx.lineTo(57.8,1.03); - ctx.lineTo(48.5,4.16); - ctx.closePath(); - ctx.moveTo(49,-0.994); - ctx.lineTo(49,3.47); - ctx.lineTo(56.2,1.07); - ctx.lineTo(49,-0.994); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - ctx.restore(); - } - - protected void drawBuoyWithFinishFlag(Context2d ctx, boolean isSelected, String color) { - ctx.setStrokeStyle("rgba(0,0,0,0)"); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.7,12.8,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.7,11.3,3.37,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.6,10.6,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(4.98,0,0,10.8,-205,50.4); - ctx.beginPath(); - ctx.moveTo(50.8,9.84); - ctx.lineTo(48.5,9.84); - ctx.lineTo(48.5,1.44); - ctx.lineTo(50.8,1.9); - ctx.lineTo(50.8,9.84); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(36.9,-0.5); - ctx.lineTo(141.9,-0.5); - ctx.quadraticCurveTo(141.9,-0.5,141.9,-0.5); - ctx.lineTo(141.9,71.2); - ctx.quadraticCurveTo(141.9,71.2,141.9,71.2); - ctx.lineTo(36.9,71.2); - ctx.quadraticCurveTo(36.9,71.2,36.9,71.2); - ctx.lineTo(36.9,-0.5); - ctx.quadraticCurveTo(36.9,-0.5,36.9,-0.5); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(46,4.04); - ctx.lineTo(76.3,4.04); - ctx.quadraticCurveTo(76.3,4.04,76.3,4.04); - ctx.lineTo(76.3,34.34); - ctx.quadraticCurveTo(76.3,34.34,76.3,34.34); - ctx.lineTo(46,34.34); - ctx.quadraticCurveTo(46,34.34,46,34.34); - ctx.lineTo(46,4.04); - ctx.quadraticCurveTo(46,4.04,46,4.04); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(46.1,34.3); - ctx.lineTo(76.4,34.3); - ctx.quadraticCurveTo(76.4,34.3,76.4,34.3); - ctx.lineTo(76.4,64.6); - ctx.quadraticCurveTo(76.4,64.6,76.4,64.6); - ctx.lineTo(46.1,64.6); - ctx.quadraticCurveTo(46.1,64.6,46.1,64.6); - ctx.lineTo(46.1,34.3); - ctx.quadraticCurveTo(46.1,34.3,46.1,34.3); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(76,3.95); - ctx.lineTo(106.3,3.95); - ctx.quadraticCurveTo(106.3,3.95,106.3,3.95); - ctx.lineTo(106.3,34.25); - ctx.quadraticCurveTo(106.3,34.25,106.3,34.25); - ctx.lineTo(76,34.25); - ctx.quadraticCurveTo(76,34.25,76,34.25); - ctx.lineTo(76,3.95); - ctx.quadraticCurveTo(76,3.95,76,3.95); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(76.1,34.2); - ctx.lineTo(106.4,34.2); - ctx.quadraticCurveTo(106.4,34.2,106.4,34.2); - ctx.lineTo(106.4,64.5); - ctx.quadraticCurveTo(106.4,64.5,106.4,64.5); - ctx.lineTo(76.1,64.5); - ctx.quadraticCurveTo(76.1,64.5,76.1,64.5); - ctx.lineTo(76.1,34.2); - ctx.quadraticCurveTo(76.1,34.2,76.1,34.2); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(106,3.96); - ctx.lineTo(136.3,3.96); - ctx.quadraticCurveTo(136.3,3.96,136.3,3.96); - ctx.lineTo(136.3,34.26); - ctx.quadraticCurveTo(136.3,34.26,136.3,34.26); - ctx.lineTo(106,34.26); - ctx.quadraticCurveTo(106,34.26,106,34.26); - ctx.lineTo(106,3.96); - ctx.quadraticCurveTo(106,3.96,106,3.96); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(106,34.3); - ctx.lineTo(136.3,34.3); - ctx.quadraticCurveTo(136.3,34.3,136.3,34.3); - ctx.lineTo(136.3,64.6); - ctx.quadraticCurveTo(136.3,64.6,136.3,64.6); - ctx.lineTo(106,64.6); - ctx.quadraticCurveTo(106,64.6,106,64.6); - ctx.lineTo(106,34.3); - ctx.quadraticCurveTo(106,34.3,106,34.3); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - ctx.restore(); - } - - protected void drawLandmark(Context2d ctx, boolean isSelected, String color) { - ctx.setStrokeStyle("rgba(0,0,0,0)"); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(4.98,0,0,10.8,-205,50.4); - ctx.beginPath(); - ctx.moveTo(50.8,9.84); - ctx.lineTo(48.5,9.84); - ctx.lineTo(48.5,1.44); - ctx.lineTo(50.8,1.9); - ctx.lineTo(50.8,9.84); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.transform(12.5,0,0,12.5,-570,22.2); - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(48.8,3.82); - ctx.lineTo(48.8,-1.32); - ctx.lineTo(57,1.05); - ctx.lineTo(48.8,3.82); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(48.5,4.16); - ctx.lineTo(48.5,-1.65); - ctx.lineTo(57.8,1.03); - ctx.lineTo(48.5,4.16); - ctx.closePath(); - ctx.moveTo(49,-0.994); - ctx.lineTo(49,3.47); - ctx.lineTo(56.2,1.07); - ctx.lineTo(49,-0.994); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(83.9,209); - ctx.bezierCurveTo(83.9,209,68.6,183,43.0,183); - ctx.bezierCurveTo(12.3,183,7.1,209,7.1,209); - ctx.lineTo(7.1,157); - ctx.lineTo(83.9,157); - ctx.lineTo(83.9,209); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - ctx.restore(); - } - - private void drawBoatmark(Context2d ctx, String color) { - ctx.beginPath(); - ctx.setFillStyle(color); - ctx.setStrokeStyle("#FFFFFF"); - ctx.setLineWidth(30.0); - ctx.setLineCap("butt"); - ctx.setLineJoin("miter"); - ctx.setMiterLimit(3.0); - ctx.moveTo(33,30.36); - ctx.quadraticCurveTo(103.47,18.96,194.65,18.55); - ctx.quadraticCurveTo(285.83,18.13,370.62,34.74); - ctx.quadraticCurveTo(455.42,51.34,520.29,87.99); - ctx.quadraticCurveTo(585.16,124.64,603,187.36); - ctx.quadraticCurveTo(584.67,244.84,520.84,277.54); - ctx.quadraticCurveTo(457,310.24,372.97,324.79); - ctx.quadraticCurveTo(288.94,339.34,197.37,339.08); - ctx.quadraticCurveTo(105.8,338.81,32,330.36); - ctx.lineTo(33,30.362205); - ctx.fill(); - ctx.stroke(); - - ctx.setFillStyle("#FFFFFF"); - ctx.beginPath(); - ctx.beginPath(); - ctx.setLineWidth(1.0); - ctx.setLineJoin("miter"); - ctx.setMiterLimit(4.0); - ctx.moveTo(81,78); - ctx.lineTo(349,78); - ctx.lineTo(349,291); - ctx.lineTo(81,291); - ctx.lineTo(81,78); - ctx.fill(); - ctx.stroke(); - - ctx.setFillStyle("#000000"); - ctx.beginPath(); - ctx.moveTo(337,186.36); - ctx.quadraticCurveTo(337,180.56,334.76,175.46); - ctx.quadraticCurveTo(332.52,170.36,328.65,166.56); - ctx.quadraticCurveTo(324.78,162.76,319.59,160.56); - ctx.quadraticCurveTo(314.4,158.36,308.5,158.36); - ctx.quadraticCurveTo(302.6,158.36,297.41,160.56); - ctx.quadraticCurveTo(292.22,162.76,288.35,166.56); - ctx.quadraticCurveTo(284.48,170.36,282.24,175.46); - ctx.quadraticCurveTo(280,180.56,280,186.36); - ctx.quadraticCurveTo(280,192.16,282.24,197.26); - ctx.quadraticCurveTo(284.48,202.36,288.35,206.16); - ctx.quadraticCurveTo(292.22,209.96,297.41,212.16); - ctx.quadraticCurveTo(302.6,214.36,308.5,214.36); - ctx.quadraticCurveTo(314.4,214.36,319.59,212.16); - ctx.quadraticCurveTo(324.78,209.96,328.65,206.16); - ctx.quadraticCurveTo(332.52,202.36,334.76,197.26); - ctx.quadraticCurveTo(337,192.16,337,186.36); - ctx.stroke(); - ctx.fill(); - ctx.beginPath(); - } - - protected void drawConicalBuoy(Context2d ctx, boolean isSelected, String color) { - ctx.setStrokeStyle("rgba(0,0,0,0)"); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.7,12.8,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.7,11.3,3.37,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.6,10.6,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(36.9,98); - ctx.lineTo(47.5,98); - ctx.quadraticCurveTo(47.5,98,47.5,98); - ctx.lineTo(47.5,154.5); - ctx.quadraticCurveTo(47.5,154.5,47.5,154.5); - ctx.lineTo(36.9,154.5); - ctx.quadraticCurveTo(36.9,154.5,36.9,154.5); - ctx.lineTo(36.9,98); - ctx.quadraticCurveTo(36.9,98,36.9,98); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(43.6,0.372); - ctx.lineTo(87.3,102); - ctx.lineTo(-0.714,102); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(43.6,14.7); - ctx.lineTo(78.5,96.6); - ctx.lineTo(8.07,96.6); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - } - - public Distance getMarkHeight() { - return markHeightInMeters; - } - - public Distance getMarkWidth() { - return markWidthInMeters; - } - - public String getColor() { - return color; - } - - public String getShape() { - return shape; - } - - public String getPattern() { - return pattern; - } - - public MarkType getType() { - return type; - } + public Distance getMarkWidth(); } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java new file mode 100644 index 00000000000..108e4406b63 --- /dev/null +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java @@ -0,0 +1,29 @@ +package com.sap.sailing.gwt.ui.shared.racemap; + +import com.sap.sailing.domain.common.MarkType; +import com.sap.sailing.gwt.ui.shared.MarkDTO; + +public class MarkVectorGraphicsFactory { + + public MarkVectorGraphics getMarkVectorGraphics(MarkType markType, MarkDTO markDTO) { + MarkVectorGraphics result; + switch (markType) { + case BUOY: + result = new BuoyMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + break; + case STARTBOAT: + result = new BoatMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + break; + case FINISHBOAT: + result = new BoatMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + break; + case LANDMARK: + result = new LandMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + break; + default: + result = new BuoyMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + break; + } + return result; + } +} From 62b64455061032a738bd0264c42e3f77dd261cf4 Mon Sep 17 00:00:00 2001 From: Kai Boernert Date: Thu, 3 Nov 2016 09:16:52 +0100 Subject: [PATCH 23/32] fix for inconsistent layouting of wind and competitorchart, disabled automatic reflow, as it is handled manually, fixed spacing top, to account correctly for the existing buttons --- .../sap/sailing/gwt/ui/client/shared/charts/WindChart.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/WindChart.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/WindChart.java index 839ead23c27..2ab315d1fd4 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/WindChart.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/WindChart.java @@ -103,6 +103,7 @@ public class WindChart extends AbstractRaceChart implements R colorMap = new ColorMapImpl(); chart = new Chart() .setPersistent(true) + .setReflow(false) .setZoomType(BaseChart.ZoomType.X) .setMarginLeft(65) .setMarginRight(65) @@ -115,7 +116,7 @@ public class WindChart extends AbstractRaceChart implements R .setPlotBackgroundColor("#f8f8f8") .setPlotBorderWidth(0) .setCredits(new Credits().setEnabled(false)) - .setChartTitle(new ChartTitle().setText(stringMessages.wind())) + .setChartTitle(new ChartTitle().setText(stringMessages.wind()).setOption("floating",true)) .setChartSubtitle(new ChartSubtitle().setText(stringMessages.clickAndDragToZoomIn())) .setLinePlotOptions(new LinePlotOptions().setLineWidth(LINE_WIDTH).setMarker( new Marker().setEnabled(false).setHoverState( @@ -182,7 +183,7 @@ public class WindChart extends AbstractRaceChart implements R chart.getYAxis(1).setOpposite(true).setAxisTitleText(stringMessages.speed()+" ("+stringMessages.knotsUnit()+")").setMin(0) .setMaxPadding(0.05).setStartOnTick(false).setGridLineWidth(0).setMinorGridLineWidth(0); if (compactChart) { - chart.setSpacingBottom(10).setSpacingLeft(10).setSpacingRight(10).setSpacingTop(2) + chart.setSpacingBottom(10).setSpacingLeft(10).setSpacingRight(10).setSpacingTop(20) .setOption("legend/margin", 2) .setOption("title/margin", 5) .setChartSubtitle(null) From 8092206a9aa22ee411be7c738336bae50b82d43f Mon Sep 17 00:00:00 2001 From: Kai Boernert Date: Fri, 4 Nov 2016 09:07:48 +0100 Subject: [PATCH 24/32] fix for competitor chart sometimes empty upon initial useage --- .../ui/client/shared/charts/AbstractCompetitorRaceChart.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/AbstractCompetitorRaceChart.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/AbstractCompetitorRaceChart.java index 71a165375af..75efb151e86 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/AbstractCompetitorRaceChart.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/charts/AbstractCompetitorRaceChart.java @@ -384,6 +384,8 @@ public abstract class AbstractCompetitorRaceChart Date: Mon, 7 Nov 2016 11:01:37 +0100 Subject: [PATCH 25/32] formatting; removed redundancies in switch/case Change-Id: I9e1567b21fce2771d9211be8c12e1abd51cd6dcf --- .../racemap/AbstractMarkVectorGraphics.java | 230 +++++----- .../racemap/BoatMarkVectorGraphics.java | 148 +++---- .../racemap/BuoyMarkVectorGraphics.java | 412 +++++++++--------- .../racemap/LandMarkVectorGraphics.java | 68 +-- .../ui/shared/racemap/MarkVectorGraphics.java | 7 +- .../racemap/MarkVectorGraphicsFactory.java | 41 +- 6 files changed, 451 insertions(+), 455 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java index 0c3df0a52ac..342af46b2e7 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java @@ -58,130 +58,130 @@ public abstract class AbstractMarkVectorGraphics implements MarkVectorGraphics { return markWidthInMeters; } - protected void drawMark(Context2d ctx, boolean isSelected, String color) { - if (isSelected) { - drawMarkSelection(ctx); - } - this.drawMarkBody(ctx, isSelected, color); - } + protected void drawMark(Context2d ctx, boolean isSelected, String color) { + if (isSelected) { + drawMarkSelection(ctx); + } + this.drawMarkBody(ctx, isSelected, color); + } protected void drawMarkSelection(Context2d ctx) { - ctx.save(); - - this.setUpScaleAndTranslateForMarkSelection(ctx); - - CanvasGradient g1=ctx.createLinearGradient(77.8,188,165,219); - g1.addColorStop(0,"rgba(240, 240, 240, 1)"); - g1.addColorStop(1,"rgba(240, 240, 240, 0)"); - ctx.setFillStyle(g1); - ctx.beginPath(); - ctx.moveTo(170,181); - ctx.translate(44.000168893718424,180.79369636814624); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,0.0016373311430805408,0.5254904360229328,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-44.000168893718424,-180.79369636814624); - ctx.lineTo(44.2,181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); + ctx.save(); - CanvasGradient g2=ctx.createLinearGradient(51,203,77.3,302); - g2.addColorStop(0,"rgba(255, 255, 255, 1)"); - g2.addColorStop(1,"rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g2); - ctx.beginPath(); - ctx.moveTo(107,290); - ctx.translate(43.79222318749837,181.0010231680087); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,1.0452923752792398,1.5667663411841573,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-43.79222318749837,-181.0010231680087); - ctx.lineTo(44.2,181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); + this.setUpScaleAndTranslateForMarkSelection(ctx); - CanvasGradient g3=ctx.createLinearGradient(26.8,197,-46.5,269); - g3.addColorStop(0,"rgba(255, 255, 255, 1)"); - g3.addColorStop(1,"rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g3); - ctx.beginPath(); - ctx.moveTo(-18.3,290); - ctx.translate(43.72636289026038,180.32443158749652); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,2.0854951576078884,2.611791628699119,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-43.72636289026038,-180.32443158749652); - ctx.lineTo(44.2,181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); + CanvasGradient g1 = ctx.createLinearGradient(77.8, 188, 165, 219); + g1.addColorStop(0, "rgba(240, 240, 240, 1)"); + g1.addColorStop(1, "rgba(240, 240, 240, 0)"); + ctx.setFillStyle(g1); + ctx.beginPath(); + ctx.moveTo(170, 181); + ctx.translate(44.000168893718424, 180.79369636814624); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, 0.0016373311430805408, 0.5254904360229328, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-44.000168893718424, -180.79369636814624); + ctx.lineTo(44.2, 181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); - CanvasGradient g4=ctx.createLinearGradient(18.7,172,-76.3,140); - g4.addColorStop(0,"rgba(255, 255, 255, 1)"); - g4.addColorStop(1,"rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g4); - ctx.beginPath(); - ctx.moveTo(-81.8,179); - ctx.translate(44.19920011832349,178.55103503179944); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,3.1380294320163484,3.670248678643417,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-44.19920011832349,-178.55103503179944); - ctx.lineTo(44.2,179); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); + CanvasGradient g2 = ctx.createLinearGradient(51, 203, 77.3, 302); + g2.addColorStop(0, "rgba(255, 255, 255, 1)"); + g2.addColorStop(1, "rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g2); + ctx.beginPath(); + ctx.moveTo(107, 290); + ctx.translate(43.79222318749837, 181.0010231680087); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, 1.0452923752792398, 1.5667663411841573, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-43.79222318749837, -181.0010231680087); + ctx.lineTo(44.2, 181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); - CanvasGradient g5=ctx.createLinearGradient(37.9,147,13.6,58.6); - g5.addColorStop(0,"rgba(255, 255, 255, 1)"); - g5.addColorStop(1,"rgba(255, 255, 255, 0)"); - ctx.setFillStyle(g5); - ctx.beginPath(); - ctx.moveTo(-18.7,71.8); - ctx.translate(44.160311222571984,180.99973110315514); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,-2.0931154263055687,-1.5728622903484606,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-44.160311222571984,-180.99973110315514); - ctx.lineTo(44.199999999999996,181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); + CanvasGradient g3 = ctx.createLinearGradient(26.8, 197, -46.5, 269); + g3.addColorStop(0, "rgba(255, 255, 255, 1)"); + g3.addColorStop(1, "rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g3); + ctx.beginPath(); + ctx.moveTo(-18.3, 290); + ctx.translate(43.72636289026038, 180.32443158749652); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, 2.0854951576078884, 2.611791628699119, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-43.72636289026038, -180.32443158749652); + ctx.lineTo(44.2, 181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); - CanvasGradient g6=ctx.createLinearGradient(80.8,139,134,91.9); - g6.addColorStop(0,"rgba(240, 240, 240, 1)"); - g6.addColorStop(1,"rgba(240, 240, 240, 0)"); - ctx.setFillStyle(g6); - ctx.beginPath(); - ctx.moveTo(108,72.1); - ctx.translate(43.50304481630927,180.3411325330301); - ctx.rotate(0); - ctx.scale(1,1); - ctx.arc(0,0,126,-1.0334238189446499,-0.5175711746742696,false); - ctx.scale(1,1); - ctx.rotate(0); - ctx.translate(-43.50304481630927,-180.3411325330301); - ctx.lineTo(44.2,181); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); + CanvasGradient g4 = ctx.createLinearGradient(18.7, 172, -76.3, 140); + g4.addColorStop(0, "rgba(255, 255, 255, 1)"); + g4.addColorStop(1, "rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g4); + ctx.beginPath(); + ctx.moveTo(-81.8, 179); + ctx.translate(44.19920011832349, 178.55103503179944); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, 3.1380294320163484, 3.670248678643417, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-44.19920011832349, -178.55103503179944); + ctx.lineTo(44.2, 179); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); - ctx.translate(-49.5,17.2); - ctx.restore(); + CanvasGradient g5 = ctx.createLinearGradient(37.9, 147, 13.6, 58.6); + g5.addColorStop(0, "rgba(255, 255, 255, 1)"); + g5.addColorStop(1, "rgba(255, 255, 255, 0)"); + ctx.setFillStyle(g5); + ctx.beginPath(); + ctx.moveTo(-18.7, 71.8); + ctx.translate(44.160311222571984, 180.99973110315514); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, -2.0931154263055687, -1.5728622903484606, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-44.160311222571984, -180.99973110315514); + ctx.lineTo(44.199999999999996, 181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + CanvasGradient g6 = ctx.createLinearGradient(80.8, 139, 134, 91.9); + g6.addColorStop(0, "rgba(240, 240, 240, 1)"); + g6.addColorStop(1, "rgba(240, 240, 240, 0)"); + ctx.setFillStyle(g6); + ctx.beginPath(); + ctx.moveTo(108, 72.1); + ctx.translate(43.50304481630927, 180.3411325330301); + ctx.rotate(0); + ctx.scale(1, 1); + ctx.arc(0, 0, 126, -1.0334238189446499, -0.5175711746742696, false); + ctx.scale(1, 1); + ctx.rotate(0); + ctx.translate(-43.50304481630927, -180.3411325330301); + ctx.lineTo(44.2, 181); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + + ctx.translate(-49.5, 17.2); + ctx.restore(); } - + protected void setUpScaleAndTranslateForMarkSelection(Context2d ctx) { ctx.scale(1.2,1.2); ctx.translate(-10,-30); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java index ca11b033594..7cd3f934692 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java @@ -7,82 +7,82 @@ import com.sap.sailing.domain.common.impl.MeterDistance; public class BoatMarkVectorGraphics extends AbstractMarkVectorGraphics { - private final static Distance BOAT_MARK_HEIGHT_IN_METERS = new MeterDistance(6.2); - private final static Distance BOAT_MARK_WIDTH_IN_METERS = new MeterDistance(3.5); - private final static double BOAT_MARK_SELECTION_SCALE = 3.5; - private final static double BOAT_MARK_SELECTION_TRANSLATE_X = -10; - private final static double BOAT_MARK_SELECTION_TRANSLATE_Y = -30; + private final static Distance BOAT_MARK_HEIGHT_IN_METERS = new MeterDistance(6.2); + private final static Distance BOAT_MARK_WIDTH_IN_METERS = new MeterDistance(3.5); + private final static double BOAT_MARK_SELECTION_SCALE = 3.5; + private final static double BOAT_MARK_SELECTION_TRANSLATE_X = -10; + private final static double BOAT_MARK_SELECTION_TRANSLATE_Y = -30; - public BoatMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { - super(type, color, shape, pattern); - this.anchorPointX = BOAT_MARK_HEIGHT_IN_METERS.getMeters() / 2; - this.anchorPointY = BOAT_MARK_WIDTH_IN_METERS.getMeters() / 2; - this.markHeightInMeters = BOAT_MARK_HEIGHT_IN_METERS; - this.markWidthInMeters = BOAT_MARK_WIDTH_IN_METERS; - } - - protected void setUpScaleAndTranslateForMarkSelection(Context2d ctx) { - ctx.scale(BOAT_MARK_SELECTION_SCALE, BOAT_MARK_SELECTION_SCALE); + public BoatMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { + super(type, color, shape, pattern); + this.anchorPointX = BOAT_MARK_HEIGHT_IN_METERS.getMeters() / 2; + this.anchorPointY = BOAT_MARK_WIDTH_IN_METERS.getMeters() / 2; + this.markHeightInMeters = BOAT_MARK_HEIGHT_IN_METERS; + this.markWidthInMeters = BOAT_MARK_WIDTH_IN_METERS; + } + + protected void setUpScaleAndTranslateForMarkSelection(Context2d ctx) { + ctx.scale(BOAT_MARK_SELECTION_SCALE, BOAT_MARK_SELECTION_SCALE); ctx.translate(BOAT_MARK_SELECTION_TRANSLATE_X, BOAT_MARK_SELECTION_TRANSLATE_Y); } - @Override - protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { - ctx.beginPath(); - ctx.setFillStyle("#000000"); - ctx.setStrokeStyle("#FFFFFF"); - ctx.setLineWidth(30.0); - ctx.setLineCap("butt"); - ctx.setLineJoin("miter"); - ctx.setMiterLimit(3.0); - ctx.moveTo(33,30.36); - ctx.quadraticCurveTo(103.47,18.96,194.65,18.55); - ctx.quadraticCurveTo(285.83,18.13,370.62,34.74); - ctx.quadraticCurveTo(455.42,51.34,520.29,87.99); - ctx.quadraticCurveTo(585.16,124.64,603,187.36); - ctx.quadraticCurveTo(584.67,244.84,520.84,277.54); - ctx.quadraticCurveTo(457,310.24,372.97,324.79); - ctx.quadraticCurveTo(288.94,339.34,197.37,339.08); - ctx.quadraticCurveTo(105.8,338.81,32,330.36); - ctx.lineTo(33,30.362205); - ctx.fill(); - ctx.stroke(); - - ctx.setFillStyle("#FFFFFF"); - ctx.beginPath(); - ctx.beginPath(); - ctx.setLineWidth(1.0); - ctx.setLineJoin("miter"); - ctx.setMiterLimit(4.0); - ctx.moveTo(81,78); - ctx.lineTo(349,78); - ctx.lineTo(349,291); - ctx.lineTo(81,291); - ctx.lineTo(81,78); - ctx.fill(); - ctx.stroke(); - - ctx.setFillStyle("#000000"); - ctx.beginPath(); - ctx.moveTo(337,186.36); - ctx.quadraticCurveTo(337,180.56,334.76,175.46); - ctx.quadraticCurveTo(332.52,170.36,328.65,166.56); - ctx.quadraticCurveTo(324.78,162.76,319.59,160.56); - ctx.quadraticCurveTo(314.4,158.36,308.5,158.36); - ctx.quadraticCurveTo(302.6,158.36,297.41,160.56); - ctx.quadraticCurveTo(292.22,162.76,288.35,166.56); - ctx.quadraticCurveTo(284.48,170.36,282.24,175.46); - ctx.quadraticCurveTo(280,180.56,280,186.36); - ctx.quadraticCurveTo(280,192.16,282.24,197.26); - ctx.quadraticCurveTo(284.48,202.36,288.35,206.16); - ctx.quadraticCurveTo(292.22,209.96,297.41,212.16); - ctx.quadraticCurveTo(302.6,214.36,308.5,214.36); - ctx.quadraticCurveTo(314.4,214.36,319.59,212.16); - ctx.quadraticCurveTo(324.78,209.96,328.65,206.16); - ctx.quadraticCurveTo(332.52,202.36,334.76,197.26); - ctx.quadraticCurveTo(337,192.16,337,186.36); - ctx.stroke(); - ctx.fill(); - ctx.beginPath(); - } + @Override + protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { + ctx.beginPath(); + ctx.setFillStyle("#000000"); + ctx.setStrokeStyle("#FFFFFF"); + ctx.setLineWidth(30.0); + ctx.setLineCap("butt"); + ctx.setLineJoin("miter"); + ctx.setMiterLimit(3.0); + ctx.moveTo(33, 30.36); + ctx.quadraticCurveTo(103.47, 18.96, 194.65, 18.55); + ctx.quadraticCurveTo(285.83, 18.13, 370.62, 34.74); + ctx.quadraticCurveTo(455.42, 51.34, 520.29, 87.99); + ctx.quadraticCurveTo(585.16, 124.64, 603, 187.36); + ctx.quadraticCurveTo(584.67, 244.84, 520.84, 277.54); + ctx.quadraticCurveTo(457, 310.24, 372.97, 324.79); + ctx.quadraticCurveTo(288.94, 339.34, 197.37, 339.08); + ctx.quadraticCurveTo(105.8, 338.81, 32, 330.36); + ctx.lineTo(33, 30.362205); + ctx.fill(); + ctx.stroke(); + + ctx.setFillStyle("#FFFFFF"); + ctx.beginPath(); + ctx.beginPath(); + ctx.setLineWidth(1.0); + ctx.setLineJoin("miter"); + ctx.setMiterLimit(4.0); + ctx.moveTo(81, 78); + ctx.lineTo(349, 78); + ctx.lineTo(349, 291); + ctx.lineTo(81, 291); + ctx.lineTo(81, 78); + ctx.fill(); + ctx.stroke(); + + ctx.setFillStyle("#000000"); + ctx.beginPath(); + ctx.moveTo(337, 186.36); + ctx.quadraticCurveTo(337, 180.56, 334.76, 175.46); + ctx.quadraticCurveTo(332.52, 170.36, 328.65, 166.56); + ctx.quadraticCurveTo(324.78, 162.76, 319.59, 160.56); + ctx.quadraticCurveTo(314.4, 158.36, 308.5, 158.36); + ctx.quadraticCurveTo(302.6, 158.36, 297.41, 160.56); + ctx.quadraticCurveTo(292.22, 162.76, 288.35, 166.56); + ctx.quadraticCurveTo(284.48, 170.36, 282.24, 175.46); + ctx.quadraticCurveTo(280, 180.56, 280, 186.36); + ctx.quadraticCurveTo(280, 192.16, 282.24, 197.26); + ctx.quadraticCurveTo(284.48, 202.36, 288.35, 206.16); + ctx.quadraticCurveTo(292.22, 209.96, 297.41, 212.16); + ctx.quadraticCurveTo(302.6, 214.36, 308.5, 214.36); + ctx.quadraticCurveTo(314.4, 214.36, 319.59, 212.16); + ctx.quadraticCurveTo(324.78, 209.96, 328.65, 206.16); + ctx.quadraticCurveTo(332.52, 202.36, 334.76, 197.26); + ctx.quadraticCurveTo(337, 192.16, 337, 186.36); + ctx.stroke(); + ctx.fill(); + ctx.beginPath(); + } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BuoyMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BuoyMarkVectorGraphics.java index ca9cd756777..c911579926e 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BuoyMarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BuoyMarkVectorGraphics.java @@ -5,55 +5,35 @@ import com.sap.sailing.domain.common.MarkType; public class BuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implements MarkVectorGraphics { - public BuoyMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { - super(type, color, shape, pattern); - } + public BuoyMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { + super(type, color, shape, pattern); + } + + @Override + protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { + if (shape != null) { + if (Shape.CYLINDER.name().equalsIgnoreCase(shape) && pattern != null + && Pattern.CHECKERED.name().equalsIgnoreCase(pattern)) { + drawBuoyWithFinishFlag(ctx, isSelected, color); + } else if (Shape.CONICAL.name().equalsIgnoreCase(shape)) { + drawConicalBuoy(ctx, isSelected, color); + } else { + drawSimpleBuoy(ctx, isSelected, color); + } + } else { + drawSimpleBuoy(ctx, isSelected, color); + } + } - @Override - protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { - if (shape != null) { - if (Shape.CYLINDER.name().equalsIgnoreCase(shape) && pattern != null - && Pattern.CHECKERED.name().equalsIgnoreCase(pattern)) { - drawBuoyWithFinishFlag(ctx, isSelected, color); - } else if (Shape.CONICAL.name().equalsIgnoreCase(shape)) { - drawConicalBuoy(ctx, isSelected, color); - } else { - drawSimpleBuoy(ctx, isSelected, color); - } - } else { - drawSimpleBuoy(ctx, isSelected, color); - } - } - void drawSimpleBuoy(Context2d ctx, boolean isSelected, String color) { ctx.setStrokeStyle("rgba(0,0,0,0)"); - + ctx.save(); ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); + ctx.beginPath(); - ctx.arc(49.7,12.8,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.7,11.3,3.37,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.6,10.6,2.66,0,doublePi,false); + ctx.arc(49.7, 12.8, 2.66, 0, doublePi, false); ctx.closePath(); ctx.fill(); ctx.stroke(); @@ -61,59 +41,79 @@ public class BuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implement ctx.save(); ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(4.98,0,0,10.8,-205,50.4); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); ctx.beginPath(); - ctx.moveTo(50.8,9.84); - ctx.lineTo(48.5,9.84); - ctx.lineTo(48.5,1.44); - ctx.lineTo(50.8,1.9); - ctx.lineTo(50.8,9.84); + ctx.arc(49.7, 11.3, 3.37, 0, doublePi, false); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); - ctx.save(); - ctx.transform(12.5,0,0,12.5,-570,22.2); ctx.save(); ctx.setFillStyle(color); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); ctx.beginPath(); - ctx.moveTo(48.8,3.82); - ctx.lineTo(48.8,-1.32); - ctx.lineTo(57,1.05); - ctx.lineTo(48.8,3.82); + ctx.arc(49.6, 10.6, 2.66, 0, doublePi, false); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); - + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.transform(4.98, 0, 0, 10.8, -205, 50.4); + ctx.beginPath(); + ctx.moveTo(50.8, 9.84); + ctx.lineTo(48.5, 9.84); + ctx.lineTo(48.5, 1.44); + ctx.lineTo(50.8, 1.9); + ctx.lineTo(50.8, 9.84); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.transform(12.5, 0, 0, 12.5, -570, 22.2); + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(48.8, 3.82); + ctx.lineTo(48.8, -1.32); + ctx.lineTo(57, 1.05); + ctx.lineTo(48.8, 3.82); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + ctx.save(); ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); ctx.beginPath(); - ctx.moveTo(48.5,4.16); - ctx.lineTo(48.5,-1.65); - ctx.lineTo(57.8,1.03); - ctx.lineTo(48.5,4.16); + ctx.moveTo(48.5, 4.16); + ctx.lineTo(48.5, -1.65); + ctx.lineTo(57.8, 1.03); + ctx.lineTo(48.5, 4.16); ctx.closePath(); - ctx.moveTo(49,-0.994); - ctx.lineTo(49,3.47); - ctx.lineTo(56.2,1.07); - ctx.lineTo(49,-0.994); + ctx.moveTo(49, -0.994); + ctx.lineTo(49, 3.47); + ctx.lineTo(56.2, 1.07); + ctx.lineTo(49, -0.994); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); ctx.restore(); } - + private void drawBuoyWithFinishFlag(Context2d ctx, boolean isSelected, String color) { ctx.setStrokeStyle("rgba(0,0,0,0)"); ctx.save(); ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); ctx.beginPath(); - ctx.arc(49.7,12.8,2.66,0,doublePi,false); + ctx.arc(49.7, 12.8, 2.66, 0, doublePi, false); ctx.closePath(); ctx.fill(); ctx.stroke(); @@ -121,50 +121,9 @@ public class BuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implement ctx.save(); ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); ctx.beginPath(); - ctx.arc(49.7,11.3,3.37,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); - ctx.beginPath(); - ctx.arc(49.6,10.6,2.66,0,doublePi,false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(4.98,0,0,10.8,-205,50.4); - ctx.beginPath(); - ctx.moveTo(50.8,9.84); - ctx.lineTo(48.5,9.84); - ctx.lineTo(48.5,1.44); - ctx.lineTo(50.8,1.9); - ctx.lineTo(50.8,9.84); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(36.9,-0.5); - ctx.lineTo(141.9,-0.5); - ctx.quadraticCurveTo(141.9,-0.5,141.9,-0.5); - ctx.lineTo(141.9,71.2); - ctx.quadraticCurveTo(141.9,71.2,141.9,71.2); - ctx.lineTo(36.9,71.2); - ctx.quadraticCurveTo(36.9,71.2,36.9,71.2); - ctx.lineTo(36.9,-0.5); - ctx.quadraticCurveTo(36.9,-0.5,36.9,-0.5); + ctx.arc(49.7, 11.3, 3.37, 0, doublePi, false); ctx.closePath(); ctx.fill(); ctx.stroke(); @@ -172,16 +131,23 @@ public class BuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implement ctx.save(); ctx.setFillStyle(color); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); ctx.beginPath(); - ctx.moveTo(46,4.04); - ctx.lineTo(76.3,4.04); - ctx.quadraticCurveTo(76.3,4.04,76.3,4.04); - ctx.lineTo(76.3,34.34); - ctx.quadraticCurveTo(76.3,34.34,76.3,34.34); - ctx.lineTo(46,34.34); - ctx.quadraticCurveTo(46,34.34,46,34.34); - ctx.lineTo(46,4.04); - ctx.quadraticCurveTo(46,4.04,46,4.04); + ctx.arc(49.6, 10.6, 2.66, 0, doublePi, false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.transform(4.98, 0, 0, 10.8, -205, 50.4); + ctx.beginPath(); + ctx.moveTo(50.8, 9.84); + ctx.lineTo(48.5, 9.84); + ctx.lineTo(48.5, 1.44); + ctx.lineTo(50.8, 1.9); + ctx.lineTo(50.8, 9.84); ctx.closePath(); ctx.fill(); ctx.stroke(); @@ -190,15 +156,32 @@ public class BuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implement ctx.save(); ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); ctx.beginPath(); - ctx.moveTo(46.1,34.3); - ctx.lineTo(76.4,34.3); - ctx.quadraticCurveTo(76.4,34.3,76.4,34.3); - ctx.lineTo(76.4,64.6); - ctx.quadraticCurveTo(76.4,64.6,76.4,64.6); - ctx.lineTo(46.1,64.6); - ctx.quadraticCurveTo(46.1,64.6,46.1,64.6); - ctx.lineTo(46.1,34.3); - ctx.quadraticCurveTo(46.1,34.3,46.1,34.3); + ctx.moveTo(36.9, -0.5); + ctx.lineTo(141.9, -0.5); + ctx.quadraticCurveTo(141.9, -0.5, 141.9, -0.5); + ctx.lineTo(141.9, 71.2); + ctx.quadraticCurveTo(141.9, 71.2, 141.9, 71.2); + ctx.lineTo(36.9, 71.2); + ctx.quadraticCurveTo(36.9, 71.2, 36.9, 71.2); + ctx.lineTo(36.9, -0.5); + ctx.quadraticCurveTo(36.9, -0.5, 36.9, -0.5); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(46, 4.04); + ctx.lineTo(76.3, 4.04); + ctx.quadraticCurveTo(76.3, 4.04, 76.3, 4.04); + ctx.lineTo(76.3, 34.34); + ctx.quadraticCurveTo(76.3, 34.34, 76.3, 34.34); + ctx.lineTo(46, 34.34); + ctx.quadraticCurveTo(46, 34.34, 46, 34.34); + ctx.lineTo(46, 4.04); + ctx.quadraticCurveTo(46, 4.04, 46, 4.04); ctx.closePath(); ctx.fill(); ctx.stroke(); @@ -207,66 +190,83 @@ public class BuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implement ctx.save(); ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); ctx.beginPath(); - ctx.moveTo(76,3.95); - ctx.lineTo(106.3,3.95); - ctx.quadraticCurveTo(106.3,3.95,106.3,3.95); - ctx.lineTo(106.3,34.25); - ctx.quadraticCurveTo(106.3,34.25,106.3,34.25); - ctx.lineTo(76,34.25); - ctx.quadraticCurveTo(76,34.25,76,34.25); - ctx.lineTo(76,3.95); - ctx.quadraticCurveTo(76,3.95,76,3.95); + ctx.moveTo(46.1, 34.3); + ctx.lineTo(76.4, 34.3); + ctx.quadraticCurveTo(76.4, 34.3, 76.4, 34.3); + ctx.lineTo(76.4, 64.6); + ctx.quadraticCurveTo(76.4, 64.6, 76.4, 64.6); + ctx.lineTo(46.1, 64.6); + ctx.quadraticCurveTo(46.1, 64.6, 46.1, 64.6); + ctx.lineTo(46.1, 34.3); + ctx.quadraticCurveTo(46.1, 34.3, 46.1, 34.3); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(76.1,34.2); - ctx.lineTo(106.4,34.2); - ctx.quadraticCurveTo(106.4,34.2,106.4,34.2); - ctx.lineTo(106.4,64.5); - ctx.quadraticCurveTo(106.4,64.5,106.4,64.5); - ctx.lineTo(76.1,64.5); - ctx.quadraticCurveTo(76.1,64.5,76.1,64.5); - ctx.lineTo(76.1,34.2); - ctx.quadraticCurveTo(76.1,34.2,76.1,34.2); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(106,3.96); - ctx.lineTo(136.3,3.96); - ctx.quadraticCurveTo(136.3,3.96,136.3,3.96); - ctx.lineTo(136.3,34.26); - ctx.quadraticCurveTo(136.3,34.26,136.3,34.26); - ctx.lineTo(106,34.26); - ctx.quadraticCurveTo(106,34.26,106,34.26); - ctx.lineTo(106,3.96); - ctx.quadraticCurveTo(106,3.96,106,3.96); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - + ctx.save(); ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); ctx.beginPath(); - ctx.moveTo(106,34.3); - ctx.lineTo(136.3,34.3); - ctx.quadraticCurveTo(136.3,34.3,136.3,34.3); - ctx.lineTo(136.3,64.6); - ctx.quadraticCurveTo(136.3,64.6,136.3,64.6); - ctx.lineTo(106,64.6); - ctx.quadraticCurveTo(106,64.6,106,64.6); - ctx.lineTo(106,34.3); - ctx.quadraticCurveTo(106,34.3,106,34.3); + ctx.moveTo(76, 3.95); + ctx.lineTo(106.3, 3.95); + ctx.quadraticCurveTo(106.3, 3.95, 106.3, 3.95); + ctx.lineTo(106.3, 34.25); + ctx.quadraticCurveTo(106.3, 34.25, 106.3, 34.25); + ctx.lineTo(76, 34.25); + ctx.quadraticCurveTo(76, 34.25, 76, 34.25); + ctx.lineTo(76, 3.95); + ctx.quadraticCurveTo(76, 3.95, 76, 3.95); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(76.1, 34.2); + ctx.lineTo(106.4, 34.2); + ctx.quadraticCurveTo(106.4, 34.2, 106.4, 34.2); + ctx.lineTo(106.4, 64.5); + ctx.quadraticCurveTo(106.4, 64.5, 106.4, 64.5); + ctx.lineTo(76.1, 64.5); + ctx.quadraticCurveTo(76.1, 64.5, 76.1, 64.5); + ctx.lineTo(76.1, 34.2); + ctx.quadraticCurveTo(76.1, 34.2, 76.1, 34.2); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(106, 3.96); + ctx.lineTo(136.3, 3.96); + ctx.quadraticCurveTo(136.3, 3.96, 136.3, 3.96); + ctx.lineTo(136.3, 34.26); + ctx.quadraticCurveTo(136.3, 34.26, 136.3, 34.26); + ctx.lineTo(106, 34.26); + ctx.quadraticCurveTo(106, 34.26, 106, 34.26); + ctx.lineTo(106, 3.96); + ctx.quadraticCurveTo(106, 3.96, 106, 3.96); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(106, 34.3); + ctx.lineTo(136.3, 34.3); + ctx.quadraticCurveTo(136.3, 34.3, 136.3, 34.3); + ctx.lineTo(136.3, 64.6); + ctx.quadraticCurveTo(136.3, 64.6, 136.3, 64.6); + ctx.lineTo(106, 64.6); + ctx.quadraticCurveTo(106, 64.6, 106, 64.6); + ctx.lineTo(106, 34.3); + ctx.quadraticCurveTo(106, 34.3, 106, 34.3); ctx.closePath(); ctx.fill(); ctx.stroke(); @@ -279,9 +279,9 @@ public class BuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implement ctx.save(); ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); ctx.beginPath(); - ctx.arc(49.7,12.8,2.66,0,doublePi,false); + ctx.arc(49.7, 12.8, 2.66, 0, doublePi, false); ctx.closePath(); ctx.fill(); ctx.stroke(); @@ -289,58 +289,58 @@ public class BuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implement ctx.save(); ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); ctx.beginPath(); - ctx.arc(49.7,11.3,3.37,0,doublePi,false); + ctx.arc(49.7, 11.3, 3.37, 0, doublePi, false); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); - + ctx.save(); ctx.setFillStyle(color); - ctx.transform(12.5,0,0,12.5,-578,22.2); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); ctx.beginPath(); - ctx.arc(49.6,10.6,2.66,0,doublePi,false); + ctx.arc(49.6, 10.6, 2.66, 0, doublePi, false); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); - + ctx.save(); ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); ctx.beginPath(); - ctx.moveTo(36.9,98); - ctx.lineTo(47.5,98); - ctx.quadraticCurveTo(47.5,98,47.5,98); - ctx.lineTo(47.5,154.5); - ctx.quadraticCurveTo(47.5,154.5,47.5,154.5); - ctx.lineTo(36.9,154.5); - ctx.quadraticCurveTo(36.9,154.5,36.9,154.5); - ctx.lineTo(36.9,98); - ctx.quadraticCurveTo(36.9,98,36.9,98); + ctx.moveTo(36.9, 98); + ctx.lineTo(47.5, 98); + ctx.quadraticCurveTo(47.5, 98, 47.5, 98); + ctx.lineTo(47.5, 154.5); + ctx.quadraticCurveTo(47.5, 154.5, 47.5, 154.5); + ctx.lineTo(36.9, 154.5); + ctx.quadraticCurveTo(36.9, 154.5, 36.9, 154.5); + ctx.lineTo(36.9, 98); + ctx.quadraticCurveTo(36.9, 98, 36.9, 98); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); - + ctx.save(); ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); ctx.beginPath(); - ctx.moveTo(43.6,0.372); - ctx.lineTo(87.3,102); - ctx.lineTo(-0.714,102); + ctx.moveTo(43.6, 0.372); + ctx.lineTo(87.3, 102); + ctx.lineTo(-0.714, 102); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); - + ctx.save(); ctx.setFillStyle(color); ctx.beginPath(); - ctx.moveTo(43.6,14.7); - ctx.lineTo(78.5,96.6); - ctx.lineTo(8.07,96.6); + ctx.moveTo(43.6, 14.7); + ctx.lineTo(78.5, 96.6); + ctx.lineTo(8.07, 96.6); ctx.closePath(); ctx.fill(); ctx.stroke(); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/LandMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/LandMarkVectorGraphics.java index 44a7fe10402..dd604da5644 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/LandMarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/LandMarkVectorGraphics.java @@ -5,73 +5,73 @@ import com.sap.sailing.domain.common.MarkType; public class LandMarkVectorGraphics extends AbstractMarkVectorGraphics implements MarkVectorGraphics { - public LandMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { - super(type, color, shape, pattern); - } + public LandMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { + super(type, color, shape, pattern); + } - @Override - protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { - ctx.setStrokeStyle("rgba(0,0,0,0)"); + @Override + protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { + ctx.setStrokeStyle("rgba(0,0,0,0)"); ctx.save(); ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(4.98,0,0,10.8,-205,50.4); + ctx.transform(4.98, 0, 0, 10.8, -205, 50.4); ctx.beginPath(); - ctx.moveTo(50.8,9.84); - ctx.lineTo(48.5,9.84); - ctx.lineTo(48.5,1.44); - ctx.lineTo(50.8,1.9); - ctx.lineTo(50.8,9.84); + ctx.moveTo(50.8, 9.84); + ctx.lineTo(48.5, 9.84); + ctx.lineTo(48.5, 1.44); + ctx.lineTo(50.8, 1.9); + ctx.lineTo(50.8, 9.84); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); ctx.save(); - ctx.transform(12.5,0,0,12.5,-570,22.2); + ctx.transform(12.5, 0, 0, 12.5, -570, 22.2); ctx.save(); ctx.setFillStyle(color); ctx.beginPath(); - ctx.moveTo(48.8,3.82); - ctx.lineTo(48.8,-1.32); - ctx.lineTo(57,1.05); - ctx.lineTo(48.8,3.82); + ctx.moveTo(48.8, 3.82); + ctx.lineTo(48.8, -1.32); + ctx.lineTo(57, 1.05); + ctx.lineTo(48.8, 3.82); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); - + ctx.save(); ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); ctx.beginPath(); - ctx.moveTo(48.5,4.16); - ctx.lineTo(48.5,-1.65); - ctx.lineTo(57.8,1.03); - ctx.lineTo(48.5,4.16); + ctx.moveTo(48.5, 4.16); + ctx.lineTo(48.5, -1.65); + ctx.lineTo(57.8, 1.03); + ctx.lineTo(48.5, 4.16); ctx.closePath(); - ctx.moveTo(49,-0.994); - ctx.lineTo(49,3.47); - ctx.lineTo(56.2,1.07); - ctx.lineTo(49,-0.994); + ctx.moveTo(49, -0.994); + ctx.lineTo(49, 3.47); + ctx.lineTo(56.2, 1.07); + ctx.lineTo(49, -0.994); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); ctx.restore(); - + ctx.save(); ctx.setFillStyle(color); ctx.beginPath(); - ctx.moveTo(83.9,209); - ctx.bezierCurveTo(83.9,209,68.6,183,43.0,183); - ctx.bezierCurveTo(12.3,183,7.1,209,7.1,209); - ctx.lineTo(7.1,157); - ctx.lineTo(83.9,157); - ctx.lineTo(83.9,209); + ctx.moveTo(83.9, 209); + ctx.bezierCurveTo(83.9, 209, 68.6, 183, 43.0, 183); + ctx.bezierCurveTo(12.3, 183, 7.1, 209, 7.1, 209); + ctx.lineTo(7.1, 157); + ctx.lineTo(83.9, 157); + ctx.lineTo(83.9, 209); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); ctx.restore(); - } + } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java index bff8dea7ed9..f7296e45a3a 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java @@ -4,10 +4,9 @@ import com.google.gwt.canvas.dom.client.Context2d; import com.sap.sailing.domain.common.Distance; public interface MarkVectorGraphics { + void drawMarkToCanvas(Context2d ctx, boolean isSelected, double width, double height, double scaleFactor); - public void drawMarkToCanvas(Context2d ctx, boolean isSelected, double width, double height, double scaleFactor); + Distance getMarkHeight(); - public Distance getMarkHeight(); - - public Distance getMarkWidth(); + Distance getMarkWidth(); } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java index 108e4406b63..ea8571cf529 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java @@ -4,26 +4,23 @@ import com.sap.sailing.domain.common.MarkType; import com.sap.sailing.gwt.ui.shared.MarkDTO; public class MarkVectorGraphicsFactory { - - public MarkVectorGraphics getMarkVectorGraphics(MarkType markType, MarkDTO markDTO) { - MarkVectorGraphics result; - switch (markType) { - case BUOY: - result = new BuoyMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); - break; - case STARTBOAT: - result = new BoatMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); - break; - case FINISHBOAT: - result = new BoatMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); - break; - case LANDMARK: - result = new LandMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); - break; - default: - result = new BuoyMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); - break; - } - return result; - } + public MarkVectorGraphics getMarkVectorGraphics(MarkType markType, MarkDTO markDTO) { + final MarkVectorGraphics result; + switch (markType) { + case BUOY: + result = new BuoyMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + break; + case STARTBOAT: + case FINISHBOAT: + result = new BoatMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + break; + case LANDMARK: + result = new LandMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + break; + default: + result = new BuoyMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + break; + } + return result; + } } From f05e40a2d4980f6f20473fe27c416bb74d4bcd0e Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Mon, 7 Nov 2016 11:09:16 +0100 Subject: [PATCH 26/32] split up BuoyMarkVectorGraphics according to drawing strategy Change-Id: I342495e36b154eca3f27b41e28c1c0f4c8270946 --- .../ConicalBuoyMarkVectorGraphics.java | 85 +++++++++ ...java => FinishFlagMarkVectorGraphics.java} | 173 +----------------- .../racemap/MarkVectorGraphicsFactory.java | 21 ++- .../racemap/SimpleBuoyMarkVectorGraphics.java | 93 ++++++++++ 4 files changed, 199 insertions(+), 173 deletions(-) create mode 100644 java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/ConicalBuoyMarkVectorGraphics.java rename java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/{BuoyMarkVectorGraphics.java => FinishFlagMarkVectorGraphics.java} (51%) create mode 100644 java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/SimpleBuoyMarkVectorGraphics.java diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/ConicalBuoyMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/ConicalBuoyMarkVectorGraphics.java new file mode 100644 index 00000000000..7f7ec139df5 --- /dev/null +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/ConicalBuoyMarkVectorGraphics.java @@ -0,0 +1,85 @@ +package com.sap.sailing.gwt.ui.shared.racemap; + +import com.google.gwt.canvas.dom.client.Context2d; +import com.sap.sailing.domain.common.MarkType; + +public class ConicalBuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implements MarkVectorGraphics { + + public ConicalBuoyMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { + super(type, color, shape, pattern); + } + + @Override + protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { + ctx.setStrokeStyle("rgba(0,0,0,0)"); + + ctx.save(); + ctx.setFillStyle(color); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); + ctx.beginPath(); + ctx.arc(49.7, 12.8, 2.66, 0, doublePi, false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); + ctx.beginPath(); + ctx.arc(49.7, 11.3, 3.37, 0, doublePi, false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); + ctx.beginPath(); + ctx.arc(49.6, 10.6, 2.66, 0, doublePi, false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(36.9, 98); + ctx.lineTo(47.5, 98); + ctx.quadraticCurveTo(47.5, 98, 47.5, 98); + ctx.lineTo(47.5, 154.5); + ctx.quadraticCurveTo(47.5, 154.5, 47.5, 154.5); + ctx.lineTo(36.9, 154.5); + ctx.quadraticCurveTo(36.9, 154.5, 36.9, 154.5); + ctx.lineTo(36.9, 98); + ctx.quadraticCurveTo(36.9, 98, 36.9, 98); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(43.6, 0.372); + ctx.lineTo(87.3, 102); + ctx.lineTo(-0.714, 102); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(43.6, 14.7); + ctx.lineTo(78.5, 96.6); + ctx.lineTo(8.07, 96.6); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + } +} diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BuoyMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/FinishFlagMarkVectorGraphics.java similarity index 51% rename from java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BuoyMarkVectorGraphics.java rename to java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/FinishFlagMarkVectorGraphics.java index c911579926e..774167d58fc 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BuoyMarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/FinishFlagMarkVectorGraphics.java @@ -3,110 +3,14 @@ package com.sap.sailing.gwt.ui.shared.racemap; import com.google.gwt.canvas.dom.client.Context2d; import com.sap.sailing.domain.common.MarkType; -public class BuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implements MarkVectorGraphics { +public class FinishFlagMarkVectorGraphics extends AbstractMarkVectorGraphics implements MarkVectorGraphics { - public BuoyMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { + public FinishFlagMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { super(type, color, shape, pattern); } @Override protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { - if (shape != null) { - if (Shape.CYLINDER.name().equalsIgnoreCase(shape) && pattern != null - && Pattern.CHECKERED.name().equalsIgnoreCase(pattern)) { - drawBuoyWithFinishFlag(ctx, isSelected, color); - } else if (Shape.CONICAL.name().equalsIgnoreCase(shape)) { - drawConicalBuoy(ctx, isSelected, color); - } else { - drawSimpleBuoy(ctx, isSelected, color); - } - } else { - drawSimpleBuoy(ctx, isSelected, color); - } - } - - void drawSimpleBuoy(Context2d ctx, boolean isSelected, String color) { - ctx.setStrokeStyle("rgba(0,0,0,0)"); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); - - ctx.beginPath(); - ctx.arc(49.7, 12.8, 2.66, 0, doublePi, false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); - ctx.beginPath(); - ctx.arc(49.7, 11.3, 3.37, 0, doublePi, false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); - ctx.beginPath(); - ctx.arc(49.6, 10.6, 2.66, 0, doublePi, false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(4.98, 0, 0, 10.8, -205, 50.4); - ctx.beginPath(); - ctx.moveTo(50.8, 9.84); - ctx.lineTo(48.5, 9.84); - ctx.lineTo(48.5, 1.44); - ctx.lineTo(50.8, 1.9); - ctx.lineTo(50.8, 9.84); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.transform(12.5, 0, 0, 12.5, -570, 22.2); - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(48.8, 3.82); - ctx.lineTo(48.8, -1.32); - ctx.lineTo(57, 1.05); - ctx.lineTo(48.8, 3.82); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(48.5, 4.16); - ctx.lineTo(48.5, -1.65); - ctx.lineTo(57.8, 1.03); - ctx.lineTo(48.5, 4.16); - ctx.closePath(); - ctx.moveTo(49, -0.994); - ctx.lineTo(49, 3.47); - ctx.lineTo(56.2, 1.07); - ctx.lineTo(49, -0.994); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - ctx.restore(); - } - - private void drawBuoyWithFinishFlag(Context2d ctx, boolean isSelected, String color) { ctx.setStrokeStyle("rgba(0,0,0,0)"); ctx.save(); @@ -273,77 +177,4 @@ public class BuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implement ctx.restore(); ctx.restore(); } - - private void drawConicalBuoy(Context2d ctx, boolean isSelected, String color) { - ctx.setStrokeStyle("rgba(0,0,0,0)"); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); - ctx.beginPath(); - ctx.arc(49.7, 12.8, 2.66, 0, doublePi, false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); - ctx.beginPath(); - ctx.arc(49.7, 11.3, 3.37, 0, doublePi, false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); - ctx.beginPath(); - ctx.arc(49.6, 10.6, 2.66, 0, doublePi, false); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(36.9, 98); - ctx.lineTo(47.5, 98); - ctx.quadraticCurveTo(47.5, 98, 47.5, 98); - ctx.lineTo(47.5, 154.5); - ctx.quadraticCurveTo(47.5, 154.5, 47.5, 154.5); - ctx.lineTo(36.9, 154.5); - ctx.quadraticCurveTo(36.9, 154.5, 36.9, 154.5); - ctx.lineTo(36.9, 98); - ctx.quadraticCurveTo(36.9, 98, 36.9, 98); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); - ctx.beginPath(); - ctx.moveTo(43.6, 0.372); - ctx.lineTo(87.3, 102); - ctx.lineTo(-0.714, 102); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - - ctx.save(); - ctx.setFillStyle(color); - ctx.beginPath(); - ctx.moveTo(43.6, 14.7); - ctx.lineTo(78.5, 96.6); - ctx.lineTo(8.07, 96.6); - ctx.closePath(); - ctx.fill(); - ctx.stroke(); - ctx.restore(); - } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java index ea8571cf529..0214a4ef9c3 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java @@ -8,7 +8,7 @@ public class MarkVectorGraphicsFactory { final MarkVectorGraphics result; switch (markType) { case BUOY: - result = new BuoyMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + result = createBuoyMarkVectorGraphics(markDTO); break; case STARTBOAT: case FINISHBOAT: @@ -18,9 +18,26 @@ public class MarkVectorGraphicsFactory { result = new LandMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); break; default: - result = new BuoyMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + result = createBuoyMarkVectorGraphics(markDTO); break; } return result; } + + private MarkVectorGraphics createBuoyMarkVectorGraphics(MarkDTO markDTO) { + final MarkVectorGraphics result; + if (markDTO.shape != null) { + if (Shape.CYLINDER.name().equalsIgnoreCase(markDTO.shape) && markDTO.pattern != null + && Pattern.CHECKERED.name().equalsIgnoreCase(markDTO.pattern)) { + result = new FinishFlagMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + } else if (Shape.CONICAL.name().equalsIgnoreCase(markDTO.shape)) { + result = new ConicalBuoyMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + } else { + result = new SimpleBuoyMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + } + } else { + result = new SimpleBuoyMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + } + return result; + } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/SimpleBuoyMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/SimpleBuoyMarkVectorGraphics.java new file mode 100644 index 00000000000..09c8be2a180 --- /dev/null +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/SimpleBuoyMarkVectorGraphics.java @@ -0,0 +1,93 @@ +package com.sap.sailing.gwt.ui.shared.racemap; + +import com.google.gwt.canvas.dom.client.Context2d; +import com.sap.sailing.domain.common.MarkType; + +public class SimpleBuoyMarkVectorGraphics extends AbstractMarkVectorGraphics implements MarkVectorGraphics { + + public SimpleBuoyMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { + super(type, color, shape, pattern); + } + + @Override + protected void drawMarkBody(Context2d ctx, boolean isSelected, String color) { + ctx.setStrokeStyle("rgba(0,0,0,0)"); + + ctx.save(); + ctx.setFillStyle(color); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); + + ctx.beginPath(); + ctx.arc(49.7, 12.8, 2.66, 0, doublePi, false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); + ctx.beginPath(); + ctx.arc(49.7, 11.3, 3.37, 0, doublePi, false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(color); + ctx.transform(12.5, 0, 0, 12.5, -578, 22.2); + ctx.beginPath(); + ctx.arc(49.6, 10.6, 2.66, 0, doublePi, false); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.transform(4.98, 0, 0, 10.8, -205, 50.4); + ctx.beginPath(); + ctx.moveTo(50.8, 9.84); + ctx.lineTo(48.5, 9.84); + ctx.lineTo(48.5, 1.44); + ctx.lineTo(50.8, 1.9); + ctx.lineTo(50.8, 9.84); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.transform(12.5, 0, 0, 12.5, -570, 22.2); + ctx.save(); + ctx.setFillStyle(color); + ctx.beginPath(); + ctx.moveTo(48.8, 3.82); + ctx.lineTo(48.8, -1.32); + ctx.lineTo(57, 1.05); + ctx.lineTo(48.8, 3.82); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + + ctx.save(); + ctx.setFillStyle(DEFAULT_MARK_BG_COLOR); + ctx.beginPath(); + ctx.moveTo(48.5, 4.16); + ctx.lineTo(48.5, -1.65); + ctx.lineTo(57.8, 1.03); + ctx.lineTo(48.5, 4.16); + ctx.closePath(); + ctx.moveTo(49, -0.994); + ctx.lineTo(49, 3.47); + ctx.lineTo(56.2, 1.07); + ctx.lineTo(49, -0.994); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); + ctx.restore(); + ctx.restore(); + } +} From b1de45ac4c26af8c846d8ace7fca50abd9eaf7b2 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Mon, 7 Nov 2016 11:49:14 +0100 Subject: [PATCH 27/32] removed redundant parameter MarkType from MarkVectorGraphicsFactory.getMarkVectorGraphics Change-Id: Idd76e591a1e79dc9f71e159692f5e469d8ca9097 --- .../gwt/ui/client/shared/racemap/CourseMarkOverlay.java | 2 +- .../gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java index 980a9dd1ab5..afc15bde793 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java @@ -67,7 +67,7 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { this.showBuoyZone = false; this.markScaleAndSizePerZoomCache = new HashMap>(); this.markVectorGraphicsFactory = new MarkVectorGraphicsFactory(); - this.markVectorGraphics = markVectorGraphicsFactory.getMarkVectorGraphics(markDTO.type, markDTO); + this.markVectorGraphics = markVectorGraphicsFactory.getMarkVectorGraphics(markDTO); setCanvasSize(50, 50); } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java index 0214a4ef9c3..96944a7951b 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java @@ -4,7 +4,8 @@ import com.sap.sailing.domain.common.MarkType; import com.sap.sailing.gwt.ui.shared.MarkDTO; public class MarkVectorGraphicsFactory { - public MarkVectorGraphics getMarkVectorGraphics(MarkType markType, MarkDTO markDTO) { + public MarkVectorGraphics getMarkVectorGraphics(MarkDTO markDTO) { + final MarkType markType = markDTO.type; final MarkVectorGraphics result; switch (markType) { case BUOY: From eb7cb9914f0b40215a6734e380f4cb10e8c86274 Mon Sep 17 00:00:00 2001 From: Steffen Schaefer Date: Mon, 7 Nov 2016 12:03:01 +0100 Subject: [PATCH 28/32] Fixed alignment of raced in fleets in Spectator.html --- java/com.sap.sailing.gwt.ui/Spectator.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/com.sap.sailing.gwt.ui/Spectator.css b/java/com.sap.sailing.gwt.ui/Spectator.css index 3e27b7f6304..6f55fe4310c 100644 --- a/java/com.sap.sailing.gwt.ui/Spectator.css +++ b/java/com.sap.sailing.gwt.ui/Spectator.css @@ -191,7 +191,8 @@ input.magnifier { margin: 5px 5px 5px 0; text-decoration: none; font-family: 'Open Sans', Arial, Verdana, sans-serif; - font-weight: 600 + font-weight: 600; + box-sizing: content-box; } .leaderboardGroupPanel-BoatClass { From 07b4a807fc85c5a4f9c8d771af453eaba0802e1a Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Mon, 7 Nov 2016 13:39:51 +0100 Subject: [PATCH 29/32] break the for loop when the startboat mark has been found; more formatting changes Change-Id: I0575610020f4fbbef00385115bfe4ed7fa1ffa77 --- .../shared/racemap/CourseMarkOverlay.java | 79 ++++++++++--------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java index afc15bde793..2d862b8e95d 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java @@ -127,34 +127,35 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { } } } - - private void setRotation() { - if (mark.type == MarkType.STARTBOAT || mark.type == MarkType.FINISHBOAT) { - Bearing lineBearing; - List lineMarkPositions = new ArrayList(); - MarkDTO firstMark = null; - MarkDTO secondMark = null; - for (WaypointDTO currentWaypoint : coursePositionsDTO.course.waypoints) { - if (currentWaypoint.passingInstructions == PassingInstruction.Line) { - Iterator marks = currentWaypoint.controlPoint.getMarks().iterator(); - firstMark = marks.next(); - if (marks.hasNext()) { - secondMark = marks.next(); - if (mark.getIdAsString().equals(firstMark.getIdAsString()) - || mark.getIdAsString().equals(secondMark.getIdAsString())) { - lineMarkPositions.add(firstMark.position); - lineMarkPositions.add(secondMark.position); - } - } - } - } - lineBearing = getLineBearing(lineMarkPositions); - if (lineBearing != null) { - setCanvasRotation(lineBearing.getDegrees()); - } - } - } - + + private void setRotation() { + if (mark.type == MarkType.STARTBOAT || mark.type == MarkType.FINISHBOAT) { + Bearing lineBearing; + List lineMarkPositions = new ArrayList(); + MarkDTO firstMark = null; + MarkDTO secondMark = null; + for (WaypointDTO currentWaypoint : coursePositionsDTO.course.waypoints) { + if (currentWaypoint.passingInstructions == PassingInstruction.Line) { + Iterator marks = currentWaypoint.controlPoint.getMarks().iterator(); + firstMark = marks.next(); + if (marks.hasNext()) { + secondMark = marks.next(); + if (mark.getIdAsString().equals(firstMark.getIdAsString()) + || mark.getIdAsString().equals(secondMark.getIdAsString())) { + lineMarkPositions.add(firstMark.position); + lineMarkPositions.add(secondMark.position); + break; + } + } + } + } + lineBearing = getLineBearing(lineMarkPositions); + if (lineBearing != null) { + setCanvasRotation(lineBearing.getDegrees()); + } + } + } + private boolean isMarkWithBuoyZone(MarkDTO mark) { return mark.type == null || mark.type == MarkType.BUOY || mark.type == MarkType.STARTBOAT || mark.type == MarkType.FINISHBOAT || mark.type == MarkType.LANDMARK; @@ -190,17 +191,17 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { return new Util.Pair(markSizeScaleFactor, Size.newInstance(markHeightInPixel * 2.0, markHeightInPixel * 2.0)); } - private Bearing getLineBearing(List markPositions) { - Bearing result = null; - if (markPositions.size() > 1) { - Position firstPosition = markPositions.get(0); - Position secondPosition = markPositions.get(1); - if (firstPosition != null) { - result = firstPosition.getBearingGreatCircle(secondPosition); - } - } - return result; - } + private Bearing getLineBearing(List markPositions) { + Bearing result = null; + if (markPositions.size() > 1) { + Position firstPosition = markPositions.get(0); + Position secondPosition = markPositions.get(1); + if (firstPosition != null) { + result = firstPosition.getBearingGreatCircle(secondPosition); + } + } + return result; + } private String getTitle() { return mark.getName(); From a4e44e4ad455e91c828dc8776e4c16cfbe6e6e71 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Mon, 7 Nov 2016 14:36:59 +0100 Subject: [PATCH 30/32] changed the rotation logic and made sure to update the course position data into the mark overlay Change-Id: I3065e4fb10f02cc2fbe6a683e07233ad0804e2d3 --- .../shared/racemap/CourseMarkOverlay.java | 56 +++---------------- .../gwt/ui/client/shared/racemap/RaceMap.java | 1 + .../racemap/AbstractMarkVectorGraphics.java | 8 +++ .../racemap/BoatMarkVectorGraphics.java | 50 ++++++++++++++++- .../ui/shared/racemap/MarkVectorGraphics.java | 12 ++++ .../racemap/MarkVectorGraphicsFactory.java | 2 +- 6 files changed, 80 insertions(+), 49 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java index 2d862b8e95d..8645ad390d9 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/CourseMarkOverlay.java @@ -1,9 +1,6 @@ package com.sap.sailing.gwt.ui.client.shared.racemap; -import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; -import java.util.List; import java.util.Map; import com.google.gwt.canvas.dom.client.Context2d; @@ -15,12 +12,10 @@ import com.google.gwt.maps.client.base.Size; import com.sap.sailing.domain.common.Bearing; import com.sap.sailing.domain.common.Distance; import com.sap.sailing.domain.common.MarkType; -import com.sap.sailing.domain.common.PassingInstruction; import com.sap.sailing.domain.common.Position; import com.sap.sailing.domain.common.impl.MeterDistance; import com.sap.sailing.gwt.ui.shared.CoursePositionsDTO; import com.sap.sailing.gwt.ui.shared.MarkDTO; -import com.sap.sailing.gwt.ui.shared.WaypointDTO; import com.sap.sailing.gwt.ui.shared.racemap.CanvasOverlayV3; import com.sap.sailing.gwt.ui.shared.racemap.MarkVectorGraphics; import com.sap.sailing.gwt.ui.shared.racemap.MarkVectorGraphicsFactory; @@ -35,7 +30,7 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { */ private final MarkDTO mark; - private final CoursePositionsDTO coursePositionsDTO; + private CoursePositionsDTO coursePositionsDTO; private Position position; @@ -99,7 +94,6 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { Context2d context2d = getCanvas().getContext2d(); // draw the course mark markVectorGraphics.drawMarkToCanvas(context2d, isSelected, canvasWidth, canvasHeight, markSizeScaleFactor); - setRotation(); // draw the buoy zone if (showBuoyZone && isMarkWithBuoyZone(mark) && buoyZoneRadiusInPixel > MIN_BUOYZONE_RADIUS_IN_PX) { CssColor grayTransparentColor = CssColor.make("rgba(37,158,255,0.75)"); @@ -119,6 +113,10 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { lastWidth = canvasWidth; lastHeight = canvasHeight; } + final Bearing rotation = markVectorGraphics.getRotationInDegrees(coursePositionsDTO); + if (rotation != null) { + setCanvasRotation(rotation.getDegrees()); + } Point buoyPositionInPx = mapProjection.fromLatLngToDivPixel(coordinateSystem.toLatLng(position)); if (showBuoyZone && isMarkWithBuoyZone(mark) && buoyZoneRadiusInPixel > MIN_BUOYZONE_RADIUS_IN_PX) { setCanvasPosition(buoyPositionInPx.getX() - buoyZoneRadiusInPixel, buoyPositionInPx.getY() - buoyZoneRadiusInPixel); @@ -128,34 +126,6 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { } } - private void setRotation() { - if (mark.type == MarkType.STARTBOAT || mark.type == MarkType.FINISHBOAT) { - Bearing lineBearing; - List lineMarkPositions = new ArrayList(); - MarkDTO firstMark = null; - MarkDTO secondMark = null; - for (WaypointDTO currentWaypoint : coursePositionsDTO.course.waypoints) { - if (currentWaypoint.passingInstructions == PassingInstruction.Line) { - Iterator marks = currentWaypoint.controlPoint.getMarks().iterator(); - firstMark = marks.next(); - if (marks.hasNext()) { - secondMark = marks.next(); - if (mark.getIdAsString().equals(firstMark.getIdAsString()) - || mark.getIdAsString().equals(secondMark.getIdAsString())) { - lineMarkPositions.add(firstMark.position); - lineMarkPositions.add(secondMark.position); - break; - } - } - } - } - lineBearing = getLineBearing(lineMarkPositions); - if (lineBearing != null) { - setCanvasRotation(lineBearing.getDegrees()); - } - } - } - private boolean isMarkWithBuoyZone(MarkDTO mark) { return mark.type == null || mark.type == MarkType.BUOY || mark.type == MarkType.STARTBOAT || mark.type == MarkType.FINISHBOAT || mark.type == MarkType.LANDMARK; @@ -191,18 +161,6 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { return new Util.Pair(markSizeScaleFactor, Size.newInstance(markHeightInPixel * 2.0, markHeightInPixel * 2.0)); } - private Bearing getLineBearing(List markPositions) { - Bearing result = null; - if (markPositions.size() > 1) { - Position firstPosition = markPositions.get(0); - Position secondPosition = markPositions.get(1); - if (firstPosition != null) { - result = firstPosition.getBearingGreatCircle(secondPosition); - } - } - return result; - } - private String getTitle() { return mark.getName(); } @@ -214,6 +172,10 @@ public class CourseMarkOverlay extends CanvasOverlayV3 { public void setShowBuoyZone(boolean showBuoyZone) { this.showBuoyZone = showBuoyZone; } + + public void setCourse(CoursePositionsDTO coursePositionsDTO) { + this.coursePositionsDTO = coursePositionsDTO; + } public MarkDTO getMark() { return mark; diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/RaceMap.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/RaceMap.java index dddbdd0f0b6..4b48619d7c3 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/RaceMap.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/shared/racemap/RaceMap.java @@ -1138,6 +1138,7 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe courseMarkOverlay.setShowBuoyZone(settings.getHelpLinesSettings().isVisible(HelpLineTypes.BUOYZONE)); courseMarkOverlay.setBuoyZoneRadius(settings.getBuoyZoneRadius()); courseMarkOverlay.setSelected(isSelected); + courseMarkOverlay.setCourse(courseDTO); courseMarkOverlay.draw(); toRemoveCourseMarks.remove(markDTO.getName()); } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java index 342af46b2e7..c2fb3578a39 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/AbstractMarkVectorGraphics.java @@ -2,9 +2,11 @@ package com.sap.sailing.gwt.ui.shared.racemap; import com.google.gwt.canvas.dom.client.CanvasGradient; import com.google.gwt.canvas.dom.client.Context2d; +import com.sap.sailing.domain.common.Bearing; import com.sap.sailing.domain.common.Distance; import com.sap.sailing.domain.common.MarkType; import com.sap.sailing.domain.common.impl.MeterDistance; +import com.sap.sailing.gwt.ui.shared.CoursePositionsDTO; /** * A class for course mark graphics based on SVG graphics drawn to a HTML5 canvas @@ -188,4 +190,10 @@ public abstract class AbstractMarkVectorGraphics implements MarkVectorGraphics { } protected abstract void drawMarkBody(Context2d ctx, boolean isSelected, String color); + + @Override + public Bearing getRotationInDegrees(CoursePositionsDTO coursePositionsDTO) { + // by default, no rotation for marks + return null; + } } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java index 7cd3f934692..9668f195925 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/BoatMarkVectorGraphics.java @@ -1,9 +1,19 @@ package com.sap.sailing.gwt.ui.shared.racemap; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + import com.google.gwt.canvas.dom.client.Context2d; +import com.sap.sailing.domain.common.Bearing; import com.sap.sailing.domain.common.Distance; import com.sap.sailing.domain.common.MarkType; +import com.sap.sailing.domain.common.PassingInstruction; +import com.sap.sailing.domain.common.Position; import com.sap.sailing.domain.common.impl.MeterDistance; +import com.sap.sailing.gwt.ui.shared.CoursePositionsDTO; +import com.sap.sailing.gwt.ui.shared.MarkDTO; +import com.sap.sailing.gwt.ui.shared.WaypointDTO; public class BoatMarkVectorGraphics extends AbstractMarkVectorGraphics { @@ -12,13 +22,15 @@ public class BoatMarkVectorGraphics extends AbstractMarkVectorGraphics { private final static double BOAT_MARK_SELECTION_SCALE = 3.5; private final static double BOAT_MARK_SELECTION_TRANSLATE_X = -10; private final static double BOAT_MARK_SELECTION_TRANSLATE_Y = -30; + private final String markIdAsString; - public BoatMarkVectorGraphics(MarkType type, String color, String shape, String pattern) { + public BoatMarkVectorGraphics(MarkType type, String color, String shape, String pattern, String markIdAsString) { super(type, color, shape, pattern); this.anchorPointX = BOAT_MARK_HEIGHT_IN_METERS.getMeters() / 2; this.anchorPointY = BOAT_MARK_WIDTH_IN_METERS.getMeters() / 2; this.markHeightInMeters = BOAT_MARK_HEIGHT_IN_METERS; this.markWidthInMeters = BOAT_MARK_WIDTH_IN_METERS; + this.markIdAsString = markIdAsString; } protected void setUpScaleAndTranslateForMarkSelection(Context2d ctx) { @@ -85,4 +97,40 @@ public class BoatMarkVectorGraphics extends AbstractMarkVectorGraphics { ctx.fill(); ctx.beginPath(); } + + @Override + public Bearing getRotationInDegrees(CoursePositionsDTO coursePositionsDTO) { + List lineMarkPositions = new ArrayList(); + MarkDTO firstMark = null; + MarkDTO secondMark = null; + for (WaypointDTO currentWaypoint : coursePositionsDTO.course.waypoints) { + if (currentWaypoint.passingInstructions == PassingInstruction.Line) { + Iterator marks = currentWaypoint.controlPoint.getMarks().iterator(); + firstMark = marks.next(); + if (marks.hasNext()) { + secondMark = marks.next(); + if (markIdAsString.equals(firstMark.getIdAsString()) + || markIdAsString.equals(secondMark.getIdAsString())) { + lineMarkPositions.add(firstMark.position); + lineMarkPositions.add(secondMark.position); + break; + } + } + } + } + return getLineBearing(lineMarkPositions); + } + + private Bearing getLineBearing(List markPositions) { + Bearing result = null; + if (markPositions.size() > 1) { + Position firstPosition = markPositions.get(0); + Position secondPosition = markPositions.get(1); + if (firstPosition != null) { + result = firstPosition.getBearingGreatCircle(secondPosition); + } + } + return result; + } + } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java index f7296e45a3a..cdf8ad1366d 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphics.java @@ -1,7 +1,9 @@ package com.sap.sailing.gwt.ui.shared.racemap; import com.google.gwt.canvas.dom.client.Context2d; +import com.sap.sailing.domain.common.Bearing; import com.sap.sailing.domain.common.Distance; +import com.sap.sailing.gwt.ui.shared.CoursePositionsDTO; public interface MarkVectorGraphics { void drawMarkToCanvas(Context2d ctx, boolean isSelected, double width, double height, double scaleFactor); @@ -9,4 +11,14 @@ public interface MarkVectorGraphics { Distance getMarkHeight(); Distance getMarkWidth(); + + /** + * If this graphical representation requires different rotations based on its state, this method can be implemented + * to compute the rotation desired. It is called after the drawing to the canvas, if it was necessary, has been + * updated. + * + * @return {@code null} if no rotation is desired; this will save the application of a CSS rotation; otherwise, a + * rotation as an angle + */ + Bearing getRotationInDegrees(CoursePositionsDTO coursePositionsDTO); } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java index 96944a7951b..cfb6aa0acce 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/shared/racemap/MarkVectorGraphicsFactory.java @@ -13,7 +13,7 @@ public class MarkVectorGraphicsFactory { break; case STARTBOAT: case FINISHBOAT: - result = new BoatMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); + result = new BoatMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern, markDTO.getIdAsString()); break; case LANDMARK: result = new LandMarkVectorGraphics(markDTO.type, markDTO.color, markDTO.shape, markDTO.pattern); From 606a29cffbc910c0102f5d0a9bcf47365cb858e3 Mon Sep 17 00:00:00 2001 From: Kai Boernert Date: Tue, 8 Nov 2016 15:46:17 +0100 Subject: [PATCH 31/32] properly handle the case, if no distance is yet available and return null, as the consumers are already checking for null values correctly --- .../sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java index 3d4056386e1..87a01c464e6 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java @@ -1288,7 +1288,14 @@ public class LeaderboardPanel extends SimplePanel implements Component { @Override public Double get(LeaderboardRowDTO row) { - return row.getDistanceTraveledInMeters(getRaceColumnName()).getMeters(); + Distance distanceForRaceColumn = row.getDistanceTraveledInMeters(getRaceColumnName()); + final Double distance; + if(distanceForRaceColumn != null){ + distance = distanceForRaceColumn.getMeters(); + } else { + distance = null; + } + return distance; } } From 1df564bf9a5a81df9618f701c539d31ed77bbcae Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 8 Nov 2016 18:16:25 +0100 Subject: [PATCH 32/32] more compact implementation using ternary expression Change-Id: Ia683af42fce1be66b6289916d27bd1e957cfd933 --- .../sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java index 87a01c464e6..e85b336979c 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/leaderboard/LeaderboardPanel.java @@ -1289,13 +1289,7 @@ public class LeaderboardPanel extends SimplePanel implements Component