📄 optionbox.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.*;
public class OptionBox extends JPanel {
private boolean expanded = true;
private Dimension regularSize = null;
private static final int shrunkenHeight = 7;
private GridBagLayout gridbag = new GridBagLayout();
private GridBagConstraints gc = new GridBagConstraints();
private Vector/*OptionWidget*/ options = new Vector();
private AppWidget app;
public OptionBox(AppWidget a) {
app = a;
setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
setLayout(gridbag);
gc.anchor = gc.WEST;
gc.insets = new Insets(3,5,3,5);
}
public void addWidget(OptionInfo info) {
if (info.hidden) return;
if (info.devOption && !app.info.sinfo.showDevOptions) return;
if (info.type == OptionInfo.MENU || info.size > 0) {
gc.fill = gc.VERTICAL;
}
else {
gc.fill = gc.BOTH;
}
OptionWidget w = new OptionWidget(info);
if (info.devOption) {
w.getLeft().setForeground(Color.red.darker());
}
addWidget(w);
}
private void addWidget(OptionWidget w) {
JComponent left = w.getLeft();
JComponent right = w.getRight();
gc.weightx = 0.0;
gc.weighty = 1.0;
gc.gridx = 0;
gc.gridy = options.size();
gridbag.setConstraints(left, gc);
gc.weightx = 1.0;
gc.gridx = 1;
gridbag.setConstraints(right, gc);
add(left);
add(right);
options.add(w);
}
protected void setExpanded(boolean grow) {
if (grow && !expanded) {
setPreferredSize(regularSize);
revalidate();
}
else if (!grow /* i.e. shrink */ && expanded) {
regularSize = getPreferredSize(); // record regularSize before shrinking
setPreferredSize(new Dimension(regularSize.height, shrunkenHeight));
revalidate();
}
expanded = grow;
}
public void updateInfo() {
for (Iterator i = options.iterator(); i.hasNext(); ) {
OptionWidget w = (OptionWidget) i.next();
w.updateInfo();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -