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
|
package vtk.sample;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.AbstractAction;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPopupMenu;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import vtk.vtkNativeLibrary;
public class InternalFrames extends JFrame {
private static final long serialVersionUID = 1L;
private Desktop theDesktop;
private Dimension screenSize;
// -----------------------------------------------------------------
// Load VTK library and print which library was not properly loaded
static {
if (!vtkNativeLibrary.LoadAllNativeLibraries()) {
for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
if (!lib.IsLoaded()) {
System.out.println(lib.GetLibraryName() + " not loaded");
}
}
}
vtkNativeLibrary.DisableOutputWindow(null);
}
// -----------------------------------------------------------------
public InternalFrames() {
super("VTK Internal Frame Demo");
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(900, 900);
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
this.addWindowListener(l);
this.getContentPane().add(new SplitFrame());
new MenuMgr();
this.setVisible(true);
}
public void addMenuBar(JMenuBar m) {
setJMenuBar(m);
}
private class SplitFrame extends JSplitPane {
private static final long serialVersionUID = 1L;
public SplitFrame() {
super(JSplitPane.VERTICAL_SPLIT);
this.setDividerLocation(screenSize.height / 2);
setContinuousLayout(true);
setOneTouchExpandable(true);
add(theDesktop = new Desktop());
add(new Tabbed());
}
}
private class Desktop extends JDesktopPane {
private static final long serialVersionUID = 1L;
public Desktop() {
super();
this.setPreferredSize(screenSize);
this.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
this.add(new VTKFrame(10, 10));
this.add(new VTKFrame(500, 10));
}
}
private class Tabbed extends JTabbedPane {
private static final long serialVersionUID = 1L;
public Tabbed() {
this.addTab("vtk1", new VTKCanvas());
this.addTab("vtk2", new VTKCanvas());
setMinimumSize(new Dimension(300, 300));
// another swing bug work around
// for some reason the first time the tabbed item is drawn,
// tab 0 is selected but the sphere (tab 1) is drawn
// manually selecting the tabs synchs the tab and the draw order
// it is harmless but it is still annoying
// so we force tab 1 to be selected and hide the bug from the user
// note that selecting 0 does not work....
this.setSelectedIndex(1);
}
}
private class VTKFrame extends JInternalFrame {
private static final long serialVersionUID = 1L;
public VTKFrame(int x, int y) {
super("VTK Window", true, true, true, true);
Dimension mySize = new Dimension();
mySize.height = 300;
mySize.width = 300;
this.setSize(mySize);
this.getContentPane().setLayout(new BorderLayout());
this.setLocation(x, y);
this.getContentPane().add(new VTKCanvas(), BorderLayout.CENTER);
this.pack();
this.setVisible(true);
}
}
private class MenuMgr extends JMenuBar {
private static final long serialVersionUID = 1L;
private JMenu menu;
public MenuMgr() {
super();
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
menu = new JMenu("File");
menu.add(new CreateWindowAction("Create New VTK Window"));
menu.add(new KillAction("Exit"));
add(menu);
addMenuBar(this);
}
}
private class CreateWindowAction extends AbstractAction {
private static final long serialVersionUID = 1L;
private int layer = 0;
public CreateWindowAction(String label) {
super(label);
}
public void actionPerformed(ActionEvent ev) {
theDesktop.add(new VTKFrame(340, 200), new Integer(layer));
}
}
private class KillAction extends AbstractAction {
private static final long serialVersionUID = 1L;
public KillAction(String label) {
super(label);
}
public void actionPerformed(ActionEvent ev) {
System.exit(0);
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new InternalFrames();
}
});
}
}
|