001    // Java tool interface class GraphPainterTool
002    // This file is generated automatically, please do not edit!
003    // generation time: Mar 14, 2007 10:38:27 AM
004    
005    package nl.cwi.sen1.gui.plugin;
006    
007    import java.util.HashSet;
008    import java.util.List;
009    import java.util.Set;
010    
011    import toolbus.SwingTool;
012    import aterm.ATerm;
013    import aterm.ATermAppl;
014    import aterm.ATermFactory;
015    import aterm.ATermList;
016    
017    abstract public class GraphPainterTool
018      extends SwingTool
019      implements GraphPainterTif
020    {
021      // This table will hold the complete input signature
022      private Set<ATerm> sigTable = new HashSet<ATerm>();
023    
024      // Patterns that are used to match against incoming terms
025      private ATerm PdisplayGraph0;
026      private ATerm PselectNode0;
027      private ATerm PupdateGraph0;
028      private ATerm PshowPopup0;
029      private ATerm PcreatePanel0;
030      private ATerm PsizeGraph0;
031      private ATerm PrecAckEvent0;
032      private ATerm PrecTerminate0;
033    
034      // Mimic the constructor from the AbstractTool class
035      protected GraphPainterTool(ATermFactory factory)
036      {
037        super(factory);
038        initSigTable();
039        initPatterns();
040      }
041    
042      // This method initializes the table with input signatures
043      private void initSigTable()
044      {
045        sigTable.add(factory.parse("rec-do(<graph-painter>,display-graph(<str>,<term>,<graph>))"));
046        sigTable.add(factory.parse("rec-do(<graph-painter>,update-graph(<str>,<term>,<term>,<term>,<term>))"));
047        sigTable.add(factory.parse("rec-eval(<graph-painter>,create-panel(<str>,<term>,<bool>,<bool>))"));
048        sigTable.add(factory.parse("rec-eval(<graph-painter>,size-graph(<str>,<term>,<graph>))"));
049        sigTable.add(factory.parse("rec-do(<graph-painter>,select-node(<str>,<term>,<term>))"));
050        sigTable.add(factory.parse("rec-do(<graph-painter>,show-popup(<str>,<term>,<term>,<list>))"));
051        sigTable.add(factory.parse("rec-ack-event(<graph-painter>,<term>)"));
052        sigTable.add(factory.parse("rec-terminate(<graph-painter>,<term>)"));
053      }
054    
055      // Initialize the patterns that are used to match against incoming terms
056      private void initPatterns()
057      {
058        PdisplayGraph0 = factory.parse("rec-do(display-graph(<str>,<term>,<term>))");
059        PselectNode0 = factory.parse("rec-do(select-node(<str>,<term>,<term>))");
060        PupdateGraph0 = factory.parse("rec-do(update-graph(<str>,<term>,<term>,<term>,<term>))");
061        PshowPopup0 = factory.parse("rec-do(show-popup(<str>,<term>,<term>,<term>))");
062        PcreatePanel0 = factory.parse("rec-eval(create-panel(<str>,<term>,<term>,<term>))");
063        PsizeGraph0 = factory.parse("rec-eval(size-graph(<str>,<term>,<term>))");
064        PrecAckEvent0 = factory.parse("rec-ack-event(<term>)");
065        PrecTerminate0 = factory.parse("rec-terminate(<term>)");
066      }
067    
068      // The generic handler calls the specific handlers
069      public ATerm handler(ATerm term)
070      {
071        List<?> result;
072    
073        result = term.match(PdisplayGraph0);
074        if (result != null) {
075          displayGraph((String)result.get(0), (ATerm)result.get(1), (ATerm)result.get(2));
076          return null;
077        }
078        result = term.match(PselectNode0);
079        if (result != null) {
080          selectNode((String)result.get(0), (ATerm)result.get(1), (ATerm)result.get(2));
081          return null;
082        }
083        result = term.match(PupdateGraph0);
084        if (result != null) {
085          updateGraph((String)result.get(0), (ATerm)result.get(1), (ATerm)result.get(2), (ATerm)result.get(3), (ATerm)result.get(4));
086          return null;
087        }
088        result = term.match(PshowPopup0);
089        if (result != null) {
090          showPopup((String)result.get(0), (ATerm)result.get(1), (ATerm)result.get(2), (ATerm)result.get(3));
091          return null;
092        }
093        result = term.match(PcreatePanel0);
094        if (result != null) {
095          return createPanel((String)result.get(0), (ATerm)result.get(1), (ATerm)result.get(2), (ATerm)result.get(3));
096        }
097        result = term.match(PsizeGraph0);
098        if (result != null) {
099          return sizeGraph((String)result.get(0), (ATerm)result.get(1), (ATerm)result.get(2));
100        }
101        result = term.match(PrecAckEvent0);
102        if (result != null) {
103          recAckEvent((ATerm)result.get(0));
104          return null;
105        }
106        result = term.match(PrecTerminate0);
107        if (result != null) {
108          recTerminate((ATerm)result.get(0));
109          return null;
110        }
111    
112        notInInputSignature(term);
113        return null;
114      }
115    
116      // Check the input signature
117      public void checkInputSignature(ATermList sigs)
118      {
119        while(!sigs.isEmpty()) {
120          ATermAppl sig = (ATermAppl)sigs.getFirst();
121          sigs = sigs.getNext();
122          if (!sigTable.contains(sig)) {
123            // Sorry, but the term is not in the input signature!
124            notInInputSignature(sig);
125          }
126        }
127      }
128    
129      // This function is called when an input term
130      // was not in the input signature.
131      void notInInputSignature(ATerm t)
132      {
133        throw new RuntimeException("term not in input signature: " + t);
134      }
135    }