00001 /* 00002 ** Author(s): Miguel Calejo 00003 ** Contact: interprolog@declarativa.com, http://www.declarativa.com 00004 ** Copyright (C) Declarativa, Portugal, 2000-2002 00005 ** Use and distribution, without any warranties, under the terms of the 00006 ** GNU Library General Public License, readable in http://www.fsf.org/copyleft/lgpl.html 00007 */ 00008 package com.declarativa.interprolog.gui; 00009 import com.declarativa.interprolog.*; 00010 import java.awt.event.*; 00011 import java.awt.*; 00012 import javax.swing.*; 00019 public class PrologEventBroker implements ActionListener { 00020 PrologEngine engine; 00021 String goal; 00022 JComponent component; 00023 public PrologEventBroker(PrologEngine e,String g){ 00024 engine=e; 00025 goal=g; 00026 component=null; 00027 maySetTooltipText("Calls an Event(this) goal"); 00028 } 00029 public PrologEventBroker(PrologEngine e,Object g){ 00030 engine=e; 00031 if (g!=null) goal=g.toString(); 00032 component=null; 00033 maySetTooltipText("Calls an Event(this) goal"); 00034 } 00035 public PrologEventBroker(PrologEngine e){ 00036 this(e,null); 00037 } 00038 void maySetTooltipText(String defaultTip){ 00039 if (component!=null) { 00040 if (goal!=null) 00041 component.setToolTipText("Calls "+goal); 00042 else 00043 component.setToolTipText(defaultTip); 00044 } 00045 } 00046 public void actionPerformed(ActionEvent e){ 00047 String thisGoal; Object theSource = e.getSource(); 00048 if (component==null) { 00049 if (theSource instanceof JComponent) component=(JComponent)theSource; 00050 } 00051 if (goal!=null) thisGoal=goal; 00052 else { 00053 thisGoal=PrologEngine.shortClassName(e.getClass()) + "("+ 00054 engine.registerJavaObject(theSource) + ")"; 00055 } 00056 maySetTooltipText("Last called "+thisGoal); 00057 engine.deterministicGoal(thisGoal); 00058 } 00059 }