Bitmap images (development)

From FreeMind
Jump to navigationJump to search

There is a requirement to let mind maps contain bitmap images. Word processors store their bitmap images in their files.

The storage of bitmap images

Solution 1: Direct storage in the XML

The images shall be stored in the XML of the mind map as binary data in a node, like

<node TYPE="image" BINARY="x4543edvc...45ert"/>

This proposal does not fix the XML representation; the above is only for illustration.

Upon creation of node view, temporary file shall be created, and HTML viewer of the JLabel shall point to that file.

Upon editing, external image editor shall be opened to edit the temporary file, like Gimp.

Evaluation

  • Pro: Mind map is still stored as one plain, unzipped XML file. Thus:
    • Fast saving.
    • Nice for storing in version control system like CVS or SVN.
    • Easy searching several maps using grep tool.
  • Pro: The existing JLabel of node view can be used with very little modification.
  • Con: The design for applet is missing.
  • Model: XML stored by certain versions of Microsoft Word.

Solution 2: Storage in (zip) archive file

Generally I see two ways to insert images into the map. We can either embed them into the maps. If we did so, the JLabels could not show them, and there were a need in a new components to show them. I do not know any free available HTML capable components which could be used for such purpose. We could certainly use components for displaying only the images without text. But I see another way which does not has such difficulties.

I have found that all graphical components we use can draw images directly from archive files created as java archives(jars). The magic word is

<html><img src = "jar:file:javaarchive.jar!/content/images/image.gif">

So if the map were saved in the jar formatted file (with any extension), all rendered images identified by HTML tag <img> could be written into the same jar file and the sources given in the HTML could be substituted by the new paths.


This brings me to the following proposal.

package freemind.main;

import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.net.URL;

import freemind.modes.MindMapNode;

/**
 * managing of the map contents.
 * 
 * @author Dimitry Polivaev
 *
 */
public interface FreeMindArchive {
	/**
	 * @param mmar - archive file or directory
	 * e.g. File("C:/MindMap.mmar") or File("C:/MindMap/")
        * Every loaded archive is copied into a temporary directory
	 */
	void load(File mmar) throws IOException;
	
    /**
     * save loaded archive
     */
	void save() throws IOException;
	/**
     * save loaded archive in a new file ( directory)
     * @param newFile
     */
	void saveAs(File newFile) throws IOException;
	/**
	 * 	  @return e.g. URL("jar:file:C:/MindMap.mmar!/content/")
	 */
	URL getBase();
	
	/**
	 *    returns URL for loading the map
	 * 	  @return e.g. URL("jar:file:C:/MindMap.mmar!/content/map.mm")
	 */
	URL getMindMapURL();
	
	/**
	 * @return a writer for saving of the mind map content in the archive
	 */
	Writer createMapWriter() throws IOException;
	
	/**
	 * creates new image URL in the temporary archive using random number generator
	 * @param img
	 * @return 
	 */
	URL addImage(Image img);
	
	/**
	 * Marks ULR internally as removed. It should not be saved when save or saveAs is called
	 * @param imageURL : URL returned by addImage
	 */
	void deleteImage(URL imageURL);

	/**
	 * Removes flag "deleted" set by call of deleteImage
	 * @param imageURL : URL returned by addImage
	 */
	void undeleteImage(URL imageURL);
}

/**
 * Observes changes in the map, adds and removes images as nodes are changed, inserted or removed.
 * Therefore image counters should be maintained and actualized.
 *  
 * @author Dimitry Polivaev
 *
 */
interface FreemindArchiveController{
	void setArchive(FreeMindArchive archive);
	FreeMindArchive getArchive();
	/**
	 * inserts all found images into the archive ,
	 * if the images paths do not point into the archive
	 * and marks them as deleted.
	 * 
	 * @param html
	 * @return html with changed image paths
	 */
	String addImagesFromHtml(String html);

	// Listener methods:
	void nodeContentChanged(MindMapNode node, String oldContent);
	void nodeRemoved(MindMapNode node);
	void nodeInserted(MindMapNode node);
}

Once it is implemented, the rest functionality can be added relatively easy.


Evaluation

  • Model: OpenOffice data format.

Solution 3: Storing the images like ...

...

Requirements

  • The mind maps shall be fast to load and save.
  • The image function shall work in FreeMind applet.

Links

  • XML
  • Binary XML - despite the name, not directly related to the problem of storing binary data in XML.