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: FileTransferDialog.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.2 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 21:00:04 $ |
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.util.swing; |
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.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.GridLayout; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.event.WindowAdapter; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
25 |
import java.io.File; |
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.JDialog; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
32 |
import javax.swing.filechooser.FileFilter; |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
public class FileTransferDialog extends JDialog { |
2 |
26 Feb 07 |
jari |
35 |
|
2 |
26 Feb 07 |
jari |
36 |
private int result; |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
private FileTransferPanel transferPanel; |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>FileTransferDialog</code> with specified |
2 |
26 Feb 07 |
jari |
* initial directory and set of file filters. |
2 |
26 Feb 07 |
jari |
43 |
*/ |
2 |
26 Feb 07 |
jari |
44 |
public FileTransferDialog(JFrame parent, String currentDirectory, FileFilter[] fileFilters) { |
2 |
26 Feb 07 |
jari |
45 |
super(parent, "Select Files", true); |
2 |
26 Feb 07 |
jari |
46 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
47 |
transferPanel = new FileTransferPanel(currentDirectory, fileFilters); |
2 |
26 Feb 07 |
jari |
48 |
JPanel btnsPanel = createBtnsPanel(listener); |
2 |
26 Feb 07 |
jari |
49 |
|
2 |
26 Feb 07 |
jari |
50 |
Container content = getContentPane(); |
2 |
26 Feb 07 |
jari |
51 |
content.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
52 |
content.add(transferPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0 |
2 |
26 Feb 07 |
jari |
53 |
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
54 |
content.add(btnsPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0 |
2 |
26 Feb 07 |
jari |
55 |
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 8, 4, 8), 0, 0)); |
2 |
26 Feb 07 |
jari |
56 |
|
2 |
26 Feb 07 |
jari |
57 |
addWindowListener(listener); |
2 |
26 Feb 07 |
jari |
58 |
pack(); |
2 |
26 Feb 07 |
jari |
59 |
} |
2 |
26 Feb 07 |
jari |
60 |
|
2 |
26 Feb 07 |
jari |
61 |
/** |
2 |
26 Feb 07 |
jari |
* Shows the dialog. |
2 |
26 Feb 07 |
jari |
63 |
*/ |
2 |
26 Feb 07 |
jari |
64 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
65 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
66 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
67 |
show(); |
2 |
26 Feb 07 |
jari |
68 |
return result; |
2 |
26 Feb 07 |
jari |
69 |
} |
2 |
26 Feb 07 |
jari |
70 |
|
2 |
26 Feb 07 |
jari |
71 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the choosed files. |
2 |
26 Feb 07 |
jari |
73 |
*/ |
2 |
26 Feb 07 |
jari |
74 |
public File[] getFiles() { |
2 |
26 Feb 07 |
jari |
75 |
return transferPanel.getFiles(); |
2 |
26 Feb 07 |
jari |
76 |
} |
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a panel with 'OK' and 'Cancel' buttons. |
2 |
26 Feb 07 |
jari |
80 |
*/ |
2 |
26 Feb 07 |
jari |
81 |
private JPanel createBtnsPanel(ActionListener listener) { |
2 |
26 Feb 07 |
jari |
82 |
GridLayout gridLayout = new GridLayout(); |
2 |
26 Feb 07 |
jari |
83 |
JPanel panel = new JPanel(gridLayout); |
2 |
26 Feb 07 |
jari |
84 |
|
2 |
26 Feb 07 |
jari |
85 |
JButton okButton = new JButton("OK"); |
2 |
26 Feb 07 |
jari |
86 |
okButton.setActionCommand("ok-command"); |
2 |
26 Feb 07 |
jari |
87 |
okButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
88 |
panel.add(okButton); |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
JButton cancelButton = new JButton("Cancel"); |
2 |
26 Feb 07 |
jari |
91 |
cancelButton.setActionCommand("cancel-command"); |
2 |
26 Feb 07 |
jari |
92 |
cancelButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
93 |
gridLayout.setHgap(4); |
2 |
26 Feb 07 |
jari |
94 |
panel.add(cancelButton); |
2 |
26 Feb 07 |
jari |
95 |
|
2 |
26 Feb 07 |
jari |
96 |
getRootPane().setDefaultButton(okButton); |
2 |
26 Feb 07 |
jari |
97 |
|
2 |
26 Feb 07 |
jari |
98 |
return panel; |
2 |
26 Feb 07 |
jari |
99 |
} |
2 |
26 Feb 07 |
jari |
100 |
|
2 |
26 Feb 07 |
jari |
101 |
/** |
2 |
26 Feb 07 |
jari |
* Listener to listen to window and action events. |
2 |
26 Feb 07 |
jari |
103 |
*/ |
2 |
26 Feb 07 |
jari |
104 |
private class Listener extends WindowAdapter implements ActionListener { |
2 |
26 Feb 07 |
jari |
105 |
|
2 |
26 Feb 07 |
jari |
106 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
107 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
108 |
if (command.equals("ok-command")) { |
2 |
26 Feb 07 |
jari |
109 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
110 |
dispose(); |
2 |
26 Feb 07 |
jari |
111 |
} else if (command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
112 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
113 |
dispose(); |
2 |
26 Feb 07 |
jari |
114 |
} |
2 |
26 Feb 07 |
jari |
115 |
} |
2 |
26 Feb 07 |
jari |
116 |
|
2 |
26 Feb 07 |
jari |
117 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
118 |
result = JOptionPane.CLOSED_OPTION; |
2 |
26 Feb 07 |
jari |
119 |
dispose(); |
2 |
26 Feb 07 |
jari |
120 |
} |
2 |
26 Feb 07 |
jari |
121 |
|
2 |
26 Feb 07 |
jari |
122 |
} |
2 |
26 Feb 07 |
jari |
123 |
} |