2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
* AnalysisSaveDialog.java |
2 |
26 Feb 07 |
jari |
3 |
* |
2 |
26 Feb 07 |
jari |
* Created on January 29, 2004, 4:06 PM |
2 |
26 Feb 07 |
jari |
5 |
*/ |
2 |
26 Feb 07 |
jari |
6 |
|
2 |
26 Feb 07 |
jari |
7 |
package org.tigr.microarray.mev; |
2 |
26 Feb 07 |
jari |
8 |
|
2 |
26 Feb 07 |
jari |
9 |
|
2 |
26 Feb 07 |
jari |
10 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
11 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
12 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
13 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
18 |
|
2 |
26 Feb 07 |
jari |
19 |
import javax.swing.BorderFactory; |
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.JButton; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.JCheckBox; |
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
24 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.border.BevelBorder; |
2 |
26 Feb 07 |
jari |
27 |
/** |
2 |
26 Feb 07 |
jari |
28 |
* |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
30 |
*/ |
2 |
26 Feb 07 |
jari |
31 |
public class AnalysisSaveDialog extends org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
32 |
|
2 |
26 Feb 07 |
jari |
33 |
int result = JOptionPane.NO_OPTION; |
2 |
26 Feb 07 |
jari |
34 |
JCheckBox askAgainBox; |
2 |
26 Feb 07 |
jari |
35 |
|
2 |
26 Feb 07 |
jari |
/** Creates a new instance of AnalysisSaveDialog */ |
2 |
26 Feb 07 |
jari |
37 |
public AnalysisSaveDialog(JFrame frame) { |
2 |
26 Feb 07 |
jari |
38 |
super(frame, "Save Analysis Check", true); |
2 |
26 Feb 07 |
jari |
39 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
40 |
|
2 |
26 Feb 07 |
jari |
41 |
JPanel buttonPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
42 |
JButton okButton = new JButton("Yes"); |
2 |
26 Feb 07 |
jari |
43 |
okButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
44 |
okButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); |
2 |
26 Feb 07 |
jari |
45 |
okButton.setPreferredSize(new Dimension(50, 30)); |
2 |
26 Feb 07 |
jari |
46 |
okButton.setActionCommand("yes"); |
2 |
26 Feb 07 |
jari |
47 |
okButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
48 |
|
2 |
26 Feb 07 |
jari |
49 |
JButton noButton = new JButton("No"); |
2 |
26 Feb 07 |
jari |
50 |
noButton.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
51 |
noButton.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); |
2 |
26 Feb 07 |
jari |
52 |
noButton.setPreferredSize(new Dimension(50, 30)); |
2 |
26 Feb 07 |
jari |
53 |
noButton.setActionCommand("no"); |
2 |
26 Feb 07 |
jari |
54 |
noButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
56 |
buttonPanel.add(okButton, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,20), 0,0)); |
2 |
26 Feb 07 |
jari |
57 |
buttonPanel.add(noButton, new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,20,0,0), 0,0)); |
2 |
26 Feb 07 |
jari |
58 |
|
2 |
26 Feb 07 |
jari |
59 |
JPanel paramPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
60 |
paramPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
61 |
paramPanel.setBorder(BorderFactory.createLineBorder(Color.black)); |
2 |
26 Feb 07 |
jari |
62 |
JLabel promptLabel = new JLabel("You are exiting without saving the state of the current analysis."); |
2 |
26 Feb 07 |
jari |
63 |
promptLabel.setHorizontalAlignment(JLabel.CENTER); |
2 |
26 Feb 07 |
jari |
64 |
JLabel promptLabel2 = new JLabel("Would you like to save the analysis?"); |
2 |
26 Feb 07 |
jari |
65 |
promptLabel2.setHorizontalAlignment(JLabel.CENTER); |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
askAgainBox = new JCheckBox("Don't show this dialog again", false); |
2 |
26 Feb 07 |
jari |
68 |
askAgainBox.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
69 |
askAgainBox.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
70 |
|
2 |
26 Feb 07 |
jari |
71 |
paramPanel.add(promptLabel, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(20,0,0,0), 0, 0)); |
2 |
26 Feb 07 |
jari |
72 |
paramPanel.add(promptLabel2, new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(5,0,0,0), 0, 0)); |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
paramPanel.add(askAgainBox, new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.CENTER,GridBagConstraints.BOTH, new Insets(30,0,0,0), 0, 0)); |
2 |
26 Feb 07 |
jari |
75 |
|
2 |
26 Feb 07 |
jari |
76 |
this.supplantButtonPanel(buttonPanel); |
2 |
26 Feb 07 |
jari |
77 |
this.addContent(paramPanel); |
2 |
26 Feb 07 |
jari |
78 |
|
2 |
26 Feb 07 |
jari |
79 |
this.setSize(470, 240); |
2 |
26 Feb 07 |
jari |
80 |
} |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
|
2 |
26 Feb 07 |
jari |
83 |
public int showModal(){ |
2 |
26 Feb 07 |
jari |
84 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
85 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
86 |
this.show(); |
2 |
26 Feb 07 |
jari |
87 |
return result; |
2 |
26 Feb 07 |
jari |
88 |
} |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
public void disposeDialog() { this.dispose(); } |
2 |
26 Feb 07 |
jari |
91 |
|
2 |
26 Feb 07 |
jari |
92 |
public boolean askAgain() { |
2 |
26 Feb 07 |
jari |
93 |
return !this.askAgainBox.isSelected(); |
2 |
26 Feb 07 |
jari |
94 |
} |
2 |
26 Feb 07 |
jari |
95 |
|
2 |
26 Feb 07 |
jari |
96 |
public class Listener implements ActionListener { |
2 |
26 Feb 07 |
jari |
97 |
public void actionPerformed(ActionEvent ae) { |
2 |
26 Feb 07 |
jari |
98 |
String command = ae.getActionCommand(); |
2 |
26 Feb 07 |
jari |
99 |
if(command.equals("yes")) |
2 |
26 Feb 07 |
jari |
100 |
result = JOptionPane.YES_OPTION; |
2 |
26 Feb 07 |
jari |
101 |
else |
2 |
26 Feb 07 |
jari |
102 |
result = JOptionPane.NO_OPTION; |
2 |
26 Feb 07 |
jari |
103 |
disposeDialog(); |
2 |
26 Feb 07 |
jari |
104 |
} |
2 |
26 Feb 07 |
jari |
105 |
|
2 |
26 Feb 07 |
jari |
106 |
} |
2 |
26 Feb 07 |
jari |
107 |
|
2 |
26 Feb 07 |
jari |
108 |
|
2 |
26 Feb 07 |
jari |
109 |
public static void main(String [] args) { |
2 |
26 Feb 07 |
jari |
110 |
AnalysisSaveDialog dialog = new AnalysisSaveDialog(new JFrame()); |
2 |
26 Feb 07 |
jari |
111 |
int result = dialog.showModal(); |
2 |
26 Feb 07 |
jari |
112 |
System.out.println("result = "+result); |
2 |
26 Feb 07 |
jari |
113 |
System.out.println("ask again = "+dialog.askAgain()); |
2 |
26 Feb 07 |
jari |
114 |
} |
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
116 |
} |