testresultsectionform.java
来自「cqME :java framework for TCK test.」· Java 代码 · 共 413 行 · 第 1/2 页
JAVA
413 行
/*
* $Id$
*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 only, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License version 2 for more details (a copy is
* included at /legal/license.txt).
*
* You should have received a copy of the GNU General Public License
* version 2 along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 or visit www.sun.com if you need additional
* information or have any questions.
*
*/
package com.sun.testme.jtviewer.jtrsupport.editor;
import com.sun.javatest.Status;
import com.sun.javatest.TestResult;
import com.sun.testme.JTUtils;
import com.sun.testme.jtviewer.jtrsupport.JTRDataObject;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
import org.openide.filesystems.FileAttributeEvent;
import org.openide.filesystems.FileChangeListener;
import org.openide.filesystems.FileEvent;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileRenameEvent;
import org.openide.util.RequestProcessor;
/**
*
* @author Alexander Glasman
*/
public class TestResultSectionForm extends JPanel implements FileChangeListener {
private TestResultSectionEditor editor;
private static StyleSheet styleSheet;
private static HTMLEditorKit htmlEditorKit;
private boolean updateCombo;
public TestResultSectionForm(TestResultSectionEditor editor) {
super();
initComponents();
this.editor = editor;
htmlPane.setContentType("text/html");
statusPane.setContentType("text/html");
SectionListener sectionListener = new SectionListener();
htmlPane.addHyperlinkListener(sectionListener);
updateSectionCombo();
getFileObject().addFileChangeListener(this);
}
private TestResult getTestResult() {
JTRDataObject jtrObject = editor.getDataObject();
return jtrObject.getTestResult();
}
private FileObject getFileObject() {
JTRDataObject jtrObject = editor.getDataObject();
return jtrObject.getPrimaryFile();
}
private void updateSectionCombo() {
updateCombo = false;
sectionCombo.removeAllItems();
updateCombo = true;
TestResult testResult = getTestResult();
if (testResult == null) {
return;
}
String [] sections = testResult.getSectionTitles();
for (int i = 0; i < sections.length; i++) {
if (TestResult.MSG_SECTION_NAME.equals(sections[i])) {
sections[i] = "Test Summary";
}
sectionCombo.addItem(sections[i]);
}
}
private TestResult.Section getCurrentSection() {
TestResult testResult = getTestResult();
if (testResult == null) {
return null;
}
int sectionId = sectionCombo.getSelectedIndex();
TestResult.Section section = null;
try {
section = testResult.getSection(sectionId);
} catch (TestResult.ReloadFault ex) {
ex.printStackTrace();
}
return section;
}
private void updateOutputCombo() {
outputCombo.removeAllItems();
TestResult.Section section = getCurrentSection();
if (section == null) {
return;
}
boolean isSummary = JTUtils.isScriptMessagesSection(section);
String [] outputs = section.getOutputNames();
for (String outputName : outputs) {
if ((outputName != null) && (!"".equals(outputName)) ) {
if ((isSummary) && ("messages".equals(outputName))) {
outputCombo.addItem("Script Messages");
} else {
outputCombo.addItem(outputName);
}
}
}
}
private String getCurrentOutputName() {
TestResult testResult = getTestResult();
TestResult.Section section = getCurrentSection();
if (section == null) {
return null;
}
int outputId = outputCombo.getSelectedIndex();
if ((outputId >= section.getOutputCount()) || (outputId < 0)) {
return null;
}
return section.getOutputNames()[outputId];
}
private void updateOutputView() {
TestResult testResult = getTestResult();
TestResult.Section section = getCurrentSection();
if (section == null) {
return;
}
String outputName = getCurrentOutputName();
if (testResult.getStatus().getType() == Status.NOT_RUN) {
showHTML(JTUtils.createNotRunSummary(), statusPane);
} else {
showHTML(JTUtils.createStatusSummary(testResult), statusPane);
}
if (outputName != null) {
showText(section.getOutput(outputName));
}
if (JTUtils.isScriptMessagesSection(section)) {
showHTML(JTUtils.createSummary(testResult), htmlPane);
} else {
showHTML(JTUtils.createSectionSummary(section), htmlPane);
}
}
private void showHTML(String s, JEditorPane pane) {
// htmlPane.setContentType("text/html");
//
// HTMLDocument doc = new HTMLDocument(getStyleSheet()) { };
// htmlPane.setDocument(doc);
Document doc = pane.getEditorKit().createDefaultDocument();
pane.setDocument(doc);
pane.setText(s);
}
private void showText(String s) {
if (s.length() == 0) {
textPane.setText("(empty)");
textPane.setEnabled(false);
}
else {
textPane.setText(s);
textPane.setEnabled(true);
}
}
private static StyleSheet getStyleSheet() {
if (htmlEditorKit == null) {
htmlEditorKit = new HTMLEditorKit();
}
if (styleSheet == null) {
styleSheet = new StyleSheet();
styleSheet.addStyleSheet(htmlEditorKit.getStyleSheet());
styleSheet.addRule("body { font-family: SansSerif; font-size: 12pt }");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?