1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
public class ErrorDialog extends javax.swing.JDialog implements ActionListener {
private static final long serialVersionUID = 1L;
private boolean details = true;
/** Creates new form BeanForm */
public ErrorDialog(String message, String details1, StackTraceElement[] details2) {
initComponents();
jButton1.addActionListener(this);
jButton2.addActionListener(this);
jButton3.addActionListener(this);
if (details2 != null) {
this.dialogVisible(message, details1, details2);
} else {
this.dialogVisible(message, details1);
}
}
public static void display(String message, String details1, StackTraceElement[] details2) {
ErrorDialog dialog = new ErrorDialog(message, details1, details2);
UserPreferences.setLocationRelativeToDefaultFrame(dialog);
dialog.setVisible(true);
}
public static void display(String message, String details) {
ErrorDialog dialog = new ErrorDialog(message, details, null);
UserPreferences.setLocationRelativeToDefaultFrame(dialog);
dialog.setVisible(true);
}
private void dialogVisible(String message, String details1, StackTraceElement[] details2) {
dialogVisible(message, details1);
// creation of details
String det = details1 + Files.NEWLINE + Files.NEWLINE;
for (int i = 0; i < details2.length; i++) {
det += details2[i].toString() + Files.NEWLINE;
}
// change the text
this.jTextArea1.setText(det);
}
private void dialogVisible(String message, String details) {
// change the text
this.jTextArea2.setText(message);
this.jTextArea2.setCaretPosition(0);
this.jTextArea1.setText(details);
// display without the details
this.hideDetails();
}
private void displayDetails() {
// if the details are not hidden
if (this.details == false) {
// modifie les elements de la boite de dialogue
this.jButton3.setText("Details <<");
this.jButton3.setToolTipText("Hide details");
// show the dialog box
jLabel2.setVisible(true);
jScrollPane1.setVisible(true);
jTextArea1.setVisible(true);
this.validate();
this.pack();
// change the state
this.details = true;
}
}
private void hideDetails() {
// if the details are not hidden
if (this.details == true) {
// modify the elements of the dialog box
this.jButton3.setText("Details >>");
this.jButton3.setToolTipText("Display details");
// put off the details
jLabel2.setVisible(false);
jScrollPane1.setVisible(false);
jTextArea1.setVisible(false);
// modifie la boite de dialogue
this.validate();
this.pack();
// change the state
this.details = false;
}
}
private void saveError() throws IOException {
GenericFileChooser fc = UserPreferences.getDefaultFileChooser();
fc.setFilterTXT();
if (fc.showSaveDialog(this) == GenericFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
file = fc.getFileWithExtension(file, GenericFileChooser.ExtensionTXT);
if (!fc.recordFile(this, file)) {
return;
}
FlowWrite flow = null;
try {
flow = new FlowWrite(file);
flow.write(jTextArea1.getText());
} finally {
flow.close();
}
}
}
@Override
public void actionPerformed(ActionEvent evt) {
// close button
if (evt.getActionCommand().equals("close")) {
this.dispose();
}
// save button
if (evt.getActionCommand().equals("saveError")) {
try {
saveError();
} catch (IOException ex) {
ExceptionSending.display(ex);
}
}
// details button
if (evt.getActionCommand().equals("details")) {
if (this.details == true) {
this.hideDetails();
} else {
this.displayDetails();
}
}
}
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Error");
setModal(true);
jLabel1.setIcon(UIManager.getIcon("OptionPane.errorIcon"));
jLabel1.setName("jLabel1"); // NOI18N
jButton2.setText("Save Error");
jButton2.setToolTipText("Save the error for degugging");
jButton2.setActionCommand("saveError");
jButton2.setMargin(new java.awt.Insets(1, 7, 1, 7));
jButton2.setName("jButton2"); // NOI18N
jButton3.setText("Details >>");
jButton3.setToolTipText("Display details");
jButton3.setActionCommand("details");
jButton3.setMargin(new java.awt.Insets(1, 7, 1, 7));
jButton3.setName("jButton3"); // NOI18N
jLabel2.setText("Error details:");
jLabel2.setName("jLabel2"); // NOI18N
jScrollPane1.setName("jScrollPane1"); // NOI18N
jTextArea1.setColumns(20);
jTextArea1.setForeground(new java.awt.Color(255, 0, 0));
jTextArea1.setRows(5);
jTextArea1.setName("jTextArea1"); // NOI18N
jScrollPane1.setViewportView(jTextArea1);
jButton1.setText("Close");
jButton1.setToolTipText("Close the window");
jButton1.setActionCommand("close");
jButton1.setName("jButton1"); // NOI18N
jScrollPane2.setBackground(java.awt.SystemColor.window);
jScrollPane2.setBorder(null);
jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane2.setName("jScrollPane2"); // NOI18N
jScrollPane2.setOpaque(false);
jTextArea2.setBackground(java.awt.SystemColor.window);
jTextArea2.setColumns(20);
jTextArea2.setEditable(false);
jTextArea2.setLineWrap(true);
jTextArea2.setRows(5);
jTextArea2.setWrapStyleWord(true);
jTextArea2.setBorder(null);
jTextArea2.setName("jTextArea2"); // NOI18N
jTextArea2.setOpaque(false);
jScrollPane2.setViewportView(jTextArea2);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE))
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3))
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jButton2, jButton3});
}
// Variables declaration
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
// End of variables declaration
} |
Partager