⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demolayer.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/DemoLayer.java,v $// $RCSfile: DemoLayer.java,v $// $Revision: 1.11.2.9 $// $Date: 2005/08/09 18:10:43 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.List;import java.util.Properties;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JMenuItem;import javax.swing.JPanel;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.event.MapMouseEvent;import com.bbn.openmap.omGraphics.EditableOMPoly;import com.bbn.openmap.omGraphics.FontSizer;import com.bbn.openmap.omGraphics.GraphicAttributes;import com.bbn.openmap.omGraphics.OMAction;import com.bbn.openmap.omGraphics.OMArc;import com.bbn.openmap.omGraphics.OMAreaList;import com.bbn.openmap.omGraphics.OMArrowHead;import com.bbn.openmap.omGraphics.OMBitmap;import com.bbn.openmap.omGraphics.OMCircle;import com.bbn.openmap.omGraphics.OMColor;import com.bbn.openmap.omGraphics.OMDecoratedSpline;import com.bbn.openmap.omGraphics.OMEllipse;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicConstants;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMLine;import com.bbn.openmap.omGraphics.OMPoint;import com.bbn.openmap.omGraphics.OMPoly;import com.bbn.openmap.omGraphics.OMRect;import com.bbn.openmap.omGraphics.OMScalingIcon;import com.bbn.openmap.omGraphics.OMSpline;import com.bbn.openmap.omGraphics.OMText;import com.bbn.openmap.omGraphics.OMTextLabeler;import com.bbn.openmap.omGraphics.awt.CircleShapeDecoration;import com.bbn.openmap.omGraphics.awt.LineShapeDecoration;import com.bbn.openmap.omGraphics.awt.ShapeDecorator;import com.bbn.openmap.omGraphics.labeled.LabeledOMSpline;import com.bbn.openmap.omGraphics.meteo.IceAreaShapeDecoration;import com.bbn.openmap.omGraphics.meteo.OMHotSurfaceFront;import com.bbn.openmap.omGraphics.meteo.OMOcclusion;import com.bbn.openmap.proj.Length;import com.bbn.openmap.tools.drawing.DrawingTool;import com.bbn.openmap.tools.drawing.DrawingToolRequestor;import com.bbn.openmap.tools.drawing.OMDrawingTool;import com.bbn.openmap.tools.symbology.milStd2525.SymbolPart;import com.bbn.openmap.tools.symbology.milStd2525.SymbolReferenceLibrary;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PaletteHelper;/** * This layer demonstrates interactive capabilities of OpenMap. * Instantiating this layer should show an icon loaded using HTTP * Protocol, which represents Boston, MA in USA. Above Boston it * should show a square that would change color when mouse is moved * over it in 'Gesture' mode. Also clicking once brings up a message * box and more than once brings up browser. * <P> *  * The DemoLayer has also been modified to demonstrate the first uses * of the OMDrawingTool. The Palette has buttons that can be used to * start the tool in several different ways. *  * @see com.bbn.openmap.layer.DemoLayer *  * Just added some decorated splines to test them. EL */public class DemoLayer extends OMGraphicHandlerLayer implements        DrawingToolRequestor {    protected JPanel legend;    /**     * Found in the findAndInit() method, in the MapHandler.     */    protected DrawingTool drawingTool;    /**     * Found in the findAndInit() method, in the MapHandler.     */    protected SymbolReferenceLibrary srl;    /**     * Used by the internal ActionListeners for a callback, see     * getGUI().     */    protected final com.bbn.openmap.tools.drawing.DrawingToolRequestor layer = this;    /**     * Used by geometries created in GUI for specify if the spatial     * filter is for objects inside the drawn shape.     */    protected final static String internalKey = "ik";    /**     * Used by geometries created in GUI for specify if the spatial     * filter is for objects outside the drawn shape.     */    protected final static String externalKey = "ek";    protected GraphicAttributes filterGA = null;    public DemoLayer() {        setName("Demo");        // This is how to set the ProjectionChangePolicy, which        // dictates how the layer behaves when a new projection is        // received.        setProjectionChangePolicy(new com.bbn.openmap.layer.policy.StandardPCPolicy(this, true));        // Making the setting so this layer receives events from the        // SelectMouseMode, which has a modeID of "Gestures". Other        // IDs can be added as needed.        setMouseModeIDsForEvents(new String[] { "Gestures" });    }    public void paint(java.awt.Graphics g) {        // Super calls the RenderPolicy that makes decisions on how to        // paint the OMGraphicList. The only reason we have this        // method overridden is to paint the legend if it exists.        super.paint(g);        if (legend != null) {            legend.paint(g);        }    }    public OMGraphicList init() {        // This layer keeps a pointer to an OMGraphicList that it uses        // for painting. It's initially set to null, which is used as        // a flag in prepare() to signal that the OMGraphcs need to be        // created. The list returned from prepare() gets set in the        // layer.        // This layer uses the StandardPCPolicy for new        // projections, which keeps the list intact and simply calls        // generate() on it with the new projection, and repaint()        // which calls paint().        OMGraphicList omList = new OMGraphicList();        // Location loc = new        // URLRasterLocation(42.3583f,-71.06f,"Boston,Massachusetts,USA","http://javamap.bbn.com:4711/appletimages/city.gif");        // //loc.setLocationColor(Color.blue);        // loc.setShowLocation(true);        // loc.setShowName(true);        // //loc.setDetails("Details");        // omList.add(loc);        int bytearrsize = (16 * 16) / 8;        byte[] bytearr = new byte[bytearrsize];        for (int i = 0; i < bytearr.length; i++) {            bytearr[i] = (byte) 0xffffffff;        }        OMBitmap omb = new OMBitmap(45.3583f, -71.06f, 16, 16, bytearr);        omb.setLinePaint(Color.red);        omb.setFillPaint(null);        omb.setSelectPaint(Color.blue);        omb.setRotationAngle(Math.PI / 2);        omList.add(omb);        OMPoint point = new OMPoint(42f, -72f, 14);        point.setFillPaint(Color.green);        point.setOval(true);        omList.add(point);        OMCircle circle = new OMCircle(40f, -70f, 50, 200);        circle.setRotationAngle(com.bbn.openmap.MoreMath.HALF_PI / 2f);        circle.putAttribute(OMGraphicConstants.LABEL,                new OMTextLabeler("Circle Label", OMText.JUSTIFY_CENTER));        omList.add(circle);        int[] llPointsx = new int[5];        int[] llPointsy = new int[5];        llPointsy[0] = 10;        llPointsx[0] = 170;        llPointsy[1] = 42;        llPointsx[1] = 273;        llPointsy[2] = 38;        llPointsx[2] = 374;        llPointsy[3] = 78;        llPointsx[3] = 468;        llPointsy[4] = 84;        llPointsx[4] = 369;        LabeledOMSpline spline = new LabeledOMSpline(40f, -72, llPointsx, llPointsy, OMPoly.COORDMODE_ORIGIN);        spline.setText("Testing");        spline.setLocateAtCenter(true);        // spline.setIndex(2);        omList.add(spline);        OMSpline spline2 = new OMSpline(llPointsx, llPointsy);        spline2.putAttribute(OMGraphicConstants.LABEL,                new OMTextLabeler("Spline Label"));        spline2.setLinePaint(Color.green);        omList.add(spline2);        float[] llPoints = { 55.0f, -10.0f, 50.0f, -5.0f, 45.0f, -7.0f, 43.0f,                -12.0f, 55.0f, -10.0f };        OMDecoratedSpline omds = new OMDecoratedSpline(llPoints, OMSpline.DECIMAL_DEGREES, OMSpline.LINETYPE_STRAIGHT);        ShapeDecorator sd = new ShapeDecorator();        sd.addDecoration(new LineShapeDecoration(5, com.bbn.openmap.omGraphics.OMColor.clear));        sd.addDecoration(new IceAreaShapeDecoration(7, 7, IceAreaShapeDecoration.RIGHT));        omds.setDecorator(sd);        omList.add(omds);        llPoints = new float[] { 56.0f, -11.0f, 51.0f, -6.0f, 46.0f, -8.0f,                44.0f, -13.0f, 56.0f, -11.0f };        omds = new OMDecoratedSpline(llPoints, OMSpline.DECIMAL_DEGREES, OMSpline.LINETYPE_STRAIGHT);        sd = new ShapeDecorator();        sd.addDecoration(new LineShapeDecoration(3, com.bbn.openmap.omGraphics.OMColor.clear));        sd.addDecoration(new CircleShapeDecoration(5, 5, Color.blue));        omds.setDecorator(sd);        omList.add(omds);        llPoints = new float[] { 57.0f, -12.0f, 52.0f, -7.0f, 47.0f, -9.0f,                45.0f, -14.0f, 57.0f, -12.0f };        omds = new OMDecoratedSpline(llPoints, OMSpline.DECIMAL_DEGREES, OMSpline.LINETYPE_STRAIGHT);        sd = new ShapeDecorator();        sd.addDecoration(new LineShapeDecoration(2, com.bbn.openmap.omGraphics.OMColor.clear));        sd.addDecoration(new CircleShapeDecoration(5, 5, Color.red));        sd.addDecoration(new LineShapeDecoration(2, com.bbn.openmap.omGraphics.OMColor.clear));        sd.addDecoration(new LineShapeDecoration(15, Color.red));        omds.setDecorator(sd);        omList.add(omds);        float[] llPoints2 = { 55.0f, -12.0f, 50.0f, -7.0f, 45.0f, -9.0f, 43.0f,                -14.0f };        OMHotSurfaceFront hf = new OMHotSurfaceFront(llPoints2, OMSpline.DECIMAL_DEGREES, OMSpline.LINETYPE_STRAIGHT);        omList.add(hf);        float[] llPoints3 = { 55.0f, -14.0f, 50.0f, -9.0f, 45.0f, -11.0f,                43.0f, -16.0f };        OMOcclusion oc = new OMOcclusion(llPoints3, OMSpline.DECIMAL_DEGREES, OMSpline.LINETYPE_STRAIGHT);        omList.add(oc);        // float[] llPoints4 = { 55.0f, -16.0f, 50.0f, -11.0f, 45.0f,        // -13.0f,        // 43.0f, -18.0f };        // OMSpline spline3 = new OMDecoratedSpline(llPoints4,        // OMSpline.DECIMAL_DEGREES, OMSpline.LINETYPE_STRAIGHT) {        // protected void initDecorations() {        //        // getDecorator().addDecoration(new TextShapeDecoration(" This        // one has a text ", new Font("arial", Font.PLAIN, 10),        // TextShapeDecoration.LEFT_TO_RIGHT        // + TextShapeDecoration.FOLLOW_POLY,        // TextShapeDecoration.CENTER));        // }        // };        // omList.add(spline3);        OMLine line = new OMLine(40f, -75f, 42f, -70f, OMGraphic.LINETYPE_GREATCIRCLE);        // line.addArrowHead(true);        line.addArrowHead(OMArrowHead.ARROWHEAD_DIRECTION_BOTH);        line.setStroke(new BasicStroke(2));        line.putAttribute(OMGraphicConstants.LABEL,                new OMTextLabeler("Line Label"));        omList.add(line);        OMGraphicList pointList = new OMGraphicList();        for (int i = 0; i < 100; i++) {            point = new OMPoint((float) (Math.random() * 89f), (float) (Math.random() * -179f), 3);            point.setSelectPaint(Color.yellow);            pointList.add(point);        }        omList.add(pointList);        OMEllipse ell = new OMEllipse(new LatLonPoint(60f, -110), 1000, 300, Length.NM, com.bbn.openmap.MoreMath.HALF_PI / 2.0);        ell.setLinePaint(Color.blue);        // ell.setFillPaint(Color.yellow);        omList.add(ell);        ell = new OMEllipse(new LatLonPoint(40f, -75), 800, 250, Length.MILE, 0);        ell.setFillPaint(Color.yellow);        omList.add(ell);        float[] llp2 = new float[] { 0.41789755f, -1.435303f, 0.41813868f,                -1.3967744f };        OMPoly p2 = new OMPoly(llp2, OMGraphic.RADIANS, OMGraphic.LINETYPE_RHUMB);        p2.setLinePaint(Color.yellow);        omList.add(p2);        // OMArc arc = new OMArc(40f, 65f, 750f, Length.MILE, 20f,        // 95f);        OMArc arc = new OMArc((float) 40.0, (float) 65.0, (float) 750.0, Length.MILE, (float) 20.0, (float) 95.0);        arc.setLinePaint(Color.red);        arc.setFillPaint(new Color(120, 0, 0, 128));        arc.setArcType(java.awt.geom.Arc2D.PIE);        arc.putAttribute(OMGraphicConstants.LABEL,                new OMTextLabeler("Arc Label", OMText.JUSTIFY_CENTER));        omList.add(arc);        OMAreaList combo = new OMAreaList();        combo.addOMGraphic(new OMLine((float) 50.453333, (float) 5.223889, (float) 50.375278, (float) 4.873889, 2));        combo.addOMGraphic(new OMLine((float) 50.375278, (float) 4.873889, (float) 50.436944, (float) 4.860556, 2));        // combo.addOMGraphic(new OMLine((float) 50.436944, (float)        // 4.860556, (float) 50.436667, (float) 4.860833, 2));        // combo.addOMGraphic(new OMLine((float) 50.436667, (float)        // 4.860833, (float) 50.490833, (float) 4.847778, 2));        // combo.addOMGraphic(new OMLine((float) 50.491269, (float)        // 4.704239, (float) 50.490833, (float) 4.847778, 3));        combo.addOMGraphic(new OMArc((float) 50.491269, (float) 4.704239, (float) 0.09168520552327833, (float) (28.201865385183652 + 90.21758717585848), (float) -90.21758717585848));        combo.addOMGraphic(new OMLine((float) 50.534167, (float) 4.831111, (float) 50.640833, (float) 4.832222, 2));        combo.addOMGraphic(new OMLine((float) 50.640833, (float) 4.832222, (float) 50.547778, (float) 5.223889, 2));        combo.addOMGraphic(new OMLine((float) 50.547778, (float) 5.223889, (float) 50.453333, (float) 5.223889, 2));        // combo.setConnectParts(true);        // combo.addOMGraphic(new OMLine(30f, -125f, 30f, -100f,        // OMGraphic.LINETYPE_RHUMB));        // combo.addOMGraphic(new OMLine(30f, -100f, 40f, -95f,        // OMGraphic.LINETYPE_GREATCIRCLE));        // combo.addOMGraphic(new OMLine(40f, -95f, 50f, -145f,        // OMGraphic.LINETYPE_GREATCIRCLE));        // combo.addOMGraphic(new OMLine(50f, -145f, 30f, -125f,        // OMGraphic.LINETYPE_STRAIGHT));        combo.setLinePaint(Color.blue);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -