File: TestInternalFrames.java

package info (click to toggle)
vtk 5.0.2-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 51,080 kB
  • ctags: 67,442
  • sloc: cpp: 522,627; ansic: 221,292; tcl: 43,377; python: 14,072; perl: 3,102; java: 1,436; yacc: 1,033; sh: 469; lex: 248; makefile: 181; asm: 154
file content (143 lines) | stat: -rw-r--r-- 3,498 bytes parent folder | download | duplicates (6)
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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.plaf.basic.*;

public class TestInternalFrames extends JFrame {

  private Desktop theDesktop;
  private Dimension screenSize;

  public TestInternalFrames() {
    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.show();
  }

  public void addMenuBar(JMenuBar m) {
    setJMenuBar(m);
  }

  private class SplitFrame extends JSplitPane {

    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 {

    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 {
    
    public Tabbed() {
      this.addTab( "vtk1", new TestVTKCanvas() );
      this.addTab( "vtk2", new TestVTKCanvas() );
      
      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 {

    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 TestVTKCanvas(), BorderLayout.CENTER); 
      this.pack();
      this.setVisible(true);
    }
  }

  private class MenuMgr extends JMenuBar {

    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 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 {
    
    public KillAction(String label) {
      super(label);
    }
    
    public void actionPerformed(ActionEvent ev) {
      System.exit(0);
    }
  }
  

  public static void main(String[] args) {
    JFrame f = new TestInternalFrames();
  }
}