📄 appname.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 javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import com.sri.oaa2.agt.monitor.frmMonitor;
public class AppName extends JPanel {
private final JMenuBar mb;
private final JMenu m;
private JMenuItem itemHide;
private JCheckBoxMenuItem itemShowOptions;
private JCheckBoxMenuItem itemRestart;
private JMenuItem itemDebug;
private JMenuItem itemStart;
private JMenuItem itemKill;
private AppWidget appW;
private ImageIcon icon = null;
private Font bigFont;
public AppName(AppWidget w) {
this(w, true);
}
public AppName(AppWidget w, boolean show) {
appW = w;
GridBagLayout layout = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(layout);
setBorder(BorderFactory.createRaisedBevelBorder());
mb = new JMenuBar();
m = new JMenu(appW.info.appname);
m.setFont(new Font("SansSerif", Font.PLAIN, 18));
m.setForeground(new Color(0,0,80));
if (appW.info.isAgent()) {
icon = new MyImageIcon(frmMonitor.getAgentIconURL(appW.info.oaaname));
}
else {
icon = new MyImageIcon(getClass().getResource("images/app.gif"));
}
showIcon(show);
itemHide = new JMenuItem("Hide");
itemHide.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
appW.hide(true);
}
});
itemShowOptions = new JCheckBoxMenuItem("Show options", true);
itemShowOptions.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
appW.expandOptions(itemShowOptions.isSelected());
}
});
itemRestart = new JCheckBoxMenuItem("Auto-Restart");
itemRestart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
appW.info.restart = itemRestart.isSelected();
}
});
itemDebug = new JMenuItem("Print start info");
itemDebug.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
appW.printStartCommands();
}
});
itemStart = new JMenuItem("Start");
bigFont = itemStart.getFont().deriveFont(16.0F);
itemStart.setFont(bigFont);
itemStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
appW.start();
}
});
itemKill = new JMenuItem("Kill");
itemKill.setFont(bigFont);
itemKill.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
appW.kill();
}
});
m.add(itemHide);
m.add(itemShowOptions);
m.add(itemRestart);
m.addSeparator();
m.add(itemDebug);
m.addSeparator();
m.add(itemStart);
m.add(itemKill);
mb.add(m);
c.fill = c.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
add(mb);
}
public void showIcon(boolean show) {
m.setIcon(show ? icon : null);
}
public void setExpanded(boolean grow) {
itemShowOptions.setSelected(grow);
}
public void setBackground(Color c) {
super.setBackground(c);
if (mb != null)
mb.setBackground(c);
if (m != null)
m.setBackground(c);
}
static public class MyImageIcon extends ImageIcon {
public MyImageIcon(java.net.URL url) { super(url); }
public MyImageIcon(Image im) { super(im); }
// public int getIconWidth() {
// return 30;
// }
public int getIconHeight() {
return 28;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -