2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: SetDatabaseDialog.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.4 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 20:59:41 $ |
2 |
26 Feb 07 |
jari |
* $Author: caliente $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.mev; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Container; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Frame; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.event.KeyEvent; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.event.KeyListener; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.event.WindowAdapter; |
2 |
26 Feb 07 |
jari |
25 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
26 |
|
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.JButton; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JComboBox; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.JDialog; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
32 |
|
2 |
26 Feb 07 |
jari |
33 |
import org.tigr.util.awt.GBA; |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
35 |
public class SetDatabaseDialog extends JDialog { |
2 |
26 Feb 07 |
jari |
36 |
|
2 |
26 Feb 07 |
jari |
37 |
private int result; |
2 |
26 Feb 07 |
jari |
38 |
private JComboBox dbChoice; |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
public SetDatabaseDialog(Frame parent) { |
2 |
26 Feb 07 |
jari |
41 |
super(parent, "Select a Database", true); |
2 |
26 Feb 07 |
jari |
42 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
43 |
addWindowListener(listener); |
2 |
26 Feb 07 |
jari |
44 |
|
2 |
26 Feb 07 |
jari |
45 |
JLabel dbLabel = new JLabel("Select a Database: "); |
2 |
26 Feb 07 |
jari |
46 |
|
2 |
26 Feb 07 |
jari |
47 |
this.dbChoice = new JComboBox(); |
2 |
26 Feb 07 |
jari |
48 |
String[] databases = TMEV.getDatabases(); |
2 |
26 Feb 07 |
jari |
49 |
for (int i = 0; i < databases.length; i++) { |
2 |
26 Feb 07 |
jari |
50 |
dbChoice.addItem(databases[i]); |
2 |
26 Feb 07 |
jari |
51 |
} |
2 |
26 Feb 07 |
jari |
52 |
this.dbChoice.addKeyListener(listener); |
2 |
26 Feb 07 |
jari |
53 |
|
2 |
26 Feb 07 |
jari |
54 |
JButton okButton = new JButton("OK"); |
2 |
26 Feb 07 |
jari |
55 |
okButton.setActionCommand("ok-command"); |
2 |
26 Feb 07 |
jari |
56 |
okButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
57 |
|
2 |
26 Feb 07 |
jari |
58 |
JButton cancelButton = new JButton("Cancel"); |
2 |
26 Feb 07 |
jari |
59 |
cancelButton.setActionCommand("cancel-command"); |
2 |
26 Feb 07 |
jari |
60 |
cancelButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
61 |
|
2 |
26 Feb 07 |
jari |
62 |
Container contentPane = getContentPane(); |
2 |
26 Feb 07 |
jari |
63 |
contentPane.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
64 |
GBA gba = new GBA(); |
2 |
26 Feb 07 |
jari |
65 |
gba.add(contentPane, dbLabel, 0, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
66 |
gba.add(contentPane, dbChoice, 1, 0, 1, 1, 1, 1, GBA.B, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
67 |
gba.add(contentPane, cancelButton, 0, 1, 1, 1, 0, 0, GBA.NONE, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
68 |
gba.add(contentPane, okButton, 1, 1, 1, 1, 0, 0, GBA.NONE, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
69 |
|
2 |
26 Feb 07 |
jari |
70 |
pack(); |
2 |
26 Feb 07 |
jari |
71 |
setResizable(false); |
2 |
26 Feb 07 |
jari |
72 |
this.dbChoice.grabFocus(); |
2 |
26 Feb 07 |
jari |
73 |
} |
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
76 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
77 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
78 |
show(); |
2 |
26 Feb 07 |
jari |
79 |
return result; |
2 |
26 Feb 07 |
jari |
80 |
} |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
public String getDatabase() { |
2 |
26 Feb 07 |
jari |
83 |
return(String)dbChoice.getSelectedItem(); |
2 |
26 Feb 07 |
jari |
84 |
} |
2 |
26 Feb 07 |
jari |
85 |
|
2 |
26 Feb 07 |
jari |
86 |
private class Listener extends WindowAdapter implements ActionListener, KeyListener { |
2 |
26 Feb 07 |
jari |
87 |
|
2 |
26 Feb 07 |
jari |
88 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
89 |
String command = event.getActionCommand(); |
2 |
26 Feb 07 |
jari |
90 |
if (command.equals("ok-command")) { |
2 |
26 Feb 07 |
jari |
91 |
onOk(); |
2 |
26 Feb 07 |
jari |
92 |
} else if (command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
93 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
94 |
dispose(); |
2 |
26 Feb 07 |
jari |
95 |
} |
2 |
26 Feb 07 |
jari |
96 |
} |
2 |
26 Feb 07 |
jari |
97 |
|
2 |
26 Feb 07 |
jari |
98 |
public void keyPressed(KeyEvent event) { |
2 |
26 Feb 07 |
jari |
99 |
if (event.getKeyCode() == KeyEvent.VK_ENTER) { |
2 |
26 Feb 07 |
jari |
100 |
onOk(); |
2 |
26 Feb 07 |
jari |
101 |
} |
2 |
26 Feb 07 |
jari |
102 |
} |
2 |
26 Feb 07 |
jari |
103 |
|
2 |
26 Feb 07 |
jari |
104 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
105 |
result = JOptionPane.CLOSED_OPTION; |
2 |
26 Feb 07 |
jari |
106 |
dispose(); |
2 |
26 Feb 07 |
jari |
107 |
} |
2 |
26 Feb 07 |
jari |
108 |
|
2 |
26 Feb 07 |
jari |
109 |
private void onOk() { |
2 |
26 Feb 07 |
jari |
110 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
111 |
dispose(); |
2 |
26 Feb 07 |
jari |
112 |
} |
2 |
26 Feb 07 |
jari |
113 |
|
2 |
26 Feb 07 |
jari |
114 |
public void keyReleased(KeyEvent event) {} |
2 |
26 Feb 07 |
jari |
115 |
public void keyTyped(KeyEvent event) {} |
2 |
26 Feb 07 |
jari |
116 |
} |
2 |
26 Feb 07 |
jari |
117 |
} |