📄 startitmenubar.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 java.awt.*;
import java.awt.event.*;
import java.util.*;
import com.sri.oaa2.guiutils.*;
public class StartitMenuBar extends JMenuBar {
private JMenu file;
private JMenu proj;
public JMenu hidden;
private JMenu view;
private JMenu kill;
private JMenu help;
private JMenuItem oaaConnectItem;
private OaaConnectDialog connectDialog;
private Startit startit;
private static final Component[] statusLightHelp = {
new JLabel("<html><u>Lights which apply to <i>all</i> processes"),
new LightLabel(StartitProcess.NOT_RUNNING, "Not running"),
new JPanel(),
new JLabel("<html><u>Lights which apply to <i>agent</i> processes"),
new LightLabel(StartitProcess.WAITING_TO_START, "Waiting to start"),
new LightLabel(StartitProcess.INITIALIZING, "Initializing"),
new LightLabel(StartitProcess.READY, "Ready"),
new LightLabel(StartitProcess.WAITING_TO_KILL, "Waiting to be killed"),
new LightLabel(StartitProcess.KILLING, "Killing"),
new LightLabel(StartitProcess.DIED, "Died"),
new JPanel(),
new JLabel("<html><u>Lights which apply to <i>non-agent</i> processes"),
new LightLabel(StartitProcess.NONAGENT_WAITING, "Waiting to start"),
new LightLabel(StartitProcess.NONAGENT_RUNNING, "Running"),
new LightLabel(StartitProcess.NONAGENT_WAITING_TO_KILL, "Waiting to be killed"),
new LightLabel(StartitProcess.NONAGENT_KILLING, "Killing"),
new LightLabel(StartitProcess.NONAGENT_DIED, "Died"),
};
public StartitMenuBar(Startit s) {
startit = s;
JMenuItem item;
JRadioButtonMenuItem radio;
setBorder(BorderFactory.createRaisedBevelBorder());
connectDialog = new OaaConnectDialog(startit, "OAA Connect", true);
////////////////////////////////////////////////////////////////////////////////
// 1: FILE menu
////////////////////////////////////////////////////////////////////////////////
file = new JMenu("File");
file.setMnemonic(KeyEvent.VK_F);
if (!startit.sinfo.managedFacilitator()) {
item = new JMenuItem("Oaa Connect...");
item.setMnemonic(KeyEvent.VK_O);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
connectDialog.setHostName("");
connectDialog.setPortNumber(0);
connectDialog.setVisible(true);
if (connectDialog.mOk) {
OaaConnection oaa = startit.sinfo.getOaaConnection();
oaa.connect(connectDialog.getHostName(), connectDialog.getPortNumber());
startit.updateFacilitatorDisplay();
}
}
});
file.add(item);
oaaConnectItem = item;
}
item = new JMenuItem("Exit");
item.setMnemonic(KeyEvent.VK_X);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startit.quit();
}
});
file.add(item);
add(file);
////////////////////////////////////////////////////////////////////////////////
// 2: PROJECTS menu (won't be there if there's no projectlist)
////////////////////////////////////////////////////////////////////////////////
if (startit.sinfo.projectlist != null) {
proj = new JMenu("Projects");
proj.setMnemonic(KeyEvent.VK_P);
ButtonGroup group = new ButtonGroup();
for (Iterator i = startit.sinfo.projectlist.iterator(); i.hasNext();) {
String name = (String) i.next();
radio = new JRadioButtonMenuItem(name);
radio.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String p = ((JRadioButtonMenuItem) e.getSource()).getText();
startit.setActiveProject(p);
}
});
proj.add(radio);
group.add(radio);
}
proj.addSeparator(); // --------------------------------------------
radio = new JRadioButtonMenuItem("Global");
radio.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startit.setActiveProject(null);
}
});
proj.add(radio);
group.add(radio);
proj.getItem(0).setSelected(true);
add(proj);
}
////////////////////////////////////////////////////////////////////////////////
// 3: APPLICATIONS menu
////////////////////////////////////////////////////////////////////////////////
hidden = new JMenu("Applications", true); // true=tear-off; though it's not actually
// implemented in java 1.4.1....
hidden.setMnemonic(KeyEvent.VK_A);
add(hidden);
////////////////////////////////////////////////////////////////////////////////
// 4: VIEW menu
////////////////////////////////////////////////////////////////////////////////
view = new JMenu("View");
view.setMnemonic(KeyEvent.VK_V);
item = new JMenuItem("Show all options");
item.setMnemonic(KeyEvent.VK_S);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startit.apps.expandAll(true);
}
});
view.add(item);
item = new JMenuItem("Hide all options");
item.setMnemonic(KeyEvent.VK_H);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startit.apps.expandAll(false);
}
});
view.add(item);
view.addSeparator(); // --------------------------------------------
item = new JCheckBoxMenuItem("Show App Icons");
item.setMnemonic(KeyEvent.VK_I);
item.setSelected(true);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JCheckBoxMenuItem me = (JCheckBoxMenuItem) e.getSource();
startit.apps.showIcons(me.isSelected());
}
});
view.add(item);
// if quiet mode is not enabled, show logging options
if (!startit.isQuiet()) {
view.addSeparator(); // --------------------------------------------
item = new JMenuItem("Show Output Window");
item.setMnemonic(KeyEvent.VK_O);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startit.outwin.setState(Frame.NORMAL);
startit.outwin.show();
}
});
view.add(item);
item = new JCheckBoxMenuItem("Auto-Show Output On Warning");
item.setMnemonic(KeyEvent.VK_A);
item.setSelected(startit.outwin.getAutoWarn());
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JCheckBoxMenuItem me = (JCheckBoxMenuItem) e.getSource();
startit.outwin.setAutoWarn(me.isSelected());
}
});
view.add(item);
}
add(view);
////////////////////////////////////////////////////////////////////////////////
// 5: KILL menu
////////////////////////////////////////////////////////////////////////////////
kill = new JMenu("Kill");
kill.setMnemonic(KeyEvent.VK_K);
item = new JMenuItem("Kill all applications");
item.setForeground(Color.red);
item.setMnemonic(KeyEvent.VK_K);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startit.sinfo.killAllApps();
}
});
kill.add(item);
item = new JMenuItem("Kill all and exit");
item.setForeground(Color.red);
item.setMnemonic(KeyEvent.VK_X);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startit.sinfo.killAndExit();
}
});
kill.add(item);
add(kill);
////////////////////////////////////////////////////////////////////////////////
// 6: HELP menu
////////////////////////////////////////////////////////////////////////////////
help = new JMenu("Help");
help.setMnemonic(KeyEvent.VK_H);
item = new JMenuItem("Status light colors");
item.setMnemonic(KeyEvent.VK_S);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(startit, statusLightHelp,
"StartIt Help: Status light colors",
JOptionPane.INFORMATION_MESSAGE);
}
});
help.add(item);
add(help);
}
public void facConnected(boolean isConnected) {
oaaConnectItem.setEnabled(!isConnected);
}
public static class LightLabel extends JPanel {
public LightLabel(int state, String text) {
setLayout(new BorderLayout(12, 0));
//setBackground(StartitColors.gray2);
StatusLight light = new StatusLight();
light.setStatus(state);
add(BorderLayout.WEST, light);
add(new JLabel(text));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -