/* Copyright (c) 2009 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.. */ /* * errorgui.java * * Created on Jun 28, 2010, 11:31:12 AM */ package org.clothocad.widget.errorreporter; import java.awt.Color; import java.awt.Dimension; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.security.Security; import javax.mail.MessagingException; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.SwingUtilities; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.MutableAttributeSet; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; import org.clothocore.api.core.Collector; import org.clothocore.util.basic.ImageSource; /** * * @author J. Christopher Anderson */ public class errorgui extends javax.swing.JFrame { /** Creates new form errorgui */ public errorgui() { super("Error Reporter"); this.setIconImage(ImageSource.getTinyLogo()); initComponents(); setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE); redirectSystemStreams(); } /** 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() { jScrollPane1 = new javax.swing.JScrollPane(); textPane = new javax.swing.JTextPane(); sendBug = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jScrollPane1.setViewportView(textPane); sendBug.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/clothocad/widget/errorreporter/gmail-logo.png"))); // NOI18N sendBug.setText("Send Bug"); sendBug.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sendBugActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE) .addComponent(sendBug)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(sendBug) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void sendBugActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendBugActionPerformed String reportingtext = textPane.getText();; Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); String emailFromAddress =null; if(Collector.isConnected()) { emailFromAddress = Collector.getCurrentUser().getEmailAddress(); } //Find out what tool they were using String plugin = JOptionPane.showInputDialog( "What plugin were you using when you saw the error?" ); //Throw up a dialog to get description of what doing Object[] params = new Object[2]; JScrollPane scroller = new JScrollPane(); JTextArea jta = new JTextArea(); scroller.setViewportView(jta); scroller.setPreferredSize(new Dimension(200,200)); params[1] = scroller; String message = "Describe what you were doing when you saw the error, and describe the error"; params[0] = message; int n = JOptionPane.showConfirmDialog(null, params, "Save objects before quiting", JOptionPane.OK_CANCEL_OPTION); if(n!=0) { return; } String emailMsgTxt = jta.getText(); emailMsgTxt += "\n\n____________________\n"; emailMsgTxt += reportingtext; if(emailFromAddress==null) { emailFromAddress = JOptionPane.showInputDialog( "What is your gmail address?" ); } if(emailFromAddress.indexOf("@gmail.com")==-1) { emailFromAddress = JOptionPane.showInputDialog( "I need a gmail address...try again" ); if(emailFromAddress.indexOf("@gmail.com")==-1) { return; } } try { new sendmail().sendSSLMessage(new String[]{"clothobugs@googlegroups.com"}, "Bug identified in " + plugin, emailMsgTxt, emailFromAddress); System.out.println("It worked!"); } catch (MessagingException ex) { System.out.println("It failed"); } }//GEN-LAST:event_sendBugActionPerformed private void updateTextPane(final String text, final boolean isErr) { SwingUtilities.invokeLater(new Runnable() { public void run() { Document doc = textPane.getDocument(); MutableAttributeSet maset = new SimpleAttributeSet(); try { int startpos = doc.getLength(); int tlength = text.length(); doc.insertString(doc.getLength(), text, null); StyledDocument d = textPane.getStyledDocument(); StyleConstants.setForeground(maset, Color.black); if(isErr) { StyleConstants.setForeground(maset, Color.red); } d.setCharacterAttributes(startpos, tlength, maset, false); } catch (BadLocationException e) { throw new RuntimeException(e); } textPane.setCaretPosition(doc.getLength() - 1); } }); } private void redirectSystemStreams() { OutputStream out = new OutputStream() { @Override public void write(final int b) throws IOException { updateTextPane(String.valueOf((char) b),false); } @Override public void write(byte[] b, int off, int len) throws IOException { updateTextPane(new String(b, off, len), false); } @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); } }; OutputStream err = new OutputStream() { @Override public void write(final int b) throws IOException { updateTextPane(String.valueOf((char) b),true); } @Override public void write(byte[] b, int off, int len) throws IOException { updateTextPane(new String(b, off, len), true); } @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); } }; System.setOut(new PrintStream(out, true)); System.setErr(new PrintStream(err, true)); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new errorgui().setVisible(true); System.out.println("Did it work?"); String[] bob = new String[5]; System.out.println(bob[7]); } }); } /**----------------- variables -----------------*/ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane jScrollPane1; private javax.swing.JButton sendBug; private javax.swing.JTextPane textPane; // End of variables declaration//GEN-END:variables }