📄 multimediaannotations.java
字号:
{
// If selected annotation delegate dragging computations to a dragger.
if(event.getTopObject() == AppFrame.this.currentAnnotation)
this.dragger.selected(event);
}
// We missed any roll-over events while dragging, so highlight any under the cursor now,
// or de-highlight the dragged shape if it's no longer under the cursor.
if (event.getEventAction().equals(SelectEvent.DRAG_END))
{
PickedObjectList pol = getWwd().getObjectsAtCurrentPosition();
if (pol != null)
{
AppFrame.this.highlight(pol.getTopObject());
AppFrame.this.getWwd().repaint();
}
}
}
}
});
}
private void highlight(Object o)
{
// Manage highlighting of Annotations.
if (this.lastPickedObject == o)
return; // same thing selected
// Turn off highlight if on.
if (this.lastPickedObject != null) // && this.lastPickedObject != this.currentAnnotation)
{
this.lastPickedObject.getAttributes().setHighlighted(false);
this.lastPickedObject = null;
}
// Turn on highlight if object selected.
if (o != null && o instanceof Annotation)
{
this.lastPickedObject = (Annotation) o;
this.lastPickedObject.getAttributes().setHighlighted(true);
}
}
private void playAnnotationAudio(GlobeAnnotation annotation, Point pickPoint)
{
String filePath = (String)annotation.getValue(FILE_ATTACHMENT);
if (filePath == null)
return;
System.out.println("Play annotation audio: " + filePath);
// Determine screen location
Point cursorLocation = getCursorPoint(pickPoint);
// Start audio player dialog
try
{
URL url = getResourceURL(filePath);
Clip clip = openAudioURL(url);
AudioPlayer player = new AudioPlayer(clip);
if (this.playerDialog == null)
this.playerDialog = new AudioPlayerDialog();
playerDialog.setAudioPlayer(player);
playerDialog.setAlwaysOnTop(true);
playerDialog.setLocation(cursorLocation);
playerDialog.setVisible(true);
player.play(); // start playing right away
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void playAnnotationImage(GlobeAnnotation annotation, Point pickPoint)
{
String filePath = (String)annotation.getValue(FILE_ATTACHMENT);
if (filePath == null)
return;
System.out.println("Play annotation image: " + filePath);
// Determine screen location
Point cursorLocation = getCursorPoint(pickPoint);
// Start image viewer dialog
if (this.viewerDialog == null)
viewerDialog = new ImageViewerDialog();
viewerDialog.getImageViewer().setImageURL(getResourceURL(filePath));
viewerDialog.getImageViewer().setScaleMode(ImageViewer.SCALE_BEST_FIT);
viewerDialog.setLocation(cursorLocation);
viewerDialog.setAlwaysOnTop(true);
viewerDialog.setDropEnabled(true);
viewerDialog.setVisible(true);
}
private void playAnnotationSlides(GlobeAnnotation annotation, Point pickPoint)
{
String[] files = (String[])annotation.getValue(FILE_ATTACHMENT);
if (files == null)
return;
System.out.println("Play annotation slides: " + files.length);
// Determine screen location
Point cursorLocation = getCursorPoint(pickPoint);
// Start image viewer dialog
if (this.slideShowPlayer == null)
slideShowPlayer = new SlideShowPlayer();
slideShowPlayer.clear();
// Add slides
for (String filePath : files)
{
String[] values = filePath.split(";");
URL fileURL = getResourceURL(values[0]);
String caption = values.length > 1 ? values[1] : filePath;
slideShowPlayer.addSlide(new SlideShowPlayer.Slide(fileURL, caption));
}
slideShowPlayer.getImageViewer().setScaleMode(ImageViewer.SCALE_BEST_FIT);
slideShowPlayer.setLocation(cursorLocation);
slideShowPlayer.setAlwaysOnTop(true);
slideShowPlayer.setDropEnabled(true);
slideShowPlayer.setVisible(true);
}
private static Clip openAudioURL(java.net.URL url) throws Exception
{
Clip clip = null;
AudioInputStream ais = null;
try
{
ais = AudioSystem.getAudioInputStream(url);
DataLine.Info info = new DataLine.Info(Clip.class, ais.getFormat());
clip = (Clip) AudioSystem.getLine(info);
clip.open(ais);
}
finally
{
if (ais != null)
{
ais.close();
}
}
return clip;
}
private URL getResourceURL(String path)
{
try
{
File f = new File(path);
if (f.exists())
return f.toURL();
URL url = this.getClass().getResource("/" + path);
if (url != null)
return url;
return new URL(path);
}
catch (Exception ignore) { }
return null;
}
private Point getCursorPoint(Point pickPoint)
{
Point wwdLocation = getWwd().getLocationOnScreen();
return new Point(wwdLocation.x + pickPoint.x, wwdLocation.y + pickPoint.y);
}
}
public static void main(String[] args)
{
ApplicationTemplate.start("World Wind Multimedia Annotations", AppFrame.class);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -