/*
* Copyright (C) 2014 Vinu K.N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.domainmath.gui.dialog;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
/**
*
* @author Vinu K.N
*/
public class ExceptionDialog extends javax.swing.JDialog {
/**
* Creates new form ExceptionDialog
*/
private String secondTitle;
private Exception exception;
public ExceptionDialog(JComponent parent, boolean modal,String secondTitle,Exception e) {
initComponents();
this.exception=e;
this.label.setText(secondTitle);
this.setSize(this.getWidth()+this.jTextArea1.getWidth(),
this.getHeight()+this.jTextArea1.getHeight());
setLocationRelativeTo(parent);
setModal(modal);
setIconImage(icon);
}
public ExceptionDialog(JComponent parent, boolean modal) {
initComponents();
this.label.setText(secondTitle);
this.setSize(this.getWidth()+this.jTextArea1.getWidth(),
this.getHeight()+this.jTextArea1.getHeight());
setLocationRelativeTo(parent);
setModal(modal);
setIconImage(icon);
}
public ExceptionDialog(JFrame parent,boolean modal) {
super(parent,modal);
initComponents();
this.setSize(this.getWidth()+this.jTextArea1.getWidth(),
this.getHeight()+this.jTextArea1.getHeight());
setLocationRelativeTo(null);
setModal(modal);
setIconImage(icon);
}
public ExceptionDialog(JComponent parent) {
initComponents();
this.label.setText(secondTitle);
this.setSize(this.getWidth()+this.jTextArea1.getWidth(),
this.getHeight()+this.jTextArea1.getHeight());
setLocationRelativeTo(parent);
setModal(true);
setIconImage(icon);
}
public ExceptionDialog(JFrame parent) {
super(parent,true);
initComponents();
this.setSize(this.getWidth()+this.jTextArea1.getWidth(),
this.getHeight()+this.jTextArea1.getHeight());
setLocationRelativeTo(null);
setModal(true);
setIconImage(icon);
}
public ExceptionDialog(JFrame parent, Exception exception) {
super(parent,true);
initComponents();
this.setSize(this.getWidth()+this.jTextArea1.getWidth(),
this.getHeight()+this.jTextArea1.getHeight());
setLocationRelativeTo(null);
setModal(true);
setIconImage(icon);
this.exception = exception;
StringWriter writer = new StringWriter();
exception.printStackTrace(new PrintWriter(writer));
this.jTextArea1.setText(writer.toString());
this.jTextArea1.setCaretPosition(0);
}
public ExceptionDialog(JFrame parent,String secondTitle, Exception exception) {
super(parent,true);
initComponents();
this.setSize(this.getWidth()+this.jTextArea1.getWidth(),
this.getHeight()+this.jTextArea1.getHeight());
setLocationRelativeTo(null);
setModal(true);
this.label.setText(secondTitle);
setIconImage(icon);
this.exception = exception;
StringWriter writer = new StringWriter();
exception.printStackTrace(new PrintWriter(writer));
this.jTextArea1.setText(writer.toString());
this.jTextArea1.setCaretPosition(0);
}
public ExceptionDialog(boolean modal) {
initComponents();
this.setSize(this.getWidth()+this.jTextArea1.getWidth(),
this.getHeight()+this.jTextArea1.getHeight());
setLocationRelativeTo(null);
setModal(modal);
setIconImage(icon);
}
public void addButton(JButton b){
this.buttonPanel.add(b);
this.buttonPanel.revalidate();
}
public String getSecondTitle() {
return secondTitle;
}
public void setSecondTitle(String secondTitle) {
this.secondTitle = secondTitle;
this.label.setText(secondTitle);
}
public Exception getException() {
return exception;
}
public void setException(Exception exception) {
this.exception = exception;
StringWriter writer = new StringWriter();
exception.printStackTrace(new PrintWriter(writer));
this.jTextArea1.setText(writer.toString());
this.jTextArea1.setCaretPosition(0);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
label = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
buttonPanel = new javax.swing.JPanel();
okButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(255, 102, 102));
label.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
label.setForeground(new java.awt.Color(255, 255, 255));
label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/domainmath/gui/dialogs/resources/appbar.close.png"))); // NOI18N
label.setText("Delete Test.m?");
label.setToolTipText("");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
jPanel2.setBackground(new java.awt.Color(255, 255, 255));
jLabel2.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
jLabel2.setText("More Information:");
jScrollPane1.setBorder(null);
jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setBorder(null);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addContainerGap(361, Short.MAX_VALUE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jScrollPane1)
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
.addContainerGap())
);
buttonPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 10, 5, 10));
buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
buttonPanel.add(okButton);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(0, 0, 0)
.addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
dispose();
}//GEN-LAST:event_okButtonActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
ExceptionDialog dialog = new ExceptionDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
}
});
}
public java.net.URL imgURL = getClass().getResource("/org/domainmath/gui/dialogs/resources/DomainMath.png");
public Image icon = Toolkit.getDefaultToolkit().getImage(imgURL);
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel buttonPanel;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JLabel label;
private javax.swing.JButton okButton;
// End of variables declaration//GEN-END:variables
}