Package com.bbn.openmap.omGraphics

Examples of com.bbn.openmap.omGraphics.OMLine


     * @param color color
     * @return an OMLine object, suitable for displaying on the map.
     */

    private OMLine createPlotLine(int x1, int y1, int x2, int y2, Paint color) {
        OMLine line = new OMLine(x1, y1, x2, y2);
        line.setLinePaint(color);
        line.setSelectPaint(Color.white);
        return line;
    }
View Full Code Here


        int y1 = findTempPoint(temp1);

        int x2 = findYearPoint(year2);
        int y2 = findTempPoint(temp2);

        OMLine line = createPlotLine(x1, y1, x2, y2, plot_color_);
        line.setLinePaint(plot_color_);
        line.setSelectPaint(select_color_);
        return line;
    }
View Full Code Here

        int right = frame_x + frame_width_ - border_width_;

        String min_year_string = GetStringDateFromFloat(min_year_);
        String max_year_string = GetStringDateFromFloat(max_year_);

        OMLine year_axis = createPlotLine(left,
                bottom,
                right,
                bottom,
                plot_color_);

        OMLine temp_axis = createPlotLine(left, top, left, bottom, plot_color_);

        OMText year_min_label = createLabel(min_year_string + " ",
                left,
                bottom + 10);

        OMText year_max_label = createLabel(max_year_string + " ",
                right - 30,
                bottom + 10);

        OMText temp_min_label = createLabel(min_temp_ + " ",
                left,
                bottom,
                plot_color_,
                OMText.JUSTIFY_RIGHT);

        OMText temp_max_label = createLabel(max_temp_ + " ",
                left,
                top,
                plot_color_,
                OMText.JUSTIFY_RIGHT);

        OMText temp_axis_label = createLabel("Temp", left, frame_y
                + (frame_height_ / 2), plot_color_, OMText.JUSTIFY_RIGHT);
        OMText year_axis_label = createLabel("Year", frame_x
                + (frame_width_ / 2), bottom + 15);

        // The background that the plot is drawn on.
        OMRect background = new OMRect(frame_x, frame_y, frame_x + frame_width_, frame_y
                + frame_height_);

        background.setFillPaint(graph_bg_color);
        background.setLinePaint(graph_bg_color);

        year_axis.setAppObject(this);
        temp_axis.setAppObject(this);

        plot_background_.addOMGraphic(background);

        plot_background_.addOMGraphic(year_axis);
        plot_background_.addOMGraphic(temp_axis);
View Full Code Here

            arcPoint.setLinePaint(OMColor.blue);
            arcGraphics.add(point1);
            arcGraphics.add(point2);
            arcGraphics.add(arcPoint);

            OMLine line1 = new OMLine(x1, y1, x2, y2);
            OMLine line2 = new OMLine(midPoint.x, midPoint.y, arcCenter.x, arcCenter.y);
            arcGraphics.add(line1);
            arcGraphics.add(line2);
        }

        int realCount = 0;

        // Figure out the arc extents for each endpoint. I think
        // it's easier to keep track of the angles if they are always
        // positive, and we always go from smaller to larger.
        double startSlope = getRealAngle(arcCenter.x, arcCenter.y, x1, y1);
        double endSlope = getRealAngle(arcCenter.x, arcCenter.y, x2, y2);

        double smallSlope, largeSlope;
        double angleIncrement;

        smallSlope = (startSlope > endSlope) ? endSlope : startSlope;
        largeSlope = (smallSlope == startSlope) ? endSlope : startSlope;

        // Have to make sure we take the smaller arc around the
        // circle.
        while (Math.abs(smallSlope - largeSlope) > Math.PI) {
            if (Math.abs(largeSlope - smallSlope - Math.PI) < .001) {
                // Catch 180 degree angles that are close enough...
                break;
            }

            Debug.message("arc",
                    "ArcCalc.generate: Modifying the starting slope.");
            double tmpSlope = smallSlope + MoreMath.TWO_PI;
            smallSlope = largeSlope;
            largeSlope = tmpSlope;
        }

        // Experienced some trouble with vertical and horizonal half
        // circles. This took care of that.
        if (arcAngle == Math.PI && arcUp) {
            Debug.message("arc",
                    "ArcCalc.generate: Modifying 180 angle points.");
            double tmpSlope = smallSlope + MoreMath.TWO_PI;
            smallSlope = largeSlope;
            largeSlope = tmpSlope;
        }

        // Figure out the angle increment for grabbing coordinates -
        // use the larger dimension of the arc end point differences.
        if (Math.abs(y2 - y1) < Math.abs(x2 - x1)) {
            angleIncrement = Math.PI / Math.abs(x2 - x1);
        } else {
            angleIncrement = Math.PI / Math.abs(y2 - y1);
        }

        int numPoints = (int) (Math.abs(smallSlope - largeSlope)
                / angleIncrement + 2);
        int[] xPoints = new int[numPoints];
        int[] yPoints = new int[numPoints];

        if (Debug.debugging("arc")) {
            Debug.output("ArcCalc.generate: angle to x1, y1 is " + startSlope
                    + " (" + (startSlope * 180.0 / Math.PI)
                    + " degrees), angle to x2, y2 is " + endSlope + " ("
                    + (endSlope * 180.0 / Math.PI) + " degrees)");

            Debug.output("ArcCalc.generate: Starting angle is " + smallSlope
                    + "(" + (smallSlope * 180.0 / Math.PI)
                    + " degrees), end angle is " + largeSlope + " ("
                    + (largeSlope * 180.0 / Math.PI)
                    + " degrees), incrementing by " + angleIncrement + " ("
                    + (angleIncrement * 180.0 / Math.PI) + " degrees)");
        }

        reversed = false;
        // Get the coordinates of the arc from the arc extents.
        while (smallSlope < largeSlope && realCount < numPoints) {

            xPoints[realCount] = arcCenter.x
                    + (int) (arcRadius * Math.cos(smallSlope));
            yPoints[realCount] = arcCenter.y
                    + (int) (arcRadius * Math.sin(smallSlope));

            if (realCount == 0 && xPoints[realCount] == x2) {
                Debug.message("arc", "ArcCalc: line reversed");
                reversed = true;
            }

            if (Debug.debugging("arc") && realCount == 0) {
                OMLine startLine = new OMLine(arcCenter.x, arcCenter.y, xPoints[0], yPoints[0]);
                startLine.setLinePaint(OMColor.white);
                arcGraphics.add(startLine);
            } else if (Debug.debugging("arcdetail")) {
                Debug.output("  angle " + smallSlope + " (" + smallSlope * 180
                        / Math.PI + " degrees)  = " + xPoints[realCount] + ", "
                        + yPoints[realCount]);
View Full Code Here

        StringTokenizer st = null;
        String tok = null;
        pushback = false;
        int idx;
        OMPoly omp = null;
        OMLine oml = null;
        MIFPoint ompoint = null;
        OMText omtext = null;
        boolean ismultiple = false;

        OMGraphicList aList = new OMGraphicList();

        // a vector of omgraphics for regions that allows adding and
        // deleting
        Vector omgs = new Vector();

        MAIN_LOOP: while (true) {

            if (!pushback) {
                // if it's null then there's no more
                if ((st = getTokens(br)) == null)
                    break MAIN_LOOP;

                tok = st.nextToken();
            } else {
                pushback = false; // pushback was true so make it
                // false so it doesn't happen twice
            }

            SWITCH: switch (action) {

            case PROCESS_HEADER:
                if (isSame(tok, DATA_WORD)) {
                    action = PROCESS_DATA;
                } else if (isSame(tok, VERSION_WORD)) {
                } else if (isSame(tok, DELIMITER_WORD)) {
                } else if (isSame(tok, COORDSYS_WORD)) {
                    // check the CoordSys header, OpenMap only
                    // directly
                    // supports LatLong type of coordsys
                    String coordSysLine = COORDSYS_WORD;
                    while (st.hasMoreElements()) {
                        coordSysLine += " " + st.nextElement();
                    }

                    String goodCoordSys = COORDSYS_WORD + " "
                            + LATLONG_COORDSYS_DEF;
                    if (goodCoordSys.length() < coordSysLine.length()) {
                        coordSysLine = coordSysLine.substring(0,
                                goodCoordSys.length());
                    } else {
                        goodCoordSys = goodCoordSys.substring(0,
                                coordSysLine.length());
                    }

                    // check that the CoordSys header matches the MIF
                    // specification for LatLong type
                    if (!isSame(coordSysLine, goodCoordSys)) {
                        Debug.error("MIFLoader file has coordinate system: "
                                + coordSysLine + ", requires " + goodCoordSys);
                        // raise error, as the coordsys header was
                        // invalid
                        throw new MIFException("File appears to contain objects with an incompatible coordinate system (Must be Lat/Lon).");
                    }

                }
                break SWITCH;

            case PROCESS_DATA:
                omgs.clear();
                if (isSame(tok, PLINE_WORD)) {
                    tok = st.nextToken();
                    if (isSame(tok, MULTIPLE_WORD)) {
                        multiple = Integer.parseInt(st.nextToken());
                        multicnt = 0;
                        action = PROCESS_MULTIPLE;
                        ismultiple = true;
                    } else {
                        number = Integer.parseInt(tok);
                        ptarray = new float[number + number];
                        count = 0;
                        action = PROCESS_PLINE;
                    }
                } else if (isSame(tok, REGION_WORD)) {
                    multiple = Integer.parseInt(st.nextToken());
                    multicnt = 0;
                    action = PROCESS_REGION_HEADER;
                } else if (isSame(tok, LINE_WORD)) {
                    float lon1 = Float.parseFloat(st.nextToken());
                    float lat1 = Float.parseFloat(st.nextToken());
                    float lon2 = Float.parseFloat(st.nextToken());
                    float lat2 = Float.parseFloat(st.nextToken());

                    oml = new OMLine(lat1, lon1, lat2, lon2, OMGraphicConstants.LINETYPE_STRAIGHT);

                    action = PROCESS_POST_LINE;
                } else if (isSame(tok, POINT_WORD)) // handle a MIF
                // POINT primitive
                {
                    // get the coordinates
                    float lon1 = Float.parseFloat(st.nextToken());
                    float lat1 = Float.parseFloat(st.nextToken());

                    // construct the OM graphic
                    ompoint = new MIFPoint(lat1, lon1, pointVisible);
                    st = getTokens(br);

                    // set the graphics attributes
                    this.processSymbolWord(st, ompoint);

                    // add to the graphic list for this layer
                    aList.add(ompoint);
                    action = PROCESS_DATA;
                } else if (isSame(tok, TEXT_WORD)) // handle a MIF
                // TEXT primitive
                {
                    String textString = "";

                    // if the actual text is not on the same line as
                    // the primitive declaration
                    if (st.countTokens() < 1) {
                        // get the next line
                        st = getTokens(br);
                    }
                    // build up the display text string,
                    while (st.hasMoreTokens()) {
                        textString += st.nextToken();
                    }

                    if (textString.length() >= 1) {
                        // remove any surrounding " characters
                        textString = textString.substring(1,
                                textString.length() - 1);
                    }
                    // get the next line, it contains the coordinates
                    st = getTokens(br);

                    float lon1 = Float.parseFloat(st.nextToken());
                    float lat1 = Float.parseFloat(st.nextToken());
                    /* float lon2 = */Float.parseFloat(st.nextToken());
                    /* float lat2 = */Float.parseFloat(st.nextToken());
                    // create the OMGraphic for the text object
                    omtext = new MIFText(lat1, lon1, textString, OMText.JUSTIFY_CENTER, textVisible);

                    // the next line contains the text attributes
                    st = getTokens(br);
                    // set the attributes agains the omgraphic
                    this.processFontWord(st, omtext);
                    // add to the layers graphic list
                    aList.add(omtext);

                    action = PROCESS_DATA;
                }
                break SWITCH;

            // We have a line, tok is the first coord and the next
            // token is the second
            case PROCESS_PLINE:
                idx = count + count;
                ptarray[idx + 1] = Float.parseFloat(tok);
                ptarray[idx] = Float.parseFloat(st.nextToken());
                count++;
                if (count == number) {
                    omp = new OMPoly(ptarray, OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_STRAIGHT);

                    aList.add(omp);
                    if (!ismultiple) {
                        action = PROCESS_POST_PLINE;
                    } else {
                        omgs.add(omp);
                        action = PROCESS_MULTIPLE;
                    }
                }
                break SWITCH;

            case PROCESS_MULTIPLE:
                multicnt++;
                if (multicnt > multiple) { // No more multiples so we
                    // can pushback
                    pushback = true;
                    multiple = 0;
                    action = PROCESS_POST_PLINE;
                    break SWITCH;
                }
                number = Integer.parseInt(tok);
                count = 0;
                ptarray = new float[number + number];
                action = PROCESS_PLINE;
                break SWITCH;

            case PROCESS_POST_PLINE:
                if (isSame(tok, PEN_WORD)) {
                    if (ismultiple) {
                        processPenWord(st, omgs);
                    } else {
                        processPenWord(st, omp);
                    }
                } else if (isSame(tok, SMOOTH_WORD)) {
                    // Smooth unimplemented
                } else {
                    ismultiple = false;
                    pushback = true;
                    action = PROCESS_DATA;
                }
                break SWITCH;

            // SCN to support lines
            case PROCESS_POST_LINE:
                if (isSame(tok, PEN_WORD)) {
                    processPenWord(st, oml);
                    aList.add(oml);
                } else {
                    ismultiple = false;
                    pushback = true;
                    action = PROCESS_DATA;
                }
                break SWITCH;

            case PROCESS_REGION_HEADER: // This processes the number
                // at the top of each region
                // sub-block
                multicnt++;
                if (multicnt > multiple) {
                    multiple = 0;
                    action = PROCESS_POST_REGION;

                    // Add this point the region is finished so add
                    // the
                    // vector contents to list
                    int len = omgs.size();
                    for (int i = 0; i < len; i++) {
                        aList.add((OMGraphic) omgs.elementAt(i));
                    }
                    break SWITCH;
                }
                number = Integer.parseInt(tok);
                count = 0;
                ptarray = new float[number + number];
                latpts = new float[number];
                lonpts = new float[number];
                action = PROCESS_REGION;
                break SWITCH;

            case PROCESS_REGION:
                idx = count + count;
                lonpts[count] = ptarray[idx + 1] = Float.parseFloat(tok);
                latpts[count] = ptarray[idx] = Float.parseFloat(st.nextToken());
                count++;
                if (count == number) {
                    // This polygon is complete so add it and process
                    // the next

                    // Use this code if we just want polygons which is
                    // much
                    // faster
                    if (accurate) {
                        omgs.add(new OMSubtraction(latpts, lonpts));

                    } else {
                        // Produces accurate MapInfo type rendering
                        // but very
                        // slow with complex regions like streets
                        int end = latpts.length - 1;

                        for (int i = 0; i < end; i++) {
                            omgs.add(new OMLine(latpts[i], lonpts[i], latpts[i + 1], lonpts[i + 1], OMGraphic.LINETYPE_STRAIGHT));
                        }
                        omgs.add(new OMLine(latpts[end], lonpts[end], latpts[0], lonpts[0], OMGraphic.LINETYPE_STRAIGHT));
                    }
                    action = PROCESS_REGION_HEADER;
                }
                break SWITCH;

View Full Code Here

        Graphics2D g = (Graphics2D) graphics;
        g.setXORMode(java.awt.Color.lightGray);
        g.setColor(java.awt.Color.darkGray);
        if (pt1 != null && pt2 != null) {
            // the line connecting the segments
            OMLine cLine = new OMLine(pt1.getLatitude(), pt1.getLongitude(), pt2.getLatitude(), pt2.getLongitude(), lineType);
            // get the map projection
            Projection proj = theMap.getProjection();
            // prepare the line for rendering
            cLine.generate(proj);
            // render the line graphic
            cLine.render(g);
        }
    }
View Full Code Here

            list = new OMGraphicList();
        } else {
            list.clear();
        }

        OMLine oldLine = null;
        Geo ogc = null;

        for (Iterator it = lines.iterator(); it.hasNext();) {

            OMLine line = (OMLine) it.next();
            float[] ll = line.getLL();
            Geo g1 = new Geo(ll[0], ll[1]);
            Geo g2 = new Geo(ll[2], ll[3]);

            Geo gc = g1.crossNormalize(g2);

            OMPoint p = new OMPoint((float) gc.getLatitude(), (float) gc.getLongitude(), 3);
            p.setLinePaint(line.getLinePaint());
            p.setFillPaint(line.getFillPaint());
            p.setStroke(line.getStroke());

            line.addArrowHead(true);

            list.add(line);
            list.add(p);

            if (oldLine != null) {

                float[] ll2 = oldLine.getLL();
                Geo g3 = new Geo(ll2[0], ll2[1]);
                Geo g4 = new Geo(ll2[2], ll2[3]);

                OMLine line2 = new OMLine((float) ogc.getLatitude(), (float) ogc.getLongitude(), (float) gc.getLatitude(), (float) gc.getLongitude(), OMGraphic.LINETYPE_GREATCIRCLE);
                line2.setLinePaint(line.getLinePaint());
                line2.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0f, new float[] {
                        10, 10 }, 0f));
                line2.addArrowHead(true);
                list.add(line2);

                Geo i = gc.crossNormalize(ogc);

                if (!(Intersection.isOnSegment(g1, g2, i) || Intersection.isOnSegment(g3,
View Full Code Here

     *
     * @return An OMLine with the given properties
     */
    public OMLine createLine(float lat1, float lon1, float lat2, float lon2,
                             Color color) {
        OMLine line = new OMLine(lat1, lon1, lat2, lon2, OMGraphic.LINETYPE_GREATCIRCLE);
        line.setLinePaint(color);
        return line;
    }
View Full Code Here

        for (int i = 1; i < nPoints - 1; i++) {
            roadPoints[i - 1] = new RoadPoint(road, createLatLonPoint(xpoints[i],
                    ypoints[i]), this);
            if (drawIntersections) {
                if (showLines) {
                    OMLine line = new YellowLine(xpoints[i - 1], ypoints[i - 1], xpoints[i], ypoints[i], width);
                    toDraw.add(line);
                    toDraw.add(new OMText((xpoints[i - 1] - xpoints[i]) / 2
                            + xpoints[i - 1], (ypoints[i - 1] - ypoints[i]) / 2
                            + ypoints[i - 1] - 5, "" + roadsMade, 0));
                } else {
                    OMPoint point = new YellowPoint(xpoints[i], ypoints[i], 10);
                    toDraw.add(point);
                }
            }
        }

        if (drawIntersections) {
            if (showLines) {
                OMLine line = new YellowLine(xpoints[nPoints - 2], ypoints[nPoints - 2], xpoints[nPoints - 1], ypoints[nPoints - 1], width);
                toDraw.add(line);
                toDraw.add(new OMText((xpoints[nPoints - 2] - xpoints[nPoints - 1])
                        / 2 + xpoints[nPoints - 2], (ypoints[nPoints - 2] - ypoints[nPoints - 1])
                        / 2 + ypoints[nPoints - 2] - 5, "" + roadsMade, 0));
                line.addArrowHead(true);
            } else {
                OMPoint point = new YellowPoint(xpoints[nPoints - 1], ypoints[nPoints - 1], 10);
                toDraw.add(point);
            }
        }
View Full Code Here

                Point last = null;
                Point first = null;
                for (Iterator iter = newPoints.iterator(); iter.hasNext();) {
                    Point pt = (Point) iter.next();
                    if (last != null) {
                        OMLine line = new BlueLine(last.x, last.y, pt.x, pt.y);
                        toDraw.add(line);
                    }
                    if (first == null)
                        first = pt;
                    last = pt;
                }

                // draw line from start to beginning intersection
                OMLine line = new YellowLine(start.x, start.y, first.x, first.y, 10);
                toDraw.add(line);
                line = new YellowLine(last.x, last.y, end.x, end.y, 10);
                toDraw.add(line);
            }
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of com.bbn.openmap.omGraphics.OMLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.