1 /*
2 * ClassChooserDialog.java
3 */
4
5 package net.sourceforge.jnipp.gui;
6
7 import net.sourceforge.jnipp.gui.App;
8 import net.sourceforge.jnipp.project;
9 import java.util.Iterator;
10 import java.util.Vector;
11 import java.awt;
12 import java.awt.event;
13 import javax.swing;
14
15 public class ClassChooserDialog
16 extends JDialog
17 implements ActionListener
18 {
19 private DynamicClassLoaderTree tree;
20 JPanel contentPane;
21
22 public ClassChooserDialog(Frame owner)
23 {
24 super(owner,"JNI++ - Select A Target Class",true);
25 init();
26 }
27
28 public Class getSelectedClass()
29 {
30 return tree.getSelectedClass();
31 }
32
33 private void init()
34 {
35 initWindowListener();
36 JButton cmdOK = new JButton(App.getProperty("button-ok.label"));
37 cmdOK.setActionCommand("ok");
38 cmdOK.addActionListener(this);
39
40 JButton cmdCancel = new JButton(App.getProperty("button-cancel.label"));
41 cmdCancel.setActionCommand("cancel");
42 cmdCancel.addActionListener(this);
43
44 tree = new DynamicClassLoaderTree();
45 JScrollPane treeView = new JScrollPane(tree);
46
47 JLabel instructions = new JLabel(App.getProperty("message.add-class-instruction"));
48
49 GridBagLayout myLayout = new GridBagLayout();
50 GridBagConstraints c = new GridBagConstraints();
51 getContentPane().setLayout(myLayout);
52
53 c.ipadx = 2;
54 c.ipady = 2;
55 c.insets = new Insets(5,5,5,5);
56
57 c.gridwidth = GridBagConstraints.REMAINDER; //2;
58 myLayout.setConstraints(instructions,c);
59
60 c.fill = GridBagConstraints.BOTH;
61 c.weightx = 1;
62 c.weighty = 1;
63 c.gridwidth = GridBagConstraints.REMAINDER;
64 myLayout.setConstraints(treeView,c);
65
66 c.anchor = GridBagConstraints.EAST;
67 c.fill = GridBagConstraints.NONE;
68 c.weightx = 0;
69 c.weighty = 0;
70 c.gridwidth = 1;
71 c.gridx = 2;
72 c.gridy = 2;
73 myLayout.setConstraints(cmdOK,c);
74 c.gridx = 3;
75 myLayout.setConstraints(cmdCancel,c);
76
77 this.setSize(new Dimension(400, 300));
78 getContentPane().add(instructions);
79 getContentPane().add(treeView);
80 getContentPane().add(cmdOK);
81 getContentPane().add(cmdCancel);
82 getRootPane().setDefaultButton(cmdOK);
83 }
84
85 public void actionPerformed(java.awt.event.ActionEvent e) {
86 if (e.getActionCommand().equals("ok"))
87 {
88 hide();
89 }
90 else
91 {
92 //TODO: clear selection
93 hide();
94 }
95
96 }
97
98 private void initWindowListener()
99 {
100 this.addWindowListener( new WindowAdapter()
101 {
102 public void windowClosing(WindowEvent e)
103 {
104 hide();
105 }
106 });
107 }
108 }