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

📄 sarannotationsupport.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }
    }

    /**
     * Add a new annotation in the screen center.
     * @param text the <code>Annotation</code> text.
     * @param owner if not null, the SARTrack to add the annotation to.
     *              annotation's border and text will be colored according to the owner SARTrack.
     */
    public void addNew(String text, SARTrack owner)
    {
        if (text == null)
            text = showAnnotationDialog("Add New Annotation", null);

        OrbitView view = (OrbitView)this.wwd.getView();
        if(text != null && text.length() > 0 && view != null)
        {
            Position centerPosition = new Position(view.getCenterPosition(), 0);
            SARAnnotation annotation = new SARAnnotation(text, centerPosition);
            addNew(annotation, owner);
            select(annotation);
        }
    }

    public void addNew(SARAnnotation annotation, SARTrack owner)
    {
        if (annotation != null)
        {
            annotation.getAttributes().setDefaults(this.defaults);
            // Reduce annotation distance scaling effect
            annotation.getAttributes().setDistanceMinScale(0.7);
            annotation.getAttributes().setDistanceMaxScale(1.3);
            if (owner != null)
            {
                annotation.setOwner(owner);
                annotation.getAttributes().setTextColor(owner.getColor());
                //annotation.getAttributes().setBorderColor(color);
            }
            add(annotation);
        }
    }

    /**
     * Multi line input dialog. Returns the input text or null if canceled.
     * @param title the dialog window title.
     * @param text the initial text.
     * @return the input text or null if the dialog was canceled.
     */
    private String showAnnotationDialog(String title, String text)
    {
        final JTextArea textArea = new JTextArea(5, 10);
        if (text != null)
            textArea.setText(text);
        // Focus to text area from http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6420212
        textArea.addHierarchyListener(new HierarchyListener() {
            public void hierarchyChanged(HierarchyEvent he) {
                if ((he.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                    if (textArea.isShowing()) {
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                textArea.requestFocus();
                            }
                        });
                    }
                }
            }
        });
        int dialogResult = -1;
        JScrollPane pane = new JScrollPane(textArea);
        if (text != null && text.length() > 0)
        {
            Object[] options = {"Save", "Delete", "Cancel"};
            dialogResult = JOptionPane.showOptionDialog(null, new Object[] {"Enter text", pane}, title,
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
        }
        else
        {
            dialogResult = JOptionPane.showOptionDialog(null, new Object[] {"Enter text", pane}, title,
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
        }
        String newText = null;
        if (dialogResult == JOptionPane.OK_OPTION || dialogResult == JOptionPane.YES_OPTION)
            newText = textArea.getText();
        if (dialogResult == JOptionPane.NO_OPTION)
            newText = "";
        return newText;
    }

    /**
     * Add an annotation.
     * @param annotation the annotation to add.
     */
    public void add(SARAnnotation annotation)
    {
        if(annotation != null)
        {
            annotationLayer.addAnnotation(annotation);
            // Mark the SARTrack as dirty.
            if (annotation.getOwner() != null)
                annotation.getOwner().markDirty();
        }
    }

    /**
     * Edit an annotation.
     * @param annotation the Annotation to be edited.
     */
    public void edit(SARAnnotation annotation)
    {
        if(annotation != null)
        {
            String text = showAnnotationDialog("Edit Annotation", annotation.getText());
            if(text != null)
            {
                if (text.length() > 0)
                {
                    annotation.setText(text);
                    // Mark the owner track as dirty.
                    if (annotation.getOwner() != null)
                        annotation.getOwner().markDirty();
                }
                else
                {
                    // The remove operation will mark the
                    // owner track as tirty.
                    this.remove(annotation);
                }
            }
            this.wwd.redraw();
        }
    }

    /**
     * Remove an annotation.
     * @param annotation the annotation to be removed.
     */
    public void remove(SARAnnotation annotation)
    {
        if (annotation != null)
        {
            annotationLayer.removeAnnotation(annotation);
            if (currentAnnotation == annotation)
                currentAnnotation = null;
            // Mark the SARTrack as dirty.
            if (annotation.getOwner() != null)
                annotation.getOwner().markDirty();
        }

    }

    public void removeAnnotationsForTrack(SARTrack owner)
    {
        for (SARAnnotation sa : getAnnotationsForTrack(owner))
        {
            if (sa != null)
                remove(sa);
        }
    }

    /**
     * Get current annotation.
     * @return current annotation.
     */
    public SARAnnotation getCurrent()
    {
        return currentAnnotation;
    }

    /**
     * Get the annotation collection from the RenderableLayer
     * @return an Annotation collection.
     */
    public Iterable<Annotation> getAnnotations()
    {
       return annotationLayer.getAnnotations();
    }

    public Iterable<SARAnnotation> getAnnotationsForTrack(SARTrack owner)
    {
        java.util.ArrayList<SARAnnotation> result = new java.util.ArrayList<SARAnnotation>();
        for (Annotation a : this.annotationLayer.getAnnotations())
        {
            if (a != null && a instanceof SARAnnotation)
            {
                if (owner == ((SARAnnotation) a).getOwner())
                    result.add((SARAnnotation) a);
            }
        }
        return result;
    }

    /**
     * Set annotations enabled state
     * @param state true if annotations should be enabled.
     */
    public void setEnabled(boolean state)
    {
        annotationLayer.setEnabled(state);
    }

    /**
     * Get the annotations enabled state.
     * @return true if annotations are enabled.
     */
    public boolean getEnabled()
    {
        return annotationLayer.isEnabled();
    }

    /**
     * Get the default attribute set used for all annotations.
     * @return the default attribute set used for all annotations.
     */
    public AnnotationAttributes getDefaults()
    {
        return this.defaults;
    }

    public void writeAnnotations(String filePath, SARTrack trackOwner) throws IOException
    {
        try
        {
            if (filePath != null)
            {
                SARAnnotationWriter writer = new SARAnnotationWriter(filePath);
                writer.writeAnnotations(getAnnotationsForTrack(trackOwner));
                writer.close();
            }
        }
        catch (javax.xml.parsers.ParserConfigurationException e)
        {
            throw new IllegalArgumentException(e);
        }
        catch (javax.xml.transform.TransformerException e)
        {
            throw new IllegalArgumentException(e);
        }
    }

    public void readAnnotations(String filePath, SARTrack trackOwner) throws IOException
    {
        try
        {
            if (filePath != null)
            {
                SARAnnotationReader reader = new SARAnnotationReader();
                reader.readFile(filePath);
                for (SARAnnotation sa : reader.getSARAnnotations())
                    addNew(sa, trackOwner);
            }
        }
        catch (javax.xml.parsers.ParserConfigurationException e)
        {
            throw new IllegalArgumentException(e);
        }
        catch (org.xml.sax.SAXException e)
        {
            throw new IllegalArgumentException(e);
        }
    }
}

⌨️ 快捷键说明

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