View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  /*****************************************************************************
25  * CoordinationPanel.java
26  *
27  * Panel through which coordination protocol are entered
28  * (In future it will also allow them to be defined)
29  ***************************************************************************/
30  
31  package zeus.generator.agent;
32  
33  import java.util.*;
34  import java.awt.*;
35  import java.awt.event.*;
36  import javax.swing.*;
37  import javax.swing.border.*;
38  import javax.swing.table.*;
39  import javax.swing.event.*;
40  
41  import zeus.generator.*;
42  import zeus.generator.util.*;
43  import zeus.ontology.*;
44  import zeus.util.*;
45  import zeus.concepts.*;
46  import zeus.gui.help.*;
47  import zeus.gui.*;
48  /*** 
49      CoordinationPanel is the thing that you interact with in the 
50      zeus.generator.AgentBuilder to arrange co-ordination methods for agents
51      */
52  public class CoordinationPanel extends JPanel {
53    static final String[] ERROR_MESSAGE = {
54       /* 0 */ "Please select a row before\ncalling this operation"
55    };
56  
57    protected ControlPanel     controlPane;
58    protected AgentDescription agent;
59    protected ProtocolModel    protocolModel;
60    protected JTable           protocolTable;
61    protected StrategyToolBar  strategyToolBar;
62    protected AttributeModel   attributeModel;
63    protected JTable           strategyTable;
64    protected StrategyModel    strategyModel;
65    protected Fact[]           clipboard = null;
66    protected OntologyDb       ontologyDb;
67    protected GeneratorModel   genmodel;
68    protected AgentEditor      editor;
69  
70    public CoordinationPanel(AgentGenerator generator,
71                             GeneratorModel genmodel,
72                             OntologyDb ontologyDb,
73                             AgentEditor editor,
74                             AgentDescription agent)  {
75  
76       this.agent = agent;
77       this.genmodel = genmodel;
78       this.ontologyDb = ontologyDb;
79       this.editor = editor;
80  
81       GridBagLayout gridBagLayout = new GridBagLayout();
82       GridBagConstraints gbc = new GridBagConstraints();
83       setLayout(gridBagLayout);
84       setBackground(Color.lightGray);
85  
86       setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
87       controlPane = new ControlPanel(editor,"Agent Coordination Panel",false,false);
88  	
89       gbc.gridwidth = GridBagConstraints.REMAINDER;
90       gbc.anchor = GridBagConstraints.NORTHWEST;
91       gbc.fill = GridBagConstraints.HORIZONTAL;
92       gbc.insets = new Insets(8,8,8,8);
93       gridBagLayout.setConstraints(controlPane,gbc);
94       add(controlPane);
95  
96       // Add the panel containing the agent's protocol to the panel.
97       JPanel protocolPanel = new JPanel();
98       gbc.anchor = GridBagConstraints.NORTHWEST;
99       gbc.fill = GridBagConstraints.BOTH;
100      gbc.gridwidth = GridBagConstraints.REMAINDER;
101      gbc.insets = new Insets(8,8,8,8);
102      gbc.weightx = gbc.weighty = 1;
103      gridBagLayout.setConstraints(protocolPanel,gbc);
104      add(protocolPanel);
105 	
106      // create Strategies info
107      JPanel strategyPanel = new JPanel();
108      gbc.anchor = GridBagConstraints.NORTHWEST;
109      gbc.fill = GridBagConstraints.BOTH;
110      gbc.weightx = gbc.weighty = 1;
111      gbc.insets = new Insets(8,8,8,8);
112      gridBagLayout.setConstraints(strategyPanel,gbc);
113      add(strategyPanel);
114 
115      // Create Protocol info
116      AttributeModel attributeModel = new AttributeModel();
117      AttributeTable attributePanel = new AttributeTable(attributeModel);
118      strategyModel = new StrategyModel(genmodel,ontologyDb,attributeModel);
119 
120      protocolModel = new ProtocolModel(ontologyDb,strategyModel,agent.getProtocols());
121 
122      protocolModel.addChangeListener(editor);
123      attributeModel.addChangeListener(editor);
124      strategyModel.addChangeListener(editor);
125 
126      TableColumnModel tm = new DefaultTableColumnModel();
127      TableColumn column;
128      column = new TableColumn(ProtocolModel.TYPE,24);
129      column.setHeaderValue(protocolModel.getColumnName(ProtocolModel.TYPE));
130      tm.addColumn(column);
131      column = new TableColumn(ProtocolModel.PROTOCOL,24,
132         new FriendlyRenderer(), new DefaultCellEditor(new JTextField()));
133      column.setHeaderValue(protocolModel.getColumnName(ProtocolModel.PROTOCOL));
134      tm.addColumn(column);
135      JCheckBox checkbox = new JCheckBox();
136      checkbox.setHorizontalAlignment(JCheckBox.CENTER);
137      DefaultCellEditor cellEditor = new DefaultCellEditor(checkbox);
138      checkbox.addItemListener(new SymItemAction());
139      column = new TableColumn(ProtocolModel.STATE,8,
140         new CheckBoxCellRenderer(), cellEditor);
141      column.setHeaderValue(protocolModel.getColumnName(ProtocolModel.STATE));
142      tm.addColumn(column);
143 
144      protocolTable = new JTable(protocolModel,tm);
145      protocolTable.getTableHeader().setReorderingAllowed(false);
146      protocolTable.setColumnSelectionAllowed(false);
147 
148      ListSelectionModel selectionModel = protocolTable.getSelectionModel();
149      selectionModel.addListSelectionListener(new SymListAction1());
150 
151      TitledBorder border = BorderFactory.createTitledBorder("Coordination Protocols");
152      border.setTitlePosition(TitledBorder.TOP);
153      border.setTitleJustification(TitledBorder.RIGHT);
154      border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
155      border.setTitleColor(Color.blue);
156      protocolPanel.setBorder(border);
157 
158      gridBagLayout = new GridBagLayout();
159      protocolPanel.setLayout(gridBagLayout);
160      protocolPanel.setBackground(Color.lightGray);
161 
162      JToolBar toolbar = new ProtocolToolBar();
163      gbc = new GridBagConstraints();
164      gbc.anchor = GridBagConstraints.NORTHWEST;
165      gbc.fill = GridBagConstraints.NONE;
166      gbc.gridwidth = GridBagConstraints.REMAINDER;
167      gbc.insets = new Insets(0,8,0,0);
168      gridBagLayout.setConstraints(toolbar,gbc);
169      protocolPanel.add(toolbar);
170 
171      JScrollPane scrollPane = new JScrollPane(protocolTable);
172      scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
173      scrollPane.setMinimumSize(new Dimension(160,80));
174      scrollPane.setPreferredSize(new Dimension(200,80));
175      protocolTable.setBackground(Color.white);
176 
177      gbc = new GridBagConstraints();
178      gbc.gridwidth = GridBagConstraints.REMAINDER;
179      gbc.anchor = GridBagConstraints.NORTHWEST;
180      gbc.fill = GridBagConstraints.BOTH;
181      gbc.weightx = gbc.weighty = 1;
182      gbc.insets = new Insets(8,8,8,8);
183      gridBagLayout.setConstraints(scrollPane,gbc);
184      protocolPanel.add(scrollPane);
185 
186      // Create strategy panel info
187      gridBagLayout = new GridBagLayout();
188      strategyPanel.setLayout(gridBagLayout);
189      strategyPanel.setBackground(Color.lightGray);
190 
191      tm = new DefaultTableColumnModel();
192      JCheckBox checkbox1 = new JCheckBox();
193      checkbox1.setHorizontalAlignment(JCheckBox.CENTER);
194      column = new TableColumn(StrategyModel.MODE,4,
195         new CheckBoxCellRenderer(), new DefaultCellEditor(checkbox1));
196      column.setHeaderValue(strategyModel.getColumnName(StrategyModel.MODE));
197      tm.addColumn(column);
198 
199      column = new TableColumn(StrategyModel.TYPE,12);
200      column.setHeaderValue(strategyModel.getColumnName(StrategyModel.TYPE));
201      tm.addColumn(column);
202 
203      column = new TableColumn(StrategyModel.AGENTS,24,
204         new StringArrayCellRenderer(), new AgentCellEditor());
205      column.setHeaderValue(strategyModel.getColumnName(StrategyModel.AGENTS));
206      tm.addColumn(column);
207 
208      column = new TableColumn(StrategyModel.RELATIONS,24,
209         new StringArrayCellRenderer(), new RelationsCellEditor());
210      column.setHeaderValue(strategyModel.getColumnName(StrategyModel.RELATIONS));
211      tm.addColumn(column);
212 
213      column = new TableColumn(StrategyModel.STRATEGY,24,
214         new FriendlyRenderer(), new StrategyCellEditor());
215      column.setHeaderValue(strategyModel.getColumnName(StrategyModel.STRATEGY));
216      tm.addColumn(column);
217 
218      column = new TableColumn(StrategyModel.PARAMETERS,24,
219         new HashtableCellRenderer(), new HashtableCellEditor());
220      column.setHeaderValue(strategyModel.getColumnName(StrategyModel.PARAMETERS));
221      tm.addColumn(column);
222 
223      strategyTable = new JTable(strategyModel,tm);
224      strategyTable.getTableHeader().setReorderingAllowed(false);
225      strategyTable.setColumnSelectionAllowed(false);
226 
227      selectionModel = strategyTable.getSelectionModel();
228      selectionModel.addListSelectionListener(new SymListAction2());
229 
230      scrollPane = new JScrollPane(strategyTable);
231      scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
232      scrollPane.setPreferredSize(new Dimension(400,100));
233      strategyTable.setBackground(Color.white);
234 
235      border = (BorderFactory.createTitledBorder("Coordination Strategies"));
236      border.setTitlePosition(TitledBorder.TOP);
237      border.setTitleJustification(TitledBorder.RIGHT);
238      border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
239      border.setTitleColor(Color.blue);
240      strategyPanel.setBorder(border);
241 
242      gbc = new GridBagConstraints();
243      strategyToolBar = new StrategyToolBar();
244 
245      gbc.gridwidth = GridBagConstraints.REMAINDER;
246      gbc.anchor = GridBagConstraints.WEST;
247      gbc.fill = GridBagConstraints.NONE;
248      gbc.weightx = gbc.weighty = 0;
249      gbc.insets = new Insets(0,8,0,0);
250      gridBagLayout.setConstraints(strategyToolBar,gbc);
251      strategyPanel.add(strategyToolBar);
252 
253      gbc.gridwidth = GridBagConstraints.REMAINDER;
254      gbc.anchor = GridBagConstraints.WEST;
255      gbc.fill = GridBagConstraints.BOTH;
256      gbc.weightx = gbc.weighty = 1;
257      gbc.insets = new Insets(8,8,8,8);
258      gridBagLayout.setConstraints(scrollPane,gbc);
259      strategyPanel.add(scrollPane);
260 
261      gbc.gridwidth = GridBagConstraints.REMAINDER;
262      gbc.anchor = GridBagConstraints.WEST;
263      gbc.fill = GridBagConstraints.BOTH;
264      gbc.weightx = gbc.weighty = 1;
265      gbc.insets = new Insets(8,8,8,8);
266      gridBagLayout.setConstraints(attributePanel,gbc);
267      strategyPanel.add(attributePanel);
268 
269      strategyToolBar.setEnabled(false);
270   }
271 
272   class SymItemAction implements ItemListener {
273      public void itemStateChanged(ItemEvent e) {
274         strategyToolBar.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
275         repaint(); 
276      }
277   }
278 
279   class StrategyCellEditor extends DefaultCellEditor {
280      public StrategyCellEditor() {
281         super( new JComboBox() {
282                       public void contentsChanged(ListDataEvent e) {
283                          selectedItemReminder = null;
284                          super.contentsChanged(e);
285                       }
286                }
287         );
288         JComboBox combo = (JComboBox)editorComponent;
289         DefaultListCellRenderer renderer = new DefaultListCellRenderer() {
290            public Component getListCellRendererComponent(JList list,
291               Object value, int index, boolean isSelected, boolean hasFocus)  {
292 
293               if ( value != null )
294                  value = SystemProps.getProperty("friendly.name." + value,
295                     (String)value);
296               return super.getListCellRendererComponent(
297                  list, value, index, isSelected, hasFocus);
298            }
299         };
300         combo.setRenderer(renderer);
301         setClickCountToStart(2);
302      }
303      public Component getTableCellEditorComponent(JTable table, Object value,
304                                                  boolean isSelected,
305                                                  int row, int column) {
306         Vector List = null;
307         JComboBox combo = (JComboBox)editorComponent;
308         if ( combo.getModel().getSize() != 0 )
309            combo.removeAllItems();
310         String type = (String)protocolModel.getValueAt(
311            protocolTable.getSelectedRow(),ProtocolModel.TYPE);
312         if ( type.equals(ProtocolInfo.INITIATOR) )
313            List = StrategyModel.INITIATOR_STRATEGY_LIST;
314         else
315            List = StrategyModel.RESPONDENT_STRATEGY_LIST;
316         for(int i = 0; i < List.size(); i++ )
317            combo.addItem(List.elementAt(i));
318         return super.getTableCellEditorComponent(table, value, isSelected,
319                                                  row, column);
320 
321      }
322   }
323 
324   class AgentCellEditor extends DefaultCellEditor
325                              implements ActionListener {
326 
327     protected JButton button = new JButton("");
328     protected int row, column;
329     protected EditableMultipleSelectionDialog dialog;
330     protected Object value;
331 
332     public AgentCellEditor() {
333       super(new JTextField());
334 
335       setClickCountToStart(2);
336 
337       dialog = new EditableMultipleSelectionDialog(
338          (Frame)SwingUtilities.getRoot(editor),"Select Agents");
339 
340       button.setBackground(Color.white);
341       button.setHorizontalAlignment(JButton.LEFT);
342       button.setBorderPainted(false);
343       button.addActionListener(this);
344     }
345 
346     public void actionPerformed(ActionEvent e) {
347       Object src = e.getSource();
348       if ( src == button ) {
349          String[] data = genmodel.getAgentNames();
350          Vector items = Misc.stringVector(data);
351          items.removeElement(editor.getObjectName());
352          data = Misc.stringArray(items);
353          dialog.setListData(data);
354          dialog.setSelection((String[])value);
355          dialog.setLocationRelativeTo(button);
356          fireEditingCanceled();
357          Object[] output = dialog.getSelection();
358          strategyModel.setValueAt(Misc.stringArray(output),row,column);
359       }
360       repaint(); 
361     }
362     
363     
364     public Component getTableCellEditorComponent(JTable table, Object value,
365                                                  boolean isSelected,
366                                                  int row, int column) {
367       this.row = row;
368       this.column = column;
369       this.value = value;
370       return button;
371     }
372   }
373 
374   class RelationsCellEditor extends DefaultCellEditor
375                              implements ActionListener {
376 
377     protected JButton button = new JButton("");
378     protected int row, column;
379     protected MultipleSelectionDialog dialog;
380     protected Object value;
381 
382     public RelationsCellEditor() {
383       super(new JTextField());
384 
385       setClickCountToStart(2);
386 
387       dialog = new MultipleSelectionDialog(
388          (Frame)SwingUtilities.getRoot(editor), "Select Relations");
389       dialog.setListData(Misc.stringArray(AcquaintanceModel.RELATIONS_LIST));
390 
391       button.setBackground(Color.white);
392       button.setHorizontalAlignment(JButton.LEFT);
393       button.setBorderPainted(false);
394       button.addActionListener(this);
395     }
396 
397     public void actionPerformed(ActionEvent e) {
398       Object src = e.getSource();
399       if ( src == button ) {
400          dialog.setSelection((String[])value);
401          dialog.setLocationRelativeTo(button);
402          fireEditingCanceled();
403          Object[] items = dialog.getSelection();
404          strategyModel.setValueAt(Misc.stringArray(items),row,column);
405       }
406       repaint(); 
407     }
408     public Component getTableCellEditorComponent(JTable table, Object value,
409                                                  boolean isSelected,
410                                                  int row, int column) {
411       this.row = row;
412       this.column = column;
413       this.value = value;
414       return button;
415     }
416   }
417 
418   class StringArrayCellRenderer extends DefaultTableCellRenderer {
419      public void setValue(Object value) {
420         String text = Misc.concat((String[])value);
421         super.setValue(text);
422      }
423   }
424 
425   class FriendlyRenderer extends DefaultTableCellRenderer {
426      public void setValue(Object value) {
427         if ( value == null )
428            super.setValue(value);
429         else {
430            String name = SystemProps.getProperty("friendly.name." + value,
431               (String)value);
432            super.setValue(name);
433         }
434      }
435   }
436 
437 
438   class HashtableCellRenderer extends DefaultTableCellRenderer {
439      public void setValue(Object input) {
440         if ( input == null )
441            super.setValue(input);
442         else {
443            Hashtable table = (Hashtable)input;
444            Enumeration enum = table.keys();
445            String key, value;
446            String result = "";
447            while( enum.hasMoreElements() ) {
448               key = (String)enum.nextElement();
449               value = (String)table.get(key);
450               result += key + "=" + value + " ";
451            }
452            super.setValue(result.trim());
453         }
454      }
455   }
456 
457   class HashtableCellEditor extends DefaultCellEditor
458                             implements ActionListener, ParameterChooser {
459 
460     protected JButton button = new JButton("");
461     protected int row, column;
462     protected ParameterDialog dialog;
463     protected Hashtable value;
464 
465     public HashtableCellEditor() {
466       super(new JTextField());
467       setClickCountToStart(1);
468 
469       dialog = new ParameterDialog((Frame)SwingUtilities.getRoot(editor),
470                                    "Set Parameters");
471 
472       button.setBackground(Color.white);
473       button.setHorizontalAlignment(JButton.LEFT);
474       button.setBorderPainted(false);
475       button.addActionListener(this);
476     }
477 
478     public void actionPerformed(ActionEvent e) {
479       Object src = e.getSource();
480       if ( src == button ) {
481          dialog.setLocationRelativeTo(button);
482          fireEditingCanceled();
483          dialog.display(this,value);
484          repaint(); 
485       }
486       repaint(); 
487     }
488 
489     public void parametersChanged(Hashtable input) {
490          strategyModel.setValueAt(input,row,column);
491          repaint(); 
492     }
493 
494     public Component getTableCellEditorComponent(JTable table, Object value,
495                                                  boolean isSelected,
496                                                  int row, int column) {
497 
498       this.row = row;
499       this.column = column;
500       this.value = (Hashtable)value;
501       repaint(); 
502       return button;
503     }
504   }
505 
506 
507   class StrategyToolBar extends JToolBar
508                     implements ActionListener,
509                                FactSelector {
510 
511      protected FactDialog    factWin;
512      protected HelpWindow    helpWin;
513      protected JToggleButton helpBtn;
514      protected JButton       newBtn;
515      protected JButton       deleteBtn;
516      protected JButton       cutBtn;
517      protected JButton       copyBtn;
518      protected JButton       pasteBtn;
519      protected JButton       allBtn;
520 
521      public StrategyToolBar() {
522         setBackground(Color.lightGray);
523         setBorder(new BevelBorder(BevelBorder.LOWERED));
524         setFloatable(false);
525 
526         String sep = System.getProperty("file.separator");
527         String path = SystemProps.getProperty("gif.dir") + "generator" + sep;
528 
529         // New Button
530         newBtn = new JButton(new ImageIcon(path + "new1.gif"));
531 	newBtn.setMargin(new Insets(0,0,0,0));
532         add(newBtn);
533         newBtn.setToolTipText("New");
534         newBtn.addActionListener(this);
535 
536         // All Button
537         allBtn = new JButton(new ImageIcon(path + "all.gif"));
538 	allBtn.setMargin(new Insets(0,0,0,0));
539         add(allBtn);
540         allBtn.setToolTipText("Set list of agents to any");
541         allBtn.addActionListener(this);
542 
543         addSeparator();
544 
545         // Delete Button
546         deleteBtn = new JButton(new ImageIcon(path + "delete1.gif"));
547 	deleteBtn.setMargin(new Insets(0,0,0,0));
548         add(deleteBtn);
549         deleteBtn.setToolTipText("Delete");
550         deleteBtn.addActionListener(this);
551 
552         addSeparator();
553 
554         // Cut Button
555         cutBtn = new JButton(new ImageIcon(path + "cut.gif"));
556 	cutBtn.setMargin(new Insets(0,0,0,0));
557         add(cutBtn);
558         cutBtn.setToolTipText("Cut");
559         cutBtn.addActionListener(this);
560 
561         // Copy Button
562         copyBtn = new JButton(new ImageIcon(path + "copy.gif"));
563 	copyBtn.setMargin(new Insets(0,0,0,0));
564         add(copyBtn);
565         copyBtn.setToolTipText("Copy");
566         copyBtn.addActionListener(this);
567 
568         // Paste Button
569         pasteBtn = new JButton(new ImageIcon(path + "paste.gif"));
570 	pasteBtn.setMargin(new Insets(0,0,0,0));
571         add(pasteBtn);
572         pasteBtn.setToolTipText("Paste");
573         pasteBtn.addActionListener(this);
574 
575         addSeparator();
576 
577         // Help Button
578         helpBtn = new JToggleButton(new ImageIcon(path + "help.gif"));
579 	helpBtn.setMargin(new Insets(0,0,0,0));
580         add(helpBtn);
581         helpBtn.setToolTipText("Help");
582         helpBtn.addActionListener(this);
583 
584         factWin = new FactDialog((Frame)SwingUtilities.getRoot(this),
585                                  ontologyDb);
586      }
587 
588      public void setEnabled(boolean set) {
589         newBtn.setEnabled(set);
590         allBtn.setEnabled(set);
591         deleteBtn.setEnabled(set);
592         cutBtn.setEnabled(set);
593         copyBtn.setEnabled(set);
594         pasteBtn.setEnabled(set);
595      }
596 
597      public void factSelected(String[] names)  {
598         // Fact Selector callback to add new entries
599         strategyModel.addNewRows(names);
600      }
601 
602      public void actionPerformed(ActionEvent e)  {
603         Object src = e.getSource();
604         if ( src == newBtn ) {
605            factWin.setLocationRelativeTo(newBtn);
606            factWin.display(this);
607         }
608         else if ( src == allBtn ) {
609            allowAllAgents();
610         }
611         else if ( src == deleteBtn ) {
612            deleteSelectedRow();
613         }
614         else if ( src == copyBtn ) {
615            clipboard = getSelectedRows();
616         }
617         else if ( src == pasteBtn ) {
618            strategyModel.addRows(clipboard);
619            strategyTable.clearSelection();
620         }
621         else if ( src == cutBtn ) {
622            clipboard = cutSelectedRows();
623         }
624         else if ( src == helpBtn ) {
625           if ( helpBtn.isSelected() ) {
626               Point dispos = getLocation();
627               helpWin = new HelpWindow(SwingUtilities.getRoot(this),
628                  dispos, "generator", "Activity Coord-2");
629               helpWin.setSource(helpBtn);
630           }
631           else
632               helpWin.dispose();
633         }
634         repaint();
635      }
636   }
637 
638   protected class CheckBoxCellRenderer extends JCheckBox
639                                        implements TableCellRenderer,
640                                        java.io.Serializable {
641 
642      public CheckBoxCellRenderer() {
643         setHorizontalAlignment(JCheckBox.CENTER);
644      }
645 
646      public Component getTableCellRendererComponent(JTable table,
647         Object value, boolean isSelected, boolean hasFocus,
648         int row, int column) {
649 
650         if ( value != null )
651            this.setSelected(((Boolean)value).booleanValue());
652         return this;
653      }
654   }
655 
656   protected class ProtocolToolBar extends JToolBar
657                                   implements ActionListener {
658 
659      protected JToggleButton helpBtn;
660      protected JButton       clearBtn;
661      protected JButton       allBtn;
662      protected HelpWindow    helpWin;
663 
664      public ProtocolToolBar() {
665         setBackground(Color.lightGray);
666         setBorder( new BevelBorder(BevelBorder.LOWERED ) );
667         setFloatable(false);
668         String path = SystemProps.getProperty("gif.dir") + "generator" +
669            System.getProperty("file.separator");
670 
671         // clear Button
672         clearBtn = new JButton(new ImageIcon(path + "clear.gif" ));
673 	clearBtn.setMargin(new Insets(0,0,0,0));
674         add(clearBtn);
675         clearBtn.setToolTipText("Clear all protocols");
676         clearBtn.addActionListener(this);
677 
678         // All Button
679         allBtn = new JButton(new ImageIcon(path + "all.gif"));
680 	allBtn.setMargin(new Insets(0,0,0,0));
681         add(allBtn);
682         allBtn.setToolTipText("Select all protocols");
683         allBtn.addActionListener(this);
684 
685         addSeparator();
686 
687         // Help Button
688         helpBtn = new JToggleButton(new ImageIcon(path + "help.gif"));
689 	helpBtn.setMargin(new Insets(0,0,0,0));
690         add(helpBtn);
691         helpBtn.setToolTipText("Help");
692         helpBtn.addActionListener(this);
693      }
694 
695      public void actionPerformed(ActionEvent e) {
696         Object src = e.getSource();
697         if ( src == clearBtn ) {
698            for(int i = 0; i < protocolModel.getRowCount(); i++ )
699               protocolModel.setValueAt(Boolean.FALSE,i,ProtocolModel.STATE);
700         }
701         else if ( src == allBtn ) {
702            for(int i = 0; i < protocolModel.getRowCount(); i++ )
703               protocolModel.setValueAt(Boolean.TRUE,i,ProtocolModel.STATE);
704         }
705         else if ( src == helpBtn ) {
706            if ( helpBtn.isSelected() ) {
707               Point dispos = getLocation();
708               helpWin = new HelpWindow(SwingUtilities.getRoot(this),
709                                        dispos, "generator",
710                                        "Activity Coord-1");
711               helpWin.setSource(helpBtn);
712            }
713            else {
714               helpWin.dispose();
715            }
716         }
717      } 
718   }
719 
720   protected void errorMsg(int tag) {
721      JOptionPane.showMessageDialog(this,ERROR_MESSAGE[tag],
722                                    "Error", JOptionPane.ERROR_MESSAGE);
723   }
724 
725   protected void allowAllAgents() {
726      if ( !isRowSelected() ) return;
727      int row = strategyTable.getSelectedRow();
728      strategyModel.setValueAt(StrategyModel.ALL,row,StrategyModel.AGENTS);
729   }
730   protected Fact[] getSelectedRows()  {
731     int[] rows = strategyTable.getSelectedRows();
732     Fact[] data = new Fact[rows.length];
733     for(int i = 0; i < rows.length; i++)
734        data[i] = (Fact)strategyModel.getValueAt(rows[i],StrategyModel.FACT);
735     return data;
736   }
737 
738   protected Fact[] cutSelectedRows()  {
739      Fact[] data = getSelectedRows();
740      strategyModel.removeRows(strategyTable.getSelectedRows());
741      return data;
742   }
743 
744   protected void deleteSelectedRow()  {
745      if ( !isRowSelected() ) return;
746      cutSelectedRows();
747      // strategyTable.clearSelection();
748   }
749 
750   protected boolean isRowSelected() {
751      int row = strategyTable.getSelectedRow();
752      if ( row == -1) {
753         errorMsg(0);
754         return false;
755      }
756      return true;
757   }
758 
759   class SymListAction1 implements ListSelectionListener {
760      public void valueChanged(ListSelectionEvent e) {
761         int row = protocolTable.getSelectedRow();
762         protocolModel.selectRow(row);
763         if ( row != -1 ) {
764           Boolean s =(Boolean)protocolModel.getValueAt(row,ProtocolModel.STATE);
765           strategyToolBar.setEnabled(s.equals(Boolean.TRUE));
766         }
767      }
768   }
769 
770   class SymListAction2 implements ListSelectionListener {
771      public void valueChanged(ListSelectionEvent e) {
772         strategyModel.selectRow(strategyTable.getSelectedRow());
773      }
774  
775   }
776 
777   void save() {
778     agent.setProtocols(protocolModel.getData());
779   }
780 
781 }