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

📄 editableomrangerings.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
字号:
// **********************************************************************// // <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/omGraphics/EditableOMRangeRings.java,v $// $RCSfile: EditableOMRangeRings.java,v $// $Revision: 1.6.2.4 $// $Date: 2005/12/28 22:30:51 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics;import java.awt.Component;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.JToolBar;import com.bbn.openmap.Environment;import com.bbn.openmap.I18n;import com.bbn.openmap.gui.GridBagToolBar;import com.bbn.openmap.proj.Length;import com.bbn.openmap.util.Debug;/** */public class EditableOMRangeRings extends EditableOMCircle {    protected boolean snapToInterval = false;    /**     * Create the EditableOMRangeRings, setting the state machine to create the     * circle off of the gestures.     */    public EditableOMRangeRings() {        createGraphic(null);    }    /**     * Create an EditableOMRangeRings with the circleType and renderType     * parameters in the GraphicAttributes object.     */    public EditableOMRangeRings(GraphicAttributes ga) {        createGraphic(ga);    }    /**     * Create the EditableOMRangeRings with an OMCircle already defined, ready     * for editing.     *      * @param omc OMCircle that should be edited.     */    public EditableOMRangeRings(OMRangeRings omc) {        setGraphic(omc);    }    /**     * Create and set the graphic within the state machine. The     * GraphicAttributes describe the type of circle to create.     */    public void createGraphic(GraphicAttributes ga) {        init();        stateMachine.setUndefined();        int renderType = OMGraphic.RENDERTYPE_LATLON;        if (ga != null) {            renderType = ga.getRenderType();        }        if (Debug.debugging("eomc")) {            Debug.output("EditableOMRangeRings.createGraphic(): rendertype = "                    + renderType);        }        circle = new OMRangeRings(90f, -180f, 0f);        if (ga != null) {            ga.setTo(circle);        }    }    /**     * Modifies the gui to not include line type adjustments, and adds widgets     * to control range ring settings.     *      * @param graphicAttributes the GraphicAttributes to use to get the GUI     *        widget from to control those parameters for this EOMG.     * @return java.awt.Component to use to control parameters for this EOMG.     */    public Component getGUI(GraphicAttributes graphicAttributes) {        Debug.message("eomg", "EditableOMRangeRings.getGUI");        if (graphicAttributes != null) {            JPanel panel = graphicAttributes.getColorAndLineGUI();            panel.add(getRangeRingGUI());            return panel;        } else {            return getRangeRingGUI();        }    }    public void updateInterval(int val) {        ((OMRangeRings) circle).setInterval(val);        if (intervalField != null) {            intervalField.setText(Integer.toString(val));        }        if (snapToInterval) {            setRadius(circle.getRadius());        }        redraw(null, true);    }    public void updateInterval(String intervalStr) {        int oldValue = ((OMRangeRings) circle).getInterval();        int value = interpretValue(intervalStr);        if (value <= 0) {            value = oldValue;        }        updateInterval(value);    }    public int interpretValue(String intervalStr) {        int value = -1;        try {            if (intervalStr.toLowerCase().endsWith("m")) {                intervalStr = intervalStr.substring(0, intervalStr.length() - 1);                value = (int) df.parse(intervalStr).intValue() * 1000000;            } else if (intervalStr.toLowerCase().endsWith("k")) {                intervalStr = intervalStr.substring(0, intervalStr.length() - 1);                value = df.parse(intervalStr).intValue() * 1000;            } else if (intervalStr.trim().equals("")) {                // do nothing            } else {                value = df.parse(intervalStr).intValue();            }        } catch (java.text.ParseException e) {            Debug.error("RangeRing interval value not valid: " + intervalStr);        } catch (NumberFormatException e) {            Debug.error("RangeRing interval value not valid: " + intervalStr);        }        return value;    }    protected JTextField intervalField = null;    protected JToolBar rrToolBar = null;    protected transient java.text.DecimalFormat df = new java.text.DecimalFormat();    protected I18n i18n = Environment.getI18n();    protected JToolBar getRangeRingGUI() {        if (rrToolBar == null) {            rrToolBar = new GridBagToolBar();            rrToolBar.setFloatable(false);            rrToolBar.setMargin(new Insets(0, 1, 0, 1));            // JPanel intervalPanel =            // PaletteHelper.createPaletteJPanel("Interval");            intervalField = new JTextField(Integer.toString(((OMRangeRings) circle).getInterval()), 5);            intervalField.setMargin(new Insets(0, 1, 0, 1));            intervalField.setHorizontalAlignment(JTextField.RIGHT);            intervalField.setToolTipText(i18n.get(this,                    "intervalField.tooltip",                    "Value for interval between rings."));            intervalField.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent ae) {                    updateInterval(((JTextField) (ae.getSource())).getText());                }            });            rrToolBar.add(intervalField);            // JSlider intervalSlide = new JSlider(            // JSlider.HORIZONTAL, 1/*min*/, 200/*max*/,            // ((OMRangeRings)circle).getInterval()/*inital*/);            // java.util.Hashtable dict = new java.util.Hashtable();            // dict.put(new Integer(1), new JLabel("1"));            // dict.put(new Integer(50), new JLabel("50"));            // dict.put(new Integer(100), new JLabel("100"));            // dict.put(new Integer(150), new JLabel("150"));            // dict.put(new Integer(200), new JLabel("200"));            // intervalSlide.setLabelTable(dict);            // intervalSlide.setPaintLabels(true);            // intervalSlide.setMajorTickSpacing(10);            // intervalSlide.setPaintTicks(true);            // intervalSlide.setSnapToTicks(false);            // intervalSlide.addChangeListener(new ChangeListener() {            // public void stateChanged(ChangeEvent ce) {            // JSlider slider = (JSlider) ce.getSource();            // if (slider.getValueIsAdjusting()) {            // ((OMRangeRings)circle).setInterval(slider.getValue());            // }            // }            // });            Length[] available = Length.getAvailable();            String[] unitStrings = new String[available.length + 1];            String current = null;            Length l = ((OMRangeRings) circle).getIntervalUnits();            if (l != null) {                current = l.toString();            }            int currentIndex = unitStrings.length - 1;            for (int i = 0; i < available.length; i++) {                unitStrings[i] = available[i].toString();                if (current != null && unitStrings[i].equals(current)) {                    currentIndex = i;                }            }            unitStrings[unitStrings.length - 1] = i18n.get(this,                    "unitStrings.concentric",                    "concentric");            JComboBox unitList = new JComboBox(unitStrings);            unitList.setBorder(new javax.swing.border.EmptyBorder(0, 1, 0, 1));            unitList.setSelectedIndex(currentIndex);            unitList.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e) {                    JComboBox jcb = (JComboBox) e.getSource();                    OMRangeRings rr = (OMRangeRings) circle;                    Length newLength = Length.get((String) jcb.getSelectedItem());                    Length oldLength = rr.getIntervalUnits();                    /*                     * If newLength is not null and oldLength is not null, just                     * translate the distance that is current specified. If                     * newLength is null, then find out how many rings are on                     * the range ring and set the interval to that. If oldLength                     * is null, find out the radius and divide it by the number                     * of rings - 1.                     */                    int value = interpretValue(intervalField.getText());                    if (value <= 0) {                        value = 4;                    }                    if (newLength != null && oldLength != null) {                        value = (int) newLength.fromRadians(oldLength.toRadians(value));                    } else {                        int numSubCircles;                        if (rr.subCircles == null || rr.subCircles.length == 0) {                            numSubCircles = 1;                        } else {                            numSubCircles = rr.subCircles.length;                        }                        if (newLength == null) {                            value = numSubCircles;                        } else if (oldLength == null) {                            value = (int) Math.ceil(newLength.fromRadians(Length.DECIMAL_DEGREE.toRadians(rr.getRadius()))                                    / numSubCircles);                        }                    }                    ((OMRangeRings) circle).setIntervalUnits(newLength);                    updateInterval(value);                }            });            rrToolBar.add(unitList);            String snapText = i18n.get(this, "snapToInterval", "Snap");            JCheckBox snapBox = new JCheckBox(snapText, isSnapToInterval());            snapText = i18n.get(this,                    "snapToInterval",                    I18n.TOOLTIP,                    "Round radius to nearest interval value.");            snapBox.setToolTipText(snapText);            snapBox.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent ae) {                    setSnapToInterval(((JCheckBox) ae.getSource()).isSelected());                    if (snapToInterval) {                        setRadius(circle.getRadius());                    }                    redraw(null, true);                }            });            rrToolBar.add(snapBox);        }        return rrToolBar;    }    protected boolean drawLabelsHolder = true;    /**     * A convenience method that gives an EditableOMGraphic a chance to modify     * the OMGraphic so it can be drawn quickly, by turning off labels, etc,     * right before the XORpainting happens. The OMGraphic should be configured     * so that the render method does the least amount of painting possible.     * Note that the DrawingAttributes for the OMGraphic have already been set     * to DrawingAttributes.DEFAULT (black line, clear fill).     */    protected void modifyOMGraphicForEditRender() {        OMRangeRings omrr = (OMRangeRings) getGraphic();        drawLabelsHolder = omrr.getDrawLabels();        omrr.setDrawLabels(false);    }    /**     * A convenience method that gives an EditableOMGraphic a chance to reset     * the OMGraphic so it can be rendered normally, after it has been modified     * for quick paints. The DrawingAttributes for the OMGraphic have already     * been reset to their normal settings, from the DrawingAttributes.DEFAULT     * settings that were used for the quick paint.     */    protected void resetOMGraphicAfterEditRender() {        ((OMRangeRings) getGraphic()).setDrawLabels(drawLabelsHolder);    }    public boolean isSnapToInterval() {        return snapToInterval;    }    public void setSnapToInterval(boolean snapToInterval) {        this.snapToInterval = snapToInterval;    }    protected void setRadius(float radius) {        if (circle != null) {            if (snapToInterval) {                OMRangeRings rr = (OMRangeRings) circle;                Length units = rr.getIntervalUnits();                if (units != null) {                    float rds = units.fromRadians(Length.DECIMAL_DEGREE.toRadians(radius));                    radius = Math.round(rds / rr.getInterval())                            * rr.getInterval();                    radius = Length.DECIMAL_DEGREE.fromRadians(units.toRadians(radius));                }            }            circle.setRadius(radius);        }    }}

⌨️ 快捷键说明

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