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

📄 societypanel.java

📁 人工智能中Agent开发包。多 Agent 系统是处理自治 Agent 之间知识层的协作问题
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        else if ( src == showBtn )
           graph.show();
     }
  }

  class SocietyNodeEditor extends AbstractGraphNodeEditor
                          implements ActionListener {

     protected JButton button = new JButton("Click to edit");
     protected GraphNode node;
     protected Graph graph;
     protected FileDialog dialog = null;
 
     public SocietyNodeEditor() {
        button.setBackground(Color.lightGray);
        button.setHorizontalAlignment(JButton.CENTER);
        button.setBorderPainted(true);
        button.addActionListener(this);
        button.setOpaque(true);
        button.setMinimumSize(new Dimension(120,30));
        button.setPreferredSize(new Dimension(120,30));
        button.setSize(120,30);
     }
 
     public void actionPerformed(ActionEvent e) {
        Object src = e.getSource();
        if ( src == button ) {
           // Note: create dialog (using button) before stopping editing
           // which will remove the button from the visible component hierachy
           if ( dialog == null )
              dialog = new FileDialog((Frame)SwingUtilities.getRoot(button),
  	       "Select Icon File",FileDialog.LOAD);
  
           SocietyModelEntry agent = (SocietyModelEntry)node.getUserObject();
           String icon_file = agent.getIcon();
  
           if ( icon_file != null ) {
  	    File f1 = new File(icon_file);
              dialog.setFile(f1.getName());
              dialog.setDirectory(f1.getParent());
           }
           else
              dialog.setFile("*.gif");
  
           dialog.pack();
           dialog.setVisible(true);
  
           String path = (dialog.getFile() == null) ? null 
              : dialog.getDirectory() + File.separator + dialog.getFile();
           if ( path == null )
              fireEditAction(EDITING_CANCELLED,this.node,null);
           else
              fireEditAction(EDITING_STOPPED,this.node,path);
        }
     }
     public Component getNodeEditorComponent(Graph graph, GraphNode gnode) {
        this.graph = graph;
        this.node = gnode;
        return button;
     }
  }


  protected class SoceityControlPanel extends JPanel implements ItemListener {
     protected JCheckBox[]    checkbox;
     protected JRadioButton[] view;

     public SoceityControlPanel()  {
       String[] RELATIONS = Misc.stringArray(AcquaintanceModel.RELATIONS_LIST);

       checkbox = new JCheckBox[RELATIONS.length];
       view = new JRadioButton[RELATIONS.length];

       JPanel topPanel = new JPanel();
       TitledBorder border = (BorderFactory.createTitledBorder("View Style"));
       border.setTitlePosition(TitledBorder.TOP);
       border.setTitleJustification(TitledBorder.RIGHT);
       border.setTitleFont(new Font("Helvetica", Font.BOLD, 12));
       border.setTitleColor(Color.blue);
       topPanel.setBorder(border);
       topPanel.setBackground(Color.lightGray);

       GridBagLayout gb = new GridBagLayout();
       GridBagConstraints gbc = new GridBagConstraints();
       gbc.insets = new Insets(4,4,0,4);
       gbc.gridwidth = GridBagConstraints.REMAINDER;
       gbc.anchor = GridBagConstraints.NORTHWEST;
       topPanel.setLayout(gb);

       ButtonGroup alignGroup = new ButtonGroup();
       for(int i = 0; i < view.length; i++ ) {
          if ( i == 0 )
             view[i] = new JRadioButton("vertical",
                ((SocietyModel)graph.getModel()).getView() == i);
          else if ( i == 1 )
             view[i] = new JRadioButton("centered",
                ((SocietyModel)graph.getModel()).getView() == i);
          else
             view[i] = new JRadioButton(RELATIONS[i],
                ((SocietyModel)graph.getModel()).getView() == i);
          view[i].setBackground(Color.lightGray);
          alignGroup.add(view[i]);
          gb.setConstraints(view[i], gbc);
          topPanel.add(view[i]);
       }

       JPanel bottomPanel = new JPanel();
       border = (BorderFactory.createTitledBorder("Relational Links"));
       border.setTitlePosition(TitledBorder.TOP);
       border.setTitleJustification(TitledBorder.RIGHT);
       border.setTitleFont(new Font("Helvetica", Font.BOLD, 12));
       border.setTitleColor(Color.blue);
       bottomPanel.setBorder(border);
       bottomPanel.setBackground(Color.lightGray);

       gb = new GridBagLayout();
       gbc = new GridBagConstraints();
       bottomPanel.setLayout(gb);

       JPanel colorPanel;
       for(int i = 0; i < checkbox.length; i++ ) {
          checkbox[i] = new JCheckBox(RELATIONS[i]);
          checkbox[i].setBackground(Color.lightGray);
          colorPanel = new JPanel();
          colorPanel.setSize(10,10);
          colorPanel.setBackground(
             ((SocietyModel)graph.getModel()).getColor(i)
          );

          gbc.fill = GridBagConstraints.NONE;
          gbc.weightx = 0;
          gbc.anchor = GridBagConstraints.NORTHWEST;
          gbc.insets = new Insets(4,4,0,0);
          gbc.gridwidth = 1;
          gb.setConstraints(checkbox[i],gbc);
          bottomPanel.add(checkbox[i]);

          gbc.anchor = GridBagConstraints.EAST;
          gbc.insets = new Insets(4,0,0,4);
          gbc.gridwidth = GridBagConstraints.REMAINDER;
          gb.setConstraints(colorPanel,gbc);
          bottomPanel.add(colorPanel);
       }

       JPanel lowerBottomPanel = new JPanel();
       border = (BorderFactory.createTitledBorder("Message codes"));
       border.setTitlePosition(TitledBorder.TOP);
       border.setTitleJustification(TitledBorder.RIGHT);
       border.setTitleFont(new Font("Helvetica", Font.BOLD, 12));
       border.setTitleColor(Color.blue);
       lowerBottomPanel.setBorder(border);
       lowerBottomPanel.setBackground(Color.lightGray);

       gb = new GridBagLayout();
       gbc = new GridBagConstraints();
       lowerBottomPanel.setLayout(gb);

       JLabel label;
       String msg_type;
       Color color;
       Enumeration enum = AnimationManager.MessageColor.keys();
       while( enum.hasMoreElements() ) {
          msg_type = (String)enum.nextElement();
          color = (Color)AnimationManager.MessageColor.get(msg_type);
          label = new JLabel(msg_type,JLabel.LEFT);
          label.setBackground(Color.lightGray);
          colorPanel = new JPanel();
          colorPanel.setSize(10,10);
          colorPanel.setBackground(color);

          gbc.fill = GridBagConstraints.NONE;
          gbc.weightx = 0;
          gbc.anchor = GridBagConstraints.NORTHWEST;
          gbc.insets = new Insets(4,4,0,0);
          gbc.gridwidth = 1;
          gb.setConstraints(label,gbc);
          lowerBottomPanel.add(label);

          gbc.anchor = GridBagConstraints.EAST;
          gbc.insets = new Insets(4,0,0,4);
          gbc.gridwidth = GridBagConstraints.REMAINDER;
          gb.setConstraints(colorPanel,gbc);
          lowerBottomPanel.add(colorPanel);
       }

       gb = new GridBagLayout();
       gbc = new GridBagConstraints();
       setLayout(gb);
       gbc.insets = new Insets(0,0,0,0);
       gbc.gridwidth = GridBagConstraints.REMAINDER;
       gbc.anchor = GridBagConstraints.NORTHWEST;
       gbc.fill = GridBagConstraints.BOTH;
       gbc.weightx = gbc.weighty = 0;
       gb.setConstraints(topPanel,gbc);
       add(topPanel);

       gbc.weightx = gbc.weighty = 0;
       gb.setConstraints(bottomPanel,gbc);
       add(bottomPanel);

       gbc.weightx = gbc.weighty = 0;
       gb.setConstraints(lowerBottomPanel,gbc);
       add(lowerBottomPanel);

       for(int i = 0; i < checkbox.length; i++ ) {
          checkbox[i].setSelected(
             ((SocietyModel)graph.getModel()).isLinkVisible(i)
          );
          checkbox[i].addItemListener(this);
          view[i].addItemListener(this);
       }
     }

     public void itemStateChanged(ItemEvent evt) {
       Object source = evt.getSource();

       for(int i = 0; i < checkbox.length; i++ ) {
          if ( source == checkbox[i] ) {
             ((SocietyModel)graph.getModel()).showLinks(i,
                checkbox[i].isSelected());
             graph.redraw();
             return;
          }
          if ( source == view[i] ) {
             switch( i ) {
                case 0:
                     graph.setViewMode(Graph.VERTICAL_PARENT_CHILD);
                     break;
                case 1:
                     graph.setViewMode(Graph.CENTRED);
                     break;
                default:
                     graph.setViewMode(Graph.CIRCLES);
                     break;
             }
             ((SocietyModel)graph.getModel()).setView(i);
             graph.recompute();
             return;
          }
       }
     }
  }

}

⌨️ 快捷键说明

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