//NewGuideOutputPanel.java
/*
 * Panel with numerical data outputs for microstrip
 * Generate classes: NewGuideOutputCanvasA and NewGuideOutputCanvasB
 * authors: Umberto Ravaioli
 * version 1.0 - Copyright: Amanogawa.com - All Rights Reserved
 */

import java.awt.*;
import java.text.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;

public class NewGuideOutputPanel extends Panel {
    NewGuide_State state;
    private static final Color bgcolor = new Color(236,236,236);
    //private static final Font labfont=new Font("SanSerif",Font.PLAIN,11);	
    //private static final Font titlefont=new Font("SanSerif",Font.BOLD,16);
    private Font labfont;
    private Font titlefont;
    Label titlelabel;	
    public NewOutputCanvasA rwocA; 
    public NewOutputCanvasB rwocB; 

    public NewGuideOutputPanel(NewGuide_State state){
        super();
        setLayout(null);
        this.state = state;

        if (MaestroG.useBiggerFont) {
            labfont = state.sanSerifFont.deriveFont((float)state.font13);
            titlefont = state.sanSerifFont.deriveFont(Font.BOLD,(float)state.font18);
        } else {
            labfont = state.sanSerifFont.deriveFont((float)state.font11);
            titlefont = state.sanSerifFont.deriveFont(Font.BOLD,(float)state.font16);
        }

        setFont(labfont);

        setBackground(bgcolor);
        titlelabel = new Label("   Output",Label.LEFT);
        add(titlelabel);
        titlelabel.setBounds(state.s5,state.s5,state.s95,state.s20);    
        titlelabel.setFont(titlefont);

        //take out backpanel for chooser
        Panel ps1 = new Panel();
        ps1.setBackground(Color.cyan);
        ps1.setBounds(153,4,104,24);

        Panel ps2 = new Panel();
        ps2.setBackground(Color.black);
        ps2.setBounds(152,3,106,26);
        //-----------------------------------
        rwocA = new NewOutputCanvasA(state);
        add(rwocA);
        rwocA.setBounds(state.s5,state.s30,state.s285,state.s252);

        rwocB = new NewOutputCanvasB(state);
        add(rwocB);
        rwocB.setBounds(state.s5,state.s30,state.s285,state.s252);

        rwocA.setVisible(true);
        rwocB.setVisible(false);	    
    }
	
public void paint(Graphics g){
	
	g.setColor(bgcolor.darker());
	g.fillRect(0,getSize().height-2,getSize().width,2);
	g.fillRect(getSize().width-2,0,2,getSize().height);
	g.setColor(bgcolor.brighter());
	g.fillRect(0,0,2,getSize().height-1);
	g.fillRect(0,0,getSize().width-2,2);
	
        g.setColor(Color.black);
        g.drawRect(0,0,getSize().width-1,getSize().height-1);
    }
}

class NewOutputCanvasA extends Canvas{
    //private static final Font normalfont = new Font("SanSerif",Font.PLAIN,11);
    //private static final Font titlefont = new Font("SanSerif",Font.PLAIN,12);
    //private static final Font symbolfont=new Font("Serif",Font.PLAIN,14);
    //private static final Font subfont    = new Font("SanSerif",Font.PLAIN,10);
    private Font normalfont;
    private Font titlefont;
    private Font symbolfont;
    private Font subfont;
    NewGuide_State state;
    private Image im;
    private Graphics buf;
    DecimalFormat dec = new DecimalFormat("0.######"); //"0.###E0"

	public NewOutputCanvasA(NewGuide_State state){
	    super();
	    this.state = state;
            if (MaestroG.useBiggerFont) {
                normalfont = state.sanSerifFont.deriveFont((float)state.font13);
                titlefont = state.sanSerifFont.deriveFont((float)state.font14);
                symbolfont = state.serifFont.deriveFont((float)state.font16);
                subfont = state.sanSerifFont.deriveFont((float)state.font12);
            } else {
                normalfont = state.sanSerifFont.deriveFont((float)state.font11);
                titlefont = state.sanSerifFont.deriveFont((float)state.font12);
                symbolfont = state.serifFont.deriveFont((float)state.font14);
                subfont = state.sanSerifFont.deriveFont((float)state.font10);
            }
	}
	
	public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawCanvas(buf);
	    }
	    else{
		drawCanvas(buf);
	    }
	    g.drawImage(im,0,0,null);
	}

	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}
	
	public void clear(){
	    this.getGraphics().clearRect(0,0,getSize().width,getSize().height);
	    repaint();
	}
	
	public void drawCanvas(Graphics g){
            
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
	    int x, y, dx, dxx, dy, dyy;
	    double v_normalized, f_normalized;
	    Color bgcolor = new Color(236,236,236);
	    String stmp;
	    FontMetrics fm;
	    
	    x = 0;
	    y = state.s20;
	    dx = state.s80;
	    dxx = state.s15;
	    g.setFont(titlefont);
	    fm = g.getFontMetrics();
	    dy = state.s14;
	    dyy = dy+state.s2;
	    
	    g.setColor(bgcolor);
	    g.fillRect(0,0,getSize().width,getSize().height);
	    
	    g.setColor(Color.blue);
	    g.drawString("Structure Data",x+state.s10,y);
	    
            g.setFont(normalfont);
	    fm = g.getFontMetrics();
            y+=dyy;
            g.setColor(Color.black);
            g.drawString("      w",x,y);
            g.drawString("   =  "+dec.format(state.w)+" [mm]",x+state.s25,y);
	    
            //g.drawString("   t",x+150,y);
            //g.drawString("   =  "+MaestroA.rounder(state.b)+" [mm]",x+175,y);
            y+=dy;
	    
            g.drawString("      h",x,y);
            g.drawString("   =  "+dec.format(state.a)+" [mm]",x+state.s25,y);
            
	    if(state.w !=0.0 && state.a == 0.0){
                g.drawString(" w/h",x+state.s150,y);
                MaestroG.subscripterInfinityThree(" =  ","","","","",g,state.font12,x+state.s175,y);
            }
            else{
                g.drawString(" w/h",x+state.s150,y);
                g.drawString("  =  "+dec.format(state.w/state.a),x+state.s175,y);
            }
            y+=state.s4;
	    
	    //frequency results
	    g.setColor(Color.red);
	    g.drawLine(state.s5,y+dyy/4,getSize().width-state.s15,y+dyy/4);
	    y+=dyy;
	    y+=state.s4;
	    
            //g.setFont(titlefont);
	    //fm = g.getFontMetrics();
	    //g.setColor(Color.blue);
	  
	    g.setColor(Color.black);
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    //y+=dyy;
	    
	    //stmp = "( 0 )";
	    stmp = "";
	    MaestroG.subscripter("   Z","0",stmp,g,state.font12,x,y);
	    //System.out.println("Zo = "+state.Z0_0+"     K = "+state.K);
	    if(state.w > 0.0 && state.a > 0.0){
		g.drawString(" =  "+dec.format(state.Z0)+"          ",x+state.s30,y);
                if(MaestroG.useBiggerFont) {
                    g.setFont(state.serifFont.deriveFont((float)state.font15));
                }
                else{
                    g.setFont(state.serifFont.deriveFont((float)state.font13));
                }
		g.drawString("[ \u03a9 ]",fm.stringWidth(" =  "+dec.format(state.Z0)+"    [ ")+x+state.s30,y);
		g.setFont(normalfont);
	    }
	    else if(state.w == 0.0 && state.a == 0.0){
		//g.drawString(" =  0    [      ]",x+state.s30,y);
                if(MaestroG.useBiggerFont) {
                    g.setFont(state.serifFont.deriveFont((float)state.font15));
                }
                else{
                    g.setFont(state.serifFont.deriveFont((float)state.font13));
                }
		g.drawString(" =  0    [ \u03a9 ]",x+state.s30,y);
                //g.drawString("\u03a9",fm.stringWidth(" =  0     [ ")+x+state.s30,y);
		g.setFont(normalfont);
	    }
            else if(state.w > 0.0 && state.a == 0.0){
		//g.drawString(" =  0    [      ]",x+state.s30,y);
                if (MaestroG.useBiggerFont) {
                    g.setFont(state.serifFont.deriveFont((float)state.font15));
                } else {
                    g.setFont(state.serifFont.deriveFont((float)state.font13));
                }
                g.drawString(" =  0    [ \u03a9 ]",x+state.s30,y);
                //g.drawString("\u03a9",fm.stringWidth(" =  0     [ ")+x+state.s30,y);
		g.setFont(normalfont);
	    }
	    else if(state.w == 0.0 && state.a > 0.0){
		MaestroG.subscripterInfinityThree(" =  ","","","","            [ \u03a9 ]",g,state.font12,x+state.s30,y);
                g.setFont(normalfont);
	    }
	    
	    y+=dyy;
	    stmp = "";
	    MaestroG.subscripter("\u03b5","r,eff",stmp,g,state.font12,fm.stringWidth("  "),y);
	    
	    if(state.a > 0.0){
		g.drawString(" =  "+dec.format(state.epsilon_eff_f),x+state.s30,y);
	    }
	    else if(state.a == 0.0){
		g.drawString(" =  undefined",x+state.s30,y); 
	    }
	    
	    y+=dyy;
	    v_normalized = state.phase_velocity/1.0E8;
	    stmp="";
	    MaestroG.subscripter("    u","p",stmp,g,state.font12,x,y);
	    if(state.a > 0.0){
		g.drawString(" =  "+dec.format(v_normalized),x+state.s30,y);
		stmp = " m/s ]";
		MaestroG.superscripter("   [ 10","8",stmp,g,state.font12,x+state.s100,y);
	    }
	    else if(state.a == 0.0){
		g.drawString(" =  undefined",x+state.s30,y);
	    }
	    
	    y+=dyy;
	    stmp = "";
	    MaestroG.subscripterSymFirst2("    \u03bb","",stmp,g,state.font12,x,y);
	    
	    if(state.a > 0.0){
		g.drawString(" =  "+dec.format(state.guide_wavelength)+"      [ m ]",x+state.s30,y);
	    }
	    else if(state.a == 0.0){
		g.drawString(" =  undefined",x+state.s30,y);
	    }
	    y+=state.s4;
	    
	    //Line parameters, etc. ----------------------------------

	    g.setColor(Color.red);
	    g.drawLine(state.s5,y+dyy/4,getSize().width-state.s15,y+dyy/4);
	    y+=dyy;
	    y+=state.s4;
	    //g.setColor(Color.blue);
	    g.setColor(Color.red);

            stmp=Character.toString((char)0x00b4);

            double tempcap;
            double capacitance = getCapacitance();

	    if(capacitance < 1.0E-9){
		tempcap = capacitance/1.0E-12;
                MaestroG.subscripter("   C","",stmp,g,state.font12,x,y);
		g.drawString("  =  "+dec.format(tempcap),x+state.s25,y);
		g.drawString("[ pF/m ]",x+state.s225,y);
	    }
	    else if(capacitance < 1.0E-6 && capacitance >= 1.0E-9){
		tempcap = capacitance/1.0E-9;
                MaestroG.subscripter("   C","",stmp,g,state.font12,x,y);
		g.drawString("  =  "+dec.format(tempcap),x+state.s25,y);
		g.drawString("[ nF/m ]",x+state.s225,y);
	    }
	    else if(capacitance >= 1.0E-6 && (state.a != state.w)){
		tempcap = capacitance/1.0E-6;
                MaestroG.subscripter("   C","",stmp,g,state.font12,x,y);
		g.drawString("  =  "+dec.format(tempcap),x+state.s25,y);
		g.drawString("[   F/m ]",x+state.s225,y);
		g.setFont(new Font("Serif",Font.PLAIN,state.font12));
		g.drawString("\u03bc",x+state.s230,y);
		g.setFont(new Font("SanSerif",Font.PLAIN,state.font12));
	    }
            else if(state.Z0_0 == 0.0 || state.epsilon_eff == 0.0){
                MaestroG.subscripter("   C","",stmp,g,state.font12,x,y);
                MaestroG.subscripterInfinityThree("  = ","","","","",g,state.font12,x+state.s25,y);
                g.drawString("[ F/m ]",x+state.s225,y);
            }
	    
	    y+=dyy;

            double tempind;
            double inductance = getInductance(capacitance);
	    
	    if(inductance < 1.0E-9){
		tempind = inductance/1.0E-12;
                MaestroG.subscripter("   L","",stmp,g,state.font12,x,y);
		g.drawString("  =  "+dec.format(tempind),x+state.s25,y);
		g.drawString("[ pH/m ]",x+state.s225,y);
	    }	
	    else if(inductance < 1.0E-6 && inductance >= 1.0E-9){
		tempind = inductance/1.0E-9;
                MaestroG.subscripter("   L","",stmp,g,state.font12,x,y);
		g.drawString("  =  "+dec.format(tempind),x+state.s25,y);
		g.drawString("[ nH/m ]",x+state.s225,y);
	    }	
	    else if(inductance < 1.0E-3 && inductance >= 1.0E-6){
		tempind = inductance/1.0E-6;
                MaestroG.subscripter("   L","",stmp,g,state.font12,x,y);
		g.drawString("  =  "+dec.format(tempind),x+state.s25,y);
		g.drawString("[   H/m ]",x+state.s225,y);
		g.setFont(new Font("Serif",Font.PLAIN,state.font12));
		g.drawString("\u03bc",x+state.s230,y);
		g.setFont(new Font("SanSerif",Font.PLAIN,state.font12));
	    }
	    else if(inductance >= 1.0E-3 && state.w != 0.0){
		tempind = inductance/1.0E-3;
                MaestroG.subscripter("   L","",stmp,g,state.font12,x,y);
		g.drawString("  =  "+dec.format(tempind),x+state.s25,y);
		g.drawString("[ mH/m ]",x+state.s225,y);
	    }
            else if(state.w == 0.0){
                MaestroG.subscripter("   L","",stmp,g,state.font12,x,y);
		MaestroG.subscripterInfinityThree("  = ","","","","",g,state.font12,x+state.s25,y);
		g.drawString("[ H/m ]",x+state.s225,y);
	    }
	    
	    y+=dyy;

            MaestroG.subscripter("   R","",stmp,g,state.font12,x,y);
            g.drawString("  =  0",x+state.s25,y);

	    //if(state.w!=0.0){
            //    MaestroG.subscripter("R","",stmp,g,12,x,y);
            //    g.drawString(" =  "+dec.format(state.Resistance),x+25,y);
            //    
            //}
            //else if(state.w == 0.0){
            //    MaestroG.subscripter("R","",stmp,g,12,x,y);
            //	MaestroG.subscripterInfinityThree(" = ","","","","",g,12,x+25,y);
            //
	    //}
            g.drawString("[     /m ]",x+state.s225,y);
            if (MaestroG.useBiggerFont) {
                g.setFont(state.serifFont.deriveFont((float)state.font15));
            } else {
                g.setFont(state.serifFont.deriveFont((float)state.font13));
            }
            g.drawString("\u03a9",x+state.s230,y);
            if (MaestroG.useBiggerFont) {
                g.setFont(new Font("SanSerif",Font.PLAIN,state.font14));
            } else {
                g.setFont(new Font("SanSerif",Font.PLAIN,state.font12));
            }
                
	    y+=dyy;
            MaestroG.subscripter("   G","",stmp,g,state.font12,x,y);
	    g.drawString("  =  0",x+state.s25,y);
	    g.drawString("[ S/m ]",x+state.s225,y);
	    
	    y+=4;
	    g.setColor(Color.red);
	    g.drawLine(state.s5,y+dyy/4,getSize().width-state.s15,y+dyy/4);
	    y+=state.s4;   
	    y+=dyy;

            g.drawString("   \u03b1",x+state.s5,y);
            g.drawString("  =  0",x+state.s25,y);
            g.drawString("[ Np/m ]",x+state.s225,y);
	    
            g.setColor(Color.blue);
	    y+=dyy;
	    y+=state.s2;
            double beta = getBeta();
            g.drawString("   \u03b2",x+state.s5,y);
            g.drawString("  =  "+dec.format(beta),x+state.s25,y);
            g.drawString("[rad/m ]",x+state.s225,y);
	}
    
    
    private double getCapacitance() {
        double c;
        
        //if(state.Z0_0 == 0.0 || state.epsilon_eff == 0.0){
        //    c = 1.0E99;
        //} else {
        //    c = 3.0E8/(state.Z0_0*Math.sqrt(state.epsilon_eff));
        //}

        if(state.Z0_0 == 0.0) {
            c = 1.0E99;
        } else {
            c = Math.sqrt(state.epsilon_eff_f) / (state.Z0_0 * 3.0E8);
        }
        return c;
    }
    
    
    private double getInductance(double capacitance) {
        double i;
        
        i = state.Z0*state.Z0*capacitance;
        return i;
    }
    
    
    private double getBeta() {
        double b;
        
        b = 2.0*Math.PI*state.frequency*Math.sqrt(state.epsilon_eff);
        b /= 3.0E8;
        return b;
    }

}

// This option is not used in the book version of the Application
// Scaling has not been applied in the code below
class NewOutputCanvasB extends Canvas{
	//private static final Font normalfont = new Font("SanSerif",Font.PLAIN,12);
	//private static final Font symbolfont = new Font("Symbol",Font.PLAIN,14);
	//private static final Font subfont    = new Font("SanSerif",Font.PLAIN,10);
	NewGuide_State state;
	private Image im;
	private Graphics buf;
        DecimalFormat dec = new DecimalFormat("0.###E0");
        
    private BufferedImage infinity;
	
        public NewOutputCanvasB(NewGuide_State state){
	    super();
	    this.state = state;
	    getImages();
	}


    private void getImages() {
        // read in the nabla images, because CHEERPJ does not render this
	//  symbol in any font!  (java to javascript converter)
        try {
            //infinity = ImageIO.read(getClass().getResource("infinity.png"));
	    BufferedImage img =
		ImageIO.read(getClass().getResource("infinity.png"));
	    int targetWidth = (int) (state.sfactor * img.getWidth());
	    int targetHeight = (int) (state.sfactor * img.getHeight());
	    infinity =
		new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
	    Graphics2D graphics2D = infinity.createGraphics();
	    graphics2D.drawImage(img, 0, 0, targetWidth, targetHeight, null);
	    graphics2D.dispose();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
	
	public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawCanvas(buf);
	    }
	    else{
		drawCanvas(buf);
	    }
	    g.drawImage(im,0,0,null);
	}

	//Addition to reduce flicker new routine
	public void update(Graphics g){		// added to avoid clearing
	    paint(g);
	}
	
	public void clear(){
	    this.getGraphics().clearRect(0,0,getSize().width,getSize().height);
	    repaint();
	}


	
	public void drawCanvas(Graphics g){
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            Font normalfont = new Font("SanSerif",Font.PLAIN,state.font12);
            Font symbolfont = new Font("Symbol",Font.PLAIN,state.font14);
            Font subfont    = new Font("SanSerif",Font.PLAIN,state.font10);
            
	    int x, y, dx, dxx, dy, dyy;
	    double v_normalized, f_normalized;
	    //Color bgcolor = Color.lightGray;
	    Color bgcolor = new Color(236,236,236);
	    String stmp;
	    FontMetrics fm;
	    
	    x = state.s10;
	    y = state.s15;
	    dx = state.s80;
	    dxx = state.s15;
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = state.s15;
	    dyy = dy + state.s2;
	    
	    g.setColor(bgcolor);
	    g.fillRect(0,0,getSize().width,getSize().height);
	    g.setColor(Color.blue);
	  if(state.a > 0.0){
	    g.drawString("Dispersion limit = Quasi-TEM assumption valid",x,y);
	    y+=dyy;
	    g.drawString("when  ",x,y);
	    g.setColor(Color.black);
	    
	    if(state.frequency_c < 1.0E3){
		    f_normalized = state.frequency_c;
		    stmp= " \u007e  "+dec.format(f_normalized)+"   [ Hz ]";
		    MaestroG.subscripter("            f < f","crit",stmp,g,state.font12,x,y);
		}
		else if(state.frequency_c < 1.0E6 && state.frequency_c >= 1.0E3  ){
		    f_normalized = state.frequency_c/1.0E3;
		    stmp = " \u007e  "+dec.format(f_normalized)+"   [ kHz ]";
		    MaestroG.subscripter("            f < f","crit",stmp,g,state.font12,x,y);
		}
		else if(state.frequency_c < 1.0E9 && state.frequency_c >= 1.0E6 ){
		    f_normalized = state.frequency_c/1.0E6;
		    stmp = " \u007e  "+dec.format(f_normalized)+"   [ MHz ]";
		    MaestroG.subscripter("            f < f","crit",stmp,g,state.font12,x,y);
		}
		else if(state.frequency_c < 1.0E12 && state.frequency_c >= 1.0E9 ){
		    f_normalized = state.frequency_c/1.0E9;
		    stmp = " \u007e  "+dec.format(f_normalized)+"   [ GHz ]";
		    MaestroG.subscripter("            f < f","crit",stmp,g,state.font12,x,y);
		}
		else if(state.frequency_c < 1.0E200 && state.frequency_c >= 1.0E12 ){
		    f_normalized = state.frequency_c/1.0E12;
		    stmp = " \u007e  "+dec.format(f_normalized)+"   [ THz ]";
		    MaestroG.subscripter("            f < f","crit",stmp,g,state.font12,x,y);
		}
		else{
		    stmp = " \u007e  ";
		    MaestroG.subscripterInfinityThree("            f < f","crit",stmp,"","  [ Hz ]",g,state.font12,x,y);
		}
	      }
	      else{
		    g.drawString("Dispersion limit: substrate thickness h =0",x,y);
		    y+=dyy;
		    
		    g.setColor(Color.black);
		    g.drawString("  \u2794  Undefined frequency range",x,y);
	      }
	    
	    y+=dyy;
	    
	    g.setColor(Color.magenta);
	  if(state.a > 0.0){
	    g.drawString("Strong coupling with TM surface mode",x,y);
	    y+=dyy;
	    g.drawString("when  ",x,y);
	    
	    g.setColor(Color.black);
	    
	    if(state.frequency_surf < 1.0E3){
		    f_normalized = state.frequency_surf;
		    stmp= " \u007e  "+dec.format(f_normalized)+"   [ Hz ]";
		    MaestroG.subscripter("            f > f","TM",stmp,g,state.font12,x,y);
		}
		else if(state.frequency_surf < 1.0E6 && state.frequency_surf >= 1.0E3  ){
		    f_normalized = state.frequency_surf/1.0E3;
		    stmp = " \u007e  "+dec.format(f_normalized)+"   [ kHz ]";
		    MaestroG.subscripter("            f > f","TM",stmp,g,state.font12,x,y);
		}
		else if(state.frequency_surf < 1.0E9 && state.frequency_surf >= 1.0E6 ){
		    f_normalized = state.frequency_surf/1.0E6;
		    stmp = " \u007e  "+dec.format(f_normalized)+"   [ MHz ]";
		    MaestroG.subscripter("            f > f","TM",stmp,g,state.font12,x,y);
		}
		else if(state.frequency_surf < 1.0E12 && state.frequency_surf >= 1.0E9 ){
		    f_normalized = state.frequency_surf/1.0E9;
		    stmp = " \u007e  "+dec.format(f_normalized)+"   [ GHz ]";
		    MaestroG.subscripter("            f > f","TM",stmp,g,state.font12,x,y);
		}
		else if(state.frequency_surf < 1.0E200 && state.frequency_surf >= 1.0E12 ){
		    f_normalized = state.frequency_surf/1.0E12;
		    stmp = " \u007e  "+dec.format(f_normalized)+"   [ THz ]";
		    MaestroG.subscripter("            f > f","TM",stmp,g,state.font12,x,y);
		}
		else{
		    stmp = " \u007e         [ Hz ]";
		    MaestroG.subscripter("            f > f","TM",stmp,g,state.font12,x,y);
		    g.setFont(symbolfont);
		    //g.drawString("\u221e",x+fm.stringWidth("            f < fTM     "),y);
		    g.drawImage(infinity,x+fm.stringWidth("            f < fTM     "),y,this);
		    g.setFont(normalfont);
		}
	    }
	    else{
		   g.drawString("Coupling with TM mode: ",x,y);
		   y+=dyy;
		    
		   g.setColor(Color.black);
		   g.drawString("  h = 0  -  Undefined frequency range",x,y);
	    }
	    y+=dyy;
	    
	    g.setColor(Color.black);
	    if(!state.IsMilsOn){
                stmp = " \u007e "+dec.format(state.maximum_h)+" [ mm ] (present frequency)";
                MaestroG.subscripter("h","max",stmp,g,state.font12,x,y);
	    }
	    else{
		stmp = " \u007e "+dec.format(state.maximum_h/0.0254)+" [mils] (present frequency)";
		MaestroG.subscripter("h","max",stmp,g,state.font12,x,y);
	    }
	    y+=state.s2;
	    g.setColor(Color.red);
	    g.drawLine(state.s5,y+dyy/4,getSize().width-state.s15,y+dyy/4);
	    y+=dyy;
	    y+=state.s2;
	    
	    g.setColor(Color.blue);
	    g.drawString("Loss tangent  ",x,y);
	    //y+=dyy;
	    g.setColor(Color.black);
	    stmp="";
	    MaestroG.subscripterSanSym2("tan","","","\u03b4",g,state.font12,x+state.s100,y);
	    
	    if(state.loss_tangent > 1.0e-5){
		stmp=" = "+dec.format(state.loss_tangent);
	    }
	    else{
		stmp=" = "+dec.format(state.loss_tangent);
	    }
	    MaestroG.subscripter("","",stmp,g,state.font12,x+state.s130,y);
	    
	    y+=dyy;
	    g.setColor(Color.blue);
	    g.drawString("Metal Skin Depth  ",x,y);
	    
	    g.setColor(Color.black);
	    if(!state.IsMilsOn){
		stmp = "";
                MaestroG.subscripterSymFirst2("\u03b4","s",stmp,g,state.font14,x+state.s110,y);
		
		stmp = " = "+dec.format(state.skin_depth*1000.0)+" [ mm ]";
		MaestroG.subscripter("","",stmp,g,state.font12,x+state.s130,y);
	    }
	    else{
		stmp = "";
		MaestroG.subscripterSymFirst2("\u03b4","s",stmp,g,state.font14,x+state.s110,y);
		stmp = " = "+dec.format(state.skin_depth*1000.0/0.0254)+" [mils]";
		MaestroG.subscripter("","",stmp,g,state.font12,x+state.s130,y);
	    }
	    y+=dyy;
	    g.setColor(Color.blue);
	    g.drawString("Sheet Resistance",x,y);
	    g.setColor(Color.black);
	    stmp = "";
	    MaestroG.subscripter("R","s",stmp,g,state.font12,x+state.s110,y);
	    stmp = " = "+dec.format(state.Resistance);
	    MaestroG.subscripter("","",stmp,g,state.font12,x+state.s130,y);
            if (MaestroG.useBiggerFont) {
                g.setFont(state.serifFont.deriveFont((float)state.font15));
            } else {
                g.setFont(state.serifFont.deriveFont((float)state.font13));
            }
	    g.drawString("[ \u03a9/sq ]",x+state.s130+fm.stringWidth(" = "+dec.format(state.Resistance)+" [ "),y);
	    g.setFont(normalfont);
		    	    
	    
	    y+=state.s2;
	    g.setColor(Color.red);
	    g.drawLine(5,y+dyy/4,getSize().width-state.s15,y+dyy/4);
	    y+=dyy;
	    y+=state.s2;
	    	   
	    g.setColor(Color.blue);
	    g.drawString("Power attenuation",x,y);
	    
	   // y+=dyy;
	    g.setColor(Color.black);
	    //g.drawString("P(z)",x+115,y);
	    stmp = " z )";
	    MaestroG.subscripter("P(z) = P(0) exp(-2 \u03b1","tot",stmp,g,state.font12,x+state.s110,y);
	    
	    g.setFont(normalfont);
	    	    
	    y+=dyy;
	    g.setColor(Color.blue);
	    g.drawString("where",x+state.s80,y);
	    g.setColor(Color.black);
	    stmp=" = ";
	    MaestroG.subscripterSymFirst2("\u03b1","tot",stmp,g,state.font12,x+state.s125,y);
	    stmp = " + ";
	    MaestroG.subscripterSymFirst2("\u03b1","d",stmp,g,state.font12,x+state.s165,y);
	    stmp="";
	    MaestroG.subscripterSymFirst2("\u03b1","c",stmp,g,state.font12,x+state.s195,y);
	    g.setFont(normalfont);
	    
            y+=dyy;
	    g.setColor(Color.red);
	    g.drawString("Dielectric loss attenuation",x,y);
	    g.setColor(Color.black);
	    y+=dyy;
	    stmp = " = "+dec.format(state.alpha_d)+" [ db/m ] = "
			+dec.format(state.alpha_d/8.686)+" [ Ne/m ]";
	    MaestroG.subscripterSymFirst2("\u03b1","d",stmp,g,state.font12,x+state.s10,y);
	    
	    y+=dyy;
	    
	    g.setColor(Color.red);
	    g.drawString("Conductor loss attenuation",x,y);
	    g.setColor(Color.black);
	    y+=dyy;
	    if(state.b==0.0){
		MaestroG.subscripter("\u03b1","c"," = Undefined",g,state.font12,x,y);
	    }
	    else{
		stmp = " = "+dec.format(state.alpha_c)+" [ db/m ] = "
			    +dec.format(state.alpha_c/8.686)+" [ Ne/m ]";
		MaestroG.subscripterSymFirst2("\u03b1","c",stmp,g,state.font12,x+state.s10,y);
		
	    }
    }

	    
}
