[Jrisk-cvs] SF.net SVN: jrisk:[446] Grasshopper
Brought to you by:
yuranet
|
From: <yu...@us...> - 2010-09-21 16:35:15
|
Revision: 446
http://jrisk.svn.sourceforge.net/jrisk/?rev=446&view=rev
Author: yuranet
Date: 2010-09-21 16:35:08 +0000 (Tue, 21 Sep 2010)
Log Message:
-----------
more bug stuff
Modified Paths:
--------------
Grasshopper/src/net/yura/grasshopper/BugSubmitter.java
Grasshopper/src/net/yura/grasshopper/SimpleBug.java
Grasshopper/src/net/yura/grasshopper/SimplePrintStream.java
Added Paths:
-----------
Grasshopper/src/net/yura/grasshopper/BugSystemInfo.java
Grasshopper/src/net/yura/grasshopper/PopupBug.java
Removed Paths:
-------------
Grasshopper/src/net/yura/grasshopper/PopupStringWriter.java
Property Changed:
----------------
Grasshopper/nbproject/
Property changes on: Grasshopper/nbproject
___________________________________________________________________
Added: svn:ignore
+ private
Modified: Grasshopper/src/net/yura/grasshopper/BugSubmitter.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/BugSubmitter.java 2010-09-21 14:47:52 UTC (rev 445)
+++ Grasshopper/src/net/yura/grasshopper/BugSubmitter.java 2010-09-21 16:35:08 UTC (rev 446)
@@ -42,42 +42,14 @@
}
+ static void submitBug(String toString) {
- public static String getSysInfo() {
+ System.out.println("submitting:\n"+toString);
+ }
- String systemLocale,localhost,systemProperties,lookandfeel;
-
- try {
- systemLocale = java.util.Locale.getDefault().toString();
- }
- catch (Throwable th) {
- systemLocale = th.toString();
- }
-
- try {
- localhost = java.net.InetAddress.getLocalHost().toString();
- }
- catch (Throwable e) {
- localhost = e.toString();
- }
-
- try {
- systemProperties = System.getProperties().toString();
- }
- catch (Throwable e) {
- systemProperties = e.toString();
- }
-
- try {
- lookandfeel = javax.swing.UIManager.getLookAndFeel().toString();
- }
- catch(Throwable th) {
- lookandfeel = th.toString();
- }
-
- return null;
-
+ static void submitBug(String text, String email) {
+ System.out.println("submitting: "+email+"\n"+text);
}
Added: Grasshopper/src/net/yura/grasshopper/BugSystemInfo.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/BugSystemInfo.java (rev 0)
+++ Grasshopper/src/net/yura/grasshopper/BugSystemInfo.java 2010-09-21 16:35:08 UTC (rev 446)
@@ -0,0 +1,57 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.yura.grasshopper;
+
+/**
+ *
+ * @author Administrator
+ */
+public class BugSystemInfo {
+
+ public static String appName,version,locale;
+
+
+
+
+ public static String getSysInfo() {
+
+
+ String systemLocale,localhost,systemProperties,lookandfeel;
+
+ try {
+ systemLocale = java.util.Locale.getDefault().toString();
+ }
+ catch (Throwable th) {
+ systemLocale = th.toString();
+ }
+
+ try {
+ localhost = java.net.InetAddress.getLocalHost().toString();
+ }
+ catch (Throwable e) {
+ localhost = e.toString();
+ }
+
+ try {
+ systemProperties = System.getProperties().toString();
+ }
+ catch (Throwable e) {
+ systemProperties = e.toString();
+ }
+
+ try {
+ lookandfeel = javax.swing.UIManager.getLookAndFeel().toString();
+ }
+ catch(Throwable th) {
+ lookandfeel = th.toString();
+ }
+
+ return null;
+
+ }
+
+
+}
Copied: Grasshopper/src/net/yura/grasshopper/PopupBug.java (from rev 445, Grasshopper/src/net/yura/grasshopper/PopupStringWriter.java)
===================================================================
--- Grasshopper/src/net/yura/grasshopper/PopupBug.java (rev 0)
+++ Grasshopper/src/net/yura/grasshopper/PopupBug.java 2010-09-21 16:35:08 UTC (rev 446)
@@ -0,0 +1,185 @@
+package net.yura.grasshopper;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowEvent;
+import java.io.IOException;
+import java.io.Writer;
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+
+/**
+ * @author Yura Mamyrin
+ */
+public class PopupBug extends Writer {
+
+ static Object instance;
+
+ private JFrame errFrame;
+ private JTextArea debugText;
+
+ private PopupBug() {
+
+ debugText = new JTextArea();
+
+ SimplePrintStream.interceptAndAlert(this, new SimplePrintStream() {
+ void action() {
+ action2();
+ }
+ });
+
+ instance = this;
+ }
+
+
+ public static void initSimple(String appname,String version,String locale) {
+ if (instance==null) {
+ new PopupBug();
+ }
+
+ BugSystemInfo.appName = appname;
+ BugSystemInfo.version = version;
+ BugSystemInfo.locale = locale;
+ }
+
+ private void action2() {
+
+ // only create all this stuff if an error has happened
+ if (errFrame==null) {
+
+ errFrame = new JFrame("an error has occurred!!!");
+
+ errFrame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
+
+ errFrame.addWindowListener(new java.awt.event.WindowAdapter() {
+ public void windowClosing(WindowEvent winEvt) {
+
+ doSubmit("closed");
+
+ errFrame.setVisible(false);
+
+ }
+ });
+
+ debugText.setEditable(false);
+
+ JScrollPane errScroll = new JScrollPane(debugText);
+
+ Dimension size = new Dimension(400,400);
+
+ errScroll.setMaximumSize(size);
+ errScroll.setPreferredSize(size);
+ errScroll.setMinimumSize(size);
+
+ JLabel label = new JLabel("an error happened, please click on the button at the bottom to send it");
+ label.setBorder( BorderFactory.createMatteBorder(10,10,10,10,Color.RED) );
+
+ JButton saveErr = new JButton("click here to send");
+
+ saveErr.addActionListener(
+ new ActionListener() {
+ public void actionPerformed(ActionEvent a) {
+ String email = JOptionPane.showInputDialog(errFrame,"tell me your e-mail please, in case i have questons about this bug");
+ if (email == null) { email ="not-given"; }
+ try {
+ doSubmit(email);
+ JOptionPane.showMessageDialog(errFrame, "SENT!");
+ }
+ catch(Exception ex) {
+ JOptionPane.showMessageDialog(errFrame, "ERROR: "+ex.getMessage() );
+ }
+ errFrame.setVisible(false);
+ }
+ }
+ );
+
+ errFrame.getContentPane().add( label , BorderLayout.NORTH );
+ errFrame.getContentPane().add( errScroll , BorderLayout.CENTER);
+ errFrame.getContentPane().add( saveErr , BorderLayout.SOUTH);
+
+ errFrame.pack();
+
+ String n = System.getProperty("line.separator");
+ debugText.append(n+n+"Date: "+new java.util.Date().toString()+n+n+n);
+
+ }
+
+ errFrame.setVisible(true);
+ }
+
+ private void doSubmit(String email) {
+
+ BugSubmitter.submitBug(debugText.getText(),email);
+ }
+
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ debugText.append(String.valueOf(cbuf, off, len));
+ }
+
+ public void flush() throws IOException {
+ }
+
+ public void close() throws IOException {
+ }
+
+ public static void main(String[] args) {
+
+ initSimple("Test", "1.0", "en");
+
+ //System.setOut( new PrintStream( new FileOutputStream(FileDescriptor.out) ) );
+
+ System.out.println("hello world! 2");
+
+ throw new RuntimeException("how could this happen");
+
+ }
+
+/*
+
+ JFileChooser fc = new JFileChooser();
+ RiskFileFilter filter = new RiskFileFilter(RiskFileFilter.RISK_LOG_FILES);
+ fc.setFileFilter(filter);
+
+ int returnVal = fc.showSaveDialog(errFrame);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ java.io.File file = fc.getSelectedFile();
+ // Write your code here what to do with selected file
+
+ String fileName = file.getAbsolutePath();
+
+ if (!(fileName.endsWith( "." + RiskFileFilter.RISK_LOG_FILES ))) {
+ fileName = fileName + "." + RiskFileFilter.RISK_LOG_FILES;
+ }
+
+ try {
+
+ FileWriter fileout = new FileWriter(fileName);
+ BufferedWriter buffer = new BufferedWriter(fileout);
+ PrintWriter printer = new PrintWriter(buffer);
+
+ printer.write(debugText.getText());
+
+ printer.close();
+
+ }
+
+ catch(Exception error) {
+ JOptionPane.showMessageDialog(errFrame, "unable to save file: " + error.getMessage(), "save error", JOptionPane.ERROR_MESSAGE);
+ }
+
+ } else {
+ // Write your code here what to do if user has canceled Save dialog
+ }
+
+
+*/
+
+}
Deleted: Grasshopper/src/net/yura/grasshopper/PopupStringWriter.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/PopupStringWriter.java 2010-09-21 14:47:52 UTC (rev 445)
+++ Grasshopper/src/net/yura/grasshopper/PopupStringWriter.java 2010-09-21 16:35:08 UTC (rev 446)
@@ -1,138 +0,0 @@
-package net.yura.grasshopper;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.StringWriter;
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
-
-/**
- * @author Yura Mamyrin
- */
-public class PopupStringWriter extends StringWriter {
-
- private JFrame errFrame;
- private JTextArea debugText;
-
- public PopupStringWriter() {
-
- debugText = new JTextArea();
-
- }
-
- public void write(String x) {
-
- // only create all this stuff if an error has happened
- if (errFrame==null) {
-
- errFrame = new JFrame("an error has occurred!!!");
-
- errFrame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
-
- debugText.setEditable(false);
-
- JScrollPane errScroll = new JScrollPane(debugText);
-
- Dimension size = new Dimension(400,400);
-
- errScroll.setMaximumSize(size);
- errScroll.setPreferredSize(size);
- errScroll.setMinimumSize(size);
-
- JLabel label = new JLabel("an error happened, please send it to yu...@yu...");
- label.setBorder( BorderFactory.createMatteBorder(10,10,10,10,Color.RED) );
-
- JButton saveErr = new JButton("click here to send");
-
- saveErr.addActionListener(
- new ActionListener() {
- public void actionPerformed(ActionEvent a) {
-
- String email = JOptionPane.showInputDialog(errFrame,"tell me your e-mail please");
-
- if (email == null) { email ="none"; }
-
- try {
-
- // TODO RiskUIUtil.sendText(email , debugText.getText(), "FlashGUI Bug");
-
- JOptionPane.showMessageDialog(errFrame, "SENT!");
-
-
- }
- catch(Exception ex) {
-
- JOptionPane.showMessageDialog(errFrame, "ERROR: "+ex.getMessage() );
-
- }
-
-/*
-
- JFileChooser fc = new JFileChooser();
- RiskFileFilter filter = new RiskFileFilter(RiskFileFilter.RISK_LOG_FILES);
- fc.setFileFilter(filter);
-
- int returnVal = fc.showSaveDialog(errFrame);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- java.io.File file = fc.getSelectedFile();
- // Write your code here what to do with selected file
-
- String fileName = file.getAbsolutePath();
-
- if (!(fileName.endsWith( "." + RiskFileFilter.RISK_LOG_FILES ))) {
- fileName = fileName + "." + RiskFileFilter.RISK_LOG_FILES;
- }
-
- try {
-
- FileWriter fileout = new FileWriter(fileName);
- BufferedWriter buffer = new BufferedWriter(fileout);
- PrintWriter printer = new PrintWriter(buffer);
-
- printer.write(debugText.getText());
-
- printer.close();
-
- }
-
- catch(Exception error) {
- JOptionPane.showMessageDialog(errFrame, "unable to save file: " + error.getMessage(), "save error", JOptionPane.ERROR_MESSAGE);
- }
-
- } else {
- // Write your code here what to do if user has canceled Save dialog
- }
-
-
-*/
-
-
- }
- }
- );
-
- errFrame.getContentPane().add( label , BorderLayout.NORTH );
- errFrame.getContentPane().add( errScroll , BorderLayout.CENTER);
- errFrame.getContentPane().add( saveErr , BorderLayout.SOUTH);
-
- errFrame.pack();
-
- String n = System.getProperty("line.separator");
- debugText.append(n+n+"Date: "+new java.util.Date().toString()+n+n+n);
-
- errFrame.setVisible(true);
-
- }
-
- debugText.append(x);
-
- }
-}
Modified: Grasshopper/src/net/yura/grasshopper/SimpleBug.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/SimpleBug.java 2010-09-21 14:47:52 UTC (rev 445)
+++ Grasshopper/src/net/yura/grasshopper/SimpleBug.java 2010-09-21 16:35:08 UTC (rev 446)
@@ -1,68 +1,39 @@
package net.yura.grasshopper;
-import java.io.FileDescriptor;
import java.io.StringWriter;
-import java.io.Writer;
/**
* @author Yura
*/
-public class SimpleBug {
+public class SimpleBug extends StringWriter {
static SimpleBug instance;
- Writer out;
- Thread thread;
- String appName,version,locale;
-
public SimpleBug() {
if (instance!=null) return;
- out = new StringWriter();
-
- System.setOut( SimplePrintStream.getSimplePrintStream(out, FileDescriptor.out,null ) );
- System.setErr( SimplePrintStream.getSimplePrintStream(out, FileDescriptor.err,new SimplePrintStream() {
- @Override
+ SimplePrintStream.interceptAndAlert(this, new SimplePrintStream() {
void action() {
action2();
}
- } ) );
+ });
instance = this;
}
private void action2() {
-
- if (thread==null) {
- thread = new Thread() {
- public void run() {
- try {
- Thread.sleep(1000);
- }
- catch (Throwable ex) {
- }
- thread = null;
- try {
- BugSubmitter.submitBug(appName,version,locale,out.toString());
- }
- catch (Throwable ex) {
- }
- }
- };
- thread.start();
- }
-
+ BugSubmitter.submitBug(toString());
}
public static void initSimple(String appname,String version,String locale) {
if (instance==null) {
new SimpleBug();
}
- instance.appName = appname;
- instance.version = version;
- instance.locale = locale;
+ BugSystemInfo.appName = appname;
+ BugSystemInfo.version = version;
+ BugSystemInfo.locale = locale;
}
Modified: Grasshopper/src/net/yura/grasshopper/SimplePrintStream.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/SimplePrintStream.java 2010-09-21 14:47:52 UTC (rev 445)
+++ Grasshopper/src/net/yura/grasshopper/SimplePrintStream.java 2010-09-21 16:35:08 UTC (rev 446)
@@ -12,46 +12,67 @@
abstract void action();
+ public static void interceptAndAlert(final Writer a,final SimplePrintStream b) {
+ System.setOut( SimplePrintStream.getSimplePrintStream( a, FileDescriptor.out ,null) );
+ System.setErr( SimplePrintStream.getSimplePrintStream( a, FileDescriptor.err , b ) );
+ }
+
public static PrintStream getSimplePrintStream(final Writer sw) {
+ return getSimplePrintStream(sw, null, null);
+ }
+
+ private static PrintStream getSimplePrintStream(final Writer sw,final FileDescriptor b, final SimplePrintStream ac) {
+
+ final OutputStream file = b==null?null:new FileOutputStream(b);
+
return new PrintStream(new OutputStream() {
private ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
- public void write(byte[] b) throws IOException {
- outputStream.write(b);
+ public void write(byte[] bi) throws IOException {
+ if (file!=null) file.write(bi);
+ outputStream.write(bi);
}
- public void write(byte[] b, int off, int len) {
- outputStream.write(b, off, len);
+ public void write(byte[] bi, int off, int len) throws IOException {
+ if (file!=null) file.write(bi, off, len);
+ outputStream.write(bi, off, len);
}
- public void write(int b) {
- outputStream.write(b);
+ public void write(int bi) throws IOException {
+ if (file!=null) file.write(bi);
+ outputStream.write(bi);
}
public void flush() throws IOException {
- super.flush();
+ if (file!=null) file.flush();
sw.write( outputStream.toString() );
outputStream.reset();
+ if (ac!=null) action(ac);
}
+ public void close() throws IOException {
+ if (file!=null) file.close();
+ }
}, true );
}
- public static PrintStream getSimplePrintStream(final Writer sw,FileDescriptor b, final SimplePrintStream ac) {
- return new PrintStream(new FileOutputStream(b) {
- private ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
- public void write(byte[] b) throws IOException {
- super.write(b); // !!!!!! we are assumeing that FileOutputStream has been properly implemented and will not call back on write(int b) !!!!!!!
- outputStream.write(b);
+
+ private static Thread thread;
+ private static void action(final SimplePrintStream ac) {
+
+ if (thread==null) {
+ thread = new Thread() {
+ public void run() {
+ try {
+ Thread.sleep(1000);
}
- public void write(byte[] b, int off, int len) throws IOException {
- super.write(b, off, len);
- outputStream.write(b, off, len);
+ catch (Throwable ex) {
}
- public void write(int b) throws IOException {
- super.write(b);
- outputStream.write(b);
+ thread = null;
+ try {
+ ac.action();
}
- public void flush() throws IOException {
- super.flush();
- sw.write( outputStream.toString() );
- if (ac!=null) ac.action();
- outputStream.reset();
+ catch (Throwable ex) {
}
- }, true );
- }
+ }
+ };
+ thread.start();
+ }
+ }
+
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|