📄 outputwindow.java
字号:
/**
* The contents of this file are subject to the OAA Community Research
* License Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License
* at http://www.ai.sri.com/~oaa/. Software distributed under the License
* is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific language governing
* rights and limitations under the License. Portions of the software are
* Copyright (c) SRI International, 1999-2003. All rights reserved.
* "OAA" is a registered trademark, and "Open Agent Architecture" is a
* trademark, of SRI International, a California nonprofit public benefit
* corporation.
*/
package com.sri.oaa2.agt.startit;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.awt.event.*;
import java.awt.*;
public class OutputWindow extends JFrame implements Outputter {
private OutputPane mainPane;
private OutputPane[] appPanes;
private JSplitPane splitPane;
private JTabbedPane tabPane;
private MyMenubar menuBar;
private Hashtable paneHash = new Hashtable();
private Hashtable tabHash = new Hashtable();
private Color[] bgColors;
private boolean autoWarn = false;
public OutputWindow(StartitInfo sinfo) {
Container top = getContentPane();
menuBar = new MyMenubar();
setJMenuBar(menuBar);
setBackground(StartitColors.gray1);
bgColors = new Color[8];
int b = 0;
bgColors[b++] = new Color( 94, 108, 183); // blue
bgColors[b++] = new Color(255, 128, 64); // orange
bgColors[b++] = new Color( 0, 119, 145); // teal
bgColors[b++] = new Color(223, 45, 45); // red
bgColors[b++] = new Color( 45, 134, 61); // green
bgColors[b++] = new Color(147, 44, 158); // purple
bgColors[b++] = new Color(158, 96, 78); // brown
bgColors[b++] = new Color(207, 73, 137); // pink
/*
mainPane = new OutputPane() {
public String getToolTipText(MouseEvent e) {
int p = viewToModel(e.getPoint());
setCaretPosition(p);
Style s = getLogicalStyle();
return s.toString();
}
};
ToolTipManager.sharedInstance().registerComponent(mainPane);
*/
mainPane = new OutputPane();
tabPane = new JTabbedPane();
int j = 0;
JScrollPane scroll;
for (Iterator i = sinfo.apps.iterator(); i.hasNext(); ) {
AppInfo app = (AppInfo) i.next();
OutputPane p = new OutputPane(bgColors[j % bgColors.length]);
scroll = new JScrollPane(p);
paneHash.put(app, p);
tabHash.put(app, scroll);
tabPane.add(app.appname, scroll);
tabPane.setForegroundAt(j, bgColors[j % bgColors.length]);
tabPane.setBackgroundAt(j, StartitColors.gray3);
j++;
}
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
new JScrollPane(mainPane),
tabPane);
splitPane.setResizeWeight(.8);
top.add(splitPane);
setTitle("Output");
pack();
setSize(new Dimension(500,630));
}
public void outputLine(final AppInfo app, final String line, final int type) {
Runnable output = new Runnable() {
public void run() {
_outputLine(app, line, type);
}
};
SwingUtilities.invokeLater(output);
}
public void _outputLine(AppInfo app, String line, int type) {
if (type == Outputter.DEBUG && !menuBar.displayDebug()) {
return;
}
OutputPane win = (app == null) ? null : (OutputPane) paneHash.get(app);
if (win != null) {
mainPane.appendLine(line, type, win);
win.appendLine(line, type);
}
else {
mainPane.appendLine(line, type);
}
if ((autoWarn) && (type == Outputter.WARNING) && (win != null)) {
tabPane.setSelectedComponent((Component) tabHash.get(app));
show();
}
}
public void setAutoWarn(boolean tf) {
autoWarn = tf;
}
public boolean getAutoWarn() {
return autoWarn;
}
private class MyMenubar extends JMenuBar {
private JMenu file, view;
JCheckBoxMenuItem debugCheck;
public MyMenubar() {
JMenuItem item;
file = new JMenu("File");
file.setMnemonic(KeyEvent.VK_F);
item = new JMenuItem("Close");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
OutputWindow.this.hide();
}
});
file.add(item);
add(file);
view = new JMenu("View");
view.setMnemonic(KeyEvent.VK_V);
item = new JMenuItem("Clear");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mainPane.clear();
}
});
debugCheck = new JCheckBoxMenuItem("Display Debug Output");
debugCheck.setSelected(true);
view.add(item);
view.addSeparator();
view.add(debugCheck);
add(view);
}
public boolean displayDebug() {
return debugCheck.isSelected();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -