forked from NASAWorldWind/WorldWindJava
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathSplitPaneUsage.java
More file actions
178 lines (157 loc) · 7.64 KB
/
SplitPaneUsage.java
File metadata and controls
178 lines (157 loc) · 7.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Copyright 2006-2009, 2017, 2020 United States Government, as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All rights reserved.
*
* The NASA World Wind Java (WWJ) platform is licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* NASA World Wind Java (WWJ) also contains the following 3rd party Open Source
* software:
*
* Jackson Parser – Licensed under Apache 2.0
* GDAL – Licensed under MIT
* JOGL – Licensed under Berkeley Software Distribution (BSD)
* Gluegen – Licensed under Berkeley Software Distribution (BSD)
*
* A complete listing of 3rd Party software notices and licenses included in
* NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party
* notices and licenses PDF found in code directory.
*/
package gov.nasa.worldwindx.examples;
import gov.nasa.worldwind.*;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.layers.WorldMapLayer;
import gov.nasa.worldwind.util.StatusBar;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
/**
* Illustrates how to use WorldWind within a Swing JSplitPane. Doing so is mostly straightforward, but in order to work
* around a Swing bug the WorldWindow must be placed within a JPanel and that JPanel's minimum preferred size must be
* set to zero (both width and height). See the code that does this in the first few lines of the AppPanel constructor
* below.
* <p>
* This example also illustrates another bug in Swing that does not have a known workaround: the WorldWindow does not
* resize when a vertical split-pane's one-touch-expand widget is clicked if that split-pane contains a horizontal
* split-plane that contains the WorldWindow. If the one-touch widget is clicked on the bottom pane of this example,
* that pane will expand to the full height of the window but the WorldWindow will not change size and will display on
* top of the expanded pane. (The horizontal split pane's one-touch behavior works correctly.) If the panes are
* rearranged so that the WorldWindow and the bottom panel are in one vertical split pane, and that split pane is the
* right component of the horizontal split pane containing the layer panel, then the one-touch widgets work correctly
* for both JSplitPanes. This bug is related only to the one-touch widget. Moving the vertical split-pane interactively
* via the split-pane's handle works correctly.
*
* @author tag
* @version $Id: SplitPaneUsage.java 1171 2013-02-11 21:45:02Z dcollins $
*/
public class SplitPaneUsage
{
public static class AppPanel extends JPanel
{
private WorldWindowGLCanvas wwd;
// Constructs a JPanel to hold the WorldWindow
public AppPanel(Dimension canvasSize, boolean includeStatusBar)
{
super(new BorderLayout());
// Create the WorldWindow and set its preferred size.
this.wwd = new WorldWindowGLCanvas();
this.wwd.setPreferredSize(canvasSize);
// THIS IS THE TRICK: Set the panel's minimum size to (0,0);
this.setMinimumSize(new Dimension(0, 0));
// Create the default model as described in the current worldwind properties.
Model m = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME);
this.wwd.setModel(m);
// Setup a select listener for the worldmap click-and-go feature
this.wwd.addSelectListener(new ClickAndGoSelectListener(this.wwd, WorldMapLayer.class));
// Add the WorldWindow to this JPanel.
this.add(this.wwd, BorderLayout.CENTER);
// Add the status bar if desired.
if (includeStatusBar)
{
StatusBar statusBar = new StatusBar();
this.add(statusBar, BorderLayout.PAGE_END);
statusBar.setEventSource(wwd);
}
}
}
private static class AppFrame extends JFrame
{
private Dimension canvasSize = new Dimension(800, 600); // the desired WorldWindow size
public AppFrame()
{
// Create the WorldWindow.
final AppPanel wwjPanel = new AppPanel(this.canvasSize, true);
LayerPanel layerPanel = new LayerPanel(wwjPanel.wwd);
// Create a horizontal split pane containing the layer panel and the WorldWindow panel.
JSplitPane horizontalSplitPane = new JSplitPane();
horizontalSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
horizontalSplitPane.setLeftComponent(layerPanel);
horizontalSplitPane.setRightComponent(wwjPanel);
horizontalSplitPane.setOneTouchExpandable(true);
horizontalSplitPane.setContinuousLayout(true); // prevents the pane's being obscured when expanding right
// Create a panel for the bottom component of a vertical split-pane.
JPanel bottomPanel = new JPanel(new BorderLayout());
JLabel label = new JLabel("Bottom Panel");
label.setBorder(new EmptyBorder(10, 10, 10, 10));
label.setHorizontalAlignment(SwingConstants.CENTER);
bottomPanel.add(label, BorderLayout.CENTER);
// Create a vertical split-pane containing the horizontal split plane and the button panel.
JSplitPane verticalSplitPane = new JSplitPane();
verticalSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
verticalSplitPane.setTopComponent(horizontalSplitPane);
verticalSplitPane.setBottomComponent(bottomPanel);
verticalSplitPane.setOneTouchExpandable(true);
verticalSplitPane.setContinuousLayout(true);
verticalSplitPane.setResizeWeight(1);
// Add the vertical split-pane to the frame.
this.getContentPane().add(verticalSplitPane, BorderLayout.CENTER);
this.pack();
// Center the application on the screen.
Dimension prefSize = this.getPreferredSize();
Dimension parentSize;
java.awt.Point parentLocation = new java.awt.Point(0, 0);
parentSize = Toolkit.getDefaultToolkit().getScreenSize();
int x = parentLocation.x + (parentSize.width - prefSize.width) / 2;
int y = parentLocation.y + (parentSize.height - prefSize.height) / 2;
this.setLocation(x, y);
this.setResizable(true);
}
}
public static void main(String[] args)
{
start("WorldWind Split Pane Usage");
}
public static void start(String appName)
{
if (Configuration.isMacOS() && appName != null)
{
System.setProperty("com.apple.mrj.application.apple.menu.about.name", appName);
}
try
{
final AppFrame frame = new AppFrame();
frame.setTitle(appName);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
frame.setVisible(true);
}
});
}
catch (Exception e)
{
e.printStackTrace();
}
}
}