better table-less and responsive layout
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 17 Oct 2014 19:46:25 +0000 (22:46 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 17 Oct 2014 19:46:25 +0000 (22:46 +0300)
src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java

index 915c7c8..8ae1002 100755 (executable)
@@ -39,24 +39,10 @@ public class MixedLayout implements Layout {
 
        public static final String encoding = "UTF-8";
 
-       int currentColumn = 0;
-
-       int horizontalColumnsLimit = 2;
-
        private AbstractIndexer indexer;
 
        private IndexingContext indexingContext;
 
-       public void columnAdded() {
-               currentColumn++;
-               if (currentColumn > horizontalColumnsLimit) {
-
-                       currentColumn = 0;
-
-                       filesHtml.append("</TR>\n");
-               }
-       }
-
        @Override
        public void enlistDirectory(final AbstractFile directory) {
                dirHtml.append("<TR>");
@@ -69,21 +55,16 @@ public class MixedLayout implements Layout {
 
        @Override
        public void enlistFile(final AbstractFile file) {
-               finishRow();
 
                final String fullFileName = file.fileName;
 
-               filesHtml.append("<TR>\n");
-               filesHtml.append("    <TD colspan=\""
-                               + String.valueOf(horizontalColumnsLimit)
-                               + "\"><a href=\""
+               filesHtml.append("<div style=\"clear: both;\"><a href=\""
                                + indexingContext.getGlobalUrl()
                                + UrlParamEncoder.encode(indexingContext.getLocalUrl() + "/"
                                                + fullFileName) + "\">" + fullFileName + "</a>\n");
                filesHtml.append("&nbsp;&nbsp;("
                                + FilePathParser.getFileSizeDescription(file.getFileLength())
-                               + ")</TD>\n");
-               filesHtml.append("</TR>\n");
+                               + ")</div><br/>\n");
 
        }
 
@@ -98,7 +79,7 @@ public class MixedLayout implements Layout {
                        final List<Dimension> recommendedDimensions = Picture
                                        .getThumbnailDimensions(imageSize);
 
-                       Dimension listingDimension = new Dimension(500, 500);
+                       Dimension listingDimension = new Dimension(1500, 450);
 
                        if (listingDimension.width > imageSize.width)
                                if (listingDimension.height > imageSize.height)
@@ -107,9 +88,8 @@ public class MixedLayout implements Layout {
                        final String listingThumbnailUrl = indexer.getThumbnailUrl(picture,
                                        listingDimension, indexingContext);
 
-                       startcolumn();
-
-                       filesHtml.append("<TD><center><a href=\""
+                       filesHtml.append("<div style=\"float:left; margin: 10px;\">");
+                       filesHtml.append("<a href=\""
                                        + indexingContext.getGlobalUrl()
                                        + UrlParamEncoder.encode(indexingContext.getLocalUrl()
                                                        + "/" + picture.fileName) + "\">\n");
@@ -133,9 +113,8 @@ public class MixedLayout implements Layout {
                                filesHtml.append("</a>");
                        }
 
-                       filesHtml.append(")</TD>\n");
-
-                       columnAdded();
+                       filesHtml.append(")\n");
+                       filesHtml.append("</div>");
 
                } catch (final Exception e) {
                        logger.error(
@@ -154,14 +133,8 @@ public class MixedLayout implements Layout {
 
                final GeneralFile file = (GeneralFile) abstractFile;
 
-               finishRow();
-
                filesHtml
-                               .append("<TR style=\"background-color: #404040; text-align: center\">\n");
-               filesHtml.append("<TD style=\"text-align: center\" colspan=\""
-                               + String.valueOf(horizontalColumnsLimit) + "\">\n");
-
-               filesHtml.append("<video controls=\"controls\" tabindex=\"0\">\n");
+                               .append("<div style=\"margin: 30px; clear: both;\"><video controls=\"controls\" tabindex=\"0\">\n");
                filesHtml
                                .append("<source type=\"video/ogg\" codecs=\"theora, vorbis\" src=\""
                                                + indexingContext.getGlobalUrl()
@@ -181,23 +154,10 @@ public class MixedLayout implements Layout {
                filesHtml.append("<a href=\""
                                + indexingContext.getGlobalUrl()
                                + UrlParamEncoder.encode(indexingContext.getLocalUrl() + "/"
-                                               + file.fileName) + "\">download as OGV</a>\n");
-
-               filesHtml.append("</TD></TR>\n");
-
-       }
-
-       public void finishRow() {
+                                               + file.fileName) + "\">download as OGV</a></div>\n");
 
-               if (currentColumn == 0)
-                       return;
+               filesHtml.append("\n");
 
-               while (currentColumn <= horizontalColumnsLimit) {
-                       filesHtml.append("<TD></TD>");
-                       currentColumn++;
-               }
-               filesHtml.append("</TR>\n");
-               currentColumn = 0;
        }
 
        /** {@inheritDoc} */
@@ -232,32 +192,11 @@ public class MixedLayout implements Layout {
                        finalHtml
                                        .append("<CENTER><H1>" + galleryTitle + "</H1></CENTER>\n");
 
-               finalHtml.append("<CENTER><H2>");
-               for (final String p : path)
-                       finalHtml.append(" / " + p);
-               finalHtml.append("</H2></CENTER>\n");
-
-               // append directory listing
-               finalHtml.append("<TABLE>\n");
-
-               if (path.size() > 0) {
-                       finalHtml.append("<TR>");
-                       finalHtml.append("<TD><b><a href=\""
-                                       + indexer.getParentDirectoryUrl(indexingContext)
-                                       + "\"><h2> &lt;== parent directory</h2></a></b></TD>");
-                       finalHtml.append("</TR>\n");
-               }
-
-               finalHtml.append(dirHtml.toString());
-               finalHtml.append("\n<TR><TD><br></TD></TR>\n");
-               finalHtml.append("</TABLE>\n");
+               showCurrentPath(finalHtml);
 
-               // append file listing
+               listDirectories(finalHtml);
 
-               finishRow();
-               finalHtml.append("<TABLE width=\"1100\">\n");
                finalHtml.append(filesHtml.toString());
-               finalHtml.append("\n</TABLE>\n");
 
                if (doHtmlHeaderAndFooter)
                        finalHtml.append("</font></BODY></HTML>\n");
@@ -278,11 +217,27 @@ public class MixedLayout implements Layout {
                filesHtml = new StringBuffer();
        }
 
-       public void startcolumn() {
-               if (currentColumn == 0) {
-                       filesHtml.append("<TR>");
-                       currentColumn = 1;
+       private void listDirectories(final StringBuffer finalHtml) {
+               finalHtml.append("<TABLE>\n");
+
+               if (path.size() > 0) {
+                       finalHtml.append("<TR>");
+                       finalHtml.append("<TD><b><a href=\""
+                                       + indexer.getParentDirectoryUrl(indexingContext)
+                                       + "\"><h2> &lt;== parent directory</h2></a></b></TD>");
+                       finalHtml.append("</TR>\n");
                }
+
+               finalHtml.append(dirHtml.toString());
+               finalHtml.append("\n<TR><TD><br></TD></TR>\n");
+               finalHtml.append("</TABLE>\n");
+       }
+
+       private void showCurrentPath(final StringBuffer finalHtml) {
+               finalHtml.append("<CENTER><H2>");
+               for (final String p : path)
+                       finalHtml.append(" / " + p);
+               finalHtml.append("</H2></CENTER>\n");
        }
 
 }