import java.awt.BorderLayout;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.HashMap;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import remoting.RServices;
import uk.ac.ebi.microarray.pools.db.monitor.ConsoleDialog;
import uk.ac.ebi.microarray.pools.db.monitor.ServantStatus;
import graphics.pop.GDDevice;
import graphics.rmi.JGDPanelPop;
import http.RHttpProxy;

public class HttpR {

  public static void main(String[] argsthrows Throwable {
    final String cmdUrl = "http://127.0.0.1:8080/rvirtual/cmd";
    HashMap<String, Object> options = new HashMap<String, Object>();
    options.put("privatename""tata");
    final String sessionId = RHttpProxy.logOn(cmdUrl, """login""pwd", options);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      public void run() {
        System.out.println("Shutdown Hook Called");
        try {
          RHttpProxy.logOff(cmdUrl, sessionId);
        catch (Exception e) {
          e.printStackTrace();
        }
      }
    }));

    RServices r = (RServicesRHttpProxy.getDynamicProxy(cmdUrl, sessionId, "R"new Class<?>[] { RServices.class }new HttpClient(new MultiThreadedHttpConnectionManager()));        
    GDDevice d = RHttpProxy.newDevice(cmdUrl, sessionId, 100100);
    
    JPanel panel = new JGDPanelPop(d);
    JFrame f = new JFrame();
    f.getContentPane().setLayout(new BorderLayout());
    f.getContentPane().add(panel, BorderLayout.CENTER);
    panel.repaint();
    f.pack();
    f.setVisible(true);
    f.setSize(300300);

    ConsoleDialog dialog = new ConsoleDialog(null, r, new ServantStatus() {
      public boolean isLocked() {
        return true;
      }
    });
    dialog.setVisible(true);

    dialog.addWindowListener(new WindowListener() {
      public void windowActivated(WindowEvent e) {}
      public void windowClosed(WindowEvent e) {System.exit(0);}
      public void windowClosing(WindowEvent e) {System.exit(0);}
      public void windowDeactivated(WindowEvent e) {}
      public void windowDeiconified(WindowEvent e) {}
      public void windowIconified(WindowEvent e) {}
      public void windowOpened(WindowEvent e) {}
    });
  }
}