| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 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 | |
|
| 27 | |
|
| 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 | |
|
| 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 | |
|
| 62 | |
|
| 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 | |
|
| 72 | |
|
| 73 | |
public String getMasterPic() { |
| 74 | 0 | return masterPic; |
| 75 | |
} |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
public void setMasterPic(String masterPic) { |
| 80 | 0 | this.masterPic = masterPic; |
| 81 | 0 | } |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
public Mosaic getMosaic() { |
| 86 | 0 | return mosaic; |
| 87 | |
} |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
public void setMosaic(Mosaic mosaic) { |
| 92 | 0 | this.mosaic = mosaic; |
| 93 | 0 | } |
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
public String getMosaicSelectName() { |
| 99 | 0 | return mosaicSelectName; |
| 100 | |
} |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
public void setMosaicSelectName(String mosaicSelectName) { |
| 105 | 0 | this.mosaicSelectName = mosaicSelectName; |
| 106 | 0 | } |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
public String getMosaicName() { |
| 111 | 0 | return mosaicName; |
| 112 | |
} |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
public void setMosaicName(String mosaicName) { |
| 117 | 0 | this.mosaicName = mosaicName; |
| 118 | 0 | } |
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
public List<Mosaic> getMosaics() { |
| 124 | 0 | return mosaics; |
| 125 | |
} |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
public void setMosaics(List<Mosaic> mosaics) { |
| 130 | 0 | this.mosaics = mosaics; |
| 131 | 0 | } |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
public void setMosaicBatches(List<MosaicBatch> mbatches) { |
| 137 | 0 | this.mosaicBatches = mbatches; |
| 138 | 0 | } |
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
public List<MosaicBatch> getMosaicBatches() { |
| 143 | 0 | return mosaicBatches; |
| 144 | |
} |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
public String getMosaicEngineName() { |
| 149 | 0 | return mosaicEngineName; |
| 150 | |
} |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
public void setMosaicEngineName(String mosaicEngineName) { |
| 155 | 0 | this.mosaicEngineName = mosaicEngineName; |
| 156 | 0 | } |
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
public List<String> getEngines() { |
| 161 | 0 | return engines; |
| 162 | |
} |
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
public void setEngines(List<String> engines) { |
| 167 | 0 | this.engines = engines; |
| 168 | 0 | } |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
public int getMosaicHeight() { |
| 173 | 0 | return mosaicHeight; |
| 174 | |
} |
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
public void setMosaicHeight(int mosaicHeight) { |
| 179 | 0 | this.mosaicHeight = mosaicHeight; |
| 180 | 0 | } |
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
public String getMosaicOutputFile() { |
| 186 | 0 | return mosaicOutputFile; |
| 187 | |
} |
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
public void setMosaicOutputFile(String mosaicOutputFile) { |
| 192 | 0 | this.mosaicOutputFile = mosaicOutputFile; |
| 193 | 0 | } |
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
public boolean isStartBuilding() { |
| 198 | 0 | return startBuilding; |
| 199 | |
} |
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
public void setStartBuilding(boolean startBuilding) { |
| 204 | 0 | this.startBuilding = startBuilding; |
| 205 | 0 | } |
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
public boolean isMakeBackups() { |
| 211 | 0 | return makeBackups; |
| 212 | |
} |
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
public void setMakeBackups(boolean makeBackups) { |
| 218 | 0 | this.makeBackups = makeBackups; |
| 219 | 0 | } |
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
public int getMosaicSid() { |
| 224 | 0 | return mosaicSid; |
| 225 | |
} |
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
public void setMosaicSid(int mosaicSid) { |
| 230 | 0 | this.mosaicSid = mosaicSid; |
| 231 | 0 | } |
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
public List<Set> getSets() { |
| 236 | 0 | return sets; |
| 237 | |
} |
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
public void setSets(List<Set> sets) { |
| 242 | 0 | this.sets = sets; |
| 243 | 0 | } |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
public boolean isBatchMode() { |
| 248 | 0 | return batchMode; |
| 249 | |
} |
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
public void setBatchMode(boolean batchMode) { |
| 254 | 0 | this.batchMode = batchMode; |
| 255 | 0 | } |
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
public String getMosaicSizes() { |
| 260 | 0 | return mosaicSizes; |
| 261 | |
} |
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
public void setMosaicSizes(String mosaicSizes) { |
| 266 | 0 | this.mosaicSizes = mosaicSizes; |
| 267 | 0 | } |
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
public String getMosaicEngineConfig() { |
| 273 | 0 | return mosaicEngineConfig; |
| 274 | |
} |
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
public void setMosaicEngineConfig(String mosaicEngineConfig) { |
| 280 | 0 | this.mosaicEngineConfig = mosaicEngineConfig; |
| 281 | 0 | } |
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
public String getMosaicConfigs() { |
| 287 | 0 | return mosaicConfigs; |
| 288 | |
} |
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
public void setMosaicConfigs(String mosaicConfigs) { |
| 294 | 0 | this.mosaicConfigs = mosaicConfigs; |
| 295 | 0 | } |
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 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 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
int i; |
| 339 | 0 | sb.setLength(0); |
| 340 | 0 | String[] cl = Classes.getClasses("com.buckosoft.PicMan.business.mosaic.engine"); |
| 341 | |
|
| 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 | |
|
| 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 | |
|
| 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 | |
} |