예제 #1
0
        /// <summary> Draws the ellipse.
        /// The draw-position is translated by (-offsetX,-offsetY)
        /// and scaled by (factorX,factorY).
        /// </summary>
        /// <param name="canvas">The canvas to draw the arrow on
        /// </param>
        /// <param name="offsetX">Translation-Vector's negative x-component
        /// </param>
        /// <param name="offsetY">Translation-Vector's negative y-component
        /// </param>
        /// <param name="factorX">Scaling-Vector*s x-component
        /// </param>
        /// <param name="factorY">Scaling-Vector*s y-component
        ///
        /// </param>
        public virtual void  draw(Graphics2D canvas, int offsetX, int offsetY, double factorX, double factorY)
        {
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int x = (int)System.Math.Round((this.x - offsetX) * factorX);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int y = (int)System.Math.Round((this.y - offsetY) * factorY);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int width = (int)System.Math.Round(this.width * factorX);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int height = (int)System.Math.Round(this.height * factorY);

            // set colors and draw
            canvas.setColor(bgcolor);
            canvas.fillOval(x, y, width + 1, height + 1);
            canvas.setColor(bordercolor);
            canvas.drawOval(x, y, width, height);
            // draw short-description
            canvas.setColor(System.Drawing.Color.Black);
            //UPGRADE_TODO: The equivalent in .NET for method 'java.awt.Color.getRGB' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
            if (bgcolor.ToArgb() == System.Drawing.Color.Black.ToArgb())
            {
                canvas.setColor(System.Drawing.Color.White);
            }
            if (height > 10)
            {
                System.Drawing.Point textpos = calculateTextPosition(text, canvas, width, height);
                canvas.drawString(text, (int)textpos.X + x, (int)textpos.Y + y);
            }
        }
예제 #2
0
        public virtual void  draw(Graphics2D canvas, int offsetX, int offsetY, double factorX, double factorY)
        {
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int ourX = (int)System.Math.Round((x - offsetX) * factorX);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int ourY = (int)System.Math.Round((y - offsetY) * factorY);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int ourWidth = (int)System.Math.Round(width * factorX);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int ourHeight = (int)System.Math.Round(height * factorY);

            //UPGRADE_WARNING: Narrowing conversions may produce unexpected results in C#. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042"'
            int[] xpoints = new int[] { ourX + (int)(ourWidth * .25), ourX + (int)(ourWidth * .75), ourX + ourWidth, ourX };
            int[] ypoints = new int[] { ourY, ourY, ourY + ourHeight, ourY + ourHeight };
            canvas.setColor(bgcolor);
            canvas.fillPolygon(xpoints, ypoints, 4);
            canvas.setColor(bordercolor);
            canvas.drawPolygon(xpoints, ypoints, 4);
            canvas.setColor(System.Drawing.Color.Black);
            //UPGRADE_TODO: The equivalent in .NET for method 'java.awt.Color.getRGB' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
            if (bgcolor.ToArgb() == System.Drawing.Color.Black.ToArgb())
            {
                canvas.setColor(System.Drawing.Color.White);
            }
            if (ourHeight > 10)
            {
                System.Drawing.Point textpos = calculateTextPosition(text, canvas, ourWidth, ourHeight);
                canvas.drawString(text, (int)textpos.X + ourX, (int)textpos.Y + ourY);
            }
        }
예제 #3
0
        /// <summary> Adds a ConnectorLine into the container
        /// </summary>
        /// <param name="p">the primitive which should become added
        ///
        /// </param>
        public virtual void  addPrimitive(ConnectorLine c)
        {
            lines.add(c);
            Graphics2D gr = (Graphics2D)Graphics;

            if (gr == null)
            {
                return;
            }
            drawPrimitive(c, gr);
        }
예제 #4
0
        /// <summary> Adds a Shape into the container
        /// </summary>
        /// <param name="p">the primitive which should become added
        ///
        /// </param>
        public virtual void  addPrimitive(Shape s)
        {
            shapes.add(s);
            if (s.width + s.x > graphwidth)
            {
                graphwidth = s.width + s.x;
            }
            if (s.height + s.y > graphheight)
            {
                graphheight = s.height + s.y;
            }
            Graphics2D gr = (Graphics2D)Graphics;

            if (gr == null)
            {
                return;
            }
            drawPrimitive(s, gr);
        }
예제 #5
0
        public virtual void  paint(System.Drawing.Graphics g)
        {
            Graphics2D gr = (Graphics2D)g;

            gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            gr.setFont(font);
            Iterator itshapes = shapes.iterator();
            Iterator itarrows = lines.iterator();

            while (itshapes.hasNext())
            {
                Shape s = (Shape)itshapes.next();
                drawPrimitive(s, gr);
            }
            while (itarrows.hasNext())
            {
                ConnectorLine l = (ConnectorLine)itarrows.next();
                drawPrimitive(l, gr);
            }
        }
예제 #6
0
 public abstract void  draw(Graphics2D canvas, int offsetX, int offsetY);
예제 #7
0
 public abstract void  draw(Graphics2D canvas, double factorX, double factorY);
예제 #8
0
 public abstract void draw(Graphics2D canvas, double factorX, double factorY);
예제 #9
0
 public abstract void draw(Graphics2D canvas, int offsetX, int offsetY, double factorX, double factorY);
예제 #10
0
        /// <summary> Draws an arrow from the From-Shape to the To-Shape
        /// with the choosen color. The draw-position is translated
        /// by (-offsetX,-offsetY) and then scaled by (factorX,factorY).
        /// </summary>
        /// <param name="canvas">The canvas to draw the arrow on
        /// </param>
        /// <param name="offsetX">Translation-Vector's negative x-component
        /// </param>
        /// <param name="offsetY">Translation-Vector's negative y-component
        /// </param>
        /// <param name="factorX">Scaling-Vector*s x-component
        /// </param>
        /// <param name="factorY">Scaling-Vector*s y-component
        /// 
        /// </param>
        public virtual void draw(Graphics2D canvas, int offsetX, int offsetY, double factorX, double factorY)
        {
            canvas.setColor(color);

            /* angleFromTo is this angle ;)
            * (between -PI;+PI)
            *                     TO
            *    ----------------(x)-------------------
            *                   /
            *                 /)
            *               / @ )
            *    --------(x)---------------------------
            *            FROM
            */
            double angleFromTo = System.Math.Atan2(- to.Y + from.Y, to.X - from.X);

            /* angleToFrom is this angle ;)
            * (between -PI;+PI)
            *                     TO
            *    ----------------(x)-------------------
            *               ( @ /
            *                (/
            *               /
            *    --------(x)---------------------------
            *            FROM
            */
            double angleToFrom;
            if (angleFromTo > 0)
            {
                angleToFrom = angleFromTo - System.Math.PI;
            }
            else
            {
                angleToFrom = angleFromTo + System.Math.PI;
            }
            System.Drawing.Point pfrom = from.calculateIntersection(angleFromTo);
            System.Drawing.Point pto = to.calculateIntersection(angleToFrom);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            System.Drawing.Point parrow1 = new System.Drawing.Point((int) System.Math.Round(6 * System.Math.Cos(angleToFrom + System.Math.PI / 4.0)), (int) System.Math.Round(6 * System.Math.Sin(angleToFrom + System.Math.PI / 4.0)));
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            System.Drawing.Point parrow2 = new System.Drawing.Point((int) System.Math.Round(6 * System.Math.Cos(angleToFrom - System.Math.PI / 4.0)), (int) System.Math.Round(6 * System.Math.Sin(angleToFrom - System.Math.PI / 4.0)));
            pfrom.X -= offsetX;
            pfrom.Y -= offsetY;
            pto.X -= offsetX;
            pto.Y -= offsetY;
            pfrom.X *= (int) (factorX);
            pfrom.Y *= (int) (factorY);
            pto.X *= (int) (factorX);
            pto.Y *= (int) (factorY);
            parrow1.X *= (int) (factorX);
            parrow1.Y *= (int) (factorY);
            parrow2.X *= (int) (factorX);
            parrow2.Y *= (int) (factorY);

            //calculate a good line width
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int linewidth = (int) System.Math.Round(1 * System.Math.Min(factorX, factorY));
            if (linewidth == 0)
                linewidth = 1;
            canvas.setStroke(new BasicStroke(linewidth));

            //draw the arrow
            canvas.drawLine(pfrom.X, pfrom.Y, pto.X, pto.Y);
            canvas.drawLine(pto.X + parrow1.X, pto.Y - parrow1.Y, pto.X, pto.Y);
            canvas.drawLine(pto.X + parrow2.X, pto.Y - parrow2.Y, pto.X, pto.Y);
        }
예제 #11
0
 public abstract void draw(Graphics2D canvas, int offsetX, int offsetY);
예제 #12
0
 /// <summary> Draws the ellipse.
 /// The draw-position is translated by (-offsetX,-offsetY)
 /// and scaled by (factorX,factorY).
 /// </summary>
 /// <param name="canvas">The canvas to draw the arrow on
 /// </param>
 /// <param name="offsetX">Translation-Vector's negative x-component
 /// </param>
 /// <param name="offsetY">Translation-Vector's negative y-component
 /// </param>
 /// <param name="factorX">Scaling-Vector*s x-component
 /// </param>
 /// <param name="factorY">Scaling-Vector*s y-component
 /// 
 /// </param>
 public virtual void draw(Graphics2D canvas, int offsetX, int offsetY, double factorX, double factorY)
 {
     //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
     int x = (int) System.Math.Round((this.x - offsetX) * factorX);
     //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
     int y = (int) System.Math.Round((this.y - offsetY) * factorY);
     //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
     int width = (int) System.Math.Round(this.width * factorX);
     //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
     int height = (int) System.Math.Round(this.height * factorY);
     // set colors and draw
     canvas.setColor(bgcolor);
     canvas.fillOval(x, y, width + 1, height + 1);
     canvas.setColor(bordercolor);
     canvas.drawOval(x, y, width, height);
     // draw short-description
     canvas.setColor(System.Drawing.Color.Black);
     //UPGRADE_TODO: The equivalent in .NET for method 'java.awt.Color.getRGB' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
     if (bgcolor.ToArgb() == System.Drawing.Color.Black.ToArgb())
         canvas.setColor(System.Drawing.Color.White);
     if (height > 10)
     {
         System.Drawing.Point textpos = calculateTextPosition(text, canvas, width, height);
         canvas.drawString(text, (int) textpos.X + x, (int) textpos.Y + y);
     }
 }
예제 #13
0
        /// <summary>
        /// Performs a convolution on BufferedImages.  Each component of the
        /// source image will be convolved (including the alpha component, if
        /// present).
        /// If the color model in the source image is not the same as that
        /// in the destination image, the pixels will be converted
        /// in the destination.  If the destination image is null,
        /// a BufferedImage will be created with the source ColorModel.
        /// The IllegalArgumentException may be thrown if the source is the
        /// same as the destination. </summary>
        /// <param name="src"> the source <code>BufferedImage</code> to filter </param>
        /// <param name="dst"> the destination <code>BufferedImage</code> for the
        ///        filtered <code>src</code> </param>
        /// <returns> the filtered <code>BufferedImage</code> </returns>
        /// <exception cref="NullPointerException"> if <code>src</code> is <code>null</code> </exception>
        /// <exception cref="IllegalArgumentException"> if <code>src</code> equals
        ///         <code>dst</code> </exception>
        /// <exception cref="ImagingOpException"> if <code>src</code> cannot be filtered </exception>
        public BufferedImage Filter(BufferedImage src, BufferedImage dst)
        {
            if (src == null)
            {
                throw new NullPointerException("src image is null");
            }
            if (src == dst)
            {
                throw new IllegalArgumentException("src image cannot be the " + "same as the dst image");
            }

            bool          needToConvert = false;
            ColorModel    srcCM         = src.ColorModel;
            ColorModel    dstCM;
            BufferedImage origDst = dst;

            // Can't convolve an IndexColorModel.  Need to expand it
            if (srcCM is IndexColorModel)
            {
                IndexColorModel icm = (IndexColorModel)srcCM;
                src   = icm.ConvertToIntDiscrete(src.Raster, false);
                srcCM = src.ColorModel;
            }

            if (dst == null)
            {
                dst     = CreateCompatibleDestImage(src, null);
                dstCM   = srcCM;
                origDst = dst;
            }
            else
            {
                dstCM = dst.ColorModel;
                if (srcCM.ColorSpace.Type != dstCM.ColorSpace.Type)
                {
                    needToConvert = true;
                    dst           = CreateCompatibleDestImage(src, null);
                    dstCM         = dst.ColorModel;
                }
                else if (dstCM is IndexColorModel)
                {
                    dst   = CreateCompatibleDestImage(src, null);
                    dstCM = dst.ColorModel;
                }
            }

            if (ImagingLib.filter(this, src, dst) == null)
            {
                throw new ImagingOpException("Unable to convolve src image");
            }

            if (needToConvert)
            {
                ColorConvertOp ccop = new ColorConvertOp(Hints);
                ccop.Filter(dst, origDst);
            }
            else if (origDst != dst)
            {
                java.awt.Graphics2D g = origDst.CreateGraphics();
                try
                {
                    g.DrawImage(dst, 0, 0, null);
                }
                finally
                {
                    g.Dispose();
                }
            }

            return(origDst);
        }
예제 #14
0
 protected internal override void drawPrimitive(Primitive p, Graphics2D g)
 {
     double factor = Factor;
     p.draw(g, factor, factor);
 }
예제 #15
0
 protected internal virtual void  drawPrimitive(Primitive p, Graphics2D g)
 {
     p.draw(g, offsetX, offsetY);
 }
예제 #16
0
        /// <summary>
        /// Transforms the source <CODE>BufferedImage</CODE> and stores the results
        /// in the destination <CODE>BufferedImage</CODE>.
        /// If the color models for the two images do not match, a color
        /// conversion into the destination color model is performed.
        /// If the destination image is null,
        /// a <CODE>BufferedImage</CODE> is created with the source
        /// <CODE>ColorModel</CODE>.
        /// <para>
        /// The coordinates of the rectangle returned by
        /// <code>getBounds2D(BufferedImage)</code>
        /// are not necessarily the same as the coordinates of the
        /// <code>BufferedImage</code> returned by this method.  If the
        /// upper-left corner coordinates of the rectangle are
        /// negative then this part of the rectangle is not drawn.  If the
        /// upper-left corner coordinates of the  rectangle are positive
        /// then the filtered image is drawn at that position in the
        /// destination <code>BufferedImage</code>.
        /// </para>
        /// <para>
        /// An <CODE>IllegalArgumentException</CODE> is thrown if the source is
        /// the same as the destination.
        ///
        /// </para>
        /// </summary>
        /// <param name="src"> The <CODE>BufferedImage</CODE> to transform. </param>
        /// <param name="dst"> The <CODE>BufferedImage</CODE> in which to store the results
        /// of the transformation.
        /// </param>
        /// <returns> The filtered <CODE>BufferedImage</CODE>. </returns>
        /// <exception cref="IllegalArgumentException"> if <code>src</code> and
        ///         <code>dst</code> are the same </exception>
        /// <exception cref="ImagingOpException"> if the image cannot be transformed
        ///         because of a data-processing error that might be
        ///         caused by an invalid image format, tile format, or
        ///         image-processing operation, or any other unsupported
        ///         operation. </exception>
        public BufferedImage Filter(BufferedImage src, BufferedImage dst)
        {
            if (src == null)
            {
                throw new NullPointerException("src image is null");
            }
            if (src == dst)
            {
                throw new IllegalArgumentException("src image cannot be the " + "same as the dst image");
            }

            bool          needToConvert = false;
            ColorModel    srcCM         = src.ColorModel;
            ColorModel    dstCM;
            BufferedImage origDst = dst;

            if (dst == null)
            {
                dst     = CreateCompatibleDestImage(src, null);
                dstCM   = srcCM;
                origDst = dst;
            }
            else
            {
                dstCM = dst.ColorModel;
                if (srcCM.ColorSpace.Type != dstCM.ColorSpace.Type)
                {
                    int  type      = Xform.Type;
                    bool needTrans = ((type & (Xform.TYPE_MASK_ROTATION | Xform.TYPE_GENERAL_TRANSFORM)) != 0);
                    if (!needTrans && type != Xform.TYPE_TRANSLATION && type != Xform.TYPE_IDENTITY)
                    {
                        double[] mtx = new double[4];
                        Xform.GetMatrix(mtx);
                        // Check out the matrix.  A non-integral scale will force ARGB
                        // since the edge conditions can't be guaranteed.
                        needTrans = (mtx[0] != (int)mtx[0] || mtx[3] != (int)mtx[3]);
                    }

                    if (needTrans && srcCM.Transparency == java.awt.Transparency_Fields.OPAQUE)
                    {
                        // Need to convert first
                        ColorConvertOp ccop   = new ColorConvertOp(Hints);
                        BufferedImage  tmpSrc = null;
                        int            sw     = src.Width;
                        int            sh     = src.Height;
                        if (dstCM.Transparency == java.awt.Transparency_Fields.OPAQUE)
                        {
                            tmpSrc = new BufferedImage(sw, sh, BufferedImage.TYPE_INT_ARGB);
                        }
                        else
                        {
                            WritableRaster r = dstCM.CreateCompatibleWritableRaster(sw, sh);
                            tmpSrc = new BufferedImage(dstCM, r, dstCM.AlphaPremultiplied, null);
                        }
                        src = ccop.Filter(src, tmpSrc);
                    }
                    else
                    {
                        needToConvert = true;
                        dst           = CreateCompatibleDestImage(src, null);
                    }
                }
            }

            if (InterpolationType_Renamed != TYPE_NEAREST_NEIGHBOR && dst.ColorModel is IndexColorModel)
            {
                dst = new BufferedImage(dst.Width, dst.Height, BufferedImage.TYPE_INT_ARGB);
            }
            if (ImagingLib.filter(this, src, dst) == null)
            {
                throw new ImagingOpException("Unable to transform src image");
            }

            if (needToConvert)
            {
                ColorConvertOp ccop = new ColorConvertOp(Hints);
                ccop.Filter(dst, origDst);
            }
            else if (origDst != dst)
            {
                java.awt.Graphics2D g = origDst.CreateGraphics();
                try
                {
                    g.Composite = AlphaComposite.Src;
                    g.DrawImage(dst, 0, 0, null);
                }
                finally
                {
                    g.Dispose();
                }
            }

            return(origDst);
        }
예제 #17
0
 /// <summary> Draws an arrow from the From-Shape to the To-Shape
 /// with the choosen color. It will be scaled by (factorX,factorY).
 /// </summary>
 /// <param name="canvas">The canvas to draw the arrow on
 /// </param>
 /// <param name="factorX">Scaling-Vector*s x-component
 /// </param>
 /// <param name="factorY">Scaling-Vector*s y-component
 /// 
 /// </param>
 public virtual void draw(Graphics2D canvas, double factorX, double factorY)
 {
     draw(canvas, 0, 0, factorX, factorY);
 }
예제 #18
0
 /// <summary> Draws an arrow from the From-Shape to the To-Shape
 /// with the choosen color. The draw-position is translated
 /// by (-offsetX,-offsetY).
 /// </summary>
 /// <param name="canvas">The canvas to draw the arrow on
 /// </param>
 /// <param name="offsetX">Translation-Vector's negative x-component
 /// </param>
 /// <param name="offsetY">Translation-Vector's negative y-component
 /// 
 /// </param>
 public virtual void draw(Graphics2D canvas, int offsetX, int offsetY)
 {
     draw(canvas, offsetX, offsetY, 1.0, 1.0);
 }
예제 #19
0
 public abstract void  draw(Graphics2D canvas, int offsetX, int offsetY, double factorX, double factorY);
예제 #20
0
 public virtual void draw(Graphics2D canvas, int offsetX, int offsetY, double factorX, double factorY)
 {
     //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
     int ourX = (int) System.Math.Round((x - offsetX) * factorX);
     //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
     int ourY = (int) System.Math.Round((y - offsetY) * factorY);
     //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
     int ourWidth = (int) System.Math.Round(width * factorX);
     //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
     int ourHeight = (int) System.Math.Round(height * factorY);
     //UPGRADE_WARNING: Narrowing conversions may produce unexpected results in C#. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042"'
     int[] xpoints = new int[]{ourX + (int) (ourWidth * .25), ourX + (int) (ourWidth * .75), ourX + ourWidth, ourX};
     int[] ypoints = new int[]{ourY, ourY, ourY + ourHeight, ourY + ourHeight};
     canvas.setColor(bgcolor);
     canvas.fillPolygon(xpoints, ypoints, 4);
     canvas.setColor(bordercolor);
     canvas.drawPolygon(xpoints, ypoints, 4);
     canvas.setColor(System.Drawing.Color.Black);
     //UPGRADE_TODO: The equivalent in .NET for method 'java.awt.Color.getRGB' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
     if (bgcolor.ToArgb() == System.Drawing.Color.Black.ToArgb())
         canvas.setColor(System.Drawing.Color.White);
     if (ourHeight > 10)
     {
         System.Drawing.Point textpos = calculateTextPosition(text, canvas, ourWidth, ourHeight);
         canvas.drawString(text, (int) textpos.X + ourX, (int) textpos.Y + ourY);
     }
 }
예제 #21
0
 protected internal virtual void drawPrimitive(Primitive p, Graphics2D g)
 {
     p.draw(g, offsetX, offsetY);
 }
        protected internal override void  drawPrimitive(Primitive p, Graphics2D g)
        {
            double factor = Factor;

            p.draw(g, factor, factor);
        }
예제 #23
0
 public virtual void  draw(Graphics2D canvas, int offsetX, int offsetY)
 {
     draw(canvas, offsetX, offsetY, 1.0, 1.0);
 }
예제 #24
0
        /// <summary>
        /// 指定したフォントを描画するとき、描画指定したy座標と、描かれる文字の中心線のズレを調べます
        /// </summary>
        /// <param name="font"></param>
        /// <returns></returns>
        public static int getStringDrawOffset(java.awt.Font font)
        {
            int ret = 0;

            java.awt.Dimension size = measureString(PANGRAM, font);
            if (size.height <= 0)
            {
                return(0);
            }
            java.awt.Image      b  = null;
            java.awt.Graphics2D g  = null;
            BitmapEx            b2 = null;

            try {
                int string_desty = size.height * 2; // 文字列が書き込まれるy座標
                int w            = size.width * 4;
                int h            = size.height * 4;
                b       = new java.awt.Image();
                b.image = new System.Drawing.Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                g       = new java.awt.Graphics2D(System.Drawing.Graphics.FromImage(b.image));
                g.setColor(java.awt.Color.white);
                g.fillRect(0, 0, w, h);
                g.setFont(font);
                g.setColor(java.awt.Color.black);
                g.drawString(PANGRAM, size.width, string_desty);

                b2 = new BitmapEx(b.image);
                // 上端に最初に現れる色つきピクセルを探す
                int  firsty = 0;
                bool found  = false;
                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        java.awt.Color c = new cadencii.java.awt.Color(b2.GetPixel(x, y));
                        if (c.getRed() != 255 || c.getGreen() != 255 || c.getBlue() != 255)
                        {
                            found  = true;
                            firsty = y;
                            break;
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }

                // 下端
                int endy = h - 1;
                found = false;
                for (int y = h - 1; y >= 0; y--)
                {
                    for (int x = 0; x < w; x++)
                    {
                        java.awt.Color c = new cadencii.java.awt.Color(b2.GetPixel(x, y));
                        if (c.getRed() != 255 || c.getGreen() != 255 || c.getBlue() != 255)
                        {
                            found = true;
                            endy  = y;
                            break;
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }

                int center = (firsty + endy) / 2;
                ret = center - string_desty;
            } catch (Exception ex) {
                serr.println("Util#getStringDrawOffset; ex=" + ex);
            } finally {
                if (b != null && b.image != null)
                {
                    b.image.Dispose();
                }
                if (g != null)
                {
                    g.nativeGraphics.Dispose();
                }
                if (b2 != null && b2 != null)
                {
                    b2.Dispose();
                }
            }
            return(ret);
        }
예제 #25
0
 public virtual void  draw(Graphics2D canvas, double factorX, double factorY)
 {
     draw(canvas, 0, 0, factorX, factorY);
 }
예제 #26
0
        /// <summary> Draws an arrow from the From-Shape to the To-Shape
        /// with the choosen color. The draw-position is translated
        /// by (-offsetX,-offsetY) and then scaled by (factorX,factorY).
        /// </summary>
        /// <param name="canvas">The canvas to draw the arrow on
        /// </param>
        /// <param name="offsetX">Translation-Vector's negative x-component
        /// </param>
        /// <param name="offsetY">Translation-Vector's negative y-component
        /// </param>
        /// <param name="factorX">Scaling-Vector*s x-component
        /// </param>
        /// <param name="factorY">Scaling-Vector*s y-component
        ///
        /// </param>
        public virtual void  draw(Graphics2D canvas, int offsetX, int offsetY, double factorX, double factorY)
        {
            canvas.setColor(color);

            /* angleFromTo is this angle ;)
             * (between -PI;+PI)
             *                     TO
             *    ----------------(x)-------------------
             *                   /
             *                 /)
             *               / @ )
             *    --------(x)---------------------------
             *            FROM
             */
            double angleFromTo = System.Math.Atan2(-to.Y + from.Y, to.X - from.X);

            /* angleToFrom is this angle ;)
             * (between -PI;+PI)
             *                     TO
             *    ----------------(x)-------------------
             *               ( @ /
             *                (/
             *               /
             *    --------(x)---------------------------
             *            FROM
             */
            double angleToFrom;

            if (angleFromTo > 0)
            {
                angleToFrom = angleFromTo - System.Math.PI;
            }
            else
            {
                angleToFrom = angleFromTo + System.Math.PI;
            }
            System.Drawing.Point pfrom = from.calculateIntersection(angleFromTo);
            System.Drawing.Point pto   = to.calculateIntersection(angleToFrom);
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            System.Drawing.Point parrow1 = new System.Drawing.Point((int)System.Math.Round(6 * System.Math.Cos(angleToFrom + System.Math.PI / 4.0)), (int)System.Math.Round(6 * System.Math.Sin(angleToFrom + System.Math.PI / 4.0)));
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            System.Drawing.Point parrow2 = new System.Drawing.Point((int)System.Math.Round(6 * System.Math.Cos(angleToFrom - System.Math.PI / 4.0)), (int)System.Math.Round(6 * System.Math.Sin(angleToFrom - System.Math.PI / 4.0)));
            pfrom.X   -= offsetX;
            pfrom.Y   -= offsetY;
            pto.X     -= offsetX;
            pto.Y     -= offsetY;
            pfrom.X   *= (int)(factorX);
            pfrom.Y   *= (int)(factorY);
            pto.X     *= (int)(factorX);
            pto.Y     *= (int)(factorY);
            parrow1.X *= (int)(factorX);
            parrow1.Y *= (int)(factorY);
            parrow2.X *= (int)(factorX);
            parrow2.Y *= (int)(factorY);

            //calculate a good line width
            //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073"'
            int linewidth = (int)System.Math.Round(1 * System.Math.Min(factorX, factorY));

            if (linewidth == 0)
            {
                linewidth = 1;
            }
            canvas.setStroke(new BasicStroke(linewidth));

            //draw the arrow
            canvas.drawLine(pfrom.X, pfrom.Y, pto.X, pto.Y);
            canvas.drawLine(pto.X + parrow1.X, pto.Y - parrow1.Y, pto.X, pto.Y);
            canvas.drawLine(pto.X + parrow2.X, pto.Y - parrow2.Y, pto.X, pto.Y);
        }