📄 annotationcontrols.java
字号:
public void detach() { super.detach(); // Stop any threads or timers the controller may be actively running. SlideShowAnnotationController controller = (SlideShowAnnotationController) this.getController(); if (controller != null) { this.stopController(controller); } } @SuppressWarnings({"StringEquality"}) protected void stopController(SlideShowAnnotationController controller) { String state = controller.getState(); if (state == AVKey.PLAY) { controller.stopSlideShow(); } controller.stopRetrievalTasks(); } } public static IconLayer createIconLayer() { IconLayer layer = new IconLayer(); layer.setPickEnabled(true); WWIcon icon = createIcon(AUDIO, Position.fromDegrees(37.304051, -121.872734, 0), "Welcome to Java Sound", URL_AUDIO_WELCOME); layer.addIcon(icon); icon = createIcon(AUDIO, Position.fromDegrees(28.533513, -81.375789, 0), "Music from the Java Sound demo", URL_AUDIO_MUSIC); layer.addIcon(icon); icon = createIcon(AUDIO, Position.fromDegrees(-10, -76, 0), "Peru<br/><i><font color=\"#808080\">\"Take a step back in time...\"</font></i>", URL_AUDIO_PERU); layer.addIcon(icon); Iterable sources = java.util.Arrays.asList(URL_IMAGE_01, URL_IMAGE_02, URL_IMAGE_03, URL_IMAGE_04); icon = createIcon(IMAGES, Position.fromDegrees(45.304051, -121.872734, 0), "", sources); layer.addIcon(icon); sources = java.util.Arrays.asList(URL_IMAGE_05); icon = createIcon(IMAGES, Position.fromDegrees(-12, -70, 0), "", sources); layer.addIcon(icon); return layer; } public static WWIcon createIcon(Object type, Position position, String title, Object data) { if (position == null) { String message = Logging.getMessage("nullValue.PositionIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (title == null) { String message = Logging.getMessage("nullValue.StringIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (data == null) { String message = Logging.getMessage("nullValue.DataSetIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } String iconPath = (type == AUDIO) ? ICON_AUDIO : ICON_IMAGES; UserFacingIcon icon = new UserFacingIcon(iconPath, position); icon.setSize(new java.awt.Dimension(64, 64)); icon.setValue(AVKey.DATA_TYPE, type); icon.setValue(AVKey.TITLE, title); icon.setValue(AVKey.URL, data); return icon; } @SuppressWarnings({"StringEquality"}) public static ContentAnnotation createContentAnnotation(AppFrame appFrame, Position position, AVList params) { if (appFrame == null) { String message = "AppFrameIsNull"; Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (position == null) { String message = Logging.getMessage("nullValue.PositionIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (params == null) { String message = Logging.getMessage("nullValue.ParamsIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } String type = params.getStringValue(AVKey.DATA_TYPE); String title = params.getStringValue(AVKey.TITLE); Object source = params.getValue(AVKey.URL); if (type == AUDIO) { return createAudioAnnotation(appFrame, position, title, source); } else if (type == IMAGES) { return createImageAnnotation(appFrame, position, title, (Iterable) source); } return null; } public static ContentAnnotation createAudioAnnotation(AppFrame appFrame, Position position, String title, Object source) { if (appFrame == null) { String message = "AppFrameIsNull"; Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (position == null) { String message = Logging.getMessage("nullValue.PositionIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (title == null) { String message = Logging.getMessage("nullValue.StringIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (source == null) { String message = Logging.getMessage("nullValue.SourceIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } AudioPlayerAnnotation annotation = new AudioPlayerAnnotation(position); annotation.setAlwaysOnTop(true); annotation.getTitleLabel().setText(title); AudioPlayerAnnotationController controller = new AudioPlayerAnnotationController(appFrame.getWwd(), annotation); return new AudioContentAnnotation(appFrame, annotation, controller, source); } @SuppressWarnings({"TypeParameterExplicitlyExtendsObject"}) public static ContentAnnotation createImageAnnotation(AppFrame appFrame, Position position, String title, Iterable sources) { if (appFrame == null) { String message = "AppFrameIsNull"; Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (position == null) { String message = Logging.getMessage("nullValue.PositionIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (title == null) { String message = Logging.getMessage("nullValue.StringIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (sources == null) { String message = Logging.getMessage("nullValue.IterableIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } SlideShowAnnotation annotation = new SlideShowAnnotation(position); annotation.setAlwaysOnTop(true); annotation.getTitleLabel().setText(title); java.util.List<Object> imageSources = new java.util.ArrayList<Object>(); for (Object source : sources) { java.net.URL url = urlFromPath(source.toString()); if (url != null) { imageSources.add(url); } else { imageSources.add(source); } } SlideShowAnnotationController controller = new SlideShowAnnotationController(appFrame.getWwd(), annotation, imageSources); return new ImageContentAnnotation(appFrame, annotation, controller); } public static Clip openAudioURL(java.net.URL url) throws Exception { if (url == null) { String message = Logging.getMessage("nullValue.URLIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } Clip clip = null; AudioInputStream ais = null; try { ais = AudioSystem.getAudioInputStream(url); AudioFormat format = ais.getFormat(); /** * Code taken from Java Sound demo at * http://java.sun.com/products/java-media/sound/samples/JavaSoundDemo * * we can't yet open the device for ALAW/ULAW playback, * convert ALAW/ULAW to PCM */ if ((format.getEncoding() == AudioFormat.Encoding.ULAW) || (format.getEncoding() == AudioFormat.Encoding.ALAW)) { AudioFormat tmp = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, format.getSampleRate(), format.getSampleSizeInBits() * 2, format.getChannels(), format.getFrameSize() * 2, format.getFrameRate(), true); ais = AudioSystem.getAudioInputStream(tmp, ais); format = tmp; } DataLine.Info info = new DataLine.Info( Clip.class, ais.getFormat(), ((int) ais.getFrameLength() * format.getFrameSize())); clip = (Clip) AudioSystem.getLine(info); clip.open(ais); } finally { if (ais != null) { ais.close(); } } return clip; } public static java.net.URL urlFromPath(String urlString) { try { return new java.net.URL(urlString); } catch (Exception e) { return null; } } public static String createErrorTitle(String path) { if (path == null) { String message = Logging.getMessage("nullValue.PathIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } StringBuilder sb = new StringBuilder(); sb.append("Cannot open the resource at <i>").append(path).append("</i>"); return sb.toString(); } public static String createTitle(Iterable sources) { if (sources == null) { String message = Logging.getMessage("nullValue.IterableIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } StringBuilder sb = new StringBuilder(); java.util.Iterator iter = sources.iterator(); while (iter.hasNext()) { Object o = iter.next(); sb.append(o); if (iter.hasNext()) { sb.append(", "); } } return sb.toString(); } public static void main(String[] args) { ApplicationTemplate.start("World Wind Annotation Controls", AppFrame.class); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -