CombineExt

some tools useful when working with COMBINE stuff

View the Project on GitHub

CombineIconizer

The CombineIconizer contains methods to get icons for certain file types. It is especially useful for web interfaces or desktop applications.

About Icons

The icons are mainly taken from fatcow. We extended the pack with the following icons to represent files related to COMBINE standards:

SED-ML Combine CellMl SBGN SBML Unknown

All Icons are licensed under Creative Commons Attribution 3.0 License.

The icons can be downloaded individually from /src/main/resources/icons. However, they are also shipped with our jar file and you can use them through the CombineIconizer:

Use Icons

The icons can be accessed through two static functions. All you need to provide is a valid format, see /CombineFormatizer.

Get corresponding Icon Stream

You can simply pass a format URL to the Iconizer.formatToIconStream (URI) (JavaDoc) method and you’ll receive an InputStream containing the icon:

URI format = ...
InputStream fin = Iconizer.formatToIconStream (format);
FileOutputStream fout = new FileOutputStream ("/some/file");

byte[] b = new byte[1024];
int noOfBytes = 0;

while ((noOfBytes = fin.read(b)) != -1)
	fout.write (b, 0, noOfBytes);

System.out.println ("File copied!");
fin.close ();
fout.close ();

This stream can then be used to, for example, store the icon in a different location (as demonstrated in the example above), or to immediately dump the file through an HTTP connection (as it is done in combinearchive-web:wiki).

Get corresponding Icon name

Of course, always reading the icons from the zipped jar container might be something to avoid. In that case, you may extract the icons and just ask our library for the name of a specific icon. Just pass the format in question to the function Iconizer.formatToIcon (URI) (JavaDoc):

URI format = ...
String iconName = Iconizer.formatToIcon (format);
// find the icon in:
File iconFile = new File ("/some/dir/" + iconName);

Use Case: Extract and Cache Icons

Extracting all icons is a good start to save computational resources. However, we might extend the icon pack at any point in time and, thus, you might miss some icons after an upgrade. Therefore, we consider the following workaround as the best option of using our icons:

For your convenience, some copy&paste-able snippet:

String cacheDir = "/tmp/";

URI format = new URI ("http://identifiers.org/combine.specifications/sbml");

String iconName = Iconizer.formatToIcon (format);
System.out.println ("icon name: " + iconName);

File expectedFile = new File (cacheDir + iconName);

if (!expectedFile.exists ())
{
	// extract the file
	InputStream fin = Iconizer.formatToIconStream (format);
	FileOutputStream fout = new FileOutputStream (expectedFile);
	
	byte[] b = new byte[1024];
	int noOfBytes = 0;
	
	while ( (noOfBytes = fin.read (b)) != -1)
	{
		fout.write (b, 0, noOfBytes);
	}
	
	System.out.println ("File copied!");
	fin.close ();
	fout.close ();
}
else
{
	// cool. msg just for debugging purposes
	System.out.println ("file extracted previously");
}

// go on using expectedFile!
System.out.println ("icon can be found in "
	+ expectedFile.getAbsolutePath ());

Extend the Iconizer with your icons

To learn how to extend the Iconizer to also deliver icons representing other file types see ExtendCombineIconizer.