// MaestroG.java
/* A Java class for
 * TwoWire.java
 * Electromagnetic Transmission Line Applet
 * Applet without Smith Chart - Prepared by Umberto Ravaioli 
 * for 6th edition of Fundamentals of Applied Electromagnetics Book
 * May 2009 - All Rights Reserved
 */   

import java.awt.*;
import java.lang.*;

public class MaestroG{
    public static boolean useBiggerFont = false;
    public static Font serifFont, sanSerifFont;
    MaestroG(){};
    //tipo=1 arrow up
    //
    public static final void drawArrow(int x, int y, int tipo, Graphics g){
        Graphics2D g2d = (Graphics2D)g;
        
	 switch (tipo){
	   case 1://ArrowUp
	  	g.drawLine(x,y,x,y-8);
		g.drawLine(x-3,y-2,x+3,y-2);
		g.drawLine(x-2,y-3,x+2,y-3);
		g.drawLine(x-2,y-4,x+2,y-4);
		g.drawLine(x-1,y-5,x+1,y-5);
		g.drawLine(x-1,y-6,x+1,y-6);
	   break;
	   case 2://Down
		g.drawLine(x,y,x,y+8);
		g.drawLine(x-1,y+6,x+1,y+6);
		g.drawLine(x-1,y+5,x+1,y+5);
		g.drawLine(x-2,y+4,x+2,y+4);
		g.drawLine(x-2,y+3,x+2,y+3);
		g.drawLine(x-3,y+2,x+3,y+2);
	   break;
	   case 3://ArrowRight
		g.drawLine(x,y,x+8,y);
		g.drawLine(x+6,y-1,x+6,y+1);
		g.drawLine(x+5,y-1,x+5,y+1);
		g.drawLine(x+4,y-2,x+4,y+2);
		g.drawLine(x+3,y-2,x+3,y+2);
		g.drawLine(x+2,y-3,x+2,y+3);
	   break;
	   case 4://ArrowLeft
		g.drawLine(x,y,x-8,y);
		g.drawLine(x-2,y-3,x-2,y+3);
		g.drawLine(x-3,y-2,x-3,y+2);
		g.drawLine(x-4,y-2,x-4,y+2);
		g.drawLine(x-5,y-1,x-5,y+1);
		g.drawLine(x-6,y-1,x-6,y+1); 
	  break;
          
           case 5://ArrowUpSmooth
               g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
                g.drawLine(x,y,x,y-8);
		//draw oblique arrow head
		Polygon pH = new Polygon();
		pH.addPoint(x-2, y-2);
		pH.addPoint(x+2, y-2);
		pH.addPoint(x,y-8);
		g.drawPolygon(pH);
		g.fillPolygon(pH);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        
          break;
          
          case 6://ArrowDownSmooth
               g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
                g.drawLine(x,y,x,y+8);
		//draw oblique arrow head
		Polygon pJ = new Polygon();
		pJ.addPoint(x-2, y+2);
		pJ.addPoint(x+2, y+2);
		pJ.addPoint(x,y+8);
		g.drawPolygon(pJ);
		g.fillPolygon(pJ);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
	   break;
           
           case 7://ArrowRightSmooth
               g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
                g.drawLine(x,y,x+8,y);
		//draw oblique arrow head
		Polygon pK = new Polygon();
		pK.addPoint(x+2, y-2);
		pK.addPoint(x+2, y+2);
		pK.addPoint(x+8,y);
		g.drawPolygon(pK);
		g.fillPolygon(pK);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
	   
	   break;
           
           case 8://ArrowLeftSmooth
               g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
                g.drawLine(x,y,x-8,y);
		//draw oblique arrow head
		Polygon pL = new Polygon();
		pL.addPoint(x-2, y-2);
		pL.addPoint(x-2, y+2);
		pL.addPoint(x-8,y);
		g.drawPolygon(pL);
		g.fillPolygon(pL);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
 
	   break;
           
           case 9://ArrowOblique 45 degrees NE
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
		//draw oblique arrow head
		Polygon pM = new Polygon();
                //draw oblique arrow head
                
                //pM.addPoint(x+6,y-6);
		//pM.addPoint(x-2,y-2);
		//pM.addPoint(x+2,y+2);
                
		pM.addPoint(x+5,y-5);
		pM.addPoint(x-1,y-2);
		pM.addPoint(x+2,y+1);
		
                g.drawPolygon(pM);
		g.fillPolygon(pM);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
                 
           break;
	}		
    }  
    
    public static void addComponent(Container container, Component component, int gridx, int gridy,
	int gridwidth, int gridheight, int fill, int anchor) throws AWTException{
	    LayoutManager lm = container.getLayout();
	    if(!(lm instanceof GridBagLayout)){
		throw new AWTException ("Invalid layout"+lm);
	    }
	    else{
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.gridx = gridx;
		gbc.gridy = gridy;
		gbc.gridwidth = gridwidth;
		gbc.gridheight = gridheight;
		gbc.fill = fill;
		gbc.anchor = anchor;
		((GridBagLayout)lm).setConstraints(component, gbc);
		container.add(component);
	    }
    }
    
  
    public static void  subscripter(String str1, String str2, String str3, Graphics g, int fsize, int x, int y){
        if (useBiggerFont) fsize += 2;
		FontMetrics fm;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
		fm = g.getFontMetrics();
		g.drawString(str1,x,y);
		x = x + fm.stringWidth(str1) + 1;
		g.setFont(sanSerifFont.deriveFont((float)(fsize-2)));
		fm = g.getFontMetrics();
		y = y + fm.getHeight()/3;
		g.drawString(str2,x,y);
		y = y - fm.getHeight()/3;
		x = x + fm.stringWidth(str2) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
		g.drawString(str3,x,y);
    }
    
    public static void  subscripter2types(String str1, String str2, String str3, Graphics g, int fsize, int x, int y){
        if (useBiggerFont) fsize += 2;
		FontMetrics fm;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
		fm = g.getFontMetrics();
		g.drawString(str1,x,y);
		x = x + fm.stringWidth(str1) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize-2));
		fm = g.getFontMetrics();
		y = y + fm.getHeight()/3;
		g.drawString(str2,x,y);
		y = y - fm.getHeight()/3;
		x = x + fm.stringWidth(str2) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize-2));
                fm = g.getFontMetrics();
		g.drawString(str3,x,y);
    }
    
    public static void  superscripter(String str1, String str2, String str3, Graphics g, int fsize, int x, int y){
        if (useBiggerFont) fsize += 2;
		FontMetrics fm;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
		fm = g.getFontMetrics();
		g.drawString(str1,x,y);
		x = x + fm.stringWidth(str1) + 1;
		g.setFont(sanSerifFont.deriveFont((float)(fsize-2)));
		fm = g.getFontMetrics();
		y = y - fm.getHeight()/3;
		g.drawString(str2,x,y);
		y = y + fm.getHeight()/3;
		x = x + fm.stringWidth(str2) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
		g.drawString(str3,x,y);
    } 
    
    public static void drawCircle(int x, int y, int radius, Graphics g){
		g.drawOval(x-radius/2,y-radius/2,radius,radius);
    }
    
    public static void fillCircle(int x, int y, int radius, Graphics g){
		g.fillOval(x-radius/2,y-radius/2,radius,radius);
    }
    
    public static void  subscripterInfinityOne(String str1, String str2, String str3, String str4, Graphics g, int fsize, int x, int y){
        if (useBiggerFont) fsize += 2;
		FontMetrics fm;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
		fm = g.getFontMetrics();
		g.drawString(str1,x,y);
		x = x + fm.stringWidth(str1) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize-2));
		fm = g.getFontMetrics();
		y = y + fm.getHeight()/3;
		g.drawString(str2,x,y);
		y = y - fm.getHeight()/3;
		x = x + fm.stringWidth(str2) + 1;
                
                g.setFont(sanSerifFont.deriveFont((float)fsize));
                fm = g.getFontMetrics();
		g.drawString(str3,x,y);
                x = x + fm.stringWidth(str3) + 1;
		
                //create a symbol for "infinity".  JAVA 1.5 has a terrible rendition of the character
                //string str4 is not used
                g.setFont(serifFont.deriveFont((float)fsize+3));
                fm = g.getFontMetrics();
                g.setFont(serifFont.deriveFont((float)fsize+5));
                fm = g.getFontMetrics();
                g.drawString("o",x,y);
                g.drawString("o",x+5,y);
                g.setFont(sanSerifFont.deriveFont((float)fsize));
                fm = g.getFontMetrics();
    }
    
    public static void  subscripterInfinityTwo(String str1, String str2, String str3, String str4, String str5, Graphics g, int fsize, int x, int y){
        if (useBiggerFont) fsize += 2;
		FontMetrics fm;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
		fm = g.getFontMetrics();
		g.drawString(str1,x,y);
		x = x + fm.stringWidth(str1) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize-2));
		fm = g.getFontMetrics();
		y = y + fm.getHeight()/3;
		g.drawString(str2,x,y);
		y = y - fm.getHeight()/3;
		x = x + fm.stringWidth(str2) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
                fm = g.getFontMetrics();
		g.drawString(str3,x,y);
                x = x + fm.stringWidth(str3) + 1;
		//create a symbol for "infinity".  JAVA 1.5 has a terrible rendition of the character
                //string str4 is not used
                g.setFont(serifFont.deriveFont((float)fsize+3));
                fm = g.getFontMetrics();
                g.setFont(serifFont.deriveFont((float)fsize+5));
                fm = g.getFontMetrics();
                g.drawString("o",x,y);
                g.drawString("o",x+5,y);
                
                x = x + fm.stringWidth("oo") + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
                fm = g.getFontMetrics();
		g.drawString(str5,x,y);
    }

    public static void  subscripterInfinityThree(String str1, String str2, String str3, String str4, String str5, Graphics g, int fsize, int x, int y){
        if (useBiggerFont) fsize += 2;
		FontMetrics fm;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
		fm = g.getFontMetrics();
		g.drawString(str1,x,y);
		x = x + fm.stringWidth(str1) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize-2));
		fm = g.getFontMetrics();
		y = y + fm.getHeight()/3;
		g.drawString(str2,x,y);
		y = y - fm.getHeight()/3;
		x = x + fm.stringWidth(str2) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
                fm = g.getFontMetrics();
		g.drawString(str3,x,y);
                x = x + fm.stringWidth(str3) + 1;
		//create a symbol for "infinity".  JAVA 1.5 has a terrible rendition of the character
                //string str4 is not used
                
                g.setFont(serifFont.deriveFont((float)fsize+4));
                fm = g.getFontMetrics();
                g.drawString("o",x,y);
                g.drawString("o",x+5,y);
                
                x = x + fm.stringWidth("oo") + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
                fm = g.getFontMetrics();
		g.drawString(str5,x,y);
    }

    
    public static void  subscripterInfinitySymFirst(String str1, String str2, String str3, String str4, String str5, Graphics g, int fsize, int x, int y){
        if (useBiggerFont) fsize += 2;
		FontMetrics fm;
		g.setFont(serifFont.deriveFont((float)fsize+1));
		fm = g.getFontMetrics();
		g.drawString(str1,x,y);
		x = x + fm.stringWidth(str1) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize-2));
		fm = g.getFontMetrics();
		y = y + fm.getHeight()/3;
		g.drawString(str2,x,y);
		y = y - fm.getHeight()/3;
		x = x + fm.stringWidth(str2) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
                fm = g.getFontMetrics();
		g.drawString(str3,x,y);
                x = x + fm.stringWidth(str3) + 1;
		//create a symbol for "infinity".  JAVA 1.5 has a terrible rendition of the character
                //string str4 is not used
                g.setFont(serifFont.deriveFont((float)fsize+3));
                fm = g.getFontMetrics();
                g.setFont(serifFont.deriveFont((float)fsize+5));
                fm = g.getFontMetrics();
                g.drawString("o",x,y);
                g.drawString("o",x+6,y);
                
                x = x + fm.stringWidth("oo") + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
                fm = g.getFontMetrics();
		g.drawString(str5,x,y);
    }
    
    public static void  subscripterSanSym2(String str1, String str2, String str3, String str4, Graphics g, int fsize, int x, int y){
        if (useBiggerFont) fsize += 2;
		FontMetrics fm;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
		fm = g.getFontMetrics();
		g.drawString(str1,x,y);
		x = x + fm.stringWidth(str1) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize-2));
		fm = g.getFontMetrics();
		y = y + fm.getHeight()/3;
		g.drawString(str2,x,y);
		y = y - fm.getHeight()/3;
		x = x + fm.stringWidth(str2) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
                fm = g.getFontMetrics();
		g.drawString(str3,x,y);
                x = x + fm.stringWidth(str3) + 1;
                g.setFont(serifFont.deriveFont((float)fsize+3));
		fm = g.getFontMetrics();
		g.drawString(str4,x,y);
    }

     public static void  subscripterSanSym(String str1, String str2, String str3, String str4, Graphics g, int fsize, int x, int y){
        if (useBiggerFont) fsize += 2;
		FontMetrics fm;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
		fm = g.getFontMetrics();
		g.drawString(str1,x,y);
		x = x + fm.stringWidth(str1) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize-2));
		fm = g.getFontMetrics();
		y = y + fm.getHeight()/3;
		g.drawString(str2,x,y);
		y = y - fm.getHeight()/3;
		x = x + fm.stringWidth(str2) + 1;
		g.setFont(serifFont.deriveFont((float)fsize+1));
                fm = g.getFontMetrics();
		g.drawString(str3,x,y);
                x = x + fm.stringWidth(str3) + 1;
                g.setFont(sanSerifFont.deriveFont((float)fsize));
		fm = g.getFontMetrics();
		g.drawString(str4,x,y);
    }
    
    public static void  subscripterSymFirst2(String str1, String str2, String str3, Graphics g, int fsize, int x, int y){
        if (useBiggerFont) fsize += 2;
		FontMetrics fm;
		//g.setFont(new Font("Serif",Font.PLAIN,fsize));
                g.setFont(serifFont.deriveFont((float)fsize+1));
                fm = g.getFontMetrics();
		g.drawString(str1,x,y);
		x = x + fm.stringWidth(str1) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize-2));
		fm = g.getFontMetrics();
		y = y + fm.getHeight()/3;
		g.drawString(str2,x,y);
		y = y - fm.getHeight()/3;
		x = x + fm.stringWidth(str2) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
                fm = g.getFontMetrics();
		g.drawString(str3,x,y);
    }



    
    public static void  subscripterSymFirst2NEW(String str1, String str2, String str3, Graphics g, int fsize, int x, int y){
        if (useBiggerFont) fsize += 2;
		FontMetrics fm;
		//g.setFont(new Font("Serif",Font.PLAIN,fsize));
                //g.setFont(TheFonts.symbolFont.deriveFont((float)fsize+1));
                g.setFont(new Font("Symbol",Font.PLAIN,fsize+1));
                fm = g.getFontMetrics();
		g.drawString(str1,x,y);
		x = x + fm.stringWidth(str1) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize-2));
		fm = g.getFontMetrics();
		y = y + fm.getHeight()/3;
		g.drawString(str2,x,y);
		y = y - fm.getHeight()/3;
		x = x + fm.stringWidth(str2) + 1;
		g.setFont(sanSerifFont.deriveFont((float)fsize));
                fm = g.getFontMetrics();
		g.drawString(str3,x,y);
    }



}
