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

📄 coordinationpanel.java

📁 人工智能中Agent开发包。多 Agent 系统是处理自治 Agent 之间知识层的协作问题
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      button.setHorizontalAlignment(JButton.LEFT);
      button.setBorderPainted(false);
      button.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
      Object src = e.getSource();
      if ( src == button ) {
         dialog.setSelection((String[])value);
         dialog.setLocationRelativeTo(button);
         fireEditingCanceled();
         Object[] items = dialog.getSelection();
         strategyModel.setValueAt(Misc.stringArray(items),row,column);
      }
      repaint(); 
    }
    public Component getTableCellEditorComponent(JTable table, Object value,
                                                 boolean isSelected,
                                                 int row, int column) {
      this.row = row;
      this.column = column;
      this.value = value;
      return button;
    }
  }

  class StringArrayCellRenderer extends DefaultTableCellRenderer {
     public void setValue(Object value) {
        String text = Misc.concat((String[])value);
        super.setValue(text);
     }
  }

  class FriendlyRenderer extends DefaultTableCellRenderer {
     public void setValue(Object value) {
        if ( value == null )
           super.setValue(value);
        else {
           String name = SystemProps.getProperty("friendly.name." + value,
              (String)value);
           super.setValue(name);
        }
     }
  }


  class HashtableCellRenderer extends DefaultTableCellRenderer {
     public void setValue(Object input) {
        if ( input == null )
           super.setValue(input);
        else {
           Hashtable table = (Hashtable)input;
           Enumeration enum = table.keys();
           String key, value;
           String result = "";
           while( enum.hasMoreElements() ) {
              key = (String)enum.nextElement();
              value = (String)table.get(key);
              result += key + "=" + value + " ";
           }
           super.setValue(result.trim());
        }
     }
  }

  class HashtableCellEditor extends DefaultCellEditor
                            implements ActionListener, ParameterChooser {

    protected JButton button = new JButton("");
    protected int row, column;
    protected ParameterDialog dialog;
    protected Hashtable value;

    public HashtableCellEditor() {
      super(new JTextField());
      setClickCountToStart(1);

      dialog = new ParameterDialog((Frame)SwingUtilities.getRoot(editor),
                                   "Set Parameters");

      button.setBackground(Color.white);
      button.setHorizontalAlignment(JButton.LEFT);
      button.setBorderPainted(false);
      button.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
      Object src = e.getSource();
      if ( src == button ) {
         dialog.setLocationRelativeTo(button);
         fireEditingCanceled();
         dialog.display(this,value);
         repaint(); 
      }
      repaint(); 
    }

    public void parametersChanged(Hashtable input) {
         strategyModel.setValueAt(input,row,column);
         repaint(); 
    }

    public Component getTableCellEditorComponent(JTable table, Object value,
                                                 boolean isSelected,
                                                 int row, int column) {

      this.row = row;
      this.column = column;
      this.value = (Hashtable)value;
      repaint(); 
      return button;
    }
  }


  class StrategyToolBar extends JToolBar
                    implements ActionListener,
                               FactSelector {

     protected FactDialog    factWin;
     protected HelpWindow    helpWin;
     protected JToggleButton helpBtn;
     protected JButton       newBtn;
     protected JButton       deleteBtn;
     protected JButton       cutBtn;
     protected JButton       copyBtn;
     protected JButton       pasteBtn;
     protected JButton       allBtn;

     public StrategyToolBar() {
        setBackground(Color.lightGray);
        setBorder(new BevelBorder(BevelBorder.LOWERED));
        setFloatable(false);

        String sep = System.getProperty("file.separator");
        String path = SystemProps.getProperty("gif.dir") + "generator" + sep;

        // New Button
        newBtn = new JButton(new ImageIcon(path + "new1.gif"));
	newBtn.setMargin(new Insets(0,0,0,0));
        add(newBtn);
        newBtn.setToolTipText("New");
        newBtn.addActionListener(this);

        // All Button
        allBtn = new JButton(new ImageIcon(path + "all.gif"));
	allBtn.setMargin(new Insets(0,0,0,0));
        add(allBtn);
        allBtn.setToolTipText("Set list of agents to any");
        allBtn.addActionListener(this);

        addSeparator();

        // Delete Button
        deleteBtn = new JButton(new ImageIcon(path + "delete1.gif"));
	deleteBtn.setMargin(new Insets(0,0,0,0));
        add(deleteBtn);
        deleteBtn.setToolTipText("Delete");
        deleteBtn.addActionListener(this);

        addSeparator();

        // Cut Button
        cutBtn = new JButton(new ImageIcon(path + "cut.gif"));
	cutBtn.setMargin(new Insets(0,0,0,0));
        add(cutBtn);
        cutBtn.setToolTipText("Cut");
        cutBtn.addActionListener(this);

        // Copy Button
        copyBtn = new JButton(new ImageIcon(path + "copy.gif"));
	copyBtn.setMargin(new Insets(0,0,0,0));
        add(copyBtn);
        copyBtn.setToolTipText("Copy");
        copyBtn.addActionListener(this);

        // Paste Button
        pasteBtn = new JButton(new ImageIcon(path + "paste.gif"));
	pasteBtn.setMargin(new Insets(0,0,0,0));
        add(pasteBtn);
        pasteBtn.setToolTipText("Paste");
        pasteBtn.addActionListener(this);

        addSeparator();

        // Help Button
        helpBtn = new JToggleButton(new ImageIcon(path + "help.gif"));
	helpBtn.setMargin(new Insets(0,0,0,0));
        add(helpBtn);
        helpBtn.setToolTipText("Help");
        helpBtn.addActionListener(this);

        factWin = new FactDialog((Frame)SwingUtilities.getRoot(this),
                                 ontologyDb);
     }

     public void setEnabled(boolean set) {
        newBtn.setEnabled(set);
        allBtn.setEnabled(set);
        deleteBtn.setEnabled(set);
        cutBtn.setEnabled(set);
        copyBtn.setEnabled(set);
        pasteBtn.setEnabled(set);
     }

     public void factSelected(String[] names)  {
        // Fact Selector callback to add new entries
        strategyModel.addNewRows(names);
     }

     public void actionPerformed(ActionEvent e)  {
        Object src = e.getSource();
        if ( src == newBtn ) {
           factWin.setLocationRelativeTo(newBtn);
           factWin.display(this);
        }
        else if ( src == allBtn ) {
           allowAllAgents();
        }
        else if ( src == deleteBtn ) {
           deleteSelectedRow();
        }
        else if ( src == copyBtn ) {
           clipboard = getSelectedRows();
        }
        else if ( src == pasteBtn ) {
           strategyModel.addRows(clipboard);
           strategyTable.clearSelection();
        }
        else if ( src == cutBtn ) {
           clipboard = cutSelectedRows();
        }
        else if ( src == helpBtn ) {
          if ( helpBtn.isSelected() ) {
              Point dispos = getLocation();
              helpWin = new HelpWindow(SwingUtilities.getRoot(this),
                 dispos, "generator", "Activity Coord-2");
              helpWin.setSource(helpBtn);
          }
          else
              helpWin.dispose();
        }
        repaint();
     }
  }

  protected class CheckBoxCellRenderer extends JCheckBox
                                       implements TableCellRenderer,
                                       java.io.Serializable {

     public CheckBoxCellRenderer() {
        setHorizontalAlignment(JCheckBox.CENTER);
     }

     public Component getTableCellRendererComponent(JTable table,
        Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {

        if ( value != null )
           this.setSelected(((Boolean)value).booleanValue());
        return this;
     }
  }

  protected class ProtocolToolBar extends JToolBar
                                  implements ActionListener {

     protected JToggleButton helpBtn;
     protected JButton       clearBtn;
     protected JButton       allBtn;
     protected HelpWindow    helpWin;

     public ProtocolToolBar() {
        setBackground(Color.lightGray);
        setBorder( new BevelBorder(BevelBorder.LOWERED ) );
        setFloatable(false);
        String path = SystemProps.getProperty("gif.dir") + "generator" +
           System.getProperty("file.separator");

        // clear Button
        clearBtn = new JButton(new ImageIcon(path + "clear.gif" ));
	clearBtn.setMargin(new Insets(0,0,0,0));
        add(clearBtn);
        clearBtn.setToolTipText("Clear all protocols");
        clearBtn.addActionListener(this);

        // All Button
        allBtn = new JButton(new ImageIcon(path + "all.gif"));
	allBtn.setMargin(new Insets(0,0,0,0));
        add(allBtn);
        allBtn.setToolTipText("Select all protocols");
        allBtn.addActionListener(this);

        addSeparator();

        // Help Button
        helpBtn = new JToggleButton(new ImageIcon(path + "help.gif"));
	helpBtn.setMargin(new Insets(0,0,0,0));
        add(helpBtn);
        helpBtn.setToolTipText("Help");
        helpBtn.addActionListener(this);
     }

     public void actionPerformed(ActionEvent e) {
        Object src = e.getSource();
        if ( src == clearBtn ) {
           for(int i = 0; i < protocolModel.getRowCount(); i++ )
              protocolModel.setValueAt(Boolean.FALSE,i,ProtocolModel.STATE);
        }
        else if ( src == allBtn ) {
           for(int i = 0; i < protocolModel.getRowCount(); i++ )
              protocolModel.setValueAt(Boolean.TRUE,i,ProtocolModel.STATE);
        }
        else if ( src == helpBtn ) {
           if ( helpBtn.isSelected() ) {
              Point dispos = getLocation();
              helpWin = new HelpWindow(SwingUtilities.getRoot(this),
                                       dispos, "generator",
                                       "Activity Coord-1");
              helpWin.setSource(helpBtn);
           }
           else {
              helpWin.dispose();
           }
        }
     } 
  }

  protected void errorMsg(int tag) {
     JOptionPane.showMessageDialog(this,ERROR_MESSAGE[tag],
                                   "Error", JOptionPane.ERROR_MESSAGE);
  }

  protected void allowAllAgents() {
     if ( !isRowSelected() ) return;
     int row = strategyTable.getSelectedRow();
     strategyModel.setValueAt(StrategyModel.ALL,row,StrategyModel.AGENTS);
  }
  protected Fact[] getSelectedRows()  {
    int[] rows = strategyTable.getSelectedRows();
    Fact[] data = new Fact[rows.length];
    for(int i = 0; i < rows.length; i++)
       data[i] = (Fact)strategyModel.getValueAt(rows[i],StrategyModel.FACT);
    return data;
  }

  protected Fact[] cutSelectedRows()  {
     Fact[] data = getSelectedRows();
     strategyModel.removeRows(strategyTable.getSelectedRows());
     return data;
  }

  protected void deleteSelectedRow()  {
     if ( !isRowSelected() ) return;
     cutSelectedRows();
     // strategyTable.clearSelection();
  }

  protected boolean isRowSelected() {
     int row = strategyTable.getSelectedRow();
     if ( row == -1) {
        errorMsg(0);
        return false;
     }
     return true;
  }

  class SymListAction1 implements ListSelectionListener {
     public void valueChanged(ListSelectionEvent e) {
        int row = protocolTable.getSelectedRow();
        protocolModel.selectRow(row);
        if ( row != -1 ) {
          Boolean s =(Boolean)protocolModel.getValueAt(row,ProtocolModel.STATE);
          strategyToolBar.setEnabled(s.equals(Boolean.TRUE));
        }
     }
  }

  class SymListAction2 implements ListSelectionListener {
     public void valueChanged(ListSelectionEvent e) {
        strategyModel.selectRow(strategyTable.getSelectedRow());
     }
 
  }

  void save() {
    agent.setProtocols(protocolModel.getData());
  }

}

⌨️ 快捷键说明

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