00001
00002
00003
00004
00005
00006
00007
00008 package com.xsb.interprolog;
00009 import com.declarativa.interprolog.*;
00010 import com.declarativa.interprolog.util.*;
00011 import com.declarativa.interprolog.gui.*;
00012 import javax.swing.*;
00013
00015 public class NativeEngineWindow extends ListenerWindow {
00016
00017 public NativeEngineWindow(NativeEngine e){
00018 this(e,true);
00019 setTitle("NativeEngine listener");
00020 }
00021 public NativeEngineWindow(NativeEngine e,boolean autoDisplay){
00022 super(e,autoDisplay);
00023 prologInput.setToolTipText("Prolog goal, sent when you press enter");
00024 prologOutput.setToolTipText("Goals and their first solutions");
00025 }
00026 public void sendToProlog(){
00027 final String goal = prologInput.getText().trim();
00028 if (goal.length()==0 || goal.endsWith(".")) {
00029 beep();
00030 prologOutput.append("Goal must be nonempty and without trailing '.'\n");
00031 return;
00032 }
00033 prologOutput.append(goal+"\n");
00034 addToHistory();
00035
00036 Thread t = new Thread(){
00037 String result;
00038 public void run(){
00039 try{
00040 Object[] bindings = engine.deterministicGoal(goal,null);
00041 if (bindings==null) result = "FAILED\n";
00042 else result = bindings[0].toString()+"\n";
00043
00044 } catch (IPInterruptedException e){
00045 result = "Goal was interrupted!";
00046 } catch (IPAbortedException e){
00047 result = "Goal was aborted!";
00048 }
00049 SwingUtilities.invokeLater(new Runnable() {
00050 public void run(){
00051 prologOutput.append(result+"\n");
00052 scrollToBottom();
00053 focusInput();
00054 }
00055 });
00056 }
00057 };
00058 t.start();
00059 }
00060
00063 public static void main(String[] args){
00064 commonMain(args);
00065 new NativeEngineWindow(new NativeEngine(prologStartCommand,debug));
00066 }
00067
00068 }