001: package com.calipso.xmleditor;
002:
003: import net.sf.jasperreports.engine.*;
004: import net.sf.jasperreports.engine.design.JasperDesign;
005: import net.sf.jasperreports.engine.base.JRBaseReport;
006:
007: import javax.swing.*;
008: import java.awt.*;
009: import java.util.*;
010:
011: public abstract class RW {
012:
013: /**
014: * Description of the Field
015: */
016: public final static String IMAGE_EXPRESSION_TYPES[] = {
017: "java.lang.String", "java.io.File", "java.net.URL",
018: "java.io.InputStream", "java.awt.Image" };
019:
020: /**
021: * Description of the Field
022: */
023: public final static String WHEN_NO_DATA[] = { "NoPages",
024: "BlankPage", "AllSectionsNoDetail" };
025:
026: /**
027: * Description of the Field
028: */
029: public final static String SCALE_TYPES[] = { "Retain shape",
030: "Fill frame", "Clip" };
031:
032: /**
033: * Description of the Field
034: */
035: public final static String STRETCH_TYPES[] = { "None",
036: "Band height", "Tallest object" };
037:
038: /**
039: * Description of the Field
040: */
041: public final static String PEN_TYPES[] = { "None", "1 pt", "2 pt",
042: "4 pt", "Dotted" };
043:
044: /**
045: * Description of the Field
046: */
047: public final static String EVAL_TIMES[] = { "Now", "Report",
048: "Page", "Column", "Group" };
049:
050: /**
051: * Description of the Field
052: */
053: public final static String ALIGNMENTS[] = { "Left", "Center",
054: "Right", "Justified" };
055:
056: /**
057: * Description of the Field
058: */
059: public final static String HORIZONTAL_ALIGNMENTS[] = { "Left",
060: "Center", "Right" };
061:
062: /**
063: * Description of the Field
064: */
065: public final static String VERTICAL_ALIGNMENTS[] = { "Top",
066: "Middle", "Bottom" };
067: /**
068: * Description of the Field
069: */
070: public final static String LINE_SPACINGS[] = { "Single", "1_1_2",
071: "Double" };
072:
073: /**
074: * Description of the Field
075: */
076: public final static String VALUE_TYPES[] = { "String", "Double",
077: "Date", "Integer", "Timestamp", "Boolean", "Byte", "Float",
078: "InputStream", "Long", "Short", };
079:
080: /**
081: * Calculation types
082: */
083: public final static String CALC_TYPES[] = { "Nothing", "Count",
084: "Sum", "Average", "Lowest", "Highest", "StandardDeviation",
085: "Variance", "System" };
086:
087: /**
088: * Reset types
089: */
090: public final static String RESET_TYPES[] = { "None", "Report",
091: "Page", "Column", "Group" };
092:
093: /**
094: * Hyperlink types
095: */
096: public final static String HYPERLINK_TYPES[] = { "None",
097: "LocalAnchor", "LocalPage", "Reference", "RemoteAnchor",
098: "RemotePage" };
099:
100: private static Map typesMap = null;
101:
102: /**
103: * Gets the resetTypeName attribute of the RW class
104: *
105: * @param var Description of the Parameter
106: * @return The resetTypeName value
107: */
108: public static String getResetTypeName(JRVariable var) {
109: return getResetTypeName(var.getResetType());
110: }
111:
112: private static void loadTypesMap() {
113: typesMap = new HashMap();
114: typesMap.put("String", java.lang.String.class);
115: typesMap.put("Boolean", java.lang.Boolean.class);
116: typesMap.put("Byte", java.lang.Byte.class);
117: typesMap.put("Date", java.util.Date.class);
118: typesMap.put("Timestamp", java.sql.Timestamp.class);
119: typesMap.put("Double", java.lang.Double.class);
120: typesMap.put("Float", java.lang.Float.class);
121: typesMap.put("Integer", java.lang.Integer.class);
122: typesMap.put("InputStream", java.io.InputStream.class);
123: typesMap.put("Long", java.lang.Long.class);
124: typesMap.put("Short", java.lang.Short.class);
125: }
126:
127: public static Class getValueClass(String typeName) {
128: if (typesMap == null) {
129: loadTypesMap();
130: }
131: return (Class) typesMap.get(typeName);
132: }
133:
134: public static String getTypeName(Class cls) {
135: String clsName = cls.getName();
136: int ix = clsName.lastIndexOf(".");
137: if (ix >= 0) {
138: clsName = clsName.substring(ix + 1);
139: }
140: return clsName;
141: }
142:
143: /**
144: * Gets the scaleTypeName attribute of the RW class
145: *
146: * @param i Description of the Parameter
147: * @return The scaleTypeName value
148: */
149: public static String getScaleTypeName(int i) {
150:
151: String penStr = "Clip";
152: switch (i) {
153: case JRImage.SCALE_IMAGE_FILL_FRAME:
154: penStr = "Fill frame";
155: break;
156: case JRImage.SCALE_IMAGE_RETAIN_SHAPE:
157: penStr = "Retain shape";
158: break;
159: }
160: return penStr;
161: }
162:
163: /**
164: * Gets the scaleType attribute of the RW class
165: *
166: * @param s Description of the Parameter
167: * @return The scaleType value
168: */
169: public static byte getScaleType(String s) {
170: if ("Fill frame".equals(s)) {
171: return JRImage.SCALE_IMAGE_FILL_FRAME;
172: } else if ("Retain shape".equals(s)) {
173: return JRImage.SCALE_IMAGE_RETAIN_SHAPE;
174: }
175: return JRImage.SCALE_IMAGE_CLIP;
176: }
177:
178: /**
179: * Gets the stretchTypeName attribute of the RW class
180: *
181: * @param i Description of the Parameter
182: * @return The stretchTypeName value
183: */
184: public static String getStretchTypeName(int i) {
185:
186: String penStr = "None";
187: switch (i) {
188: case JRGraphicElement.STRETCH_TYPE_RELATIVE_TO_BAND_HEIGHT:
189: penStr = "Band height";
190: break;
191: case JRGraphicElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT:
192: penStr = "Tallest object";
193: break;
194: }
195: return penStr;
196: }
197:
198: /**
199: * Gets the stretchType attribute of the RW class
200: *
201: * @param s Description of the Parameter
202: * @return The stretchType value
203: */
204: public static byte getStretchType(String s) {
205: if ("Band height".equals(s)) {
206: return JRGraphicElement.STRETCH_TYPE_RELATIVE_TO_BAND_HEIGHT;
207: } else if ("Tallest object".equals(s)) {
208: return JRGraphicElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT;
209: }
210: return JRGraphicElement.STRETCH_TYPE_NO_STRETCH;
211: }
212:
213: /**
214: * Gets the penTypeName attribute of the RW class
215: *
216: * @param i Description of the Parameter
217: * @return The penTypeName value
218: */
219: public static String getPenTypeName(int i) {
220:
221: String penStr = "None";
222: switch (i) {
223: case JRGraphicElement.PEN_1_POINT:
224: penStr = "1 pt";
225: break;
226: case JRGraphicElement.PEN_2_POINT:
227: penStr = "2 pt";
228: break;
229: case JRGraphicElement.PEN_4_POINT:
230: penStr = "4 pt";
231: break;
232: case JRGraphicElement.PEN_DOTTED:
233: penStr = "Dotted";
234: break;
235: }
236: return penStr;
237: }
238:
239: /**
240: * Gets the penType attribute of the RW class
241: *
242: * @param s Description of the Parameter
243: * @return The penType value
244: */
245: public static byte getPenType(String s) {
246: if ("1 pt".equals(s)) {
247: return JRGraphicElement.PEN_1_POINT;
248: } else if ("2 pt".equals(s)) {
249: return JRGraphicElement.PEN_2_POINT;
250: } else if ("4 pt".equals(s)) {
251: return JRGraphicElement.PEN_4_POINT;
252: } else if ("Dotted".equals(s)) {
253: return JRGraphicElement.PEN_DOTTED;
254: }
255: return JRGraphicElement.PEN_NONE;
256: }
257:
258: /**
259: * Gets the resetTypeName attribute of the RW class
260: *
261: * @param i Description of the Parameter
262: * @return The resetTypeName value
263: */
264: public static String getResetTypeName(int i) {
265:
266: String resetStr = "None";
267: switch (i) {
268: case JRVariable.RESET_TYPE_COLUMN:
269: resetStr = "Column";
270: break;
271: case JRVariable.RESET_TYPE_GROUP:
272: resetStr = "Group";
273: break;
274: case JRVariable.RESET_TYPE_NONE:
275: resetStr = "None";
276: break;
277: case JRVariable.RESET_TYPE_PAGE:
278: resetStr = "Page";
279: break;
280: case JRVariable.RESET_TYPE_REPORT:
281: resetStr = "Report";
282: break;
283: }
284: return resetStr;
285: }
286:
287: /**
288: * Gets the calculationName attribute of the RW class
289: *
290: * @param var Description of the Parameter
291: * @return The calculationName value
292: */
293: public static String getCalculationName(JRVariable var) {
294: return getCalculationName(var.getCalculation());
295: }
296:
297: /**
298: * Gets the evaluationTimeName attribute of the RW class
299: *
300: * @param i Description of the Parameter
301: * @return The evaluationTimeName value
302: */
303: public static String getEvaluationTimeName(int i) {
304:
305: switch (i) {
306: case JRExpression.EVALUATION_TIME_COLUMN:
307: return "Column";
308: case JRExpression.EVALUATION_TIME_GROUP:
309: return "Group";
310: case JRExpression.EVALUATION_TIME_PAGE:
311: return "Page";
312: case JRExpression.EVALUATION_TIME_REPORT:
313: return "Report";
314: }
315: return "Now";
316: }
317:
318: /**
319: * Gets the evaluationTime attribute of the RW class
320: *
321: * @param s Description of the Parameter
322: * @return The evaluationTime value
323: */
324: public static byte getEvaluationTime(String s) {
325:
326: if ("Column".equals(s)) {
327: return JRExpression.EVALUATION_TIME_COLUMN;
328: } else if ("Report".equals(s)) {
329: return JRExpression.EVALUATION_TIME_REPORT;
330: } else if ("Page".equals(s)) {
331: return JRExpression.EVALUATION_TIME_PAGE;
332: } else if ("Group".equals(s)) {
333: return JRExpression.EVALUATION_TIME_GROUP;
334: }
335: return JRExpression.EVALUATION_TIME_NOW;
336: }
337:
338: /**
339: * Gets the calculationName attribute of the RW class
340: *
341: * @param i Description of the Parameter
342: * @return The calculationName value
343: */
344: public static String getCalculationName(int i) {
345:
346: String calcName = "Nothing";
347: switch (i) {
348: case JRVariable.CALCULATION_AVERAGE:
349: calcName = "Average";
350: break;
351: case JRVariable.CALCULATION_COUNT:
352: calcName = "Count";
353: break;
354: case JRVariable.CALCULATION_HIGHEST:
355: calcName = "Highest";
356: break;
357: case JRVariable.CALCULATION_LOWEST:
358: calcName = "Lowest";
359: break;
360: case JRVariable.CALCULATION_NOTHING:
361: calcName = "Nothing";
362: break;
363: case JRVariable.CALCULATION_STANDARD_DEVIATION:
364: calcName = "StandardDeviation";
365: break;
366: case JRVariable.CALCULATION_SUM:
367: calcName = "Sum";
368: break;
369: case JRVariable.CALCULATION_SYSTEM:
370: calcName = "System";
371: break;
372: case JRVariable.CALCULATION_VARIANCE:
373: calcName = "Variance";
374: break;
375: default:
376: calcName = "Nothing";
377: }
378: return calcName;
379: }
380:
381: /**
382: * Gets the calculationType attribute of the RW class
383: *
384: * @param str Description of the Parameter
385: * @return The calculationType value
386: */
387: public static byte getCalculationType(String str) {
388:
389: if ("Count".equals(str)) {
390: return JRVariable.CALCULATION_COUNT;
391: } else if ("Sum".equals(str)) {
392: return JRVariable.CALCULATION_SUM;
393: } else if ("Average".equals(str)) {
394: return JRVariable.CALCULATION_AVERAGE;
395: } else if ("Lowest".equals(str)) {
396: return JRVariable.CALCULATION_LOWEST;
397: } else if ("Highest".equals(str)) {
398: return JRVariable.CALCULATION_HIGHEST;
399: } else if ("StandardDeviation".equals(str)) {
400: return JRVariable.CALCULATION_STANDARD_DEVIATION;
401: } else if ("Variance".equals(str)) {
402: return JRVariable.CALCULATION_VARIANCE;
403: } else if ("System".equals(str)) {
404: return JRVariable.CALCULATION_SYSTEM;
405: }
406: return JRVariable.CALCULATION_NOTHING;
407: }
408:
409: /**
410: * Gets the resetType attribute of the RW class
411: *
412: * @param str Description of the Parameter
413: * @return The resetType value
414: */
415: public static byte getResetType(String str) {
416:
417: if ("Report".equals(str)) {
418: return JRVariable.RESET_TYPE_REPORT;
419: } else if ("Page".equals(str)) {
420: return JRVariable.RESET_TYPE_PAGE;
421: } else if ("Column".equals(str)) {
422: return JRVariable.RESET_TYPE_COLUMN;
423: } else if ("Group".equals(str)) {
424: return JRVariable.RESET_TYPE_GROUP;
425: }
426: return JRVariable.RESET_TYPE_NONE;
427: }
428:
429: public static String getHyperlinkTypeName(int aType) {
430: if (aType == JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR) {
431: return "LocalAnchor";
432: } else if (aType == JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE) {
433: return "LocalPage";
434: } else if (aType == JRHyperlink.HYPERLINK_TYPE_REFERENCE) {
435: return "Reference";
436: } else if (aType == JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR) {
437: return "RemoteAnchor";
438: } else if (aType == JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE) {
439: return "RemotePage";
440: }
441: return "None";
442: }
443:
444: public static byte getHyperlinkType(String str) {
445: if ("LocalAnchor".equals(str)) {
446: return JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR;
447: } else if ("LocalPage".equals(str)) {
448: return JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE;
449: } else if ("Reference".equals(str)) {
450: return JRHyperlink.HYPERLINK_TYPE_REFERENCE;
451: } else if ("RemoteAnchor".equals(str)) {
452: return JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR;
453: } else if ("RemotePage".equals(str)) {
454: return JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE;
455: }
456: return JRHyperlink.HYPERLINK_TYPE_NONE;
457: }
458:
459: /**
460: * Gets the expressionText attribute of the RW class
461: *
462: * @param exp Description of the Parameter
463: * @return The expressionText value
464: */
465: public static String getExpressionText(JRExpression exp) {
466:
467: StringBuffer expressionTxt = new StringBuffer();
468: if (exp == null) {
469: return "";
470: }
471: JRExpressionChunk chunks[] = exp.getChunks();
472: for (int i = 0; chunks != null && i < chunks.length; i++) {
473: JRExpressionChunk chunk = chunks[i];
474: switch (chunk.getType()) {
475: case JRExpressionChunk.TYPE_FIELD:
476: expressionTxt.append("$F{" + chunk.getText() + "}");
477: break;
478: case JRExpressionChunk.TYPE_VARIABLE:
479: expressionTxt.append("$V{" + chunk.getText() + "}");
480: break;
481: case JRExpressionChunk.TYPE_PARAMETER:
482: expressionTxt.append("$P{" + chunk.getText() + "}");
483: break;
484: default:
485: expressionTxt.append(chunk.getText());
486: }
487: }
488: return expressionTxt.toString();
489: }
490:
491: /**
492: * Gets the groupNames attribute of the RW class
493: *
494: * @param report Description of the Parameter
495: * @return The groupNames value
496: */
497: public static Vector getGroupNames(JRBaseReport report) {
498: Vector v = new Vector(report.getGroups().length);
499: JRGroup grps[] = report.getGroups();
500: for (int i = 0; i < grps.length; i++) {
501: JRGroup group = grps[i];
502: v.add(group.getName());
503: }
504: return v;
505: }
506:
507: /**
508: * Gets the alignmentName attribute of the RW class
509: *
510: * @param i Description of the Parameter
511: * @return The alignmentName value
512: */
513: public static String getAlignmentName(int i) {
514:
515: switch (i) {
516: case JRTextElement.TEXT_ALIGN_CENTER:
517: return "Center";
518: case JRTextElement.TEXT_ALIGN_RIGHT:
519: return "Right";
520: case JRTextElement.TEXT_ALIGN_JUSTIFIED:
521: return "Justified";
522: default:
523: return "Left";
524: }
525: }
526:
527: public static byte getHorizontalAlignment(String s) {
528:
529: if ("Center".equals(s)) {
530: return JRAlignment.HORIZONTAL_ALIGN_CENTER;
531: } else if ("Right".equals(s)) {
532: return JRAlignment.HORIZONTAL_ALIGN_RIGHT;
533: }
534: return JRAlignment.HORIZONTAL_ALIGN_LEFT;
535: }
536:
537: public static String getHorizontalAlignmentName(byte b) {
538: if (JRAlignment.HORIZONTAL_ALIGN_CENTER == b) {
539: return "Center";
540: } else if (JRAlignment.HORIZONTAL_ALIGN_RIGHT == b) {
541: return "Right";
542: }
543: return "Left";
544: }
545:
546: public static byte getVerticalAlignment(String s) {
547:
548: if ("Middle".equals(s)) {
549: return JRAlignment.VERTICAL_ALIGN_MIDDLE;
550: } else if ("Bottome".equals(s)) {
551: return JRAlignment.VERTICAL_ALIGN_BOTTOM;
552: }
553: return JRAlignment.VERTICAL_ALIGN_TOP;
554: }
555:
556: public static String getVerticalAlignmentName(byte b) {
557: if (JRAlignment.VERTICAL_ALIGN_MIDDLE == b) {
558: return "Middle";
559: } else if (JRAlignment.VERTICAL_ALIGN_BOTTOM == b) {
560: return "Bottom";
561: }
562: return "Top";
563: }
564:
565: /**
566: * Gets the alignment attribute of the RW class
567: *
568: * @param s Description of the Parameter
569: * @return The alignment value
570: */
571: public static byte getAlignment(String s) {
572:
573: if ("Center".equals(s)) {
574: return JRTextElement.TEXT_ALIGN_CENTER;
575: } else if ("Right".equals(s)) {
576: return JRTextElement.TEXT_ALIGN_RIGHT;
577: } else if ("Justified".equals(s)) {
578: return JRTextElement.TEXT_ALIGN_JUSTIFIED;
579: }
580: return JRTextElement.TEXT_ALIGN_LEFT;
581: }
582:
583: public static String getWhenNoDataName(int i) {
584: switch (i) {
585: case JRReport.WHEN_NO_DATA_TYPE_BLANK_PAGE:
586: return "BlankPage";
587: case JRReport.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL:
588: return "AllSectionsNoDetail";
589: }
590: return "NoPages";
591: }
592:
593: public static byte getWhenNoData(String s) {
594:
595: if ("BlankPage".equals(s)) {
596: return JRReport.WHEN_NO_DATA_TYPE_BLANK_PAGE;
597: } else if ("AllSectionsNoDetail".equals(s)) {
598: return JRReport.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL;
599: }
600: return JRReport.WHEN_NO_DATA_TYPE_NO_PAGES;
601: }
602:
603: /**
604: * Gets the lineSpacingName attribute of the RW class
605: *
606: * @param i Description of the Parameter
607: * @return The lineSpacingName value
608: */
609: public static String getLineSpacingName(int i) {
610:
611: switch (i) {
612: case JRTextElement.LINE_SPACING_SINGLE:
613: return "Single";
614: case JRTextElement.LINE_SPACING_DOUBLE:
615: return "Double";
616: case JRTextElement.LINE_SPACING_1_1_2:
617: return "1_1_2";
618: }
619: return "Single";
620: }
621:
622: /**
623: * Gets the lineSpacing attribute of the RW class
624: *
625: * @param s Description of the Parameter
626: * @return The lineSpacing value
627: */
628: public static byte getLineSpacing(String s) {
629:
630: if ("Single".equals(s)) {
631: return JRTextElement.LINE_SPACING_SINGLE;
632: } else if ("Double".equals(s)) {
633: return JRTextElement.LINE_SPACING_DOUBLE;
634: } else if ("1_1_2".equals(s)) {
635: return JRTextElement.LINE_SPACING_1_1_2;
636: }
637: return JRTextElement.LINE_SPACING_SINGLE;
638: }
639:
640: /**
641: * Gets the jdbcTypeClass attribute of the RW class
642: *
643: * @param t jdbc Type code value
644: * @return The jdbcTypeClass value
645: */
646: public static String getJdbcTypeClass(int t) {
647: String cls = "java.lang.String";
648: switch (t) {
649: case java.sql.Types.TINYINT:
650: case java.sql.Types.BIT:
651: cls = "java.lang.Byte";
652: break;
653: case java.sql.Types.SMALLINT:
654: cls = "java.lang.Short";
655: break;
656: case java.sql.Types.INTEGER:
657: cls = "java.lang.Integer";
658: break;
659: case java.sql.Types.REAL:
660: case java.sql.Types.DOUBLE:
661: case java.sql.Types.NUMERIC:
662: case java.sql.Types.DECIMAL:
663: cls = "java.lang.Double";
664: break;
665: case java.sql.Types.CHAR:
666: case java.sql.Types.VARCHAR:
667: cls = "java.lang.String";
668: break;
669: case java.sql.Types.BOOLEAN:
670: cls = "java.lang.Boolean";
671: break;
672: case java.sql.Types.BIGINT:
673: cls = "java.lang.Long";
674: break;
675: case java.sql.Types.DATE:
676: case java.sql.Types.TIME:
677: cls = "java.util.Date";
678: break;
679: case java.sql.Types.TIMESTAMP:
680: cls = "java.sql.Timestamp";
681: break;
682: }
683: return cls;
684: }
685:
686: /**
687: * Gets the JRReportFont to an specific name
688: *
689: * @param name The reportFont-Name to search for
690: * @param design The JasperDesign which holds the reportFont-Definitions
691: * @return The JRReportFont to the name or null if not found
692: */
693: public static JRReportFont searchReportFont(String name,
694: JasperDesign design) {
695: if (design == null) {
696: return null;
697: }
698: JRReportFont[] allReportf = design.getFonts();
699: for (int i = 0; i < allReportf.length; i++) {
700: if (allReportf[i].getName().equals(name)) {
701: return allReportf[i];
702: }
703: }
704: return null;
705: }
706: }
|