Coverage Report - com.buckosoft.PicMan.web.PicFilterWeb
 
Classes in this File Line Coverage Branch Coverage Complexity
PicFilterWeb
0%
0/94
0%
0/60
8.5
 
 1  
 /******************************************************************************
 2  
  * PicFilterWeb.java - Output a pic as a filter list
 3  
  * 
 4  
  * PicMan - The BuckoSoft Picture Manager in Java
 5  
  * Copyright(c) 2005 - Dick Balaska
 6  
  * 
 7  
  */
 8  
 package com.buckosoft.PicMan.web;
 9  
 
 10  
 import java.util.Iterator;
 11  
 import java.util.List;
 12  
 import java.util.ListIterator;
 13  
 
 14  
 import org.apache.commons.logging.Log;
 15  
 import org.apache.commons.logging.LogFactory;
 16  
 
 17  
 import com.buckosoft.PicMan.db.DatabaseFacade;
 18  
 
 19  
 import com.buckosoft.PicMan.domain.Filter;
 20  
 import com.buckosoft.PicMan.domain.Set;
 21  
 
 22  0
 public class PicFilterWeb {
 23  
         
 24  0
         protected final Log logger = LogFactory.getLog(getClass());
 25  
         static private final String eol = "\r\n";
 26  
 
 27  
         private DatabaseFacade dbf;
 28  
         
 29  0
         public void setDatabase(DatabaseFacade dbf) { this.dbf = dbf; }
 30  0
         public DatabaseFacade getDatabase() { return(dbf); }
 31  
 
 32  
 
 33  
         /**
 34  
          * Given a picName, output a table segment that displays the thumbnail and the filter
 35  
          * as a series of checkboxs.
 36  
          * 
 37  
          * @param picName the name of the pic to display
 38  
          * @return a big HTML string
 39  
          */
 40  
         public        String        getFilterEdit(String picName) {
 41  0
                 Filter                f = dbf.getFilter(picName);
 42  0
                 List<Integer>        sizes = dbf.getSizes();
 43  0
                 List<Set>                sets = dbf.getSets();
 44  
                 Iterator<Integer>        isize;
 45  0
                 int                                csizes = sizes.size();
 46  
                 int                                size;
 47  
                 Iterator<Set>        iset;
 48  
                 Set                                set;
 49  
 
 50  0
                 int                        activeSets = 0;
 51  0
                 iset = sets.iterator();
 52  0
                 while (iset.hasNext()) {
 53  0
                         set = iset.next();
 54  0
                         if (set.isActive() && !set.isMetaSet() && !set.isMicroSet())
 55  0
                                 activeSets++;
 56  
                 }
 57  
                 
 58  
                 // the output string
 59  0
                 StringBuffer        s = new StringBuffer();
 60  0
                 s.append("<tr><td rowspan=4><img src=\"getThumbNail.do?pic=");
 61  0
                 s.append(picName);
 62  0
                 s.append("\"/></td>");
 63  0
                 s.append(eol);
 64  0
                 s.append("<td colspan=" + ((csizes+1)*activeSets-1) + ">" + picName);
 65  
 
 66  0
                 s.append("<script language=\"JavaScript1.1\">");
 67  0
                 iset = sets.iterator();
 68  
                 ListIterator<Integer> li;
 69  0
                 while (iset.hasNext()) {
 70  0
                         set = (Set)iset.next();
 71  0
                         if (set.isActive() && !set.isMetaSet()) {
 72  0
                                 s.append("function doCl_" + picName + "_" + set.getName() + "(z) { while(1) {" + eol);
 73  0
                                 s.append("var n=\"" + picName + "_" + set.getName() + "_\"+z;");
 74  0
                                 s.append("var c=document.getElementById(n).checked;" + eol);
 75  0
                                 li = sizes.listIterator(sizes.size());
 76  0
                                 while (li.hasPrevious()) {
 77  0
                                         size = ((Integer)(li.previous())).intValue();
 78  0
                                         s.append("if (z==" + size + ") break;" + eol);
 79  0
                                         s.append("document.getElementById(\"" + getPSSName(picName, set.getName(), size) 
 80  
                                                 + "\").checked = c;" + eol);
 81  
                                 }
 82  0
                                 s.append("}}" + eol);
 83  
                         }
 84  
                 }
 85  0
                 s.append("</script><input type=\"hidden\" name=\"pic_" + picName + "\" value=\"1\" />" + eol);
 86  0
                 s.append("</td></tr>" + eol);
 87  
 
 88  
                 // row 2 is the sizes
 89  0
                 s.append("<tr>");
 90  0
                 isize = sizes.iterator();
 91  0
                 while (isize.hasNext()) {
 92  0
                         size = ((Integer)(isize.next())).intValue();
 93  0
                         s.append("<td colspan=" + activeSets + " align=center>" + size + "</td><td rowspan=3 width=1 bgcolor=#000000><br/></td>" + eol);
 94  
                 }
 95  0
                 s.append("</tr>" + eol);
 96  
                 
 97  
                 // row 3 is the sets
 98  0
                 s.append("<tr>");
 99  0
                 isize = sizes.iterator();
 100  0
                 while (isize.hasNext()) {
 101  0
                         size = ((Integer)(isize.next())).intValue();
 102  0
                         iset = sets.iterator();
 103  0
                         while (iset.hasNext()) {
 104  0
                                 set = (Set)iset.next();
 105  0
                                 if (set.isActive() && !set.isMetaSet() && !set.isMicroSet())
 106  0
                                         s.append("<td align=center>" + set.getName() + "</td>" + eol);
 107  
                         }
 108  
                 }
 109  0
                 s.append("</tr>" + eol);
 110  
                 
 111  
                 // row 4 is the checkboxes and selectors
 112  0
                 s.append("<tr>");
 113  0
                 isize = sizes.iterator();
 114  0
                 while (isize.hasNext()) {
 115  0
                         size = ((Integer)(isize.next())).intValue();
 116  0
                         iset = sets.iterator();
 117  0
                         while (iset.hasNext()) {
 118  0
                                 set = (Set)iset.next();
 119  0
                                 if (set.isActive() && !set.isMetaSet() && !set.isMicroSet()) {
 120  0
                                         int        value = f.getFilter(set.getName(), size);
 121  0
                                         s.append("<td><input type=\"checkbox\" id=\"" + getPSSName(picName, set.getName(), size) + "\"");
 122  0
                                         s.append(" name=\"" + getPSSName(picName, set.getName(), size) + "\"");
 123  0
                                         s.append(" onclick='doCl_" + picName + "_" + set.getName() + "(" + size + "); return true;'");
 124  0
                                         s.append(((value != 0) ? " CHECKED " : "") + "/>" + eol);
 125  0
                                         s.append("<select name=\"sl_" + getPSSName(picName, set.getName(), size) + "\"");
 126  0
                                         s.append(" id='sl_" + getPSSName(picName, set.getName(), size) + "'");
 127  0
                                         s.append(" onchange='selChanged(\"" + picName + "\",\"" + set.getName() + "\"," + size + ");'> ");
 128  0
                                         s.append("<option value=\"9\"");
 129  0
                                         if (value >= 9) s.append(" SELECTED"); s.append(">9</option>");
 130  0
                                         s.append("<option value=\"8\"");
 131  0
                                         if (value == 8) s.append(" SELECTED"); s.append(">8</option>");
 132  0
                                         s.append("<option value=\"7\"");
 133  0
                                         if (value == 7) s.append(" SELECTED"); s.append(">7</option>");
 134  0
                                         s.append("<option value=\"6\"");
 135  0
                                         if (value == 6) s.append(" SELECTED"); s.append(">6</option>");
 136  0
                                         s.append("<option value=\"5\"");
 137  0
                                         if (value == 5) s.append(" SELECTED"); s.append(">5</option>");
 138  0
                                         s.append("<option value=\"4\"");
 139  0
                                         if (value == 4) s.append(" SELECTED"); s.append(">4</option>");
 140  0
                                         s.append("<option value=\"3\"");
 141  0
                                         if (value == 3) s.append(" SELECTED"); s.append(">3</option>");
 142  0
                                         s.append("<option value=\"2\"");
 143  0
                                         if (value == 2) s.append(" SELECTED"); s.append(">2</option>");
 144  0
                                         s.append("<option value=\"1\"");
 145  0
                                         if (value == 1) s.append(" SELECTED"); s.append(">1</option>");
 146  0
                                         s.append("<option value=\"0\"");
 147  0
                                         if (value == 0) s.append(" SELECTED"); s.append(">0</option>");
 148  0
                                         s.append("</select></td>" + eol);
 149  0
                                 }
 150  
                         }
 151  
                 }
 152  0
                 s.append("</tr>");
 153  0
                 return(s.toString());
 154  
         }
 155  
         
 156  
         private        String        getPSSName(String pic, String set, int size) {
 157  0
                 String s = pic + "_" + set + "_" + size;
 158  0
                 return(s);
 159  
         }
 160  
 }