From: Svjatoslav Agejenko Date: Sat, 3 Jan 2015 12:19:09 +0000 (+0200) Subject: refactored code for better readability X-Git-Tag: meviz-1.0~34 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=115456739edd5ae7dc67ac9e9f90d628aa65b4a3;p=meviz.git refactored code for better readability --- diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java index 08a308b..4e6b5bf 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java @@ -75,49 +75,7 @@ public class MixedLayout implements Layout { public void enlistImage(final Picture picture, final DirectoryMetadata parentDirectoryMetadata) { try { - - final Dimension imageSize = picture.getDimensions(); - - final List recommendedDimensions = Picture - .getThumbnailDimensions(imageSize); - - Dimension listingDimension = new Dimension(1500, 450); - - if (listingDimension.width > imageSize.width) - if (listingDimension.height > imageSize.height) - listingDimension = imageSize; - - final String listingThumbnailUrl = indexer.getThumbnailUrl(picture, - listingDimension, indexingContext); - - filesHtml.append("
"); - filesHtml.append("\n"); - - filesHtml.append("\n"); - filesHtml.append("
" - + FilePathParser - .getFileNameWithoutExtension(picture.fileName) - + "
("); - - int count = 0; - for (final Dimension dimension : recommendedDimensions) { - count++; - if (count > 1) - filesHtml.append(", "); - filesHtml.append(""); - filesHtml.append(dimension.width + "x" + dimension.height); - filesHtml.append(""); - } - - filesHtml.append(")\n"); - filesHtml.append("
"); - + enlistImageInternal(picture); } catch (final Exception e) { logger.error( "Error generating thumbnails for image file: " @@ -128,6 +86,50 @@ public class MixedLayout implements Layout { } } + private String enlistImageDimensions(final Picture picture) { + final StringBuilder html = new StringBuilder(); + + final List recommendedDimensions = Picture + .getThumbnailDimensions(picture.getDimensions()); + + int count = 0; + for (final Dimension dimension : recommendedDimensions) { + count++; + if (count > 1) + html.append(", "); + html.append(""); + html.append(dimension.width + "x" + dimension.height); + html.append(""); + } + + return html.toString(); + } + + private void enlistImageInternal(final Picture picture) { + + filesHtml.append("
"); + + // clickable image thumbnail + filesHtml.append("\n"); + filesHtml.append("
\n"); + + // file name + filesHtml.append("" + + FilePathParser.getFileNameWithoutExtension(picture.fileName) + + "
"); + + // links to thumbnails of various sizes + filesHtml.append("(" + enlistImageDimensions(picture) + ")\n"); + + filesHtml.append("
"); + } + /** {@inheritDoc} */ @Override public void enlistOgv(final AbstractFile abstractFile, @@ -136,29 +138,34 @@ public class MixedLayout implements Layout { final GeneralFile file = (GeneralFile) abstractFile; + filesHtml.append("
"); + + // watchable video filesHtml - .append("
" - + "
\n"); + + file.fileName) + "\">download as OGV"); + + filesHtml.append("
\n"); filesHtml.append("\n"); @@ -208,6 +215,19 @@ public class MixedLayout implements Layout { return finalHtml.toString(); } + private String getImageThumbnailUrl(final Picture picture) { + final Dimension imageSize = picture.getDimensions(); + + Dimension listingDimension = new Dimension(1500, 450); + + if (listingDimension.width > imageSize.width) + if (listingDimension.height > imageSize.height) + listingDimension = imageSize; + + return indexer.getThumbnailUrl(picture, listingDimension, + indexingContext); + } + @Override public void init(final String galleryTitle, final List path, final AbstractIndexer indexer, final IndexingContext indexingContext) { diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/MevizSpecialFile.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/MevizSpecialFile.java index f4ddc20..fa692d6 100644 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/MevizSpecialFile.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/MevizSpecialFile.java @@ -3,8 +3,12 @@ package eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes; import java.io.File; import java.io.IOException; +import eu.svjatoslav.commons.file.IOHelper; + public class MevizSpecialFile extends AbstractFile { + private String fileContent; + private static final long serialVersionUID = -8749190459653455640L; public MevizSpecialFile(final File parentDirectory, final String fileName) @@ -12,9 +16,16 @@ public class MevizSpecialFile extends AbstractFile { super(parentDirectory, fileName); } + public String getFileContent() { + return fileContent; + } + @Override protected void updateFileMetainfo(final File parentDirectory) throws IOException { + + fileContent = IOHelper + .getFileContentsAsString(getFile(parentDirectory)); } }