/**
 * This program and the accompanying materials
 * are made available under the terms of the License
 * which accompanies this distribution in the file LICENSE.txt
 */
package com.archimatetool.editor.diagram.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.widgets.Display;


/**
 * Gradient Utils for Figures
 * 
 * @author Phillip Beauvoir
 */
public class GradientUtils {

    /**
     * Gradient Direction
     */
    public static enum Direction {
        LEFT, RIGHT, TOP, BOTTOM
    }

    /**
     * Create a Pattern class with consideration to the scale of the Graphics class
     * Adapted from https://www.eclipse.org/forums/index.php?t=msg&th=198946&goto=894610&#msg_894610
     */
    public static Pattern createScaledPattern(Graphics graphics, Device device, float x1, float y1, float x2, float y2, Color color1,
            int alpha1, Color color2, int alpha2) {
        
        double scale = graphics.getAbsoluteScale();
        
        return new Pattern(device, (int)(x1 * scale), (int)(y1 * scale), (int)(x2 * scale), (int)(y2 * scale), color1, alpha1, color2,
                alpha2);
    }

    /**
     * Create a Pattern class with consideration to the scale of the Graphics class
     * Adapted from https://www.eclipse.org/forums/index.php?t=msg&th=198946&goto=894610&#msg_894610
     */
    public static Pattern createScaledPattern(Graphics graphics, Device device, float x1, float y1, float x2, float y2, Color color1,
            Color color2) {
        
        double scale = graphics.getAbsoluteScale();
        
        return new Pattern(device, (int)(x1 * scale), (int)(y1 * scale), (int)(x2 * scale), (int)(y2 * scale), color1, color2);
    }
    
    /**
     * Create a Pattern class with consideration to the scale of the Graphics class using the default gradient direction and default gradient end color
     */
    public static Pattern createScaledPattern(Graphics graphics, Rectangle r, Color color) {
        Direction direction = Direction.TOP;
        Color endColor = ColorConstants.white;

        switch(direction) {
            case LEFT:
                return createScaledPattern(graphics, Display.getDefault(), r.x, r.y, r.getRight().x, r.y, color, endColor);
            case RIGHT:
                return createScaledPattern(graphics, Display.getDefault(), r.getRight().x, r.y, r.x, r.y, color, endColor);
            default:
            case TOP:
                return createScaledPattern(graphics, Display.getDefault(), r.x, r.y, r.x, r.getBottomRight().y, color, endColor);
            case BOTTOM:
                return createScaledPattern(graphics, Display.getDefault(), r.x, r.getBottomRight().y, r.x, r.y, color, endColor);
        }
    }

}

@@ -685,16 +685,21 @@
 %0A       
+ TOP,
  LEFT, R
@@ -703,21 +703,16 @@
 , RIGHT,
- TOP,
  BOTTOM%0A
@@ -2271,59 +2271,291 @@
 te;%0A
-%0A        switch(direction) %7B%0A            case LEFT:
+        %0A        // Gradienting all the way to pure white is too much, this extends the gradient area to cover that%0A        float deltaFactor = 0.15f;%0A%0A        switch(direction) %7B%0A            case TOP:%0A            default:%0A                int delta = (int) (r.height * deltaFactor); 
 %0A   
@@ -2635,36 +2635,45 @@
 .x, r.y,
+ r.x,
  r.get
-Right().x, r.y
+Bottom().y + delta
 , color,
@@ -2700,19 +2700,87 @@
     
-case RIGHT:
+%0A            case LEFT:%0A                delta = (int) (r.width * deltaFactor); 
 %0A   
@@ -2850,16 +2850,26 @@
 fault(),
+ r.x, r.y,
  r.getRi
@@ -2875,26 +2875,24 @@
 ight().x
-, r.y, r.x
+ + delta
 , r.y, c
@@ -2916,32 +2916,24 @@
             
-default:
 %0A           
@@ -2930,37 +2930,95 @@
            case 
-TOP
+RIGHT
 :%0A
+                delta = (int) (r.width * deltaFactor); %0A
                 
@@ -3082,39 +3082,41 @@
 , r.
-x, r.y, r.x, r.getBottomRight()
+getRight().x, r.y, r.x - delta, r
 .y, 
@@ -3125,32 +3125,45 @@
 lor, endColor);%0A
+            %0A
             case
@@ -3171,16 +3171,73 @@
 BOTTOM:%0A
+                delta = (int) (r.height * deltaFactor); %0A
         
@@ -3319,21 +3319,16 @@
 etBottom
-Right
 ().y, r.
@@ -3329,24 +3329,32 @@
 .y, r.x, r.y
+ - delta
 , color, end

Add delta factor to GradientUtils