Created
October 20, 2010 07:11
-
-
Save manuel-woelker/635943 to your computer and use it in GitHub Desktop.
"Usage in Tabbed Pane" example as of WWJ 0.6.601 exhibiting issue in RenderableLayer.disposeRenderables()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2001, 2006 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.Configuration; | |
import gov.nasa.worldwind.Model; | |
import gov.nasa.worldwind.WorldWind; | |
import gov.nasa.worldwind.avlist.AVKey; | |
import gov.nasa.worldwind.awt.WorldWindowGLCanvas; | |
import gov.nasa.worldwind.layers.Earth.BMNGOneImage; | |
import gov.nasa.worldwind.util.StatusBar; | |
import java.awt.BorderLayout; | |
import java.awt.Dimension; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
import javax.swing.JTabbedPane; | |
/** | |
* @author tag | |
* @version $Id: UsageInTabbedPane.java 4331 2008-02-01 03:38:37Z tgaskins $ | |
*/ | |
public class UsageInTabbedPane { | |
static { | |
if (Configuration.isMacOS()) { | |
System.setProperty("apple.laf.useScreenMenuBar", "true"); | |
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "World Wind Tabbed Pane Application"); | |
System.setProperty("com.apple.mrj.application.growbox.intrudes", "false"); | |
} | |
} | |
public static class WWJPanel extends JPanel { | |
protected WorldWindowGLCanvas wwd; | |
protected StatusBar statusBar; | |
public WWJPanel(final Dimension canvasSize, final boolean includeStatusBar) { | |
super(new BorderLayout()); | |
this.wwd = new WorldWindowGLCanvas(); | |
this.wwd.setPreferredSize(canvasSize); | |
// Create the default model as described in the current worldwind properties. | |
final Model m = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME); | |
this.wwd.setModel(m); | |
m.getLayers().clear(); | |
m.getLayers().add(new BMNGOneImage()); | |
this.add(this.wwd, BorderLayout.CENTER); | |
if (includeStatusBar) { | |
this.statusBar = new StatusBar(); | |
this.add(statusBar, BorderLayout.PAGE_END); | |
this.statusBar.setEventSource(wwd); | |
} | |
} | |
} | |
public static void main(final String[] args) { | |
try { | |
final JFrame mainFrame = new JFrame(); | |
mainFrame.setTitle("World Wind Tabbed Pane"); | |
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
final JTabbedPane tabbedPane = new JTabbedPane(); | |
final WWJPanel wwjPanel = new WWJPanel(new Dimension(800, 600), true); | |
final JPanel controlPanel = new JPanel(new BorderLayout()); | |
final JButton detachButton = new JButton("Detach"); | |
detachButton.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(final ActionEvent actionEvent) { | |
System.out.println("Detaching wwj"); | |
// wwjPanel.wwd.detachFromParent(); | |
System.out.println("Removing tab"); | |
tabbedPane.removeTabAt(0); | |
System.out.println("Tab removed"); | |
} | |
}); | |
final JButton attachButton = new JButton("Attach"); | |
attachButton.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(final ActionEvent actionEvent) { | |
System.out.println("Adding tab"); | |
tabbedPane.insertTab("WWJ Pane 1", null, wwjPanel, "Reattach", 0); | |
System.out.println("Tab added"); | |
} | |
}); | |
controlPanel.add(detachButton, BorderLayout.NORTH); | |
controlPanel.add(attachButton, BorderLayout.SOUTH); | |
tabbedPane.add("WWJ Pane 1", wwjPanel); | |
tabbedPane.add("Dummy Pane", controlPanel); | |
mainFrame.getContentPane().add(tabbedPane, BorderLayout.CENTER); | |
mainFrame.pack(); | |
mainFrame.setVisible(true); | |
} catch (final Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment