//GraphCanvas.java import java.awt.*; public class GraphCanvasD extends Canvas{ protected static final Color bgcolor = new Color(216,216,191); protected Image im; protected Graphics buf; protected int LeftMargin; protected int TopSep; protected int BottomSep; protected int RightMargin; protected int VPos=0; protected String XLabel, YLabel, TITLE; protected String X1, X2, X3; protected String Y1, Y2, Y3; protected int NumPoints; protected double x[]; protected double y[]; protected double phi_angle; protected double ymin, ymax; protected double xmin, xmax; protected int xx[]; protected int yy[]; protected int flag; protected int type; protected double xRef; protected boolean Should_Plot_Zero_Line; protected boolean Should_Plot_Ref_Point; protected boolean IsYRangeMinSet, IsYRangeMaxSet; protected boolean IsXRangeMinSet, IsXRangeMaxSet; protected boolean IsPolar, is_theta_plane; protected Font font1; protected Font font2; NewGuide_State state; public GraphCanvasD(NewGuide_State state){ super(); this.state = state; setBackground(bgcolor); int LeftMargin = state.s40; int TopSep = state.s40; int BottomSep = state.s40; int RightMargin = state.s40; font1 = new Font("Serif",Font.PLAIN,state.font12); font2 = new Font("SanSerif",Font.PLAIN,state.font11); XLabel="x-axis"; YLabel="y-axis"; TITLE ="Unknown Title"; Y1 = " "; Y2 = " "; Y3 = " "; X1 = " "; X2 = " "; X3 = " "; NumPoints = 1001; x = new double[NumPoints]; y = new double[NumPoints]; xx = new int[NumPoints]; yy = new int[NumPoints]; for(int i=0;i= 1.0e-3){ Y2=""+MaestroA.rounder(ymax,5); flag = 0; } else if(ymax >= 1.0e-4 && ymax < 1.0e-3){ Y2=""+MaestroA.rounder(ymax*1.0e4,5); flag = 4; } else if(ymax >= 1.0e-5 && ymax < 1.0e-4){ Y2=""+MaestroA.rounder(ymax*1.0e5,4); flag = 5; } else if(ymax >= 1.0e-6 && ymax < 1.0e-5){ Y2=""+MaestroA.rounder(ymax*1.0e6,4); flag = 6; } else if(ymax >= 1.0e-7 && ymax < 1.0e-6){ Y2=""+MaestroA.rounder(ymax*1.0e7,4); flag = 7; } else if(ymax >= 1.0e-8 && ymax < 1.0e-7){ Y2=""+MaestroA.rounder(ymax*1.0e8,4); flag = 8; } else if(ymax >= 1.0e-9 && ymax < 1.0e-8){ Y2=""+MaestroA.rounder(ymax*1.0e9,4); flag = 9; } else if(ymax >= 1.0e-10 && ymax < 1.0e-9){ Y2=""+MaestroA.rounder(ymax*1.0e10,4); flag = 10; } else if(ymax >= 1.0e-11 && ymax < 1.0e-10){ Y2=""+MaestroA.rounder(ymax*1.0e11,4); flag = 11; } else if(ymax >= 1.0e-12 && ymax < 1.0e-11){ Y2=""+MaestroA.rounder(ymax*1.0e12,4); flag = 12; } else if(ymax >= 1.0e-13 && ymax < 1.0e-12){ Y2=""+MaestroA.rounder(ymax*1.0e13,4); flag = 13; } else if(ymax >= 1.0e-14 && ymax < 1.0e-13){ Y2=""+MaestroA.rounder(ymax*1.0e14,4); flag = 14; } else if(ymax >= 1.0e-15 && ymax < 1.0e-14){ Y2=""+MaestroA.rounder(ymax*1.0e15,4); flag = 14; } else if(ymax >= 1.0e-16 && ymax < 1.0e-15){ Y2=""+MaestroA.rounder(ymax*1.0e16,4); flag = 16; } else if(ymax >= 1.0e-17 && ymax < 1.0e-16){ Y2=""+MaestroA.rounder(ymax*1.0e17,4); flag = 17; } else if(ymax >= 1.0e-18 && ymax < 1.0e-17){ Y2=""+MaestroA.rounder(ymax*1.0e18,4); flag = 18; } else if(ymax >= 1.0e-19 && ymax < 1.0e-18){ Y2=""+MaestroA.rounder(ymax*1.0e19,4); flag = 19; } else if(ymax >= 1.0e-20 && ymax < 1.0e-19){ Y2=""+MaestroA.rounder(ymax*1.0e20,4); flag = 20; } else if(ymax < 1.0e-20){ Y2=""+ymax; flag = 0; } } else{ Y2="\u221e"; flag = 0; } Y3="_"; } protected void plotZeroLine(Graphics g){ if(ymin*ymax>0){return;} FontMetrics fm = g.getFontMetrics(); g.setFont(font1); int yy; yy = (int)MaestroA.mapper(0.0,(double)TopSep,(double)(getSize().height-BottomSep),ymax,ymin); g.setColor(Color.red); g.drawLine(LeftMargin,yy,getSize().width-RightMargin,yy); g.drawString("0",LeftMargin-fm.stringWidth("0"),yy+fm.getHeight()/3); } public synchronized void plotZeroLine(boolean Should_Plot_Zero_Line){ this.Should_Plot_Zero_Line = Should_Plot_Zero_Line; } protected void plotRefPoint(Graphics g){ int myX=0, myY=0, i; i = (int)((NumPoints-1)*(xRef-x[0])/(x[x.length-1]-x[0])); if(i<0) {i = 0;} if(i>=NumPoints){i=NumPoints-1;} myX = (int)MaestroA.mapper(xRef,(double)(getSize().width-RightMargin),(double)(LeftMargin),xmax,xmin); if(y[i]>0.0){ myY = (int)MaestroA.mapper(y[i],(double)TopSep,(double)(getSize().height-BottomSep),ymax,ymin); } else{ myY =getSize().height-BottomSep ; } Graphics2D g2d = (Graphics2D)g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.white); g.drawLine(myX,myY,myX,getSize().height-BottomSep+state.s5); g.setColor(Color.red); MaestroG.fillCircle(myX,myY,state.s6,g); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF); } public synchronized void plotRefPoint(boolean Should_Plot_Ref_Point){ this.Should_Plot_Ref_Point = Should_Plot_Ref_Point; } protected void plotPoints(Graphics g){ ignition(); g.setColor(Color.white); g.drawPolyline(xx,yy,xx.length); } protected void drawTitle(Graphics g){ Graphics2D g2d = (Graphics2D)g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); FontMetrics fm = g.getFontMetrics(); g.setFont(font1); g.setColor(Color.white); g.drawString(XLabel,(getSize().width-fm.stringWidth(XLabel))/2+state.s60,getSize().height-BottomSep+3*fm.getHeight()/2+state.s5); g.setColor(Color.white); g.drawString(TITLE,(getSize().width)*70/100,TopSep/2-state.s3); if(type == 1){ g.drawString("V/m",LeftMargin-state.s30,getSize().height/2); MaestroG.subscripterSymbol("| E","\u03b8"," |",g,state.font14,LeftMargin+state.s13,state.s16); } if(type == 2){ g.drawString("V/m",LeftMargin-state.s30,getSize().height/2); MaestroG.subscripter2("| E","R"," |",g,state.font14,LeftMargin+state.s13,state.s16); } if(type == 3){ g.drawString("V/m",LeftMargin-state.s30,getSize().height/2); MaestroG.subscripter2("| E","x"," |",g,state.font14,LeftMargin+state.s13,state.s16); } if(type == 4){ g.drawString("V/m",LeftMargin-state.s30,getSize().height/2); MaestroG.subscripter2("| E","y"," |",g,state.font14,LeftMargin+state.s13,state.s16); } if(type == 5){ g.drawString("V/m",LeftMargin-state.s30,getSize().height/2); MaestroG.subscripter2("| E","z"," |",g,state.font14,LeftMargin+state.s13,state.s16); } if(type == 6){ g.drawString("A/m",LeftMargin-state.s30,getSize().height/2); MaestroG.subscripterSymbol("| H","\u03c6"," |",g,state.font14,LeftMargin+state.s13,state.s16); } if(type == 7){ g.drawString("A/m",LeftMargin-state.s30,getSize().height/2); MaestroG.subscripter2("| H","x"," |",g,state.font14,LeftMargin+state.s13,state.s16); } if(type == 8){ g.drawString("A/m",LeftMargin-state.s30,getSize().height/2); MaestroG.subscripter2("| H","y"," |",g,state.font14,LeftMargin+state.s13,state.s16); } g.setFont(font1); g.setColor(Color.yellow); g.drawString(X1,LeftMargin-state.s6,getSize().height-BottomSep+3*fm.getHeight()/2); g.drawString(X2,getSize().width-RightMargin-fm.stringWidth(X2)+state.s10,getSize().height-BottomSep+3*fm.getHeight()/2); // horizontal tick marks. Using fonts (above) DOES NOT WORK on Mac - Mac sucks!!!!! g.drawLine(LeftMargin,getSize().height-BottomSep,LeftMargin,getSize().height-BottomSep+state.s6); g.drawLine(LeftMargin+(getSize().width-RightMargin-LeftMargin)/2,getSize().height-BottomSep, LeftMargin+(getSize().width-RightMargin-LeftMargin)/2,getSize().height-BottomSep+state.s6); g.drawLine(getSize().width-RightMargin,getSize().height-BottomSep, getSize().width-RightMargin,getSize().height-BottomSep+state.s6); g.drawLine(LeftMargin-state.s6,getSize().height-BottomSep,LeftMargin,getSize().height-BottomSep); g.drawLine(LeftMargin,TopSep,LeftMargin-state.s6,TopSep); g.drawString("180",(getSize().width-RightMargin + LeftMargin-1)/2-state.s7,getSize().height-BottomSep+3*fm.getHeight()/2); g.drawString(Y1,state.s10,getSize().height-BottomSep+state.s5); if(fm.stringWidth(Y2)>(LeftMargin-state.s10)){ if(flag == 0){ g.drawString(Y2,state.s5,TopSep-state.s4); } else{ MaestroG.superscripter2(Y2+" 10","-"+flag,"",g,state.font12,state.s5,TopSep-state.s4); } } else{ if(flag == 0){ g.drawString(Y2,4,TopSep-4); } else{ MaestroG.superscripter2(Y2+" 10","-"+flag,"",g,state.font12,state.s5,TopSep-state.s4); } } g.setColor(Color.yellow); } protected void drawAxis(Graphics g){ VPos = getSize().height-BottomSep; g.setColor(Color.yellow); //Vertical Axis g.drawLine(LeftMargin,TopSep-state.s1,LeftMargin,getSize().height-BottomSep); g.drawLine(LeftMargin,VPos,getSize().width-RightMargin+state.s10,VPos); //MaestroG.drawArrow(getSize().width-RightMargin+state.s10,VPos,7,g); MaestroG.drawArrowScaled(getSize().width-RightMargin+state.s10,VPos,3,state.sfactor,g); } public final synchronized void setXLabel(String XLabel){ this.XLabel=XLabel; } public final synchronized void setYLabel(String YLabel){ this.YLabel=YLabel; } public final synchronized void setTitle(String TITLE){ this.TITLE = TITLE; } public final synchronized void setLabels(String TITLE, String YLabel, String XLabel){ this.TITLE=TITLE; this.YLabel = YLabel; this.XLabel = XLabel; } public void plot(double[] xdata, double[] ydata){ if(NumPoints != xdata.length){ NumPoints = xdata.length; x = new double[NumPoints]; y = new double[NumPoints]; xx = new int[NumPoints]; yy = new int[NumPoints]; } for(int i = 0; i < NumPoints; i++){ x[i] = xdata[i]; y[i] = ydata[i]; } repaint(); } public void setPolar(boolean IsPolar){ this.IsPolar = IsPolar; } public void setPhiAngle(double phi_angle){ this.phi_angle=phi_angle; } public void setType(int type){ this.type=type; } public void setYRange(double ymax, double ymin){ IsYRangeMaxSet=true; IsYRangeMinSet=true; this.ymax=ymax; this.ymin=ymin; } public void setYRangeMin(double ymin){ IsYRangeMinSet=true; this.ymin=ymin; } public void setYRangeMax(double ymax){ IsYRangeMaxSet=true; this.ymax=ymax; } public void setAuto(){ IsYRangeMaxSet=false; IsYRangeMinSet=false; IsXRangeMaxSet=false; IsXRangeMinSet=false; } public synchronized void setRefPoint(double xRef){ this.xRef = xRef; } public void update(Graphics g){ paint(g); } }