Scenario 2, making Java2D fully available via string-based commands (Re: Minor thoughts (Re: [External] : Re: JEP draft: Prepare to Restrict The Use of JNI
Rony G. Flatscher
Rony.Flatscher at wu.ac.at
Tue Sep 5 09:56:47 UTC 2023
Consider the following ooRexx program that exploits the JRE (the Java classes available via the Java
runtime environment, installed by OpenJDK) for Java2D:
jdor=.bsf~new("org.oorexx.handlers.jdor.JavaDrawingHandler") -- create a JDOR handler
call BsfCommandHandler "add", "JDOR", jdor -- add the JDOR handler to ooRexx
address JDOR -- set default environment to the JDOR command handler
-- now we may use JDOR commands, executed by default by the JDOR command handler
width =220 -- define width of image in pixels (there are 72 px to an inch)
height=250 -- define height of image in pixels (there are 72 px to an inch)
newImage width height -- create new bitmap with currX=0, currY=0, width=220, height=250
winShow -- show frame on screen
-- draw two lines forming a big X
drawLine (width-1) (height-1) -- from currX=0, currY=0
color red -- set the color to red (preregistered with nickname "RED")
moveTo (width-1) 0 -- currX=219, currY=0
position -- query current position
say "--> rc="pp(rc) -- RC refers to the previous command's result: "219 0" (currX=219,
currY=0)
drawLine 0 (height-1) -- from currX=219, currY=0
-- draw a rectangle at the center of the bitmap
len = 50 -- drawing a rectangle with each side being 50 px (a square)
moveTo (width-len)/2 (height-len)/2 -- go to the center minus half of the square's side lengths
color green -- set color to green (preregistered with nickname "GREEN")
fillRect len len -- fill the square with the green color
stroke str3 3 -- set line stroke to 3 points width, store it with nickname "STR3"
color blue -- set color to blue (preregistered with nickname "BLUE")
drawRect len len -- draw the frame with the blue color
-- draw a string (text) at the lower half of the bitmap
color somePurple 127 46 111 -- define a custom RGB color, store it with nickname "SOMEPURPLE"
color -- query current color
say "--> rc="pp(rc) -- show result from command (a Java color object)
say " rc~toString:" pp(rc~toString) -- shows the RGB intensities of the current color
-- draw three lines of centered strings at the bottom
lineHeight = 15 -- default font size is 12px, add 3 px lead
newY=height-40 -- draw the three strings at the bottom
clrs=("somePurple", "blue", "gray") -- define three different colors
text=("Hello, Rexx world ...", "... from JDOR ...", "(a Rexx command handler)") -- array of
3 strings
do counter c i=0 to 30 by lineHeight -- iterate over array of strings
s=text[c] -- fetch the string to draw from array
stringBounds s -- get the bounding box dimensions for this string
parse var rc . . w . -- parse the width of the string's bounding box
moveTo (width-w)/2 (newY+i) -- calc x position to center this string, set y position
color clrs[c] -- fetch and use the color from the array
drawString s -- draw the string
end
-- save the current image
saveImage "jdor_doc_sample.png" -- save image to file "jdor_doc_sample.png"
sleep 3.123 -- sleep for 3.123 seconds
::requires "BSF.CLS" -- get ooRexx-Java bridge, contains JDOR Rexx command handler
To see its output in the command line window and the produced graphic cf.
<https://wi.wu.ac.at/rgf/rexx/misc/jdor_doc.tmp/jdor_doc.html>. That is also at the same time (a
temporary) location of the JDOR (Java2D for ooRexx) documentation.
---
This program runs on all versions of Java/OpenJDK unchanged.
With your currently intended warning all of a sudden all users of such programs/applications get
frightened for no good reason!
---rony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20230905/f510517e/attachment.htm>
More information about the jdk-dev
mailing list