Author: jflesch
Date: 2007-08-30 14:57:43 +0000 (Thu, 30 Aug 2007)
New Revision: 14925

Added:
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/SubMessagePanel.java
Modified:
   trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
   trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostPanel.java
Log:
Fix an NPE reported by tooom (#freenet-fr) : Throwed when many Thaw are used 
with nameless keys

Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2007-08-30 14:51:36 UTC 
(rev 14924)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2007-08-30 14:57:43 UTC 
(rev 14925)
@@ -1017,7 +1017,9 @@
        }

        public String getFilename() {
-               return filename.replaceAll("\\|", "-");
+               if (filename != null)
+                       return filename.replaceAll("\\|", "-");
+               return key;
        }

        public int getAttempt() {

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-08-30 14:51:36 UTC 
(rev 14924)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-08-30 14:57:43 UTC 
(rev 14925)
@@ -154,7 +154,9 @@

 thaw.config.uncheckIfProblem=(D\u00e9sactiver cette option en cas de 
probl\u00e8me)

+thaw.config.downloadLocally=T\u00e9l\u00e9charger les fichiers depuis la node

+
 ## Plugins
 thaw.plugin.queueWatcher=Transferts


Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java        
2007-08-30 14:51:36 UTC (rev 14924)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessagePanel.java        
2007-08-30 14:57:43 UTC (rev 14925)
@@ -88,7 +88,9 @@
                msgsPanel = new JPanel(new BorderLayout(0, 20));
                msgsPanel.add(new JLabel(""), BorderLayout.CENTER);

-               scrollPane = new JScrollPane(msgsPanel);
+               scrollPane = new JScrollPane(msgsPanel,
+                                            
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
+                                            
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                panel.add(scrollPane, BorderLayout.CENTER);


@@ -132,6 +134,15 @@
                panel.add(northPanel, BorderLayout.NORTH);
        }

+
+       public MiniFrostPanel getMiniFrostPanel() {
+               return mainPanel;
+       }
+
+       public void revalidate() {
+               panel.revalidate();
+       }
+
        public void hided() {
                nextUnread.setMnemonic(KeyEvent.VK_Z);
        }
@@ -154,153 +165,7 @@
        }


-       protected class AuthorPanel extends JPanel implements ActionListener {
-               private JComboBox box = null;
-               private JLabel nick;
-               private Author author;

-               public AuthorPanel(Author author) {
-                       super(new BorderLayout(5, 5));
-
-                       this.author = author;
-
-                       nick = new JLabel(" "+author.toString(false));
-
-                       add(nick, BorderLayout.CENTER);
-
-                       if (author.getIdentity() != null
-                           && author.getIdentity().getPrivateKey() == null) {
-
-                               if (author.getIdentity().getTrustLevel()
-                                   == Identity.trustLevelInt[0]) /* if dev */
-                                       box = new 
JComboBox(Identity.trustLevelStr);
-                               else
-                                       box = new 
JComboBox(Identity.trustLevelUserStr);
-
-                               
nick.setForeground(author.getIdentity().getTrustLevelColor());
-
-                               
box.setSelectedItem(author.getIdentity().getTrustLevelStr());
-                               
box.setForeground(author.getIdentity().getTrustLevelColor());
-                               box.addActionListener(this);
-
-                               add(box, BorderLayout.EAST);
-
-                       } else if (author.getIdentity() != null) {
-
-                               JLabel status = new 
JLabel(I18n.getMessage("thaw.plugin.signature.trustLevel.me"));
-                               
status.setForeground(author.getIdentity().getTrustLevelColor());
-                               add(status, BorderLayout.EAST);
-
-                       }
-               }
-
-               public void actionPerformed(ActionEvent e) {
-                       
author.getIdentity().setTrustLevel((String)box.getSelectedItem());
-                       
box.setForeground(author.getIdentity().getTrustLevelColor());
-                       
nick.setForeground(author.getIdentity().getTrustLevelColor());
-
-                       /* we just refresh, because if now the trust level is 
below what must be
-                        * displayed ... */
-                       mainPanel.getMessageTreeTable().refresh();
-               }
-       }
-
-       protected class SubMessagePanel extends JPanel implements 
ActionListener {
-               private JButton upDownButton;
-               private boolean retracted;
-               private SubMessage msg;
-
-               private JTextArea area;
-
-
-               public SubMessagePanel(SubMessage msg, boolean retracted) {
-
-                       super(new BorderLayout(5,5));
-
-
-                       this.retracted=retracted;
-                       this.msg = msg;
-
-                       setBorder(BorderFactory.createLineBorder(Color.BLACK));
-
-
-                       /* header */
-                       JPanel headPanel = new JPanel(new BorderLayout(40, 40));
-
-                       JLabel dateLabel = new 
JLabel(java.text.DateFormat.getDateTimeInstance().format(msg.getDate()));
-                       AuthorPanel authorLabel = new 
AuthorPanel(msg.getAuthor());
-                       //authorLabel.setPreferredSize(new 
java.awt.Dimension(400, 15));
-
-
-                       upDownButton = new JButton("", (retracted ? 
IconBox.minDown : IconBox.minUp));
-                       upDownButton.addActionListener(this);
-
-                       JPanel rightPanel = new JPanel(new BorderLayout(10, 
10));
-                       rightPanel.add(dateLabel, BorderLayout.CENTER);
-                       rightPanel.add(upDownButton,BorderLayout.EAST);
-
-                       headPanel.add(authorLabel, BorderLayout.CENTER);
-                       headPanel.add(rightPanel, BorderLayout.EAST);
-
-                       this.add(headPanel, BorderLayout.NORTH);
-
-
-                       /* text */
-
-                       if (!retracted) {
-                               area = getTextArea(msg.getMessage().trim());
-
-                               this.add(area, BorderLayout.CENTER);
-                       }
-
-               }
-
-               private JTextArea getTextArea(String txt) {
-                       JTextArea a = new JTextArea(txt);
-
-                       a.setLineWrap(true);
-                       a.setWrapStyleWord(true);
-                       a.setFont(a.getFont().deriveFont((float)13.5));
-                       a.setEditable(false);
-
-                       return a;
-               }
-
-
-               public void forceDot() {
-                       area.getCaret().setDot(msg.getMessage().length());
-               }
-
-               public void setRetracted(boolean retracted) {
-                       if (!retracted) {
-                               area = getTextArea(msg.getMessage());
-                               this.add(area, BorderLayout.CENTER);
-
-                               upDownButton.setIcon(IconBox.minUp);
-                       } else {
-                               if (area != null)
-                                       this.remove(area);
-                               area = null;
-                               upDownButton.setIcon(IconBox.minDown);
-                       }
-
-                       this.retracted = retracted;
-
-                       this.revalidate();
-                       panel.revalidate();
-                       msgsPanel.revalidate();
-               }
-
-
-               public void actionPerformed(ActionEvent e) {
-                       if (e.getSource() == upDownButton) {
-                               setRetracted(!retracted);
-                       }
-               }
-
-       }
-
-
        protected class AttachmentAction extends JMenuItem
                implements ActionListener {

@@ -402,7 +267,7 @@
                        SubMessage subMsg = (SubMessage)it.next();
                        //SubMessagePanel panel = new SubMessagePanel(subMsg,
                        //                                          (i + 
DEFAULT_UNFOLDED) < subMsgs.size());
-                       SubMessagePanel panel = new SubMessagePanel(subMsg, 
false);
+                       SubMessagePanel panel = new SubMessagePanel(this, 
subMsg, false);

                        subPanels.add(panel);

@@ -466,6 +331,11 @@
        }


+       public JScrollPane getScrollPane() {
+               return scrollPane;
+       }
+
+
        private void putScrollBarAtBottom() {
                int max = scrollPane.getVerticalScrollBar().getMaximum();
                scrollPane.getVerticalScrollBar().setValue(max);

Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostPanel.java      
2007-08-30 14:51:36 UTC (rev 14924)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostPanel.java      
2007-08-30 14:57:43 UTC (rev 14925)
@@ -20,12 +20,11 @@

 /**
  * Some explanations :<br/>
- * At the beginning, I wanted to the UI like Frost, with a board tree, a 
message tree,
- * etc. In the end, I will do like Gmail : Smart. :) <br/>
+ * At the beginning, I wanted to the UI like Frost, with a board tree,
+ * etc. In the end, a board list is enought <br/>
  * So:
  * <ul>
  * <li>BoardTree => Board list</li>
- * <li>MessageTreeTable => message table</li>
  * </ul>
  */
 public class MiniFrostPanel implements Observer {

Added: trunk/apps/Thaw/src/thaw/plugins/miniFrost/SubMessagePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/SubMessagePanel.java             
                (rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/SubMessagePanel.java     
2007-08-30 14:57:43 UTC (rev 14925)
@@ -0,0 +1,230 @@
+package thaw.plugins.miniFrost;
+
+import javax.swing.JButton;
+import javax.swing.JEditorPane;
+import javax.swing.JComboBox;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+import javax.swing.JLabel;
+import javax.swing.JEditorPane;
+import javax.swing.JTextPane;
+import javax.swing.JScrollPane;
+
+import javax.swing.BorderFactory;
+
+import java.awt.BorderLayout;
+import java.awt.GridLayout;
+
+import java.awt.Rectangle;
+import java.awt.Dimension;
+
+import java.awt.Color;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+import thaw.plugins.miniFrost.interfaces.Author;
+import thaw.plugins.miniFrost.interfaces.SubMessage;
+
+import thaw.gui.IconBox;
+import thaw.plugins.signatures.Identity;
+import thaw.core.I18n;
+
+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 MessagePanel messagePanel;
+
+       public SubMessagePanel(MessagePanel messagePanel, SubMessage msg, 
boolean retracted) {
+
+               super(new BorderLayout(5,5));
+
+               this.messagePanel = messagePanel;
+               this.retracted=retracted;
+               this.msg = msg;
+
+               setBorder(BorderFactory.createLineBorder(Color.BLACK));
+
+
+               /* header */
+               JPanel headPanel = new JPanel(new BorderLayout(40, 40));
+
+               JLabel dateLabel = new 
JLabel(java.text.DateFormat.getDateTimeInstance().format(msg.getDate()));
+               AuthorPanel authorLabel = new AuthorPanel(msg.getAuthor());
+               //authorLabel.setPreferredSize(new java.awt.Dimension(400, 15));
+
+
+               upDownButton = new JButton("", (retracted ? IconBox.minDown : 
IconBox.minUp));
+               upDownButton.addActionListener(this);
+
+               JPanel rightPanel = new JPanel(new BorderLayout(10, 10));
+               rightPanel.add(dateLabel, BorderLayout.CENTER);
+               rightPanel.add(upDownButton,BorderLayout.EAST);
+
+               headPanel.add(authorLabel, BorderLayout.CENTER);
+               headPanel.add(rightPanel, BorderLayout.EAST);
+
+               this.add(headPanel, BorderLayout.NORTH);
+
+
+               /* text */
+
+               if (!retracted) {
+                       area = getEditorPane(msg.getMessage().trim());
+
+                       this.add(area, BorderLayout.CENTER);
+               }
+
+       }
+
+
+       protected class AuthorPanel extends JPanel implements ActionListener {
+               private JComboBox box = null;
+               private JLabel nick;
+               private Author author;
+
+               public AuthorPanel(Author author) {
+                       super(new BorderLayout(5, 5));
+
+                       this.author = author;
+
+                       nick = new JLabel(" "+author.toString(false));
+
+                       add(nick, BorderLayout.CENTER);
+
+                       if (author.getIdentity() != null
+                           && author.getIdentity().getPrivateKey() == null) {
+
+                               if (author.getIdentity().getTrustLevel()
+                                   == Identity.trustLevelInt[0]) /* if dev */
+                                       box = new 
JComboBox(Identity.trustLevelStr);
+                               else
+                                       box = new 
JComboBox(Identity.trustLevelUserStr);
+
+                               
nick.setForeground(author.getIdentity().getTrustLevelColor());
+
+                               
box.setSelectedItem(author.getIdentity().getTrustLevelStr());
+                               
box.setForeground(author.getIdentity().getTrustLevelColor());
+                               box.addActionListener(this);
+
+                               add(box, BorderLayout.EAST);
+
+                       } else if (author.getIdentity() != null) {
+
+                               JLabel status = new 
JLabel(I18n.getMessage("thaw.plugin.signature.trustLevel.me"));
+                               
status.setForeground(author.getIdentity().getTrustLevelColor());
+                               add(status, BorderLayout.EAST);
+
+                       }
+               }
+
+               public void actionPerformed(ActionEvent e) {
+                       
author.getIdentity().setTrustLevel((String)box.getSelectedItem());
+                       
box.setForeground(author.getIdentity().getTrustLevelColor());
+                       
nick.setForeground(author.getIdentity().getTrustLevelColor());
+
+                       /* we just refresh, because if now the trust level is 
below what must be
+                        * displayed ... */
+                       
messagePanel.getMiniFrostPanel().getMessageTreeTable().refresh();
+               }
+       }
+
+
+
+       private class TextPanel extends JTextPane {
+
+               public TextPanel() {
+                       super();
+               }
+
+               private Rectangle rect(javax.swing.text.Position p)
+                       throws javax.swing.text.BadLocationException
+                       {
+                               int off = p.getOffset();
+                               Rectangle r = modelToView(off>0 ? off-1 : off);
+                               return r;
+                       }
+
+
+               public Dimension getPreferredSize() {
+                       try {
+                               Rectangle start =
+                                       rect(getDocument().getStartPosition());
+                               Rectangle end =
+                                       rect(getDocument().getEndPosition());
+                               if (start==null || end==null) {
+                                       return super.getPreferredSize();
+                               }
+                               int height = end.y + end.height - start.y + 4;
+
+                               return new 
Dimension(messagePanel.getScrollPane().getWidth()-30, height);
+
+                       } catch (javax.swing.text.BadLocationException e) {
+                               return super.getPreferredSize();
+                       }
+               }
+
+       }
+
+
+       public final static String[][] RECOGNIZED_KEYS = {
+               { "KSK@", " " /* or eol */ },
+               { "CHK@", null /* eol */ },
+               { "USK@", ".frdx" },
+       };
+
+
+
+       private JScrollPane 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);
+
+               a.firePropertyChange("lineWrap", false, true);
+               a.firePropertyChange("wrapStyleWord", false, true);
+
+               JScrollPane pane = new JScrollPane(a,
+                                                  
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
+                                                  
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
+               return pane;
+       }
+
+       public void setRetracted(boolean retracted) {
+               if (!retracted) {
+                       area = getEditorPane(msg.getMessage());
+                       this.add(area, BorderLayout.CENTER);
+
+                       upDownButton.setIcon(IconBox.minUp);
+               } else {
+                       if (area != null)
+                               this.remove(area);
+                       area = null;
+                       upDownButton.setIcon(IconBox.minDown);
+               }
+
+               this.retracted = retracted;
+
+               messagePanel.revalidate();
+       }
+
+
+       public void actionPerformed(ActionEvent e) {
+               if (e.getSource() == upDownButton) {
+                       setRetracted(!retracted);
+               }
+       }
+
+}


Reply via email to