| 1 |
/* |
| 2 |
* DiTAA - Diagrams Through Ascii Art |
| 3 |
* |
| 4 |
* Copyright (C) 2004 Efstathios Sideris |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU General Public License |
| 8 |
* as published by the Free Software Foundation; either version 2 |
| 9 |
* of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
* |
| 20 |
*/ |
| 21 |
package org.stathissideris.ascii2image.text; |
| 22 |
|
| 23 |
import java.util.ArrayList; |
| 24 |
import java.util.Iterator; |
| 25 |
|
| 26 |
/** |
| 27 |
* |
| 28 |
* @author Efstathios Sideris |
| 29 |
*/ |
| 30 |
public class GridPatternGroup extends ArrayList<GridPattern> { |
| 31 |
public boolean areAllMatchedBy(TextGrid grid){ |
| 32 |
Iterator<GridPattern> it = iterator(); |
| 33 |
while (it.hasNext()) { |
| 34 |
GridPattern pattern = it.next(); |
| 35 |
if(!pattern.isMatchedBy(grid)) return false; |
| 36 |
} |
| 37 |
return true; |
| 38 |
} |
| 39 |
|
| 40 |
public boolean isAnyMatchedBy(TextGrid grid){ |
| 41 |
Iterator<GridPattern> it = iterator(); |
| 42 |
while (it.hasNext()) { |
| 43 |
GridPattern pattern = it.next(); |
| 44 |
if(pattern.isMatchedBy(grid)) return true; |
| 45 |
} |
| 46 |
return false; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
public void add(GridPattern... patterns) { |
| 51 |
for(GridPattern p : patterns) add(p); |
| 52 |
} |
| 53 |
|
| 54 |
//TODO: define criteria for on-line type? |
| 55 |
|
| 56 |
public static final GridPatternGroup cornerCriteria = new GridPatternGroup(); |
| 57 |
public static final GridPatternGroup normalCornerCriteria = new GridPatternGroup(); |
| 58 |
public static final GridPatternGroup roundCornerCriteria = new GridPatternGroup(); |
| 59 |
|
| 60 |
public static final GridPatternGroup corner1Criteria = new GridPatternGroup(); |
| 61 |
public static final GridPatternGroup corner2Criteria = new GridPatternGroup(); |
| 62 |
public static final GridPatternGroup corner3Criteria = new GridPatternGroup(); |
| 63 |
public static final GridPatternGroup corner4Criteria = new GridPatternGroup(); |
| 64 |
|
| 65 |
|
| 66 |
public static final GridPatternGroup normalCorner1Criteria = new GridPatternGroup(); |
| 67 |
public static final GridPatternGroup normalCorner2Criteria = new GridPatternGroup(); |
| 68 |
public static final GridPatternGroup normalCorner3Criteria = new GridPatternGroup(); |
| 69 |
public static final GridPatternGroup normalCorner4Criteria = new GridPatternGroup(); |
| 70 |
|
| 71 |
public static final GridPatternGroup roundCorner1Criteria = new GridPatternGroup(); |
| 72 |
public static final GridPatternGroup roundCorner2Criteria = new GridPatternGroup(); |
| 73 |
public static final GridPatternGroup roundCorner3Criteria = new GridPatternGroup(); |
| 74 |
public static final GridPatternGroup roundCorner4Criteria = new GridPatternGroup(); |
| 75 |
|
| 76 |
public static final GridPatternGroup intersectionCriteria = new GridPatternGroup(); |
| 77 |
public static final GridPatternGroup TCriteria = new GridPatternGroup(); |
| 78 |
public static final GridPatternGroup inverseTCriteria = new GridPatternGroup(); |
| 79 |
public static final GridPatternGroup KCriteria = new GridPatternGroup(); |
| 80 |
public static final GridPatternGroup inverseKCriteria = new GridPatternGroup(); |
| 81 |
|
| 82 |
public static final GridPatternGroup crossCriteria = new GridPatternGroup(); |
| 83 |
|
| 84 |
public static final GridPatternGroup stubCriteria = new GridPatternGroup(); |
| 85 |
public static final GridPatternGroup verticalLinesEndCriteria = new GridPatternGroup(); |
| 86 |
public static final GridPatternGroup horizontalLinesEndCriteria = new GridPatternGroup(); |
| 87 |
public static final GridPatternGroup linesEndCriteria = new GridPatternGroup(); |
| 88 |
|
| 89 |
public static final GridPatternGroup crossOnLineCriteria = new GridPatternGroup(); |
| 90 |
public static final GridPatternGroup horizontalCrossOnLineCriteria = new GridPatternGroup(); |
| 91 |
public static final GridPatternGroup verticalCrossOnLineCriteria = new GridPatternGroup(); |
| 92 |
|
| 93 |
public static final GridPatternGroup starOnLineCriteria = new GridPatternGroup(); |
| 94 |
public static final GridPatternGroup horizontalStarOnLineCriteria = new GridPatternGroup(); |
| 95 |
public static final GridPatternGroup verticalStarOnLineCriteria = new GridPatternGroup(); |
| 96 |
|
| 97 |
public static final GridPatternGroup loneDiagonalCriteria = new GridPatternGroup(); |
| 98 |
|
| 99 |
static { |
| 100 |
GridPattern crossPattern1 = new GridPattern( |
| 101 |
".6.", |
| 102 |
"4+8", |
| 103 |
".2." |
| 104 |
); |
| 105 |
crossCriteria.add(crossPattern1); |
| 106 |
|
| 107 |
GridPattern KPattern1 = new GridPattern( |
| 108 |
".6.", |
| 109 |
"%4+8", |
| 110 |
".2." |
| 111 |
); |
| 112 |
KCriteria.add(KPattern1); |
| 113 |
|
| 114 |
GridPattern inverseKPattern1 = new GridPattern( |
| 115 |
".6.", |
| 116 |
"4+%8", |
| 117 |
".2." |
| 118 |
); |
| 119 |
inverseKCriteria.add(inverseKPattern1); |
| 120 |
|
| 121 |
GridPattern TPattern1 = new GridPattern( |
| 122 |
".%6.", |
| 123 |
"4+8", |
| 124 |
".2." |
| 125 |
); |
| 126 |
TCriteria.add(TPattern1); |
| 127 |
|
| 128 |
GridPattern inverseTPattern1 = new GridPattern( |
| 129 |
".6.", |
| 130 |
"4+8", |
| 131 |
".%2." |
| 132 |
); |
| 133 |
inverseTCriteria.add(inverseTPattern1); |
| 134 |
|
| 135 |
|
| 136 |
// ****** normal corners ******* |
| 137 |
|
| 138 |
GridPattern normalCorner1Pattern1 = new GridPattern( |
| 139 |
".[.", |
| 140 |
"~+(", |
| 141 |
".^." |
| 142 |
); |
| 143 |
normalCorner1Criteria.add(normalCorner1Pattern1); |
| 144 |
|
| 145 |
GridPattern normalCorner2Pattern1 = new GridPattern( |
| 146 |
".[.", |
| 147 |
"(+~", |
| 148 |
".^." |
| 149 |
); |
| 150 |
normalCorner2Criteria.add(normalCorner2Pattern1); |
| 151 |
|
| 152 |
GridPattern normalCorner3Pattern1 = new GridPattern( |
| 153 |
".^.", |
| 154 |
"(+~", |
| 155 |
".[." |
| 156 |
); |
| 157 |
normalCorner3Criteria.add(normalCorner3Pattern1); |
| 158 |
|
| 159 |
GridPattern normalCorner4Pattern1 = new GridPattern( |
| 160 |
".^.", |
| 161 |
"~+(", |
| 162 |
".[." |
| 163 |
); |
| 164 |
normalCorner4Criteria.add(normalCorner4Pattern1); |
| 165 |
|
| 166 |
// ******* round corners ******* |
| 167 |
|
| 168 |
GridPattern roundCorner1Pattern1 = new GridPattern( |
| 169 |
".[.", |
| 170 |
"~/4", |
| 171 |
".2." |
| 172 |
); |
| 173 |
roundCorner1Criteria.add(roundCorner1Pattern1); |
| 174 |
|
| 175 |
GridPattern roundCorner2Pattern1 = new GridPattern( |
| 176 |
".[.", |
| 177 |
"4\\~", |
| 178 |
".2." |
| 179 |
); |
| 180 |
roundCorner2Criteria.add(roundCorner2Pattern1); |
| 181 |
|
| 182 |
GridPattern roundCorner3Pattern1 = new GridPattern( |
| 183 |
".6.", |
| 184 |
"4/~", |
| 185 |
".[." |
| 186 |
); |
| 187 |
roundCorner3Criteria.add(roundCorner3Pattern1); |
| 188 |
|
| 189 |
GridPattern roundCorner4Pattern1 = new GridPattern( |
| 190 |
".6.", |
| 191 |
"~\\8", |
| 192 |
".[." |
| 193 |
); |
| 194 |
roundCorner4Criteria.add(roundCorner4Pattern1); |
| 195 |
|
| 196 |
//stubs |
| 197 |
|
| 198 |
GridPattern stubPattern1 = new GridPattern( |
| 199 |
"!^!", |
| 200 |
"!+!", |
| 201 |
".!." |
| 202 |
); |
| 203 |
stubCriteria.add(stubPattern1); |
| 204 |
|
| 205 |
GridPattern stubPattern2 = new GridPattern( |
| 206 |
"!^!", |
| 207 |
"!+!", |
| 208 |
".-." |
| 209 |
); |
| 210 |
stubCriteria.add(stubPattern2); |
| 211 |
|
| 212 |
GridPattern stubPattern3 = new GridPattern( |
| 213 |
"!!.", |
| 214 |
"(+!", |
| 215 |
"!!." |
| 216 |
); |
| 217 |
stubCriteria.add(stubPattern3); |
| 218 |
|
| 219 |
GridPattern stubPattern4 = new GridPattern( |
| 220 |
"!!.", |
| 221 |
"(+|", |
| 222 |
"!!." |
| 223 |
); |
| 224 |
stubCriteria.add(stubPattern4); |
| 225 |
|
| 226 |
GridPattern stubPattern5 = new GridPattern( |
| 227 |
".!.", |
| 228 |
"!+!", |
| 229 |
"!^!" |
| 230 |
); |
| 231 |
stubCriteria.add(stubPattern5); |
| 232 |
|
| 233 |
GridPattern stubPattern6 = new GridPattern( |
| 234 |
".-.", |
| 235 |
"!+!", |
| 236 |
"!^!" |
| 237 |
); |
| 238 |
stubCriteria.add(stubPattern6); |
| 239 |
|
| 240 |
GridPattern stubPattern7 = new GridPattern( |
| 241 |
".!!", |
| 242 |
"!+(", |
| 243 |
".!!" |
| 244 |
); |
| 245 |
stubCriteria.add(stubPattern7); |
| 246 |
|
| 247 |
GridPattern stubPattern8 = new GridPattern( |
| 248 |
".!!", |
| 249 |
"|+(", |
| 250 |
".!!" |
| 251 |
); |
| 252 |
stubCriteria.add(stubPattern8); |
| 253 |
|
| 254 |
|
| 255 |
// ****** ends of lines ****** |
| 256 |
GridPattern verticalLinesEndPattern1 = new GridPattern( |
| 257 |
".^.", |
| 258 |
".|.", |
| 259 |
".!." |
| 260 |
); |
| 261 |
verticalLinesEndCriteria.add(verticalLinesEndPattern1); |
| 262 |
|
| 263 |
GridPattern verticalLinesEndPattern2 = new GridPattern( |
| 264 |
".^.", |
| 265 |
".|.", |
| 266 |
".-." |
| 267 |
); |
| 268 |
verticalLinesEndCriteria.add(verticalLinesEndPattern2); |
| 269 |
|
| 270 |
GridPattern horizontalLinesEndPattern3 = new GridPattern( |
| 271 |
"...", |
| 272 |
"(-!", |
| 273 |
"..." |
| 274 |
); |
| 275 |
horizontalLinesEndCriteria.add(horizontalLinesEndPattern3); |
| 276 |
|
| 277 |
GridPattern horizontalLinesEndPattern4 = new GridPattern( |
| 278 |
"...", |
| 279 |
"(-|", |
| 280 |
"..." |
| 281 |
); |
| 282 |
horizontalLinesEndCriteria.add(horizontalLinesEndPattern4); |
| 283 |
|
| 284 |
GridPattern verticalLinesEndPattern5 = new GridPattern( |
| 285 |
".!.", |
| 286 |
".|.", |
| 287 |
".^." |
| 288 |
); |
| 289 |
verticalLinesEndCriteria.add(verticalLinesEndPattern5); |
| 290 |
|
| 291 |
GridPattern verticalLinesEndPattern6 = new GridPattern( |
| 292 |
".-.", |
| 293 |
".|.", |
| 294 |
".^." |
| 295 |
); |
| 296 |
verticalLinesEndCriteria.add(verticalLinesEndPattern6); |
| 297 |
|
| 298 |
GridPattern horizontalLinesEndPattern7 = new GridPattern( |
| 299 |
"...", |
| 300 |
"!-(", |
| 301 |
"..." |
| 302 |
); |
| 303 |
horizontalLinesEndCriteria.add(horizontalLinesEndPattern7); |
| 304 |
|
| 305 |
GridPattern horizontalLinesEndPattern8 = new GridPattern( |
| 306 |
"...", |
| 307 |
"|-(", |
| 308 |
"..." |
| 309 |
); |
| 310 |
horizontalLinesEndCriteria.add(horizontalLinesEndPattern8); |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
// ****** others ******* |
| 315 |
|
| 316 |
GridPattern horizontalCrossOnLinePattern1 = new GridPattern( |
| 317 |
"...", |
| 318 |
"(+(", |
| 319 |
"..." |
| 320 |
); |
| 321 |
horizontalCrossOnLineCriteria.add(horizontalCrossOnLinePattern1); |
| 322 |
|
| 323 |
GridPattern verticalCrossOnLinePattern1 = new GridPattern( |
| 324 |
".^.", |
| 325 |
".+.", |
| 326 |
".^." |
| 327 |
); |
| 328 |
verticalCrossOnLineCriteria.add(verticalCrossOnLinePattern1); |
| 329 |
|
| 330 |
|
| 331 |
GridPattern horizontalStarOnLinePattern1 = new GridPattern( |
| 332 |
"...", |
| 333 |
"(*(", |
| 334 |
"..." |
| 335 |
); |
| 336 |
horizontalStarOnLineCriteria.add(horizontalStarOnLinePattern1); |
| 337 |
|
| 338 |
GridPattern horizontalStarOnLinePattern2 = new GridPattern( |
| 339 |
"...", |
| 340 |
"!*(", |
| 341 |
"..." |
| 342 |
); |
| 343 |
horizontalStarOnLineCriteria.add(horizontalStarOnLinePattern2); |
| 344 |
|
| 345 |
GridPattern horizontalStarOnLinePattern3 = new GridPattern( |
| 346 |
"...", |
| 347 |
"(*!", |
| 348 |
"..." |
| 349 |
); |
| 350 |
horizontalStarOnLineCriteria.add(horizontalStarOnLinePattern3); |
| 351 |
|
| 352 |
|
| 353 |
GridPattern verticalStarOnLinePattern1 = new GridPattern( |
| 354 |
".^.", |
| 355 |
".*.", |
| 356 |
".^." |
| 357 |
); |
| 358 |
verticalStarOnLineCriteria.add(verticalStarOnLinePattern1); |
| 359 |
|
| 360 |
GridPattern verticalStarOnLinePattern2 = new GridPattern( |
| 361 |
".!.", |
| 362 |
".*.", |
| 363 |
".^." |
| 364 |
); |
| 365 |
verticalStarOnLineCriteria.add(verticalStarOnLinePattern2); |
| 366 |
|
| 367 |
GridPattern verticalStarOnLinePattern3 = new GridPattern( |
| 368 |
".^.", |
| 369 |
".*.", |
| 370 |
".!." |
| 371 |
); |
| 372 |
verticalStarOnLineCriteria.add(verticalStarOnLinePattern3); |
| 373 |
|
| 374 |
|
| 375 |
GridPattern loneDiagonalPattern1 = new GridPattern( |
| 376 |
".%6%7", |
| 377 |
"%4/%8", |
| 378 |
"%3%2." |
| 379 |
); |
| 380 |
loneDiagonalCriteria.add(loneDiagonalPattern1); |
| 381 |
|
| 382 |
GridPattern loneDiagonalPattern2 = new GridPattern( |
| 383 |
"%1%6.", |
| 384 |
"%4\\%8", |
| 385 |
".%2%5" |
| 386 |
); |
| 387 |
loneDiagonalCriteria.add(loneDiagonalPattern2); |
| 388 |
|
| 389 |
|
| 390 |
//groups |
| 391 |
|
| 392 |
intersectionCriteria.addAll(crossCriteria); |
| 393 |
intersectionCriteria.addAll(KCriteria); |
| 394 |
intersectionCriteria.addAll(TCriteria); |
| 395 |
intersectionCriteria.addAll(inverseKCriteria); |
| 396 |
intersectionCriteria.addAll(inverseTCriteria); |
| 397 |
|
| 398 |
normalCornerCriteria.addAll(normalCorner1Criteria); |
| 399 |
normalCornerCriteria.addAll(normalCorner2Criteria); |
| 400 |
normalCornerCriteria.addAll(normalCorner3Criteria); |
| 401 |
normalCornerCriteria.addAll(normalCorner4Criteria); |
| 402 |
|
| 403 |
roundCornerCriteria.addAll(roundCorner1Criteria); |
| 404 |
roundCornerCriteria.addAll(roundCorner2Criteria); |
| 405 |
roundCornerCriteria.addAll(roundCorner3Criteria); |
| 406 |
roundCornerCriteria.addAll(roundCorner4Criteria); |
| 407 |
|
| 408 |
corner1Criteria.addAll(normalCorner1Criteria); |
| 409 |
corner1Criteria.addAll(roundCorner1Criteria); |
| 410 |
|
| 411 |
corner2Criteria.addAll(normalCorner2Criteria); |
| 412 |
corner2Criteria.addAll(roundCorner2Criteria); |
| 413 |
|
| 414 |
corner3Criteria.addAll(normalCorner3Criteria); |
| 415 |
corner3Criteria.addAll(roundCorner3Criteria); |
| 416 |
|
| 417 |
corner4Criteria.addAll(normalCorner4Criteria); |
| 418 |
corner4Criteria.addAll(roundCorner4Criteria); |
| 419 |
|
| 420 |
cornerCriteria.addAll(normalCornerCriteria); |
| 421 |
cornerCriteria.addAll(roundCornerCriteria); |
| 422 |
|
| 423 |
crossOnLineCriteria.addAll(horizontalCrossOnLineCriteria); |
| 424 |
crossOnLineCriteria.addAll(verticalCrossOnLineCriteria); |
| 425 |
|
| 426 |
starOnLineCriteria.addAll(horizontalStarOnLineCriteria); |
| 427 |
starOnLineCriteria.addAll(verticalStarOnLineCriteria); |
| 428 |
|
| 429 |
|
| 430 |
linesEndCriteria.addAll(horizontalLinesEndCriteria); |
| 431 |
linesEndCriteria.addAll(verticalLinesEndCriteria); |
| 432 |
linesEndCriteria.addAll(stubCriteria); |
| 433 |
|
| 434 |
} |
| 435 |
} |