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: TransferDialog.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.awt; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.AWTEventMulticaster; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Container; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.List; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.event.WindowListener; |
2 |
26 Feb 07 |
jari |
23 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.JButton; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.JDialog; |
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
29 |
|
2 |
26 Feb 07 |
jari |
30 |
public class TransferDialog extends JDialog { |
2 |
26 Feb 07 |
jari |
31 |
private List availableList, selectedList; |
2 |
26 Feb 07 |
jari |
32 |
private JButton addButton, removeButton, addAllButton, removeAllButton, okButton, cancelButton; |
2 |
26 Feb 07 |
jari |
33 |
private JLabel availableLabel, selectedLabel; |
2 |
26 Feb 07 |
jari |
34 |
private EventListener eventListener; |
2 |
26 Feb 07 |
jari |
35 |
private ActionListener listeners; |
2 |
26 Feb 07 |
jari |
36 |
private String[] selectedItems; |
2 |
26 Feb 07 |
jari |
37 |
private GBA gba; |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
//Add tooltip text? |
2 |
26 Feb 07 |
jari |
40 |
|
2 |
26 Feb 07 |
jari |
41 |
public TransferDialog(JFrame parentFrame, String title, boolean modal, Vector availableVector, Vector selectedVector) { |
2 |
26 Feb 07 |
jari |
42 |
super(parentFrame, title, modal); |
2 |
26 Feb 07 |
jari |
43 |
|
2 |
26 Feb 07 |
jari |
44 |
gba = new GBA(); |
2 |
26 Feb 07 |
jari |
45 |
eventListener = new EventListener(); |
2 |
26 Feb 07 |
jari |
46 |
addWindowListener(eventListener); |
2 |
26 Feb 07 |
jari |
47 |
Container cc = getContentPane(); |
2 |
26 Feb 07 |
jari |
48 |
cc.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
49 |
|
2 |
26 Feb 07 |
jari |
50 |
selectedItems = new String[0]; |
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
//Create components |
2 |
26 Feb 07 |
jari |
//Put the lists in scrollpanes! |
2 |
26 Feb 07 |
jari |
54 |
availableList = new List(); |
2 |
26 Feb 07 |
jari |
55 |
availableList.setMultipleMode(true); |
2 |
26 Feb 07 |
jari |
56 |
try { |
2 |
26 Feb 07 |
jari |
57 |
for (int i = 0; i < availableVector.size(); i++) availableList.add((String) availableVector.elementAt(i)); |
2 |
26 Feb 07 |
jari |
58 |
} catch (NullPointerException npe) { |
2 |
26 Feb 07 |
jari |
59 |
; |
2 |
26 Feb 07 |
jari |
60 |
} |
2 |
26 Feb 07 |
jari |
61 |
selectedList = new List(); |
2 |
26 Feb 07 |
jari |
62 |
selectedList.setMultipleMode(true); |
2 |
26 Feb 07 |
jari |
63 |
try { |
2 |
26 Feb 07 |
jari |
64 |
for (int i = 0; i < selectedVector.size(); i++) selectedList.add((String) selectedVector.elementAt(i)); |
2 |
26 Feb 07 |
jari |
65 |
} catch (NullPointerException npe) { |
2 |
26 Feb 07 |
jari |
66 |
; |
2 |
26 Feb 07 |
jari |
67 |
} |
2 |
26 Feb 07 |
jari |
68 |
addButton = new JButton("Add (->)"); |
2 |
26 Feb 07 |
jari |
69 |
addButton.addActionListener(eventListener); |
2 |
26 Feb 07 |
jari |
70 |
addAllButton = new JButton("Add All (=>>)"); |
2 |
26 Feb 07 |
jari |
71 |
addAllButton.addActionListener(eventListener); |
2 |
26 Feb 07 |
jari |
72 |
removeAllButton = new JButton("Remove All (<<=)"); |
2 |
26 Feb 07 |
jari |
73 |
removeAllButton.addActionListener(eventListener); |
2 |
26 Feb 07 |
jari |
74 |
removeButton = new JButton("Remove (<-)"); |
2 |
26 Feb 07 |
jari |
75 |
removeButton.addActionListener(eventListener); |
2 |
26 Feb 07 |
jari |
76 |
cancelButton = new JButton("Cancel"); |
2 |
26 Feb 07 |
jari |
77 |
cancelButton.addActionListener(eventListener); |
2 |
26 Feb 07 |
jari |
78 |
okButton = new JButton("OK"); |
2 |
26 Feb 07 |
jari |
79 |
okButton.addActionListener(eventListener); |
2 |
26 Feb 07 |
jari |
80 |
availableLabel = new JLabel("Available"); |
2 |
26 Feb 07 |
jari |
81 |
selectedLabel = new JLabel("Selected"); |
2 |
26 Feb 07 |
jari |
82 |
|
2 |
26 Feb 07 |
jari |
//Add components to layout |
2 |
26 Feb 07 |
jari |
84 |
gba.add(cc, availableList, 0, 0, 1, 6, 1, 1, GBA.B, GBA.C, new Insets(5, 5, 5, 0), 0, 0); |
2 |
26 Feb 07 |
jari |
85 |
gba.add(cc, selectedList, 2, 0, 1, 6, 1, 1, GBA.B, GBA.C, new Insets(5, 0, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
86 |
gba.add(cc, addButton, 1, 0, 1, 1, 0, 0, GBA.H, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
87 |
gba.add(cc, addAllButton, 1, 1, 1, 1, 0, 0, GBA.H, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
88 |
gba.add(cc, removeAllButton, 1, 2, 1, 1, 0, 0, GBA.H, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
89 |
gba.add(cc, removeButton, 1, 3, 1, 1, 0, 0, GBA.H, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
90 |
gba.add(cc, cancelButton, 1, 4, 1, 1, 0, 0, GBA.H, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
91 |
gba.add(cc, okButton, 1, 6, 1, 1, 0, 0, GBA.H, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
92 |
gba.add(cc, availableLabel, 0, 6, 1, 1, 0, 0, GBA.N, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
93 |
gba.add(cc, selectedLabel, 2, 6, 1, 1, 0, 0, GBA.N, GBA.C, new Insets(5, 5, 5, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
94 |
pack(); |
2 |
26 Feb 07 |
jari |
95 |
} |
2 |
26 Feb 07 |
jari |
96 |
|
2 |
26 Feb 07 |
jari |
97 |
public boolean hasSelectedItems() { |
2 |
26 Feb 07 |
jari |
98 |
if (selectedItems.length < 1) return false; |
2 |
26 Feb 07 |
jari |
99 |
else return true; |
2 |
26 Feb 07 |
jari |
100 |
} |
2 |
26 Feb 07 |
jari |
101 |
|
2 |
26 Feb 07 |
jari |
102 |
public String[] getSelectedItems() {return this.selectedItems;} |
2 |
26 Feb 07 |
jari |
103 |
|
2 |
26 Feb 07 |
jari |
104 |
public void addActionListener(ActionListener al) {listeners = AWTEventMulticaster.add(listeners, al);} |
2 |
26 Feb 07 |
jari |
105 |
public void removeActionListener(ActionListener al) {listeners = AWTEventMulticaster.remove(listeners, al);} |
2 |
26 Feb 07 |
jari |
106 |
|
2 |
26 Feb 07 |
jari |
107 |
private class EventListener implements ActionListener, WindowListener { |
2 |
26 Feb 07 |
jari |
108 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
//Do the lists need to be sorted with each action? |
2 |
26 Feb 07 |
jari |
110 |
|
2 |
26 Feb 07 |
jari |
111 |
if (event.getSource() == addButton) { |
2 |
26 Feb 07 |
jari |
112 |
String[] chosen = availableList.getSelectedItems(); |
2 |
26 Feb 07 |
jari |
113 |
for (int i = 0; i < chosen.length; i++) { |
2 |
26 Feb 07 |
jari |
114 |
availableList.remove(chosen[i]); |
2 |
26 Feb 07 |
jari |
115 |
selectedList.add(chosen[i]); |
2 |
26 Feb 07 |
jari |
116 |
} |
2 |
26 Feb 07 |
jari |
117 |
} else if (event.getSource() == addAllButton) { |
2 |
26 Feb 07 |
jari |
118 |
String[] available = availableList.getItems(); |
2 |
26 Feb 07 |
jari |
119 |
for (int i = 0; i < available.length; i++) { |
2 |
26 Feb 07 |
jari |
120 |
availableList.remove(available[i]); |
2 |
26 Feb 07 |
jari |
121 |
selectedList.add(available[i]); |
2 |
26 Feb 07 |
jari |
122 |
} |
2 |
26 Feb 07 |
jari |
123 |
} else if (event.getSource() == removeAllButton) { |
2 |
26 Feb 07 |
jari |
124 |
String[] selected = selectedList.getItems(); |
2 |
26 Feb 07 |
jari |
125 |
for (int i = 0; i < selected.length; i++) { |
2 |
26 Feb 07 |
jari |
126 |
selectedList.remove(selected[i]); |
2 |
26 Feb 07 |
jari |
127 |
availableList.add(selected[i]); |
2 |
26 Feb 07 |
jari |
128 |
} |
2 |
26 Feb 07 |
jari |
129 |
} else if (event.getSource() == removeButton) { |
2 |
26 Feb 07 |
jari |
130 |
String[] chosen = selectedList.getSelectedItems(); |
2 |
26 Feb 07 |
jari |
131 |
for (int i = 0; i < chosen.length; i++) { |
2 |
26 Feb 07 |
jari |
132 |
selectedList.remove(chosen[i]); |
2 |
26 Feb 07 |
jari |
133 |
availableList.add(chosen[i]); |
2 |
26 Feb 07 |
jari |
134 |
} |
2 |
26 Feb 07 |
jari |
135 |
} else if (event.getSource() == cancelButton) { |
2 |
26 Feb 07 |
jari |
136 |
dispose(); |
2 |
26 Feb 07 |
jari |
137 |
} else if (event.getSource() == okButton) { |
2 |
26 Feb 07 |
jari |
138 |
String[] selected = selectedList.getItems(); |
2 |
26 Feb 07 |
jari |
139 |
selectedItems = selected; |
2 |
26 Feb 07 |
jari |
140 |
dispose(); |
2 |
26 Feb 07 |
jari |
141 |
|
2 |
26 Feb 07 |
jari |
142 |
if (listeners != null) listeners.actionPerformed(new ActionEvent(this, event.getID(), event.getActionCommand())); |
2 |
26 Feb 07 |
jari |
143 |
} |
2 |
26 Feb 07 |
jari |
144 |
} |
2 |
26 Feb 07 |
jari |
145 |
|
2 |
26 Feb 07 |
jari |
146 |
public void windowClosing(WindowEvent event) {dispose();} |
2 |
26 Feb 07 |
jari |
147 |
public void windowOpened(WindowEvent event) {;} |
2 |
26 Feb 07 |
jari |
148 |
public void windowClosed(WindowEvent event) {;} |
2 |
26 Feb 07 |
jari |
149 |
public void windowIconified(WindowEvent event) {;} |
2 |
26 Feb 07 |
jari |
150 |
public void windowDeiconified(WindowEvent event) {;} |
2 |
26 Feb 07 |
jari |
151 |
public void windowActivated(WindowEvent event) {;} |
2 |
26 Feb 07 |
jari |
152 |
public void windowDeactivated(WindowEvent event) {;} |
2 |
26 Feb 07 |
jari |
153 |
} |
2 |
26 Feb 07 |
jari |
154 |
} |