2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
* ListOrderDialog.java |
2 |
26 Feb 07 |
jari |
3 |
* |
2 |
26 Feb 07 |
jari |
* Created on May 14, 2004, 12:15 PM |
2 |
26 Feb 07 |
jari |
5 |
*/ |
2 |
26 Feb 07 |
jari |
6 |
|
2 |
26 Feb 07 |
jari |
7 |
package org.tigr.microarray.mev.cluster.gui.impl.dialogs; |
2 |
26 Feb 07 |
jari |
8 |
|
2 |
26 Feb 07 |
jari |
9 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
10 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
11 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
12 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
13 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
14 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.event.ItemEvent; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.event.ItemListener; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
18 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
19 |
|
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.BorderFactory; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.DefaultListSelectionModel; |
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JButton; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
24 |
import javax.swing.JList; |
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.JScrollPane; |
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.border.BevelBorder; |
2 |
26 Feb 07 |
jari |
28 |
|
2 |
26 Feb 07 |
jari |
29 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
30 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow; |
2 |
26 Feb 07 |
jari |
31 |
|
2 |
26 Feb 07 |
jari |
32 |
|
2 |
26 Feb 07 |
jari |
33 |
/** |
2 |
26 Feb 07 |
jari |
34 |
* |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
36 |
*/ |
2 |
26 Feb 07 |
jari |
37 |
public class ListOrderDialog extends AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
int result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
40 |
JList list; |
2 |
26 Feb 07 |
jari |
41 |
Vector data; |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
/** Creates a new instance of ListOrderDialog */ |
2 |
26 Feb 07 |
jari |
44 |
public ListOrderDialog(JFrame parent, JList list, Vector data, String listTitle, String message) { |
2 |
26 Feb 07 |
jari |
45 |
super(parent, "List Sorter", true); |
2 |
26 Feb 07 |
jari |
46 |
this.list = list; |
2 |
26 Feb 07 |
jari |
47 |
this.data = data; |
2 |
26 Feb 07 |
jari |
48 |
EventListener listener = new EventListener(); |
2 |
26 Feb 07 |
jari |
49 |
|
2 |
26 Feb 07 |
jari |
50 |
ParameterPanel parameters = new ParameterPanel(listTitle); |
2 |
26 Feb 07 |
jari |
51 |
list.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); |
2 |
26 Feb 07 |
jari |
52 |
list.setSelectedIndex(0); |
2 |
26 Feb 07 |
jari |
53 |
parameters.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
54 |
JScrollPane pane = new JScrollPane(list); |
2 |
26 Feb 07 |
jari |
// pane.set |
2 |
26 Feb 07 |
jari |
56 |
parameters.add(pane, new GridBagConstraints(0,0,1,1,1.0,0.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(20,20,20,0), 0,0)); |
2 |
26 Feb 07 |
jari |
57 |
|
2 |
26 Feb 07 |
jari |
58 |
ParameterPanel buttonPanel = new ParameterPanel("Move"); |
2 |
26 Feb 07 |
jari |
59 |
buttonPanel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
60 |
JButton upButton = new JButton(GUIFactory.getIcon("arrow_up.gif")); |
2 |
26 Feb 07 |
jari |
61 |
upButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
62 |
upButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); |
2 |
26 Feb 07 |
jari |
63 |
upButton.setPreferredSize(new Dimension(30, 50)); |
2 |
26 Feb 07 |
jari |
64 |
upButton.setActionCommand("shift-up-command"); |
2 |
26 Feb 07 |
jari |
65 |
upButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
JButton downButton = new JButton(GUIFactory.getIcon("arrow_down.gif")); |
2 |
26 Feb 07 |
jari |
68 |
downButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
69 |
downButton.setPreferredSize(new Dimension(30, 50)); |
2 |
26 Feb 07 |
jari |
70 |
downButton.setActionCommand("shift-down-command"); |
2 |
26 Feb 07 |
jari |
71 |
downButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); |
2 |
26 Feb 07 |
jari |
72 |
downButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
buttonPanel.add(upButton, new GridBagConstraints(0,0,1,1,0.0,0.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,2,20), 0,0)); |
2 |
26 Feb 07 |
jari |
75 |
buttonPanel.add(downButton, new GridBagConstraints(0,1,1,1,0.0,0.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2,0,0,20), 0,0)); |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
parameters.add(buttonPanel, new GridBagConstraints(1,0,1,1,0.0,0.0,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(20,5,20,20), 0,0)); |
2 |
26 Feb 07 |
jari |
78 |
|
2 |
26 Feb 07 |
jari |
79 |
addContent(parameters); |
2 |
26 Feb 07 |
jari |
80 |
setActionListeners(listener); |
2 |
26 Feb 07 |
jari |
81 |
pack(); |
2 |
26 Feb 07 |
jari |
82 |
} |
2 |
26 Feb 07 |
jari |
83 |
|
2 |
26 Feb 07 |
jari |
84 |
/** |
2 |
26 Feb 07 |
jari |
* Shows the dialog. |
2 |
26 Feb 07 |
jari |
86 |
*/ |
2 |
26 Feb 07 |
jari |
87 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
88 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
89 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
90 |
show(); |
2 |
26 Feb 07 |
jari |
91 |
return result; |
2 |
26 Feb 07 |
jari |
92 |
} |
2 |
26 Feb 07 |
jari |
93 |
|
2 |
26 Feb 07 |
jari |
94 |
public Vector getSortedVector() { |
2 |
26 Feb 07 |
jari |
95 |
return data; |
2 |
26 Feb 07 |
jari |
96 |
} |
2 |
26 Feb 07 |
jari |
97 |
|
2 |
26 Feb 07 |
jari |
98 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to the dialog and check boxes items events. |
2 |
26 Feb 07 |
jari |
100 |
*/ |
2 |
26 Feb 07 |
jari |
101 |
private class EventListener extends DialogListener implements ItemListener { |
2 |
26 Feb 07 |
jari |
102 |
|
2 |
26 Feb 07 |
jari |
103 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
104 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
105 |
if (command.equals("ok-command")) { |
2 |
26 Feb 07 |
jari |
106 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
107 |
dispose(); |
2 |
26 Feb 07 |
jari |
108 |
} else if (command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
109 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
110 |
dispose(); |
2 |
26 Feb 07 |
jari |
111 |
} else if (command.equals("reset-command")){ |
2 |
26 Feb 07 |
jari |
112 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
113 |
return; |
2 |
26 Feb 07 |
jari |
114 |
} else if (command.equals("info-command")){ |
2 |
26 Feb 07 |
jari |
115 |
HelpWindow hw = new HelpWindow(ListOrderDialog.this, "List Sorter Dialog"); |
2 |
26 Feb 07 |
jari |
116 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
117 |
if(hw.getWindowContent()){ |
2 |
26 Feb 07 |
jari |
118 |
hw.setSize(450,600); |
2 |
26 Feb 07 |
jari |
119 |
hw.setLocation(); |
2 |
26 Feb 07 |
jari |
120 |
hw.show(); |
2 |
26 Feb 07 |
jari |
121 |
} |
2 |
26 Feb 07 |
jari |
122 |
else { |
2 |
26 Feb 07 |
jari |
123 |
hw.setVisible(false); |
2 |
26 Feb 07 |
jari |
124 |
hw.dispose(); |
2 |
26 Feb 07 |
jari |
125 |
} |
2 |
26 Feb 07 |
jari |
126 |
} else if (command.equals("shift-up-command")) { |
2 |
26 Feb 07 |
jari |
127 |
int index = list.getSelectedIndex(); |
2 |
26 Feb 07 |
jari |
128 |
if(index == 0) |
2 |
26 Feb 07 |
jari |
129 |
return; |
2 |
26 Feb 07 |
jari |
130 |
Object obj = list.getSelectedValue(); |
2 |
26 Feb 07 |
jari |
131 |
data.remove(obj); |
2 |
26 Feb 07 |
jari |
132 |
data.insertElementAt(obj, index-1); |
2 |
26 Feb 07 |
jari |
133 |
list.setSelectedIndex(index-1); |
2 |
26 Feb 07 |
jari |
134 |
} else if (command.equals("shift-down-command")) { |
2 |
26 Feb 07 |
jari |
135 |
int index = list.getSelectedIndex(); |
2 |
26 Feb 07 |
jari |
136 |
if(index == data.size()-1) |
2 |
26 Feb 07 |
jari |
137 |
return; |
2 |
26 Feb 07 |
jari |
138 |
Object obj = list.getSelectedValue(); |
2 |
26 Feb 07 |
jari |
139 |
data.remove(obj); |
2 |
26 Feb 07 |
jari |
140 |
data.insertElementAt(obj, index+1); |
2 |
26 Feb 07 |
jari |
141 |
list.setSelectedIndex(index+1); |
2 |
26 Feb 07 |
jari |
142 |
} |
2 |
26 Feb 07 |
jari |
143 |
} |
2 |
26 Feb 07 |
jari |
144 |
|
2 |
26 Feb 07 |
jari |
145 |
public void itemStateChanged(ItemEvent e) { |
2 |
26 Feb 07 |
jari |
//okButton.setEnabled(genes_box.isSelected() || cluster_box.isSelected()); |
2 |
26 Feb 07 |
jari |
147 |
} |
2 |
26 Feb 07 |
jari |
148 |
|
2 |
26 Feb 07 |
jari |
149 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
150 |
result = JOptionPane.CLOSED_OPTION; |
2 |
26 Feb 07 |
jari |
151 |
dispose(); |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
} |
2 |
26 Feb 07 |
jari |
154 |
|
2 |
26 Feb 07 |
jari |
155 |
|
2 |
26 Feb 07 |
jari |
156 |
|
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
158 |
public static void main(String [] args) { |
2 |
26 Feb 07 |
jari |
159 |
Vector data = new Vector(); |
2 |
26 Feb 07 |
jari |
160 |
data.add("Label1"); |
2 |
26 Feb 07 |
jari |
161 |
data.add("Label2"); |
2 |
26 Feb 07 |
jari |
162 |
data.add("Label3"); |
2 |
26 Feb 07 |
jari |
163 |
JList list = new JList(data); |
2 |
26 Feb 07 |
jari |
164 |
ListOrderDialog dialog = new ListOrderDialog(new JFrame(), list, data, "Sample Label Keys", "Please Arrange Keys in Desired order."); |
2 |
26 Feb 07 |
jari |
165 |
dialog.showModal(); |
2 |
26 Feb 07 |
jari |
166 |
} |
2 |
26 Feb 07 |
jari |
167 |
|
2 |
26 Feb 07 |
jari |
168 |
} |