[Webfunds-commits] java/webfunds/client/contracts ContractBrowser.java

Ian Grigg iang@cypherpunks.ai
Sat, 7 Oct 2000 15:53:28 -0400 (AST)


iang        00/10/07 15:53:28

  Modified:    webfunds/client/contracts ContractBrowser.java
  Log:
  some cleanups, sadly, there is now a bug where the
  list of contracts fails after a delete.  Also, Explorer
  button was lost.  Need to redo the Grid stuff.

Revision  Changes    Path
1.2       +64 -43    java/webfunds/client/contracts/ContractBrowser.java

Index: ContractBrowser.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/contracts/ContractBrowser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContractBrowser.java	2000/03/28 19:13:20	1.1
+++ ContractBrowser.java	2000/10/07 19:53:28	1.2
@@ -1,5 +1,5 @@
 /*
- * $Id: ContractBrowser.java,v 1.1 2000/03/28 19:13:20 iang Exp $
+ * $Id: ContractBrowser.java,v 1.2 2000/10/07 19:53:28 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -39,9 +39,9 @@
     public String getGeneralAction()  { return generalaction; }
     public String getContractAction() { return contractaction; }
 
-    public static final String ADD_BUTTON     = "Add Contract";
+    public static final String ADD_BUTTON     = "Add URL";
     public static final String DELETE_BUTTON  = "Delete";
-    public static final String FILE_BUTTON    = "File Explorer";
+    public static final String FILE_BUTTON    = "Explorer";
     public static final String CLOSE_BUTTON   = "Close";
     public static final String OPEN_BUTTON    = "Open";
     public static final String HASH_BUTTON    = "Hash";
@@ -58,6 +58,7 @@
     JPanel              urlpanel;
 
 
+
     public ContractBrowser() { }
 
     public void init()
@@ -71,6 +72,15 @@
         this.contract  = con;
     }
 
+    JMenu file;
+
+    protected void addFileMenuButton(String s)
+    {
+        JMenuItem item = new JMenuItem(s);
+        file.add(item);
+        item.addActionListener( this );
+    }
+
     public void run()
     {
         frame = new JFrame("ContractBrowser");
@@ -79,11 +89,7 @@
         DefaultListModel listmodel = new DefaultListModel();
 
         JMenuBar   mb           = new JMenuBar();
-        JMenu      file         = new JMenu("File");
-                   fileexit     = new JMenuItem(CLOSE_BUTTON);
-        JMenuItem  fileopen     = new JMenuItem(OPEN_BUTTON);
-        JMenuItem  filedel      = new JMenuItem(DELETE_BUTTON);
-        JMenuItem  filehash     = new JMenuItem(HASH_BUTTON);
+                   file         = new JMenu("File");
 
                    text         = new JTextArea();
                    contractlist = new JList(listmodel);
@@ -95,12 +101,15 @@
         text.setEditable(false);
         contractlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
         contractlist.setVisibleRowCount(6);
+
 
-        file.add(fileopen);
-        file.add(filedel);
-        file.add(filehash);
+// what does OPEN do?
+//        addFileMenuButton(OPEN_BUTTON);
+        addFileMenuButton(FILE_BUTTON);
+        addFileMenuButton(DELETE_BUTTON);
+        addFileMenuButton(HASH_BUTTON);
         file.add(new JSeparator ());
-        file.add(fileexit);
+        addFileMenuButton(CLOSE_BUTTON);
         mb.add(file);
 
         contentpane.add("North", urlpanel);
@@ -109,24 +118,24 @@
         frame.setJMenuBar(mb);
 
         frame.setSize(600,400);
-        addUrlPanel(urlpanel);
+        addUrlPanel(urlpanel);          // sets url
         contractlist.addListSelectionListener( new ListSelectionListener()
             {
                 public void valueChanged(ListSelectionEvent evt)
                 {
+// System.err.println("click!");
                     if (!(evt.getValueIsAdjusting()))
                     {
-                        showContract((Contract)contractlist.getSelectedValue());
+                        Contract c = (Contract)contractlist.getSelectedValue();
+// System.err.println(" on " + c.getName());
+                        showContract(c);
                         url.setText("");
                     }
                 }
             });
 
         url.addActionListener( this );
-        fileopen.addActionListener( this );
-        filehash.addActionListener( this );
-        filedel.addActionListener( this );
-        fileexit.addActionListener( this );
+
         try
         {
             if (contract != null)
@@ -145,7 +154,7 @@
 
     public void destroy()
     {
-        System.err.println("Thread destroyed");
+        logmsg("Thread destroyed");
     }
 
     public void setContractStore(ChangeContractStore contractstore)
@@ -189,7 +198,6 @@
                 {
                     public void run() { ContractBrowser.this.fileHash(); }
                 };
-System.err.println("start thread");
             t1.start();
         }
         else if (action == FILE_BUTTON)
@@ -202,14 +210,17 @@
         }
     }
 
+// hmm, something's gone wrong here, breaks after delete contract
     private void refreshList()
     {
         DefaultListModel listmodel = (DefaultListModel)contractlist.getModel();
         Contract[] contracts = cs.getAllContracts();
         listmodel.clear();
+// System.err.println("  refreshing with " + contracts.length + " contracts");
         for (int i = 0; i < contracts.length; i++)
         {
             listmodel.addElement( contracts[i] );
+// System.err.println("       " + contracts[i].getName());
         }
     }
 
@@ -285,7 +296,7 @@
      */
     private void fileHash()
     {
-System.err.println("fileHash()");
+logmsg("fileHash()");
         File f = fileChooser();
         if (f == null)
             return ;
@@ -340,18 +351,18 @@
 
     private void showContract()
     {
-        System.err.println("URL: <" + url.getText() + ">");
+        logmsg("URL: <" + url.getText() + ">");
         String s = url.getText().trim();
         int index = s.indexOf(httpproto);
         int index2 = s.indexOf(fileproto);
-        System.err.println("s: <" + s + ">" + " index = "  + index);
+        logmsg("s: <" + s + ">" + " index = "  + index);
         if (index < 0 && index2 < 0)
             s = httpproto + s;
 
         URL contracturl = null;
         try
         {
-        System.err.println("trying: <" + s + ">");
+        logmsg("trying: <" + s + ">");
             contracturl = new URL(s);
         }
         catch (MalformedURLException ex)
@@ -360,7 +371,7 @@
             return ;
         }
 
-        System.err.println("contract: " + contracturl);
+        logmsg("contract: " + contracturl);
         contractlist.getSelectionModel().clearSelection();
         Contract con;
         try {
@@ -415,14 +426,13 @@
         url             = new JTextField(50);
         JLabel urllabel = new JLabel("URL: ");
         JButton butadd  = new JButton(ADD_BUTTON);
-        //JButton butdel  = new JButton(DELETE_BUTTON);
-        JButton butfile = new JButton(FILE_BUTTON);
+//        JButton butfile = new JButton(FILE_BUTTON);
         GridBagConstraints c = new GridBagConstraints();
 
         panel.setLayout(new GridBagLayout());
         c.gridx = 0;
         c.gridy = 0;
-        c.gridwidth = GridBagConstraints.RELATIVE;
+        // c.gridwidth = GridBagConstraints.RELATIVE;
         c.gridheight = 1;
         c.weightx = 0.0;
         c.weighty = 0.5;
@@ -432,39 +442,50 @@
         panel.add(urllabel, c);
 
         c.gridx = 1;
-        c.gridwidth = GridBagConstraints.REMAINDER;
-        c.weightx = 1.0;
+        c.gridwidth = GridBagConstraints.RELATIVE; // GridBagConstraints.REMAINDER;
+        c.weightx = 1.0; // 1.0;
         c.weighty = .5;
         c.fill = GridBagConstraints.BOTH;
         panel.add(url, c);
 
-        //
-        //  Next row - the button bar.
-        //  Adding a 3rd button doesn't work?
-        //
-        //int x = 1;
-        c.gridx = 0;
-        c.gridy = 1;
-        c.gridwidth = GridBagConstraints.RELATIVE;
+        c.gridx = 2;
+        c.gridwidth = GridBagConstraints.REMAINDER;
         c.weightx = 0.0;
+        c.weighty = .5;
         c.fill = GridBagConstraints.NONE;
         panel.add(butadd, c);
-
-        c.gridx = GridBagConstraints.RELATIVE;
-        panel.add(butfile, c);
 
+//        //
+//        //  Next row - the button bar.
+//        //  Adding a 3rd button doesn't work?
+//        //
+//        //int x = 1;
+//        c.gridx = 0;
+//        c.gridy = 1;
+//        c.gridwidth = GridBagConstraints.RELATIVE;
+//        c.weightx = 0.0;
+//        c.fill = GridBagConstraints.NONE;
+//        panel.add(butadd, c);
+//
+//        c.gridx = GridBagConstraints.RELATIVE;
+//        panel.add(butfile, c);
+//
         butadd.addActionListener( this );
-        butfile.addActionListener( this );
+//        butfile.addActionListener( this );
 
     }
 
     public static void main(String[] args)
         throws Exception
     {
+        String dir = ".";
+        if (args.length > 0)
+            dir = args[0];
 
         ContractBrowser cb = new ContractBrowser();
         cb.setUInterface(new UInterfaceImpl());
-        cb.setContractStore(new ChangeContractStore(new File(".")));
+        cb.setContractStore(new ChangeContractStore(new File(dir)));
         cb.init();
+        cb.start();
     }
 }