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

📄 testlayer.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
// **********************************************************************// // <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/test/TestLayer.java,v $// $RCSfile: TestLayer.java,v $// $Revision: 1.4.2.2 $// $Date: 2005/08/09 21:17:55 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.test;import java.awt.Color;import java.awt.Component;import java.awt.Font;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.FocusAdapter;import java.awt.event.FocusEvent;import java.awt.event.MouseEvent;import java.util.StringTokenizer;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JRootPane;import javax.swing.JTextArea;import javax.swing.JTextField;import com.bbn.openmap.event.MapMouseListener;import com.bbn.openmap.event.NavMouseMode;import com.bbn.openmap.event.NullMouseMode;import com.bbn.openmap.event.SelectMouseMode;import com.bbn.openmap.layer.OMGraphicHandlerLayer;import com.bbn.openmap.omGraphics.OMArrowHead;import com.bbn.openmap.omGraphics.OMCircle;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMLine;import com.bbn.openmap.omGraphics.OMPoly;import com.bbn.openmap.omGraphics.OMRect;import com.bbn.openmap.omGraphics.OMText;import com.bbn.openmap.proj.Length;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PaletteHelper;/** * A Layer for testing different types of graphics. The GUI code is * very large and ugly. Maybe break this off into several classes. * <p> * This layer responds to the following properties: <code><pre> *  *  # initial visibility settings: *  test.line.visible=true *  test.circ.visible=true *  test.rect.visible=true *  test.text.visible=true *  test.poly.visible=true *  # latlon vertices of the poly *  #test.poly.vertices=80 -180 80 -90 80 0 80 90 80 180 70 180 70 90 70 0 70 -90 70 -180 *   * </pre></code> In addition, you can get this layer to work with the * OpenMap viewer by editing your openmap.properties file: <code><pre> *  *  # layers *  openmap.layers=test ... *  # class *  test.class=com.bbn.openmap.layer.TestLayer *  # name *  test.prettyName=Graticule *   * </pre></code> */public class TestLayer extends OMGraphicHandlerLayer implements        MapMouseListener {    public final static transient String LineVisibleProperty = ".line.visible";    public final static transient String CircVisibleProperty = ".circ.visible";    public final static transient String RectVisibleProperty = ".rect.visible";    public final static transient String TextVisibleProperty = ".text.visible";    public final static transient String PolyVisibleProperty = ".poly.visible";    public final static transient String PolyVertsProperty = ".poly.vertices";    // colors    protected final static transient String[] colorNames = new String[] {            "white", "lightGray", "gray", "darkGray", "black", "red", "pink",            "orange", "yellow", "green", "magenta", "cyan", "blue", "clear" };    protected final static transient Color[] colors = new Color[] {            Color.white, Color.lightGray, Color.gray, Color.darkGray,            Color.black, Color.red, Color.pink, Color.orange, Color.yellow,            Color.green, Color.magenta, Color.cyan, Color.blue, OMGraphic.clear };    protected final static transient int NCOLORS = colors.length;    // graphics and peers    protected OMCircle omcircle = new OMCircle();    protected Circle circle = new Circle();    protected OMLine omline = new OMLine();    protected Line line = new Line();    protected OMRect omrect = new OMRect();    protected Rect rect = new Rect();    protected OMText omtext = new OMText();    protected Text text = new Text();    protected OMPoly ompoly = new OMPoly();    protected Poly poly = new Poly();    protected JPanel gui = null;// the GUI    /**     * Construct the TestLayer.     */    public TestLayer() {}    /**     * The properties and prefix are managed and decoded here, for the     * standard uses of the GraticuleLayer.     *      * @param prefix string prefix used in the properties file for     *        this layer.     * @param properties the properties set in the properties file.     */    public void setProperties(String prefix, java.util.Properties properties) {        super.setProperties(prefix, properties);        line.visible = Boolean.valueOf(properties.getProperty(prefix                + LineVisibleProperty, "true")).booleanValue();        circle.visible = Boolean.valueOf(properties.getProperty(prefix                + CircVisibleProperty, "true")).booleanValue();        rect.visible = Boolean.valueOf(properties.getProperty(prefix                + RectVisibleProperty, "true")).booleanValue();        text.visible = Boolean.valueOf(properties.getProperty(prefix                + TextVisibleProperty, "true")).booleanValue();        poly.visible = Boolean.valueOf(properties.getProperty(prefix                + PolyVisibleProperty, "true")).booleanValue();        String verts = properties.getProperty(prefix + PolyVertsProperty);        if (verts != null) {            poly.setVertices(verts);        }    }    public synchronized OMGraphicList prepare() {        if (getList() == null) {            setList(generateGraphics());        }        return super.prepare();    }    /**     * Create and project the graphics.     */    protected OMGraphicList generateGraphics() {        OMGraphicList graphics = new OMGraphicList();        // create OMLine from internal line representation        switch (line.rt) {        case OMGraphic.RENDERTYPE_LATLON:            omline = new OMLine(line.llpts[0], line.llpts[1], line.llpts[2], line.llpts[3], line.type, line.nsegs);            break;        case OMGraphic.RENDERTYPE_XY:            omline = new OMLine(line.xypts[0], line.xypts[1], line.xypts[2], line.xypts[3]);            break;        case OMGraphic.RENDERTYPE_OFFSET:            omline = new OMLine(line.llpts[0], line.llpts[1], line.xypts[0], line.xypts[1], line.xypts[2], line.xypts[3]);            break;        default:            System.err.println("ARRRR!");            break;        }        if (line.arrowhead) {            omline.addArrowHead(line.arrowtype);        }        // create OMCircle from internal circle representation        switch (circle.rt) {        case OMGraphic.RENDERTYPE_LATLON:            omcircle = new OMCircle(circle.llpts[0], circle.llpts[1], circle.radius, Length.KM, circle.nsegs);            omcircle.setPolarCorrection(true);            break;        case OMGraphic.RENDERTYPE_XY:            omcircle = new OMCircle(circle.xypts[0], circle.xypts[1], circle.width, circle.height);            break;        case OMGraphic.RENDERTYPE_OFFSET:            omcircle = new OMCircle(circle.llpts[0], circle.llpts[1], circle.xypts[0], circle.xypts[1], circle.width, circle.height);            break;        default:            System.err.println("ARRRR!");            break;        }        // create OMRect from internal rect representation        switch (rect.rt) {        case OMGraphic.RENDERTYPE_LATLON:            omrect = new OMRect(rect.llpts[0], rect.llpts[1], rect.llpts[2], rect.llpts[3], rect.type, rect.nsegs);            break;        case OMGraphic.RENDERTYPE_XY:            omrect = new OMRect(rect.xypts[0], rect.xypts[1], rect.xypts[2], rect.xypts[3]);            break;        case OMGraphic.RENDERTYPE_OFFSET:            omrect = new OMRect(rect.llpts[0], rect.llpts[1], rect.xypts[0], rect.xypts[1], rect.xypts[2], rect.xypts[3]);            break;        default:            System.err.println("ARRRR!");            break;        }        // create OMText from internal text representation        switch (text.rt) {        case OMGraphic.RENDERTYPE_LATLON:            omtext = new OMText(text.llpts[0], text.llpts[1], text.data, Font.decode(text.font), text.just);            break;        case OMGraphic.RENDERTYPE_XY:            omtext = new OMText(text.xypts[0], text.xypts[1], text.data, Font.decode(text.font), text.just);            break;        case OMGraphic.RENDERTYPE_OFFSET:            omtext = new OMText(text.llpts[0], text.llpts[1], text.xypts[0], text.xypts[1], text.data, Font.decode(text.font), text.just);            break;        default:            System.err.println("ARRRR!");            break;        }        // create OMPoly from internal poly representation        switch (poly.rt) {        case OMGraphic.RENDERTYPE_LATLON:            int len = poly.llpts.length;            float[] llpts = new float[len];            System.arraycopy(poly.llpts, 0, llpts, 0, len);            ompoly = new OMPoly(llpts, OMPoly.DECIMAL_DEGREES, poly.type, poly.nsegs);            break;        case OMGraphic.RENDERTYPE_XY:            ompoly = new OMPoly(poly.xypts);            break;        case OMGraphic.RENDERTYPE_OFFSET:            ompoly = new OMPoly(poly.lat, poly.lon, poly.xypts, poly.cMode);            break;        default:            System.err.println("ARRRR!");            break;        }        // generic        omline.setVisible(line.visible);        omline.setLinePaint(colors[line.lineColor]);        omcircle.setVisible(circle.visible);        omcircle.setLinePaint(colors[circle.lineColor]);        omrect.setVisible(rect.visible);        omrect.setLinePaint(colors[rect.lineColor]);        ompoly.setVisible(poly.visible);        ompoly.setLinePaint(colors[poly.lineColor]);        omtext.setVisible(text.visible);        omtext.setLinePaint(colors[text.lineColor]);        if (circle.isFilled)            omcircle.setFillPaint(colors[circle.fillColor]);        if (rect.isFilled)            omrect.setFillPaint(colors[rect.fillColor]);        if (poly.isFilled)            ompoly.setFillPaint(colors[poly.fillColor]);        graphics.add(omline);        graphics.add(omcircle);        graphics.add(omrect);        graphics.add(omtext);        graphics.add(ompoly);        graphics.generate(getProjection());        return graphics;    }    /**     * Gets the palette associated with the layer.     * <p>     *      * @return Component or null     */    public Component getGUI() {        if (gui == null) {            JPanel pal;            gui = PaletteHelper.createPaletteJPanel("Test");            GridBagLayout gridbag = new GridBagLayout();            GridBagConstraints constraints = new GridBagConstraints();            gui.setLayout(gridbag);            constraints.fill = GridBagConstraints.HORIZONTAL; // fill                                                              // horizontally            constraints.gridwidth = GridBagConstraints.REMAINDER; //another                                                                  // row            constraints.anchor = GridBagConstraints.EAST; // tack to                                                          // the left                                                          // edge            //          constraints.weightx = 0.0;            ActionListener al = new ActionListener() {                public void actionPerformed(ActionEvent e) {                    int index = Integer.parseInt(e.getActionCommand(), 10);                    switch (index) {

⌨️ 快捷键说明

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