Author: dieppe
Date: 2008-02-21 21:16:48 +0000 (Thu, 21 Feb 2008)
New Revision: 18099

Added:
   
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBFlogWizardDialog.java
Modified:
   
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/ThingamablogFrame.java
   
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBGeneralPanel.java
   
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBPublishTransportPanel.java
   
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWeblogPropertiesDialog.java
   
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWizardDialog.java
Log:
GUI improvement : new wizard for the flogs;
                  TBPublishTransportPanel allow to generate other keys;
Some few little other changes;


Modified: 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/ThingamablogFrame.java
===================================================================
--- 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/ThingamablogFrame.java  
    2008-02-21 19:47:31 UTC (rev 18098)
+++ 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/app/ThingamablogFrame.java  
    2008-02-21 21:16:48 UTC (rev 18099)
@@ -98,6 +98,7 @@
 import net.sf.thingamablog.gui.ViewerPane;
 import net.sf.thingamablog.gui.editor.EntryEditor;
 import net.sf.thingamablog.gui.editor.HTMLEditor;
+import net.sf.thingamablog.gui.properties.TBFlogWizardDialog;
 import net.sf.thingamablog.gui.properties.TBWizardDialog;
 import net.sf.thingamablog.gui.properties.WeblogPropertiesDialogFactory;
 import net.sf.thingamablog.gui.table.JSortTable;
@@ -221,6 +222,7 @@
        //private Action importLegacyWeblogAction;

        private Action newWeblogAction;
+        private Action newFlogAction;
        private Action deleteWeblogAction;

        private Action importFileAction;
@@ -763,6 +765,8 @@
                actions.add(weblogPropertiesAction);
                newWeblogAction = new NewWeblogAction();
                actions.add(newWeblogAction);
+                newFlogAction = new NewFlogAction();
+                actions.add(newFlogAction);
                deleteWeblogAction = new DeleteWeblogAction();
                actions.add(deleteWeblogAction);
                editTemplateAction = new EditTemplateAction();
@@ -870,6 +874,7 @@
                JMenu fileMenu = new JMenu(i18n.str("file")); //$NON-NLS-1$
                fileMenu.setMnemonic(i18n.mnem("file")); //$NON-NLS-1$
                fileMenu.add(newWeblogAction);
+                fileMenu.add(newFlogAction);
                fileMenu.add(newEntryAction);
                //fileMenu.add(newFeedAction);
                fileMenu.addSeparator();
@@ -1301,6 +1306,35 @@
                        selectWeblog(wiz.getWeblog());
                }
        }
+        
+               
+        private void showNewFlogWizard()
+       {
+               if(!isDBOpen)
+               {
+                   JOptionPane.showMessageDialog(FRAME, 
i18n.str("no_database_is_open")); //$NON-NLS-1$
+                   return;
+               }
+           
+                TBFlogWizardDialog wiz = new TBFlogWizardDialog(FRAME, curDB, 
backend);
+               wiz.setLocationRelativeTo(FRAME);
+               wiz.setVisible(true);
+               
+               if(!wiz.hasUserCancelled())
+               {
+                       Weblog w = wiz.getWeblog();
+            weblogList.addWeblog(w);
+            taskDialog.addWeblog(w);
+            
+                       weblogTreeModel.setData(weblogList);                    
        
+                       if(searchDialog != null)
+                               searchDialog.setWeblogList(weblogList);
+                               
+                       //updateActions();
+                       saveCurrentData();
+                       selectWeblog(wiz.getWeblog());
+               }
+       }

        private void selectWeblog(Weblog blog)
        {
@@ -3700,6 +3734,33 @@
                    showNewWeblogWizard();
                }       
        }
+        
+        //************************************************
+       //Action for creating a new Flog from the wizard
+       //************************************************
+       private class NewFlogAction extends AbstractAction
+       {
+               /**
+         * 
+         */
+        private static final long serialVersionUID = 1L;
+
+        public NewFlogAction()
+               {
+                       super(i18n.str("new_flog_")); //$NON-NLS-1$
+            putValue(MNEMONIC_KEY, new Integer(i18n.mnem("new_flog_"))); 
//$NON-NLS-1$
+                       putValue(ACCELERATOR_KEY,
+                               KeyStroke.getKeyStroke(KeyEvent.VK_F, 
Event.CTRL_MASK));
+                       putValue(Action.SMALL_ICON, 
+                UIUtils.getIcon(UIUtils.X16, "flog_glow.png")); //$NON-NLS-1$
+                       putValue("LARGE_ICON", UIUtils.getIcon(UIUtils.X24, 
"flog_glow.png"));
+               }
+               
+               public void actionPerformed(ActionEvent e)
+               {
+                   showNewFlogWizard();
+               }       
+       }

        //*************************************************
        //Action for deleting the currently selected weblog

Added: 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBFlogWizardDialog.java
===================================================================
--- 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBFlogWizardDialog.java
                              (rev 0)
+++ 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBFlogWizardDialog.java
      2008-02-21 21:16:48 UTC (rev 18099)
@@ -0,0 +1,697 @@
+
+package net.sf.thingamablog.gui.properties;
+
+import java.awt.BorderLayout;
+import java.awt.CardLayout;
+import java.awt.Color;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.EtchedBorder;
+
+import net.atlanticbb.tantlinger.i18n.I18n;
+import net.atlanticbb.tantlinger.ui.UIUtils;
+import net.atlanticbb.tantlinger.ui.text.TextEditPopupManager;
+import net.sf.thingamablog.TBGlobals;
+import net.sf.thingamablog.blog.Author;
+import net.sf.thingamablog.blog.BackendException;
+import net.sf.thingamablog.blog.TBWeblog;
+import net.sf.thingamablog.blog.TemplatePack;
+import net.sf.thingamablog.blog.WeblogBackend;
+import net.sf.thingamablog.blog.WeblogsDotComPing;
+import net.sf.thingamablog.gui.LabelledItemPanel;
+import net.sf.thingamablog.gui.MultilineText;
+import net.sf.thingamablog.gui.app.TemplateSelectionPanel;
+import net.sf.thingamablog.gui.app.WeblogPreviewer;
+import net.sf.thingamablog.transport.FCPTransport;
+import net.sf.thingamablog.transport.LocalTransport;
+import net.sf.thingamablog.util.freenet.fcp.fcpManager;
+import net.sf.thingamablog.util.string.ASCIIconv;
+
+
+
+
+/**
+ * @author Dieppe
+ *
+ *
+ *
+ */
+public class TBFlogWizardDialog extends JDialog {
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+    
+    private static final I18n i18n = 
I18n.getInstance("net.sf.thingamablog.gui.properties"); //$NON-NLS-1$
+    private Logger logger = 
Logger.getLogger("net.sf.thingamablog.gui.properties");
+    
+    private static final String CANCEL = i18n.str("cancel"); //$NON-NLS-1$
+    private static final String FINISH = i18n.str("finish");    //$NON-NLS-1$
+    
+    private CardLayout wizLayout;
+    private JPanel wizPanel;
+    
+    private PropertyPanel starterPanel;
+    private TitleDescrPanel titlePanel;
+    private CategoriesPanel catPanel;
+    private AuthorsPanel authPanel;
+    private PropertyPanel emailPanel;
+    private PropertyPanel templPanel;
+    private PropertyPanel transportPanel;
+    private PropertyPanel donePanel;
+    private Vector panels = new Vector();
+    
+    private JButton nextButton, backButton, doneButton;
+    
+    private boolean isCancelled;
+    
+    private TBWeblog flog;
+    
+    private TextEditPopupManager popupManager = 
TextEditPopupManager.getInstance();
+    
+    private TemplatePack selectedPack;
+    
+    public TBFlogWizardDialog(Frame f, File dir, WeblogBackend backend) {
+        super(f, true);
+        setTitle(i18n.str("new_flog")); //$NON-NLS-1$
+        
+        WindowAdapter windowAdapter = new WindowAdapter() {
+            public void windowClosing(WindowEvent windowEvent) {
+                cancelDialog();
+            }
+        };
+        addWindowListener(windowAdapter);
+        
+        flog = new TBWeblog(dir);
+        flog.setBackend(backend);
+        try {
+            fcpManager Manager = new fcpManager();
+            int port = Integer.parseInt(TBGlobals.getProperty("NODE_PORT"));
+            String keys[]=new String[2];
+            String hostname = TBGlobals.getProperty("NODE_HOSTNAME");
+            Manager.setNode(hostname,port);            
+            keys=Manager.generateKeyPair();
+            Manager.getConnection().disconnect();
+            // We put "USK" instead of "SSK"
+            keys[1] = keys[1].substring("SSK".length());
+            String url = "USK" + keys[1];
+            flog.setBlogUrls("",url,url,url);
+            
+            flog.setPublishTransport(new 
net.sf.thingamablog.transport.FCPTransport());
+            ((FCPTransport) flog.getPublishTransport()).setInsertURI(keys[0]); 
           
+        } catch (IOException ex) {
+            logger.log(Level.INFO,"Node unreachable : " + ex.getMessage());
+            logger.log(Level.INFO,"Transport method set to Local");
+            flog.setPublishTransport(new 
net.sf.thingamablog.transport.LocalTransport());
+        }
+        
+        //weblog.setAuthorStore(authStore);
+        //weblog.setCategoryStore(catStore);
+        
+        wizLayout = new CardLayout();
+        wizPanel = new JPanel(wizLayout);
+        
+        starterPanel = new StarterPanel();
+        starterPanel.setBorder(new EmptyBorder(15, 10, 15, 10));
+        panels.add(starterPanel);
+        
+        titlePanel = new TitleDescrPanel();
+        titlePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+        panels.add(titlePanel);
+        
+        catPanel = new CategoriesPanel();
+        catPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+        panels.add(catPanel);
+        
+        authPanel = new AuthorsPanel();
+        authPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+        panels.add(authPanel);
+        
+        emailPanel = new EmailPanel();
+        emailPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+        panels.add(emailPanel);
+        
+        templPanel = new TemplatePanel();
+        templPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+        panels.add(templPanel);
+        
+        transportPanel = new TransportPanel();
+        transportPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+        panels.add(transportPanel);
+        
+        donePanel = new DonePanel();
+        donePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+        panels.add(donePanel);
+        
+        wizPanel.add(starterPanel, "1"); //$NON-NLS-1$
+        wizPanel.add(titlePanel, "2"); //$NON-NLS-1$
+        wizPanel.add(catPanel, "3"); //$NON-NLS-1$
+        wizPanel.add(authPanel, "4"); //$NON-NLS-1$
+        wizPanel.add(emailPanel, "5"); //$NON-NLS-1$
+        wizPanel.add(templPanel, "6"); //$NON-NLS-1$
+        wizPanel.add(transportPanel, "7"); //$NON-NLS-1$
+        wizPanel.add(donePanel, "8");   //$NON-NLS-1$
+        
+        ActionListener listener = new ButtonHandler();
+        nextButton = new JButton(i18n.str("next-")); //$NON-NLS-1$
+        nextButton.addActionListener(listener);
+        backButton = new JButton(i18n.str("-back")); //$NON-NLS-1$
+        backButton.setEnabled(false);
+        backButton.addActionListener(listener);
+        doneButton = new JButton(CANCEL);
+        doneButton.addActionListener(listener);
+        
+        JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+        controlPanel.setBorder(new EtchedBorder());
+        JPanel buttonPanel = new JPanel(new GridLayout(1, 3, 5, 5));
+        buttonPanel.add(backButton);
+        buttonPanel.add(nextButton);
+        buttonPanel.add(doneButton);
+        controlPanel.add(buttonPanel);
+        
+        JLabel img = new JLabel();
+        img.setVerticalAlignment(SwingConstants.TOP);
+        img.setOpaque(true);
+        img.setBackground(Color.WHITE);
+        img.setIcon(UIUtils.getIcon(UIUtils.MISC, "wizard.jpg")); //$NON-NLS-1$
+        
+        getContentPane().add(wizPanel, BorderLayout.CENTER);
+        getContentPane().add(controlPanel, BorderLayout.SOUTH);
+        getContentPane().add(img, BorderLayout.WEST);
+        
+        pack();
+        setSize(560, getHeight());
+        setResizable(false);
+    }
+    
+    public TBWeblog getWeblog() {
+        return flog;
+    }
+    
+    public boolean hasUserCancelled() {
+        return isCancelled;
+    }
+    
+    private void doFinish() {
+                /*for(int i = 0; i < panels.size(); i++)
+                {
+                        PropertyPanel p = (PropertyPanel)panels.elementAt(i);
+                        p.saveProperties();
+                }*/
+        
+        try {
+            donePanel.saveProperties();
+            selectedPack.installPack(flog.getHomeDirectory());
+        } catch(Exception ex) {
+            UIUtils.showError(this, ex);
+        }
+        
+        //add a couple ping services
+        WeblogsDotComPing ping = new WeblogsDotComPing();
+        
+        //removed because the TAMB ping server has been shutdown...
+                /*ping.setServiceName("Updated Thingamablogs");
+                
ping.setServiceUrl("http://thingamablog.sourceforge.net/rpc.php";);
+                ping.setEnabled(true);
+                weblog.addPingService(ping);*/
+        
+        ping = new WeblogsDotComPing();
+        ping.setServiceName("weblogs.com"); //$NON-NLS-1$
+        ping.setServiceUrl("http://rpc.weblogs.com/RPC2";); //$NON-NLS-1$
+        ping.setEnabled(false);
+        flog.addPingService(ping);
+        
+        dispose();
+    }
+    
+    private void cancelDialog() {
+        isCancelled = true;
+        try{
+            flog.deleteAll();
+        }catch(BackendException ex){}
+        dispose();
+    }
+    
+    public void dispose() {
+        WeblogPreviewer.getInstance().clearPreviewData();
+        super.dispose();
+    }
+    
+    
+    private JLabel createHeaderLabel(String text) {
+        JLabel label = new JLabel("<html><h2>" + text + "</h2></html>"); 
//$NON-NLS-1$ //$NON-NLS-2$
+        return label;
+    }
+    
+    
+    
+    private PropertyPanel getCurrentPanel() {
+        for(int i = 0; i < panels.size(); i++) {
+            PropertyPanel p = (PropertyPanel)panels.elementAt(i);
+            if(p.isVisible()) {
+                //return p.isValidData();
+                return p;
+            }
+        }
+        
+        return null;
+    }
+    
+    private class ButtonHandler implements ActionListener {
+        public void actionPerformed(ActionEvent e) {
+            if(e.getSource() == nextButton) {
+                if(!donePanel.isVisible()) {
+                    //if(isCurrentPanelValid())
+                    PropertyPanel p = getCurrentPanel();
+                    if(p != null && p.isValidData()) {
+                        p.saveProperties();
+                        wizLayout.next(wizPanel);
+                    }
+                }
+                
+                if( donePanel.isVisible()) {
+                    doneButton.setText(FINISH);
+                    nextButton.setEnabled(false);
+                }
+                backButton.setEnabled(true);
+            } else if(e.getSource() == backButton) {
+                if(!starterPanel.isVisible())
+                    wizLayout.previous(wizPanel);
+                if(starterPanel.isVisible())
+                    backButton.setEnabled(false);
+                if(doneButton.getText().equals(FINISH))
+                    doneButton.setText(CANCEL);
+                nextButton.setEnabled(true);
+            } else if(e.getSource() == doneButton) {
+                //the new Weblog was canceled, so delete the
+                //directory structure that was created when
+                //the Weblog was instantiated
+                if(doneButton.getText().equals(FINISH)) {
+                    doFinish();
+                } else {
+                    cancelDialog();
+                }
+            }
+        }
+    }
+    
+    
+    
+    
+    private class StarterPanel extends PropertyPanel {
+        /**
+         *
+         */
+        private static final long serialVersionUID = 1L;
+        private JTextField pathField = new JTextField(20);
+        private JTextField requestUriField = new JTextField(20);
+        private JTextField insertUriField = new JTextField(20);
+        private fcpManager Manager = new fcpManager();
+        
+        public StarterPanel() {
+            LabelledItemPanel lip = new LabelledItemPanel();
+            JLabel header;
+            String text;
+            if(flog.getPublishTransport() instanceof LocalTransport) {
+                header = createHeaderLabel(i18n.str("flog_wizard_local"));     
                 //$NON-NLS-1$
+                text = i18n.str("welcome_flog_panel_text_local"); //$NON-NLS-1$
+                pathField.setText("The path of the flog's export directory");
+                requestUriField.setText("The entire request uri of your flog");
+                lip.addItem(i18n.str("base_path"), pathField); //$NON-NLS-1$
+                lip.addItem(i18n.str("requestUri"), requestUriField); 
//$NON-NLS-1$
+            } else {
+                header = createHeaderLabel(i18n.str("flog_wizard_fcp"));
+                text = i18n.str("welcome_flog_panel_text_fcp"); //$NON-NLS-1$
+                requestUriField.setEditable(false);
+                insertUriField.setEditable(false);
+                pathField.setText("none");
+                requestUriField.setText(flog.getBaseUrl());
+                insertUriField.setText("USK@" + ((FCPTransport) 
flog.getPublishTransport()).getInsertURI() + "/");
+                lip.addItem(i18n.str("requestUri"), requestUriField); 
//$NON-NLS-1$
+                lip.addItem(i18n.str("insertUri"), insertUriField); 
//$NON-NLS-1$
+            }            
+            
+            popupManager.registerJTextComponent(pathField);
+            popupManager.registerJTextComponent(requestUriField);
+            
+            setLayout(new BorderLayout());
+            add(header, BorderLayout.NORTH);
+            add(new MultilineText(text), BorderLayout.CENTER);
+            add(lip, BorderLayout.SOUTH);
+        }
+        
+        public boolean isValidData() {
+            if(pathField.getText().equals("")) //$NON-NLS-1$
+            {
+                JOptionPane.showMessageDialog(TBFlogWizardDialog.this,
+                        i18n.str("invalid_path_prompt"), 
i18n.str("invalid_path"),  //$NON-NLS-1$ //$NON-NLS-2$
+                        JOptionPane.WARNING_MESSAGE);
+                return false;
+            }
+            
+            if(requestUriField.getText().equals("")) //$NON-NLS-1$
+            {
+                JOptionPane.showMessageDialog(TBFlogWizardDialog.this,
+                        i18n.str("invalid_url_prompt"), 
i18n.str("invalid_url"),  //$NON-NLS-1$ //$NON-NLS-2$
+                        JOptionPane.WARNING_MESSAGE);
+                return false;
+            }
+            boolean valid = true;
+            valid = valid && isValidSSK(requestUriField.getText());
+            valid = valid && isValidSSK(insertUriField.getText());
+            return valid;
+        }
+        private boolean isValidSSK(String u) {
+            // TODO : Check if u match a SSK key
+            return true;
+        }
+        public void saveProperties() {
+            String path = pathField.getText();
+            String url = requestUriField.getText();
+            if(!url.endsWith("/")){ //$NON-NLS-1$
+                url += "/";; //$NON-NLS-1$
+            }
+            // If the flog is publish localy, we need a slash before the key
+            if(!url.startsWith("/") && flog.getPublishTransport() instanceof 
LocalTransport){
+                url = "/" + url;
+            }
+            String arcUrl = url + "archives"; //$NON-NLS-1$
+            String mediaUrl = url + "medias"; //$NON-NLS-1$
+            
+            flog.setBlogUrls(path, url, arcUrl, mediaUrl);
+            flog.setType("freenet");
+        }
+    }
+    
+    private class TitleDescrPanel extends PropertyPanel {
+        /**
+         *
+         */
+        private static final long serialVersionUID = 1L;
+        private JTextField titleField = new JTextField();
+        private JTextArea textArea = new JTextArea(4, 4);
+        
+        public TitleDescrPanel() {
+            setLayout(new BorderLayout());
+            
+            JPanel instrPanel = new JPanel(new BorderLayout());
+            JLabel header = 
createHeaderLabel(i18n.str("title_and_description")); //$NON-NLS-1$
+            String text =
+                    i18n.str("title_panel_text"); //$NON-NLS-1$
+            instrPanel.add(header, BorderLayout.NORTH);
+            instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
+            
+            popupManager.registerJTextComponent(titleField);
+            popupManager.registerJTextComponent(textArea);
+            
+            LabelledItemPanel lip = new LabelledItemPanel();
+            lip.addItem(i18n.str("site_title"), titleField); //$NON-NLS-1$
+            lip.addItem(i18n.str("description"), new JScrollPane(textArea)); 
//$NON-NLS-1$
+            
+            add(instrPanel, BorderLayout.NORTH);
+            add(lip, BorderLayout.CENTER);
+        }
+        
+        public boolean isValidData() {
+            if(titleField.getText().equals("")) //$NON-NLS-1$
+            {
+                JOptionPane.showMessageDialog(TBFlogWizardDialog.this,
+                        i18n.str("invalid_title_prompt"), i18n.str("title"), 
JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ //$NON-NLS-2$
+                return false;
+            }
+            return true;
+        }
+        
+        public void saveProperties() {
+            flog.setTitle(titleField.getText());
+            flog.setDescription(textArea.getText());
+        }
+        
+        public String getTitle() {
+            return titleField.getText();
+        }
+        
+        public String getDescription() {
+            return textArea.getText();
+        }
+    }
+    
+    private class CategoriesPanel extends PropertyPanel {
+        /**
+         *
+         */
+        private static final long serialVersionUID = 1L;
+        private EditableList list;
+        private WeblogEditableListModel model;
+        
+        public CategoriesPanel() {
+            setLayout(new BorderLayout(5, 5));
+            
+            JPanel instrPanel = new JPanel(new BorderLayout());
+            JLabel header = createHeaderLabel(i18n.str("categories")); 
//$NON-NLS-1$
+            String text =
+                    i18n.str("categories_panel_text"); //$NON-NLS-1$
+            instrPanel.add(header, BorderLayout.NORTH);
+            instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
+            
+            model = new 
WeblogEditableListModel(WeblogEditableListModel.CATEGORIES);
+            list = new EditableList(model);
+            setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
+            
+            add(instrPanel, BorderLayout.NORTH);
+            add(list, BorderLayout.CENTER);
+            
+            
+        }
+        
+        public boolean isValidData() {
+            return true;
+        }
+        
+        public void saveProperties() {
+            //ListModel lm = catList.getModel();
+            try {
+                model.syncListWithWeblog(flog);
+            } catch(Exception ex) {
+                ex.printStackTrace();
+            }
+        }
+        
+        public String[] getCategories() {
+            List data = list.getListData();
+            String[] cats = new String[data.size()];
+            for(int i = 0; i < cats.length; i++)
+                cats[i] = data.get(i).toString();
+            return cats;
+        }
+        
+        public WeblogEditableListModel getModel() {
+            return model;
+        }
+    }
+    
+    private class AuthorsPanel extends PropertyPanel {
+        /**
+         *
+         */
+        private static final long serialVersionUID = 1L;
+        private EditableList list;
+        private WeblogEditableListModel model;
+        
+        public AuthorsPanel() {
+            setLayout(new BorderLayout(5, 5));
+            
+            JPanel instrPanel = new JPanel(new BorderLayout());
+            JLabel header = createHeaderLabel(i18n.str("authors")); 
//$NON-NLS-1$
+            String text =
+                    i18n.str("authors_panel_text"); //$NON-NLS-1$
+            instrPanel.add(header, BorderLayout.NORTH);
+            instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
+            
+            model = new 
WeblogEditableListModel(WeblogEditableListModel.AUTHORS);
+            list = new EditableList(model);
+            setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
+            
+            add(instrPanel, BorderLayout.NORTH);
+            add(list, BorderLayout.CENTER);
+        }
+        
+        public boolean isValidData() {
+            return true;
+        }
+        
+        public void saveProperties() {
+            try {
+                model.syncListWithWeblog(flog);
+            } catch(Exception ex) {
+                ex.printStackTrace();
+            }
+        }
+        
+        public Author[] getAuthors() {
+            List data = list.getListData();
+            Author[] a = new Author[data.size()];
+            for(int i = 0; i < a.length; i++)
+                a[i] = (Author)data.get(i);
+            return a;
+        }
+        
+        public WeblogEditableListModel getModel() {
+            return model;
+        }
+    }
+    
+    private class EmailPanel extends PropertyPanel {
+        
+        /**
+         *
+         */
+        private static final long serialVersionUID = 1L;
+        TBEmailPanel emailPanel;
+        
+        public EmailPanel() {
+            setLayout(new BorderLayout(5, 5));
+            
+            JPanel instrPanel = new JPanel(new BorderLayout());
+            JLabel header = createHeaderLabel("Email"); //$NON-NLS-1$
+            String text =
+                    i18n.str("specify_mail_server_prompt"); //$NON-NLS-1$
+            
+            instrPanel.add(header, BorderLayout.NORTH);
+            instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
+            
+            emailPanel = new TBEmailPanel(flog);
+            add(instrPanel, BorderLayout.NORTH);
+            add(emailPanel, BorderLayout.CENTER);
+        }
+        
+        /* (non-Javadoc)
+         * @see net.sf.thingamablog.gui.properties.PropertyPanel#isValidData()
+         */
+        public boolean isValidData() {
+            return emailPanel.isValidData();
+        }
+        
+        /* (non-Javadoc)
+         * @see 
net.sf.thingamablog.gui.properties.PropertyPanel#saveProperties()
+         */
+        public void saveProperties() {
+            emailPanel.saveProperties();
+        }
+        
+    }
+    
+    private class TransportPanel extends PropertyPanel {
+        /**
+         *
+         */
+        private static final long serialVersionUID = 1L;
+        TBPublishTransportPanel pubPanel;
+        
+        public TransportPanel() {
+            setLayout(new BorderLayout());
+            
+            JPanel instrPanel = new JPanel(new BorderLayout());
+            JLabel header = createHeaderLabel(i18n.str("publishing")); 
//$NON-NLS-1$
+            String text =
+                    i18n.str("publishing_panel_text"); //$NON-NLS-1$
+            instrPanel.add(header, BorderLayout.NORTH);
+            instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
+            
+            pubPanel = new TBPublishTransportPanel(flog);
+            add(instrPanel, BorderLayout.NORTH);
+            add(pubPanel, BorderLayout.CENTER);
+        }
+        
+        public boolean isValidData() {
+            return pubPanel.isValidData();
+        }
+        
+        public void saveProperties() {
+            pubPanel.saveProperties();
+        }
+    }
+    
+    private class TemplatePanel extends PropertyPanel {
+        /**
+         *
+         */
+        private static final long serialVersionUID = 1L;
+        //private JComboBox tmplCombo;
+        //private TemplatePropertiesPanel propertyPanel;
+        private TemplateSelectionPanel selPanel;
+        
+        public TemplatePanel() {
+            JPanel instrPanel = new JPanel(new BorderLayout());
+            JLabel header = createHeaderLabel(i18n.str("templates")); 
//$NON-NLS-1$
+            String text =
+                    i18n.str("templates_panel_text"); //$NON-NLS-1$
+            instrPanel.add(header, BorderLayout.NORTH);
+            instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
+            
+            selPanel = new TemplateSelectionPanel(flog);
+            
+            setLayout(new BorderLayout(5, 5));
+            add(instrPanel, BorderLayout.NORTH);
+            add(selPanel, BorderLayout.CENTER);
+        }
+        
+        public boolean isValidData() {
+            if(selPanel.getSelectedPack() == null)
+                return false;
+            return true;
+        }
+        
+        public void saveProperties() {
+            selectedPack = selPanel.getSelectedPack();
+        }
+    }
+    
+    private class DonePanel extends PropertyPanel {
+        /**
+         *
+         */
+        private static final long serialVersionUID = 1L;
+        
+        public DonePanel() {
+            JLabel header = createHeaderLabel(i18n.str("done")); //$NON-NLS-1$
+            String text =
+                    i18n.str("finished_panel_text"); //$NON-NLS-1$
+            
+            setLayout(new BorderLayout());
+            add(header, BorderLayout.NORTH);
+            add(new MultilineText(text), BorderLayout.CENTER);
+        }
+        
+        public boolean isValidData() {
+            return true;
+        }
+        
+        public void saveProperties() {
+            System.out.println("Creating the flog...");
+        }
+    }
+}

Modified: 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBGeneralPanel.java
===================================================================
--- 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBGeneralPanel.java
  2008-02-21 19:47:31 UTC (rev 18098)
+++ 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBGeneralPanel.java
  2008-02-21 21:16:48 UTC (rev 18099)
@@ -46,6 +46,7 @@

        private JTextField titleField;
        private JTextArea descrArea;
+        private JTextField typeField;
        private JTextField basePathField;
        private JTextField urlField;
        private JTextField arcUrlField;
@@ -54,10 +55,8 @@
        private JComboBox localeCombo;
        private JComboBox dateFormatCombo;
        private JComboBox timeFormatCombo;
-        private JComboBox typeCombo;

        private static Locale LOCS[] = DateFormat.getAvailableLocales();
-        private static String TYPE[] = {"internet","freenet"};

        private String[] getDateFormats(Locale locale) {
                String s = i18n.str("DateFormatOptions",locale);
@@ -158,9 +157,10 @@
                timeFormatCombo = new 
JComboBox(getTimeFormats(weblog.getLocale()));
                
timeFormatCombo.setSelectedItem(weblog.getPageGenerator().getTimeFormat());
                timeFormatCombo.setRenderer(new ComboRenderer());
-               
-                typeCombo = new JComboBox(TYPE);
-                typeCombo.setSelectedItem(weblog.getType());
+                               
+                typeField = new JTextField();
+                typeField.setText(weblog.getType());
+                typeField.setEditable(false);                

                basePathField = new JTextField();
                basePathField.setText(weblog.getBasePath());
@@ -190,7 +190,7 @@
                lip1.addItem(i18n.str("language"), localeCombo); //$NON-NLS-1$
                lip1.addItem(i18n.str("date_format"), dateFormatCombo); 
//$NON-NLS-1$
                lip1.addItem(i18n.str("time_format"), timeFormatCombo); 
//$NON-NLS-1$
-               lip1.addItem(i18n.str("type"), typeCombo);
+               lip1.addItem(i18n.str("type"), typeField);

                LabelledItemPanel lip2 = new LabelledItemPanel();
                lip2.setBorder(new TitledBorder(i18n.str("location"))); 
//$NON-NLS-1$
@@ -224,7 +224,6 @@
         weblog.setDescription(descrArea.getText());
         
weblog.getPageGenerator().setDateFormat(dateFormatCombo.getSelectedItem().toString());
                
weblog.getPageGenerator().setTimeFormat(timeFormatCombo.getSelectedItem().toString());
-                weblog.setType(typeCombo.getSelectedItem().toString());
     }


@@ -243,10 +242,10 @@
                                return false;
                }

-               if(typeCombo.getSelectedItem().toString().equals("internet") && 
(!isValidUrl(base) || !isValidUrl(arc) || !isValidUrl(media)))
+               if(typeField.getText().equals("internet") && (!isValidUrl(base) 
|| !isValidUrl(arc) || !isValidUrl(media)))
                        return false;   

-                if(typeCombo.getSelectedItem().toString().equals("freenet") && 
(!isValidSSK(base)) || !isValidSSK(arc) || !isValidSSK(media))
+                if(typeField.getText().equals("freenet") && 
(!isValidSSK(base)) || !isValidSSK(arc) || !isValidSSK(media))
                         return false;

                if(!arc.startsWith(base))

Modified: 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBPublishTransportPanel.java
===================================================================
--- 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBPublishTransportPanel.java
 2008-02-21 19:47:31 UTC (rev 18098)
+++ 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBPublishTransportPanel.java
 2008-02-21 21:16:48 UTC (rev 18099)
@@ -36,6 +36,7 @@
 import java.util.SortedMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import javax.swing.JButton;

 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
@@ -78,7 +79,6 @@
        private final String SFTP = "SFTP"; //$NON-NLS-1$
        private final String LOCAL = "Local"; //$NON-NLS-1$
         private final String FCP = "FCP";
-        private String InsertURI;

        private TBWeblog weblog;
        private JComboBox encodingsCombo;
@@ -93,13 +93,13 @@
     private ASCIIPanel asciiPanel = new ASCIIPanel();
     private Logger logger = 
Logger.getLogger("net.sf.thingamablog.gui.properties");

-       public TBPublishTransportPanel(TBWeblog wb, String InsertURI)
+       public TBPublishTransportPanel(TBWeblog wb)
        {
                weblog = wb;
                 String types[];
                 tLayout = new CardLayout();
-                // If we are currently building a blog, the publish process 
can be FTP, SFTP, or LOCAL
-                if (weblog.getType().toString().equals("internet")) {          
          
+                // If we are currently building a blog, the publish process 
can be FTP, SFTP, or LOCAL (default set to FTP)
+                if (weblog.getPublishTransport() instanceof FTPTransport || 
(weblog.getType() != null && weblog.getType().equals("internet"))) {
                     types=new String[3];
                     types[0]="Local";
                     types[1]="FTP";
@@ -114,26 +114,24 @@
                     p.add(asciiPanel);
                     ftpTabs.add(p, "ASCII");
                  }
-                // Else, we are building a flog, and the transport process is 
LOCAL or FCP
-                else {
-                    // The InsertURI parameter is here only for the 
TBWizardDialog process (yes I know, it's quite ugly)
-                    if(weblog.getPublishTransport()==null || 
weblog.getPublishTransport() instanceof LocalTransport){
-                        this.InsertURI=InsertURI;
-                    } else {
-                        FCPTransport fcp = (FCPTransport) 
weblog.getPublishTransport();
-                        this.InsertURI=fcp.getInsertURI();
-                    }
+                // Else, we are building a flog, and the transport process is 
LOCAL or FCP 
+                else {                   
                     types=new String[2];
                     types[0]="Local";
                     types[1]="FCP";                    
                     fcpPanel = new FcpTransportPanel();
                     fcpPanel.setBorder(new 
TitledBorder(i18n.str("fcp_transport")));
+                    if(weblog.getPublishTransport() instanceof FCPTransport){
+                        types[0]="FCP";
+                        types[1]="Local";   
+                    }
+                    fcpPanel.setRequestUri(weblog.getBaseUrl());
                  }
                 localPanel = new JPanel();

                transportsPanel = new JPanel();
                transportsPanel.setLayout(tLayout);
-                if (weblog.getType().toString().equals("internet")) {
+                if (weblog.getPublishTransport() instanceof FTPTransport || 
(weblog.getType() != null && weblog.getType().equals("internet"))) {
                     transportsPanel.add(localPanel, LOCAL);
                     transportsPanel.add(ftpTabs, FTP);
                     transportsPanel.add(sftpPanel, SFTP);
@@ -187,10 +185,9 @@
                        tLayout.show(transportsPanel, LOCAL);
                } else {
                         FCPTransport t =(FCPTransport)wb.getPublishTransport();
-                        fcpPanel.setMachineNameField(t.getHostname());
-                        fcpPanel.setPortField(Integer.parseInt(t.getPort()));
-                        if (t.getInsertURI() != null)
-                            InsertURI=t.getInsertURI();
+                        
fcpPanel.setMachineNameField(TBGlobals.getProperty("NODE_HOSTNAME"));
+                        
fcpPanel.setPortField(Integer.parseInt(TBGlobals.getProperty("NODE_PORT")));
+                        fcpPanel.setInsertUri("USK@" + t.getInsertURI() + "/");
                         transportTypeCombo.setSelectedItem(FCP);
                         tLayout.show(transportsPanel, FCP);
                 }
@@ -259,32 +256,12 @@
                        transport = new LocalTransport();
                } else {
                         FCPTransport pt = new FCPTransport();
-                        
pt.setNode(fcpPanel.getMachineNameField(),fcpPanel.getPortField());
-                        // If we are changing the publish transport after the 
Dialog Wizard, we need to create a new key pair
-                        
-                        if(InsertURI == null && !(weblog.getPublishTransport() 
instanceof FCPTransport)) {
-                            logger.log(Level.INFO,"Creating a new SSK key 
pair...");
-                            fcpManager fcp = new fcpManager();
-                            String keys[];
-                            
fcp.setNode(fcpPanel.getMachineNameField(),fcpPanel.getPortField());
-                            try {
-                                keys=fcp.generateKeyPair();
-                                keys[0]=keys[0].substring("SSK".length());
-                                keys[1]=keys[1].substring("SSK".length());
-                                InsertURI="USK" + keys[0];
-                                String url="USK" + keys[1];
-                                url += 
ASCIIconv.convertNonAscii(weblog.getTitle()) + "/1/";
-                                
weblog.setBlogUrls(weblog.getBasePath(),url,url,url);
-                            } catch (IOException ex) {
-                                
JOptionPane.showMessageDialog(TBPublishTransportPanel.this,
-                                    fcpPanel.getMachineNameField() + ":" + 
fcpPanel.getPortField() + " : " + ex, i18n.str("key_generation_failure"),  
//$NON-NLS-1$ //$NON-NLS-2$
-                                    JOptionPane.ERROR_MESSAGE);
-                                    return;
-                            }
-                            logger.log(Level.INFO,"Done!");
-                            
-                        }
-                        pt.setInsertURI(InsertURI);                        
+                        
pt.setNode(fcpPanel.getMachineNameField(),fcpPanel.getPortField());  
+                        pt.setInsertURI(fcpPanel.getInsertUri());              
                                                       
+                        String url = fcpPanel.getRequestUri();
+                        int firstSlash = url.indexOf('/');
+                        url = url.substring(0,firstSlash+1) + 
ASCIIconv.convertNonAscii(weblog.getTitle()) + "/1/";
+                        weblog.setBlogUrls("none",url,url,url);
                         pt.setEdition("1");
                         transport = pt;
                 }
@@ -474,24 +451,37 @@
                 private static final long serialVersionUID = 1L;               
                private JTextField portField;
                private JTextField machineNameField;
+                private JTextField requestUriField;
+                private JTextField insertUriField;
+                private JButton generateKeyButton;
                public FcpTransportPanel()
                {
                         portField = new JTextField();
                         machineNameField = new JTextField();
+                        requestUriField = new JTextField();
+                        insertUriField = new JTextField();
+                        generateKeyButton = new JButton();

                        TextEditPopupManager pm = 
TextEditPopupManager.getInstance();
                        pm.registerJTextComponent(machineNameField);

+                        TypeListener listener = new TypeListener();
+                        generateKeyButton.addActionListener(listener);
+                        
                         // Default port
                         portField.setText(TBGlobals.getProperty("NODE_PORT"));
                         //Default machine name
                         
machineNameField.setText(TBGlobals.getProperty("NODE_HOSTNAME"));
+                        generateKeyButton.setText(i18n.str("generate_keys"));
                        LabelledItemPanel lip = new LabelledItemPanel();
                        JPanel p = new JPanel(new BorderLayout());
                        p.add(portField, BorderLayout.WEST);
                        p.add(new JPanel(), BorderLayout.CENTER);
                        lip.addItem(i18n.str("port"), p);
                         lip.addItem(i18n.str("machineName"),machineNameField);
+                        lip.addItem(i18n.str("requestUri"),requestUriField);
+                        lip.addItem(i18n.str("insertUri"),insertUriField);
+                        lip.addItem("",generateKeyButton);
                        setLayout(new BorderLayout());
                        add(lip, BorderLayout.CENTER);  
                }
@@ -516,5 +506,54 @@
         public void setMachineNameField(String machineNameField) {
             this.machineNameField.setText(machineNameField);
         }
+        
+        public void setInsertUri(String insertUri){
+            this.insertUriField.setText(insertUri);
+        }
+        
+        public String getInsertUri(){
+            return this.insertUriField.getText();
+        }
+        
+        public void setRequestUri(String requestUri){
+            this.requestUriField.setText(requestUri);
+        }
+        
+        public String getRequestUri(){
+            return this.requestUriField.getText();
+        }
+        
+        private class TypeListener implements ActionListener {
+            public void actionPerformed(ActionEvent e) {
+                if (e.getSource() instanceof JButton){
+                    
if(generateKeyButton.getText().equals(i18n.str("generate_keys"))){
+                        fcpManager Manager = new fcpManager();
+                        int port = 
Integer.parseInt(TBGlobals.getProperty("NODE_PORT"));
+                        String keys[]=new String[2];
+                        String hostname = 
TBGlobals.getProperty("NODE_HOSTNAME");
+                        Manager.setNode(hostname,port);
+                        try {
+                            keys=Manager.generateKeyPair();
+                        } catch (IOException ex) {
+                            
JOptionPane.showMessageDialog(TBPublishTransportPanel.this,
+                                    hostname + ":" + port + " : " + ex, 
i18n.str("key_generation_failure"),  //$NON-NLS-1$ //$NON-NLS-2$
+                                    JOptionPane.ERROR_MESSAGE);
+                            return;
+                        }
+                        // We put "USK" instead of "SSK"
+                        keys[0] = keys[0].substring("SSK".length());
+                        keys[1] = keys[1].substring("SSK".length());
+                        insertUriField.setText("USK" + keys[0]);
+                        requestUriField.setText("USK" + keys[1]);
+                        Manager.getConnection().disconnect();
+                        generateKeyButton.setText(i18n.str("cancel"));
+                    } else {
+                        requestUriField.setText("");
+                        insertUriField.setText("");
+                        generateKeyButton.setText(i18n.str("generate_keys"));
+                    }
+                }
+            }
+        }
     }
 }
\ No newline at end of file

Modified: 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWeblogPropertiesDialog.java
===================================================================
--- 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWeblogPropertiesDialog.java
        2008-02-21 19:47:31 UTC (rev 18098)
+++ 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWeblogPropertiesDialog.java
        2008-02-21 21:16:48 UTC (rev 18099)
@@ -85,7 +85,7 @@
         opts.add(new DialogPanel(new TBTemplatesPanel(tbw), 
i18n.str("templates"))); //$NON-NLS-1$
         opts.add(new DialogPanel(new TBEmailPanel(tbw), i18n.str("email"))); 
//$NON-NLS-1$
         opts.add(new DialogPanel(new XmlRpcPingPanel(tbw), 
i18n.str("pinging")));               //$NON-NLS-1$
-               opts.add(new DialogPanel(new TBPublishTransportPanel(tbw,null), 
i18n.str("publishing"))); //$NON-NLS-1$
+               opts.add(new DialogPanel(new TBPublishTransportPanel(tbw), 
i18n.str("publishing"))); //$NON-NLS-1$

                optionPanel = new JPanel(optionLayout);
                for(int i = 0; i < opts.size(); i++)

Modified: 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWizardDialog.java
===================================================================
--- 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWizardDialog.java
  2008-02-21 19:47:31 UTC (rev 18098)
+++ 
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWizardDialog.java
  2008-02-21 21:16:48 UTC (rev 18099)
@@ -728,7 +728,7 @@
                        instrPanel.add(header, BorderLayout.NORTH);
                        instrPanel.add(new MultilineText(text), 
BorderLayout.CENTER);

-                       pubPanel = new 
TBPublishTransportPanel(weblog,InsertURI);
+                       pubPanel = new TBPublishTransportPanel(weblog);
                        add(instrPanel, BorderLayout.NORTH);
                        add(pubPanel, BorderLayout.CENTER);                     
                                
                }


Reply via email to