package isip.java.bullyse.bullydb; import java.net.*; import java.io.*; import java.awt.*; import java.awt.Component; import java.text.*; import java.util.*; import java.applet.*; import java.lang.*; import javax.servlet.*; import javax.servlet.http.*; import com.bigfoot.bugar.image.*; class graph extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Image winScratch = null; Graphics gScratch = null; Graphics g = null; System.out.println("Here 1"); String Symbol = "IFC"; String Type = (String)null; Vector data = new Vector(); double max = 0.00; double min = 0.00; double mid = 9999.99; Type = "1"; winScratch = java.awt.Component.createImage(240, 200); gScratch = winScratch.getGraphics(); System.out.println("Here 2"); try { getData(); } catch (Exception e) { e.printStackTrace(); } // double Values[] = {14.95, 37.96, 28.47, 42.95, 11.43, 12.47, 15.96, 18.47, 19.75, 14.29, 2.75, 9.47}; // double Times[] = {0, 5, 7, 8, 9, 11, 12, 14, 17, 19, 23, 23.9}; // int numVals = 12; System.out.println("Here 3"); double scale = 0.00; double tscale = 0.00; String thisDate = (String)null; String thisTime = (String)null; int t = 0; double j = 39; Hist obj = new Hist(); int numVals = data.size(); DecimalFormat numFormat = new DecimalFormat("#0.00"); DecimalFormat tFormat = new DecimalFormat("00"); java.util.Date lastDate = new java.util.Date(); java.util.Date lastTime = new java.util.Date(); System.out.println("Here 4"); int hour = lastTime.getHours(); int minute = lastTime.getMinutes(); // Set the format for time and date DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG); thisDate = dateFormat.format(lastDate); thisTime = tFormat.format(hour) + ":" + tFormat.format(minute); System.out.println("Here 5"); // Get max and min values for (int i = 0 ; i < numVals ; i++) { obj = (Hist)data.elementAt(i); double Val = obj.getValue(); if (min > Val) { min = Val; } if (max < Val) { max = Val; } } System.out.println("Here 6"); mid = (max+min) / 2; scale = 64 / (max-min); tscale = 196 / 24; Color tan = new Color(250, 235, 215); Color lightgray = new Color(220, 220, 220); Color darkgray = new Color(169, 169, 169); Color ivory = new Color(255, 255, 240); Color smoke = new Color(239, 239, 239); //Color smoke = new Color(204, 204, 204); Color slateblue = new Color(106, 90, 205); Color sky = new Color(0, 91, 251); Color darkblue = new Color(0, 0, 139); Color nasBlue = new Color(40, 100, 188); // Color nasGray = new Color(104, 104, 104); Color nasGray = new Color(102, 102, 102); Color nasLightGray = new Color(187, 187, 187); Color lightblue = new Color(162, 188, 221); // Color medgray = new Color(142, 143, 144); Color medgray = new Color(179, 179, 179); Color gold = new Color(255, 215, 0); Color khaki = new Color(240, 230, 140); Color BSEBlue = new Color(0, 0, 204); gScratch.setColor(smoke); gScratch.fillRect(5, 10, 230, 126); gScratch.setColor(medgray); gScratch.fillRect(8, 13, 224, 17); gScratch.setColor(nasGray); gScratch.fillRect(8, 31, 30, 79); gScratch.setColor(Color.white); gScratch.fillRect(38, 31, 194, 79); gScratch.setColor(nasGray); gScratch.fillRect(8, 98, 224, 14); gScratch.setColor(medgray); gScratch.fillRect(8, 113, 224, 20); System.out.println("Here 7"); Font thisFont = new Font("Helvetica", (int)Font.BOLD, 12); gScratch.setFont(thisFont); gScratch.setColor(smoke); if (Symbol != null) { gScratch.drawString(Symbol, 115, 26); } else { gScratch.drawString("BSE", 115, 26); } thisFont = new Font("Helvetica", (int)Font.PLAIN, 10); gScratch.setFont(thisFont); gScratch.drawString(thisDate, 10, 25); gScratch.drawString(thisTime, 200, 25); String pMax = (String)null; pMax = pMax.valueOf(numFormat.format(max)); String pMin = (String)null; pMin = pMin.valueOf(numFormat.format(min)); String pMid = (String)null; pMid = pMid.valueOf(numFormat.format(mid)); gScratch.drawString(pMax, 10, 45); gScratch.drawString(pMid, 10, 69); gScratch.drawString(pMin, 10, 93); String tOut = (String)null; while (t < 24) { tOut = tOut.valueOf(t); gScratch.drawString(tOut, (int)j, 108); t = t + 4; j = j + (196/6); } System.out.println("Here 8"); thisFont = new Font("Helvetica", (int)Font.PLAIN, 10); gScratch.setFont(thisFont); gScratch.setColor(smoke); gScratch.drawString("Today on the Bulldog Stock Exchange", 25, 126); // Draw grid lines gScratch.setColor(smoke); for (int i = 38 ; i < 232 ; i=i+12) { gScratch.drawLine(i, 31, i, 96); } for (int i = 97 ; i > 32 ; i=i-10) { gScratch.drawLine(38, i, 230, i); } gScratch.setColor(BSEBlue); for (int i = 1 ; i < numVals ; i++) { obj = (Hist)data.elementAt(i-1); double Val1 = obj.getValue(); double Time1 = obj.getAt(); obj = (Hist)data.elementAt(i); double Val2 = obj.getValue(); double Time2 = obj.getAt(); int x[] = {((int)(Time1*tscale)+39), ((int)(Time2*tscale)+39), ((int)(Time2*tscale)+39), ((int)(Time1*tscale)+39)}; int y[] = {((97+(int)(min*scale))-(int)((Val1*scale))), ((97+(int)(min*scale))-(int)((Val2*scale))), ((97+(int)(min*scale))-(int)((Val2*scale))-3), ((97+(int)(min*scale))-(int)((Val1*scale))-3)}; gScratch.fillPolygon(x, y, 4); } System.out.println("Here 9"); /* for (int i = 0 ; i < (numVals-1) ; i++) { gScratch.drawLine(((int)(Times[i]*tscale)+39), ((97+(int)(min*scale))-(int)((Values[i]*scale))), ((int)(Times[i+1]*tscale)+39), ((97+(int)(min*scale))-(int)((Values[i+1]*scale))-3)); } */ try { OutputStream fileOut = new FileOutputStream("/ftp/pub/projects/bse/images/image.png"); PNGEncoder encoder = new PNGEncoder( winScratch, fileOut ); encoder.encodeImage(); fileOut.close(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Here 10"); response.sendRedirect("http://www.isip.msstate.edu/projects/bse/html/errors/not_logged_in.html"); } public void getData() throws MalformedURLException, IOException { String Symbol = "IFC"; int Type = 1; URL newUrl = null; BufferedReader in = null; try { newUrl = new URL("http://www.isip.msstate.edu:8080/isip/servlet/isip.java.bullyse.bullydb.History?Task=getData&Symbol=" + Symbol + "&Type=" + Type); in = new BufferedReader(new InputStreamReader(newUrl.openStream())); } catch (Exception e) { e.printStackTrace(); } String inputLine; int Shares = 0; double Value = 0.00; double TransTime = 0.00; Vector data = new Vector(); String Val = (String)null; String Shar = (String)null; String Time = (String)null; int i = 1; while ((inputLine = in.readLine()) != null) { if (i == 1) { Val = inputLine; Double ValTmp = Double.valueOf(Val); Value = ValTmp.doubleValue(); i++; } else if (i == 2) { Shar = inputLine; Integer SharTmp = Integer.valueOf(Shar); Shares = SharTmp.intValue(); i++; } else if (i == 3) { Time = inputLine; Double TimeTmp = Double.valueOf(Time); TransTime = TimeTmp.doubleValue(); data.addElement(new Hist(Value, Shares, TransTime)); i = 1; } else { i++; } } in.close(); } public class Hist { private double Value; private int Shares; private double transDate; public Hist () { this.Value = 0.00; this.Shares = 0; this.transDate = 0.00; } public Hist (double Value, int Shares, double transDate) { this.Value = Value; this.Shares = Shares; this.transDate = transDate; } public double getValue() { return Value; } public int getShares() { return Shares; } public double getAt() { return transDate; } } }