[Schmitzm-commits] r2117 - in trunk: schmitzm-core/src/main/java/de/schmitzm/net/mail schmitzm-mail schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/metaphaseeditor schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales schmitzm-mail/src/test/java/de/schmitzm/net/mail/gui

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 31 13:13:38 CET 2012


Author: mojays
Date: 2012-10-31 13:13:38 +0100 (Wed, 31 Oct 2012)
New Revision: 2117

Added:
   trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/AttachmentsPanel.java
   trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/metaphaseeditor/
   trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/metaphaseeditor/ImageDialog.java
   trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/metaphaseeditor/MetaphaseEditorPanel.java
Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java
   trunk/schmitzm-mail/pom.xml
   trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/MailEditorPanel.java
   trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle.properties
   trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle_de.properties
   trunk/schmitzm-mail/src/test/java/de/schmitzm/net/mail/gui/MailEditorTest.java
Log:
schmitzm-mail: Umstellung auf erweiterten MetaphaseEditor (ImageDialog, MetaphaseEditorPanel)
new classes: AttachmentsPanel

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java	2012-10-17 11:53:42 UTC (rev 2116)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java	2012-10-31 12:13:38 UTC (rev 2117)
@@ -3,12 +3,17 @@
 import java.awt.Desktop;
 import java.awt.GraphicsEnvironment;
 import java.io.File;
+import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import javax.activation.DataHandler;
@@ -30,6 +35,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 
+import de.schmitzm.io.IOUtil;
 import de.schmitzm.lang.LangUtil;
 import de.schmitzm.lang.ResourceProvider;
 import de.schmitzm.swing.ExceptionDialog;
@@ -45,7 +51,12 @@
 	/** Mail address for SCHMITZM bug reports. */
 	public static final String MAIL_ADR_SCHMITZM_BUGS = "schmitzm-bugs at wikisquare.de";
 
-	/**
+    /** RegEx pattern string to identify image references in img-tags */ 
+    public static final String IMG_TAG_REGEX_STR = "<[iI][mM][gG].*?src=['\"](.*?)['\"].*?>";
+    /** RegEx pattern to identify image references in img-tags */
+    public static final Pattern IMG_TAG_REGEX = Pattern.compile("<[iI][mM][gG].*?src=['\"](.*?)['\"].*?>");
+
+    /**
 	 * A RegEx pattern that matches Strings which look like email-addresses.
 	 */
 	public static final Pattern EMAIL_ADDRESS_REGEX = Pattern
@@ -194,7 +205,47 @@
       // Send message
       Transport.send(message);
 	}
+	
 
+	/**
+	 * Identifies all img-tags in HTML mail body and replaces its local file reference
+	 * by a "cid:filename" reference (which refers to mail attachment file).
+	 * @param htmlBody html mail body to parse
+	 * @param replacedRefs (empty) map where the replaces file references are put in;
+	 *                     map key is the new "cid"-reference and map value is the
+	 *                     refered file (is not allowed to be null!)
+	 * @exception IllegalArgumentException if {@code replacedRefs} is {@code null} 
+	 */
+	public static String replaceLocalImageReferencesInHTMLBody(String htmlBody, Map<String,File> replacedRefs) {
+	  if ( replacedRefs == null )
+	    throw new IllegalArgumentException("Map to put the replaced references in, is not allowed to be NULL");
+      Matcher matcher = IMG_TAG_REGEX.matcher(htmlBody);
+      Map<File,String> replacedRefsInverted = new HashMap<File, String>();
+      while (matcher.find()) {
+        try {
+          String fileURL    = matcher.group(1);
+          File   file       = IOUtil.urlToFile(new URL(fileURL));
+          String newFileURL = "cid:"+file.getName();
+          // store replaced file in map with reference to new cid-URL
+          if ( replacedRefsInverted.containsKey(file) )
+            newFileURL = replacedRefsInverted.get(file);
+          else {
+            for (int i=1; replacedRefs.containsKey(newFileURL); i++ ) {
+              newFileURL = "cid:"+IOUtil.getBaseFileName(file)+i+IOUtil.getFileExt(file, true);
+            }
+            replacedRefs.put(newFileURL, file);
+            replacedRefsInverted.put(file, newFileURL);
+          }          
+          htmlBody = htmlBody.replace(fileURL, newFileURL);
+        } catch (MalformedURLException err) {
+          // given image URL is not an absolute URL,
+          // so ignore this exception because the given URL
+          // already is a relative URL
+        }
+      }
+	  return htmlBody;
+	}
+
     /**
      * Opens the local mail client with a new mail.
      * 

Modified: trunk/schmitzm-mail/pom.xml
===================================================================
--- trunk/schmitzm-mail/pom.xml	2012-10-17 11:53:42 UTC (rev 2116)
+++ trunk/schmitzm-mail/pom.xml	2012-10-31 12:13:38 UTC (rev 2117)
@@ -19,7 +19,11 @@
                 <dependency>
                         <groupId>com.metaphaseeditor</groupId>
                         <artifactId>metaphaseEditor</artifactId>
-                        <version>1.1.0-with-jazzy</version>
+                        <!-- MetaphaseEditor with some litte modifications in
+                             - MetaphaseEditorPanel
+                             - ImageDialog
+                             to allow some extensions in sub-classes -->
+                        <version>1.1.0-mod-with-jazzy</version>
 			<scope>compile</scope>
                 </dependency>
 		<dependency>

Added: trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/AttachmentsPanel.java
===================================================================
--- trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/AttachmentsPanel.java	                        (rev 0)
+++ trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/AttachmentsPanel.java	2012-10-31 12:13:38 UTC (rev 2117)
@@ -0,0 +1,270 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.net.mail.gui;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.PopupMenu;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.Action;
+import javax.swing.BorderFactory;
+import javax.swing.JComponent;
+import javax.swing.JFileChooser;
+import javax.swing.JLabel;
+import javax.swing.JPopupMenu;
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingConstants;
+import javax.swing.event.TableModelEvent;
+import javax.swing.event.TableModelListener;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.TableCellRenderer;
+
+import de.schmitzm.lang.LangUtil;
+import de.schmitzm.swing.JPanel;
+import de.schmitzm.swing.SwingUtil;
+import de.schmitzm.swing.table.AbstractMutableTableModel;
+import de.schmitzm.swing.table.ComponentRenderer;
+import de.schmitzm.swing.table.MutableTable;
+
+/**
+ * Panel to maintain mail attachments.
+ * @author Martin O.J. Schmitz
+ */
+public class AttachmentsPanel extends JPanel implements ActionListener, TableModelListener {
+  /** Global file chooser for all panel instances. */
+  public static final JFileChooser FILE_CHOOSER = new JFileChooser();
+  static {
+    FILE_CHOOSER.setMultiSelectionEnabled(true);
+    FILE_CHOOSER.setFileSelectionMode(JFileChooser.FILES_ONLY);
+  }
+
+  protected JLabel attachmentsCaption = new JLabel(MailGUIUtil.R("AttachmentsPanel.caption"));
+  protected FilesTableModel attachmentsTableModel;
+  protected MutableTable attachments;
+
+  /**
+   * Creates a new panel including caption and file list/table.
+   */
+  public AttachmentsPanel() {
+    this(true);
+  }
+  
+  /**
+   * Creates a new panel.
+   * @param inclCaption indicates whether the panel shows a caption (or only the
+   *                    attachment list/table)
+   */
+  public AttachmentsPanel(boolean inclCaption) {
+    super( new BorderLayout() );
+    
+    
+    attachmentsTableModel = new FilesTableModel();
+    attachmentsTableModel.addTableModelListener(this);
+    attachments = new MutableTable(attachmentsTableModel, MutableTable.ITEM_ADD | MutableTable.ITEM_REMOVE);
+    SwingUtil.hideTableGrid(attachments);
+    attachments.setTableHeader(null);
+    attachments.getColumnModel().getColumn(0).setCellRenderer(new ComponentRenderer(SwingConstants.LEFT,SwingConstants.CENTER,false));
+    attachments.getColumnModel().getColumn(1).setCellRenderer(new ComponentRenderer(SwingConstants.RIGHT,SwingConstants.CENTER,false));
+//    attachments.addFocusListener( new FocusAdapter() {
+//      @Override
+//      public void focusLost(FocusEvent e) {
+//        if ( !(e.getOppositeComponent() instanceof JPopupMenu) )
+//          attachments.clearSelection();
+//      }
+//    });
+    
+    if ( inclCaption )
+      add(attachmentsCaption, BorderLayout.NORTH);
+    add(attachments.createScrollPane(true), BorderLayout.CENTER);
+  }
+  
+  /**
+   * Adds attachments to list by 
+   */
+  public void addAttachments() {
+    attachmentsTableModel.performAddRow();
+  }
+  
+  /**
+   * Updates the panels caption which includes the current
+   * total file size of all attachments.
+   */
+  public void updateCaption() {
+    String caption = MailGUIUtil.R("AttachmentsPanel.caption");
+    long attachmentSize = attachmentsTableModel.getTotalFileSize();
+    if ( attachmentSize > 0 )
+      caption += " (" + LangUtil.formatFileSize(attachmentSize) + ")";
+    attachmentsCaption.setText(caption);
+  }
+  
+  /**
+   * Creates an action which an be used to add attachment (without using
+   * the panels context menu.
+   */
+  public Action createAddAction() {
+    Action addAttachmentAction = SwingUtil.createAction(MailGUIUtil.R("AttachmentsPanel.add"),
+                                                        this,
+                                                        "ADD_ATTACHMENT",
+                                                        MailGUIUtil.R("AttachmentsPanel.add.desc"),
+                                                        SwingUtil.createImageIconFromResourcePath("resource/icons/small/attach.png", null));
+    return addAttachmentAction;
+  }
+  
+  /**
+   * Called on editor actions.
+   */
+  @Override
+  public void actionPerformed(ActionEvent e) {
+    String actionID = e.getActionCommand();
+    if ( "ADD_ATTACHMENT".equals(actionID) )
+      addAttachments();
+  }
+
+  @Override
+  public void tableChanged(TableModelEvent e) {
+    updateCaption();  
+  }
+
+  /**
+   * Table model for the attachments files which shows the files an the file
+   * size.
+   * @author Martin O.J. Schmitz
+   */
+  protected class FilesTableModel extends AbstractMutableTableModel {
+    /** Holds the attachment files. */
+    List<File> files = new ArrayList<File>();
+    
+    /**
+     * Creates a new table model.
+     */
+    public FilesTableModel() {
+      super();
+    }
+    
+    
+    /**
+     * Creates two column names (one for the files, one for the file size).
+     */
+    @Override
+    public String[] createColumnNames() {
+      return new String[] {MailGUIUtil.R("AttachmentsPanel.caption"),
+                           MailGUIUtil.R("AttachmentsPanel.size")};
+    }
+
+    /**
+     * Returns the total file size in bytes.
+     * @return
+     */
+    public long getTotalFileSize() {
+      long totalSize = 0;
+      for (File f : files)
+        totalSize += f.length();
+      return totalSize;
+    }
+    
+    /**
+     * Returns the number of attachment files.
+     */
+    @Override
+    public int getRowCount() {
+      return files.size();
+    }
+
+    /**
+     * Adds files to attachment list.
+     */
+    public void addFiles(File[] file) {
+      for (File f : file)
+        files.add(f);
+      fireTableDataChanged();
+    }
+
+    /**
+     * Add a file to attachment list.
+     */
+    public void addFile(File file) {
+      files.add(file);
+      fireTableDataChanged();
+    }
+    
+    /**
+     * Returns the table values (file name and file size).
+     */
+    @Override
+    public Object getValueAt(int row, int col) {
+      File f = files.get(row);
+      switch (col) {
+        case 0: return f.getName();
+        case 1: return LangUtil.formatFileSize(f.length());
+      }
+      return null;
+    }
+    
+    /**
+     * Removes the selected row (file) from list.
+     */
+    @Override
+    public void performRemoveRow(int row) {
+      files.remove(row);
+    }
+    
+    /**
+     * Does nothing because model does not support editing cells.
+     */
+    @Override
+    public void performChangeData(int row, int col) {
+      // not used
+    }
+    
+    /**
+     * Shows a {@link JFileChooser} to select files which are added
+     * to the attachment list.
+     */
+    @Override
+    public void performAddRow() {
+      if ( FILE_CHOOSER.showOpenDialog(AttachmentsPanel.this) != JFileChooser.APPROVE_OPTION )
+        return;
+      File[] files = FILE_CHOOSER.getSelectedFiles();
+      attachmentsTableModel.addFiles(files);
+    }
+    
+  }
+
+}

Modified: trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/MailEditorPanel.java
===================================================================
--- trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/MailEditorPanel.java	2012-10-17 11:53:42 UTC (rev 2116)
+++ trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/MailEditorPanel.java	2012-10-31 12:13:38 UTC (rev 2117)
@@ -29,49 +29,48 @@
  */
 package de.schmitzm.net.mail.gui;
 
+import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
 import java.io.File;
+import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
+import javax.swing.AbstractAction;
 import javax.swing.Action;
+import javax.swing.BorderFactory;
+import javax.swing.GroupLayout;
 import javax.swing.JButton;
-import javax.swing.JFileChooser;
-import javax.swing.JLabel;
-import javax.swing.SwingConstants;
+import javax.swing.JSplitPane;
+import javax.swing.JToolBar;
 
 import net.miginfocom.swing.MigLayout;
 
-import com.metaphaseeditor.MetaphaseEditorPanel;
+import com.metaphaseeditor.SpellCheckDictionaryVersion;
 
-import de.schmitzm.lang.LangUtil;
+import de.schmitzm.io.IOUtil;
+import de.schmitzm.net.mail.MailUtil;
+import de.schmitzm.net.mail.gui.metaphaseeditor.MetaphaseEditorPanel;
 import de.schmitzm.swing.JPanel;
 import de.schmitzm.swing.SwingUtil;
-import de.schmitzm.swing.table.AbstractMutableTableModel;
-import de.schmitzm.swing.table.ComponentRenderer;
-import de.schmitzm.swing.table.MutableTable;
 
 /**
  * A panel based on {@link BaseEditor} to edit an HTML mail. 
  * 
  * @author Martin O.J. Schmitz
  */
-public class MailEditorPanel extends JPanel implements ActionListener {
-  public static final JFileChooser FILE_CHOOSER = new JFileChooser();
-  static {
-    FILE_CHOOSER.setMultiSelectionEnabled(true);
-    FILE_CHOOSER.setFileSelectionMode(JFileChooser.FILES_ONLY);
-  }
+public class MailEditorPanel extends JPanel {
   
   protected MailAddressesPanel addresses;
 //  protected BaseEditor mailEditor;
   protected MetaphaseEditorPanel mailEditor;
-  protected JLabel attachmentsCaption = new JLabel(MailGUIUtil.R("MailEditorPanel.attachments"));
-  protected FilesTableModel attachmentsTableModel;
-  protected MutableTable attachments;
+  protected AttachmentsPanel attachments;
+  protected JPanel toolBar;
  
   
   /**
@@ -93,124 +92,80 @@
 //        MailEditorPanel.this.addButtons(defaultComponents, editComponents, formatComponents);
 //      }
 //    };
+    toolBar = new JPanel(new MigLayout("","0[]0","2[]2"));
     mailEditor = new MetaphaseEditorPanel();
-    attachmentsTableModel = new FilesTableModel();
-    attachments = new MutableTable(attachmentsTableModel, MutableTable.ITEM_ADD | MutableTable.ITEM_REMOVE);
-    attachments.setShowHorizontalLines(false);
-    attachments.setShowVerticalLines(false);
-    attachments.setTableHeader(null);
-    attachments.getColumnModel().getColumn(1).setCellRenderer(new ComponentRenderer(SwingConstants.RIGHT,SwingConstants.CENTER));
-//    SwingUtil.setPreferredWidth(attachments, 150);
+    attachments = new AttachmentsPanel();
+    attachments.setBorder( BorderFactory.createEmptyBorder(0,5,0,0) );
+    SwingUtil.setPreferredWidth(attachments, 150);
+    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
+    split.setLeftComponent(new JPanel(new BorderLayout()));
+    ((JPanel)split.getLeftComponent()).add(addresses, BorderLayout.CENTER);
+    ((JPanel)split.getLeftComponent()).add(toolBar, BorderLayout.SOUTH);
+    split.setRightComponent(attachments);
+    split.setResizeWeight(0.9);
+    split.setBorder( BorderFactory.createEmptyBorder() );
 
-//    JPanel attachmentsPanel = new JPanel(new BorderLayout());
-//    attachmentsPanel.add(attachmentsCaption, BorderLayout.NORTH);
-//    attachmentsPanel.add(attachments.createScrollPane(), BorderLayout.CENTER);
+    initToolBar();
     
-//    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
-//    split.setLeftComponent(mailEditor);
-//    split.setRightComponent(attachmentsPanel);
-//    split.setResizeWeight(1.0);
-
-//    MultiSplitPane split = new MultiSplitPane(2,JSplitPane.HORIZONTAL_SPLIT);
-//    split.setContainer(0, new JPanel(new BorderLayout()));
-//    split.setContainer(1, new JPanel(new BorderLayout()));
-//    split.getContainer(1).add(attachmentsCaption, BorderLayout.NORTH);
-//    split.getContainer(1).add(attachments.createScrollPane(), BorderLayout.CENTER);
-//    split.getContainer(0).add(mailEditor, BorderLayout.CENTER);
-//    split.setResizeWeigth( new double[] {0.8,0.2});
-    add(addresses,"span 2, growx");
-    add(mailEditor,"span 1 2, h :2000:, growx, growy");
-    add(attachmentsCaption,"");
-    add(attachments.createScrollPane(),"w :150:, growy");
-//    add(split,"span 2, growx, growy");
+    add(split,"span 2, growx");
+    add(mailEditor,"span 2, h :2000:, growx, growy");
   }
-
+  
   /**
-   * Does nothing. Can be overridden by sub classes to add or remove tools.
+   * Sets a (custom) dictionary.
+   * @param zipFilename file path to ZIP file which includes the custom dictionary (if
+   *                    {@code null} the {@link SpellCheckDictionaryVersion} is
+   *                    automatically set to {@link SpellCheckDictionaryVersion#CUSTOM})
    */
-  protected void addButtons( List<Component> defaultComponents, List<Component> editComponents, List<Component> formatComponents ) {
-    Action addAttachmentAction = SwingUtil.createAction(MailGUIUtil.R("MailEditorPanel.attachments.add"),
-                                         this,
-                                         "ADD_ATTACHMENT",
-                                         MailGUIUtil.R("MailEditorPanel.attachments.add.desc"),
-                                         SwingUtil.createImageIconFromResourcePath("resource/icons/small/attach.png", null));
-    final JButton sendButton = new JButton(addAttachmentAction);
-    editComponents.add(editComponents.size(),sendButton);
+  public void setDictionary(String zipFilename) {
+    mailEditor.setCustomDictionaryFilename(zipFilename);
+    if ( zipFilename != null )
+      mailEditor.setDictionaryVersion(SpellCheckDictionaryVersion.CUSTOM);
+    else
+      mailEditor.setDictionaryVersion(SpellCheckDictionaryVersion.LIBERAL_US);
   }
 
   /**
-   * Called on editor actions.
+   * Sets the dictionary for the HTML editor.<br>
+   * Note: Before set to {@link SpellCheckDictionaryVersion#CUSTOM} a custom directory
+   * file must be set
+   * @see #setDictionary(SpellCheckDictionaryVersion)  
    */
-  @Override
-  public void actionPerformed(ActionEvent e) {
-    String actionID = e.getActionCommand();
-    if ( "ADD_ATTACHMENT".equals(actionID) )
-      performAddAttachment();
-   
+  public void setDictionary(SpellCheckDictionaryVersion dict) {
+    mailEditor.setDictionaryVersion(dict);
   }
-  
-  protected void performAddAttachment() {
-    if ( FILE_CHOOSER.showSaveDialog(this) != JFileChooser.APPROVE_OPTION )
-      return;
-    File[] files = FILE_CHOOSER.getSelectedFiles();
-    attachmentsTableModel.addFiles(files);
-  }
-  
-  protected class FilesTableModel extends AbstractMutableTableModel {
 
-    List<File> files = new ArrayList<File>();
-    public FilesTableModel() {
-      super();
-    }
-    
-    
-    @Override
-    public String[] createColumnNames() {
-      return new String[] {MailGUIUtil.R("MailEditorPanel.attachments"),
-                           MailGUIUtil.R("MailEditorPanel.attachments.size")};
-    }
+//  /**
+//   * Adds the "Add attachments" action to editor tools.
+//   */
+//  protected void addButtons( List<Component> defaultComponents, List<Component> editComponents, List<Component> formatComponents ) {
+//    Action addAttachmentAction = attachments.createAddAction();
+//    final JButton sendButton = new JButton(addAttachmentAction);
+//    editComponents.add(editComponents.size(),sendButton);
+//  }
 
-    @Override
-    public int getRowCount() {
-      return files.size();
-    }
+  /**
+   * Initializes the additional tool bar (above the {@link MetaphaseEditorPanel} toolbars).
+   * Can be overridden to add new action.
+   */
+  protected void initToolBar() {
+    Action addAttachmentAction = attachments.createAddAction();
+    JButton addAttachmentButton = new JButton(addAttachmentAction);
+    this.toolBar.add(addAttachmentButton);
 
-    public void addFiles(File[] file) {
-      for (File f : file)
-        files.add(f);
-      fireTableDataChanged();
-    }
-
-    public void addFile(File file) {
-      files.add(file);
-      fireTableDataChanged();
-    }
-    
-    @Override
-    public Object getValueAt(int row, int col) {
-      File f = files.get(row);
-      switch (col) {
-        case 0: return f.getName();
-        case 1: return LangUtil.formatFileSize(f.length());
+    this.toolBar.add(new JButton(new AbstractAction("Test") {
+      @Override
+      public void actionPerformed(ActionEvent e) {
+        String html = mailEditor.getDocument();
+        System.out.println( html + "\n\n***************");
+        Map<String,File> refs = new HashMap<String, File>();
+        html = MailUtil.replaceLocalImageReferencesInHTMLBody(html, refs);
+        for (String r : refs.keySet())
+          System.out.println(r + " --> " + refs.get(r));
+        System.out.println("***************\n"+html+"\n***************");
       }
-      return null;
-    }
+    }));
     
-    
-    @Override
-    public void performRemoveRow(int row) {
-      files.remove(row);
-    }
-    
-    @Override
-    public void performChangeData(int row, int col) {
-      // not used
-    }
-    
-    @Override
-    public void performAddRow() {
-      performAddAttachment();
-    }
-    
   }
+
 }

Added: trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/metaphaseeditor/ImageDialog.java
===================================================================
--- trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/metaphaseeditor/ImageDialog.java	                        (rev 0)
+++ trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/metaphaseeditor/ImageDialog.java	2012-10-31 12:13:38 UTC (rev 2117)
@@ -0,0 +1,102 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.net.mail.gui.metaphaseeditor;
+
+import java.awt.Frame;
+import java.io.File;
+
+import javax.swing.JComponent;
+import javax.swing.JTextField;
+
+import org.apache.commons.lang.StringUtils;
+
+import de.schmitzm.swing.input.FileInputOption;
+
+
+/**
+ * Extends the {@link com.metaphaseeditor.ImageDialog} by a file zoom.
+ * Furthermore {@link #getURLTextFieldText()} automatically adds a "file:"
+ * prefix to field input, so that file reference in HTML works with full
+ * path reference.
+ * @author Martin O.J. Schmitz
+ */
+public class ImageDialog extends com.metaphaseeditor.ImageDialog {
+
+  /**
+   * Creates a new dialog-
+   * @param parent parent frame (may be {@code null}
+   * @param modal indicates whether the dialog should be modal 
+   */
+  public ImageDialog(Frame parent, boolean modal) {
+    super(parent, modal);
+  }
+
+  /**
+   * Creates a text field for image URL. Sub classes can override this
+   * method to use alternative implementations.
+   */
+  @Override
+  protected JComponent createURLTextField() {
+    return new FileInputOption(null, false) {
+      /**
+       * Automatically adds a "file:" prefix to file string.
+       */
+      public String convertToString(Object object) {
+        String path = super.convertToString(object);
+        if ( !StringUtils.isBlank(path) )
+          path = "file:"+path;
+        return path;
+      }
+      
+      /**
+       * Automatically removes a possible "file:" prefix before calling
+       * the super-method.
+       */
+      public File convertFromString(String objectStr) {
+        if ( objectStr != null && objectStr.toLowerCase().startsWith("file:") )
+          objectStr = objectStr.substring(5);
+        return super.convertFromString(objectStr);
+      }
+    };
+  }
+  
+  
+  /**
+   * Returns the text from URL text field component. If path does not starts with
+   * "file:" this prefix is automatically added.
+   */
+  @Override
+  protected String getURLTextFieldText() {
+    String text = ((JTextField)((FileInputOption)urlTextField).getInputComponent()).getText();
+    if ( !text.toLowerCase().startsWith("file:") )
+      text = "file:"+text;
+    return text;
+  }
+}

Added: trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/metaphaseeditor/MetaphaseEditorPanel.java
===================================================================
--- trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/metaphaseeditor/MetaphaseEditorPanel.java	                        (rev 0)
+++ trunk/schmitzm-mail/src/main/java/de/schmitzm/net/mail/gui/metaphaseeditor/MetaphaseEditorPanel.java	2012-10-31 12:13:38 UTC (rev 2117)
@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.net.mail.gui.metaphaseeditor;
+
+import com.metaphaseeditor.ImageDialog;
+
+import de.schmitzm.swing.SwingUtil;
+
+
+/**
+ * Extends the {@link com.metaphaseeditor.MetaphaseEditorPanel} by an alternative
+ * version of {@link de.schmitzm.net.mail.gui.metaphaseeditor.ImageDialog}.
+ * @author Martin O.J. Schmitz
+ */
+public class MetaphaseEditorPanel extends com.metaphaseeditor.MetaphaseEditorPanel {
+
+  /** 
+   * Creates a new panel.
+   */
+  public MetaphaseEditorPanel() {        
+      super();
+  }
+  
+  /**
+   * Creates an instance of {@link de.schmitzm.net.mail.gui.metaphaseeditor.ImageDialog}
+   * instead of {@link ImageDialog}.
+   */
+  protected ImageDialog createImageDialog() {
+    return new de.schmitzm.net.mail.gui.metaphaseeditor.ImageDialog(null,true);
+  }
+  
+  
+}

Modified: trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle.properties
===================================================================
--- trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle.properties	2012-10-17 11:53:42 UTC (rev 2116)
+++ trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle.properties	2012-10-31 12:13:38 UTC (rev 2117)
@@ -37,8 +37,8 @@
 MailAddressesPanel.to=To
 MailAddressesPanel.cc=CC
 MailAddressesPanel.bcc=BCC
-MailEditorPanel.attachments=Attachments
-MailEditorPanel.attachments.size=Size
-MailEditorPanel.attachments.add=Attachment
-MailEditorPanel.attachments.add.desc=Add file attachment(s) to mail
+AttachmentsPanel.caption=Attachments
+AttachmentsPanel.size=Size
+AttachmentsPanel.add=Attachment
+AttachmentsPanel.add.desc=Add file attachment(s) to mail
 

Modified: trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle_de.properties	2012-10-17 11:53:42 UTC (rev 2116)
+++ trunk/schmitzm-mail/src/main/resources/de/schmitzm/net/mail/gui/resource/locales/MailGUIResourceBundle_de.properties	2012-10-31 12:13:38 UTC (rev 2117)
@@ -36,7 +36,7 @@
 MailAddressesPanel.to=An
 MailAddressesPanel.cc=Kopie (CC)
 MailAddressesPanel.bcc=Blindkopie (BCC)
-MailEditorPanel.attachments=Anhänge
-MailEditorPanel.attachments.size=Größe
-MailEditorPanel.attachments.add=Anhang
-MailEditorPanel.attachments.add.desc=Datei-Anhang der Mail hinzufügen
\ No newline at end of file
+AttachmentsPanel.caption=Anhänge
+AttachmentsPanel.size=Größe
+AttachmentsPanel.add=Anhang
+AttachmentsPanel.add.desc=Datei-Anhang der Mail hinzufügen
\ No newline at end of file

Modified: trunk/schmitzm-mail/src/test/java/de/schmitzm/net/mail/gui/MailEditorTest.java
===================================================================
--- trunk/schmitzm-mail/src/test/java/de/schmitzm/net/mail/gui/MailEditorTest.java	2012-10-17 11:53:42 UTC (rev 2116)
+++ trunk/schmitzm-mail/src/test/java/de/schmitzm/net/mail/gui/MailEditorTest.java	2012-10-31 12:13:38 UTC (rev 2117)
@@ -40,6 +40,7 @@
 import com.metaphaseeditor.MetaphaseEditorPanel;
 import com.metaphaseeditor.SpellCheckDictionaryVersion;
 
+import de.schmitzm.swing.SwingUtil;
 import de.schmitzm.testing.TestingClass;
 import de.schmitzm.testing.TestingUtil;
 
@@ -173,12 +174,12 @@
 //
 //      };
 //      
-//      gui = new MailEditorPanel(true, true, true, false);
-      
-      gui = new MetaphaseEditorPanel();
-      ((MetaphaseEditorPanel)gui).setCustomDictionaryFilename("D:/java/MetaphaseEditor/dict_de_de.zip");
-      ((MetaphaseEditorPanel)gui).setDictionaryVersion(SpellCheckDictionaryVersion.CUSTOM );
-      gui.setPreferredSize(new Dimension(800,500));
+//      gui = new MetaphaseEditorPanel();
+//      ((MetaphaseEditorPanel)gui).setCustomDictionaryFilename("D:/java/MetaphaseEditor/dict_de_de.zip");
+//      ((MetaphaseEditorPanel)gui).setDictionaryVersion(SpellCheckDictionaryVersion.CUSTOM );
+      gui = new MailEditorPanel(true, true, true, false);
+      ((MailEditorPanel)gui).setDictionary("D:/java/MetaphaseEditor/dict_de_de.zip");
+      SwingUtil.setPreferredHeight(gui,500);
       TestingUtil.testGui( gui,-1 );
   }
 



More information about the Schmitzm-commits mailing list