⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nodespanel.java

📁 人工智能中Agent开发包。多 Agent 系统是处理自治 Agent 之间知识层的协作问题
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* 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
*/



/****************************************************************************
* NodesPanel.java
*
* Panel through which summary task nodes are entered
***************************************************************************/

package zeus.generator.task;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.text.*;
import javax.swing.event.*;

import zeus.util.*;
import zeus.concepts.*;
import zeus.concepts.fn.*;
import zeus.generator.*;
import zeus.generator.util.*;
import zeus.generator.event.*;
import zeus.gui.graph.*;
import zeus.gui.fields.*;
import zeus.gui.help.*;

public class NodesPanel extends JPanel {
  protected SummaryTask      task;
  protected Graph            graph;
  protected GraphNode[]      clipboard;
  protected SummaryTaskModel model;
  protected JCheckBox        autorun;
  protected LargeTextField   costfield;
  protected LargeTextField   timefield;
  protected BasicFactModel   preconditionsModel;
  protected BasicFactModel   postconditionsModel;

  public NodesPanel(AgentGenerator generator, GeneratorModel genmodel,
                    OntologyDb ontologyDb, TaskEditor editor,
                    SummaryTask task)  {

    this.task = task;

    model = new SummaryTaskModel(ontologyDb,task.getNodes(),task.getLinks());
    model.addChangeListener(editor);
    graph = new Graph(model);
    graph.setNodeRenderer(new SummaryTaskNodeRenderer());
    graph.setNodeEditor(new SummaryTaskNodeEditor(ontologyDb,model));

    preconditionsModel =
       new SymBasicFactModel(SummaryTaskModel.PRECONDITION,model);
    postconditionsModel =
       new SymBasicFactModel(SummaryTaskModel.POSTCONDITION,model);

    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    setLayout(gridBagLayout);
    setBackground(Color.lightGray);
    setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));

    // Add the control panel
    ControlPanel controlPane =
       new ControlPanel(editor,"Task Decomposition Graph",true,false);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(8,8,8,8);
    gbc.weightx = gbc.weighty = 0;
    gridBagLayout.setConstraints(controlPane,gbc);
    add(controlPane);

    // Add the panel that will contain the task's nodes
    JPanel dataPanel = new JPanel();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = gbc.weighty = 1;
    gbc.insets = new Insets(8,8,8,8);
    gridBagLayout.setConstraints(dataPanel,gbc);
    add(dataPanel);

    // Add the panel that will contain the task's cost and time fields
    JPanel costPanel = new JPanel();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(8,8,8,8);
    gbc.weightx = gbc.weighty = 0;
    gridBagLayout.setConstraints(costPanel,gbc);
    add(costPanel);

    // Cost/Time panel info

    String title = task.isScript() ? "Task Mode, Cost and Time" :
       "Task Cost and Time";

    TitledBorder border =
       BorderFactory.createTitledBorder(title);
    border.setTitlePosition(TitledBorder.TOP);
    border.setTitleJustification(TitledBorder.RIGHT);
    border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
    border.setTitleColor(Color.blue);
    costPanel.setBorder(border);

    gridBagLayout = new GridBagLayout();
    costPanel.setLayout(gridBagLayout);
    costPanel.setBackground(Color.lightGray);

    JLabel label;

    if ( task.isScript() ) {
       label = new JLabel("Autorun:");
       label.setToolTipText("Set autorun on if task is invoked automatically");
       gbc = new GridBagConstraints();
       gbc.anchor = GridBagConstraints.WEST;
       gbc.fill = GridBagConstraints.NONE;
       gbc.gridwidth = 1;
       gbc.insets = new Insets(0,8,8,0);
       gridBagLayout.setConstraints(label,gbc);
       costPanel.add(label);

       autorun = new JCheckBox();
       autorun.setBackground(Color.lightGray);
       autorun.setSelected(((PlanScript)task).isAutorun());
       autorun.setEnabled(false); // REM for now
       autorun.addChangeListener(editor);

       gbc = new GridBagConstraints();
       gbc.gridwidth = GridBagConstraints.REMAINDER;
       gbc.anchor = GridBagConstraints.WEST;
       gbc.fill = GridBagConstraints.NONE;
       gbc.insets = new Insets(0,8,8,8);
       gridBagLayout.setConstraints(autorun,gbc);
       costPanel.add(autorun);
    }


    label = new JLabel("Cost:");
    label.setToolTipText("Default cost of performing this task");
    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(0,8,0,0);
    gridBagLayout.setConstraints(label,gbc);
    costPanel.add(label);

    costfield = new LargeTextField(2,15);
    costfield.setLineWrap(true);
    costfield.setText(task.getCostFn().toString());
    costfield.addChangeListener(editor);

    gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = gbc.weighty = 1;
    gbc.insets = new Insets(0,8,0,8);
    gridBagLayout.setConstraints(costfield,gbc);
    costPanel.add(costfield);

    label = new JLabel("Time:");
    label.setToolTipText("Default duration of this task");
    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridwidth = 1;
    gbc.insets = new Insets(8,8,8,0);
    gridBagLayout.setConstraints(label,gbc);
    costPanel.add(label);

    timefield = new LargeTextField(2,15);
    timefield.setLineWrap(true);
    timefield.setText(task.getTimeFn().toString());
    timefield.addChangeListener(editor);

    gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = gbc.weighty = 1;
    gbc.insets = new Insets(8,8,8,8);
    gridBagLayout.setConstraints(timefield,gbc);
    costPanel.add(timefield);

    // Data panel info
    gridBagLayout = new GridBagLayout();
    dataPanel.setLayout(gridBagLayout);
    dataPanel.setBackground(Color.lightGray);

    JScrollPane scrollPane = new JScrollPane(graph);
    scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
    scrollPane.setPreferredSize(new Dimension(600,400));
    graph.setPreferredSize(new Dimension(2000,2000));
    graph.setBackground(Color.white);

    border = (BorderFactory.createTitledBorder("Task Decomposition Graph"));
    border.setTitlePosition(TitledBorder.TOP);
    border.setTitleJustification(TitledBorder.RIGHT);
    border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
    border.setTitleColor(Color.blue);
    dataPanel.setBorder(border);

    JToolBar toolbar = new NodesToolBar(task.isScript());

    gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = gbc.weighty = 0;
    gbc.insets = new Insets(0,8,0,0);
    gridBagLayout.setConstraints(toolbar,gbc);
    dataPanel.add(toolbar);

    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);

    // Initialisation Information
    // for renaming cost/time expressions
    SymRenameAction rs = new SymRenameAction();
    preconditionsModel.addRenameListener(rs);
    postconditionsModel.addRenameListener(rs);

    // for validating cost/time expressions
    SymFocusAction fs = new SymFocusAction();
    costfield.addFocusListener(fs);
    timefield.addFocusListener(fs);

    // for supporting attribute tree creation for cost and time fields
    SymMouseAction ms  = new SymMouseAction();
    costfield.addMouseListener(ms);
    timefield.addMouseListener(ms);

  }

  protected class SymFocusAction implements FocusListener {
    public void focusLost(FocusEvent e) {
       LargeTextField field = (LargeTextField)e.getSource();
       validate(field);
    }
    public void focusGained(FocusEvent e) {
       LargeTextField field = (LargeTextField)e.getSource();
       field.setForeground(Color.black);
    }
    protected void validate(LargeTextField field) {
       String s = field.getText();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -