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: MessageDisplay.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.3 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2005/03/10 15:26:21 $ |
2 |
26 Feb 07 |
jari |
* $Author: braistedj $ |
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.Font; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.GridBagLayout; |
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 |
import java.awt.event.KeyEvent; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.event.KeyListener; |
2 |
26 Feb 07 |
jari |
20 |
|
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.JButton; |
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 |
|
2 |
26 Feb 07 |
jari |
25 |
public class MessageDisplay extends ActionInfoDialog { |
2 |
26 Feb 07 |
jari |
26 |
final static int MESSAGE_TEXT = 0; |
2 |
26 Feb 07 |
jari |
27 |
final static int CLOSE_BUTTON = 1; |
2 |
26 Feb 07 |
jari |
28 |
|
2 |
26 Feb 07 |
jari |
29 |
private JFrame parent; |
2 |
26 Feb 07 |
jari |
30 |
private GBA gba; |
2 |
26 Feb 07 |
jari |
31 |
JLabel messageLabel; |
2 |
26 Feb 07 |
jari |
32 |
JButton closeButton; |
2 |
26 Feb 07 |
jari |
33 |
Font messageDisplayFont; |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
35 |
public MessageDisplay(JFrame parent, String message) { |
2 |
26 Feb 07 |
jari |
36 |
super(parent, true); |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
try { |
2 |
26 Feb 07 |
jari |
39 |
this.parent = parent; |
2 |
26 Feb 07 |
jari |
40 |
gba = new GBA(); |
2 |
26 Feb 07 |
jari |
41 |
messageDisplayFont = new Font("serif", Font.PLAIN, 12); |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
messageLabel = new JLabel(message); |
2 |
26 Feb 07 |
jari |
44 |
messageLabel.setFont(messageDisplayFont); |
2 |
26 Feb 07 |
jari |
45 |
messageLabel.addKeyListener(new EventListener()); |
2 |
26 Feb 07 |
jari |
46 |
closeButton = new JButton("Close"); |
2 |
26 Feb 07 |
jari |
47 |
closeButton.addActionListener(new EventListener()); |
2 |
26 Feb 07 |
jari |
48 |
|
2 |
26 Feb 07 |
jari |
49 |
contentPane.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
50 |
gba.add(contentPane, messageLabel, 0, 0, 3, 1, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
51 |
gba.add(contentPane, closeButton, 1, 1, 1, 1, 0, 0, GBA.NONE, GBA.C); |
2 |
26 Feb 07 |
jari |
52 |
|
2 |
26 Feb 07 |
jari |
53 |
pack(); |
2 |
26 Feb 07 |
jari |
54 |
setResizable(true); |
2 |
26 Feb 07 |
jari |
55 |
setTitle("TIGR MultiExperimentViewer Message"); |
2 |
26 Feb 07 |
jari |
56 |
setLocation(300, 300); |
2 |
26 Feb 07 |
jari |
57 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
58 |
System.out.println("Exception (MessageDisplay.const()): " + e); |
2 |
26 Feb 07 |
jari |
59 |
} |
2 |
26 Feb 07 |
jari |
60 |
} |
2 |
26 Feb 07 |
jari |
61 |
|
2 |
26 Feb 07 |
jari |
62 |
public MessageDisplay(JFrame parent, String message, String value) { |
2 |
26 Feb 07 |
jari |
63 |
super(parent, true); |
2 |
26 Feb 07 |
jari |
64 |
|
2 |
26 Feb 07 |
jari |
//Would you be so kind as to fix me? |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
try { |
2 |
26 Feb 07 |
jari |
68 |
this.parent = parent; |
2 |
26 Feb 07 |
jari |
69 |
gba = new GBA(); |
2 |
26 Feb 07 |
jari |
70 |
messageDisplayFont = new Font("serif", Font.PLAIN, 12); |
2 |
26 Feb 07 |
jari |
71 |
|
2 |
26 Feb 07 |
jari |
72 |
if (message.startsWith("Result set is DEAD")) { |
2 |
26 Feb 07 |
jari |
73 |
message = "No data to retrieve for Plate Number " + value; |
2 |
26 Feb 07 |
jari |
74 |
} else if (message.startsWith("Incorrect syntax near")) { |
2 |
26 Feb 07 |
jari |
75 |
message = value + " is an invalid Plate Number - Code B1"; |
2 |
26 Feb 07 |
jari |
76 |
} else if (message.startsWith("Invalid column name")) { |
2 |
26 Feb 07 |
jari |
77 |
message = value + " is an invalid Plate Number - Code C1"; |
2 |
26 Feb 07 |
jari |
78 |
} else if (message.startsWith("Connection failed")) { |
2 |
26 Feb 07 |
jari |
79 |
message = "Could not connect to database."; |
2 |
26 Feb 07 |
jari |
80 |
} else if (message.startsWith("Login failed")) { |
2 |
26 Feb 07 |
jari |
81 |
message = "Could not login to database."; |
2 |
26 Feb 07 |
jari |
82 |
} else if (message.startsWith("SELECT permission denied")) { |
2 |
26 Feb 07 |
jari |
83 |
message = "Database access error. Contact support."; |
2 |
26 Feb 07 |
jari |
84 |
} else if (message.startsWith("EXECUTE permission denied")) { |
2 |
26 Feb 07 |
jari |
85 |
message = "Database access error. Contact support."; |
2 |
26 Feb 07 |
jari |
86 |
} else if (message.startsWith("divide by zero")) { |
2 |
26 Feb 07 |
jari |
87 |
message = "Numerical Exception. Contact support."; |
2 |
26 Feb 07 |
jari |
88 |
} else if (message.startsWith("Null")) { |
2 |
26 Feb 07 |
jari |
89 |
message = "Null on Plate Number " + value + "?! Contact support."; |
2 |
26 Feb 07 |
jari |
90 |
} else if (message.startsWith("Thread write failed")) { |
2 |
26 Feb 07 |
jari |
91 |
message = "Error writing data to socket. Contact support."; |
2 |
26 Feb 07 |
jari |
92 |
} else if (message.startsWith("Server user id")) { |
2 |
26 Feb 07 |
jari |
93 |
message = "Invalid login for database."; |
2 |
26 Feb 07 |
jari |
94 |
} else if (message.startsWith("Subquery returned more than 1 value")) { |
2 |
26 Feb 07 |
jari |
95 |
message = "Query exception. Contact support."; |
2 |
26 Feb 07 |
jari |
96 |
} |
2 |
26 Feb 07 |
jari |
97 |
|
2 |
26 Feb 07 |
jari |
98 |
messageLabel = new JLabel(message); |
2 |
26 Feb 07 |
jari |
99 |
messageLabel.setFont(messageDisplayFont); |
2 |
26 Feb 07 |
jari |
100 |
messageLabel.addKeyListener(new EventListener()); |
2 |
26 Feb 07 |
jari |
101 |
closeButton = new JButton("Close TIGR MultiViewer Message"); |
2 |
26 Feb 07 |
jari |
102 |
closeButton.addActionListener(new EventListener()); |
2 |
26 Feb 07 |
jari |
103 |
|
2 |
26 Feb 07 |
jari |
104 |
contentPane.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
105 |
gba.add(contentPane, messageLabel, 0, 0, 3, 1, 1, 1, GBA.B, GBA.C); |
2 |
26 Feb 07 |
jari |
106 |
gba.add(contentPane, closeButton, 1, 1, 1, 1, 0, 0, GBA.NONE, GBA.C); |
2 |
26 Feb 07 |
jari |
107 |
|
2 |
26 Feb 07 |
jari |
108 |
pack(); |
2 |
26 Feb 07 |
jari |
109 |
setResizable(true); |
2 |
26 Feb 07 |
jari |
110 |
setTitle("TIGR MultiViewer Message"); |
2 |
26 Feb 07 |
jari |
111 |
setLocation(300, 300); |
2 |
26 Feb 07 |
jari |
112 |
show(); |
2 |
26 Feb 07 |
jari |
113 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
114 |
System.out.println("Exception (MessageDisplay.const()): " + e); |
2 |
26 Feb 07 |
jari |
115 |
} |
2 |
26 Feb 07 |
jari |
116 |
} |
2 |
26 Feb 07 |
jari |
117 |
|
2 |
26 Feb 07 |
jari |
118 |
public MessageDisplay(JFrame parent, String message, int value) { |
2 |
26 Feb 07 |
jari |
119 |
this(parent, message, "" + value); |
2 |
26 Feb 07 |
jari |
120 |
} |
2 |
26 Feb 07 |
jari |
121 |
|
2 |
26 Feb 07 |
jari |
122 |
public MessageDisplay(JFrame parent, Exception e, String value) { |
2 |
26 Feb 07 |
jari |
123 |
this(parent, e.getMessage(), value); |
2 |
26 Feb 07 |
jari |
124 |
} |
2 |
26 Feb 07 |
jari |
125 |
|
2 |
26 Feb 07 |
jari |
126 |
public MessageDisplay(JFrame parent, Exception e, int value) { |
2 |
26 Feb 07 |
jari |
127 |
this(parent, e.getMessage(), "" + value); |
2 |
26 Feb 07 |
jari |
128 |
} |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
class EventListener implements ActionListener, KeyListener { |
2 |
26 Feb 07 |
jari |
131 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
132 |
if (event.getSource() == closeButton) dispose(); |
2 |
26 Feb 07 |
jari |
133 |
} |
2 |
26 Feb 07 |
jari |
134 |
|
2 |
26 Feb 07 |
jari |
135 |
public void keyPressed(KeyEvent event) { |
2 |
26 Feb 07 |
jari |
136 |
if (event.getKeyCode() == KeyEvent.VK_ENTER) { |
2 |
26 Feb 07 |
jari |
137 |
dispose(); |
2 |
26 Feb 07 |
jari |
138 |
} |
2 |
26 Feb 07 |
jari |
139 |
} |
2 |
26 Feb 07 |
jari |
140 |
|
2 |
26 Feb 07 |
jari |
141 |
public void keyReleased(KeyEvent event) {;} |
2 |
26 Feb 07 |
jari |
142 |
public void keyTyped(KeyEvent event) {;} |
2 |
26 Feb 07 |
jari |
143 |
} |
2 |
26 Feb 07 |
jari |
144 |
} |