//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.awt.event.*;
import java.applet.*;
import java.lang.*;  
import java.awt.image.*;
import java.net.*;
import java.text.*;

public class NewGuideOutputPanel extends Panel {
	NewGuide_State state;
	//private static final Color bgcolor = Color.lightGray;
	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 static  Font labfont;
    private static  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(13F);
                titlefont = state.sanSerifFont.deriveFont(Font.BOLD,18F);
            } else {
                labfont = state.sanSerifFont.deriveFont(11F);
                titlefont = state.sanSerifFont.deriveFont(Font.BOLD,16F);
            }

            setFont(labfont);  //??

	    setBackground(bgcolor);
	    titlelabel = new Label("   Output",Label.LEFT);
	    add(titlelabel);
	    titlelabel.setBounds(5,5,95,20);    
	    titlelabel.setFont(titlefont);
	    	    
            //take out backpanel for chooser
	    Panel ps1 = new Panel();
	    ps1.setBackground(Color.cyan);
	    //add(ps1);
	    ps1.setBounds(153,4,104,24);
	    
	    Panel ps2 = new Panel();
	    ps2.setBackground(Color.black);
	    //add(ps2);
	    ps2.setBounds(152,3,106,26);
	    //-----------------------------------
	    rwocA = new NewOutputCanvasA(state);
	    //pane1.add(rwocA);
	    add(rwocA);
	    rwocA.setBounds(5,30,285,252);
	    
	    rwocB = new NewOutputCanvasB(state);
	    //pane2.add(rwocB);
	    add(rwocB);
	    rwocB.setBounds(5,30,285,252);
	    
	    rwocA.setVisible(true);
	    rwocB.setVisible(false);
	    //pane1.setVisible(true);
	    //pane2.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);
	
    }
}

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 static Font normalfont;
    private static Font titlefont;
    private static Font symbolfont;
    private static 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(13f);
                titlefont = state.sanSerifFont.deriveFont(14f);
                symbolfont = state.serifFont.deriveFont(16f);
                subfont = state.sanSerifFont.deriveFont(12f);
            } else {
                normalfont = state.sanSerifFont.deriveFont(11f);
                titlefont = state.sanSerifFont.deriveFont(12f);
                symbolfont = state.serifFont.deriveFont(14f);
                subfont = state.sanSerifFont.deriveFont(10f);
            }
	}
	
	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 = Color.lightGray;
	    Color bgcolor = new Color(236,236,236);
	    String stmp;
	    FontMetrics fm;
	    
	    x = 0;
	    y = 20;
	    dx = 80;
	    dxx = 15;
	    g.setFont(titlefont);
	    fm = g.getFontMetrics();
	    //dy = 15;
	    //dyy = dy+2;
	    dy = 14;
	    dyy = dy+2;
	    
	    g.setColor(bgcolor);
	    g.fillRect(0,0,getSize().width,getSize().height);
	    
	    g.setColor(Color.blue);
	    g.drawString("Structure Data",x+10,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+25,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+25,y);
            
	    if(state.w !=0.0 && state.a == 0.0){
                g.drawString(" w/h",x+150,y);
                MaestroG.subscripterInfinityThree(" =  ","","","","",g,12,x+175,y);
            }
            else{
                g.drawString(" w/h",x+150,y);
                g.drawString("  =  "+dec.format(state.w/state.a),x+175,y);
            }
            y+=4;
	    
	    //Low frequency results

	    g.setColor(Color.red);
	    g.drawLine(5,y+dyy/4,getSize().width-15,y+dyy/4);
	    y+=dyy;
	    y+=4;
	    
            //g.setFont(titlefont);
	    //fm = g.getFontMetrics();
	    //g.setColor(Color.blue);
	    //g.drawString("Low Frequency",x+10,y);
	    g.setColor(Color.black);
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    //y+=dyy;
	    
	    //stmp = "( 0 )";
	    stmp = "";
	    MaestroG.subscripter("   Z","0",stmp,g,12,x,y);
	    
	    if(state.w > 0.0 && state.a > 0.0){
		g.drawString(" =  "+dec.format(state.Z0_0)+"          ",x+30,y);
                if (MaestroG.useBiggerFont) {
                    g.setFont(state.serifFont.deriveFont(15f));
                } else {
                    g.setFont(state.serifFont.deriveFont(13f));
                }
		g.drawString("[ \u03a9 ]",fm.stringWidth(" =  "+dec.format(state.Z0_0)+"    [ ")+x+30,y);
		g.setFont(normalfont);
	    }
	    else if(state.w == 0.0 && state.a == 0.0){
		g.drawString(" =  0    [      ]",x+30,y);
                if (MaestroG.useBiggerFont) {
                    g.setFont(state.serifFont.deriveFont(15f));
                } else {
                    g.setFont(state.serifFont.deriveFont(13f));
                }
		g.drawString("\u03a9",fm.stringWidth(" =  0     [ ")+x+30,y);
		g.setFont(normalfont);
	    }
            else if(state.w > 0.0 && state.a == 0.0){
		g.drawString(" =  0    [      ]",x+30,y);
                if (MaestroG.useBiggerFont) {
                    g.setFont(state.serifFont.deriveFont(15f));
                } else {
                    g.setFont(state.serifFont.deriveFont(13f));
                }
		g.drawString("\u03a9",fm.stringWidth(" =  0     [ ")+x+30,y);
		g.setFont(normalfont);
	    }
	    else if(state.w == 0.0 && state.a > 0.0){
		MaestroG.subscripterInfinityThree(" =  ","","","","            [ \u03a9 ]",g,12,x+30,y);
                g.setFont(normalfont);
	    }
	    
	    y+=dyy;
	    stmp = "";
	    MaestroG.subscripter("\u03b5","eff",stmp,g,12,fm.stringWidth("  "),y);
	    
	    if(state.a > 0.0){
		g.drawString(" =  "+dec.format(state.epsilon_eff),x+30,y);
	    }
	    else if(state.a == 0.0){
		g.drawString(" =  undefined",x+30,y); 
	    }
	    
	    y+=dyy;
	    v_normalized = state.phase_velocity0/1.0E8;
	    stmp="";
	    MaestroG.subscripter("    u","p",stmp,g,12,x,y);
	    if(state.a > 0.0){
		g.drawString(" =  "+dec.format(v_normalized),x+30,y);
		stmp = " m/s ]";
		MaestroG.superscripter("   [ 10","8",stmp,g,12,x+100,y);
	    }
	    else if(state.a == 0.0){
		g.drawString(" =  undefined",x+30,y);
	    }
	    
	    y+=dyy;
	    stmp = "";
	    MaestroG.subscripterSymFirst2("    \u03bb","",stmp,g,12,x,y);
	    
	    if(state.a > 0.0){
		g.drawString(" =  "+dec.format(state.guide_wavelength0)+"      [ m ]",x+30,y);
	    }
	    else if(state.a == 0.0){
		g.drawString(" =  undefined",x+30,y);
	    }
	    y+=4;
	    
	    //Line parameters, etc. ----------------------------------

	    g.setColor(Color.red);
	    g.drawLine(5,y+dyy/4,getSize().width-15,y+dyy/4);
	    y+=dyy;
	    y+=4;
	    //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,12,x,y);
		//g.drawString("  =  "+dec.format(tempcap),x+25,y);
		g.drawString("  =  "+dec.format(tempcap),x+25,y);
		g.drawString("[ pF/m ]",x+225,y);
	    }
	    else if(capacitance < 1.0E-6 && capacitance >= 1.0E-9){
		tempcap = capacitance/1.0E-9;
                MaestroG.subscripter("   C","",stmp,g,12,x,y);
		//g.drawString("  =  "+dec.format(tempcap),x+25,y);
		g.drawString("  =  "+dec.format(tempcap),x+25,y);
		g.drawString("[ nF/m ]",x+225,y);
	    }
	    else if(capacitance >= 1.0E-6 && (state.a != state.w)){
		tempcap = capacitance/1.0E-6;
                MaestroG.subscripter("   C","",stmp,g,12,x,y);
		//g.drawString("  =  "+dec.format(tempcap),x+25,y);
		g.drawString("  =  "+dec.format(tempcap),x+25,y);
		g.drawString("[   F/m ]",x+225,y);
		g.setFont(new Font("Serif",Font.PLAIN,12));
		g.drawString("\u03bc",x+230,y);
		g.setFont(new Font("SanSerif",Font.PLAIN,12));
	    }
            else if(state.Z0_0 == 0.0 || state.epsilon_eff == 0.0){
                MaestroG.subscripter("   C","",stmp,g,12,x,y);
                MaestroG.subscripterInfinityThree("  = ","","","","",g,12,x+25,y);
                g.drawString("[ F/m ]",x+225,y);
            }
	    
	    y+=dyy;

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

            MaestroG.subscripter("   R","",stmp,g,12,x,y);
            g.drawString("  =  0",x+25,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+225,y);
            if (MaestroG.useBiggerFont) {
                g.setFont(state.serifFont.deriveFont(15f));
            } else {
                g.setFont(state.serifFont.deriveFont(13f));
            }
            g.drawString("\u03a9",x+230,y);
            if (MaestroG.useBiggerFont) {
                g.setFont(new Font("SanSerif",Font.PLAIN,14));
            } else {
                g.setFont(new Font("SanSerif",Font.PLAIN,12));
            }
                
	    y+=dyy;
            MaestroG.subscripter("   G","",stmp,g,12,x,y);
	    //g.drawString(" =  "+dec.format(state.Conductance),x+25,y);
	    g.drawString("  =  0",x+25,y);
	    g.drawString("[ S/m ]",x+225,y);
	    
	    y+=4;
	    g.setColor(Color.red);
	    g.drawLine(5,y+dyy/4,getSize().width-15,y+dyy/4);
	    y+=4;   
	    y+=dyy;

            g.drawString("   \u03b1",x+5,y);
		g.drawString("  =  0",x+25,y);
		g.drawString("[ Np/m ]",x+225,y);
	    
            g.setColor(Color.blue);
	    y+=dyy;
	    y+=2;
            double beta = getBeta();
            g.drawString("   \u03b2",x+5,y);
		g.drawString("  =  "+dec.format(beta),x+25,y);
		g.drawString("[rad/m ]",x+225,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) / (state.Z0_0 * 3.0E8);
        }
        return c;
    }
    
    
    private double getInductance(double capacitance) {
        double i;
        
        i = state.Z0_0*state.Z0_0*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;
    }

}
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");
	public NewOutputCanvasB(NewGuide_State state){
	    super();
	    this.state = state;
	}
	
	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 = Color.lightGray;
	    Color bgcolor = new Color(236,236,236);
	    String stmp;
	    FontMetrics fm;
	    
	    x = 10;
	    y = 15;
	    dx = 80;
	    dxx = 15;
	    g.setFont(normalfont);
	    fm = g.getFontMetrics();
	    dy = 15;
	    dyy = dy+2;
	    
	    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,12,x,y);
		    //g.drawString("    f  =  "+dec.format(f_normalized)+"   [ Hz ]",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,12,x,y);
		    //g.drawString("    f  =  "+dec.format(f_normalized)+"   [ kHz ]",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,12,x,y);
		    //g.drawString("    f  =  "+dec.format(f_normalized)+"   [ MHz ]",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,12,x,y);
		    //g.drawString("    f  =  "+dec.format(f_normalized)+"   [ GHz ]",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,12,x,y);
		    //g.drawString("    f  =  "+dec.format(f_normalized)+"   [ THz ]",x,y);	
		}
		else{
		    stmp = " \u007e  ";
		    //MaestroG.subscripter("            f < f","crit",stmp,g,12,x,y);
		    MaestroG.subscripterInfinityThree("            f < f","crit",stmp,"","  [ Hz ]",g,12,x,y);
		    //g.drawString("    f  =  \u221e",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,12,x,y);
		    //g.drawString("    f  =  "+dec.format(f_normalized)+"   [ Hz ]",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,12,x,y);
		    //g.drawString("    f  =  "+dec.format(f_normalized)+"   [ kHz ]",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,12,x,y);
		    //g.drawString("    f  =  "+dec.format(f_normalized)+"   [ MHz ]",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,12,x,y);
		    //g.drawString("    f  =  "+dec.format(f_normalized)+"   [ GHz ]",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,12,x,y);
		    //g.drawString("    f  =  "+dec.format(f_normalized)+"   [ THz ]",x,y);	
		}
		else{
		    stmp = " \u007e         [ Hz ]";
		    MaestroG.subscripter("            f > f","TM",stmp,g,12,x,y);
		    g.setFont(symbolfont);
		    g.drawString("\u221e",x+fm.stringWidth("            f < fTM     "),y);
		    g.setFont(normalfont);
		    //g.drawString("    f  =  \u221e",x,y);
		}
	      }
	      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,12,x,y);
	    }
	    else{
		stmp = " \u007e "+dec.format(state.maximum_h/0.0254)+" [mils] (present frequency)";
		MaestroG.subscripter("h","max",stmp,g,12,x,y);
	    }
	    y+=2;
	    g.setColor(Color.red);
	    g.drawLine(5,y+dyy/4,getSize().width-15,y+dyy/4);
	    y+=dyy;
	    y+=2;
	    
	    g.setColor(Color.blue);
	    g.drawString("Loss tangent  ",x,y);
	    //y+=dyy;
	    g.setColor(Color.black);
	    stmp="";
	    MaestroG.subscripterSanSym2("tan","","","\u03b4",g,12,x+100,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,12,x+130,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,14,x+110,y);
		
		stmp = " = "+dec.format(state.skin_depth*1000.0)+" [ mm ]";
		MaestroG.subscripter("","",stmp,g,12,x+130,y);
	    }
	    else{
		stmp = "";
		MaestroG.subscripterSymFirst2("\u03b4","s",stmp,g,14,x+110,y);
		stmp = " = "+dec.format(state.skin_depth*1000.0/0.0254)+" [mils]";
		MaestroG.subscripter("","",stmp,g,12,x+130,y);
	    }
	    y+=dyy;
	    g.setColor(Color.blue);
	    g.drawString("Sheet Resistance",x,y);
	    g.setColor(Color.black);
	    stmp = "";
	    MaestroG.subscripter("R","s",stmp,g,12,x+110,y);
	    stmp = " = "+dec.format(state.Resistance);
	    MaestroG.subscripter("","",stmp,g,12,x+130,y);
            if (MaestroG.useBiggerFont) {
                g.setFont(state.serifFont.deriveFont(15f));
            } else {
                g.setFont(state.serifFont.deriveFont(13f));
            }
	    g.drawString("[ \u03a9/sq ]",x+130+fm.stringWidth(" = "+dec.format(state.Resistance)+" [ "),y);
	    g.setFont(normalfont);
		    	    
	    
	    y+=2;
	    g.setColor(Color.red);
	    g.drawLine(5,y+dyy/4,getSize().width-15,y+dyy/4);
	    y+=dyy;
	    y+=2;
	    	   
	    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,12,x+110,y);
	    //g.setFont(new Font("Serif",Font.PLAIN,12));
	    //g.drawString("\u03b1",x+145+fm.stringWidth("  = P(0) exp( -2 "),y);
	    g.setFont(normalfont);
	    	    
	    y+=dyy;
	    g.setColor(Color.blue);
	    g.drawString("where",x+80,y);
	    g.setColor(Color.black);
	    stmp=" = ";
	    MaestroG.subscripterSymFirst2("\u03b1","tot",stmp,g,12,x+125,y);
	    stmp = " + ";
	    MaestroG.subscripterSymFirst2("\u03b1","d",stmp,g,12,x+165,y);
	    stmp="";
	    MaestroG.subscripterSymFirst2("\u03b1","c",stmp,g,12,x+195,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,12,x+10,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,12,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,12,x+10,y);
		
	    }
    }

	    
}
