Example #1
0
        internal virtual void paint(javax.microedition.lcdui.Graphics g)
        {
            int old = g.Color;

            g.Color = color;
            if (marker == ' ')
            {
                for (int i = 0; i < x.Length - 1; i++)
                {
                    g.drawLine(outerInstance.getScreenX(x[i]), outerInstance.getScreenY(y[i]), outerInstance.getScreenX(x[i + 1]), outerInstance.getScreenY(y[i + 1]));
                }
            }
            else
            {
                for (int i = 0; i < x.Length - 1; i++)
                {
                    drawSymbol(g, outerInstance.getScreenX(x[i]), outerInstance.getScreenY(y[i]), marker);
                }
            }
            if (eu != null)
            {
                for (int i = 0; i < x.Length - 1; i++)
                {
                    g.drawLine(outerInstance.getScreenX(x[i]), outerInstance.getScreenY(y[i] - el[i]), outerInstance.getScreenX(x[i]), outerInstance.getScreenY(y[i] + eu[i]));
                    g.drawLine(outerInstance.getScreenX(x[i]) - 3, outerInstance.getScreenY(y[i] - el[i]), outerInstance.getScreenX(x[i]) + 3, outerInstance.getScreenY(y[i] - el[i]));
                    g.drawLine(outerInstance.getScreenX(x[i]) - 3, outerInstance.getScreenY(y[i] + eu[i]), outerInstance.getScreenX(x[i]) + 3, outerInstance.getScreenY(y[i] + eu[i]));
                }
            }
            g.Color = old;
        }
Example #2
0
    public virtual void  drawCross(Point point, int color)
    {
        Image    bufImage = Image.createImage(image.getWidth(), image.getHeight());
        Graphics g        = bufImage.getGraphics();

        g.drawImage(image, 0, 0, 0);
        g.setColor(color);
        g.drawLine(point.getX() - 5, point.getY(), point.getX() + 5, point.getY());
        g.drawLine(point.getX(), point.getY() - 5, point.getX(), point.getY() + 5);
        image = bufImage;
        repaint();
    }
Example #3
0
    public virtual void  drawPolygon(Point[] points, int color)
    {
        Image    bufImage = Image.createImage(image.getWidth(), image.getHeight());
        Graphics g        = bufImage.getGraphics();

        g.drawImage(image, 0, 0, 0);
        g.setColor(color);
        int i = 0;

        for (; i < points.length - 1; i++)
        {
            g.drawLine(points[i].getX(), points[i].getY(), points[i + 1].getX(), points[i + 1].getY());
        }
        g.drawLine(points[i].getX(), points[i].getY(), points[0].getX(), points[0].getY());
        image = bufImage;
        repaint();
    }
Example #4
0
    public virtual void  drawLine(Line line, int color)
    {
        Image    bufImage = Image.createImage(image.getWidth(), image.getHeight());
        Graphics g        = bufImage.getGraphics();

        g.drawImage(image, 0, 0, 0);
        g.setColor(color);
        g.drawLine(line.getP1().getX(), line.getP1().getY(), line.getP2().getX(), line.getP2().getY());
        image = bufImage;
        repaint();
    }
Example #5
0
    public virtual void  drawLines(Line[] lines, int color)
    {
        Image    bufImage = Image.createImage(image.getWidth(), image.getHeight());
        Graphics g        = bufImage.getGraphics();

        g.drawImage(image, 0, 0, 0);
        g.setColor(color);

        for (int i = 0; i < lines.length - 1; i++)
        {
            g.drawLine(lines[i].getP1().getX(), lines[i].getP1().getY(), lines[i].getP2().getX(), lines[i].getP2().getY());
        }
        image = bufImage;
        repaint();
    }
Example #6
0
    public virtual void  drawMatrix(bool[][] matrix)
    {
        Image    bufImage = Image.createImage(image.getWidth(), image.getHeight());
        Graphics g        = bufImage.getGraphics();

        g.setColor(0xCCCCCC);
        for (int y = 0; y < matrix[0].Length; y++)
        {
            for (int x = 0; x < matrix.Length; x++)
            {
                if (matrix[x][y] == true)
                {
                    g.drawLine(x, y, x + 1, y);
                }
            }
        }
        image = bufImage;
        repaint();
    }
Example #7
0
    internal virtual void drawAxis(javax.microedition.lcdui.Graphics g)
    {
        g.Color = BLACK;
        int x2 = width - xright, y2 = height - ybottom;

        g.drawLine(xleft, ytop, x2, ytop);
        g.drawLine(xleft, ytop, xleft, y2);
        g.drawLine(x2, ytop, x2, y2);
        g.drawLine(xleft, y2, x2, y2);
        if (minx < 0 && 0 < maxx)
        {
            g.StrokeStyle = g.DOTTED;
            g.drawLine(getScreenX(0.0), getScreenY(miny), getScreenX(0.0), getScreenY(maxy));
            g.StrokeStyle = g.SOLID;
        }
        if (miny < 0 && 0 < maxy)
        {
            g.StrokeStyle = g.DOTTED;
            g.drawLine(getScreenX(minx), getScreenY(0.0), getScreenX(maxx), getScreenY(0.0));
            g.StrokeStyle = g.SOLID;
        }
        drawOrnaments(g);
    }
Example #8
0
    internal virtual void drawOrnaments(javax.microedition.lcdui.Graphics g)
    {
        int    lenMajor = height / 40, i;
        double x = 0, y = 0;
        int    axis_w = width - xleft - xright;
        int    axis_h = height - ytop - ybottom;
        string label;
        int    lenlabel   = g.Font.stringWidth(" 00.00 ");
        int    maxnumtics = axis_w / lenlabel;
        double dX         = (maxx - minx) / ntx;
        double startx     = minx;

        while ((maxx - minx) / dX > maxnumtics)
        {
            dX    *= 2;
            startx = (int)(startx / dX + 0.5) * dX;
            if ((maxx - minx) / dX > maxnumtics)
            {
                dX    *= 2.5;
                startx = (int)(startx / dX + 0.5) * dX;
            }
        }
        if (plotmode == LOGLIN || plotmode == LOGLOG)
        {
            while (Math.Abs((startx / dX) - JMath.round(startx / dX)) > 0.01)
            {
                startx += dX;
            }
            if (dX < 1.0)
            {
                dX = 1.0;
            }
            else if (dX == 2.5)
            {
                dX = 2.0;
            }
            startx = dX * JMath.floor(startx / dX);
        }
        int exponent = Math.Max(decExp(maxx), decExp(minx)) - 1;

        if (Math.Abs(exponent) < 2)
        {
            exponent = 0;
        }
        double scf = JMath.pow(10.0, (double)exponent);

        for (i = 0, x = startx; x <= maxx; i++, x += dX)
        {
            int xworld = getScreenX(x);
            if (xworld < xleft)
            {
                continue;
            }
            g.drawLine(xworld, ytop, xworld, ytop + lenMajor);
            g.drawLine(xworld, height - ybottom - lenMajor, xworld, height - ybottom);
            if ((plotmode == LOGLIN || plotmode == LOGLOG) && (dX < 1.5))
            {
                for (int k = 2; k <= 9; k++)
                {
                    int xk = getScreenX(x + JMath.log((double)k) / JMath.log(10.0));
                    if (xk > xleft && xk < xleft + width)
                    {
                        g.drawLine(xk, ytop, xk, ytop + lenMajor / 2);
                        g.drawLine(xk, height - ybottom - lenMajor / 2, xk, height - ybottom);
                    }
                }
            }
            if (plotmode == LOGLIN || plotmode == LOGLOG)
            {
                label = "10^";
            }
            else
            {
                label = "";
            }
            if (x + dX > maxx && exponent != 0)
            {
                label = "E" + exponent;
            }
            else
            {
                label += fmt.ToString(x / scf);
            }
            centerText(g, label, height - ybottom + 1.5 * g.Font.Height, xworld);
        }
        if (Xlabel_Renamed != null)
        {
            centerText(g, Xlabel_Renamed, height - ybottom + 3 * g.Font.Height, xleft + (width - xleft - xright) / 2);
        }
        if (Tlabel_Renamed != null)
        {
            centerText(g, Tlabel_Renamed, ytop - g.Font.Height / 2, xleft + (width - xleft - xright) / 2);
        }
        if (Ylabel_Renamed != null)
        {
            centerTextV(g, Ylabel_Renamed, g.Font.Height, ytop + (height - ytop - ybottom) / 2);
        }
        int hilabel = g.Font.Height;

        maxnumtics = (int)((axis_h) / (1.5 * hilabel));
        double dY     = (maxy - miny) / nty;
        double starty = miny;

        while ((maxy - miny) / dY > maxnumtics)
        {
            dY    *= 2;
            starty = (int)(starty / dY + 0.5) * dY;
            if ((maxy - miny) / dY > maxnumtics)
            {
                dY    *= 2.5;
                starty = (int)(starty / dY + 0.5) * dY;
            }
        }
        if (plotmode == LINLOG || plotmode == LOGLOG)
        {
            if (dY < 1.0)
            {
                dY = 1.0;
            }
            else if (dY == 2.5)
            {
                dY = 2.0;
            }
            starty = dY * JMath.floor(starty / dY);
        }
        exponent = Math.Max(decExp(maxy), decExp(miny)) - 1;
        if (Math.Abs(exponent) < 2)
        {
            exponent = 0;
        }
        scf = JMath.pow(10.0, (double)exponent);
        for (i = 0, y = starty; y <= maxy; i++, y += dY)
        {
            int yworld = getScreenY(y);
            if (yworld > height - ybottom)
            {
                continue;
            }
            g.drawLine(xleft, yworld, xleft + lenMajor, yworld);
            g.drawLine(xleft + axis_w, yworld, xleft + axis_w - lenMajor, yworld);
            if ((plotmode == LINLOG || plotmode == LOGLOG) && dY < 1.5)
            {
                for (int k = 2; k <= 9; k++)
                {
                    int yk = getScreenY(y + JMath.log((double)k) / JMath.log(10.0));
                    if (yk > ytop && yk < ytop + height)
                    {
                        g.drawLine(xleft, yk, xleft + lenMajor / 2, yk);
                        g.drawLine(xleft + axis_w, yk, xleft + axis_w - lenMajor / 2, yk);
                    }
                }
            }
            if (plotmode == LINLOG || plotmode == LOGLOG)
            {
                label = "10^";
            }
            else
            {
                label = "";
            }
            if (y + dY > maxy && exponent != 0)
            {
                label = "E" + exponent;
            }
            else
            {
                label += fmt.ToString(y / scf);
            }
            g.drawString(label, xleft - g.Font.stringWidth(label) - 3, yworld + hilabel / 2 - 3, g.BOTTOM | g.LEFT);
        }
    }
Example #9
0
        internal virtual void drawSymbol(javax.microedition.lcdui.Graphics g, int x, int y, char marker)
        {
            switch (marker)
            {
            case '+':
                g.drawLine(x, y - 3, x, y + 3);
                g.drawLine(x - 3, y, x + 3, y);
                break;

            case 'o':
                g.drawLine(x - 1, y - 3, x + 1, y - 3);
                g.drawLine(x + 1, y - 3, x + 3, y - 1);
                g.drawLine(x + 3, y - 1, x + 3, y + 1);
                g.drawLine(x + 3, y + 1, x + 1, y + 3);
                g.drawLine(x + 1, y + 3, x - 1, y + 3);
                g.drawLine(x - 1, y + 3, x - 3, y + 1);
                g.drawLine(x - 3, y + 1, x - 3, y - 1);
                g.drawLine(x - 3, y - 1, x - 1, y - 3);
                break;

            case 'x':
                g.drawLine(x - 3, y - 3, x + 3, y + 3);
                g.drawLine(x + 3, y - 3, x - 3, y + 3);
                break;

            case '*':
            default:
                g.drawLine(x, y - 3, x, y + 3);
                g.drawLine(x - 3, y, x + 3, y);
                g.drawLine(x - 2, y - 2, x + 2, y + 2);
                g.drawLine(x + 2, y - 2, x - 2, y + 2);
                break;
            }
        }
Example #10
0
    internal virtual void drawStraightLine(javax.microedition.lcdui.Graphics g)
    {
        double xl = minx;
        double yl = a1 * xl + a0;

        if (yl > maxy)
        {
            yl = maxy;
            xl = (yl - a0) / a1;
        }
        else if (yl < miny)
        {
            yl = miny;
            xl = (yl - a0) / a1;
        }
        double xr = maxx;
        double yr = a1 * xr + a0;

        if (yr > maxy)
        {
            yr = maxy;
            xr = (yr - a0) / a1;
        }
        else if (yr < miny)
        {
            yr = miny;
            xr = (yr - a0) / a1;
        }
        if (xp >= 0 && pointerMode == PMODE_LINE)
        {
            double xm = getXCoordinate(xp);
            double ym = getYCoordinate(yp);
            int    Xr = getScreenX(xr), Yr = getScreenY(yr), Xl = getScreenX(xl), Yl = getScreenY(yl);
            if ((xp - Xr) * (xp - Xr) + (yp - Yr) * (yp - Yr) < (xp - Xl) * (xp - Xl) + (yp - Yl) * (yp - Yl))
            {
                a1 = (ym - yl) / (xm - xl);
                a0 = yl - a1 * xl;
                xr = maxx;
                yr = a1 * xr + a0;
                if (yr > maxy)
                {
                    yr = maxy;
                    xr = (yr - a0) / a1;
                }
                else if (yr < miny)
                {
                    yr = miny;
                    xr = (yr - a0) / a1;
                }
            }
            else
            {
                a1 = (yr - ym) / (xr - xm);
                a0 = yr - a1 * xr;
                xl = minx;
                yl = a1 * xl + a0;
                if (yl > maxy)
                {
                    yl = maxy;
                    xl = (yl - a0) / a1;
                }
                else if (yl < miny)
                {
                    yl = miny;
                    xl = (yl - a0) / a1;
                }
            }
        }
        g.Color = GREEN;
        g.drawLine(getScreenX(xl), getScreenY(yl), getScreenX(xr), getScreenY(yr));
        g.Color = BLACK;
        if (pointerMode == PMODE_LINE)
        {
            drawMessage(g, xp, yp, new string[] { "a1=" + fmt.ToString(a1), "a0=" + fmt.ToString(a0) });
        }
    }