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

📄 slideshowannotationcontroller.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2001, 2009 United States Government as represented bythe Administrator of the National Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.examples.util;import gov.nasa.worldwind.*;import gov.nasa.worldwind.avlist.AVKey;import gov.nasa.worldwind.cache.*;import gov.nasa.worldwind.data.ImageIOReader;import gov.nasa.worldwind.util.*;/** * @author dcollins * @version $Id: SlideShowAnnotationController.java 10631 2009-04-29 03:02:34Z dcollins $ */@SuppressWarnings({"TypeParameterExplicitlyExtendsObject"})public class SlideShowAnnotationController extends DialogAnnotationController{    public static final String BUFFERED_IMAGE_CACHE_SIZE = "gov.nasa.worldwind.avkey.BufferedImageCacheSize";    public static final String BUFFERED_IMAGE_CACHE_NAME = java.awt.image.BufferedImage.class.getName();    protected static final long SLIDESHOW_UPDATE_DELAY_MILLIS = 2000;    protected static final long DEFAULT_BUFFERED_IMAGE_CACHE_SIZE = 30000000;    protected static java.awt.Dimension SMALL_IMAGE_PREFERRED_SIZE = new java.awt.Dimension(320, 240);    protected static java.awt.Dimension LARGE_IMAGE_PREFERRED_SIZE = new java.awt.Dimension(600, 450);    protected int index;    protected String state;    protected java.util.List<Object> imageSources;    // Concurrent task components.    private Thread readThread;    private javax.swing.Timer updateTimer;    public SlideShowAnnotationController(WorldWindow worldWindow, SlideShowAnnotation annotation,        java.util.List<? extends Object> imageSources)    {        super(worldWindow, annotation);        this.state = AVKey.STOP;        this.index = -1;        this.imageSources = new java.util.ArrayList<Object>();                if (imageSources != null)        {            this.imageSources.addAll(imageSources);        }                if (!WorldWind.getMemoryCacheSet().containsCache(BUFFERED_IMAGE_CACHE_NAME))        {            long size = Configuration.getLongValue(BUFFERED_IMAGE_CACHE_SIZE, DEFAULT_BUFFERED_IMAGE_CACHE_SIZE);            MemoryCache cache = new BasicMemoryCache((long) (0.85 * size), size);            WorldWind.getMemoryCacheSet().addCache(BUFFERED_IMAGE_CACHE_NAME, cache);        }        this.initializeSlideShow();    }    public SlideShowAnnotationController(WorldWindow worldWindow, SlideShowAnnotation annotation)    {        this(worldWindow, annotation, null);    }    protected void initializeSlideShow()    {        SlideShowAnnotation annotation = (SlideShowAnnotation) this.getAnnotation();        // Set the image preferred size.        this.setPreferredImageSize(SMALL_IMAGE_PREFERRED_SIZE);        if (this.imageSources.size() <= 1)        {            annotation.getPlayButton().getAttributes().setVisible(false);            annotation.getPreviousButton().getAttributes().setVisible(false);            annotation.getNextButton().getAttributes().setVisible(false);            annotation.getBeginButton().getAttributes().setVisible(false);            annotation.getEndButton().getAttributes().setVisible(false);        }        if (!this.imageSources.isEmpty())        {            // Load the first image.            this.doGoToImage(0);        }    }    public java.util.List<? extends Object> getImageSources()    {        return java.util.Collections.unmodifiableList(this.imageSources);    }    public void setImageSources(java.util.List<? extends Object> imageSources)    {        this.imageSources.clear();        if (imageSources != null)        {            this.imageSources.addAll(imageSources);        }    }    public String getState()    {        return this.state;    }    public int getIndex()    {        return this.index;    }    @SuppressWarnings({"StringEquality"})    public void goToImage(int index)    {        if (this.getAnnotation() == null)            return;        if (this.getState() == AVKey.PLAY)        {            this.stopSlideShow();        }        this.doGoToImage(index);    }    @SuppressWarnings({"StringEquality"})    public void startSlideShow()    {        if (this.getAnnotation() == null)            return;        if (this.hasNextIndex() && this.getState() == AVKey.STOP)        {            this.state = AVKey.PLAY;            SlideShowAnnotation slideShowAnnotation = (SlideShowAnnotation) this.getAnnotation();            slideShowAnnotation.setPlayButtonState(AVKey.PAUSE);            this.startSlideShowUpdate();        }    }    @SuppressWarnings({"StringEquality"})    public void stopSlideShow()    {        if (this.getAnnotation() == null)            return;        if (this.getState() == AVKey.PLAY)        {            this.state = AVKey.STOP;            SlideShowAnnotation slideShowAnnotation = (SlideShowAnnotation) this.getAnnotation();            slideShowAnnotation.setPlayButtonState(AVKey.PLAY);            this.stopSlideShowUpdate();        }    }    public void stopRetrievalTasks()    {        this.stopImageRetrieval();    }    public java.awt.Dimension getPreferredImageSize()    {        if (this.getAnnotation() == null)            return null;        SlideShowAnnotation slideShowAnnotation = (SlideShowAnnotation) this.getAnnotation();        return slideShowAnnotation.getImageAnnotation().getAttributes().getSize();    }    public void setPreferredImageSize(java.awt.Dimension size)    {        if (this.getAnnotation() == null)            return;        SlideShowAnnotation slideShowAnnotation = (SlideShowAnnotation) this.getAnnotation();        slideShowAnnotation.getImageAnnotation().getAttributes().setSize(size);    }    protected boolean hasPreviousIndex()    {        // The slide show loops, so there's always a previous index.        return true;    }    protected boolean hasNextIndex()    {        // The slide show loops, so there's always a next index.        return true;    }    protected int getPreviousIndex()    {        int maxIndex = this.imageSources.size() - 1;        return (this.index > 0) ? (this.index - 1) : maxIndex;    }    protected int getNextIndex()    {        int maxIndex = this.imageSources.size() - 1;        return (this.index < maxIndex) ? (this.index + 1) : 0;    }    protected void doGoToImage(int index)    {        int maxIndex = this.imageSources.size() - 1;        if (index < 0 || index > maxIndex)            return;        if (index == this.index)            return;        this.retrieveAndSetImage(this.imageSources.get(index), index);    }    protected void doSetImage(Object source, int index)    {        int length = this.imageSources.size();        Object imageSource = this.imageSources.get(index);        String title = this.createTitle(imageSource);        String positionText = this.createPositionText(index, length);        this.index = index;        SlideShowAnnotation slideShowAnnotation = (SlideShowAnnotation) this.getAnnotation();        slideShowAnnotation.getTitleLabel().setText(title);        slideShowAnnotation.getPositionLabel().setText(positionText);        slideShowAnnotation.getImageAnnotation().setImageSource(source);        // Update next and previous button states.        slideShowAnnotation.getBeginButton().setEnabled(this.hasPreviousIndex());        slideShowAnnotation.getPreviousButton().setEnabled(this.hasPreviousIndex());        slideShowAnnotation.getNextButton().setEnabled(this.hasNextIndex());        slideShowAnnotation.getEndButton().setEnabled(this.hasNextIndex());        this.getWorldWindow().redraw();    }    //**************************************************************//    //********************  Action Listener  ***********************//    //**************************************************************//    @SuppressWarnings({"StringEquality"})    public void onActionPerformed(java.awt.event.ActionEvent e)    {        super.onActionPerformed(e);        if (e.getActionCommand() == AVKey.PLAY)        {            this.playPressed(e);        }        else if (e.getActionCommand() == AVKey.PREVIOUS)        {            this.previousPressed(e);        }        else if (e.getActionCommand() == AVKey.NEXT)        {            this.nextPressed(e);        }        else if (e.getActionCommand() == AVKey.BEGIN)        {            this.beginPressed(e);        }        else if (e.getActionCommand() == AVKey.END)        {            this.endPressed(e);        }        else if (e.getActionCommand() == AVKey.RESIZE)        {            this.resizePressed(e);        }    }    protected void playPressed(java.awt.event.ActionEvent e)    {        if (e == null)            return;        if (this.getAnnotation() == null)            return;        this.onPlayPressed(e);    }    protected void previousPressed(java.awt.event.ActionEvent e)    {        if (e == null)            return;        if (this.getAnnotation() == null)            return;        this.onPreviousPressed(e);    }    protected void nextPressed(java.awt.event.ActionEvent e)    {        if (e == null)            return;        if (this.getAnnotation() == null)            return;        this.onNextPressed(e);    }    protected void beginPressed(java.awt.event.ActionEvent e)    {        if (e == null)            return;

⌨️ 快捷键说明

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