📄 slideshowannotationcontroller.java
字号:
if (this.getAnnotation() == null) return; this.onBeginPressed(e); } protected void endPressed(java.awt.event.ActionEvent e) { if (e == null) return; if (this.getAnnotation() == null) return; this.onEndPressed(e); } protected void resizePressed(java.awt.event.ActionEvent e) { if (e == null) return; if (this.getAnnotation() == null) return; this.onResizePressed(e); } @SuppressWarnings({"UnusedDeclaration", "StringEquality"}) protected void onPlayPressed(java.awt.event.ActionEvent e) { String state = this.getState(); if (state == null) return; if (state == AVKey.PLAY) { this.stopSlideShow(); } else if (state == AVKey.STOP) { this.startSlideShow(); } } @SuppressWarnings({"UnusedDeclaration"}) protected void onPreviousPressed(java.awt.event.ActionEvent e) { if (!this.hasPreviousIndex()) return; int newIndex = this.getPreviousIndex(); this.goToImage(newIndex); } @SuppressWarnings({"UnusedDeclaration"}) protected void onNextPressed(java.awt.event.ActionEvent e) { if (!this.hasNextIndex()) return; int newIndex = this.getNextIndex(); this.goToImage(newIndex); } @SuppressWarnings({"UnusedDeclaration"}) protected void onBeginPressed(java.awt.event.ActionEvent e) { this.goToImage(0); } @SuppressWarnings({"UnusedDeclaration"}) protected void onEndPressed(java.awt.event.ActionEvent e) { int maxIndex = this.imageSources.size() - 1; if (maxIndex < 0) return; this.goToImage(maxIndex); } @SuppressWarnings({"UnusedDeclaration"}) protected void onResizePressed(java.awt.event.ActionEvent e) { if (this.getAnnotation() == null) return; java.awt.Dimension preferredSize = this.getPreferredImageSize(); if (preferredSize.equals(SMALL_IMAGE_PREFERRED_SIZE)) { this.setPreferredImageSize(LARGE_IMAGE_PREFERRED_SIZE); SlideShowAnnotation slideShowAnnotation = (SlideShowAnnotation) this.getAnnotation(); slideShowAnnotation.setSizeButtonState(SlideShowAnnotation.DECREASE); } else { this.setPreferredImageSize(SMALL_IMAGE_PREFERRED_SIZE); SlideShowAnnotation slideShowAnnotation = (SlideShowAnnotation) this.getAnnotation(); slideShowAnnotation.setSizeButtonState(SlideShowAnnotation.INCREASE); } } //**************************************************************// //******************** Image Load Thread *********************// //**************************************************************// protected void retrieveAndSetImage(Object source, int index) { java.awt.image.BufferedImage image = this.getImage(source); if (image != null) { this.doSetImage(image, index); return; } this.startImageRetrieval(source, index); } protected void doRetrieveAndSetImage(Object source, final int index) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { if (updateTimer != null) { updateTimer.stop(); } getAnnotation().setBusy(true); getWorldWindow().redraw(); } }); final Object image = this.readImage(source); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { doSetImage(image, index); getAnnotation().setBusy(false); getWorldWindow().redraw(); if (updateTimer != null) { updateTimer.start(); } } }); } protected java.awt.image.BufferedImage readImage(Object source) { ImageIOReader reader = new ImageIOReader(); try { java.awt.image.BufferedImage image = reader.read(source); this.putImage(source, image); return image; } catch (Exception e) { String message = Logging.getMessage("generic.ExceptionWhileRequestingImage", source); Logging.logger().log(java.util.logging.Level.SEVERE, message, e); } return null; } protected void startImageRetrieval(final Object source, final int index) { this.readThread = new Thread(new Runnable() { public void run() { doRetrieveAndSetImage(source, index); } }); this.readThread.start(); } protected void stopImageRetrieval() { if (this.readThread != null) { if (this.readThread.isAlive()) { this.readThread.interrupt(); } } this.readThread = null; } protected java.awt.image.BufferedImage getImage(Object source) { return (java.awt.image.BufferedImage) WorldWind.getMemoryCache(BUFFERED_IMAGE_CACHE_NAME).getObject(source); } protected boolean putImage(Object source, java.awt.image.BufferedImage image) { long sizeInBytes = ImageUtil.computeSizeInBytes(image); MemoryCache cache = WorldWind.getMemoryCache(BUFFERED_IMAGE_CACHE_NAME); boolean addToCache = (sizeInBytes < cache.getCapacity()); // If the image is too large for the cache, then do not add it to the cache. if (addToCache) { cache.add(source, image, sizeInBytes); } return addToCache; } //**************************************************************// //******************** Slideshow Update Timer *******************// //**************************************************************// protected boolean nextSlideShowImage() { if (this.getAnnotation() == null) return false; if (this.hasNextIndex()) { int newIndex = this.getNextIndex(); this.doGoToImage(newIndex); } return this.hasNextIndex(); } protected void onSlideShowUpdate() { if (!this.nextSlideShowImage()) { this.stopSlideShow(); } } protected void startSlideShowUpdate() { this.updateTimer = new javax.swing.Timer((int) SLIDESHOW_UPDATE_DELAY_MILLIS, new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent actionEvent) { onSlideShowUpdate(); } }); // Coalesce timer events, so that an image load delay on the timer thread does not cause slide transition // events to bunch up. this.updateTimer.setCoalesce(true); this.updateTimer.start(); } protected void stopSlideShowUpdate() { if (this.updateTimer != null) { this.updateTimer.stop(); } this.updateTimer = null; } //**************************************************************// //******************** Utilities *****************************// //**************************************************************// protected String createTitle(Object imageSource) { String imageName = this.getImageName(imageSource); return (imageName != null) ? imageName : ""; } protected String createPositionText(int position, int length) { if (length <= 1) return ""; StringBuilder sb = new StringBuilder(); sb.append(position + 1).append(" of ").append(length); return sb.toString(); } protected String getImageName(Object imageSource) { if (imageSource == null) return null; String s = imageSource.toString(); s = WWIO.stripTrailingSeparator(s); int index = s.lastIndexOf("/"); if (index == -1) index = s.lastIndexOf("\\"); if (index != -1 && index < s.length() - 1) { s = s.substring(index + 1, s.length()); } return s; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -