Package com.bbn.openmap.omGraphics

Examples of com.bbn.openmap.omGraphics.OMGraphicList


     *        could be there, too, but then we wouldn't do anything.
     */
    protected OMGraphicList constructGraticuleLines(float up, float down,
                                                    float left, float right,
                                                    int showWhichLines) {
        OMGraphicList lines = new OMGraphicList();

        // Set the line limits for the lat/lon lines...
        int north = (int) Math.ceil(up);
        if (north > 80)
            north = 80;

        int south = (int) Math.floor(down);
        south -= (south % 10); // Push down to the lowest 10 degree
        // line.
        // for neg numbers, Mod raised it, lower it again. Also
        // handle straddling the equator.
        if ((south < 0 && south > -80) || south == 0)
            south -= 10;

        int west = (int) Math.floor(left);
        west -= (west % 10);
        // for neg numbers, Mod raised it, lower it again. Also
        // handle straddling the prime meridian.
        if ((west < 0 && west > -180) || west == 0)
            west -= 10;

        int east = (int) Math.ceil(right);
        if (east > 180)
            east = 180;

        int stepSize;
        // Choose how far apart the lines will be.
        stepSize = ((showWhichLines == SHOW_ONES) ? 1 : 5);
        float[] llp;
        OMPoly currentLine;
        OMText currentText;

        // For calculating text locations
        java.awt.Point point;
        LatLonPoint llpoint;

        Projection projection = getProjection();

        // generate other parallels of latitude be creating series
        // of polylines
        for (int i = south; i < north; i += stepSize) {
            float lat = (float) i;
            // generate parallel of latitude North/South of the
            // equator
            if (west < 0 && east > 0) {
                llp = new float[6];
                llp[2] = lat;
                llp[3] = 0f;
                llp[4] = lat;
                llp[5] = east;
            } else {
                llp = new float[4];
                llp[2] = lat;
                llp[3] = east;
            }
            llp[0] = lat;
            llp[1] = west;

            // Do not duplicate the 10 degree line.
            if ((lat % 10) != 0) {
                currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT
                        : OMGraphic.LINETYPE_RHUMB);
                if ((lat % 5) == 0) {
                    currentLine.setLinePaint(fiveDegreeColor);
                } else {
                    currentLine.setLinePaint(oneDegreeColor);
                }
                lines.addOMGraphic(currentLine);
            }

            if (showRuler && (lat % 2) == 0) {
                if (boxy) {
                    point = projection.forward(lat, west);
                    point.x = 0;
                    llpoint = projection.inverse(point);
                } else {
                    llpoint = new LatLonPoint(lat, west);
                    while (projection.forward(llpoint).x < 0) {
                        llpoint.setLongitude(llpoint.getLongitude() + stepSize);
                    }
                }

                currentText = new OMText(llpoint.getLatitude(), llpoint.getLongitude(),
                // Move them up a little
                        (int) 2, (int) -2, Integer.toString((int) lat), font, OMText.JUSTIFY_LEFT);
                currentText.setLinePaint(textColor);
                lines.addOMGraphic(currentText);
            }
        }

        // generate lines of longitude
        for (int i = west; i < east; i += stepSize) {
            float lon = (float) i;

            if (north < 0 && south > 0) {
                llp = new float[6];
                llp[2] = 0f;
                llp[3] = lon;
                llp[4] = south;
                llp[5] = lon;
            } else {
                llp = new float[4];
                llp[2] = south;
                llp[3] = lon;
            }
            llp[0] = north;
            llp[1] = lon;

            if ((lon % 10) != 0) {
                currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT
                        : OMGraphic.LINETYPE_GREATCIRCLE);
                if ((lon % 5) == 0) {
                    currentLine.setLinePaint(fiveDegreeColor);
                } else {
                    currentLine.setLinePaint(oneDegreeColor);
                }
                lines.addOMGraphic(currentLine);
            }

            if (showRuler && (lon % 2) == 0) {
                if (boxy) {
                    point = projection.forward(south, lon);
                    point.y = projection.getHeight();
                    llpoint = projection.inverse(point);
                } else {
                    llpoint = new LatLonPoint(south, lon);
                    while (projection.forward(llpoint).y > projection.getHeight()) {
                        llpoint.setLatitude(llpoint.getLatitude() + stepSize);
                    }
                }

                currentText = new OMText(llpoint.getLatitude(), llpoint.getLongitude(),
                // Move them up a little
                        (int) 2, (int) -5, Integer.toString((int) lon), font, OMText.JUSTIFY_CENTER);
                currentText.setLinePaint(textColor);
                lines.addOMGraphic(currentText);

            }
        }

        if (Debug.debugging("graticule")) {
            Debug.output("GraticuleLayer.constructTenDegreeLines(): "
                    + "constructed " + lines.size() + " graticule lines");
        }
        lines.generate(projection);
        return lines;
    }
View Full Code Here


    }

    /** Create the ten degree lines. */
    protected OMGraphicList constructTenDegreeLines() {

        OMGraphicList lines = new OMGraphicList(3);
        OMPoly currentLine;

        // generate other parallels of latitude by creating series
        // of polylines
        for (int i = 1; i <= 8; i++) {
            for (int j = -1; j < 2; j += 2) {
                float lat = (float) (10 * i * j);
                // generate parallel of latitude North/South of the
                // equator
                float[] llp = { lat, -180f, lat, -90f, lat, 0f, lat, 90f, lat,
                        180f };
                currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT
                        : OMGraphic.LINETYPE_RHUMB);
                currentLine.setLinePaint(tenDegreeColor);
                lines.addOMGraphic(currentLine);
            }
        }

        // generate lines of longitude
        for (int i = 1; i < 18; i++) {
            for (int j = -1; j < 2; j += 2) {
                float lon = (float) (10 * i * j);
                //not quite 90.0 for beautification reasons.
                float[] llp = { 80f, lon, 0f, lon, -80f, lon };
                if (MoreMath.approximately_equal(Math.abs(lon), 90f, 0.001f)) {
                    llp[0] = 90f;
                    llp[4] = -90f;
                }
                currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT
                        : OMGraphic.LINETYPE_GREATCIRCLE);
                currentLine.setLinePaint(tenDegreeColor);
                lines.addOMGraphic(currentLine);
            }
        }

        if (Debug.debugging("graticule")) {
            Debug.output("GraticuleLayer.constructTenDegreeLines(): "
                    + "constructed " + lines.size() + " graticule lines");
        }
        lines.generate(getProjection());
        return lines;
    }
View Full Code Here

     */
    protected OMGraphicList constructTensLabels(float up, float down,
                                                float left, float right,
                                                boolean doLats) {

        OMGraphicList labels = new OMGraphicList();

        // Set the line limits for the lat/lon lines...
        int north = (int) Math.ceil(up);
        if (north > 80)
            north = 80;

        int south = (int) Math.floor(down);
        south -= (south % 10); // Push down to the lowest 10 degree
        // line.
        // for neg numbers, Mod raised it, lower it again
        if ((south < 0 && south > -70) || south == 0) {
            south -= 10;
        }

        int west = (int) Math.floor(left);
        west -= (west % 10);
        // for neg numbers, Mod raised it, lower it again
        if ((west < 0 && west > -170) || west == 0) {
            west -= 10;
        }

        int east = (int) Math.ceil(right);
        if (east > 180)
            east = 180;

        int stepSize = 10;
        OMText currentText;

        // For calculating text locations
        java.awt.Point point;
        LatLonPoint llpoint;
        Projection projection = getProjection();

        if (doLats) {

            // generate other parallels of latitude be creating series
            // of labels
            for (int i = south; i < north; i += stepSize) {
                float lat = (float) i;

                if ((lat % 2) == 0) {
                    if (boxy) {
                        point = projection.forward(lat, west);
                        point.x = 0;
                        llpoint = projection.inverse(point);
                    } else {
                        llpoint = new LatLonPoint(lat, west);
                        while (projection.forward(llpoint).x < 0) {
                            llpoint.setLongitude(llpoint.getLongitude()
                                    + stepSize);
                        }
                    }

                    currentText = new OMText(llpoint.getLatitude(), llpoint.getLongitude(), (int) 2, (int) -2, // Move
                            // them
                            // up a
                            // little
                            Integer.toString((int) lat), font, OMText.JUSTIFY_LEFT);
                    currentText.setLinePaint(textColor);
                    labels.addOMGraphic(currentText);
                }
            }
        }

        // generate labels of longitude
        for (int i = west; i < east; i += stepSize) {
            float lon = (float) i;

            if ((lon % 2) == 0) {
                if (boxy) {
                    point = projection.forward(south, lon);
                    point.y = projection.getHeight();
                    llpoint = projection.inverse(point);
                } else {
                    llpoint = new LatLonPoint(south, lon);
                    while (projection.forward(llpoint).y > projection.getHeight()) {
                        llpoint.setLatitude(llpoint.getLatitude() + stepSize);
                    }
                }

                currentText = new OMText(llpoint.getLatitude(), llpoint.getLongitude(),
                // Move them up a little
                        (int) 2, (int) -5, Integer.toString((int) lon), font, OMText.JUSTIFY_CENTER);
                currentText.setLinePaint(textColor);
                labels.addOMGraphic(currentText);

            }
        }

        if (Debug.debugging("graticule")) {
            Debug.output("GraticuleLayer.constructTensLabels(): "
                    + "constructed " + labels.size() + " graticule labels");
        }
        labels.generate(projection);
        return labels;
    }
View Full Code Here

    }

    /** Constructs the Dateline and Prime Meridian lines. */
    protected OMGraphicList constructMarkerLines() {

        OMGraphicList lines = new OMGraphicList(3);
        OMPoly currentLine;

        // generate Prime Meridian and Dateline
        for (int j = 0; j < 360; j += 180) {
            float lon = (float) j;
            float[] llp = { 90f, lon, 0f, lon, -90f, lon };
            currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT
                    : OMGraphic.LINETYPE_GREATCIRCLE);
            currentLine.setLinePaint(dateLineColor);
            lines.addOMGraphic(currentLine);
        }

        // equator
        float[] llp = { 0f, -180f, 0f, -90f, 0f, 0f, 0f, 90f, 0f, 180f };
        // polyline
        currentLine = new OMPoly(llp, OMGraphic.DECIMAL_DEGREES, boxy ? OMGraphic.LINETYPE_STRAIGHT
                : OMGraphic.LINETYPE_GREATCIRCLE);
        currentLine.setLinePaint(equatorColor);
        lines.addOMGraphic(currentLine);

        if (Debug.debugging("graticule")) {
            Debug.output("GraticuleLayer.constructMarkerLines(): "
                    + "constructed " + lines.size() + " graticule lines");
        }
        lines.generate(getProjection());
        return lines;
    }
View Full Code Here

     *
     * @param p projection of the screen, holding scale, center
     * coords, height, width.
     */
    public OMGraphicList getRectangle(Projection p) {
        OMGraphicList list = new OMGraphicList();
       
        currentProjection = p;

        String urlString = createQueryString(p);

        if (Debug.debugging("cis")) {
            Debug.output("CorbaImagePlugIn.getRectangle() with \"" + urlString + "\"");
        }

        if (urlString == null) {
            return list;
        }

        Server serv = getServer();
        if (serv == null) return null;
        byte[] imageData;

        Debug.message("cis", "CorbaImagePlugIn: requesting image data from server...");

        try {
            imageData = serv.getImage(urlString);

            if (Debug.debugging("cis")){
                Debug.output("CorbaImagePlugIn: got image data length " +
                             imageData.length);
            }
            ImageIcon ii = new ImageIcon(imageData);
            OMRaster image = new OMRaster((int)0, (int)0, ii);
            list.add(image);

        } catch (org.omg.CORBA.SystemException e){
            handleCORBAError(e);
            server = null;
        }

        list.generate(p);
        return list;
    } //end getRectangle
View Full Code Here

     *
     * @param p projection of the screen, holding scale, center coords, height,
     *        width.
     */
    public OMGraphicList getRectangle(Projection p) {
        OMGraphicList list = new OMGraphicList();

        currentProjection = p;

        String urlString = createQueryString(p);

        if (Debug.debugging("plugin")) {
            Debug.output("WebImagePlugIn.getRectangle() with \"" + urlString
                    + "\"");
        }

        if (urlString == null) {
            return list;
        }

        java.net.URL url = null;

        try {
            url = new java.net.URL(urlString);
            java.net.HttpURLConnection urlc = (java.net.HttpURLConnection) url.openConnection();

            if (Debug.debugging("plugin")) {
                Debug.output("url content type: " + urlc.getContentType());
            }

            if (urlc == null || urlc.getContentType() == null) {
                if (layer != null) {
                    layer.fireRequestMessage(getName()
                            + ": unable to connect to " + getServerName());
                } else {
                    Debug.error(getName() + ": unable to connect to "
                            + getServerName());
                }
                return list;
            }

            // text
            if (urlc.getContentType().startsWith("text")) {
                java.io.BufferedReader bin = new java.io.BufferedReader(new java.io.InputStreamReader(urlc.getInputStream()));
                String st;
                String message = "";
                while ((st = bin.readLine()) != null) {
                    message += st;
                }

                // Debug.error(message);
                // How about we toss the message out to the user
                // instead?
                if (layer != null) {
                    layer.fireRequestMessage(message);
                }

                // image
            } else if (urlc.getContentType().startsWith("image")) {
                // disconnect and reconnect in ImageIcon is very
                // expensive
                // urlc.disconnect();
                // ImageIcon ii = new ImageIcon(url);

                // this doesn't work always
                // ImageIcon ii = new ImageIcon((Image)
                // urlc.getContent());

                // the best way, no reconnect, but can be an
                // additional 'in memory' image
                InputStream in = urlc.getInputStream();
                // ------- Testing without this
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                int buflen = 2048; // 2k blocks
                byte buf[] = new byte[buflen];
                int len = -1;
                while ((len = in.read(buf, 0, buflen)) != -1) {
                    out.write(buf, 0, len);
                }
                out.flush();
                out.close();
                ImageIcon ii = new ImageIcon(out.toByteArray());

                // -------- To here, replaced by two lines below...

                // DFD - I've seen problems with these lines below handling PNG
                // images, and with some servers with some coverages, like there
                // was something in the image under certain conditions that made
                // it tough to view. So while it might be more memory efficient
                // to do the code below, we'll error on the side of correctness
                // until we figure out what's going on.

                // FileCacheImageInputStream fciis = new
                // FileCacheImageInputStream(in, null);
                // BufferedImage ii = ImageIO.read(fciis);

                OMRaster image = new OMRaster((int) 0, (int) 0, ii);
                list.add(image);
            } // end if image
        } catch (java.net.MalformedURLException murle) {
            Debug.error("WebImagePlugIn: URL \"" + urlString
                    + "\" is malformed.");
        } catch (java.io.IOException ioe) {
            JOptionPane.showMessageDialog(null,
                    getName() + ":\n\n   Couldn't connect to "
                            + getServerName(),
                    "Connection Problem",
                    JOptionPane.INFORMATION_MESSAGE);

        }

        list.generate(p);
        return list;
    } // end getRectangle
View Full Code Here

                    + "calling getRectangle " + " with projection: " + proj
                    + " ul = " + proj.getUpperLeft() + " lr = "
                    + proj.getLowerRight());
        }

        OMGraphicList omGraphicList = null;

        if (plugin != null && proj != null) {
            omGraphicList = plugin.getRectangle(proj);
        }

        /////////////////////
        // safe quit
        int size = 0;
        if (omGraphicList != null) {
            size = omGraphicList.size();
            if (Debug.debugging("basic")) {
                Debug.output(getName()
                        + "|PlugInLayer.prepare(): finished with " + size
                        + " graphics");
            }
        } else {
            if (Debug.debugging("basic")) {
                Debug.output(getName()
                        + "|PlugInLayer.prepare(): finished with null graphics list");
            }
            omGraphicList = new OMGraphicList();
        }

        // NOTE - We've assumed that the graphics are projected!

        return omGraphicList;
View Full Code Here

     *
     * @return a list of graphics.
     */
    public synchronized OMGraphicList prepare() {

        OMGraphicList currentList = getList();

        if (listener == null) {
            listener = new LinkListener(linkManager, this, currentGenerator);
        }

        if (listener != null && !listener.isListening()) {
            // Call LinkListener to launch SwingWorker to kick off a
            // thread for the listener.
            listener.startUp();
        }

        if (Debug.debugging("link")) {
            Debug.output(getName() + "|LinkLayer.prepare(): Listener "
                    + (listener == null ? "is null," : "is OK,")
                    + " listening ("
                    + (listener == null ? "nope" : "" + listener.isListening())
                    + ")");
        }

        if (isCancelled()) {
            Debug.message("link", getName() + "|LinkLayer.prepare(): aborted.");
            return currentList;
        }

        Projection projection = getProjection();
        if (projection == null) {
            Debug.error("Link Layer needs to be added to the MapBean before it can get graphics!");
            return currentList;
        } else if (currentList != null) {
            // If the list isn't empty, it isn't being cleared when a
            // new projection is received, as dictated by the policy
            // of the layer. Should regenerate it here. If it's
            // understood that a new list will be sent by the server,
            // then a different ProjectionChangePolicy should be used.
            currentList.generate(projection);
        }

        Debug.message("basic", getName() + "|LinkLayer.prepare(): doing it");

        // Setting the OMGraphicsList for this layer. Remember, the
View Full Code Here

     *
     * @param graphic An OMGraphic to add the graphics list
     * @param record A record to add to the DbfTableModel
     */
    public void addRecord(OMGraphic graphic, ArrayList record) {
        OMGraphicList _list = getList();
       
        // Associate the record directly in the OMGraphic
        graphic.putAttribute(SHAPE_DBF_INFO_ATTRIBUTE, record);
       
        if (_list != null) {
            _list.add(graphic);
        }

        if (_model != null) {
            _model.addRecord(record);
        }
View Full Code Here

        if (loader != null) {
            loader.setProjection(p);
        }

        OMGraphicList list = (OMGraphicList) super.getList();
        list.generate(p);

        if (Debug.debugging("graphicloader")) {
            Debug.output("GraphicLoaderPlugIn returning list of " + list.size()
                    + " objects.");
        }

        // Used to control the doPrepare() call in setList().
        synchronized (lock) {
View Full Code Here

TOP

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

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.