📄 gplogconsole.java
字号:
this.add(jMenuItemSaveToFile);
this.add(jMenuItemSendEmail);
jMenuItemClearWindow
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
clearWindow();
}
});
jMenuItemSaveToFile
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
saveWindowToFile();
}
});
jMenuItemSendEmail
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
String email = Translator.getString("Error.EmailTechSupportAddress");
String subj = "?subject=runtime error message&body=";
String msg = null;
try {
// UTF8 is not exactly to spec for mailto: encoding
// but it will work. only alternative is attaching
// the javamail package at ~1.5Mb
msg = URLEncoder.encode(currentWindow.getText(), "UTF-8");
}
catch (java.io.UnsupportedEncodingException ue){
System.out.println(ue);
}
try {
BrowserLauncher.openURL("mailto:"+email+subj+msg);
}
catch (IOException ioe){
System.out.println(ioe);
}
}
});
//jMenuItemSaveToFile.setEnabled(false);//.disable();
}
/** Sets the current text area
*
*/
public void setTextArea(JTextArea ta) {
currentWindow = ta;
}
/** clears the window
*/
private void clearWindow() {
currentWindow.setText("");
}
/** Shows a file chooser and saves the
* file to the selected name
*/
private void saveWindowToFile() {
JFileChooser fileDlg = new JFileChooser();
//fileDlg.setFileFilter(filter);
// no file selected.
if (JFileChooser.APPROVE_OPTION != fileDlg.showSaveDialog(null)) {
System.out.println("No file selected"/*#Frozen*/);
return;
}
File f = fileDlg.getSelectedFile();
if (!f.canWrite())
System.err.println("Can't write to file " + f.getAbsolutePath()/*#Frozen*/);
try {
PrintStream os = new PrintStream(new FileOutputStream(f));
os.println(currentWindow.getText());
os.close();
clearWindow();
} catch (FileNotFoundException e) {
System.err.println("Can't write to file " + f.getAbsolutePath()/*#Frozen*/);
}
}
}
/**A PrintStream for the text area output.
*
* @author Sven Luzar
* */
class JTextAreaOutputStream extends PrintStream {
/** the target for this printstream
*/
private JTextArea target = null;
/** the original PrintStream to forward this
* stream to the original stream
*/
private PrintStream orig = null;
/** Flag is true if the stream should forward
* the output to the original stream
*
*/
private boolean showOrig = false;
/**creates an instance
*
*/
public JTextAreaOutputStream(
JTextArea t,
PrintStream orig,
boolean showOrig) {
super(new ByteArrayOutputStream());
target = t;
this.showOrig = showOrig;
this.orig = orig;
}
/** writes a boolean value to the target
*/
public void print(boolean b) {
if (showOrig)
orig.print(b);
if (b)
target.append("true"/*#Frozen*/);
else
target.append("false"/*#Frozen*/);
target.setCaretPosition(target.getText().length());
}
/** writes a boolean value to the target
*
*/
public void println(boolean b) {
if (showOrig)
orig.println(b);
if (b)
target.append("true\n"/*#Frozen*/);
else
target.append("false\n"/*#Frozen*/);
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void print(char c) {
if (showOrig)
orig.print(c);
char[] tmp = new char[1];
tmp[0] = c;
target.append(new String(tmp));
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void println(char c) {
if (showOrig)
orig.println(c);
char[] tmp = new char[2];
tmp[0] = c;
tmp[1] = '\n';
target.append(new String(tmp));
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void print(char[] s) {
if (showOrig)
orig.print(s);
target.append(new String(s));
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void println(char[] s) {
if (showOrig)
orig.println(s);
target.append(new String(s) + "\n"/*#Frozen*/);
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void print(double d) {
if (showOrig)
orig.print(d);
target.append(Double.toString(d));
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void println(double d) {
if (showOrig)
orig.println(d);
target.append(Double.toString(d) + "\n"/*#Frozen*/);
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void print(float f) {
if (showOrig)
orig.print(f);
target.append(Float.toString(f));
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void println(float f) {
if (showOrig)
orig.println(f);
target.append(Float.toString(f) + "\n"/*#Frozen*/);
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void print(int i) {
if (showOrig)
orig.print(i);
target.append(Integer.toString(i));
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void println(int i) {
if (showOrig)
orig.println(i);
target.append(Integer.toString(i) + "\n"/*#Frozen*/);
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void print(long l) {
if (showOrig)
orig.print(l);
target.append(Long.toString(l));
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void println(long l) {
if (showOrig)
orig.println(l);
target.append(Long.toString(l) + "\n"/*#Frozen*/);
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void print(Object o) {
if (showOrig)
orig.print(o);
target.append(o.toString());
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void println(Object o) {
if (showOrig)
orig.println(o);
target.append(o.toString() + "\n"/*#Frozen*/);
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void print(String s) {
if (showOrig)
orig.print(s);
target.append(s);
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void println(String s) {
if (showOrig)
orig.println(s);
target.append(s + "\n"/*#Frozen*/);
target.setCaretPosition(target.getText().length());
}
/** writes the value to the target
*
*/
public void println() {
if (showOrig)
orig.println();
target.append(new String("\n"/*#Frozen*/));
target.setCaretPosition(target.getText().length());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -