1 7 package javax.print.attribute.standard; 8 9 import java.util.HashMap ; 10 import java.util.Vector ; 11 12 import javax.print.attribute.Size2DSyntax ; 13 import javax.print.attribute.Attribute ; 14 15 35 public class MediaSize extends Size2DSyntax implements Attribute { 36 37 private static final long serialVersionUID = -1967958664615414771L; 38 39 private MediaSizeName mediaName; 40 41 private static HashMap mediaMap = new HashMap (100, 10); 42 43 private static Vector sizeVector = new Vector (100, 10); 44 45 59 public MediaSize(float x, float y,int units) { 60 super (x, y, units); 61 if (x > y) { 62 throw new IllegalArgumentException ("X dimension > Y dimension"); 63 } 64 sizeVector.add(this); 65 } 66 67 80 public MediaSize(int x, int y,int units) { 81 super (x, y, units); 82 if (x > y) { 83 throw new IllegalArgumentException ("X dimension > Y dimension"); 84 } 85 sizeVector.add(this); 86 } 87 88 103 public MediaSize(float x, float y,int units, MediaSizeName media) { 104 super (x, y, units); 105 if (x > y) { 106 throw new IllegalArgumentException ("X dimension > Y dimension"); 107 } 108 mediaName = media; 109 mediaMap.put(mediaName, this); 110 sizeVector.add(this); 111 } 112 113 127 public MediaSize(int x, int y,int units, MediaSizeName media) { 128 super (x, y, units); 129 if (x > y) { 130 throw new IllegalArgumentException ("X dimension > Y dimension"); 131 } 132 mediaName = media; 133 mediaMap.put(mediaName, this); 134 sizeVector.add(this); 135 } 136 137 143 public MediaSizeName getMediaSizeName() { 144 return mediaName; 145 } 146 147 154 public static MediaSize getMediaSizeForName(MediaSizeName media) { 155 return (MediaSize )mediaMap.get(media); 156 } 157 158 178 public static MediaSizeName findMedia(float x, float y, int units) { 179 180 MediaSize match = MediaSize.ISO.A4; 181 182 if (x <= 0.0f || y <= 0.0f || units < 1) { 183 throw new IllegalArgumentException ("args must be +ve values"); 184 } 185 186 double ls = x * x + y * y; 187 double tmp_ls; 188 float []dim; 189 float diffx = x; 190 float diffy = y; 191 192 for (int i=0; i < sizeVector.size() ; i++) { 193 MediaSize mediaSize = (MediaSize )sizeVector.elementAt(i); 194 dim = mediaSize.getSize(units); 195 if (x == dim[0] && y == dim[1]) { 196 match = mediaSize; 197 break; 198 } else { 199 diffx = x - dim[0]; 200 diffy = y - dim[1]; 201 tmp_ls = diffx * diffx + diffy * diffy; 202 if (tmp_ls < ls) { 203 ls = tmp_ls; 204 match = mediaSize; 205 } 206 } 207 } 208 209 return match.getMediaSizeName(); 210 } 211 212 234 public boolean equals(Object object) { 235 return (super.equals(object) && object instanceof MediaSize ); 236 } 237 238 248 public final Class <? extends Attribute > getCategory() { 249 return MediaSize .class; 250 } 251 252 261 public final String getName() { 262 return "media-size"; 263 } 264 265 270 public final static class ISO { 271 274 public static final MediaSize 275 A0 = new MediaSize (841, 1189, Size2DSyntax.MM, MediaSizeName.ISO_A0); 276 279 public static final MediaSize 280 A1 = new MediaSize (594, 841, Size2DSyntax.MM, MediaSizeName.ISO_A1); 281 284 public static final MediaSize 285 A2 = new MediaSize (420, 594, Size2DSyntax.MM, MediaSizeName.ISO_A2); 286 289 public static final MediaSize 290 A3 = new MediaSize (297, 420, Size2DSyntax.MM, MediaSizeName.ISO_A3); 291 294 public static final MediaSize 295 A4 = new MediaSize (210, 297, Size2DSyntax.MM, MediaSizeName.ISO_A4); 296 299 public static final MediaSize 300 A5 = new MediaSize (148, 210, Size2DSyntax.MM, MediaSizeName.ISO_A5); 301 304 public static final MediaSize 305 A6 = new MediaSize (105, 148, Size2DSyntax.MM, MediaSizeName.ISO_A6); 306 309 public static final MediaSize 310 A7 = new MediaSize (74, 105, Size2DSyntax.MM, MediaSizeName.ISO_A7); 311 314 public static final MediaSize 315 A8 = new MediaSize (52, 74, Size2DSyntax.MM, MediaSizeName.ISO_A8); 316 319 public static final MediaSize 320 A9 = new MediaSize (37, 52, Size2DSyntax.MM, MediaSizeName.ISO_A9); 321 324 public static final MediaSize 325 A10 = new MediaSize (26, 37, Size2DSyntax.MM, MediaSizeName.ISO_A10); 326 329 public static final MediaSize 330 B0 = new MediaSize (1000, 1414, Size2DSyntax.MM, MediaSizeName.ISO_B0); 331 334 public static final MediaSize 335 B1 = new MediaSize (707, 1000, Size2DSyntax.MM, MediaSizeName.ISO_B1); 336 339 public static final MediaSize 340 B2 = new MediaSize (500, 707, Size2DSyntax.MM, MediaSizeName.ISO_B2); 341 344 public static final MediaSize 345 B3 = new MediaSize (353, 500, Size2DSyntax.MM, MediaSizeName.ISO_B3); 346 349 public static final MediaSize 350 B4 = new MediaSize (250, 353, Size2DSyntax.MM, MediaSizeName.ISO_B4); 351 354 public static final MediaSize 355 B5 = new MediaSize (176, 250, Size2DSyntax.MM, MediaSizeName.ISO_B5); 356 359 public static final MediaSize 360 B6 = new MediaSize (125, 176, Size2DSyntax.MM, MediaSizeName.ISO_B6); 361 364 public static final MediaSize 365 B7 = new MediaSize (88, 125, Size2DSyntax.MM, MediaSizeName.ISO_B7); 366 369 public static final MediaSize 370 B8 = new MediaSize (62, 88, Size2DSyntax.MM, MediaSizeName.ISO_B8); 371 374 public static final MediaSize 375 B9 = new MediaSize (44, 62, Size2DSyntax.MM, MediaSizeName.ISO_B9); 376 379 public static final MediaSize 380 B10 = new MediaSize (31, 44, Size2DSyntax.MM, MediaSizeName.ISO_B10); 381 384 public static final MediaSize 385 C3 = new MediaSize (324, 458, Size2DSyntax.MM, MediaSizeName.ISO_C3); 386 389 public static final MediaSize 390 C4 = new MediaSize (229, 324, Size2DSyntax.MM, MediaSizeName.ISO_C4); 391 394 public static final MediaSize 395 C5 = new MediaSize (162, 229, Size2DSyntax.MM, MediaSizeName.ISO_C5); 396 399 public static final MediaSize 400 C6 = new MediaSize (114, 162, Size2DSyntax.MM, MediaSizeName.ISO_C6); 401 404 public static final MediaSize 405 DESIGNATED_LONG = new MediaSize (110, 220, Size2DSyntax.MM, 406 MediaSizeName.ISO_DESIGNATED_LONG); 407 408 411 private ISO() { 412 } 413 } 414 415 419 public final static class JIS { 420 421 424 public static final MediaSize 425 B0 = new MediaSize (1030, 1456, Size2DSyntax.MM, MediaSizeName.JIS_B0); 426 429 public static final MediaSize 430 B1 = new MediaSize (728, 1030, Size2DSyntax.MM, MediaSizeName.JIS_B1); 431 434 public static final MediaSize 435 B2 = new MediaSize (515, 728, Size2DSyntax.MM, MediaSizeName.JIS_B2); 436 439 public static final MediaSize 440 B3 = new MediaSize (364, 515, Size2DSyntax.MM, MediaSizeName.JIS_B3); 441 444 public static final MediaSize 445 B4 = new MediaSize (257, 364, Size2DSyntax.MM, MediaSizeName.JIS_B4); 446 449 public static final MediaSize 450 B5 = new MediaSize (182, 257, Size2DSyntax.MM, MediaSizeName.JIS_B5); 451 454 public static final MediaSize 455 B6 = new MediaSize (128, 182, Size2DSyntax.MM, MediaSizeName.JIS_B6); 456 459 public static final MediaSize 460 B7 = new MediaSize (91, 128, Size2DSyntax.MM, MediaSizeName.JIS_B7); 461 464 public static final MediaSize 465 B8 = new MediaSize (64, 91, Size2DSyntax.MM, MediaSizeName.JIS_B8); 466 469 public static final MediaSize 470 B9 = new MediaSize (45, 64, Size2DSyntax.MM, MediaSizeName.JIS_B9); 471 474 public static final MediaSize 475 B10 = new MediaSize (32, 45, Size2DSyntax.MM, MediaSizeName.JIS_B10); 476 479 public static final MediaSize CHOU_1 = new MediaSize (142, 332, Size2DSyntax.MM); 480 483 public static final MediaSize CHOU_2 = new MediaSize (119, 277, Size2DSyntax.MM); 484 487 public static final MediaSize CHOU_3 = new MediaSize (120, 235, Size2DSyntax.MM); 488 491 public static final MediaSize CHOU_4 = new MediaSize (90, 205, Size2DSyntax.MM); 492 495 public static final MediaSize CHOU_30 = new MediaSize (92, 235, Size2DSyntax.MM); 496 499 public static final MediaSize CHOU_40 = new MediaSize (90, 225, Size2DSyntax.MM); 500 503 public static final MediaSize KAKU_0 = new MediaSize (287, 382, Size2DSyntax.MM); 504 507 public static final MediaSize KAKU_1 = new MediaSize (270, 382, Size2DSyntax.MM); 508 511 public static final MediaSize KAKU_2 = new MediaSize (240, 332, Size2DSyntax.MM); 512 515 public static final MediaSize KAKU_3 = new MediaSize (216, 277, Size2DSyntax.MM); 516 519 public static final MediaSize KAKU_4 = new MediaSize (197, 267, Size2DSyntax.MM); 520 523 public static final MediaSize KAKU_5 = new MediaSize (190, 240, Size2DSyntax.MM); 524 527 public static final MediaSize KAKU_6 = new MediaSize (162, 229, Size2DSyntax.MM); 528 531 public static final MediaSize KAKU_7 = new MediaSize (142, 205, Size2DSyntax.MM); 532 535 public static final MediaSize KAKU_8 = new MediaSize (119, 197, Size2DSyntax.MM); 536 539 public static final MediaSize KAKU_20 = new MediaSize (229, 324, Size2DSyntax.MM); 540 543 public static final MediaSize KAKU_A4 = new MediaSize (228, 312, Size2DSyntax.MM); 544 547 public static final MediaSize YOU_1 = new MediaSize (120, 176, Size2DSyntax.MM); 548 551 public static final MediaSize YOU_2 = new MediaSize (114, 162, Size2DSyntax.MM); 552 555 public static final MediaSize YOU_3 = new MediaSize (98, 148, Size2DSyntax.MM); 556 559 public static final MediaSize YOU_4 = new MediaSize (105, 235, Size2DSyntax.MM); 560 563 public static final MediaSize YOU_5 = new MediaSize (95, 217, Size2DSyntax.MM); 564 567 public static final MediaSize YOU_6 = new MediaSize (98, 190, Size2DSyntax.MM); 568 571 public static final MediaSize YOU_7 = new MediaSize (92, 165, Size2DSyntax.MM); 572 575 private JIS() { 576 } 577 } 578 579 583 public final static class NA { 584 585 588 public static final MediaSize 589 LETTER = new MediaSize (8.5f, 11.0f, Size2DSyntax.INCH, 590 MediaSizeName.NA_LETTER); 591 594 public static final MediaSize 595 LEGAL = new MediaSize (8.5f, 14.0f, Size2DSyntax.INCH, 596 MediaSizeName.NA_LEGAL); 597 600 public static final MediaSize 601 NA_5X7 = new MediaSize (5, 7, Size2DSyntax.INCH, 602 MediaSizeName.NA_5X7); 603 606 public static final MediaSize 607 NA_8X10 = new MediaSize (8, 10, Size2DSyntax.INCH, 608 MediaSizeName.NA_8X10); 609 613 public static final MediaSize 614 NA_NUMBER_9_ENVELOPE = 615 new MediaSize (3.875f, 8.875f, Size2DSyntax.INCH, 616 MediaSizeName.NA_NUMBER_9_ENVELOPE); 617 621 public static final MediaSize 622 NA_NUMBER_10_ENVELOPE = 623 new MediaSize (4.125f, 9.5f, Size2DSyntax.INCH, 624 MediaSizeName.NA_NUMBER_10_ENVELOPE); 625 629 public static final MediaSize 630 NA_NUMBER_11_ENVELOPE = 631 new MediaSize (4.5f, 10.375f, Size2DSyntax.INCH, 632 MediaSizeName.NA_NUMBER_11_ENVELOPE); 633 637 public static final MediaSize 638 NA_NUMBER_12_ENVELOPE = 639 new MediaSize (4.75f, 11.0f, Size2DSyntax.INCH, 640 MediaSizeName.NA_NUMBER_12_ENVELOPE); 641 645 public static final MediaSize 646 NA_NUMBER_14_ENVELOPE = 647 new MediaSize (5.0f, 11.5f, Size2DSyntax.INCH, 648 MediaSizeName.NA_NUMBER_14_ENVELOPE); 649 650 653 public static final MediaSize 654 NA_6X9_ENVELOPE = new MediaSize (6.0f, 9.0f, Size2DSyntax.INCH, 655 MediaSizeName.NA_6X9_ENVELOPE); 656 659 public static final MediaSize 660 NA_7X9_ENVELOPE = new MediaSize (7.0f, 9.0f, Size2DSyntax.INCH, 661 MediaSizeName.NA_7X9_ENVELOPE); 662 665 public static final MediaSize 666 NA_9x11_ENVELOPE = new MediaSize (9.0f, 11.0f, Size2DSyntax.INCH, 667 MediaSizeName.NA_9X11_ENVELOPE); 668 671 public static final MediaSize 672 NA_9x12_ENVELOPE = new MediaSize (9.0f, 12.0f, Size2DSyntax.INCH, 673 MediaSizeName.NA_9X12_ENVELOPE); 674 677 public static final MediaSize 678 NA_10x13_ENVELOPE = new MediaSize (10.0f, 13.0f, Size2DSyntax.INCH, 679 MediaSizeName.NA_10X13_ENVELOPE); 680 683 public static final MediaSize 684 NA_10x14_ENVELOPE = new MediaSize (10.0f, 14.0f, Size2DSyntax.INCH, 685 MediaSizeName.NA_10X14_ENVELOPE); 686 689 public static final MediaSize 690 NA_10X15_ENVELOPE = new MediaSize (10.0f, 15.0f, Size2DSyntax.INCH, 691 MediaSizeName.NA_10X15_ENVELOPE); 692 695 private NA() { 696 } 697 } 698 699 703 public final static class Engineering { 704 705 708 public static final MediaSize 709 A = new MediaSize (8.5f, 11.0f, Size2DSyntax.INCH, 710 MediaSizeName.A); 711 714 public static final MediaSize 715 B = new MediaSize (11.0f, 17.0f, Size2DSyntax.INCH, 716 MediaSizeName.B); 717 720 public static final MediaSize 721 C = new MediaSize (17.0f, 22.0f, Size2DSyntax.INCH, 722 MediaSizeName.C); 723 726 public static final MediaSize 727 D = new MediaSize (22.0f, 34.0f, Size2DSyntax.INCH, 728 MediaSizeName.D); 729 732 public static final MediaSize 733 E = new MediaSize (34.0f, 44.0f, Size2DSyntax.INCH, 734 MediaSizeName.E); 735 738 private Engineering() { 739 } 740 } 741 742 746 public final static class Other { 747 750 public static final MediaSize 751 EXECUTIVE = new MediaSize (7.25f, 10.5f, Size2DSyntax.INCH, 752 MediaSizeName.EXECUTIVE); 753 756 public static final MediaSize 757 LEDGER = new MediaSize (11.0f, 17.0f, Size2DSyntax.INCH, 758 MediaSizeName.LEDGER); 759 760 763 public static final MediaSize 764 TABLOID = new MediaSize (11.0f, 17.0f, Size2DSyntax.INCH, 765 MediaSizeName.TABLOID); 766 767 770 public static final MediaSize 771 INVOICE = new MediaSize (5.5f, 8.5f, Size2DSyntax.INCH, 772 MediaSizeName.INVOICE); 773 776 public static final MediaSize 777 FOLIO = new MediaSize (8.5f, 13.0f, Size2DSyntax.INCH, 778 MediaSizeName.FOLIO); 779 782 public static final MediaSize 783 QUARTO = new MediaSize (8.5f, 10.83f, Size2DSyntax.INCH, 784 MediaSizeName.QUARTO); 785 788 public static final MediaSize 789 ITALY_ENVELOPE = new MediaSize (110, 230, Size2DSyntax.MM, 790 MediaSizeName.ITALY_ENVELOPE); 791 794 public static final MediaSize 795 MONARCH_ENVELOPE = new MediaSize (3.87f, 7.5f, Size2DSyntax.INCH, 796 MediaSizeName.MONARCH_ENVELOPE); 797 800 public static final MediaSize 801 PERSONAL_ENVELOPE = new MediaSize (3.625f, 6.5f, Size2DSyntax.INCH, 802 MediaSizeName.PERSONAL_ENVELOPE); 803 806 public static final MediaSize 807 JAPANESE_POSTCARD = new MediaSize (100, 148, Size2DSyntax.MM, 808 MediaSizeName.JAPANESE_POSTCARD); 809 812 public static final MediaSize 813 JAPANESE_DOUBLE_POSTCARD = new MediaSize (148, 200, Size2DSyntax.MM, 814 MediaSizeName.JAPANESE_DOUBLE_POSTCARD); 815 818 private Other() { 819 } 820 } 821 822 825 static { 826 MediaSize ISOA4 = ISO.A4; 827 MediaSize JISB5 = JIS.B5; 828 MediaSize NALETTER = NA.LETTER; 829 MediaSize EngineeringC = Engineering.C; 830 MediaSize OtherEXECUTIVE = Other.EXECUTIVE; 831 } 832 } 833 | Popular Tags |