1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45:
46:
65: public class MediaSize extends Size2DSyntax
66: implements Attribute
67: {
68: private static final long serialVersionUID = -1967958664615414771L;
69:
70: private static ArrayList<MediaSize> mediaCache;
71:
72: static
73: {
74: mediaCache = new ArrayList<MediaSize>();
75:
76:
77:
78:
79:
80:
81:
82:
83: MediaSize tmp = MediaSize.ISO.A0;
84: tmp = MediaSize.JIS.B0;
85: tmp = MediaSize.Engineering.A;
86: tmp = MediaSize.NA.LEGAL;
87: tmp = MediaSize.Other.EXECUTIVE;
88: }
89:
90: private MediaSizeName mediaName;
91:
92:
106: public MediaSize(float x, float y, int units)
107: {
108: super(x, y, units);
109: mediaCache.add(this);
110: }
111:
112:
128: public MediaSize(float x, float y, int units, MediaSizeName media)
129: {
130: super(x, y, units);
131: mediaName = media;
132: mediaCache.add(this);
133: }
134:
135:
149: public MediaSize(int x, int y, int units)
150: {
151: super(x, y, units);
152: mediaCache.add(this);
153: }
154:
155:
171: public MediaSize(int x, int y, int units, MediaSizeName media)
172: {
173: super(x, y, units);
174: mediaName = media;
175: mediaCache.add(this);
176: }
177:
178:
183: public Class< ? extends Attribute> getCategory()
184: {
185: return MediaSize.class;
186: }
187:
188:
189:
200: public static MediaSizeName findMedia(float x, float y, int units)
201: {
202: if (x <= 0.0f || y <= 0.0f)
203: throw new IllegalArgumentException(
204: "x and/or y may not be less or equal 0");
205:
206: if (units < 1)
207: throw new IllegalArgumentException("units may not be less then 1");
208:
209: MediaSize bestMatch = null;
210: int bestDistance = Integer.MAX_VALUE;
211:
212: int xMicro = (int) x * units;
213: int yMicro = (int) y * units;
214:
215: for (int i = 0; i < mediaCache.size(); i++)
216: {
217: MediaSize size = (MediaSize) mediaCache.get(i);
218: int dist = (Math.abs(size.getXMicrometers() - xMicro)
219: + Math.abs(size.getYMicrometers() - yMicro));
220:
221: if (dist < bestDistance)
222: {
223: bestMatch = size;
224: bestDistance = dist;
225: }
226: }
227:
228: return bestMatch.getMediaSizeName();
229: }
230:
231:
239: public static MediaSize getMediaSizeForName(MediaSizeName media)
240: {
241: for (int i = 0; i < mediaCache.size(); i++)
242: {
243: MediaSize size = (MediaSize) mediaCache.get(i);
244:
245: if (size.getMediaSizeName().equals(media))
246: return size;
247: }
248:
249: return null;
250: }
251:
252:
260: public boolean equals(Object obj)
261: {
262: if (!(obj instanceof MediaSize))
263: return false;
264:
265: MediaSize tmp = (MediaSize) obj;
266: return (tmp.getXMicrometers() == this.getXMicrometers()
267: && tmp.getYMicrometers() == this.getYMicrometers());
268: }
269:
270:
275: public MediaSizeName getMediaSizeName()
276: {
277: return mediaName;
278: }
279:
280:
285: public final String getName()
286: {
287: return "media-size";
288: }
289:
290:
295: public static final class ISO
296: {
297: private ISO()
298: {
299:
300: }
301:
302:
305: public static final MediaSize A0 = new MediaSize(841, 1189,
306: MediaSize.MM,
307: MediaSizeName.ISO_A0);
308:
309:
312: public static final MediaSize A1 = new MediaSize(594, 841, MediaSize.MM,
313: MediaSizeName.ISO_A1);
314:
315:
318: public static final MediaSize A2 = new MediaSize(420, 594, MediaSize.MM, MediaSizeName.ISO_A2);
319:
320:
323: public static final MediaSize A3 = new MediaSize(297, 420, MediaSize.MM, MediaSizeName.ISO_A3);
324:
325:
328: public static final MediaSize A4 = new MediaSize(210, 297, MediaSize.MM, MediaSizeName.ISO_A4);
329:
330:
333: public static final MediaSize A5 = new MediaSize(148, 210, MediaSize.MM, MediaSizeName.ISO_A5);
334:
335:
338: public static final MediaSize A6 = new MediaSize(105, 148, MediaSize.MM, MediaSizeName.ISO_A6);
339:
340:
343: public static final MediaSize A7 = new MediaSize(74, 105, MediaSize.MM, MediaSizeName.ISO_A7);
344:
345:
348: public static final MediaSize A8 = new MediaSize(52, 74, MediaSize.MM, MediaSizeName.ISO_A8);
349:
350:
353: public static final MediaSize A9 = new MediaSize(37, 52, MediaSize.MM, MediaSizeName.ISO_A9);
354:
355:
358: public static final MediaSize A10 = new MediaSize(26, 37, MediaSize.MM, MediaSizeName.ISO_A10);
359:
360:
361:
364: public static final MediaSize B0 = new MediaSize(1000, 1414, MediaSize.MM, MediaSizeName.ISO_B0);
365:
366:
369: public static final MediaSize B1 = new MediaSize(707, 1000, MediaSize.MM, MediaSizeName.ISO_B1);
370:
371:
374: public static final MediaSize B2 = new MediaSize(500, 707, MediaSize.MM, MediaSizeName.ISO_B2);
375:
376:
379: public static final MediaSize B3 = new MediaSize(353, 500, MediaSize.MM, MediaSizeName.ISO_B3);
380:
381:
384: public static final MediaSize B4 = new MediaSize(250, 353, MediaSize.MM, MediaSizeName.ISO_B4);
385:
386:
389: public static final MediaSize B5 = new MediaSize(176, 250, MediaSize.MM, MediaSizeName.ISO_B5);
390:
391:
394: public static final MediaSize B6 = new MediaSize(125, 176, MediaSize.MM, MediaSizeName.ISO_B6);
395:
396:
399: public static final MediaSize B7 = new MediaSize(88, 125, MediaSize.MM, MediaSizeName.ISO_B7);
400:
401:
404: public static final MediaSize B8 = new MediaSize(62, 88, MediaSize.MM, MediaSizeName.ISO_B8);
405:
406:
409: public static final MediaSize B9 = new MediaSize(44, 62, MediaSize.MM, MediaSizeName.ISO_B9);
410:
411:
414: public static final MediaSize B10 = new MediaSize(31, 44, MediaSize.MM, MediaSizeName.ISO_B10);
415:
416:
419: public static final MediaSize C3 = new MediaSize(324, 458, MediaSize.MM, MediaSizeName.ISO_C3);
420:
421:
424: public static final MediaSize C4 = new MediaSize(229, 324, MediaSize.MM, MediaSizeName.ISO_C4);
425:
426:
429: public static final MediaSize C5 = new MediaSize(162, 229, MediaSize.MM, MediaSizeName.ISO_C5);
430:
431:
434: public static final MediaSize C6 = new MediaSize(114, 162, MediaSize.MM, MediaSizeName.ISO_C6);
435:
436:
439: public static final MediaSize DESIGNATED_LONG =
440: new MediaSize(324, 458, MediaSize.MM, MediaSizeName.ISO_DESIGNATED_LONG);
441: }
442:
443:
448: public static final class NA
449: {
450: private NA()
451: {
452:
453: }
454:
455:
458: public static final MediaSize LEGAL = new MediaSize(8.5f, 14f, MediaSize.INCH,
459: MediaSizeName.NA_LEGAL);
460:
461:
464: public static final MediaSize LETTER = new MediaSize(8.5f, 11f, MediaSize.INCH,
465: MediaSizeName.NA_LETTER);
466:
467:
470: public static final MediaSize NA_5X7 = new MediaSize(5, 7, MediaSize.INCH,
471: MediaSizeName.NA_5X7);
472:
473:
476: public static final MediaSize NA_8X10 = new MediaSize(8, 10, MediaSize.INCH,
477: MediaSizeName.NA_8X10);
478:
479:
482: public static final MediaSize NA_6X9_ENVELOPE = new MediaSize(6f, 9f,
483: MediaSize.INCH,
484: MediaSizeName.NA_6X9_ENVELOPE);
485:
486:
489: public static final MediaSize NA_7X9_ENVELOPE = new MediaSize(7f, 9f,
490: MediaSize.INCH,
491: MediaSizeName.NA_7X9_ENVELOPE);
492:
493:
496: public static final MediaSize NA_9x11_ENVELOPE = new MediaSize(9f, 11f,
497: MediaSize.INCH,
498: MediaSizeName.NA_9X11_ENVELOPE);
499:
500:
503: public static final MediaSize NA_9x12_ENVELOPE = new MediaSize(9f, 12f,
504: MediaSize.INCH,
505: MediaSizeName.NA_9X12_ENVELOPE);
506:
507:
508:
511: public static final MediaSize NA_10x13_ENVELOPE = new MediaSize(10f, 13f,
512: MediaSize.INCH,
513: MediaSizeName.NA_10X13_ENVELOPE);
514:
515:
518: public static final MediaSize NA_10x14_ENVELOPE = new MediaSize(10f, 14f,
519: MediaSize.INCH,
520: MediaSizeName.NA_10X14_ENVELOPE);
521:
522:
525: public static final MediaSize NA_10X15_ENVELOPE = new MediaSize(10f, 15f,
526: MediaSize.INCH,
527: MediaSizeName.NA_10X15_ENVELOPE);
528:
529:
532: public static final MediaSize NA_NUMBER_9_ENVELOPE = new MediaSize(3.875f, 8.875f,
533: MediaSize.INCH,
534: MediaSizeName.NA_NUMBER_9_ENVELOPE);
535:
536:
539: public static final MediaSize NA_NUMBER_10_ENVELOPE =
540: new MediaSize(4.125f, 9.5f, MediaSize.INCH, MediaSizeName.NA_NUMBER_10_ENVELOPE);
541:
542:
545: public static final MediaSize NA_NUMBER_11_ENVELOPE = new MediaSize(4.5f, 10.375f, MediaSize.INCH,
546: MediaSizeName.NA_NUMBER_11_ENVELOPE);
547:
548:
551: public static final MediaSize NA_NUMBER_12_ENVELOPE = new MediaSize(4.75f, 11f,
552: MediaSize.INCH,
553: MediaSizeName.NA_NUMBER_12_ENVELOPE);
554:
555:
558: public static final MediaSize NA_NUMBER_14_ENVELOPE = new MediaSize(5f, 11.5f,
559: MediaSize.INCH,
560: MediaSizeName.NA_NUMBER_14_ENVELOPE);
561: }
562:
563:
568: public static final class Engineering
569: {
570: private Engineering()
571: {
572:
573: }
574:
575:
578: public static final MediaSize A = new MediaSize(8.5f, 11f,
579: MediaSize.INCH, MediaSizeName.A);
580:
581:
584: public static final MediaSize B = new MediaSize(11f, 17f,
585: MediaSize.INCH, MediaSizeName.B);
586:
587:
590: public static final MediaSize C = new MediaSize(17f, 22f,
591: MediaSize.INCH, MediaSizeName.C);
592:
593:
596: public static final MediaSize D = new MediaSize(22f, 34f,
597: MediaSize.INCH, MediaSizeName.D);
598:
599:
602: public static final MediaSize E = new MediaSize(34f, 44f,
603: MediaSize.INCH, MediaSizeName.E);
604: }
605:
606:
611: public static final class JIS
612: {
613: private JIS()
614: {
615:
616: }
617:
618:
622: public static final MediaSize B0 = new MediaSize(1030, 1456, MediaSize.MM, MediaSizeName.JIS_B0);
623:
624:
628: public static final MediaSize B1 = new MediaSize(728, 1030, MediaSize.MM, MediaSizeName.JIS_B1);
629:
630:
634: public static final MediaSize B2 = new MediaSize(515, 728, MediaSize.MM, MediaSizeName.JIS_B2);
635:
636:
640: public static final MediaSize B3 = new MediaSize(364, 515, MediaSize.MM, MediaSizeName.JIS_B3);
641:
642:
646: public static final MediaSize B4 = new MediaSize(257, 364, MediaSize.MM, MediaSizeName.JIS_B4);
647:
648:
652: public static final MediaSize B5 = new MediaSize(182, 257, MediaSize.MM, MediaSizeName.JIS_B5);
653:
654:
658: public static final MediaSize B6 = new MediaSize(128, 182, MediaSize.MM, MediaSizeName.JIS_B6);
659:
660:
664: public static final MediaSize B7 = new MediaSize(91, 128, MediaSize.MM, MediaSizeName.JIS_B7);
665:
666:
670: public static final MediaSize B8 = new MediaSize(64, 91, MediaSize.MM, MediaSizeName.JIS_B8);
671:
672:
676: public static final MediaSize B9 = new MediaSize(45, 64, MediaSize.MM, MediaSizeName.JIS_B9);
677:
678:
682: public static final MediaSize B10 = new MediaSize(32, 45, MediaSize.MM, MediaSizeName.JIS_B10);
683:
684:
687: public static final MediaSize CHOU_1 = new MediaSize(142, 332, MediaSize.MM);
688:
689:
692: public static final MediaSize CHOU_2 = new MediaSize(119, 227, MediaSize.MM);
693:
694:
697: public static final MediaSize CHOU_3 = new MediaSize(120, 235, MediaSize.MM);
698:
699:
702: public static final MediaSize CHOU_4 = new MediaSize(90, 205, MediaSize.MM);
703:
704:
707: public static final MediaSize CHOU_30 = new MediaSize(92, 235, MediaSize.MM);
708:
709:
712: public static final MediaSize CHOU_40 = new MediaSize(90, 225, MediaSize.MM);
713:
714:
717: public static final MediaSize KAKU_0 = new MediaSize(287, 382, MediaSize.MM);
718:
719:
722: public static final MediaSize KAKU_1 = new MediaSize(270, 382, MediaSize.MM);
723:
724:
727: public static final MediaSize KAKU_2 = new MediaSize(240, 332, MediaSize.MM);
728:
729:
732: public static final MediaSize KAKU_20 = new MediaSize(229, 324, MediaSize.MM);
733:
734:
737: public static final MediaSize KAKU_3 = new MediaSize(216, 227, MediaSize.MM);
738:
739:
742: public static final MediaSize KAKU_4 = new MediaSize(197, 267, MediaSize.MM);
743:
744:
747: public static final MediaSize KAKU_5 = new MediaSize(190, 240, MediaSize.MM);
748:
749:
752: public static final MediaSize KAKU_6 = new MediaSize(162, 229, MediaSize.MM);
753:
754:
757: public static final MediaSize KAKU_7 = new MediaSize(142, 205, MediaSize.MM);
758:
759:
762: public static final MediaSize KAKU_8 = new MediaSize(119, 197, MediaSize.MM);
763:
764:
767: public static final MediaSize KAKU_A4 = new MediaSize(228, 312, MediaSize.MM);
768:
769:
772: public static final MediaSize YOU_1 = new MediaSize(120, 176, MediaSize.MM);
773:
774:
777: public static final MediaSize YOU_2 = new MediaSize(114, 162, MediaSize.MM);
778:
779:
782: public static final MediaSize YOU_3 = new MediaSize(98, 148, MediaSize.MM);
783:
784:
787: public static final MediaSize YOU_4 = new MediaSize(105, 235, MediaSize.MM);
788:
789:
792: public static final MediaSize YOU_5 = new MediaSize(95, 217, MediaSize.MM);
793:
794:
797: public static final MediaSize YOU_6 = new MediaSize(98, 190, MediaSize.MM);
798:
799:
802: public static final MediaSize YOU_7 = new MediaSize(92, 165, MediaSize.MM);
803: }
804:
805:
810: public static final class Other
811: {
812: private Other()
813: {
814:
815: }
816:
817:
820: public static final MediaSize EXECUTIVE = new MediaSize(7.25f, 10.5f,
821: MediaSize.INCH, MediaSizeName.EXECUTIVE);
822:
823:
826: public static final MediaSize FOLIO = new MediaSize(8.5f, 13f, MediaSize.INCH, MediaSizeName.FOLIO);
827:
828:
831: public static final MediaSize QUARTO = new MediaSize(8.5f, 10.83f, MediaSize.INCH,
832: MediaSizeName.QUARTO);
833:
834:
837: public static final MediaSize INVOICE = new MediaSize(5.5f, 8.5f,
838: MediaSize.INCH, MediaSizeName.INVOICE);
839:
840:
843: public static final MediaSize LEDGER = new MediaSize(11, 17, MediaSize.INCH,
844: MediaSizeName.LEDGER);
845:
846:
849: public static final MediaSize MONARCH_ENVELOPE = new MediaSize(3.87f, 7.5f,
850: MediaSize.INCH,
851: MediaSizeName.MONARCH_ENVELOPE);
852:
853:
856: public static final MediaSize PERSONAL_ENVELOPE = new MediaSize(3.625f, 6.5f, MediaSize.INCH,
857: MediaSizeName.PERSONAL_ENVELOPE);
858:
859:
862: public static final MediaSize ITALY_ENVELOPE = new MediaSize(110, 230,
863: MediaSize.MM,
864: MediaSizeName.ITALY_ENVELOPE);
865:
866:
869: public static final MediaSize JAPANESE_POSTCARD = new MediaSize(100, 148, MediaSize.MM, MediaSizeName.JAPANESE_POSTCARD);
870:
871:
874: public static final MediaSize JAPANESE_DOUBLE_POSTCARD = new MediaSize(148, 200, MediaSize.MM, MediaSizeName.JAPANESE_DOUBLE_POSTCARD);
875:
876:
880: public static final MediaSize TABLOID =
881: new MediaSize(11, 17, Size2DSyntax.INCH, MediaSizeName.TABLOID);
882: }
883: }