📄 textresultviewer.java
字号:
import java.awt.Color;
import javax.swing.JTextPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
/**
* Description of the Class
*
* @author kilo
* @created 2003年12月22日
*/
public final class TextResultViewer
extends ResultViewer {
/**
* Description of the Field
*/
private static SimpleAttributeSet attrset = new SimpleAttributeSet();
/**
* Description of the Field
*/
private JTextPane textPane;
/**
* Description of the Field
*/
private Color oldc;
/**
* Constructor for the TextResultViewer object
*
* @param d Description of the Parameter
*/
public TextResultViewer( DataManager d ) {
super( d );
textPane = new JTextPane();
oldc = textPane.getForeground();
StyleConstants.setForeground( attrset, oldc );
textPane.setEditable( false );
add( textPane );
}
/**
* Description of the Method
*
* @param str Description of the Parameter
* @param attrset Description of the Parameter
*/
private void insert( String str, AttributeSet attrset ) {
Document docs = textPane.getDocument();
try {
docs.insertString( docs.getLength(),
str,
attrset );
} catch ( BadLocationException ble ) {
System.out.println( "BadLocationException: " + ble );
}
}
/**
* Description of the Method
*/
public void updateDisplay() {
if ( !dataManager.isNewOp ) {
if ( !"".equals( dataManager.curName ) ) {
StyleConstants.setForeground( attrset, oldc );
insert( dataManager.curName + "--->\n", attrset );
String result = dataManager.newName +
( dataManager.isOK ? " 成功改名\n" : "\n" );
if ( !dataManager.isOK )
StyleConstants.setForeground( attrset, Color.red );
insert( result, attrset );
}
}
else
textPane.setText( "" );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -