📄 organisationpanel.java
字号:
/*
* The contents of this file are subject to the BT "ZEUS" Open Source
* Licence (L77741), Version 1.0 (the "Licence"); you may not use this file
* except in compliance with the Licence. You may obtain a copy of the Licence
* from $ZEUS_INSTALL/licence.html or alternatively from
* http://www.labs.bt.com/projects/agents/zeus/licence.htm
*
* Except as stated in Clause 7 of the Licence, software distributed under the
* Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the Licence for the specific language governing rights and
* limitations under the Licence.
*
* The Original Code is within the package zeus.*.
* The Initial Developer of the Original Code is British Telecommunications
* public limited company, whose registered office is at 81 Newgate Street,
* London, EC1A 7AJ, England. Portions created by British Telecommunications
* public limited company are Copyright 1996-9. All Rights Reserved.
*
* THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
*/
/****************************************************************************
* OrganisationPanel.java
*
* Panel through which agent relationships are specified
***************************************************************************/
package zeus.generator.agent;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import javax.swing.event.*;
import zeus.util.*;
import zeus.concepts.*;
import zeus.generator.*;
import zeus.generator.util.*;
import zeus.ontology.*;
import zeus.gui.fields.*;
import zeus.gui.help.*;
public class OrganisationPanel extends JPanel {
static final String[] ERROR_MESSAGE = {
/* 0 */ "Please select a row before\ncalling this operation"
};
protected ControlPanel controlPane;
protected AgentDescription agent;
protected AcquaintanceModel acquaintanceModel;
protected JTable acquaintanceTable;
protected AbilityModel abilityModel;
protected JTable abilityTable;
protected AgentGenerator generator;
protected GeneratorModel genmodel;
protected OntologyDb ontologyDb;
protected AgentEditor editor;
protected AbilitySpec[] clipboard = null;
protected FactToolBar factToolBar;
public OrganisationPanel(AgentGenerator generator,
GeneratorModel genmodel,
OntologyDb ontologyDb,
AgentEditor editor,
AgentDescription agent) {
this.agent = agent;
this.generator = generator;
this.genmodel = genmodel;
this.editor = editor;
this.ontologyDb = ontologyDb;
GridBagLayout gridBagLayout = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
setLayout(gridBagLayout);
setBackground(Color.lightGray);
setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
controlPane = new ControlPanel(editor,"Agent Organisation Panel",false,false);
JPanel acquaintancePanel = new JPanel();
JPanel dataPanel = new JPanel();
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(8,8,8,8);
gridBagLayout.setConstraints(controlPane,gbc);
add(controlPane);
// Add the panel containing the other agents table to the panel.
gbc.anchor = GridBagConstraints.NORTHEAST;
gbc.fill = GridBagConstraints.BOTH;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.insets = new Insets(8,8,8,8);
gbc.weightx = gbc.weighty = 1;
gridBagLayout.setConstraints(acquaintancePanel,gbc);
add(acquaintancePanel);
// Add the panel containing the known suppliers
gbc.anchor = GridBagConstraints.SOUTH;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(8,8,8,8);
gbc.weightx = gbc.weighty = 1;
gridBagLayout.setConstraints(dataPanel,gbc);
add(dataPanel);
// Create acquaintance info area
AttributeModel attributeModel = new AttributeModel();
AttributeTable attributeTable = new AttributeTable(attributeModel);
abilityModel = new AbilityModel(ontologyDb,attributeModel);
acquaintanceModel = new AcquaintanceModel(genmodel,ontologyDb,
abilityModel,agent.getAcquaintances());
attributeModel.addChangeListener(editor);
abilityModel.addChangeListener(editor);
acquaintanceModel.addChangeListener(editor);
TableColumnModel tm = new DefaultTableColumnModel();
TableColumn column;
column = new TableColumn(AcquaintanceModel.AGENT,12,
new DefaultTableCellRenderer(),
new DefaultCellEditor(new NameField()));
column.setHeaderValue(acquaintanceModel.getColumnName(AcquaintanceModel.AGENT));
tm.addColumn(column);
column = new TableColumn(AcquaintanceModel.RELATION,12,
new DefaultTableCellRenderer(), new RelationEditor());
column.setHeaderValue(acquaintanceModel.getColumnName(AcquaintanceModel.RELATION));
tm.addColumn(column);
acquaintanceTable = new JTable(acquaintanceModel,tm);
acquaintanceTable.getTableHeader().setReorderingAllowed(false);
acquaintanceTable.setColumnSelectionAllowed(false);
ListSelectionModel selectionModel = acquaintanceTable.getSelectionModel();
selectionModel.addListSelectionListener(new SymListAction1());
JScrollPane scrollPane = new JScrollPane(acquaintanceTable);
scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
scrollPane.setPreferredSize(new Dimension(340,120));
acquaintanceTable.setBackground(Color.white);
gridBagLayout = new GridBagLayout();
acquaintancePanel.setLayout(gridBagLayout);
acquaintancePanel.setBackground(Color.lightGray);
acquaintanceTable.setMinimumSize(new Dimension(400,140));
TitledBorder border = BorderFactory.createTitledBorder("Acquaintances");
border.setTitlePosition(TitledBorder.TOP);
border.setTitleJustification(TitledBorder.RIGHT);
border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
border.setTitleColor(java.awt.Color.blue);
acquaintancePanel.setBorder(border);
JToolBar toolbar = new AcquaintanceToolBar();
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.NONE;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.insets = new Insets(0,8,0,0);
gridBagLayout.setConstraints(toolbar,gbc);
acquaintancePanel.add(toolbar);
gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = gbc.weighty = 1;
gbc.insets = new Insets(8,8,8,8);
gridBagLayout.setConstraints(scrollPane,gbc);
acquaintancePanel.add(scrollPane);
// Create data info area
tm = new DefaultTableColumnModel();
column = new TableColumn(AbilityModel.TYPE,12);
column.setHeaderValue(abilityModel.getColumnName(AbilityModel.TYPE));
tm.addColumn(column);
column = new TableColumn(AbilityModel.COST,12,
new DefaultTableCellRenderer(),
new DefaultCellEditor(new RealNumberField()));
column.setHeaderValue(abilityModel.getColumnName(AbilityModel.COST));
tm.addColumn(column);
column = new TableColumn(AbilityModel.TIME,12,
new DefaultTableCellRenderer(),
new DefaultCellEditor(new WholeNumberField()));
column.setHeaderValue(abilityModel.getColumnName(AbilityModel.TIME));
tm.addColumn(column);
abilityTable = new JTable(abilityModel,tm);
abilityTable.getTableHeader().setReorderingAllowed(false);
abilityTable.setColumnSelectionAllowed(false);
selectionModel = abilityTable.getSelectionModel();
selectionModel.addListSelectionListener(new SymListAction2());
scrollPane = new JScrollPane(abilityTable);
scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
scrollPane.setPreferredSize(new Dimension(400,100));
abilityTable.setBackground(Color.white);
gridBagLayout = new GridBagLayout();
dataPanel.setLayout(gridBagLayout);
dataPanel.setBackground(Color.lightGray);
abilityTable.setMinimumSize(new Dimension(400,120));
attributeTable.setMinimumSize(new Dimension(400,140));
border = BorderFactory.createTitledBorder("Acquaintance Abilities");
border.setTitlePosition(TitledBorder.TOP);
border.setTitleJustification(TitledBorder.RIGHT);
border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
border.setTitleColor(Color.blue);
dataPanel.setBorder(border);
factToolBar = new FactToolBar();
factToolBar.setEnabled(false);
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.NONE;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.insets = new Insets(0,8,0,0);
gridBagLayout.setConstraints(factToolBar,gbc);
dataPanel.add(factToolBar);
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = gbc.weighty = 1;
gbc.insets = new Insets(8,8,8,8);
gridBagLayout.setConstraints(scrollPane,gbc);
dataPanel.add(scrollPane);
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = gbc.weighty = 1;
gbc.insets = new Insets(8,8,8,8);
gridBagLayout.setConstraints(attributeTable,gbc);
dataPanel.add(attributeTable);
}
// Begin inner classes
class AcquaintanceToolBar extends JToolBar implements ActionListener {
protected JToggleButton helpBtn, allBtn, peerBtn, nonpeerBtn;
protected HelpWindow helpWin;
protected JButton resetBtn;
protected JButton newBtn;
protected JButton editBtn;
protected JButton deleteBtn;
protected JPopupMenu popup;
protected JMenuItem addMenuItem;
public AcquaintanceToolBar() {
setBackground(Color.lightGray);
setBorder(new BevelBorder(BevelBorder.LOWERED));
setFloatable(false);
String path = SystemProps.getProperty("gif.dir") + "generator" +
System.getProperty("file.separator");
// new Button
newBtn = new JButton(new ImageIcon(path + "new1.gif"));
newBtn.setMargin(new Insets(0,0,0,0));
add(newBtn);
newBtn.setToolTipText("New acquaintance");
newBtn.addActionListener(this);
addSeparator();
editBtn = new JButton(new ImageIcon(path + "edit1.gif"));
editBtn.setMargin(new Insets(0,0,0,0));
add(editBtn);
editBtn.setToolTipText("Edit this acquaintance");
editBtn.addActionListener(this);
deleteBtn = new JButton(new ImageIcon(path + "delete1.gif"));
deleteBtn.setMargin(new Insets(0,0,0,0));
add(deleteBtn);
deleteBtn.setToolTipText("Delete this acquaintance");
deleteBtn.addActionListener(this);
addSeparator();
// Reset Button
resetBtn = new JButton(new ImageIcon(path + "reset.gif" ));
resetBtn.setMargin(new Insets(0,0,0,0));
add(resetBtn);
resetBtn.setToolTipText("Reset acquaintance to peer");
resetBtn.addActionListener(this);
addSeparator();
ButtonGroup group = new ButtonGroup();
// All Button
allBtn = new JToggleButton(new ImageIcon(path + "all.gif"), true);
allBtn.setMargin(new Insets(0,0,0,0));
add(allBtn);
allBtn.setToolTipText("Show all acquaintances");
allBtn.addActionListener(this);
group.add(allBtn);
// Peers Button
peerBtn = new JToggleButton(new ImageIcon(path + "peers.gif"));
peerBtn.setMargin(new Insets(0,0,0,0));
add(peerBtn);
peerBtn.setToolTipText("Show peers only");
peerBtn.addActionListener(this);
group.add(peerBtn);
// Non-Peers Button
nonpeerBtn = new JToggleButton(new ImageIcon(path + "others.gif"));
nonpeerBtn.setMargin(new Insets(0,0,0,0));
add(nonpeerBtn);
nonpeerBtn.setToolTipText("Show non-peers only");
nonpeerBtn.addActionListener(this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -