internal static CompositeHelper Create(java.awt.Composite comp, Graphics graphics){ if (comp is java.awt.AlphaComposite) { java.awt.AlphaComposite alphaComp = (java.awt.AlphaComposite)comp; float alpha = alphaComp.getAlpha(); switch (alphaComp.getRule()) { case java.awt.AlphaComposite.CLEAR: graphics.CompositingMode = CompositingMode.SourceCopy; return new ClearCompositeHelper(); case java.awt.AlphaComposite.SRC: graphics.CompositingMode = CompositingMode.SourceCopy; break; case java.awt.AlphaComposite.SRC_OVER: graphics.CompositingMode = CompositingMode.SourceOver; break; case java.awt.AlphaComposite.DST: graphics.CompositingMode = CompositingMode.SourceOver; alpha = 0.0F; break; default: graphics.CompositingMode = CompositingMode.SourceOver; Console.Error.WriteLine("AlphaComposite with Rule " + alphaComp.getRule() + " not supported."); break; } if (alpha == 1.0) { return new CompositeHelper(); } else { return new AlphaCompositeHelper(alpha); } } else { graphics.CompositingMode = CompositingMode.SourceOver; Console.Error.WriteLine("Composite not supported: " + comp.GetType().FullName); return new CompositeHelper(); } }
internal static Bitmap ConvertImage(java.awt.Image img) { if (img is BufferedImage) { return ((BufferedImage)img).getBitmap(); } if (img is NetVolatileImage) { return ((NetVolatileImage)img).bitmap; } if (img is sun.awt.image.ToolkitImage) { sun.awt.image.ImageRepresentation ir = ((sun.awt.image.ToolkitImage)img).getImageRep(); // start the production and wait if not produce the image lock( ir ) { ir.prepare(null); while ( ir.getBufferedImage() == null ) { ir.wait(); } } return ir.getBufferedImage().getBitmap(); } if (img is NoImage) { return null; } Console.WriteLine(new System.Diagnostics.StackTrace()); throw new NotImplementedException("Image class:" + img.GetType().FullName); }
internal static Image ConvertImage(java.awt.Image img) { if (img is BufferedImage) { return ((BufferedImage)img).getBitmap(); } if (img is NetVolatileImage) { return ((NetVolatileImage)img).bitmap; } if (img is NetProducerImage) { return ((NetProducerImage)img).getBitmap(); } if (img is NoImage) { return null; } Console.WriteLine(new System.Diagnostics.StackTrace()); throw new NotImplementedException("Image class:" + img.GetType().FullName); }
public override void setPaint(java.awt.Paint paint) { if (paint is java.awt.Color) { setColor((java.awt.Color)paint); return; } if (paint == null || this.javaPaint == paint) { return; } this.javaPaint = paint; if (paint is java.awt.GradientPaint) { java.awt.GradientPaint gradient = (java.awt.GradientPaint)paint; LinearGradientBrush linear; if (gradient.isCyclic()) { linear = new LinearGradientBrush( J2C.ConvertPoint(gradient.getPoint1()), J2C.ConvertPoint(gradient.getPoint2()), composite.GetColor(gradient.getColor1()), composite.GetColor(gradient.getColor2())); } else { //HACK because .NET does not support continue gradient like Java else Tile Gradient //that we receize the rectangle very large (factor z) and set 4 color values // a exact solution will calculate the size of the Graphics with the current transform Color color1 = composite.GetColor(gradient.getColor1()); Color color2 = composite.GetColor(gradient.getColor2()); float x1 = (float)gradient.getPoint1().getX(); float x2 = (float)gradient.getPoint2().getX(); float y1 = (float)gradient.getPoint1().getY(); float y2 = (float)gradient.getPoint2().getY(); float diffX = x2 - x1; float diffY = y2 - y1; const float z = 60; //HACK zoom factor, with a larger factor .NET will make the gradient wider. linear = new LinearGradientBrush( new PointF(x1 - z * diffX, y1 - z * diffY), new PointF(x2 + z * diffX, y2 + z * diffY), color1, color1); ColorBlend colorBlend = new ColorBlend(4); Color[] colors = colorBlend.Colors; colors[0] = colors[1] = color1; colors[2] = colors[3] = color2; float[] positions = colorBlend.Positions; positions[1] = z / (2 * z + 1); positions[2] = (z + 1) / (2 * z + 1); positions[3] = 1.0f; linear.InterpolationColors = colorBlend; } linear.WrapMode = WrapMode.TileFlipXY; brush = linear; pen.Brush = brush; return; } if (paint is java.awt.TexturePaint) { java.awt.TexturePaint texture = (java.awt.TexturePaint)paint; brush = new TextureBrush( J2C.ConvertImage(texture.getImage()), J2C.ConvertRect(texture.getAnchorRect()), composite.GetImageAttributes()); pen.Brush = brush; return; } if (paint is java.awt.LinearGradientPaint) { java.awt.LinearGradientPaint gradient = (java.awt.LinearGradientPaint)paint; PointF start = J2C.ConvertPoint(gradient.getStartPoint()); PointF end = J2C.ConvertPoint(gradient.getEndPoint()); java.awt.Color[] javaColors = gradient.getColors(); ColorBlend colorBlend; Color[] colors; bool noCycle = gradient.getCycleMethod() == java.awt.MultipleGradientPaint.CycleMethod.NO_CYCLE; if (noCycle) { //HACK because .NET does not support continue gradient like Java else Tile Gradient //that we receize the rectangle very large (factor z) and set 2 additional color values //an exact solution will calculate the size of the Graphics with the current transform float diffX = end.X - start.X; float diffY = end.Y - start.Y; SizeF size = GetSize(); //HACK zoom factor, with a larger factor .NET will make the gradient wider. float z = Math.Min(10, Math.Max(size.Width / diffX, size.Height / diffY)); start.X -= z * diffX; start.Y -= z * diffY; end.X += z * diffX; end.Y += z * diffY; colorBlend = new ColorBlend(javaColors.Length + 2); colors = colorBlend.Colors; float[] fractions = gradient.getFractions(); float[] positions = colorBlend.Positions; for (int i = 0; i < javaColors.Length; i++) { colors[i + 1] = composite.GetColor(javaColors[i]); positions[i + 1] = (z + fractions[i]) / (2 * z + 1); } colors[0] = colors[1]; colors[colors.Length - 1] = colors[colors.Length - 2]; positions[positions.Length - 1] = 1.0f; } else { colorBlend = new ColorBlend(javaColors.Length); colors = colorBlend.Colors; colorBlend.Positions = gradient.getFractions(); for (int i = 0; i < javaColors.Length; i++) { colors[i] = composite.GetColor(javaColors[i]); } } LinearGradientBrush linear = new LinearGradientBrush(start, end, colors[0], colors[colors.Length - 1]); linear.InterpolationColors = colorBlend; switch (gradient.getCycleMethod().ordinal()) { case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.NO_CYCLE: case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.REFLECT: linear.WrapMode = WrapMode.TileFlipXY; break; case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.REPEAT: linear.WrapMode = WrapMode.Tile; break; } brush = linear; pen.Brush = brush; return; } throw new NotImplementedException("setPaint("+paint.GetType().FullName+")"); }
public override void setPaint(java.awt.Paint paint) { if (paint is java.awt.Color) { setColor((java.awt.Color)paint); return; } if (paint == null || this.javaPaint == paint) { return; } this.javaPaint = paint; if (paint is java.awt.GradientPaint) { java.awt.GradientPaint gradient = (java.awt.GradientPaint)paint; LinearGradientBrush linear; if (gradient.isCyclic()) { linear = new LinearGradientBrush( J2C.ConvertPoint(gradient.getPoint1()), J2C.ConvertPoint(gradient.getPoint2()), J2C.ConvertColor(gradient.getColor1()), J2C.ConvertColor(gradient.getColor2())); } else { //HACK because .NET does not support continue gradient like Java else Tile Gradient //that we receize the rectangle very large (factor z) and set 4 color values // a exact solution will calculate the size of the Graphics with the current transform Color color1 = J2C.ConvertColor(gradient.getColor1()); Color color2 = J2C.ConvertColor(gradient.getColor2()); float x1 = (float)gradient.getPoint1().getX(); float x2 = (float)gradient.getPoint2().getX(); float y1 = (float)gradient.getPoint1().getY(); float y2 = (float)gradient.getPoint2().getY(); float diffX = x2 - x1; float diffY = y2 - y1; const float z = 60; //HACK zoom factor, with a larger factor .NET will make the gradient wider. linear = new LinearGradientBrush( new PointF(x1 - z * diffX, y1 - z * diffY), new PointF(x2 + z * diffX, y2 + z * diffY), color1, color1); ColorBlend colorBlend = new ColorBlend(4); Color[] colors = colorBlend.Colors; colors[0] = colors[1] = color1; colors[2] = colors[3] = color2; float[] positions = colorBlend.Positions; positions[1] = z / (2 * z + 1); positions[2] = (z + 1) / (2 * z + 1); positions[3] = 1.0f; linear.InterpolationColors = colorBlend; } linear.WrapMode = WrapMode.TileFlipXY; brush = linear; pen.Brush = brush; return; } if (paint is java.awt.TexturePaint) { java.awt.TexturePaint texture = (java.awt.TexturePaint)paint; brush = new TextureBrush( J2C.ConvertImage(texture.getImage()), J2C.ConvertRect(texture.getAnchorRect())); pen.Brush = brush; return; } throw new NotImplementedException("setPaint("+paint.GetType().FullName+")"); }