Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
     }
 }
Exemplo n.º 6
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);
     }
 }
Exemplo n.º 7
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);
        }