home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: Java
/
Java.zip
/
rdb084r2.zip
/
plugins.Zip
/
TGShow.nrx
< prev
next >
Wrap
Text File
|
1997-03-15
|
3KB
|
100 lines
/* TGShow: an applet which shows an image, some text, or both */
/* ---------------------------------------------------------- */
/* Based on GifShow.nrx by Mike Cowlishaw, */
/* as an example of Plugin for MaxBase */
/* ---------------------------------------------------------- */
options binary -- optional; runs a bit faster if set
class TGShow extends Applet
gif =String -- name of the image
recipe =String
goodimage=Image -- the Image to draw (null if no good)
rRecTxt = Rexx[1000]
rMaxLine = Rexx ""
rxRecipe = RXFile()
/* init gets the requested image, then uses a MediaTracker to track it
and wait until it has all arrived. If it looks good, the goodimage
property is set so paint(g) can use it. */
method init
rx = RXFile()
gif = (rx.linein()).strip() -- Get the name of the image
recipe = (rx.linein()).strip() -- Get the name of the text file
-- If there is a text file, read it.
rRecTxt[0]=0
if rxRecipe.stream(recipe, "c", "query exists") \= "" then
do
rxRecipe.stream(recipe, "c", "open read")
loop while(rxRecipe.lines() \= 0)
rRecTxt[0] = rRecTxt[0] + 1
rRecTxt[rRecTxt[0]] = rxRecipe.linein()
if rRecTxt[rRecTxt[0]].length() > rMaxLine.length() then
rMaxLine = rRecTxt[rRecTxt[0]]
end
rxRecipe.stream("c", "close")
end
else
if rxRecipe.stream(gif, "c", "query exists") = "" then
exit -- If we don't have a valid image OR text file, then exit.
newimage=getImage(getDocumentBase(), gif) -- get the image
tracker=MediaTracker(this) -- 'this' is the "observer"
tracker.addImage(newimage, 0) -- track image arrival, ID=0
do
tracker.waitForID(0) -- wait for image 0 to complete
catch InterruptedException -- something stopped us
return -- can do no more
end
-- Good images have useful dimensions, bad images have -1 or 0 in X or Y
if newimage.getWidth(this)>0
then if newimage.getHeight(this)>0
then goodimage=newimage
if goodimage = null & rRecTxt[0] = 0 then -- again, no text and no image
exit
method paint(g=Graphics)
w = int
h = int
f = Font("Courier", Font.PLAIN, 12)
iCount = int
if goodimage\=null then
do
w = goodimage.getWidth(this)
h = goodimage.getHeight(this);
if rRecTxt[0] > 0 then -- The file has to have some text in it to be valid.
do
-- Resize the window
if h > f.getSize()*rRecTxt[0] then
this.resize(w + (f.getSize() % 7)*5*rMaxLine.length() + 150, h + 5)
else
this.resize(w + (f.getSize() % 7)*5*rMaxLine.length() + 150, f.getSize()*rRecTxt[0] + 10)
loop iCount = 1 to rRecTxt[0] -- Draw the text file
g.drawString(rRecTxt[iCount], w + 5, f.getSize() * iCount)
end
end
else
this.resize(w + 5, h + 5)
g.drawImage(goodimage, 1, 1, w, h, this) -- Draw the image
end
else -- No image.
do
g.drawString('Errore!', 5, f.getSize())
this.resize((f.getSize() % 7)*4*rMaxLine.length() + 150, f.getSize()*rRecTxt[0] + 10)
loop iCount = 1 to rRecTxt[0]
g.drawString(rRecTxt[iCount], 5, f.getSize() * iCount)
end
end