📄 appbox.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.border.*;
import java.awt.*;
import java.awt.event.*;
public class AppBox extends JPanel {
private JMenu hiddenAppMenu;
private GridBagLayout gridbag = new GridBagLayout();
private GridBagConstraints gc = new GridBagConstraints();
private Container spaceEater = new Container(); // vertical glue
private StartitInfo sinfo;
private Vector appWidgets = new Vector();
public AppBox(StartitInfo si, JMenu hm) {
sinfo = si;
JCheckBoxMenuItem item;
hiddenAppMenu = hm;
setLayout(gridbag);
gc.weightx = 1.0;
gc.gridx = 0;
gc.fill = gc.BOTH;
gc.anchor = gc.NORTH;
for (int i = 0; i < sinfo.apps.size(); i++) {
AppInfo app = (AppInfo) sinfo.apps.get(i);
AppWidget appW = new AppWidget(this, app);
appWidgets.add(appW);
item = new AppMenuItem(app, appW, !app.hidden);
hiddenAppMenu.add(item);
appW.setHideMenuItem(item);
}
showApps();
}
public void setBackground(Color c) {
super.setBackground(c);
if (appWidgets == null) return;
for (Iterator i = appWidgets.iterator(); i.hasNext(); ) {
AppWidget w = (AppWidget) i.next();
w.setBackground(c);
}
//spaceEater.setBackground(c);
}
public void showApps() {
int y = 0;
gc.weighty = 0.0;
removeAll();
for (Iterator i = appWidgets.iterator(); i.hasNext(); ) {
AppWidget w = (AppWidget) i.next();
if (isShown(w)) {
gc.gridy = y++;
gridbag.setConstraints(w, gc);
add(w);
}
w.hideMenuItem.setEnabled(w.info.isInProject(sinfo.getActiveProject()));
}
gc.weighty = 1.0;
gc.gridy = y;
gridbag.setConstraints(spaceEater, gc);
add(spaceEater);
revalidate();
}
public void updateStartitInfo() {
for (Iterator i = appWidgets.iterator(); i.hasNext(); ) {
AppWidget w = (AppWidget) i.next();
w.updateInfo();
}
}
public void expandAll(boolean grow) {
for (Iterator i = appWidgets.iterator(); i.hasNext(); ) {
AppWidget w = (AppWidget) i.next();
if (isShown(w)) {
w.expandOptions(grow);
}
}
}
public void showIcons(boolean show) {
for (Iterator i = appWidgets.iterator(); i.hasNext(); ) {
AppWidget w = (AppWidget) i.next();
w.nameBtn.showIcon(show);
}
}
public boolean isShown(AppWidget w) {
return !w.info.hidden && w.info.isInProject(sinfo.getActiveProject());
}
private class AppMenuItem extends JCheckBoxMenuItem {
private AppInfo app;
private AppWidget appW;
public AppMenuItem(AppInfo a, AppWidget w, boolean hidden) {
super(a.appname, hidden);
app = a;
appW = w;
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
app.hidden = !app.hidden;
showApps();
}
});
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -