| 1 | |
package net.sf.jabref; |
| 2 | |
|
| 3 | |
import java.awt.Component; |
| 4 | |
import java.awt.Dimension; |
| 5 | |
import java.io.PrintWriter; |
| 6 | |
import java.io.StringWriter; |
| 7 | |
import java.lang.reflect.InvocationTargetException; |
| 8 | |
import java.lang.reflect.Method; |
| 9 | |
|
| 10 | |
import javax.swing.BorderFactory; |
| 11 | |
import javax.swing.JEditorPane; |
| 12 | |
import javax.swing.JOptionPane; |
| 13 | |
import javax.swing.JScrollPane; |
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
public class JabRefMain { |
| 28 | |
|
| 29 | |
public static String exceptionToString(Throwable t){ |
| 30 | |
StringWriter stackTraceWriter = new StringWriter(); |
| 31 | |
t.printStackTrace(new PrintWriter(stackTraceWriter)); |
| 32 | |
return stackTraceWriter.toString(); |
| 33 | |
} |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public static void main(String[] args) { |
| 40 | |
|
| 41 | |
String javaVersion = System.getProperty("java.version", null); |
| 42 | |
|
| 43 | |
if (javaVersion.compareTo("1.5") < 0) { |
| 44 | |
String javaVersionWarning = "\n" + |
| 45 | |
"WARNING: You are running Java version 1.4 or lower (" + javaVersion + " to be exact).\n" + |
| 46 | |
" JabRef needs at least a Java Runtime Environment 1.5 or higher.\n" + |
| 47 | |
" JabRef should not start properly and output an error message\n" + |
| 48 | |
" (probably java.lang.UnsupportedClassVersionError ... (Unsupported major.minor version 49.0)\n" + |
| 49 | |
" See http://jabref.sf.net/faq.php for more information.\n"; |
| 50 | |
|
| 51 | |
System.out.println(javaVersionWarning); |
| 52 | |
} |
| 53 | |
|
| 54 | |
String javaVendor = System.getProperty("java.vendor", null); |
| 55 | |
if (javaVendor.indexOf("Sun Microsystems") == -1) { |
| 56 | |
System.out.println("\n" + |
| 57 | |
"WARNING: You are not running a Java version from Sun Microsystems.\n" + |
| 58 | |
" Your java vendor is: " + javaVendor + "\n" + |
| 59 | |
" If JabRef crashes please consider switching to a Sun Java Runtime.\n" + |
| 60 | |
" See http://jabref.sf.net/faq.php for more information.\n"); |
| 61 | |
} |
| 62 | |
|
| 63 | |
try { |
| 64 | |
|
| 65 | |
|
| 66 | |
Method method = Class.forName("net.sf.jabref.JabRef").getMethod( |
| 67 | |
"main", new Class[] { args.getClass() }); |
| 68 | |
method.invoke(null, new Object[] { args }); |
| 69 | |
|
| 70 | |
} catch (InvocationTargetException e) { |
| 71 | |
|
| 72 | |
String errorMessage = |
| 73 | |
"\nERROR while starting or running JabRef:\n\n" + |
| 74 | |
exceptionToString(e.getCause()) + "\n" + |
| 75 | |
"Please first check if this problem and a solution is already known. Find our...\n" + |
| 76 | |
" * ...FAQ at http://jabref.sf.net/faq.php and our...\n" + |
| 77 | |
" * ...user mailing-list at http://sf.net/mailarchive/forum.php?forum_name=jabref-users\n\n" + |
| 78 | |
"If you do not find a solution there, please let us know about the problem by writing a bug report.\n" + |
| 79 | |
"You can find our bug tracker at http://sourceforge.net/tracker/?atid=600306&group_id=92314\n\n" + |
| 80 | |
" * If the bug has already been reported there, please add your comments to the existing bug.\n" + |
| 81 | |
" * If the bug has not been reported yet, then we need the complete error message given above\n" + |
| 82 | |
" and a description of what you did before the error occured.\n\n" + |
| 83 | |
"We also need the following information (you can copy and paste all this):\n" + |
| 84 | |
" * Java Version: " + javaVersion + "\n" + |
| 85 | |
" * Java Vendor: " + javaVendor + "\n" + |
| 86 | |
" * Operating System: " + System.getProperty("os.name") + " (" + System.getProperty("os.version") + ")\n" + |
| 87 | |
" * Hardware Architecture: " + System.getProperty("os.arch") + "\n\n" + |
| 88 | |
"We are sorry for the trouble and thanks for reporting problems with JabRef!\n"; |
| 89 | |
|
| 90 | |
System.out.println(errorMessage); |
| 91 | |
|
| 92 | |
JEditorPane pane = new JEditorPane("text/html", |
| 93 | |
"<html>The following error occurred while running JabRef:<p><font color=\"red\">" + |
| 94 | |
exceptionToString(e.getCause()).replaceAll("\\n", "<br>") + |
| 95 | |
"</font></p>" + |
| 96 | |
"<p>Please first check if this problem and a solution is already known. Find our...</p>" + |
| 97 | |
"<ul><li>...FAQ at <b>http://jabref.sf.net/faq.php</b> and our..." + |
| 98 | |
"<li>...user mailing-list at <b>http://sf.net/mailarchive/forum.php?forum_name=jabref-users</b></ul>" + |
| 99 | |
"If you do not find a solution there, please let us know about the problem by writing a bug report.<br>" + |
| 100 | |
"You can find our bug tracker at <b>http://sourceforge.net/tracker/?atid=600306&group_id=92314</b>.<br>" + |
| 101 | |
"<ul><li>If the bug has already been reported there, please add your comments to the existing bug.<br>" + |
| 102 | |
"<li>If the bug has not been reported yet, then we need the complete error message given above<br>" + |
| 103 | |
"and a description of what you did before the error occured.</ul>" + |
| 104 | |
"We also need the following information (you can copy and paste all this):</p>" + |
| 105 | |
"<ul><li>Java Version: " + javaVersion + |
| 106 | |
"<li>Java Vendor: " + javaVendor + |
| 107 | |
"<li>Operating System: " + System.getProperty("os.name") + " (" + System.getProperty("os.version") + ")" + |
| 108 | |
"<li>Hardware Architecture: " + System.getProperty("os.arch") + "</ul>" + |
| 109 | |
"We are sorry for the trouble and thanks for reporting problems with JabRef!</html>"); |
| 110 | |
pane.setEditable(false); |
| 111 | |
pane.setOpaque(false); |
| 112 | |
pane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); |
| 113 | |
|
| 114 | |
Component componentToDisplay; |
| 115 | |
if (pane.getPreferredSize().getHeight() > 700){ |
| 116 | |
JScrollPane sPane = new JScrollPane(pane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
| 117 | |
sPane.setBorder(BorderFactory.createEmptyBorder()); |
| 118 | |
sPane.setPreferredSize(new Dimension((int)pane.getPreferredSize().getWidth() + 30, 700)); |
| 119 | |
componentToDisplay = sPane; |
| 120 | |
} else { |
| 121 | |
componentToDisplay = pane; |
| 122 | |
} |
| 123 | |
|
| 124 | |
JOptionPane.showMessageDialog(null, componentToDisplay, "An error occurred while running JabRef", JOptionPane.ERROR_MESSAGE); |
| 125 | |
} catch (SecurityException e) { |
| 126 | |
System.out.println("ERROR: You are running JabRef in a sandboxed" |
| 127 | |
+ " environment that does not allow it to be started."); |
| 128 | |
e.printStackTrace(); |
| 129 | |
} catch (NoSuchMethodException e) { |
| 130 | |
System.out |
| 131 | |
.println("This error should not happen." |
| 132 | |
+ " Write an email to the JabRef developers and tell them 'NoSuchMethodException in JabRefMain'"); |
| 133 | |
} catch (ClassNotFoundException e) { |
| 134 | |
System.out |
| 135 | |
.println("This error should not happen." |
| 136 | |
+ " Write an email to the JabRef developers and tell them 'ClassNotFoundException in JabRefMain'"); |
| 137 | |
} catch (IllegalArgumentException e) { |
| 138 | |
System.out |
| 139 | |
.println("This error should not happen." |
| 140 | |
+ " Write an email to the JabRef developers and tell them 'IllegalArgumentException in JabRefMain'"); |
| 141 | |
} catch (IllegalAccessException e) { |
| 142 | |
System.out |
| 143 | |
.println("This error should not happen." |
| 144 | |
+ " Write an email to the JabRef developers and tell them 'IllegalAccessException in JabRefMain'"); |
| 145 | |
} catch (UnsupportedClassVersionError e){ |
| 146 | |
|
| 147 | |
String errorMessage = |
| 148 | |
exceptionToString(e) + "\n" + |
| 149 | |
"This means that your Java version (" + javaVersion + ") is not high enough to run JabRef.\n" + |
| 150 | |
"Please update your Java Runtime Environment to a version 1.5 or higher.\n"; |
| 151 | |
|
| 152 | |
System.out.println(errorMessage); |
| 153 | |
|
| 154 | |
JEditorPane pane = new JEditorPane("text/html", |
| 155 | |
"<html>You are using Java version " + javaVersion + ", but JabRef needs version 1.5 or higher." + |
| 156 | |
"<p>Please update your Java Runtime Environment.</p>" + |
| 157 | |
"<p>For more information visit <b>http://jabref.sf.net/faq.php</b>.</p></html>"); |
| 158 | |
pane.setEditable(false); |
| 159 | |
pane.setOpaque(false); |
| 160 | |
pane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); |
| 161 | |
|
| 162 | |
JOptionPane.showMessageDialog(null, pane, "Insufficient Java Version Installed", JOptionPane.ERROR_MESSAGE); |
| 163 | |
} |
| 164 | |
} |
| 165 | |
} |