corbamnqjta.java
来自「UCS (Ultra Corba Simulator) is one more 」· Java 代码 · 共 317 行
JAVA
317 行
package com.corba.mnq.ui;
import com.corba.mnq.main.MNQmainFrame;
import com.corba.mnq.ui.CorbaMNQReqLogger.OperationCannotBeLoggedException;
import javax.swing.JTextArea;
import javax.swing.text.Document;
import java.util.Date;
/**
* name: "CorbaMNQJTA"
*
* @author ucs_2008
*/
public class CorbaMNQJTA extends JTextArea {
private MNQmainFrame client;
private CorbaMNQReqLogger fileLogger;
/**
* This is one class constructor
*
* @param client
*/
public CorbaMNQJTA(MNQmainFrame client) {
super();
this.client = client;
fileLogger = new CorbaMNQReqLogger(client);
}
/**
* This is one class constructor
*
* @param rows
* @param columns
* @param client
*/
public CorbaMNQJTA(int rows, int columns, MNQmainFrame client) {
super(rows, columns);
this.client = client;
fileLogger = new CorbaMNQReqLogger(client);
}
/**
* Appends a line containing many '-------'.
*/
public void outSeparatorLine() {
String out = "-------------------------------------------------\n";
myAppend(out);
// Move the text insertion caret to the end of the text.
setCaretPosition(getText().length());
logToFile(out, false);
}
/**
* Appends the given text plus NewLine to the end of the document.
*
* @param str1
* the 1st text to add
*/
public void outLn(String str1, boolean isD) {
String out = str1 + '\n';
myAppend(out);
// Move the text insertion caret to the end of the text.
setCaretPosition(getText().length());
logToFile(out, isD);
}
/**
* Appends the given text plus NewLine to the end of the document.
*
* @param str1
* the 1st text to add
* @param str2
* the 2nd text to add in the same line
*/
public void outLn(String str1, String str2, boolean isD) {
String out = str1 + str2 + '\n';
myAppend(out);
// Move the text insertion caret to the end of the text.
setCaretPosition(getText().length());
logToFile(out, isD);
}
/**
* Appends the given text plus NewLine to the end of the document.
*
* @param str1
* the 1st text to add
* @param str2
* the 2nd text to add in the same line. Will be
* converted from int to string before.
*/
public void outLn(String str1, int str2, boolean isD) {
String out = str1 + str2 + '\n';
myAppend(out);
// Move the text insertion caret to the end of the text.
setCaretPosition(getText().length());
logToFile(out, isD);
}
/**
* Appends the given text plus NewLine to the end of the document.
*
* @param str1
* the 1st text to add
* @param str2
* the 2nd text to add in the same line
* @param str3
* the 3rd text to add in the same line
*/
public void outLn(String str1, String str2, String str3, boolean isD) {
String out = str1 + str2 + str3 + '\n';
myAppend(out);
// Move the text insertion caret to the end of the text.
setCaretPosition(getText().length());
logToFile(out, isD);
}
/**
* Appends the given text plus NewLine to the end of the document.
*
* @param str1
* the 1st text to add
* @param str2
* the 2nd text to add in the same line
* @param str3
* the 3rd text to add in the same line
* @param str4
* the 4th text to add in the same line
*/
public void outLn(String str1, String str2, String str3, String str4, boolean isD) {
String out = str1 + str2 + str3 + str4 + '\n';
myAppend(out);
// Move the text insertion caret to the end of the text.
setCaretPosition(getText().length());
logToFile(out, isD);
}
/**
* Appends the given text plus NewLine to the end of the document.
*
* @param str1
* the 1st text to add
* @param str2
* the 2nd text to add in the same line
* @param str3
* the 3rd text to add in the same line
* @param str4
* the 4th text to add in the same line
* @param str5
* the 5th text to add in the same line
*/
public void outLn(String str1, String str2, String str3, String str4, String str5, boolean isD) {
String out = str1 + str2 + str3 + str4 + str5 + '\n';
myAppend(out);
// Move the text insertion caret to the end of the text.
setCaretPosition(getText().length());
logToFile(out, isD);
}
/**
* For each string in str[], calls
* <code>appendLn(title, str[i])</code>.
*
* @param title
* the prefix of each line.
* @param str
* the strings to add.
*/
public void forEachOutLn(String title, String[] str, boolean isD) {
for (int i = 0; i < str.length; i++) {
outLn(title, str[i], isD);
}
}
/**
* For each int in int[], calls
* <code>appendLn(title, int[i])</code>.
*
* @param title
* the prefix of each line.
* @param i
* the integers to add.
*/
public void forEachOutLn(String title, int[] i, boolean isD) {
for (int x = 0; x < i.length; x++) {
outLn(title, i[x], isD);
}
}
/**
* For each short in short[], calls
* <code>appendLn(title, short[i])</code>.
*
* @param title
* the prefix of each line.
* @param s
* the shorts to add.
*/
public void forEachOutLn(String title, short[] s, boolean isD) {
for (int x = 0; x < s.length; x++) {
outLn(title, s[x], isD);
}
}
/**
* Appends "CALL TOOK " + time + " ms" plus NewLine to the end of
* the document.
*
* @param time
* the time that should be reported.
*/
public void outCallTookLn(long time, boolean isD) {
String out = "CALL TOOK " + time + " ms\n";
myAppend(out);
// Move the text insertion caret to the end of the text.
setCaretPosition(getText().length());
logToFile(out, isD);
}
/**
* Writes "CALL RETURNED SUCCESS" or "CALL RETURNED FAILURE" plus
* NewLine to the end of the document, depending on parameter
* success.
*
* @param success
* should "CALL RETURNED SUCCESS" be written?
*/
public void outFailureSuccessLn(boolean success, boolean isD) {
if (success) {
String out = "CALL RETURNED SUCCESS\n";
myAppend(out);
logToFile(out, isD);
} else {
String out = "CALL RETURNED FAILURE\n";
myAppend(out);
logToFile(out, isD);
}
// Move the text insertion caret to the end of the text.
setCaretPosition(getText().length());
}
/**
* Writes "CALL RETURNED OK" or "CALL RETURNED FAILURE" plus
* NewLine to the end of the document, depending on parameter ok.
*
* @param ok
* should "CALL RETURNED OK" be written?
*/
public void outFailureOkLn(boolean ok, boolean isD) {
if (ok) {
String out = "CALL RETURNED OK\n";
myAppend(out);
logToFile(out, isD);
} else {
String out = "CALL RETURNED FAILURE\n";
myAppend(out);
logToFile(out, isD);
}
// Move the text insertion caret to the end of the text.
setCaretPosition(getText().length());
}
private void logToFile(String out, boolean includeDate) {
if (client.getIsOperationLogEnabledValue()) {
try {
if (includeDate) {
fileLogger.writeToLogFile("" + new Date() + " -->\n");
fileLogger.writeToLogFile(" " + out + "\n");
} else {
fileLogger.writeToLogFile(" " + out);
}
} catch (OperationCannotBeLoggedException e) {
// PETERTASK handle situation when log is not
// reachable
}
}
}
public void writeStartupMessageToFile() {
if (client.getIsOperationLogEnabledValue()) {
try {
fileLogger
.writeToLogFile("\n\n"
+ new Date()
+ " -------------------- Ultra Corba Simulator Is Started --------------------\n\n");
} catch (OperationCannotBeLoggedException e) {
// PETERTASK handle situation when log is not
// reachable
}
}
}
private Document textArea = getDocument();
private static int maxLen = 2000000; // 2M Characters in the
// TextArea
private void myAppend(String in) {
try {
if (textArea.getLength() > maxLen) {
textArea.remove(0, 100000);
}
} catch (Exception e) {
// nothing to do
}
append(in);
}
}
/* EOF */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?