Coverage Report - com.buckosoft.PicMan.web.MosaicSetupForm
 
Classes in this File Line Coverage Branch Coverage Complexity
MosaicSetupForm
0%
0/117
0%
0/20
1.341
MosaicSetupForm$MosaicConfig
0%
0/1
N/A
1.341
 
 1  
 /******************************************************************************
 2  
  * MosaicForm.java - The backing form to edit PicMan's Mosaic setup
 3  
  * 
 4  
  * PicMan - The BuckoSoft Picture Manager in Java
 5  
  * Copyright(c) 2007 - Dick Balaska
 6  
  * 
 7  
  */
 8  
 package com.buckosoft.PicMan.web;
 9  
 
 10  
 import java.util.HashMap;
 11  
 import java.util.LinkedList;
 12  
 import java.util.List;
 13  
 
 14  
 import org.apache.commons.logging.Log;
 15  
 import org.apache.commons.logging.LogFactory;
 16  
 
 17  
 import com.buckosoft.BSAccount.web.BSAccountUserWebSession;
 18  
 import com.buckosoft.PicMan.business.PicManFacade;
 19  
 import com.buckosoft.PicMan.business.mosaic.MosaicEngine;
 20  
 import com.buckosoft.PicMan.business.mosaic.MosaicEngine.ConfigItem;
 21  
 import com.buckosoft.PicMan.business.util.Classes;
 22  
 import com.buckosoft.PicMan.domain.Mosaic;
 23  
 import com.buckosoft.PicMan.domain.MosaicBatch;
 24  
 import com.buckosoft.PicMan.domain.Set;
 25  
 
 26  
 /** The backing form to edit PicMan's Mosaic setup
 27  
  * @author dick
 28  
  *
 29  
  */
 30  0
 public class MosaicSetupForm {
 31  
         private        final static boolean DEBUG = true;
 32  0
     protected final Log logger = LogFactory.getLog(getClass());
 33  
 
 34  
     private        BSAccountUserWebSession        userWebSession;
 35  
         private        Mosaic                        mosaic;
 36  
         private        String                        masterPic;
 37  
         private        int                                mosaicHeight;
 38  
         private        String                        mosaicOutputFile;
 39  
 
 40  
 //        private        String                        mosaicSetName;
 41  
         private        int                                mosaicSid;
 42  
         private        List<Set>                sets;
 43  
         private        boolean                        startBuilding;
 44  0
         private        boolean                        makeBackups = true;
 45  0
         private        String                        mosaicName = "New Mosaic";
 46  
         private        List<Mosaic>        mosaics;
 47  
         private        List<MosaicBatch>        mosaicBatches;
 48  
 
 49  
         private        String                        mosaicEngineName;
 50  
         private        List<String>        engines;
 51  0
         private        String                        mosaicSelectName = "";
 52  0
         private        boolean                        batchMode = false;
 53  
         private        String                        mosaicSizes;
 54  
 
 55  
         private        String                        mosaicEngineConfig;
 56  
         private        String                        mosaicConfigs;
 57  
         
 58  
         @SuppressWarnings("unused")
 59  
         private PicManFacade pmf;
 60  
 
 61  
         /** Set the reference to the PicMan API.
 62  
          * @param pmf The PicManFacade
 63  
          */
 64  0
         public void setPicMan(PicManFacade pmf) { this.pmf = pmf; }
 65  
         
 66  0
         public        BSAccountUserWebSession        getUserWebSession() { return(userWebSession); }
 67  0
         public        void                setUserWebSession(BSAccountUserWebSession us) { userWebSession = us; }
 68  
 
 69  
         
 70  
         /**
 71  
          * @return the masterPic
 72  
          */
 73  
         public String getMasterPic() {
 74  0
                 return masterPic;
 75  
         }
 76  
         /**
 77  
          * @param masterPic the masterPic to set
 78  
          */
 79  
         public void setMasterPic(String masterPic) {
 80  0
                 this.masterPic = masterPic;
 81  0
         }
 82  
         /**
 83  
          * @return the mosaic
 84  
          */
 85  
         public Mosaic getMosaic() {
 86  0
                 return mosaic;
 87  
         }
 88  
         /**
 89  
          * @param mosaic the mosaic to set
 90  
          */
 91  
         public void setMosaic(Mosaic mosaic) {
 92  0
                 this.mosaic = mosaic;
 93  0
         }
 94  
         
 95  
         /**
 96  
          * @return the mosaicSelectName
 97  
          */
 98  
         public String getMosaicSelectName() {
 99  0
                 return mosaicSelectName;
 100  
         }
 101  
         /**
 102  
          * @param mosaicSelectName the mosaicSelectName to set
 103  
          */
 104  
         public void setMosaicSelectName(String mosaicSelectName) {
 105  0
                 this.mosaicSelectName = mosaicSelectName;
 106  0
         }
 107  
         /**
 108  
          * @return the mosaicName
 109  
          */
 110  
         public String getMosaicName() {
 111  0
                 return mosaicName;
 112  
         }
 113  
         /**
 114  
          * @param mosaicName the mosaicName to set
 115  
          */
 116  
         public void setMosaicName(String mosaicName) {
 117  0
                 this.mosaicName = mosaicName;
 118  0
         }
 119  
         
 120  
         /**
 121  
          * @return the mosaics
 122  
          */
 123  
         public List<Mosaic> getMosaics() {
 124  0
                 return mosaics;
 125  
         }
 126  
         /**
 127  
          * @param mosaics the mosaics to set
 128  
          */
 129  
         public void setMosaics(List<Mosaic> mosaics) {
 130  0
                 this.mosaics = mosaics;
 131  0
         }
 132  
         
 133  
         /**
 134  
          * @param mbatches the mbatches to set
 135  
          */
 136  
         public void setMosaicBatches(List<MosaicBatch> mbatches) {
 137  0
                 this.mosaicBatches = mbatches;        
 138  0
         }        
 139  
         /**
 140  
          * @return the mosaicBatches
 141  
          */
 142  
         public List<MosaicBatch> getMosaicBatches() {
 143  0
                 return mosaicBatches;
 144  
         }
 145  
         /**
 146  
          * @return the mosaicEngineName
 147  
          */
 148  
         public String getMosaicEngineName() {
 149  0
                 return mosaicEngineName;
 150  
         }
 151  
         /**
 152  
          * @param mosaicEngineName the mosaicEngineName to set
 153  
          */
 154  
         public void setMosaicEngineName(String mosaicEngineName) {
 155  0
                 this.mosaicEngineName = mosaicEngineName;
 156  0
         }
 157  
         /**
 158  
          * @return the engines
 159  
          */
 160  
         public List<String> getEngines() {
 161  0
                 return engines;
 162  
         }
 163  
         /**
 164  
          * @param engines the engines to set
 165  
          */
 166  
         public void setEngines(List<String> engines) {
 167  0
                 this.engines = engines;
 168  0
         }
 169  
         /**
 170  
          * @return the mosaicHeight
 171  
          */
 172  
         public int getMosaicHeight() {
 173  0
                 return mosaicHeight;
 174  
         }
 175  
         /**
 176  
          * @param mosaicHeight the mosaicHeight to set
 177  
          */
 178  
         public void setMosaicHeight(int mosaicHeight) {
 179  0
                 this.mosaicHeight = mosaicHeight;
 180  0
         }
 181  
 
 182  
         /** Where to write the mosaic output
 183  
          * @return the mosaicOutputFile
 184  
          */
 185  
         public String getMosaicOutputFile() {
 186  0
                 return mosaicOutputFile;
 187  
         }
 188  
         /**
 189  
          * @param mosaicOutputFile the mosaicOutputFile to set
 190  
          */
 191  
         public void setMosaicOutputFile(String mosaicOutputFile) {
 192  0
                 this.mosaicOutputFile = mosaicOutputFile;
 193  0
         }
 194  
         /**
 195  
          * @return the startBuilding
 196  
          */
 197  
         public boolean isStartBuilding() {
 198  0
                 return startBuilding;
 199  
         }
 200  
         /**
 201  
          * @param startBuilding the startBuilding to set
 202  
          */
 203  
         public void setStartBuilding(boolean startBuilding) {
 204  0
                 this.startBuilding = startBuilding;
 205  0
         }
 206  
 
 207  
         /** Should we save the mosaic output jpeg before overwriting it with a new file?
 208  
          * @return the makeBackups
 209  
          */
 210  
         public boolean isMakeBackups() {
 211  0
                 return makeBackups;
 212  
         }
 213  
 
 214  
         /** Should we save the mosaic output jpeg before overwriting it with a new file?
 215  
          * @param makeBackups the makeBackups to set
 216  
          */
 217  
         public void setMakeBackups(boolean makeBackups) {
 218  0
                 this.makeBackups = makeBackups;
 219  0
         }
 220  
         /**
 221  
          * @return the mosaicSid
 222  
          */
 223  
         public int getMosaicSid() {
 224  0
                 return mosaicSid;
 225  
         }
 226  
         /**
 227  
          * @param mosaicSid the mosaicSid to set
 228  
          */
 229  
         public void setMosaicSid(int mosaicSid) {
 230  0
                 this.mosaicSid = mosaicSid;
 231  0
         }
 232  
         /**
 233  
          * @return the sets
 234  
          */
 235  
         public List<Set> getSets() {
 236  0
                 return sets;
 237  
         }
 238  
         /**
 239  
          * @param sets the sets to set
 240  
          */
 241  
         public void setSets(List<Set> sets) {
 242  0
                 this.sets = sets;
 243  0
         }
 244  
         /**
 245  
          * @return the batchMode
 246  
          */
 247  
         public boolean isBatchMode() {
 248  0
                 return batchMode;
 249  
         }
 250  
         /**
 251  
          * @param batchMode the batchMode to set
 252  
          */
 253  
         public void setBatchMode(boolean batchMode) {
 254  0
                 this.batchMode = batchMode;
 255  0
         }
 256  
         /** If this is a Batch Mosaic, then this is the sizes to make.
 257  
          * @return the mosaicSizes
 258  
          */
 259  
         public String getMosaicSizes() {
 260  0
                 return mosaicSizes;
 261  
         }
 262  
         /**
 263  
          * @param mosaicSizes the mosaicSizes to set
 264  
          */
 265  
         public void setMosaicSizes(String mosaicSizes) {
 266  0
                 this.mosaicSizes = mosaicSizes;
 267  0
         }
 268  
 
 269  
         /**
 270  
          * @return the mosaicEngineConfig
 271  
          */
 272  
         public String getMosaicEngineConfig() {
 273  0
                 return mosaicEngineConfig;
 274  
         }
 275  
 
 276  
         /**
 277  
          * @param mosaicEngineConfig the mosaicEngineConfig to set
 278  
          */
 279  
         public void setMosaicEngineConfig(String mosaicEngineConfig) {
 280  0
                 this.mosaicEngineConfig = mosaicEngineConfig;
 281  0
         }
 282  
 
 283  
         /**
 284  
          * @return the mosaicConfigs
 285  
          */
 286  
         public String getMosaicConfigs() {
 287  0
                 return mosaicConfigs;
 288  
         }
 289  
 
 290  
         /**
 291  
          * @param mosaicConfigs the mosaicConfigs to set
 292  
          */
 293  
         public void setMosaicConfigs(String mosaicConfigs) {
 294  0
                 this.mosaicConfigs = mosaicConfigs;
 295  0
         }
 296  
 
 297  
         
 298  
 /*        public String getEngineConfig() {
 299  
                 if (mosaicEngineConfig == null && mosaicEngineName != null && mosaicEngineName.length() > 1) 
 300  
                         mosaicEngineConfig = pmf.getMosaicMan().getMosaicConfigParams(mosaicEngineName);
 301  
                 return(mosaicEngineConfig);
 302  
         }
 303  
 */
 304  
 
 305  0
         public static class MosaicConfig {
 306  
                 public String engineConfig;
 307  
                 public String mosaicConfig;
 308  
                 public List<String>        engines;
 309  
                 
 310  
         }
 311  
         
 312  
         public static MosaicConfig getConfigs(List<Mosaic> list) {
 313  0
                 MosaicConfig mosaicConfig = new MosaicConfig();
 314  0
                 mosaicConfig.engines = new LinkedList<String>();
 315  0
                 StringBuffer sb = new StringBuffer();
 316  0
                 sb.append("var mosaicConfigs = new Array();\n");
 317  0
                 for (Mosaic mb : list) {
 318  0
                         if (!mb.getEngineConfig().isEmpty()) {
 319  0
                                 sb.append("mosaicConfigs[" + mb.getMid() + "] = [\n");
 320  0
                                 for (String key : mb.getEngineConfig().keySet()) {
 321  0
                                         sb.append("new KeyValue(\"" + key + "\",\"" + mb.getEngineConfig().get(key) + "\"),\n");
 322  0
                                 }
 323  0
                                 sb.append("];\n");
 324  
                         }
 325  0
                 }
 326  0
                 mosaicConfig.mosaicConfig = sb.toString();
 327  
 /*
 328  
                 Enumeration<URL> eu        = ClassLoader.getSystemResources("com/buckosoft/PicMan/business/mosaic/engine/*");
 329  
                 if (DEBUG) {
 330  
                         //logger.info("eu check");
 331  
                         while (eu.hasMoreElements()) {
 332  
                                 URL u = eu.nextElement();
 333  
                                 //logger.info("u=" + u.toString());
 334  
                         }
 335  
                 }
 336  
 */
 337  
                 //Package p = this.getClass().getClassLoader().getPackage("com/buckosoft/PicMan/business/mosaic/engine");
 338  
                 int i;
 339  0
                 sb.setLength(0);
 340  0
                 String[] cl = Classes.getClasses("com.buckosoft.PicMan.business.mosaic.engine");
 341  
 //                List<String> classes = new LinkedList<String>();
 342  0
                 for (i=0; i<cl.length; i++) {
 343  0
                         if (cl[i].indexOf('$') != -1)
 344  0
                                 continue;
 345  0
                         mosaicConfig.engines.add(cl[i]);
 346  0
                         addEngineConfig(sb, cl[i]);
 347  
                 }
 348  
                 if (DEBUG) {
 349  0
                         for (i=0; i<cl.length; i++) {
 350  
                                 //logger.info("class: " + cl[i]);
 351  
                         }
 352  
                 }
 353  0
                 mosaicConfig.engineConfig = sb.toString();
 354  
                 
 355  0
                 return(mosaicConfig);
 356  
         }
 357  
 
 358  
         private        static void addEngineConfig(StringBuffer sb, String className) {
 359  
                 MosaicEngine        mosaicEngine;
 360  
         
 361  
                 try {
 362  0
                         mosaicEngine = (MosaicEngine)Class.forName("com.buckosoft.PicMan.business.mosaic.engine."
 363  0
                                                         + className).newInstance();
 364  0
                 } catch (Exception e) {
 365  0
                         Exception ex = new Exception("Can't instantiate Mosaic Engine: " + className, e);
 366  0
                         LogFactory.getLog(MosaicSetupForm.class).warn("addEngineConfig", ex);
 367  
                         //pmf.addError(ex);
 368  0
                         sb.append("engineConfigArray[\"" + className + "\"]=\"<tr><td colspan=\"2\">addEngineConfig Can't instantiate '" + className + "'</td></tr>\";\n");
 369  0
                         return;
 370  0
                 }
 371  0
                 HashMap<String, ConfigItem> configMap = mosaicEngine.getConfigMap();
 372  0
                 if (configMap.isEmpty())
 373  0
                         return;
 374  0
                 sb.append("engineConfigArray[\"" + className + "\"]=\'");
 375  0
                 int flipFlop = 0;
 376  0
                 for (String key : configMap.keySet()) {
 377  0
                         ConfigItem item = configMap.get(key);
 378  0
                         sb.append("<tr class=\"back" + flipFlop + "\"><td>");
 379  0
                         sb.append(item.getDescription());
 380  0
                         sb.append("</td><td><input type=\"text\" name=\"");
 381  0
                         sb.append(key);
 382  0
                         sb.append("\" id=\"inp_");
 383  0
                         sb.append(key);
 384  0
                         sb.append("\" value=\"");
 385  0
                         if (item.getType() == ConfigItem.TYPE_INT)
 386  0
                                 sb.append("" + item.getValueInt());
 387  0
                         sb.append("\"/>");
 388  0
                         flipFlop++;
 389  0
                         if (flipFlop >= 2)
 390  0
                                 flipFlop = 0;
 391  0
                 }
 392  0
                 sb.append("';\n");
 393  0
         }
 394  
         
 395  
 
 396  
 }