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

📄 multimediaannotations.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
Copyright (C) 2001, 2008 United States Government
as represented by the Administrator of the
National Aeronautics and Space Administration.
All Rights Reserved.
*/
package gov.nasa.worldwind.examples;

import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.event.*;
import gov.nasa.worldwind.examples.util.*;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.layers.AnnotationLayer;
import gov.nasa.worldwind.pick.*;
import gov.nasa.worldwind.render.*;

import javax.sound.sampled.*;
import java.awt.*;
import java.io.File;
import java.net.URL;

/**
 * Testing audio playback
 *
 * @author Patrick Murris
 * @version $Id: MultimediaAnnotations.java 10542 2009-04-27 17:28:30Z dcollins $
 */
public class MultimediaAnnotations extends ApplicationTemplate
{
    public static class AppFrame extends ApplicationTemplate.AppFrame
    {
        private final static String HELLO_AUDIO_FILE_PATH = "http://simplythebest.net/sounds/WAV/events_WAV/event_WAV_files/welcome.wav";
        //private final static String IDENTIFICATION_AUDIO_FILE_PATH = "http://simplythebest.net/sounds/WAV/WAV_files/TV_show_WAV_files/identification.wav";
        //private final static String AUDIO_FILE_PATH = "demodata/boing.wav";

        private final static String MSH_IMAGE_FILE_PATH = "http://worldwind.arc.nasa.gov/java/demos/images/MountStHelens_01_800.jpg";
        private final static String MSH_IMAGE_FILE_PATH1 = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/8c/Sthelens1.jpg/800px-Sthelens1.jpg";
        //private final static String IMAGE_FILE_PATH = "images/400x230-splash-nww.png";

        private final static String FILE_ATTACHMENT = "FileAttachment";
        private final static String PLAY_AUDIO_CMD = "play:audio";
        private final static String PLAY_IMAGE_CMD = "play:image";
        private final static String PLAY_SLIDES_CMD = "play:slides";

        private Annotation currentAnnotation;
        private Annotation lastPickedObject;
        private Color savedBorderColor;

        private AudioPlayerDialog playerDialog;
        private ImageViewerDialog viewerDialog;
        private SlideShowPlayer slideShowPlayer;

        public AppFrame()
        {
            super(true, true, false);

            // Create annotation layer
            AnnotationLayer layer = new AnnotationLayer();
            layer.setName("Annotations");
            insertBeforePlacenames(getWwd(), layer);
            getLayerPanel().update(getWwd());

            // Setup annotation attributes
            AnnotationAttributes aa = new AnnotationAttributes();
            aa.setBackgroundColor(Color.WHITE);
            aa.setBorderColor(Color.BLACK);
            aa.setSize(new Dimension(240, 0));
            aa.setHighlightScale(1);
            aa.setInsets(new Insets(12, 12, 12, 20));
            aa.setFont(Font.decode("SansSerif-PLAIN-14"));
            aa.setTextColor(Color.BLACK);

            // Create an annotation with an attached slide show
            GlobeAnnotation ga;
            ga = new GlobeAnnotation("<p>\n<b><font color=\"#664400\">MOUNT SAINT HELENS</font></b><br />"
                + "\n<i>Alt: 1404m</i></p><p>Mount St. Helens is an active stratovolcano located in Skamania "
                + "County, Washington.</p>", Position.fromDegrees(46.2000, -122.1882, 0), aa);
            // Attach an image/caption encoded string array to the annotation and add an hyperlink to view them
            String[] slideList = new String[]
            {
                MSH_IMAGE_FILE_PATH1 + ";Mt Saint Helens before May 1980",
                MSH_IMAGE_FILE_PATH + ";Mt Saint Helens May 1982",

            };
            ga.setValue(FILE_ATTACHMENT, slideList);
            ga.setText(ga.getText() + "<br /><a href=\"" + PLAY_SLIDES_CMD + "\">View slides</a>...");
            layer.addAnnotation(ga);

            // Add an annotation with sound
            ga = new GlobeAnnotation("<p>Welcome...</p>", Position.fromDegrees(44, -100, 0), aa);
            // Attach a sound file to the annotation and add an hyperlink for play back
            ga.setValue(FILE_ATTACHMENT, HELLO_AUDIO_FILE_PATH);
            ga.setText(ga.getText() + "<br /><a href=\"" + PLAY_AUDIO_CMD + "\">Play audio</a>...");
            layer.addAnnotation(ga);

            // Add select listener
            setupSelectListener();
        }

        private void setupSelectListener()
        {
            // Add a select listener to select or highlight annotations on rollover, and playback audio
            this.getWwd().addSelectListener(new SelectListener()
            {
                private BasicDragger dragger = new BasicDragger(getWwd());

                public void selected(SelectEvent event)
                {
                    if (event.hasObjects() && event.getTopObject() instanceof Annotation)
                    {
                        // Handle cursor change on hyperlink
                        if (event.getTopPickedObject().getValue(AVKey.URL) != null)
                            getWwd().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                        else
                            getWwd().setCursor(Cursor.getDefaultCursor());
                    }

                    // Select/unselect on left click on annotations
                    if (event.getEventAction().equals(SelectEvent.LEFT_CLICK))
                    {
                        if (event.hasObjects())
                        {
                            if (event.getTopObject() instanceof Annotation)
                            {
                                // Check for text or url
                                PickedObject po = event.getTopPickedObject();
                                if(po.getValue(AVKey.TEXT) != null)
                                {
                                    // Check for audio play url command
                                    String url = (String)po.getValue(AVKey.URL);
                                    if (url != null && url.equals(PLAY_AUDIO_CMD))
                                        playAnnotationAudio((GlobeAnnotation)event.getTopObject(), event.getPickPoint());
                                        // Check for image play url command
                                    else if (url != null && url.equals(PLAY_IMAGE_CMD))
                                        playAnnotationImage((GlobeAnnotation)event.getTopObject(), event.getPickPoint());
                                        // Check for slides play command
                                    else if (url != null && url.equals(PLAY_SLIDES_CMD))
                                        playAnnotationSlides((GlobeAnnotation)event.getTopObject(), event.getPickPoint());


                                    if(AppFrame.this.currentAnnotation == event.getTopObject())
                                        return;
                                }
                                // Left click on an annotation - select
                                if(AppFrame.this.currentAnnotation != null)
                                {
                                    // Unselect current
                                    AppFrame.this.currentAnnotation.getAttributes().setBorderColor(AppFrame.this.savedBorderColor);
                                }
                                if(AppFrame.this.currentAnnotation != event.getTopObject())
                                {
                                    // Select new one if not current one already
                                    AppFrame.this.currentAnnotation = (Annotation)event.getTopObject();
                                    AppFrame.this.savedBorderColor = AppFrame.this.currentAnnotation.getAttributes().getBorderColor();
                                    AppFrame.this.currentAnnotation.getAttributes().setBorderColor(Color.YELLOW);
                                }
                                else
                                {
                                    // Clear current annotation
                                    AppFrame.this.currentAnnotation = null; // switch off
                                }
                            }
                            else
                                System.out.println("Left click on " + event.getTopObject());

                        }
                    }
                    // Highlight on rollover
                    else if (event.getEventAction().equals(SelectEvent.ROLLOVER) && !this.dragger.isDragging())
                    {
                        AppFrame.this.highlight(event.getTopObject());
                    }
                    // Have drag events drag the selected object.
                    else if (event.getEventAction().equals(SelectEvent.DRAG_END)
                        || event.getEventAction().equals(SelectEvent.DRAG))
                    {
                        if (event.hasObjects())

⌨️ 快捷键说明

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