| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.phoenix.chart2d; |
| 34 | | | |
| 35 | | | |
| 36 | | | import java.awt.AlphaComposite; |
| 37 | | | import java.awt.Color; |
| 38 | | | import java.awt.Dimension; |
| 39 | | | import java.io.BufferedReader; |
| 40 | | | import java.io.BufferedWriter; |
| 41 | | | import java.io.File; |
| 42 | | | import java.io.FileInputStream; |
| 43 | | | import java.io.FileReader; |
| 44 | | | import java.io.FileWriter; |
| 45 | | | import java.io.FilenameFilter; |
| 46 | | | import java.io.IOException; |
| 47 | | | import java.lang.reflect.Field; |
| 48 | | | import java.lang.reflect.Method; |
| 49 | | | import java.util.ArrayList; |
| 50 | | | import java.util.Arrays; |
| 51 | | | import java.util.Collection; |
| 52 | | | import java.util.HashMap; |
| 53 | | | import java.util.Iterator; |
| 54 | | | import java.util.List; |
| 55 | | | import java.util.Map; |
| 56 | | | import java.util.Set; |
| 57 | | | import java.util.TreeSet; |
| 58 | | | import java.util.Map.Entry; |
| 59 | | (1) | import java.util.logging.Handler; |
| 60 | | | import java.util.logging.Level; |
| 61 | | | import java.util.logging.Logger; |
| 62 | | | import java.util.regex.Matcher; |
| 63 | | | import java.util.regex.Pattern; |
| 64 | | | |
| 65 | | | import javax.xml.parsers.DocumentBuilder; |
| 66 | | | import javax.xml.parsers.DocumentBuilderFactory; |
| 67 | | | import javax.xml.parsers.ParserConfigurationException; |
| 68 | | | |
| 69 | | | import net.sourceforge.chart2d.Chart2D; |
| 70 | | | import net.sourceforge.chart2d.Chart2DProperties; |
| 71 | | | import net.sourceforge.chart2d.Dataset; |
| 72 | | | import net.sourceforge.chart2d.GraphChart2D; |
| 73 | | | import net.sourceforge.chart2d.GraphChart2DProperties; |
| 74 | | | import net.sourceforge.chart2d.GraphProperties; |
| 75 | | | import net.sourceforge.chart2d.LBChart2D; |
| 76 | | | import net.sourceforge.chart2d.LLChart2D; |
| 77 | | | import net.sourceforge.chart2d.LegendProperties; |
| 78 | | | import net.sourceforge.chart2d.MultiColorsProperties; |
| 79 | | | import net.sourceforge.chart2d.Object2DProperties; |
| 80 | | | import net.sourceforge.chart2d.PieChart2D; |
| 81 | | | import net.sourceforge.chart2d.PieChart2DProperties; |
| 82 | | | import net.sourceforge.chart2d.WarningRegionProperties; |
| 83 | | | |
| 84 | | | import org.apache.xpath.XPathAPI; |
| 85 | | | import org.apache.xpath.objects.XObject; |
| 86 | | | import org.jcoderz.commons.types.Date; |
| 87 | | | import org.jcoderz.commons.util.Constants; |
| 88 | | | import org.jcoderz.commons.util.IoUtil; |
| 89 | | | import org.jcoderz.commons.util.LoggingProxy; |
| 90 | | | import org.jcoderz.commons.util.LoggingUtils; |
| 91 | | | import org.w3c.dom.Document; |
| 92 | | | import org.w3c.dom.Node; |
| 93 | | | import org.w3c.dom.traversal.NodeIterator; |
| 94 | | | import org.xml.sax.Attributes; |
| 95 | | | import org.xml.sax.InputSource; |
| 96 | | | import org.xml.sax.SAXException; |
| 97 | | | |
| 98 | | | |
| 99 | | | |
| 100 | | | |
| 101 | | | |
| 102 | | | |
| 103 | | | |
| 104 | | | |
| 105 | | | |
| 106 | | | |
| 107 | | | |
| 108 | | | |
| 109 | | | |
| 110 | | | |
| 111 | | | |
| 112 | | | |
| 113 | | | |
| 114 | | | |
| 115 | | | <code></code> |
| 116 | | | |
| 117 | | | |
| 118 | | | <code></code> |
| 119 | | | <code></code> |
| 120 | | | <i></i> |
| 121 | | | |
| 122 | | | |
| 123 | | | <code></code> |
| 124 | | | |
| 125 | | | <code></code> |
| 126 | | | |
| 127 | | | |
| 128 | | | <code></code> |
| 129 | | | |
| 130 | | | |
| 131 | | | <i></i> |
| 132 | | | |
| 133 | | | |
| 134 | | | <code></code> |
| 135 | | | <code></code> |
| 136 | | | |
| 137 | | | <code></code> |
| 138 | | | <code></code> |
| 139 | | | |
| 140 | | | |
| 141 | | | |
| 142 | | | <code></code> |
| 143 | | | |
| 144 | | | <code></code> |
| 145 | | | |
| 146 | | | |
| 147 | | | |
| 148 | | | |
| 149 | | | <code></code><code></code> |
| 150 | | | <code></code> |
| 151 | | (2) | <code></code> |
| 152 | | | |
| 153 | | | <code></code> |
| 154 | | | |
| 155 | | | <code></code> |
| 156 | | | |
| 157 | | | |
| 158 | | | |
| 159 | | | @author |
| 160 | | | @author |
| 161 | | | |
| 162 | | | public class Chart2DHandlerImpl implements Chart2DHandler |
| 163 | | | { |
| 164 | | | private static final int DEFAULT_WIDTH = 768; |
| 165 | | | private static final int DEFAULT_HEIGHT = 1024; |
| 166 | | | private static final int DEBUG_ARG_NUM = 3; |
| 167 | | | |
| 168 | | | private static final String TIME_PATTERN |
| 169 | | | = "(([0-9]+) minutes? )?([0-9]+) seconds?"; |
| 170 | | | private static final int TIME_PATTERN_MINUTES_GROUP = 2; |
| 171 | | | private static final int TIME_PATTERN_SECONDS_GROUP = 3; |
| 172 | 0 | | private static boolean sDebug = false; |
| 173 | 0 | | private static boolean sMultible = false; |
| 174 | | | private Object2DProperties mObject2DProperties; |
| 175 | | | private Chart2DProperties mChart2DProperties; |
| 176 | | | private GraphChart2DProperties mGraphChart2DProperties; |
| 177 | | | private List mCurrentLabelText; |
| 178 | | | private PieChart2DProperties mPieChart2DProperties; |
| 179 | | | private LegendProperties mLegendProperties; |
| 180 | 0 | | private final List mDataSets = new ArrayList(); |
| 181 | 0 | | private final List mMultiColorsProperties = new ArrayList(); |
| 182 | 0 | | private final List mGraphProperties = new ArrayList(); |
| 183 | 0 | | private final List mWarningRegionProperties = new ArrayList(); |
| 184 | 0 | | private int mWidth = DEFAULT_WIDTH; |
| 185 | 0 | | private int mHeight = DEFAULT_HEIGHT; |
| 186 | | | private String mFilename; |
| 187 | | | private String mType; |
| 188 | | | private List mCurrentDataSet; |
| 189 | | | private List mCurrentSet; |
| 190 | | | private List mCurrentCategory; |
| 191 | | | private MultiColorsProperties mCurrentMultiColorsProperties; |
| 192 | | | private List mCurrentMultiColors; |
| 193 | | | private String mChartType; |
| 194 | | | private List mCurrentLegendLabelsTexts; |
| 195 | | | private boolean mDoConvertToStacked; |
| 196 | | | private final File mDataRepository; |
| 197 | 0 | | private final Set mFilePatterns = new TreeSet(); |
| 198 | 0 | | private final List mXaxis = new ArrayList(); |
| 199 | 0 | | private int mXaxisModulus = 1; |
| 200 | 0 | | private final Map mXpathCache = new HashMap(); |
| 201 | | | private DocumentBuilder mDocumentBuilder; |
| 202 | | | |
| 203 | | | |
| 204 | | | |
| 205 | | | |
| 206 | | | |
| 207 | | | |
| 208 | | | @param |
| 209 | | | |
| 210 | | | |
| 211 | | | public Chart2DHandlerImpl (File dataRepository) |
| 212 | 0 | | { |
| 213 | 0 | | mDataRepository = dataRepository; |
| 214 | 0 | | if (mDataRepository != null) |
| 215 | | | { |
| 216 | 0 | | collectPatterns(mDataRepository, null); |
| 217 | 0 | | if (mFilePatterns.isEmpty()) |
| 218 | | | { |
| 219 | 0 | | throw new RuntimeException("No files found in repository path " |
| 220 | | | + mDataRepository + "."); |
| 221 | | | } |
| 222 | 0 | | readCache(); |
| 223 | | | } |
| 224 | 0 | | } |
| 225 | | | |
| 226 | | | |
| 227 | | | |
| 228 | | | |
| 229 | | | |
| 230 | | | |
| 231 | | | |
| 232 | | | @param |
| 233 | | | @throws |
| 234 | | | |
| 235 | | (3) | public static void main (String[] args) throws IOException |
| 236 | | | { |
| 237 | | | File[] in; |
| 238 | | | File para; |
| 239 | | | |
| 240 | 0 | | if ((args.length < 1) || (args.length > DEBUG_ARG_NUM)) |
| 241 | | | { |
| 242 | | | String msg; |
| 243 | | | |
| 244 | 0 | | msg = "Usage: java " + Chart2DHandlerImpl.class.getName() |
| 245 | | | + " <input file or directory> [context path] [debug]"; |
| 246 | 0 | | log(msg); |
| 247 | 0 | | throw new IllegalArgumentException(msg); |
| 248 | | | } |
| 249 | | | |
| 250 | 0 | | if (args.length == DEBUG_ARG_NUM) |
| 251 | | | { |
| 252 | 0 | | sDebug = true; |
| 253 | | | } |
| 254 | | | |
| 255 | 0 | | File dataRepository = null; |
| 256 | | | |
| 257 | 0 | | if (args.length > 1) |
| 258 | | | { |
| 259 | 0 | (4) | if (args[1].equals("debug")) |
| 260 | | | { |
| 261 | 0 | | sDebug = true; |
| 262 | | | } |
| 263 | | | else |
| 264 | | | { |
| 265 | 0 | | dataRepository = new File(args[1]); |
| 266 | | | } |
| 267 | | | } |
| 268 | | | |
| 269 | 0 | | if (sDebug) |
| 270 | | | { |
| 271 | 0 | | LoggingUtils.setGlobalHandlerLogLevel(Level.ALL); |
| 272 | 0 | | Logger.getLogger("org.jcoderz.phoenix.chart2d").setLevel(Level.ALL); |
| 273 | 0 | | Logger.getLogger("").setLevel(Level.ALL); |
| 274 | | | } |
| 275 | 0 | | para = new File(args[0]); |
| 276 | 0 | | if (para.isFile()) |
| 277 | | | { |
| 278 | 0 | | in = new File[] {para}; |
| 279 | | | } |
| 280 | | | else |
| 281 | | | { |
| 282 | 0 | | final FilenameFilter filter = new FilenameFilter() |
| 283 | 0 | | { |
| 284 | | | public boolean accept (File dir, String name) |
| 285 | | | { |
| 286 | 0 | | return name.endsWith(".xml"); |
| 287 | | | } |
| 288 | | | }; |
| 289 | | | |
| 290 | 0 | | in = para.listFiles(filter); |
| 291 | | | } |
| 292 | | | |
| 293 | 0 | | sMultible = in.length > 1; |
| 294 | | | |
| 295 | 0 | | final Iterator i = Arrays.asList(in).iterator(); |
| 296 | | | |
| 297 | 0 | | while (i.hasNext()) |
| 298 | | | { |
| 299 | 0 | | final File current = (File) i.next(); |
| 300 | | | |
| 301 | 0 | | log("in: " + current.getAbsolutePath()); |
| 302 | | | try |
| 303 | | | { |
| 304 | 0 | | final Chart2DHandlerImpl handler |
| 305 | | | = new Chart2DHandlerImpl(dataRepository); |
| 306 | 0 | | Chart2DHandler theHandler = handler; |
| 307 | 0 | | if (sDebug) |
| 308 | | | { |
| 309 | 0 | | theHandler = (Chart2DHandler) LoggingProxy.getProxy(handler); |
| 310 | | | } |
| 311 | 0 | | Chart2DParser.parse(new InputSource(new FileInputStream(current)), |
| 312 | | | theHandler); |
| 313 | 0 | | handler.writeCache(); |
| 314 | | | } |
| 315 | 0 | | catch (Exception ex) |
| 316 | | | { |
| 317 | 0 | | log("Got exception", ex); |
| 318 | 0 | | } |
| 319 | 0 | | } |
| 320 | | | |
| 321 | 0 | | log("Done."); |
| 322 | 0 | | } |
| 323 | | | |
| 324 | | | |
| 325 | | | {@inheritDoc} |
| 326 | | | public void handleGraphLabelsLinesStyle (final Attributes meta) |
| 327 | | | throws SAXException |
| 328 | | | { |
| 329 | | | |
| 330 | 0 | | } |
| 331 | | | |
| 332 | | | |
| 333 | | | |
| 334 | | | |
| 335 | | | @param |
| 336 | | | @throws |
| 337 | | | |
| 338 | | | public void startCategory (final Attributes meta) throws SAXException |
| 339 | | | { |
| 340 | 0 | | if (mCurrentSet.size() < mCurrentLabelText.size()) |
| 341 | | | { |
| 342 | 0 | | logDebug("startCategory x = " + mCurrentSet.size() + "/" |
| 343 | | | + mCurrentLabelText.get(mCurrentSet.size())); |
| 344 | | | } |
| 345 | 0 | | mCurrentCategory = new ArrayList(); |
| 346 | 0 | | } |
| 347 | | | |
| 348 | | | |
| 349 | | | |
| 350 | | | |
| 351 | | | |
| 352 | | | @throws |
| 353 | | | |
| 354 | | | public void endCategory () throws SAXException |
| 355 | | | { |
| 356 | 0 | | if (mCurrentSet.size() < mCurrentLabelText.size()) |
| 357 | | | { |
| 358 | 0 | | logDebug("endCategory x = " |
| 359 | | | + mCurrentSet.size() + "/" |
| 360 | | | + mCurrentLabelText.get(mCurrentSet.size())); |
| 361 | | | } |
| 362 | 0 | | mCurrentSet.add(mCurrentCategory); |
| 363 | 0 | | mCurrentCategory = null; |
| 364 | 0 | | } |
| 365 | | | |
| 366 | | | |
| 367 | | | |
| 368 | | | @param |
| 369 | | | @throws |
| 370 | | | |
| 371 | | | public void startMultiColorsProperties (final Attributes meta) |
| 372 | | | throws SAXException |
| 373 | | | { |
| 374 | 0 | | final MultiColorsProperties props = new MultiColorsProperties(); |
| 375 | | | |
| 376 | 0 | | props.setMultiColorsPropertiesToDefaults(); |
| 377 | | | |
| 378 | 0 | | setProperties(props, meta); |
| 379 | | | |
| 380 | 0 | | mCurrentMultiColorsProperties = props; |
| 381 | 0 | | mCurrentMultiColors = new ArrayList(); |
| 382 | 0 | | } |
| 383 | | | |
| 384 | | | |
| 385 | | | |
| 386 | | | |
| 387 | | | @throws |
| 388 | | | |
| 389 | | | public void endMultiColorsProperties () throws SAXException |
| 390 | | | { |
| 391 | 0 | | if (!mCurrentMultiColors.isEmpty()) |
| 392 | | | { |
| 393 | 0 | (5) | mCurrentMultiColorsProperties |
| 394 | | | .setColorsCustom((Color[]) mCurrentMultiColors |
| 395 | | | .toArray(new Color[] {})); |
| 396 | | | } |
| 397 | | | |
| 398 | 0 | | mMultiColorsProperties.add(mCurrentMultiColorsProperties); |
| 399 | 0 | | mCurrentMultiColors = null; |
| 400 | 0 | | } |
| 401 | | | |
| 402 | | | |
| 403 | | | |
| 404 | | | |
| 405 | | | @param |
| 406 | | | @throws |
| 407 | | | |
| 408 | | | public void startLBChart2D (final Attributes meta) throws SAXException |
| 409 | | | { |
| 410 | 0 | | mChartType = "LBChart2D"; |
| 411 | 0 | | } |
| 412 | | | |
| 413 | | | {@inheritDoc} |
| 414 | | | public void endLBChart2D () throws SAXException |
| 415 | | | { |
| 416 | | | |
| 417 | 0 | | } |
| 418 | | | |
| 419 | | | |
| 420 | | | |
| 421 | | | |
| 422 | | | {@link } |
| 423 | | | @param |
| 424 | | | @param |
| 425 | | | @throws |
| 426 | | | |
| 427 | | | public void handleLegendLabelsTexts (final String data, |
| 428 | | | final Attributes meta) throws SAXException |
| 429 | | | { |
| 430 | 0 | (6) | if (data.startsWith("!")) |
| 431 | | | { |
| 432 | | | try |
| 433 | | | { |
| 434 | 0 | | final DocumentBuilder builder = getDocumentBuilder(); |
| 435 | 0 | | final Document document = builder.parse( |
| 436 | | | new File(mDataRepository, |
| 437 | | | ((Pair) mXaxis.get(mXaxis.size() - 1)).getFileName())); |
| 438 | 0 | | final NodeIterator i |
| 439 | | | = XPathAPI.selectNodeIterator( |
| 440 | | | document, data.substring(1)); |
| 441 | 0 | | Node node = i.nextNode(); |
| 442 | 0 | | while (node != null) |
| 443 | | | { |
| 444 | 0 | | logDebug("Legend Label: " + node.getNodeValue()); |
| 445 | 0 | | mCurrentLegendLabelsTexts.add(node.getNodeValue()); |
| 446 | 0 | | node = i.nextNode(); |
| 447 | | | } |
| 448 | | | } |
| 449 | 0 | | catch (Exception ex) |
| 450 | | | { |
| 451 | 0 | | final SAXException e = new SAXException(ex); |
| 452 | 0 | | e.initCause(ex); |
| 453 | 0 | | throw e; |
| 454 | 0 | | } |
| 455 | | | } |
| 456 | | | else |
| 457 | | | { |
| 458 | 0 | | mCurrentLegendLabelsTexts.add(data); |
| 459 | | | } |
| 460 | 0 | | } |
| 461 | | | |
| 462 | | | {@inheritDoc} |
| 463 | | | public void startDataset (final Attributes meta) throws SAXException |
| 464 | | | { |
| 465 | 0 | | mDoConvertToStacked = meta.getIndex("DoConvertToStacked") != -1; |
| 466 | 0 | | mCurrentDataSet = new ArrayList(); |
| 467 | 0 | | } |
| 468 | | | |
| 469 | | | |
| 470 | | | |
| 471 | | | |
| 472 | | | @throws |
| 473 | | | |
| 474 | | | public void endDataset () throws SAXException |
| 475 | | | { |
| 476 | 0 | | final int zSize |
| 477 | | | = ((List) ((List) mCurrentDataSet.get(0)).get(0)).size(); |
| 478 | 0 | | final int ySize |
| 479 | | | = ((List) mCurrentDataSet.get(0)).size(); |
| 480 | | | |
| 481 | 0 | | final Dataset dataset = new Dataset(mCurrentDataSet.size(), ySize, zSize); |
| 482 | | | |
| 483 | 0 | | if (!sMultible) |
| 484 | | | { |
| 485 | 0 | | log("Dimension: [" + mCurrentDataSet.size() + "][" |
| 486 | | | + ySize + "][" + zSize + "]"); |
| 487 | | | } |
| 488 | | | |
| 489 | | | Iterator i; |
| 490 | | | Iterator j; |
| 491 | | | Iterator k; |
| 492 | | | int x; |
| 493 | | | int y; |
| 494 | | | int z; |
| 495 | | | |
| 496 | 0 | | x = 0; |
| 497 | 0 | | i = mCurrentDataSet.iterator(); |
| 498 | 0 | | while (i.hasNext()) |
| 499 | | | { |
| 500 | 0 | | y = 0; |
| 501 | 0 | | j = ((List) i.next()).iterator(); |
| 502 | 0 | | while (j.hasNext()) |
| 503 | | | { |
| 504 | 0 | | z = 0; |
| 505 | 0 | | k = ((List) j.next()).iterator(); |
| 506 | 0 | | while (k.hasNext()) |
| 507 | | | { |
| 508 | 0 | | final float f = ((Float) k.next()).floatValue(); |
| 509 | | | |
| 510 | 0 | | if (!sMultible) |
| 511 | | | { |
| 512 | 0 | | log("point[" |
| 513 | | | + x + "/" + mCurrentLegendLabelsTexts.get(x) + "][" |
| 514 | | | + y + "/" + mCurrentLabelText.get(y) + "][" + z |
| 515 | | | + "] = " + f); |
| 516 | | | } |
| 517 | | | |
| 518 | 0 | | dataset.set(x, y, z, f); |
| 519 | 0 | | z++; |
| 520 | 0 | | } |
| 521 | 0 | | y++; |
| 522 | | | } |
| 523 | 0 | | x++; |
| 524 | | | } |
| 525 | 0 | | if (mDoConvertToStacked) |
| 526 | | | { |
| 527 | 0 | | dataset.doConvertToStacked(); |
| 528 | | | } |
| 529 | | | |
| 530 | 0 | | mDataSets.add(dataset); |
| 531 | 0 | | mCurrentDataSet = null; |
| 532 | 0 | | } |
| 533 | | | |
| 534 | | | {@inheritDoc} |
| 535 | | | public void handlePieChart2DProperties (final Attributes meta) |
| 536 | | | throws SAXException |
| 537 | | | { |
| 538 | 0 | | mPieChart2DProperties = new PieChart2DProperties(); |
| 539 | 0 | | mPieChart2DProperties.setPieChart2DPropertiesToDefaults(); |
| 540 | 0 | | setProperties(mPieChart2DProperties, meta); |
| 541 | 0 | | } |
| 542 | | | |
| 543 | | | {@inheritDoc} |
| 544 | | | public void startGraphChart2DProperties (final Attributes meta) |
| 545 | | | throws SAXException |
| 546 | | | { |
| 547 | 0 | | mGraphChart2DProperties = new GraphChart2DProperties(); |
| 548 | 0 | | mGraphChart2DProperties.setGraphChart2DPropertiesToDefaults(); |
| 549 | 0 | | setProperties(mGraphChart2DProperties, meta); |
| 550 | 0 | | mCurrentLabelText = new ArrayList(); |
| 551 | 0 | | } |
| 552 | | | |
| 553 | | | {@inheritDoc} |
| 554 | | | public void endGraphChart2DProperties () throws SAXException |
| 555 | | | { |
| 556 | 0 | | if (!mCurrentLabelText.isEmpty()) |
| 557 | | | { |
| 558 | 0 | (7) | mGraphChart2DProperties |
| 559 | | | .setLabelsAxisLabelsTexts((String[]) mCurrentLabelText |
| 560 | | | .toArray(new String[] {})); |
| 561 | | | } |
| 562 | 0 | | } |
| 563 | | | |
| 564 | | | {@inheritDoc} |
| 565 | | | public void handleAxisLabelText (final java.lang.String data, |
| 566 | | | final Attributes meta) throws SAXException |
| 567 | | | { |
| 568 | 0 | (8) | if (data.startsWith("!")) |
| 569 | | | { |
| 570 | | | |
| 571 | 0 | | final int max = Integer.parseInt(meta.getValue("max")); |
| 572 | | | |
| 573 | 0 | | final int count = Integer.parseInt(meta.getValue("count")); |
| 574 | | | |
| 575 | 0 | | Collection map = fileMatcher(data.substring(1)); |
| 576 | | | |
| 577 | 0 | | int size = map.size(); |
| 578 | 0 | | if (size == 0) |
| 579 | | | { |
| 580 | 0 | | throw new RuntimeException("No files found for pattern " |
| 581 | | | + data + " in " + mDataRepository + "."); |
| 582 | | | } |
| 583 | | | |
| 584 | 0 | | if (size > max * count) |
| 585 | | | { |
| 586 | 0 | | final List newList = new ArrayList(max * count); |
| 587 | 0 | | final Iterator it = map.iterator(); |
| 588 | 0 | | int remove = size - (max * count); |
| 589 | 0 | | while (remove > 0) |
| 590 | | | { |
| 591 | 0 | | it.next(); |
| 592 | 0 | | remove--; |
| 593 | | | } |
| 594 | 0 | | while (it.hasNext()) |
| 595 | | | { |
| 596 | 0 | (9) | newList.add(it.next()); |
| 597 | | | } |
| 598 | 0 | | map = newList; |
| 599 | 0 | | size = map.size(); |
| 600 | | | } |
| 601 | | | |
| 602 | 0 | | mXaxisModulus = Math.max(1, size / count); |
| 603 | 0 | | logDebug("Will have " + mXaxisModulus + " enties per category."); |
| 604 | | | |
| 605 | 0 | | mXaxis.addAll(map); |
| 606 | 0 | | final Iterator i = map.iterator(); |
| 607 | 0 | | int xPos = 0; |
| 608 | 0 | | while (i.hasNext()) |
| 609 | | | { |
| 610 | 0 | | final String label = ((Pair) i.next()).getLabel(); |
| 611 | 0 | | if (xPos % mXaxisModulus == 0) |
| 612 | | | { |
| 613 | 0 | | logDebug("X-Label: " + label); |
| 614 | 0 | | mCurrentLabelText.add(label); |
| 615 | | | } |
| 616 | 0 | | xPos++; |
| 617 | 0 | | } |
| 618 | 0 | | } |
| 619 | | | else |
| 620 | | | { |
| 621 | 0 | | mCurrentLabelText.add(data); |
| 622 | | | } |
| 623 | 0 | | } |
| 624 | | | |
| 625 | | | private List fileMatcher (String filePattern) |
| 626 | | | { |
| 627 | 0 | | final List result = new ArrayList(); |
| 628 | 0 | | final Pattern pattern = Pattern.compile(filePattern); |
| 629 | 0 | | final Iterator i = mFilePatterns.iterator(); |
| 630 | 0 | | while (i.hasNext()) |
| 631 | | | { |
| 632 | 0 | | final String fileName = (String) i.next(); |
| 633 | 0 | | final Matcher m = pattern.matcher(fileName); |
| 634 | 0 | | if (m.matches()) |
| 635 | | | { |
| 636 | 0 | | result.add(new Pair(fileName, m.group(1))); |
| 637 | | | } |
| 638 | 0 | | } |
| 639 | 0 | | return result; |
| 640 | | | } |
| 641 | | | |
| 642 | | | {@inheritDoc} |
| 643 | | | public void startChart2D (final Attributes meta) throws SAXException |
| 644 | | | { |
| 645 | | | String value; |
| 646 | | | |
| 647 | 0 | | value = meta.getValue("Width"); |
| 648 | 0 | | if (value != null) |
| 649 | | | { |
| 650 | 0 | | mWidth = Integer.decode(value).intValue(); |
| 651 | | | } |
| 652 | | | |
| 653 | 0 | | value = meta.getValue("Height"); |
| 654 | 0 | | if (value != null) |
| 655 | | | { |
| 656 | 0 | | mHeight = Integer.decode(value).intValue(); |
| 657 | | | } |
| 658 | | | |
| 659 | 0 | | value = meta.getValue("Type"); |
| 660 | 0 | | if (value != null) |
| 661 | | | { |
| 662 | 0 | | mType = value; |
| 663 | | | } |
| 664 | | | |
| 665 | 0 | | value = meta.getValue("Filename"); |
| 666 | 0 | | if (value != null) |
| 667 | | | { |
| 668 | 0 | | mFilename = value; |
| 669 | | | } |
| 670 | 0 | | } |
| 671 | | | |
| 672 | | | {@inheritDoc} |
| 673 | | | public void endChart2D () throws SAXException |
| 674 | | | { |
| 675 | | | try |
| 676 | | | { |
| 677 | 0 | | Chart2D chart2d = null; |
| 678 | | | |
| 679 | 0 | | if ("PieChart2D".equals(mChartType)) |
| 680 | | | { |
| 681 | 0 | | final PieChart2D chart = new PieChart2D(); |
| 682 | | | |
| 683 | 0 | | chart.setObject2DProperties(mObject2DProperties); |
| 684 | 0 | | chart.setChart2DProperties(mChart2DProperties); |
| 685 | 0 | | chart.setPieChart2DProperties(mPieChart2DProperties); |
| 686 | 0 | | chart.setLegendProperties(mLegendProperties); |
| 687 | 0 | | chart.setDataset((Dataset) mDataSets.get(0)); |
| 688 | 0 | | chart.setMultiColorsProperties( |
| 689 | | | (MultiColorsProperties) mMultiColorsProperties.get(0)); |
| 690 | 0 | | chart2d = chart; |
| 691 | 0 | | } |
| 692 | 0 | | else if ("LLChart2D".equals(mChartType)) |
| 693 | | | { |
| 694 | 0 | | final LLChart2D chart = new LLChart2D(); |
| 695 | 0 | | fillChartData(chart); |
| 696 | 0 | | chart2d = chart; |
| 697 | 0 | | } |
| 698 | 0 | | else if ("LBChart2D".equals(mChartType)) |
| 699 | | | { |
| 700 | 0 | | final LBChart2D chart = new LBChart2D(); |
| 701 | 0 | | fillChartData(chart); |
| 702 | 0 | | chart2d = chart; |
| 703 | 0 | | } |
| 704 | | | else |
| 705 | | | { |
| 706 | 0 | | throw new SAXException("Unknown chart type " + mChartType + "."); |
| 707 | | | } |
| 708 | | | |
| 709 | 0 | | final Dimension size = new Dimension(mWidth, mHeight); |
| 710 | | | |
| 711 | 0 | | chart2d.setMaximumSize(size); |
| 712 | 0 | | chart2d.setPreferredSize(size); |
| 713 | | | |
| 714 | 0 | | if (chart2d.validate(false)) |
| 715 | | | { |
| 716 | 0 | | javax.imageio.ImageIO.write(chart2d.getImage(), mType, new File( |
| 717 | | | mFilename)); |
| 718 | 0 | | log("out: " + new File(mFilename).getAbsolutePath()); |
| 719 | | | } |
| 720 | | | else |
| 721 | | | { |
| 722 | 0 | | chart2d.validate(true); |
| 723 | | | } |
| 724 | | | } |
| 725 | 0 | | catch (Exception ex) |
| 726 | | | { |
| 727 | 0 | | final SAXException e = new SAXException(ex); |
| 728 | 0 | | e.initCause(ex); |
| 729 | 0 | | throw e; |
| 730 | 0 | | } |
| 731 | 0 | | } |
| 732 | | | |
| 733 | | | {@inheritDoc} |
| 734 | | | public void startLLChart2D (final Attributes meta) throws SAXException |
| 735 | | | { |
| 736 | 0 | | mChartType = "LLChart2D"; |
| 737 | 0 | | } |
| 738 | | | |
| 739 | | | {@inheritDoc} |
| 740 | | | public void endLLChart2D () throws SAXException |
| 741 | | | { |
| 742 | | | |
| 743 | 0 | | } |
| 744 | | | |
| 745 | | | {@inheritDoc} |
| 746 | | | public void handleGraphNumbersLinesStyle (final Attributes meta) |
| 747 | | | throws SAXException |
| 748 | | | { |
| 749 | | | |
| 750 | 0 | | } |
| 751 | | | |
| 752 | | | {@inheritDoc} |
| 753 | | (10) | public void handleData (final java.lang.String data, final Attributes meta) |
| 754 | | | throws SAXException |
| 755 | | | { |
| 756 | 0 | (11) | if (data.startsWith("!")) |
| 757 | | | { |
| 758 | | | |
| 759 | 0 | | final Iterator z = mCurrentLegendLabelsTexts.iterator(); |
| 760 | 0 | | while (z.hasNext()) |
| 761 | | | { |
| 762 | 0 | | final String zValue = (String) z.next(); |
| 763 | | | |
| 764 | 0 | | int xPos = 0; |
| 765 | 0 | | final Iterator x = mXaxis.iterator(); |
| 766 | 0 | | while (x.hasNext()) |
| 767 | | | { |
| 768 | 0 | | final Pair pair = (Pair) x.next(); |
| 769 | 0 | | final String fileName = pair.getFileName(); |
| 770 | | | |
| 771 | 0 | | String query = data.substring(1); |
| 772 | 0 | | query = query.replaceAll("\\$z", zValue); |
| 773 | | | |
| 774 | 0 | | String value = resolveXpath(fileName, query); |
| 775 | 0 | | if (value.length() == 0) |
| 776 | | | { |
| 777 | 0 | | value = "0"; |
| 778 | | | } |
| 779 | 0 | | else if (value.indexOf("second") != -1) |
| 780 | | | { |
| 781 | 0 | | value = parseAntTime(value); |
| 782 | | | } |
| 783 | 0 | (12) | mCurrentCategory.add(new Float(Float.parseFloat(value))); |
| 784 | | | |
| 785 | 0 | | xPos++; |
| 786 | 0 | | while (xPos % mXaxisModulus != 0 && !x.hasNext()) |
| 787 | | | { |
| 788 | 0 | | xPos++; |
| 789 | | | |
| 790 | 0 | (13) | mCurrentCategory.add(new Float(Float.parseFloat(value))); |
| 791 | | | } |
| 792 | 0 | | if ((xPos % mXaxisModulus == 0 && x.hasNext()) |
| 793 | | | || (!x.hasNext() && z.hasNext())) |
| 794 | | | { |
| 795 | 0 | | endCategory(); |
| 796 | | | |
| 797 | 0 | | startCategory(null); |
| 798 | | | } |
| 799 | 0 | | } |
| 800 | | | |
| 801 | | | |
| 802 | 0 | | if (z.hasNext()) |
| 803 | | | { |
| 804 | 0 | | endSet(); |
| 805 | 0 | | startSet(null); |
| 806 | 0 | | startCategory(null); |
| 807 | | | } |
| 808 | 0 | | } |
| 809 | 0 | | } |
| 810 | | | else |
| 811 | | | { |
| 812 | 0 | (14) | mCurrentCategory.add(new Float(Float.parseFloat(data))); |
| 813 | | | } |
| 814 | 0 | | } |
| 815 | | | |
| 816 | | | private String parseAntTime (String value) |
| 817 | | | { |
| 818 | 0 | | final Pattern pat = Pattern.compile(TIME_PATTERN); |
| 819 | 0 | | final Matcher mat = pat.matcher(value); |
| 820 | 0 | | logDebug("grops " + value); |
| 821 | 0 | | String result = value; |
| 822 | 0 | | if (mat.matches()) |
| 823 | | | { |
| 824 | 0 | | int minutes = 0; |
| 825 | 0 | | int seconds = 0; |
| 826 | 0 | | if (mat.group(TIME_PATTERN_MINUTES_GROUP) != null) |
| 827 | | | { |
| 828 | 0 | | minutes = Integer.parseInt( |
| 829 | | | mat.group(TIME_PATTERN_MINUTES_GROUP)); |
| 830 | | | } |
| 831 | 0 | | if (mat.group(TIME_PATTERN_SECONDS_GROUP) != null) |
| 832 | | | { |
| 833 | 0 | | seconds = Integer.parseInt( |
| 834 | | | mat.group(TIME_PATTERN_SECONDS_GROUP)); |
| 835 | | | } |
| 836 | 0 | | result = String.valueOf( |
| 837 | | | Date.SECONDS_PER_MINUTE * minutes + seconds); |
| 838 | | | } |
| 839 | 0 | | return result; |
| 840 | | | } |
| 841 | | | |
| 842 | | | private String resolveXpath (String fileName, String xpath) |
| 843 | | | throws SAXException |
| 844 | | | { |
| 845 | 0 | | logDebug(xpath + " in " + fileName); |
| 846 | 0 | | String result = null; |
| 847 | 0 | | final String cacheKey = xpath + "@" + fileName; |
| 848 | 0 | | result = (String) mXpathCache.get(cacheKey); |
| 849 | 0 | | if (result == null) |
| 850 | | | { |
| 851 | | | try |
| 852 | | | { |
| 853 | 0 | | final DocumentBuilder builder = getDocumentBuilder(); |
| 854 | 0 | | final Document document = builder.parse(new File(mDataRepository, |
| 855 | | | fileName)); |
| 856 | 0 | | final XObject object = XPathAPI.eval(document, xpath); |
| 857 | 0 | | result = object.str(); |
| 858 | | | } |
| 859 | 0 | | catch (Exception ex) |
| 860 | | | { |
| 861 | 0 | | final SAXException e = new SAXException(ex); |
| 862 | 0 | | e.initCause(ex); |
| 863 | 0 | | throw e; |
| 864 | 0 | | } |
| 865 | 0 | | logDebug(" = " + result); |
| 866 | 0 | | mXpathCache.put(cacheKey, result); |
| 867 | | | } |
| 868 | | | else |
| 869 | | | { |
| 870 | 0 | | logDebug(" = " + result + " (cached)"); |
| 871 | | | } |
| 872 | 0 | | return result; |
| 873 | | | } |
| 874 | | | |
| 875 | | | {@inheritDoc} |
| 876 | | | public void startPieChart2D (final Attributes meta) throws SAXException |
| 877 | | | { |
| 878 | 0 | | mChartType = "PieChart2D"; |
| 879 | 0 | | } |
| 880 | | | |
| 881 | | | {@inheritDoc} |
| 882 | | | public void endPieChart2D () throws SAXException |
| 883 | | | { |
| 884 | | | |
| 885 | 0 | | } |
| 886 | | | |
| 887 | | | {@inheritDoc} |
| 888 | | | public void handleObject2DProperties (final Attributes meta) |
| 889 | | | throws SAXException |
| 890 | | | { |
| 891 | 0 | | mObject2DProperties = new Object2DProperties(); |
| 892 | 0 | | mObject2DProperties.setObject2DPropertiesToDefaults(); |
| 893 | 0 | | setProperties(mObject2DProperties, meta); |
| 894 | 0 | | } |
| 895 | | | |
| 896 | | | {@inheritDoc} |
| 897 | | | public void handleWarningRegionProperties (final Attributes meta) |
| 898 | | | throws SAXException |
| 899 | | | { |
| 900 | 0 | | final WarningRegionProperties props = new WarningRegionProperties(); |
| 901 | | | |
| 902 | 0 | | props.setToDefaults(); |
| 903 | 0 | | setProperties(props, meta); |
| 904 | 0 | | } |
| 905 | | | |
| 906 | | | {@inheritDoc} |
| 907 | | | public void handleChart2DProperties (final Attributes meta) |
| 908 | | | throws SAXException |
| 909 | | | { |
| 910 | 0 | | mChart2DProperties = new Chart2DProperties(); |
| 911 | 0 | | mChart2DProperties.setChart2DPropertiesToDefaults(); |
| 912 | 0 | | setProperties(mChart2DProperties, meta); |
| 913 | 0 | | } |
| 914 | | | |
| 915 | | | {@inheritDoc} |
| 916 | | | public void startSet (final Attributes meta) throws SAXException |
| 917 | | | { |
| 918 | 0 | | if (mCurrentDataSet.size() < mCurrentLegendLabelsTexts.size()) |
| 919 | | | { |
| 920 | 0 | | logDebug("startSet z = " + mCurrentDataSet.size() + "/" |
| 921 | | | + mCurrentLegendLabelsTexts.get(mCurrentDataSet.size())); |
| 922 | | | } |
| 923 | 0 | | mCurrentSet = new ArrayList(); |
| 924 | 0 | | } |
| 925 | | | |
| 926 | | | {@inheritDoc} |
| 927 | | | public void endSet () throws SAXException |
| 928 | | | { |
| 929 | 0 | | if (mCurrentDataSet.size() < mCurrentLegendLabelsTexts.size()) |
| 930 | | | { |
| 931 | 0 | | logDebug("endSet z = " + mCurrentDataSet.size() + "/" |
| 932 | | | + mCurrentLegendLabelsTexts.get(mCurrentDataSet.size())); |
| 933 | | | } |
| 934 | 0 | | mCurrentDataSet.add(mCurrentSet); |
| 935 | 0 | | mCurrentSet = null; |
| 936 | 0 | | } |
| 937 | | | |
| 938 | | | {@inheritDoc} |
| 939 | | | public void startGraphProperties (final Attributes meta) throws SAXException |
| 940 | | | { |
| 941 | 0 | | final GraphProperties props = new GraphProperties(); |
| 942 | | | |
| 943 | 0 | | props.setGraphPropertiesToDefaults(); |
| 944 | 0 | | setProperties(props, meta); |
| 945 | 0 | | mGraphProperties.add(props); |
| 946 | 0 | | } |
| 947 | | | |
| 948 | | | {@inheritDoc} |
| 949 | | | public void endGraphProperties () throws SAXException |
| 950 | | | { |
| 951 | | | |
| 952 | 0 | | } |
| 953 | | | |
| 954 | | | {@inheritDoc} |
| 955 | | | public void handleColorsCustom (final java.lang.String data, |
| 956 | | | final Attributes meta) throws SAXException |
| 957 | | | { |
| 958 | 0 | | mCurrentMultiColors.add(getColor(data)); |
| 959 | 0 | | } |
| 960 | | | |
| 961 | | | {@inheritDoc} |
| 962 | | | public void startLegendProperties (final Attributes meta) |
| 963 | | | throws SAXException |
| 964 | | | { |
| 965 | 0 | | mLegendProperties = new LegendProperties(); |
| 966 | 0 | | mLegendProperties.setLegendPropertiesToDefaults(); |
| 967 | 0 | | mCurrentLegendLabelsTexts = new ArrayList(); |
| 968 | 0 | | } |
| 969 | | | |
| 970 | | | {@inheritDoc} |
| 971 | | | public void endLegendProperties () throws SAXException |
| 972 | | | { |
| 973 | 0 | | if (!mCurrentLegendLabelsTexts.isEmpty()) |
| 974 | | | { |
| 975 | 0 | (15) | mLegendProperties |
| 976 | | | .setLegendLabelsTexts((String[]) mCurrentLegendLabelsTexts |
| 977 | | | .toArray(new String[] {})); |
| 978 | | | } |
| 979 | 0 | | } |
| 980 | | | |
| 981 | | (16)(17)(18) | private void setProperties (Object props, final Attributes meta) |
| 982 | | | { |
| 983 | 0 | | int i = meta.getLength() - 1; |
| 984 | | | |
| 985 | 0 | | for (; i >= 0; i--) |
| 986 | | | { |
| 987 | 0 | | final String key = meta.getQName(i); |
| 988 | 0 | | final String value = meta.getValue(i); |
| 989 | | | Method m; |
| 990 | 0 | | final String setterName = "set" + key; |
| 991 | | | |
| 992 | | | try |
| 993 | | | { |
| 994 | 0 | | m = props.getClass().getDeclaredMethod(setterName, |
| 995 | | | new Class[] {String.class}); |
| 996 | | | |
| 997 | 0 | | m.invoke(props, new Object[] {value}); |
| 998 | | | } |
| 999 | 0 | | catch (Exception ex) |
| 1000 | | | { |
| 1001 | 0 | | m = null; |
| 1002 | 0 | | } |
| 1003 | | | |
| 1004 | 0 | | if (m == null) |
| 1005 | | | { |
| 1006 | | | try |
| 1007 | | | { |
| 1008 | 0 | | m = props.getClass().getDeclaredMethod(setterName, |
| 1009 | | | new Class[] {Boolean.TYPE}); |
| 1010 | | | |
| 1011 | 0 | | m.invoke(props, new Object[] {Boolean.valueOf(value)}); |
| 1012 | | | } |
| 1013 | 0 | | catch (Exception ex) |
| 1014 | | | { |
| 1015 | 0 | | m = null; |
| 1016 | 0 | | } |
| 1017 | | | } |
| 1018 | | | |
| 1019 | 0 | | if (m == null) |
| 1020 | | | { |
| 1021 | | | try |
| 1022 | | | { |
| 1023 | 0 | | m = props.getClass().getDeclaredMethod(setterName, |
| 1024 | | | new Class[] {Integer.TYPE}); |
| 1025 | | | |
| 1026 | 0 | | m.invoke(props, new Object[] {getInteger(value, props)}); |
| 1027 | | | } |
| 1028 | 0 | | catch (Exception ex) |
| 1029 | | | { |
| 1030 | 0 | | m = null; |
| 1031 | 0 | | } |
| 1032 | | | } |
| 1033 | | | |
| 1034 | 0 | | if (m == null) |
| 1035 | | | { |
| 1036 | | | try |
| 1037 | | | { |
| 1038 | 0 | | m = props.getClass().getDeclaredMethod(setterName, |
| 1039 | | | new Class[] {Color.class}); |
| 1040 | | | |
| 1041 | 0 | | m.invoke(props, new Object[] {getColor(value)}); |
| 1042 | | | } |
| 1043 | 0 | | catch (Exception ex) |
| 1044 | | | { |
| 1045 | 0 | | m = null; |
| 1046 | 0 | | } |
| 1047 | | | } |
| 1048 | | | |
| 1049 | 0 | | if (m == null) |
| 1050 | | | { |
| 1051 | | | try |
| 1052 | | | { |
| 1053 | 0 | | m = props.getClass().getDeclaredMethod(setterName, |
| 1054 | | | new Class[] {Float.TYPE}); |
| 1055 | | | |
| 1056 | 0 | | m.invoke(props, new Object[] {Float.valueOf(value)}); |
| 1057 | | | } |
| 1058 | 0 | | catch (Exception ex) |
| 1059 | | | { |
| 1060 | 0 | | m = null; |
| 1061 | 0 | | } |
| 1062 | | | } |
| 1063 | | | |
| 1064 | 0 | | if (m == null) |
| 1065 | | | { |
| 1066 | | | try |
| 1067 | | | { |
| 1068 | 0 | | m = props.getClass().getDeclaredMethod(setterName, |
| 1069 | | | new Class[] {Dimension.class}); |
| 1070 | | | |
| 1071 | 0 | | m.invoke(props, new Object[] {getDimension(value)}); |
| 1072 | | | } |
| 1073 | 0 | | catch (Exception ex) |
| 1074 | | | { |
| 1075 | 0 | | m = null; |
| 1076 | 0 | | } |
| 1077 | | | } |
| 1078 | | | |
| 1079 | 0 | | if (m == null) |
| 1080 | | | { |
| 1081 | | | try |
| 1082 | | | { |
| 1083 | 0 | | m = props.getClass().getDeclaredMethod(setterName, |
| 1084 | | | new Class[] {java.awt.AlphaComposite.class}); |
| 1085 | | | |
| 1086 | 0 | | m.invoke(props, new Object[] {getAlphaComposite(value, props)}); |
| 1087 | | | } |
| 1088 | 0 | | catch (Exception ex) |
| 1089 | | | { |
| 1090 | 0 | | m = null; |
| 1091 | 0 | | } |
| 1092 | | | } |
| 1093 | | | |
| 1094 | 0 | | if (m == null) |
| 1095 | | | { |
| 1096 | 0 | | log("Could not set " + props.getClass().getName() |
| 1097 | | | + "." + setterName + " = " + value); |
| 1098 | | | } |
| 1099 | | | } |
| 1100 | 0 | | } |
| 1101 | | | |
| 1102 | | | private Color getColor (String col) |
| 1103 | | | { |
| 1104 | 0 | | Color c = null; |
| 1105 | | | |
| 1106 | | | try |
| 1107 | | | { |
| 1108 | | | try |
| 1109 | | | { |
| 1110 | 0 | | c = Color.decode(col); |
| 1111 | | | } |
| 1112 | 0 | | catch (Exception ex) |
| 1113 | | | { |
| 1114 | 0 | | final Field f = Color.class.getField(col); |
| 1115 | 0 | | c = (Color) f.get(null); |
| 1116 | 0 | | } |
| 1117 | | | } |
| 1118 | 0 | | catch (Exception ex) |
| 1119 | | | { |
| 1120 | | | |
| 1121 | 0 | | } |
| 1122 | | | |
| 1123 | 0 | | return c; |
| 1124 | | | } |
| 1125 | | | |
| 1126 | | | private Dimension getDimension (String val) |
| 1127 | | | { |
| 1128 | 0 | | final double w = Double.parseDouble(val.substring(0, val.indexOf('x'))); |
| 1129 | 0 | | final double h = Double.parseDouble(val.substring(1 + val.indexOf('x'))); |
| 1130 | 0 | | final Dimension d = new Dimension(); |
| 1131 | 0 | | d.setSize(w, h); |
| 1132 | 0 | | return d; |
| 1133 | | | } |
| 1134 | | | |
| 1135 | | | private Integer getInteger (String value, Object properties) |
| 1136 | | (19) | throws Exception |
| 1137 | | | { |
| 1138 | | | int i; |
| 1139 | | | |
| 1140 | | | try |
| 1141 | | | { |
| 1142 | 0 | | i = Integer.decode(value).intValue(); |
| 1143 | | | } |
| 1144 | 0 | | catch (Exception ex) |
| 1145 | | | { |
| 1146 | | | try |
| 1147 | | | { |
| 1148 | 0 | | final Field f = properties.getClass().getField(value); |
| 1149 | | | |
| 1150 | 0 | | i = f.getInt(null); |
| 1151 | | | } |
| 1152 | 0 | | catch (Exception exx) |
| 1153 | | | { |
| 1154 | 0 | | final Field f = java.awt.Font.class.getField(value); |
| 1155 | | | |
| 1156 | 0 | | i = f.getInt(null); |
| 1157 | 0 | | } |
| 1158 | 0 | | } |
| 1159 | | | |
| 1160 | 0 | | return new Integer(i); |
| 1161 | | | } |
| 1162 | | | |
| 1163 | | | private AlphaComposite getAlphaComposite (String value, Object properties) |
| 1164 | | (20) | throws Exception |
| 1165 | | | { |
| 1166 | 0 | | AlphaComposite alpha = null; |
| 1167 | | | |
| 1168 | | | try |
| 1169 | | | { |
| 1170 | 0 | | final Field f = properties.getClass().getField( |
| 1171 | | | value.toUpperCase(Constants.SYSTEM_LOCALE)); |
| 1172 | | | |
| 1173 | 0 | | alpha = (AlphaComposite) f.get(null); |
| 1174 | | | } |
| 1175 | 0 | | catch (Exception exx) |
| 1176 | | | { |
| 1177 | | | try |
| 1178 | | | { |
| 1179 | 0 | | final Field f = AlphaComposite.class.getField( |
| 1180 | | | value.toUpperCase(Constants.SYSTEM_LOCALE)); |
| 1181 | 0 | | alpha = AlphaComposite.getInstance(f.getInt(null)); |
| 1182 | | | } |
| 1183 | 0 | | catch (Exception ex) |
| 1184 | | | { |
| 1185 | | | try |
| 1186 | | | { |
| 1187 | 0 | | final Field f = AlphaComposite.class.getField(value); |
| 1188 | | | |
| 1189 | 0 | | alpha = (AlphaComposite) f.get(null); |
| 1190 | | | } |
| 1191 | 0 | | catch (Exception exxx) |
| 1192 | | | { |
| 1193 | | | |
| 1194 | 0 | | } |
| 1195 | 0 | | } |
| 1196 | 0 | | } |
| 1197 | | | |
| 1198 | 0 | | return alpha; |
| 1199 | | | } |
| 1200 | | | |
| 1201 | | | private void fillChartData (final GraphChart2D chart) |
| 1202 | | | { |
| 1203 | 0 | | chart.setObject2DProperties(mObject2DProperties); |
| 1204 | 0 | | chart.setChart2DProperties(mChart2DProperties); |
| 1205 | 0 | | chart.setGraphChart2DProperties(mGraphChart2DProperties); |
| 1206 | 0 | | chart.setLegendProperties(mLegendProperties); |
| 1207 | | | |
| 1208 | 0 | | Iterator i = mDataSets.iterator(); |
| 1209 | 0 | | while (i.hasNext()) |
| 1210 | | | { |
| 1211 | 0 | | chart.addDataset((Dataset) i.next()); |
| 1212 | | | } |
| 1213 | | | |
| 1214 | 0 | | i = mMultiColorsProperties.iterator(); |
| 1215 | 0 | | while (i.hasNext()) |
| 1216 | | | { |
| 1217 | 0 | | chart.addMultiColorsProperties((MultiColorsProperties) i.next()); |
| 1218 | | | } |
| 1219 | | | |
| 1220 | 0 | | i = mGraphProperties.iterator(); |
| 1221 | 0 | | while (i.hasNext()) |
| 1222 | | | { |
| 1223 | 0 | | chart.addGraphProperties((GraphProperties) i.next()); |
| 1224 | | | } |
| 1225 | | | |
| 1226 | 0 | | i = mWarningRegionProperties.iterator(); |
| 1227 | 0 | | while (i.hasNext()) |
| 1228 | | | { |
| 1229 | 0 | | chart.addWarningRegionProperties( |
| 1230 | | | (WarningRegionProperties) i.next()); |
| 1231 | | | } |
| 1232 | 0 | | } |
| 1233 | | | |
| 1234 | | | |
| 1235 | | | |
| 1236 | | | |
| 1237 | | | private void readCache () |
| 1238 | | | { |
| 1239 | 0 | | BufferedReader reader = null; |
| 1240 | | | try |
| 1241 | | | { |
| 1242 | 0 | | final File inFile = new File(mDataRepository, "stat-cache"); |
| 1243 | 0 | | if (inFile.canRead()) |
| 1244 | | | { |
| 1245 | 0 | | reader = new BufferedReader(new FileReader(inFile)); |
| 1246 | 0 | | String line = reader.readLine(); |
| 1247 | 0 | | while (line != null) |
| 1248 | | | { |
| 1249 | 0 | | if (line.length() > 0) |
| 1250 | | | { |
| 1251 | 0 | | final String[] data = line.split("\t"); |
| 1252 | 0 | | if (data.length > 1) |
| 1253 | | | { |
| 1254 | 0 | (21) | mXpathCache.put(data[0], data[1]); |
| 1255 | | | } |
| 1256 | | | else |
| 1257 | | | { |
| 1258 | 0 | | mXpathCache.put(data[0], ""); |
| 1259 | | | } |
| 1260 | 0 | | line = reader.readLine(); |
| 1261 | 0 | | } |
| 1262 | | | } |
| 1263 | | | } |
| 1264 | | | } |
| 1265 | 0 | | catch (IOException ex) |
| 1266 | | | { |
| 1267 | 0 | | throw new RuntimeException("Failed to read cache.", ex); |
| 1268 | | | } |
| 1269 | | | finally |
| 1270 | | | { |
| 1271 | 0 | | IoUtil.close(reader); |
| 1272 | 0 | | } |
| 1273 | 0 | | } |
| 1274 | | | |
| 1275 | | | |
| 1276 | | | |
| 1277 | | | |
| 1278 | | | public void writeCache () |
| 1279 | | | { |
| 1280 | 0 | | if (mDataRepository != null) |
| 1281 | | | { |
| 1282 | 0 | | BufferedWriter writer = null; |
| 1283 | | | try |
| 1284 | | | { |
| 1285 | 0 | | final File file = new File(mDataRepository, "stat-cache"); |
| 1286 | 0 | | writer = new BufferedWriter(new FileWriter(file, false)); |
| 1287 | 0 | | final Iterator i = mXpathCache.entrySet().iterator(); |
| 1288 | 0 | | while (i.hasNext()) |
| 1289 | | | { |
| 1290 | 0 | | final Entry entry = (Entry) i.next(); |
| 1291 | 0 | | writer.write((String) entry.getKey()); |
| 1292 | 0 | | writer.write('\t'); |
| 1293 | 0 | | writer.write((String) entry.getValue()); |
| 1294 | 0 | | writer.write('\n'); |
| 1295 | 0 | | } |
| 1296 | | | } |
| 1297 | 0 | | catch (IOException ex) |
| 1298 | | | { |
| 1299 | 0 | | throw new RuntimeException("Failed to write cache.", ex); |
| 1300 | | | } |
| 1301 | | | finally |
| 1302 | | | { |
| 1303 | 0 | | IoUtil.close(writer); |
| 1304 | 0 | | } |
| 1305 | | | } |
| 1306 | 0 | | } |
| 1307 | | | |
| 1308 | | | |
| 1309 | | | |
| 1310 | | | @param |
| 1311 | | | @param |
| 1312 | | | |
| 1313 | | | private void collectPatterns (File dataRepository, String path) |
| 1314 | | | { |
| 1315 | | | final String thisPath; |
| 1316 | 0 | | if (path == null) |
| 1317 | | | { |
| 1318 | 0 | | thisPath = ""; |
| 1319 | | | } |
| 1320 | | | else |
| 1321 | | | { |
| 1322 | 0 | | thisPath = path + "/" + dataRepository.getName(); |
| 1323 | | | } |
| 1324 | 0 | | if (dataRepository.isFile()) |
| 1325 | | | { |
| 1326 | 0 | | mFilePatterns.add(thisPath); |
| 1327 | | | } |
| 1328 | 0 | | else if (dataRepository.isDirectory()) |
| 1329 | | | { |
| 1330 | 0 | | final File[] sub = dataRepository.listFiles(); |
| 1331 | 0 | | for (int i = 0; i < sub.length; i++) |
| 1332 | | | { |
| 1333 | 0 | | collectPatterns(sub[i], thisPath); |
| 1334 | | | } |
| 1335 | | | } |
| 1336 | 0 | | } |
| 1337 | | | |
| 1338 | | | |
| 1339 | | | private DocumentBuilder getDocumentBuilder () |
| 1340 | | | throws ParserConfigurationException |
| 1341 | | | { |
| 1342 | 0 | | if (mDocumentBuilder == null) |
| 1343 | | | { |
| 1344 | 0 | | mDocumentBuilder = DocumentBuilderFactory.newInstance(). |
| 1345 | | | newDocumentBuilder(); |
| 1346 | | | } |
| 1347 | 0 | | return mDocumentBuilder; |
| 1348 | | | } |
| 1349 | | | |
| 1350 | | | private static void log (String data) |
| 1351 | | | { |
| 1352 | 0 | | System.out.println(data); |
| 1353 | 0 | | } |
| 1354 | | | |
| 1355 | | | private static void log (String data, Throwable thr) |
| 1356 | | | { |
| 1357 | 0 | | System.out.println(data + thr.getMessage()); |
| 1358 | 0 | | thr.printStackTrace(System.out); |
| 1359 | 0 | | } |
| 1360 | | | |
| 1361 | | | |
| 1362 | | | private static void logDebug (String data) |
| 1363 | | | { |
| 1364 | 0 | | if (sDebug) |
| 1365 | | | { |
| 1366 | 0 | | log(data); |
| 1367 | | | } |
| 1368 | 0 | | } |
| 1369 | | | |
| 1370 | | | private static class Pair |
| 1371 | | | { |
| 1372 | | | private final String mFileName; |
| 1373 | | | private final String mLabel; |
| 1374 | | | public Pair (final String fileName, final String label) |
| 1375 | | | { |
| 1376 | 0 | | super(); |
| 1377 | 0 | | mFileName = fileName; |
| 1378 | 0 | | mLabel = label; |
| 1379 | 0 | | } |
| 1380 | | | public String getFileName () |
| 1381 | | | { |
| 1382 | 0 | (22) | return mFileName; |
| 1383 | | | } |
| 1384 | | | public String getLabel () |
| 1385 | | | { |
| 1386 | 0 | | return mLabel; |
| 1387 | | | } |
| 1388 | | | } |
| 1389 | | | } |