// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://kpdus.tripod.com/jad.html // Decompiler options: packimports(3) // Source File Name: D:\Sergey\JavaPM\ver10\Plota\PanelA.java import java.awt.*; import java.awt.image.*; import java.util.*; class PanelA extends Panel implements Runnable { public void start() { if(m_Runner == null) { m_Runner = new Thread(this); m_Runner.start(); } } public void stop() { if(m_Runner != null) { m_Runner.stop(); m_Runner = null; } } public int max(int a, int b, int c, int d, int e) { int max = a; if (b > max) { max = b; }; if (c > max) { max = c; }; if (d > max) { max = d; }; if (e > max) { max = e; }; return max; } public int max(int a, int b, int c, int d, int e, int f) { return Math.max(max(a,b,c,d,e),f); } public void setInvalid() { m_bInvalid = true; } PanelA(Plota applet) { m_pszX = 500; m_pszY = 300; m_bInvalid = true; m_Font = new Font("Helvetica", 1, 12); m_FM = getFontMetrics(m_Font); m_Xmax = 400D; m_Ymax = 200D; m_strMessage = "my message"; m_Applet = applet; setFont(m_Font); m_bInvalid = true; } public Dimension preferredSize() { return new Dimension(m_pszX, m_pszY); } public void run() { do { if(m_bInvalid) { repaint(); m_bInvalid = true; } try { Thread.sleep(500L); } catch(InterruptedException interruptedexception) { } } while(true); } public float round (float x){ if (Math.abs((float)Math.round((double)10000*x)/10000-x)<=.001) x= (float)Math.round((double)10000*x)/10000; return x; } public void update(Graphics g) { Dimension d = size(); if(m_ImageOff == null || d.width != m_DimOff.width || d.height != m_DimOff.height) { m_ImageOff = createImage(d.width, d.height); m_DimOff = d; m_GraphOff = m_ImageOff.getGraphics(); } paint(m_GraphOff); g.drawImage(m_ImageOff, 0, 0, null); } public void paint(Graphics g) { Dimension d = size(); int border = Rect3D.drawRect(g, 0, 0, d.width - 1, d.height - 1); g.setColor(Color.red); m_strMessage = m_Applet.m_strMessage; m_NumPoints = m_Applet.m_NumPoints; m_Xmin = m_Applet.m_Xmin; m_Xmax = m_Applet.m_Xmax; m_Ymin = m_Applet.m_Ymin; m_Ymax = m_Applet.m_Ymax; m_Xs = m_Applet.m_Xs; m_Ys = m_Applet.m_Ys; String sy0 = Float.toString(round((float)m_Ymin)); String syq1 = Float.toString(round((float)(m_Ymin + (Math.abs(m_Ymax-m_Ymin)) * (0.75)))); String syq2 = Float.toString(round((float)(m_Ymin + (Math.abs(m_Ymax-m_Ymin)) * (0.50)))); String syq3 = Float.toString(round((float)(m_Ymin + (Math.abs(m_Ymax-m_Ymin)) * (0.25)))); String sy1 = Float.toString(round((float)m_Ymax)); String sx0 = Float.toString(round((float)m_Xmin)); String sxq1 = Float.toString(round((float)(m_Xmin + (Math.abs(m_Xmax-m_Xmin)) * (0.25)))); String sxq2 = Float.toString(round((float)(m_Xmin + (Math.abs(m_Xmax-m_Xmin)) * (0.50)))); String sxq3 = Float.toString(round((float)(m_Xmin + (Math.abs(m_Xmax-m_Xmin)) * (0.75)))); String sx1 = Float.toString(round((float)m_Xmax)); int wsx0 = m_FM.stringWidth(sx0); int wsxq1 = m_FM.stringWidth(sxq1); int wsxq2 = m_FM.stringWidth(sxq2); int wsxq3 = m_FM.stringWidth(sxq3); int wsx1 = m_FM.stringWidth(sx1); int wsy0 = m_FM.stringWidth(sy0); int wsyq1 = m_FM.stringWidth(syq1); int wsyq2 = m_FM.stringWidth(syq2); int wsyq3 = m_FM.stringWidth(syq3); int wsy1 = m_FM.stringWidth(sy1); int h = m_FM.getHeight(); int xl = 6; // If there's a Y-axis image, adjust the border width accordingly. if (!(yAxisImg.equals(null))) { xl = border + max(wsy0, wsy1, wsyq1, wsyq2, wsyq3, yAxisImg.getWidth(this)) + 6; } else { xl = border + max(wsy0, wsy1, wsyq1, wsyq2, wsyq3) + 6; } int xr = d.width - border - 3; int yt = border + 3; int yb = d.height - border - (3 * h) / 2; if (!(yAxisImg.equals(null))) { yb = d.height - border - Math.max((3 * h) / 2, xAxisImg.getHeight(this)+1); //yb = d.height - border - (3 * Math.max(h, xAxisImg.getHeight(this))) / 2; } double coefX = (double)(xr - xl) / (m_Xmax - m_Xmin); double coefY = (double)(yt - yb) / (m_Ymax - m_Ymin); int i = 0; int x = 0; int y = 0; int x0 = 0; int y0 = 0; g.setColor(Color.black); g.drawLine(xl, yb, xl, yt); double del = (double)(yt - yb) / 5D; i = 1; //if (!(xAxisImg.equals(null))) g.drawImage(xAxisImg,xr-xAxisImg.getWidth(this),yb,this); //if (!(yAxisImg.equals(null))) g.drawImage(yAxisImg,5,5,this); g.setColor(Color.yellow); do { y = yb + (int)((double)i * del); // g.drawLine(xl, y, xl + 10, y); g.drawLine(xl, y, 640, y); } while(++i <= 10); g.drawLine(xl, yb, xr, yb); del = (double)(xr - xl) / 10D; i = 1; g.setColor(Color.yellow); do { x = xl + (int)((double)i * del); // g.drawLine(x, yb, x, yb - 7); g.drawLine(x, yb, x, 0); } while(++i <= 10); g.setFont(m_Font); g.setColor(Color.black); g.drawString(sy0, xl - wsy0 - 3, yb); // ymin g.drawString(syq3, xl-wsyq3-3, yt+(int)(Math.abs(Math.abs(yt)-Math.abs(yb))*3/4)+(int)(h*3/4)-6); g.drawString(syq2, xl-wsyq2-3, yt+(int)(Math.abs(Math.abs(yt)-Math.abs(yb))/2)+(int)(h/2)); g.drawString(syq1, xl-wsyq1-3, yt+(int)(Math.abs(Math.abs(yt)-Math.abs(yb))/4)+(int)(h/4)+6); // Instead of ymax, draw the y-axis-label if one exists if (!(yAxisImg.equals(null))) { g.drawImage(yAxisImg,xl-yAxisImg.getWidth(this)-3,yt,this); //g.drawImage(yAxisImg,5,5,this); } else { g.drawString(sy1, xl - wsy1 - 3, yt + h); // ymax } g.drawString(sx0, xl, yb + h); // xmin g.drawString(sxq1, (int)(xl+Math.abs(xl-xr)/4-wsxq1/4), yb+h); g.drawString(sxq2, (int)(xl+Math.abs(xl-xr)/2-wsxq2/2), yb+h); g.drawString(sxq3, (int)(xl+Math.abs(xl-xr)*3/4-wsxq3*3/4), yb+h); if (!(xAxisImg.equals(null))) { g.drawImage(xAxisImg,xr-xAxisImg.getWidth(this),yb+1,this); //g.drawImage(xAxisImg,xr-xAxisImg.getWidth(this),yb,this); } else { g.drawString(sx1, xr - wsx1, yb + h); // xmax } for (int graphnum=0; graphnum < m_Xs.size(); graphnum++) { g.setColor(LineColors.getColor(graphnum)); //System.out.println("Updating plot for graph #" + (graphnum + 1)); /* if (graphnum==0) { g.setColor(Color.black); } else if (graphnum == 1) { g.setColor(Color.red); } else if (graphnum == 2) { g.setColor(Color.blue); } else if (graphnum == 3) { g.setColor(Color.magenta); } else if (graphnum == 4) { g.setColor(Color.orange); } else { System.out.println("Note: Distinct colors only set for the first 6 equations"); g.setColor (Color.gray); };*/ double[] m_X = (double[])m_Xs.elementAt(graphnum); double[] m_Y = (double[])m_Ys.elementAt(graphnum); for(i = 0; i < m_NumPoints; i++) { x = xl + (int)(coefX * (m_X[i] - m_Xmin)); y = yb + (int)(coefY * (m_Y[i] - m_Ymin)); // so that the drawing does not go past the graph boundaries // if(x < xl) { x = xl; } else if (x > xr) { x = xr; } // if both y values are off the chart, then we don't want to graph the // particular line at all. if (y > yb) { y = yb; } else if (y < yt) { y = yt; } if (i != 0) { if (!( ((y <= yt) || (y >= yb)) && ((y0 <= yt) || (y0 >= yb)) )) { g.drawLine(x0, y0, x, y); // responsible for drawing the lines } } x0 = x; y0 = y; } } } private Plota m_Applet; private Thread m_Runner; private int m_pszX; private int m_pszY; private boolean m_bInvalid; private Image m_ImageOff; private Dimension m_DimOff; private Graphics m_GraphOff; private Font m_Font; private FontMetrics m_FM; private int m_NumPoints; private Vector m_Xs; private Vector m_Ys; //private double m_X[]; //private double m_Y[]; public double m_Xmin; public double m_Xmax; public double m_Ymin; public double m_Ymax; public Image xAxisImg, yAxisImg; private String m_strMessage; }