/*-----
* group: Data presentation
* purpose: Simplfy utilization of Java2D Graphics
* notes: Uses javaobj.
Java source, jar and examples are here
*/
/**html
*
Java source, jar and examples can be found here
*/ %macro jdsgimac; %* place this file in your sasautos path; %* or %include it prior to using the jDSGI macros; %mend; /* * Richard A. DeVenezia * June 1, 2004 * Copyright 2004 * * jDSGI macros */ /* * JavaObj array passing has a memory bug, thus until 9.2, * the auxiallary macros setArray and getArray should be * used to ensure the SAS session does not encounter a * Write Access Violation (WAV) */ %macro canvas (javaobj, width, height, color); %global jdsgi; %let jdsgi = &javaobj; declare javaobj &jdsgi ('jdsgi/Graphics'); declare javaobj &jdsgi._x ('jdsgi/DoubleArray'); declare javaobj &jdsgi._y ('jdsgi/DoubleArray'); &jdsgi..exceptionDescribe(1); &jdsgi..callVoidMethod ('setXData', &jdsgi._x); &jdsgi..callVoidMethod ('setYData', &jdsgi._Y); %createBuffer (&width, &height); %setColor (&color); %fillRect (0,0,&width,&height); %setColor (0); %mend; %macro canvas_delete(); &jdsgi..delete(); &jdsgi._x.delete(); &jdsgi._y.delete(); %symdel jdsgi; %mend; %macro setArray(sasArray, doubleArray); &doubleArray..callVoidMethod ('setLength', dim(&sasArray)); do _&sysindex = 1 to dim(&sasArray); &doubleArray..callVoidMethod('set', _&sysindex-1, &sasArray[_&sysindex]); end; %mend; %macro getArray(sasArray, doubleArray); &doubleArray..callIntMethod ('getLength', l_&sysindex); drop l_&sysindex; do _&sysindex = 1 to min (dim(&sasArray), l_&sysindex); &doubleArray..callDoubleMethod('get', _&sysindex-1, &sasArray[_&sysindex]); end; %mend; %macro createBuffer (width, height); &jdsgi..callVoidMethod ('createBuffer', &width, &height) %mend; %macro setRenderingHint (key, value); &jdsgi..callVoidMethod ('setRenderingHint', &key, &value) %mend; %macro setBackground (color); &jdsgi..callVoidMethod ('setBackground', &color) %mend; %macro setBackgroundRGB (r,g,b); &jdsgi..callVoidMethod ('setBackground', &r,&g,&b) %mend; %macro getBackground (argb); &jdsgi..callIntMethod ('getBackground', &argb) %mend; %macro getColor (argb); &jdsgi..callIntMethod ('getColor', &argb) %mend; %macro setColor (color); &jdsgi..callVoidMethod ('setColor', &color) %mend; %macro setColorA (color); &jdsgi..callVoidMethod ('setColor', &color, 1) %mend; %macro setColorRGB (r,g,b); &jdsgi..callVoidMethod ('setColor', &r,&g,&b) %mend; %macro setColorHSB (h,s,b); &jdsgi..callVoidMethod ('setColorHSB', &h,&s,&b) %mend; %macro setColorDarker (); &jdsgi..callVoidMethod ('setColorDarker') %mend; %macro setColorBrighter (); &jdsgi..callVoidMethod ('setColorBrighter') %mend; %macro translate (x,y); &jdsgi..callVoidMethod ('translate', &x, &y) %mend; %macro resetFont (); &jdsgi..callVoidMethod ('resetFont') %mend; %macro setFont (name,style,size); &jdsgi..callVoidMethod ('setFont', &name, &style, &size) %mend; %macro setFontName (name); &jdsgi..callVoidMethod ('setFontName', &name) %mend; %macro getFontName (name); &jdsgi..callStringMethod ('getFontName', &name) %mend; %macro setFontSize (size); &jdsgi..callVoidMethod ('setFontSize', &size) %mend; %macro getFontSize (size); &jdsgi..callIntMethod ('getFontSize', &size) %mend; %macro setFontStyle (style); &jdsgi..callVoidMethod ('setFontStyle', &style) %mend; %macro getFontStyle (style); &jdsgi..callIntMethod ('getFontStyle', &style) %mend; %let FONT_PLAIN = 0; %let FONT_BOLD = 1; %let FONT_ITALIC = 2; %macro drawString (string,x,y); &jdsgi..callVoidMethod ('drawString', &string, &x, &y) %mend; %macro getStringWidth (text,width); &jdsgi..callIntMethod ('getStringWidth', &text, &width) %mend; %macro drawLine (x1,y1,x2,y2); &jdsgi..callvoidMethod ('drawLine', &x1,&y1, &x2,&y2) %mend; %macro draw3DRect (x,y,width,height,raised); &jdsgi..callVoidMethod ('draw3DRect', &x, &y, &width, &height,&raised) %mend; %macro fill3DRect (x,y,width,height,raised); &jdsgi..callVoidMethod ('fill3DRect', &x, &y, &width, &height,&raised) %mend; %macro drawRect (x,y,width,height); &jdsgi..callVoidMethod ('drawRect', &x, &y, &width, &height) %mend; %macro clearRect (x,y,width,height); &jdsgi..callVoidMethod ('clearRect', &x, &y, &width, &height) %mend; %macro fillRect (x,y,width,height); &jdsgi..callVoidMethod ('fillRect', &x, &y, &width, &height) %mend; %macro drawRoundRect (x,y,width,height,arcWidth,arcHeight); &jdsgi..callVoidMethod ('drawRoundRect', &x, &y, &width, &height, &arcWidth, &arcHeight) %mend; %macro fillRoundRect (x,y,width,height,arcWidth,arcHeight); &jdsgi..callVoidMethod ('fillRoundRect', &x, &y, &width, &height, &arcWidth, &arcHeight) %mend; %macro drawArc (x,y,width,height,startAngle,arcAngle); &jdsgi..callVoidMethod ('drawArc', &x, &y, &width, &height, &startAngle, &arcAngle) %mend; %macro fillArc (x,y,width,height,startAngle,arcAngle); &jdsgi..callVoidMethod ('fillArc', &x, &y, &width, &height, &startAngle, &arcAngle) %mend; %macro drawOval (x,y,width,height); &jdsgi..callVoidMethod ('drawOval', &x, &y, &width, &height) %mend; %macro fillOval (x,y,width,height); &jdsgi..callVoidMethod ('fillOval', &x, &y, &width, &height) %mend; %macro tsetFillMode (mode); &jdsgi..callVoidMethod ('tsetFillMode', &mode) %mend; %macro resetPen (); &jdsgi..callVoidMethod ('resetPen') %mend; %macro resetPenDash (); &jdsgi..callVoidMethod ('resetPenDash') %mend; %macro setPenWidth (w); &jdsgi..callVoidMethod ('setPenWidth',&w) %mend; %macro setPenEndCap (p); &jdsgi..callVoidMethod ('setPenEndCap',&p) %mend; %macro setPenLineJoin (p); &jdsgi..callVoidMethod ('setPenLineJoin',&p) %mend; %macro setPenMiterLimit (p); &jdsgi..callVoidMethod ('setPenMiterLimit',&p) %mend; %macro setPenDashPhase (p); &jdsgi..callVoidMethod ('setPenDashPhase',&p) %mend; %macro setPenDash2 (p1,p2); &jdsgi..callVoidMethod ('setPenDash2',&p1,&p2) %mend; %macro setPenDash (sasArray); %local javaArray; %let javaArray = _&sysindex; declare javaobj &javaArray ("jdsgi/DoubleArray"); %setArray (&sasArray, &javaArray); &jdsgi..callVoidMethod ('setPenDash', &javaArray); /* &jdsgi..callVoidMethod ('setPenDash', &xpoints, &ypoints) */ &javaArray..delete() %mend; %let CAP_BUTT = 0; %let CAP_ROUND = 1; %let CAP_SQUARE = 2; %let JOIN_MITER = 0; %let JOIN_ROUND = 1; %let JOIN_BEVEL = 2; %macro drawPolygon (xpoints, ypoints); %setArray (&xpoints, &jdsgi._x) %setArray (&ypoints, &jdsgi._y) &jdsgi..callVoidMethod ('drawPolygon') /* &jdsgi..callVoidMethod ('drawPolygon', &xpoints, &ypoints) */ %mend; %macro fillPolygon (xpoints, ypoints); %setArray (&xpoints, &jdsgi._x) %setArray (&ypoints, &jdsgi._y) &jdsgi..callVoidMethod ('fillPolygon') /* &jdsgi..callVoidMethod ('fillPolygon', &xpoints, &ypoints) */ %mend; %macro drawPolyline (xpoints, ypoints); %setArray (&xpoints, &jdsgi._x) %setArray (&ypoints, &jdsgi._y) &jdsgi..callVoidMethod ('drawPolyline') /* &jdsgi..callVoidMethod ('drawPolyline', &xpoints, &ypoints) */ %mend; %macro setClip (x,y,width,height); &jdsgi..callVoidMethod ('setClip', &x, &y, &width, &height) %mend; %macro setClipPolygon (xpoints, ypoints); %setArray (&xpoints, &jdsgi._x) %setArray (&ypoints, &jdsgi._y) &jdsgi..callVoidMethod ('setClipPolygon') /* &jdsgi..callVoidMethod ('setClipPolygon', &xpoints, &ypoints) */ %mend; %macro getClipBounds (doubleArray); %setNData (&doubleArray); &jdsgi..callVoidMethod ('getClipBounds') %mend; %macro getImageWidth (width); &jdsgi..callIntMethod ('getImageWidth', &width) %mend; %macro getImageHeight (height); &jdsgi..callIntMethod ('getImageHeight', &height) %mend; %macro drawImage (x,y,bgcolor); &jdsgi..callVoidMethod ('drawImage', &x,&y,&bgcolor) %mend; %macro readImage (source); &jdsgi..callVoidMethod ('readImage', &source) %mend; %macro canvas_saveAs (basename, type, savedAs); &savedAs = repeat(' ', 300); &jdsgi..callStringMethod ('saveAs', trim(&type), catx('.',&basename,&type), &savedAs); put &savedAs= %mend; %macro setNData(doubleArray); &jdsgi..callVoidMethod ('setNData', &doubleArray) %mend; %macro tSetViewport (n,x1,y1,x2,y2); &jdsgi..callVoidMethod ('tsetViewport', &n,&x1,&y1,&x2,&y2) %mend; %macro tSetWindow (n,x1,y1,x2,y2); &jdsgi..callVoidMethod ('tsetWindow', &n,&x1,&y1,&x2,&y2) %mend; %macro tsetWindowAspectedForWidth (n,x1,y1,w); &jdsgi..callVoidMethod ('tsetWindowAspectedForWidth', &n,&x1,&y1,&w) %mend; %macro tsetWindowAspectedForHeight (n,x1,y1,h); &jdsgi..callVoidMethod ('tsetWindowAspectedForHeight', &n,&x1,&y1,&h) %mend; %macro tGetViewport (n,doubleArray); &jdsgi..callVoidMethod ('tgetViewport', &n,&doubleArray) %mend; %macro tGetWindow (n,doubleArray); &jdsgi..callVoidMethod ('tgetWindow', &n,&doubleArray) %mend; %macro tComputeAspectedViewport (n,x1,y1,x2,y2,doubleArray); &jdsgi..callVoidMethod ('tcomputeAspectedViewport', &n,&x1,&y1,&x2,&y2,&doubleArray) %mend; %macro tString (text,x,y,function=trim); %local n; %let n = %sysfunc(count(&function,:)); %let text = %sysfunc(translate(&function,%str(%(),:))(&text.%sysfunc(repeat(%str(%)),&n)); &jdsgi..callVoidMethod ('tstring', &text,&x,&y) %mend; %macro tStringCenter(text,x,y,function=trim); %local n; %let n = %sysfunc(count(&function,:)); %let text = %sysfunc(translate(&function,%str(%(),:))(&text.%sysfunc(repeat(%str(%)),&n)); &jdsgi..callVoidMethod ('tstringCenter', &text,&x,&y) %mend; %macro tStringRight (text,x,y,function=trim); %local n; %let n = %sysfunc(count(&function,:)); %let text = %sysfunc(translate(&function,%str(%(),:))(&text.%sysfunc(repeat(%str(%)),&n)); &jdsgi..callVoidMethod ('tstringRight', &text,&x,&y) %mend; %macro tGetClipRect (n,doubleArray); &jdsgi..callVoidMethod ('tgetClipRect', &n,&doubleArray) %mend; %macro tSetClip (onoff); &jdsgi..callVoidMethod ('tsetClip', &onoff) %mend; %macro tGetClip (onoff); &jdsgi..callBooleanMethod ('tgetClip', &onoff) %mend; %macro tSetTransno (t); &jdsgi..callVoidMethod ('tsetTransno', &t) %mend; %macro tGetTransno (t); &jdsgi..callIntMethod ('tgetTransno', &t) %mend; %macro tArc (x,y,r,start,end); &jdsgi..callVoidMethod ('tarc',&x,&y,&r,&start,&end,0) %mend; %macro tArcChord (x,y,r,start,end); &jdsgi..callVoidMethod ('tarc',&x,&y,&r,&start,&end,1) %mend; %macro tArcPieSlice (x,y,r,start,end); &jdsgi..callVoidMethod ('tarc',&x,&y,&r,&start,&end,2) %mend; %macro tLine (x1,y1,x2,y2); &jdsgi..callVoidMethod ('tline',&x1,&y1,&x2,&y2) %mend; %macro tBar (x1,y1,x2,y2); &jdsgi..callVoidMethod ('tbar',&x1,&y1,&x2,&y2) %mend; %macro tRBar (x1,y1,x2,y2,w,h); &jdsgi..callVoidMethod ('trbar',&x1,&y1,&x2,&y2,&w,&h) %mend; %macro tEllarc (x,y,major,minor,start,end,angle); &jdsgi..callVoidMethod ('tellarc',&x,&y,&major,&minor,&start,&end,&angle,0) %mend; %macro tEllarcChord (x,y,major,minor,start,end,angle); &jdsgi..callVoidMethod ('tellarc',&x,&y,&major,&minor,&start,&end,&angle,1) %mend; %macro tEllarcPieSlice (x,y,major,minor,start,end,angle); &jdsgi..callVoidMethod ('tellarc',&x,&y,&major,&minor,&start,&end,&angle,2) %mend; %macro tPolyline (xpoints, ypoints,n=); %setArray (&xpoints, &jdsgi._x) %setArray (&ypoints, &jdsgi._y) %if %length(&n) = 0 %then %let n = dim(&xpoints); &jdsgi..callVoidMethod ('tpolyline', &n) /* &jdsgi..callVoidMethod ('tpolyline', &xpoints, &ypoints) */ %mend; %macro tPolygon (xpoints, ypoints,n=); %setArray (&xpoints, &jdsgi._x) %setArray (&ypoints, &jdsgi._y) %if %length(&n) = 0 %then %let n = dim(&xpoints); &jdsgi..callVoidMethod ('tpolygon', &n) /* &jdsgi..callVoidMethod ('tpolygon', &xpoints, &ypoints) */ %mend; %macro tsetRotation (angle); &jdsgi..callVoidMethod ('tsetRotation', &angle) %mend; %macro reportFormats (); &jdsgi..callVoidMethod ('reportFormats') %mend;