Author: jflesch
Date: 2006-11-04 22:37:44 +0000 (Sat, 04 Nov 2006)
New Revision: 10818

Added:
   trunk/apps/Thaw/images/key.png
Modified:
   trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java
   trunk/apps/Thaw/src/thaw/core/IconBox.java
   trunk/apps/Thaw/src/thaw/core/Main.java
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java
   trunk/apps/Thaw/src/thaw/plugins/index/File.java
   trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
Log:
Add a button to add specific key to an index

Added: trunk/apps/Thaw/images/key.png
===================================================================
(Binary files differ)


Property changes on: trunk/apps/Thaw/images/key.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java 2006-11-04 18:17:12 UTC 
(rev 10817)
+++ trunk/apps/Thaw/src/thaw/core/FreenetURIHelper.java 2006-11-04 22:37:44 UTC 
(rev 10818)
@@ -22,6 +22,14 @@
                        Logger.warning(new FreenetURIHelper(), 
"UnsupportedEncodingException (UTF-8): "+e.toString());
                }

+               if (uri.indexOf("CHK@") < 0
+                   && uri.indexOf("USK@") < 0
+                   && uri.indexOf("KSK@") < 0
+                   && uri.indexOf("SSK@") < 0) {
+                       Logger.notice(new FreenetURIHelper(), "Not a valid key: 
"+uri);
+                       return null;
+               }
+
                return uri;
        }


Modified: trunk/apps/Thaw/src/thaw/core/IconBox.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/IconBox.java  2006-11-04 18:17:12 UTC (rev 
10817)
+++ trunk/apps/Thaw/src/thaw/core/IconBox.java  2006-11-04 22:37:44 UTC (rev 
10818)
@@ -59,6 +59,9 @@

        public static ImageIcon search;

+       public static ImageIcon key;
+
+
        /**
         * Not really used
         */
@@ -126,6 +129,7 @@
                quitAction = loadIcon("system-log-out.png");
                minQuitAction = loadIcon("min-system-log-out.png");
                search = loadIcon("system-search.png");
+               key = loadIcon("key.png");
        }

 }

Modified: trunk/apps/Thaw/src/thaw/core/Main.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Main.java     2006-11-04 18:17:12 UTC (rev 
10817)
+++ trunk/apps/Thaw/src/thaw/core/Main.java     2006-11-04 22:37:44 UTC (rev 
10818)
@@ -12,8 +12,8 @@
  */
 public class Main {

-       public final static String VERSION="0.6 WIP r at custom@";
-       //public final static String VERSION="0.5.9b Beta";
+       //public final static String VERSION="0.6 WIP r at custom@";
+       public final static String VERSION="0.5.9b Beta";

        /**
         * Look & feel use by GUI front end

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-11-04 18:17:12 UTC 
(rev 10817)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-11-04 22:37:44 UTC 
(rev 10818)
@@ -132,7 +132,7 @@
 thaw.plugin.priority.p5=Very low
 thaw.plugin.priority.p6=Will never finish

-thaw.plugin.fetch.keyList=Key list (one key per line)
+thaw.plugin.fetch.keyList=Key list (one key per line) #?Also used in 
IndexEditorPanel
 thaw.plugin.fetch.loadKeyListFromFile=Load keys from file ...
 thaw.plugin.fetch.destinationDirectory=Destination directory
 thaw.plugin.fetch.chooseDestination=Choose destination ...
@@ -245,3 +245,5 @@
 thaw.plugin.index.selectIndex=Select an index or specify the key

 thaw.plugin.index.gotoIndex=Go to the corresponding index
+
+thaw.plugin.index.addKeys=Add specific key(s)

Modified: trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java   2006-11-04 18:17:12 UTC 
(rev 10817)
+++ trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java   2006-11-04 22:37:44 UTC 
(rev 10818)
@@ -110,11 +110,12 @@

                        String key = FreenetURIHelper.cleanURI(subKey[0]);

-                       
this.core.getQueueManager().addQueryToThePendingQueue(new FCPClientGet(key,
-                                                                               
          priority,
-                                                                               
          persistence,
-                                                                               
          globalQueue, -1,
-                                                                               
          destination));
+                       if (key != null)
+                               
this.core.getQueueManager().addQueryToThePendingQueue(new FCPClientGet(key,
+                                                                               
                       priority,
+                                                                               
                       persistence,
+                                                                               
                       globalQueue, -1,
+                                                                               
                       destination));
                }

                fetchFrame.setVisible(false);

Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/File.java    2006-11-04 18:17:12 UTC 
(rev 10817)
+++ trunk/apps/Thaw/src/thaw/plugins/index/File.java    2006-11-04 22:37:44 UTC 
(rev 10818)
@@ -37,6 +37,16 @@

        private FCPQueueManager queueManager = null;

+
+       public File(Hsqldb db, String publicKey, Index parent) {
+               this.db = db;
+               this.id = -1;
+               this.publicKey = publicKey;
+               deduceFilenameFromKey();
+
+               this.size = 0;
+       }
+
        /**
         * @param path Local path
         * @param transfer Corresponding tranfer (can be null).
@@ -402,6 +412,7 @@

                        if(this.transfer.isFinished() && this.transfer 
instanceof FCPClientGet) {
                                
((FCPClientGet)this.transfer).deleteObserver(this);
+                               this.size = (new 
java.io.File(transfer.getPath())).length();
                        }

                        if(this.transfer.isFinished() && 
this.transfer.isSuccessful()) {

Modified: trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2006-11-04 
18:17:12 UTC (rev 10817)
+++ trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2006-11-04 
22:37:44 UTC (rev 10818)
@@ -366,8 +366,12 @@
                        if(column == 0)
                                return file.getFilename();

-                       if(column == 1)
-                               return new Long(file.getSize());
+                       if(column == 1) {
+                               if (file.getSize() > 0)
+                                       return new Long(file.getSize());
+                               else
+                                       return 
I18n.getMessage("thaw.common.unknown");
+                       }

                        if(column == 2 && FileTable.this.modifiables)
                                return file.getLocalPath();

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java        
2006-11-04 18:17:12 UTC (rev 10817)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java        
2006-11-04 22:37:44 UTC (rev 10818)
@@ -10,7 +10,14 @@

 import javax.swing.JFileChooser;

+import javax.swing.JOptionPane;
+
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JTextArea;
+
 import java.awt.BorderLayout;
+import java.awt.GridLayout;
 import java.awt.event.ActionListener;
 import java.awt.event.ActionEvent;

@@ -38,6 +45,7 @@
        private JToolBar toolBar;
        private JButton addButton;
        private JButton insertAndAddButton;
+       private JButton addKeyButton;
        private JButton linkButton;

        private FileList fileList = null; /* Index or SearchResult object */
@@ -61,19 +69,23 @@
                
this.addButton.setToolTipText(I18n.getMessage("thaw.plugin.index.addFilesWithoutInserting"));
                this.insertAndAddButton = new 
JButton(IconBox.insertAndAddToIndexAction);
                
this.insertAndAddButton.setToolTipText(I18n.getMessage("thaw.plugin.index.addFilesWithInserting"));
+               this.addKeyButton = new JButton(IconBox.key);
+               
this.addKeyButton.setToolTipText(I18n.getMessage("thaw.plugin.index.addKeys"));
                this.linkButton = new JButton(IconBox.makeALinkAction);
                
this.linkButton.setToolTipText(I18n.getMessage("thaw.plugin.index.addLink"));

                this.addButton.addActionListener(this);
                this.insertAndAddButton.addActionListener(this);
                this.linkButton.addActionListener(this);
+               this.addKeyButton.addActionListener(this);

                this.buttonsEnabled(false);

-               this.toolBar.add(this.insertAndAddButton);
-               this.toolBar.add(this.addButton);
+               this.toolBar.add(insertAndAddButton);
+               this.toolBar.add(addButton);
+               this.toolBar.add(addKeyButton);
                this.toolBar.addSeparator();
-               this.toolBar.add(this.linkButton);
+               this.toolBar.add(linkButton);

                this.tables = new Tables(true, db, queueManager, 
this.indexTree, config);
                this.fileDetails = new FileDetailsEditor(true);
@@ -113,6 +125,7 @@
                this.addButton.setEnabled(a);
                this.insertAndAddButton.setEnabled(a);
                this.linkButton.setEnabled(a);
+               this.addKeyButton.setEnabled(a);
        }

        protected void setList(FileAndLinkList l) {
@@ -169,6 +182,14 @@
                        linkMakerThread.start();
                }

+               if (e.getSource() == this.addKeyButton) {
+                       if (fileList instanceof Index) {
+                               Thread keyAdder = new Thread(new 
KeyAdder((Index)fileList));
+                               keyAdder.start();
+                       } else
+                               Logger.warning(this, "Not in an index ?!");
+               }
+
                if(e.getSource() == this.addButton
                   || e.getSource() == this.insertAndAddButton) {
                        FileChooser fileChooser = new FileChooser();
@@ -220,8 +241,66 @@
                }
        }

+       private class KeyAdder implements Runnable, ActionListener {
+               JFrame frame = null;
+               JLabel header = null;
+               JTextArea textArea = null;
+               JPanel buttonPanel = null;
+               JButton cancelButton = null;
+               JButton okButton = null;

-       public class LinkMaker implements Runnable {
+               Index parent;
+
+               public KeyAdder(Index parent) {
+                       this.parent = parent;
+               }
+
+               public void run() {
+                       frame = new 
JFrame(I18n.getMessage("thaw.plugins.insert.addKeys"));
+                       frame.setVisible(false);
+
+                       header = new 
JLabel(I18n.getMessage("thaw.plugin.fetch.keyList"));
+                       textArea = new JTextArea();
+                       buttonPanel = new JPanel();
+                       cancelButton = new 
JButton(I18n.getMessage("thaw.common.cancel"));
+                       okButton = new 
JButton(I18n.getMessage("thaw.common.ok"));
+
+                       cancelButton.addActionListener(this);
+                       okButton.addActionListener(this);
+
+                       frame.getContentPane().setLayout(new BorderLayout());
+                       frame.getContentPane().add(header, BorderLayout.NORTH);
+                       frame.getContentPane().add(textArea, 
BorderLayout.CENTER);
+
+                       buttonPanel.setLayout(new GridLayout(1, 2));
+                       buttonPanel.add(okButton);
+                       buttonPanel.add(cancelButton);
+
+                       frame.getContentPane().add(buttonPanel, 
BorderLayout.SOUTH);
+
+                       frame.setSize(500, 300);
+
+                       frame.setVisible(true);
+               }
+
+               public void actionPerformed(ActionEvent e) {
+                       frame.setVisible(false);
+
+                       String[] keys = textArea.getText().split("\n");
+
+                       for (int i = 0 ; i < keys.length ; i++) {
+                               String key = FreenetURIHelper.cleanURI(keys[i]);
+
+                               if (key != null) {
+                                       thaw.plugins.index.File file = new 
thaw.plugins.index.File(db, key, parent);
+                                       parent.addFile(file);
+                               }
+                       }
+
+               }
+       }
+
+       private class LinkMaker implements Runnable {
                public LinkMaker() { }

                public void run() {

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java       2006-11-04 
18:17:12 UTC (rev 10817)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java       2006-11-04 
22:37:44 UTC (rev 10818)
@@ -361,11 +361,11 @@
                        if(!this.modifiables) {
                                publicKey = 
this.askAName(I18n.getMessage("thaw.plugin.index.indexKey"), "USK@");

+                               publicKey = 
FreenetURIHelper.cleanURI(publicKey);
+
                                if (publicKey == null)
                                        return;

-                               publicKey = 
FreenetURIHelper.cleanURI(publicKey);
-
                                name = Index.getNameFromKey(publicKey);

                        } else {


Reply via email to