// ----------------------------------------------------------- // tscroll.java | class tscroll // ----------------------------------------------------------- // ------------------- tScroll V 2.02 ------------------------ // Scrolling Texte Message - FreeWare - // Author : R. BERTHOU // E-Mail : rberthou@pratique.fr // URL : http://www.pratique.fr/~rberthou // ----------------------------------------------------------- // If you add new function in this applet send me a new file // - // Si vous ajoutez de nouvelles fonction a l'applet envoyez moi // le source. // ----------------------------------------------------------- // Ver * Author * DATE * Description // ....................DD/MM/YY............................... // 2.00 * R. BERTHOU * 26/05/97 * Input Data in file // .............................* Add rd2.java // 2.01.*.R. BERTHOU * 27/06/97.* Add Scroll Type (0, 1, 2) // 2.02.*.R. BERTHOU * 01/07/97.* Add iScroll 3 (Fade Effect) // ...................................iScroll 4 (no Effet) // 2.03 * R. BERTHOU * 02/08/97 * Add target option // 2.10 * R. BERTHOU * 02/10/97 * Add foreground Image // ----------------------------------------------------------- import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Color; import java.awt.Image; import java.awt.Event; import java.io.InputStream ; import java.io.StreamTokenizer ; import java.util.Vector ; import java.util.Enumeration ; import java.net.URL; import rd2 ; public class tscroll extends java.applet.Applet implements Runnable { // Declare the controlling thread for the applet public Vector dFile = new Vector( 5, 5 ); Thread scrollmessage; private String[] ligne = new String[20] ; // texte du message reformaté // Declare the details for the message to be displayed int iLigne ; // Nombre de lignes du message int s_h ; // Longueur du message int s_v ; // Hauteur du message int iMax ; // Nombre de Message int iActif = 999; // Message Actif boolean iCharge = true ; boolean iEffect = false ; int cBk = 0x000000 ; // Nombre de Message int cTx = 0xFFFFFF ; // Message Actif int iR, iB, iG ; int iRp, iBp, iGp ; int iR2, iB2, iG2 ; int iR2p, iB2p, iG2p ; // Variables controlling the display of the message int x_coord, // present x-position y_coord, // present y-position x_effect, // speed, // scrolling amount iScroll, // (integer) Type de défilement iPause, // (integer) pause delay; // scrolling speed // for storing the dimensions of the applet int appletWidth, appletHeight; // for double buffering to prevent flicker Image offScreenImage; Image fdImg = null; // Image de fond Image gdImg = null; // Image de fond Graphics offScreen; // Font control variables Font wordFont; FontMetrics wordMetrics; // Applet initialisation routine public void init() { // Temporary storage space String temp; // get the size of the applet appletWidth = size().width; appletHeight = size().height; // initialise the double buffering screen try { offScreenImage = createImage (appletWidth, appletHeight); offScreen = offScreenImage.getGraphics (); } catch (Exception e) { offScreen = null; } wordFont = getFont(); wordMetrics = getFontMetrics (wordFont); // get the speed of the scrolling temp = getParameter("speed"); speed= (temp==null) ? 1 : Integer.parseInt( temp ); temp = getParameter("delay"); delay= (temp==null) ? 100 : Integer.parseInt( temp ); temp = getParameter("pause"); iPause= (temp==null) ? 0 : Integer.parseInt( temp ); temp = getParameter("tscr"); iScroll= (temp==null) ? 1 : Integer.parseInt( temp ); temp = getParameter("image"); if (temp != null) fdImg = getImage(getCodeBase(), temp) ; temp = getParameter("fgimg"); if (temp != null) gdImg = getImage(getCodeBase(), temp) ; temp = getParameter("file"); readFile(temp) ; } // end of init public void Charge() { iActif++ ; if (iActif > iMax) iActif = 0 ; String s ; s = new String( ((rd2)dFile.elementAt(iActif)).sM ) ; if (iScroll==1) { // défilement horizontal ligne[0] = new String( s ) ; iLigne = 1 ; } else { // défilement vertical int iE = 0, iB = 0 ; iLigne = 0 ; iE = s.indexOf("\n", iB) ; while(iE > -1) { ligne[iLigne++] = s.substring(iB, iE) ; iB = iE+1 ; iE = s.indexOf("\n", iB) ; } ligne[iLigne++] = s.substring(iB, s.length()) ; } iCharge = false ; if ( ((rd2)dFile.elementAt(iActif)).wFont != null ) { wordFont = ((rd2)dFile.elementAt(iActif)).wFont ; wordMetrics = getFontMetrics (wordFont); } s_h=-wordMetrics.stringWidth(ligne[0]); s_v=wordMetrics.getHeight(); } public void readFile(String f) { dFile.removeAllElements() ; iMax = 0; try { InputStream fis = (new URL( getCodeBase(), f )).openStream() ; StreamTokenizer st = new StreamTokenizer( fis ); st.commentChar(';'); st.quoteChar('"'); st.eolIsSignificant(true); while ( true ) { rd2 s = new rd2(); if (s.get( s, st)) { dFile.addElement( s ); iMax++ ; } else break ; } } catch( Exception e ) { // A traiter } } // control the starting of the applet public void start() { // Set the initial coordinates if (iScroll==1) { // défilement horizontal y_coord = appletHeight/2 + (wordMetrics.getHeight()-wordMetrics.getDescent())/2; x_coord = appletWidth; } else { // défilement vertical x_coord = (appletWidth + s_h) / 2 ; y_coord = appletHeight + wordMetrics.getHeight() ; } // start the thread scrollmessage = new Thread(this); scrollmessage.start(); } // end of start // control the stopping of the applet public void stop() { scrollmessage.stop(); } // end of stop // control the running of the applet public void run() { // set the priority of the thread to low Thread.currentThread().setPriority(Thread.MIN_PRIORITY); // loop continuously while(true) { // values for working out the constant delay long thisTick, waitTick; // calculate the tick to wait for waitTick = System.currentTimeMillis() + delay; // update the screen if (iEffect == false) { if (iScroll==1) { x_coord -= speed; if (x_coord= s_v) && ((y_coord-speed) < s_v)) { waitTick += iPause ; x_effect = -1 ; } // delay for the appropriate amount of time thisTick = System.currentTimeMillis(); if ( thisTick -1) cBk = ((rd2)dFile.elementAt(iActif)).iB ; // setBackground(new Color(((rd2)dFile.elementAt(iActif)).iB) ) ; if ( ((rd2)dFile.elementAt(iActif)).iT > -1) cTx = ((rd2)dFile.elementAt(iActif)).iT ; // set the font in the graphics context g.setFont (wordFont); if ( (iActif+1) == iMax) iR = 0 ; else iR = iActif + 1 ; if ( ((rd2)dFile.elementAt(iR)).iB > -1) { cTemp = new Color(((rd2)dFile.elementAt(iR)).iB ) ; } else { cTemp = new Color(cBk) ; } cTemp2 = new Color(cBk) ; iRp = cTemp2.getRed() - cTemp.getRed() ; iBp = cTemp2.getBlue() - cTemp.getBlue() ; iGp = cTemp2.getGreen() - cTemp.getGreen() ; cTemp2 = new Color(cTx) ; iR2 = cTemp2.getRed() ; iB2 = cTemp2.getBlue() ; iG2 = cTemp2.getGreen() ; iR2p = iR2 - cTemp.getRed() ; iB2p = iB2 - cTemp.getBlue() ; iG2p = iG2 - cTemp.getGreen() ; cTemp = new Color(cBk) ; iR = cTemp.getRed() ; iB = cTemp.getBlue() ; iG = cTemp.getGreen() ; } g.clearRect(0,0,appletWidth,appletHeight); if (iEffect && (iScroll == 3)) { g.setColor ( new Color ( iR - ((iRp*x_effect)/20), iG - ((iGp*x_effect)/20), iB - ((iBp*x_effect)/20)) ); } else g.setColor ( new Color ( cBk ) ); g.fillRect(0, 0, appletWidth, appletHeight ) ; if (iEffect && (iScroll == 3)) { g.setColor ( new Color ( iR2 - ((iR2p*x_effect)/20), iG2 - ((iG2p*x_effect)/20), iB2 - ((iB2p*x_effect)/20)) ); } else g.setColor ( new Color ( cTx ) ); if (fdImg != null) g.drawImage(fdImg,0,0, appletWidth, appletHeight, this); int i = 0 ; while (i < iLigne) { if (iScroll != 1) { if (((rd2)dFile.elementAt(iActif)).iScr == 1) x_coord = (appletWidth - wordMetrics.stringWidth(ligne[i])) - 5 ; else if (((rd2)dFile.elementAt(iActif)).iScr == 2) x_coord = 5 ; else x_coord = (appletWidth - wordMetrics.stringWidth(ligne[i])) / 2 ; } g.drawString (ligne[i], x_coord, y_coord + (s_v * i) ); i++ ; } if (iEffect) { x_effect++ ; if (iScroll == 2) g.fillRect(0, 0, appletWidth * x_effect / 20, appletHeight* x_effect / 20 ) ; if (x_effect >= 20) { iEffect = false ; iCharge = true ; x_effect = 0 ; // Set the initial coordinates if (iScroll==1) { // défilement horizontal y_coord = appletHeight/2 + (wordMetrics.getHeight()-wordMetrics.getDescent())/2; x_coord = appletWidth; } else { // défilement vertical x_coord = (appletWidth + s_h) / 2 ; y_coord = appletHeight + wordMetrics.getHeight() ; } } } if (gdImg != null) g.drawImage(gdImg,0,0, appletWidth, appletHeight, this); } // end of paintApplet // Return the information on the applet public String getAppletInfo() { return "tscroll v2.10 * Message Applet by R. BERTHOU (1997) - E-Mail : rberthou@pratique.fr"; } // end of getAppletInfo // Return the parameter information on the applet public String[][] getParameterInfo() { String[][] info = { {"file", "text", "file mess URL"}, {"image", "text", "background img"}, {"fgimg", "text", "foreground img"}, {"speed", "int", "speed scroll"}, {"delay", "int", "msecs between jumps"}, {"pause", "int", "msecs wait v scroll"}, {"tscr", "int", "scroll type 1..4"}, }; return info; } // end of getParameterInfo } // end of class ScrollingMessage