Author: jflesch
Date: 2007-08-30 18:46:33 +0000 (Thu, 30 Aug 2007)
New Revision: 14927

Modified:
   trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
   trunk/apps/Thaw/src/thaw/plugins/index/Index.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/SubMessagePanel.java
Log:
Highlight keys in minifrost messages => make it possible to download keys 
quickly and add indexes quickly

Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-08-30 
18:09:45 UTC (rev 14926)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-08-30 
18:46:33 UTC (rev 14927)
@@ -656,6 +656,14 @@
 thaw.plugin.miniFrost.attachFiles=Attacher des fichiers


+thaw.plugin.miniFrost.downloadThisKey=T?l?charger cette clef
+thaw.plugin.miniFrost.downloadAllKeys=T?l?charger toutes les clefs
+thaw.plugin.miniFrost.addThisIndex=Ajouter cet index
+thaw.plugin.miniFrost.addAllIndexes=Ajouter tout les indexes
+thaw.plugin.miniFrost.copyThisKey=Copier cette clef dans le presse-papier
+thaw.plugin.miniFrost.copyAllKeys=Copier toutes les clefs dans le presse-papier
+
+
 ## Index web grapher
 thaw.plugin.indexWebGrapher=Une tentative de repr?sentation de la toile des 
indexes
 thaw.plugin.indexWebGrapher.shortName=Toile d'indexes

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-08-30 18:09:45 UTC 
(rev 14926)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-08-30 18:46:33 UTC 
(rev 14927)
@@ -669,7 +669,14 @@
 thaw.plugin.miniFrost.attachBoards=Attach board(s)
 thaw.plugin.miniFrost.attachFiles=Attach file(s)

+thaw.plugin.miniFrost.downloadThisKey=Download this key
+thaw.plugin.miniFrost.downloadAllKeys=Download all the keys
+thaw.plugin.miniFrost.addThisIndex=Add this index
+thaw.plugin.miniFrost.addAllIndexes=Add all the indexes
+thaw.plugin.miniFrost.copyThisKey=Copy this key to the clipboard
+thaw.plugin.miniFrost.copyAllKeys=Copy all the keys to the clipboard

+
 ## index web grapher

 thaw.plugin.indexWebGrapher=An attempt to draw a graph of the index web

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-08-30 18:09:45 UTC 
(rev 14926)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-08-30 18:46:33 UTC 
(rev 14927)
@@ -656,6 +656,14 @@
 thaw.plugin.miniFrost.attachFiles=Attacher des fichiers


+thaw.plugin.miniFrost.downloadThisKey=T\u00e9l\u00e9charger cette clef
+thaw.plugin.miniFrost.downloadAllKeys=T\u00e9l\u00e9charger toutes les clefs
+thaw.plugin.miniFrost.addThisIndex=Ajouter cet index
+thaw.plugin.miniFrost.addAllIndexes=Ajouter tout les indexes
+thaw.plugin.miniFrost.copyThisKey=Copier cette clef dans le presse-papier
+thaw.plugin.miniFrost.copyAllKeys=Copier toutes les clefs dans le presse-papier
+
+
 ## Index web grapher
 thaw.plugin.indexWebGrapher=Une tentative de repr\u00e9sentation de la toile 
des indexes
 thaw.plugin.indexWebGrapher.shortName=Toile d'indexes

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-08-30 18:09:45 UTC 
(rev 14926)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-08-30 18:46:33 UTC 
(rev 14927)
@@ -885,7 +885,7 @@
                                             2, /* <= priority */
                                             
FCPClientGet.PERSISTENCE_UNTIL_DISCONNECT,
                                             false, /* <= globalQueue */
-                                            5, /* maxRetries */
+                                            10, /* maxRetries */
                                             
System.getProperty("java.io.tmpdir"), /* destination directory */
                                             MAX_SIZE, /* max size */
                                             true /* <= noDDA */);

Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java        
2007-08-30 18:09:45 UTC (rev 14926)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java        
2007-08-30 18:46:33 UTC (rev 14927)
@@ -18,7 +18,9 @@
 import java.awt.event.ActionEvent;

 import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;

+
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
@@ -34,7 +36,11 @@
 import thaw.plugins.miniFrost.interfaces.Attachment;
 import thaw.plugins.miniFrost.interfaces.Draft;

+import thaw.fcp.*;
+import thaw.plugins.IndexBrowser;
+import thaw.plugins.index.IndexManagementHelper;

+
 public class MessagePanel
        implements ActionListener {

@@ -427,4 +433,217 @@

                }
        }
+
+
+       public final static JMenuItem[] chkActions = {
+               new 
JMenuItem(I18n.getMessage("thaw.plugin.miniFrost.downloadThisKey")),
+               new 
JMenuItem(I18n.getMessage("thaw.plugin.miniFrost.downloadAllKeys")),
+               null,
+               new 
JMenuItem(I18n.getMessage("thaw.plugin.miniFrost.copyThisKey")),
+               new 
JMenuItem(I18n.getMessage("thaw.plugin.miniFrost.copyAllKeys"))
+       };
+
+       public final static JMenuItem[] indexActions = {
+               new 
JMenuItem(I18n.getMessage("thaw.plugin.miniFrost.addThisIndex")),
+               new 
JMenuItem(I18n.getMessage("thaw.plugin.miniFrost.addAllIndexes")),
+               null,
+               new 
JMenuItem(I18n.getMessage("thaw.plugin.miniFrost.copyThisKey")),
+               new 
JMenuItem(I18n.getMessage("thaw.plugin.miniFrost.copyAllKeys"))
+       };
+
+
+
+       protected MiniFrostPanel getMainPanel() {
+               return mainPanel;
+       }
+
+       public Vector getAllKeys() {
+               Vector v = new Vector();
+
+               for (Iterator it = subPanels.iterator();
+                    it.hasNext();) {
+                       v.addAll( ((SubMessagePanel)it.next()).getKeys() );
+               }
+
+               return v;
+       }
+
+       public Vector getCHKKeys() {
+               Vector v = new Vector();
+
+               Vector keys = getAllKeys();
+
+               for (Iterator it = keys.iterator();
+                    it.hasNext();) {
+                       String key = (String)it.next();
+
+                       if (key.startsWith("CHK@"))
+                               v.add(key);
+               }
+
+               return v;
+       }
+
+
+       public Vector getIndexKeys() {
+               Vector v = new Vector();
+
+               Vector keys = getAllKeys();
+
+               for (Iterator it = keys.iterator();
+                    it.hasNext();) {
+                       String key = (String)it.next();
+
+                       if (key.endsWith(".frdx"))
+                               v.add(key);
+               }
+
+               return v;
+       }
+
+
+       protected static class KeyActionMenu extends JPopupMenu implements 
ActionListener {
+               private String key;
+               private JMenuItem[] chkActions;
+               private JMenuItem[] indexActions;
+               private MessagePanel messagePanel;
+
+               public KeyActionMenu(JMenuItem[] chkActions, JMenuItem[] 
indexActions) {
+                       super();
+
+                       this.chkActions = chkActions;
+                       this.indexActions = indexActions;
+
+                       for (int i = 0 ; i < indexActions.length;i++) {
+                               if (indexActions[i] != null)
+                                       indexActions[i].addActionListener(this);
+                       }
+
+                       for (int i = 0 ; i < indexActions.length;i++) {
+                               if (chkActions[i] != null)
+                                       chkActions[i].addActionListener(this);
+                       }
+               }
+
+
+               public void setKeys(MessagePanel panel, String key) {
+                       this.key = key;
+                       this.messagePanel = panel;
+
+                       removeAll();
+
+                       boolean index = key.endsWith(".frdx");
+
+                       JMenuItem[] items = (index ? indexActions : chkActions);
+
+                       for (int i = 0 ; i < items.length ;i++) {
+                               if (items[i] != null)
+                                       add(items[i]);
+                               else
+                                       addSeparator();
+                       }
+               }
+
+               public void download(String key) {
+                       FCPQueueManager queueManager = 
messagePanel.getMainPanel().getPluginCore().getCore().getQueueManager();
+
+                       thaw.gui.FileChooser chooser = new 
thaw.gui.FileChooser();
+
+                       
chooser.setTitle(I18n.getMessage("thaw.plugin.fetch.chooseDestination"));
+                       chooser.setDirectoryOnly(true);
+                       
chooser.setDialogType(javax.swing.JFileChooser.OPEN_DIALOG);
+
+                       java.io.File file = chooser.askOneFile();
+
+                       if (file == null)
+                               return;
+
+                       FCPClientGet get = new FCPClientGet(key, 
FCPClientGet.DEFAULT_PRIORITY,
+                                                           
FCPClientGet.PERSISTENCE_FOREVER,
+                                                           true /* global 
queue */,
+                                                           
FCPClientGet.DEFAULT_MAX_RETRIES /* max retries */,
+                                                           file.getPath());
+
+                       queueManager.addQueryToThePendingQueue(get);
+               }
+
+
+               public void addIndex(String key) {
+                       FCPQueueManager queueManager = 
messagePanel.getMainPanel().getPluginCore().getCore().getQueueManager();
+                       IndexBrowser browser = 
(IndexBrowser)messagePanel.getMainPanel().getPluginCore().getCore().getPluginManager().getPlugin("thaw.plugins.IndexBrowser");
+
+                       if (browser == null) {
+                               Logger.error(this, "The index browser is not 
running. Can't add an index");
+                               return;
+                       }
+
+                       IndexManagementHelper.addIndex(queueManager,
+                                                      
browser.getIndexBrowserPanel(),
+                                                      null,
+                                                      key,
+                                                      true);
+               }
+
+               public void actionPerformed(ActionEvent e) {
+
+                       if (e.getSource() == chkActions[2]
+                           || e.getSource() == indexActions[2]) { /* copy this 
key */
+
+                               thaw.gui.GUIHelper.copyToClipboard(key);
+
+                       } else if (e.getSource() == chkActions[3]
+                                  || e.getSource() == indexActions[3]) { /* 
copy all keys */
+
+                               Vector v = ( (e.getSource() == indexActions[3]) 
?
+                                            messagePanel.getIndexKeys() :
+                                            messagePanel.getCHKKeys() );
+
+                               String str = "";
+
+                               for (Iterator it = v.iterator();
+                                    it.hasNext();) {
+                                       str += ((String)it.next())+"\n";
+                               }
+
+                               thaw.gui.GUIHelper.copyToClipboard(str);
+
+                       } else if (e.getSource() == chkActions[0]) { /* 
download this key */
+
+                               download(key);
+
+                       } else if (e.getSource() == chkActions[1]) { /* 
download all the keys */
+
+                               Vector v = messagePanel.getCHKKeys();
+
+                               for (Iterator it = v.iterator();
+                                    it.hasNext();) {
+                                       download((String)it.next());
+                               }
+
+                       } else if (e.getSource() == indexActions[0]) { /* add 
this index */
+
+                               addIndex(key);
+
+                       } else if (e.getSource() == indexActions[1]) { /* add 
all the indexes */
+
+                               Vector v = messagePanel.getIndexKeys();
+
+                               for (Iterator it = v.iterator();
+                                    it.hasNext();) {
+                                       addIndex((String)it.next());
+                               }
+
+                       }
+
+               }
+       }
+
+
+       public final static KeyActionMenu keyActionMenu = new 
KeyActionMenu(chkActions, indexActions);
+
+
+       public void popMenuOnKey(MouseEvent e, String key) {
+               keyActionMenu.setKeys(this, key);
+               keyActionMenu.show(e.getComponent(), e.getX(), e.getY());
+       }
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/SubMessagePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/SubMessagePanel.java     
2007-08-30 18:09:45 UTC (rev 14926)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/SubMessagePanel.java     
2007-08-30 18:46:33 UTC (rev 14927)
@@ -23,23 +23,45 @@
 import java.awt.event.ActionListener;
 import java.awt.event.ActionEvent;

+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.StyledDocument;
+import javax.swing.text.Document;
+
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.Element;
+
 import thaw.plugins.miniFrost.interfaces.Author;
 import thaw.plugins.miniFrost.interfaces.SubMessage;

+import javax.swing.JComponent;
+import javax.swing.AbstractAction;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import javax.swing.event.MouseInputAdapter;
+
+import java.awt.Cursor;
+import java.util.Vector;
+import java.util.Iterator;
+
+
 import thaw.gui.IconBox;
 import thaw.plugins.signatures.Identity;
 import thaw.core.I18n;
+import thaw.core.Logger;

 import java.util.regex.Pattern;


+
 public class SubMessagePanel extends JPanel implements ActionListener {

        private JButton upDownButton;
        private boolean retracted;
        private SubMessage msg;

-       private JScrollPane area;
+       private JComponent area;
        private MessagePanel messagePanel;

        public SubMessagePanel(MessagePanel messagePanel, SubMessage msg, 
boolean retracted) {
@@ -54,7 +76,7 @@


                /* header */
-               JPanel headPanel = new JPanel(new BorderLayout(40, 40));
+               JPanel headPanel = new JPanel(new BorderLayout(10, 10));

                JLabel dateLabel = new 
JLabel(java.text.DateFormat.getDateTimeInstance().format(msg.getDate()));
                AuthorPanel authorLabel = new AuthorPanel(msg.getAuthor());
@@ -64,7 +86,7 @@
                upDownButton = new JButton("", (retracted ? IconBox.minDown : 
IconBox.minUp));
                upDownButton.addActionListener(this);

-               JPanel rightPanel = new JPanel(new BorderLayout(10, 10));
+               JPanel rightPanel = new JPanel(new BorderLayout(5, 5));
                rightPanel.add(dateLabel, BorderLayout.CENTER);
                rightPanel.add(upDownButton,BorderLayout.EAST);

@@ -181,25 +203,193 @@
        };


+       public final static String KEY_ATTRIBUTE = "key";

-       private JScrollPane getEditorPane(String txt) {
+
+       private Vector keys = null;
+
+
+       public Vector getKeys() {
+               return keys;
+       }
+
+
+       /**
+        * inspired by frost code
+        */
+       private StyledDocument parseText(String txt) {
+
+               keys = new Vector();
+
+               DefaultStyledDocument doc = new DefaultStyledDocument();
+
+               String[] split = txt.trim().split("\n");
+
+               SimpleAttributeSet noAttrs = new SimpleAttributeSet();
+               SimpleAttributeSet keyAttrs = new SimpleAttributeSet();
+
+               //keyAttrs.addAttribute(LinkEditorKit.LINK, s);
+               keyAttrs.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+               keyAttrs.addAttribute(StyleConstants.Foreground, Color.BLUE);
+
+
+               for (int i = 0 ; i < split.length ; i++) { /* foreach line */
+                       String startStr = null; /* before the key */
+                       String keyStr = null; /* the key */
+                       String endStr = null; /* after the key */
+
+                       for (int j = 0 ; j < RECOGNIZED_KEYS.length ; j++) { /* 
foreach key type */
+
+                               int startKeyInt = 
split[i].indexOf(RECOGNIZED_KEYS[j][0]);
+
+                               if (startKeyInt >= 0) {
+                                       startStr = split[i].substring(0, 
startKeyInt);
+
+                                       String keyAndEndStr = 
split[i].substring(startKeyInt);
+
+                                       int keyEndInt = -1;
+
+                                       if (RECOGNIZED_KEYS[j][1] != null) {
+                                               keyEndInt = 
keyAndEndStr.indexOf(RECOGNIZED_KEYS[j][1]);
+
+                                               if (keyEndInt >= 0) {
+                                                       keyEndInt += 
RECOGNIZED_KEYS[j][1].length();
+                                               }
+
+                                       }
+
+                                       if (keyEndInt < 0
+                                           && RECOGNIZED_KEYS[j][1] != null
+                                           && !" 
".equals(RECOGNIZED_KEYS[j][1])) {
+                                               startStr = null;
+                                               continue; /* will try to find 
another key */
+                                       }
+
+                                       if (keyEndInt >= 0) {
+                                               keyStr = 
keyAndEndStr.substring(0, keyEndInt);
+                                               endStr = 
keyAndEndStr.substring(keyEndInt);
+                                       } else {
+                                               keyStr = keyAndEndStr;
+                                               endStr = null;
+                                       }
+
+
+                                       break; /* we got a key */
+                               }
+                       }
+
+
+                       try {
+                               /* insertString() will generate Elements and 
insert them in the document */
+
+                               if (startStr == null) {
+                                       doc.insertString(doc.getLength(), 
split[i], noAttrs);
+                               } else {
+                                       doc.insertString(doc.getLength(), 
startStr, noAttrs);
+                               }
+
+                               if (keyStr != null) {
+                                       keys.add(keyStr);
+
+                                       SimpleAttributeSet cloned = 
(SimpleAttributeSet)keyAttrs.clone();
+
+                                       cloned.addAttribute(KEY_ATTRIBUTE, new 
KeyLinkAction(keyStr));
+
+                                       doc.insertString(doc.getLength(), 
keyStr, cloned);
+                               }
+
+                               if (endStr != null)
+                                       doc.insertString(doc.getLength(), 
endStr, noAttrs);
+
+                               if (i != split.length-1)
+                                       doc.insertString(doc.getLength(), "\n", 
noAttrs);
+                       } catch(javax.swing.text.BadLocationException e) {
+                               Logger.error(this, "Error while parsing the 
text: "+e.toString()+" ; A line will be missing");
+                               e.printStackTrace();
+                       }
+               }
+
+               return doc;
+
+       }
+
+
+       protected class KeyLinkAction {
+               private String key;
+
+               public KeyLinkAction(String key) {
+                       this.key = key;
+               }
+
+               public void execute(MouseEvent e) {
+                       messagePanel.popMenuOnKey(e, key);
+               }
+
+       }
+
+
+       protected class TextMouseMotionListener extends MouseInputAdapter {
+               private TextPanel txtArea;
+               private StyledDocument doc;
+
+               public TextMouseMotionListener(TextPanel txtArea, 
StyledDocument doc) {
+                       this.txtArea = txtArea;
+                       this.doc = doc;
+               }
+
+                public void mouseMoved(MouseEvent e) {
+                        Element elem = 
doc.getCharacterElement(txtArea.viewToModel(e.getPoint()));
+                        AttributeSet as = elem.getAttributes();
+                        if(StyleConstants.isUnderline(as))
+                                txtArea.setCursor(new 
Cursor(Cursor.HAND_CURSOR));
+                        else
+                                txtArea.setCursor(new 
Cursor(Cursor.DEFAULT_CURSOR));
+                }
+        }
+
+
+       protected class TextClickListener extends MouseAdapter {
+               private TextPanel txtArea;
+               private StyledDocument doc;
+
+               public TextClickListener(TextPanel txtArea, StyledDocument doc) 
{
+                       this.txtArea = txtArea;
+                       this.doc = doc;
+               }
+
+               public void mouseClicked( MouseEvent e ) {
+                       Element elem = 
doc.getCharacterElement(txtArea.viewToModel(e.getPoint()));
+                       AttributeSet as = elem.getAttributes();
+                       KeyLinkAction fla = 
(KeyLinkAction)as.getAttribute(KEY_ATTRIBUTE);
+
+                       if(fla != null)
+                               fla.execute(e);
+               }
+       }
+
+       private JComponent getEditorPane(String txt) {
                TextPanel a = new TextPanel();

-               a.setContentType("text/html");
-
                a.setFont(a.getFont().deriveFont((float)13.5));
                a.setEditable(false);

-               a.setText(txt);
+               StyledDocument doc = parseText(txt);

+               a.setStyledDocument(parseText(txt));
+
                a.firePropertyChange("lineWrap", false, true);
                a.firePropertyChange("wrapStyleWord", false, true);

+               a.addMouseListener(new TextClickListener(a, doc));
+               a.addMouseMotionListener(new TextMouseMotionListener(a, doc));
+
+               /*
                JScrollPane pane = new JScrollPane(a,
                                                   
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
                                                   
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+               */

-               return pane;
+               return a;
        }

        public void setRetracted(boolean retracted) {


Reply via email to