// About.java
/* A Java class for
 * LineImpedance.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.io.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.geom.Arc2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

public class Instructions extends Panel implements ItemListener{
    
    private static final Color bgcolor = new Color(255,255,245);
    //private static final Color bgcolor = Color.white;
    
    public TextField epsilon;
    private Paint paint;
    
    private Image im;
    private Graphics buf;
    private BufferedImage figure;
  
    public Button bupdate;
    CheckboxGroup chgroup;
    Checkbox ch1, ch2;
    Boolean setopen = false;
    public int ydown;
    
    StateVars state;
  
    public Instructions (StateVars state){
	super();
        this.state = state;
	setLayout(null);
	setBackground(bgcolor);
	
        // update button
	bupdate = new Button("CLOSE");
        bupdate.setBackground(new Color(240,240,255));
	add(bupdate);
        
        ydown = state.s50;
        int buttonx = state.s490;
        int buttony = state.s390+ydown;
        int buttonwide = state.s70;
        int buttonheight = state.s27;
        
        bupdate.setBounds(buttonx,buttony,buttonwide,buttonheight);
        bupdate.setFont(state.ttfFont.deriveFont(Font.BOLD,(float)state.font12));
        
        Panel ps7 = new Panel();
	    ps7.setBackground(Color.lightGray);
	    add(ps7);
	    ps7.setBounds(buttonx-1,buttony-1,buttonwide+2,buttonheight+2);
	    
	Panel ps8 = new Panel();
	    ps8.setBackground(Color.black);
	    add(ps8);
	    ps8.setBounds(buttonx-2,buttony-2,buttonwide+4,buttonheight+4);
            
        chgroup = new CheckboxGroup();
        ch1 = new Checkbox(" Open Stub ",false,chgroup);
	ch2 = new Checkbox(" Shorted Stub ",true,chgroup);
	ch1.setFont(state.ttfFont.deriveFont((float)state.font12));
	ch2.setFont(state.ttfFont.deriveFont((float)state.font12));
	ch1.setBackground(bgcolor);
	ch2.setBackground(bgcolor);
	ch1.setForeground(Color.black);
	ch2.setForeground(Color.black);
        add(ch1);
	add(ch2);
	ch1.setBounds(state.s20,state.s360+ydown,state.s150,state.s20);
        ch2.setBounds(state.s20,state.s380+ydown,state.s150,state.s20);
        
        // Listeners
        ch1.addItemListener(this);
	ch2.addItemListener(this);
    }
    
    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){
        FontMetrics fm;
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);        
        g.clearRect(0,0,getSize().width-1,getSize().height-1);

        boolean saveOldFlag = MaestroG.useBiggerFont;
        MaestroG.useBiggerFont = false;
        
        g.setColor(Color.black);
        g.setFont(state.ttfFont.deriveFont(Font.BOLD,(float)state.font16));

        try {
            figure = ImageIO.read(getClass().getResource("figuree.gif"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        g.drawString("Instructions", state.s20,state.s25+ydown);
        
        g.setColor(Color.red);
        g.setFont(state.ttfFont.deriveFont(Font.BOLD,(float)state.font15));
        g.drawString("Input", state.s25,state.s60+ydown);
        g.drawString("Design Procedure", state.s391,state.s30);
        g.setColor(Color.black);
        g.setFont(state.ttfFont.deriveFont((float)state.font14));
        int deltaY = state.s20;
        //INPUT

        FontMetrics fmNormal, fmSmall;
        
        g.setFont(state.ttfFont.deriveFont((float)state.font12));
        fmSmall = g.getFontMetrics();
        
        g.setFont(state.ttfFont.deriveFont((float)state.font14));
        fmNormal = g.getFontMetrics();
        
        int lineLength = fmNormal.stringWidth("Line Parameters (Z and ");
        lineLength += fmSmall.stringWidth("01");
        
        MaestroG.subscripter("Line Parameters (Z","0"," and",g,state.font14,state.s25,state.s90+ydown);
        MaestroG.subscripter("\u03b5","r",")",g,state.font14,state.s25+lineLength,state.s90+ydown);

        //dblsubscriptor("Line Parameters (Z","01","and \u03b5","r1",")",
        //               g,25,80);
        MaestroG.subscripter("Load Impedance Z","L","",g,state.font14,state.s25,state.s100+ydown+deltaY);
        //DESIGN PROCEDURE
        int ystart = state.s20+ydown;
        deltaY = state.s22;
        
        g.drawString("The goal is to match the feedline to the load by", state.s391,ystart);
        g.drawString("connecting to the original line a separate, short- or",
                     state.s391,ystart+deltaY);
        g.drawString("open-circuited line at a distance d from the load.",
                     state.s391,ystart+2*deltaY);
        
        g.drawString("Two solutions exist:", state.s391,ystart+4*deltaY);
        
        lineLength = fmNormal.stringWidth("    (a) Select d such that y (");
        lineLength += fmSmall.stringWidth("1");
        MaestroG.subscripter("    (a) Select d","1"," such that y (",
                             g,state.font14,state.s391,ystart+6*deltaY);
        MaestroG.subscripter(" d","1",") = 1 + j x,",
                             g,state.font14,state.s391+lineLength,ystart+6*deltaY);

        //dblsubscriptor("    (a) Select d","1"," such that y(d",
        //               "1",") = 1+ j x,", g,391,ystart+5*deltaY);
        lineLength = fmNormal.stringWidth("        and then select ");
        g.drawString("        and then select ",state.s391,ystart+7*deltaY);
        MaestroG.subscripterIT("l","1"," such that ",
                               g,state.font14,state.s391+lineLength,ystart+7*deltaY);
        g.setFont(state.italicFont.deriveFont((float)state.font14));
        FontMetrics fmItalic = g.getFontMetrics();
        lineLength += fmItalic.stringWidth("l");
        lineLength += fmSmall.stringWidth("1");
        lineLength += fmNormal.stringWidth(" such that ");
        g.setFont(state.ttfFont.deriveFont((float)state.font14));
        MaestroG.subscripter("y","s","(",
                             g,state.font14,state.s396+lineLength,ystart+7*deltaY);
        lineLength += fmNormal.stringWidth("y(");
        lineLength += fmSmall.stringWidth("s");
        MaestroG.subscripterIT(" l","1",") = - j x.",g,state.font14,state.s396+lineLength,ystart+7*deltaY);

        //tplsubscriptor("        and then select Z","1"," such that y","s",
        //                "(Z","1",") = - j x.", g,351,ystart+7*deltaY);

        lineLength = fmNormal.stringWidth("    (b) Select d such that y (");
        lineLength += fmSmall.stringWidth("2");
        MaestroG.subscripter("    (b) Select d","2"," such that y (",
                             g,state.font14,state.s391,ystart+9*deltaY);
        MaestroG.subscripter(" d","2",") = 1 - j x,",
                             g,state.font14,state.s391+lineLength,ystart+9*deltaY);

        //dblsubscriptor("    (b) Select d","2"," such that y(d","2",
        //               ") = 1 - j x,",g,391,ystart+8*deltaY);

        lineLength = fmNormal.stringWidth("        and then select ");
        g.drawString("        and then select ",state.s391,ystart+10*deltaY);
        MaestroG.subscripterIT("l","2"," such that ",
                               g,state.font14,state.s391+lineLength,ystart+10*deltaY);
        lineLength += fmItalic.stringWidth("l");
        lineLength += fmSmall.stringWidth("2");
        lineLength += fmNormal.stringWidth(" such that ");
        MaestroG.subscripter("y","s","(",
                             g,state.font14,state.s396+lineLength,ystart+10*deltaY);
        lineLength += fmNormal.stringWidth("y(");
        lineLength += fmSmall.stringWidth("s");
        MaestroG.subscripterIT(" l","2",") = j x.",
                               g,state.font14,state.s396+lineLength,ystart+10*deltaY);

        g.drawString("The final output is a plot of | \u0393 |, as seen by",
                     state.s391,ystart+12*deltaY);
        g.drawString("the feedline, as a function of frequency.",
                     state.s391,ystart+13*deltaY);

        //g.drawImage(figure,state.s20,state.s175,this);
        
        // DRAW SCALABLE IMAGE OF THE CIRCUIT
        int y_fig = state.s228 + ydown;
        int x_left = state.s30;
        int Length_A = state.s120;
        int Length_B = 0;
        int Length_C = state.s120;
        int Length_D = state.s20;
        int height_A = state.s70;
        int height_B = state.s12;
        int height_C = state.s50;
        int load_wx = state.s12;
        int load_wy = state.s20;
        int loadx = x_left + Length_A + Length_C + Length_D;
        int loady = y_fig + height_A/2;
        int stem = state.s15;
        int stub_down = state.s50;
        
        int Radius = state.s8;
        int Radius1 = state.s8;
        int Radius2 = state.s4;
        
        // Input section Line
        drawLineThick(g,(double)x_left,(double)y_fig,
                (double)(x_left + Length_A),(double)y_fig,state.s2,Color.cyan.darker());
        drawLineThick(g,(double)x_left,(double)(y_fig+height_A),
                (double)(x_left + Length_A),(double)(y_fig+height_A),state.s2,Color.cyan.darker());
        
        // Output section Line
        drawLineThick(g,(double)(x_left + Length_A + Length_B),(double)y_fig,
                (double)(x_left + Length_A + Length_B + Length_C),(double)y_fig,state.s2,Color.cyan.darker());
        drawLineThick(g,(double)(x_left + Length_A + Length_B),(double)(y_fig+height_A),
                (double)(x_left + Length_A + Length_B + Length_C),(double)(y_fig+height_A),state.s2,Color.cyan.darker());
        
        // Stub Line
        drawLineThick(g,(double)(x_left + Length_A + Length_B),(double)y_fig,
                (double)(x_left + Length_A + Length_B + Length_C),(double)(y_fig + height_A + stub_down),state.s2,Color.red);
        drawLineThick(g,(double)(x_left + Length_A + Length_B),(double)(y_fig + height_A),
                (double)(x_left + Length_A + Length_B + Length_C),(double)(y_fig + 2*height_A + stub_down),state.s2,Color.red);
        
        
        //  short wire
        if(!setopen){
            drawLineThick(g,(double)(x_left + Length_A + Length_B + Length_C),(double)(y_fig + height_A + stub_down),
                (double)(x_left + Length_A + Length_B + Length_C),(double)(y_fig + 2*height_A + stub_down),state.s2,Color.black);
        }
        
        // Load
        drawLineThick(g,(double)(x_left + Length_A + Length_B + Length_C),(double)y_fig,
                (double)(x_left + Length_A + Length_B + Length_C + Length_D),(double)y_fig,state.s2,Color.black);
        drawLineThick(g,(double)(x_left + Length_A + Length_B + Length_C),(double)(y_fig+height_A),
                (double)(x_left + Length_A + Length_B + Length_C + Length_D),(double)(y_fig+height_A),state.s2,Color.black);
        drawLineThick(g,(double)(x_left + Length_A + Length_B + Length_C + Length_D),(double)(y_fig),
                (double)(x_left + Length_A + Length_B + Length_C + Length_D),(double)(y_fig+height_A),state.s2,Color.black);
        
        // Wire connections
        drawConnect(x_left + Length_A, y_fig, g);
        drawConnect(x_left + Length_A, y_fig + height_A, g);
        if(!setopen){
            drawConnect(x_left + Length_A + Length_B + Length_C, y_fig + height_A + stub_down, g);
            drawConnect(x_left + Length_A + Length_B + Length_C, y_fig + 2*height_A + stub_down, g);
        }
        drawConnect(x_left + Length_A + Length_B + Length_C, y_fig, g);
        drawConnect(x_left + Length_A + Length_B + Length_C, y_fig + height_A, g);
        
        fillRectangleThick(g2d,(double)(loadx-load_wx), (double)(loady - load_wy),
                (double)(2.0 * load_wx),(double)(2.0 * load_wy), 2, Color.white);
        drawRectangleThick(g2d,(double)(loadx-load_wx), (double)(loady - load_wy),
                (double)(2.0 * load_wx),(double)(2.0 * load_wy), 1, Color.black);
        
        MaestroG.subscripter2("Z","0","",g,state.font12,x_left + 3*Length_A/35,loady+load_wy/4);
        MaestroG.subscripter2("Z","0","",g,state.font12,x_left + Length_A + Length_B + 45*Length_C/100,loady+load_wy/4);
        MaestroG.subscripter2("Z","0","",g,state.font12,x_left + Length_A + Length_B + 45*Length_C/100,loady+load_wy/4 + 9*height_A/10);
        MaestroG.subscripter2("Z","L","",g,state.font11,loadx-55*load_wx/100,loady+load_wy/4);
        MaestroG.subsubSerifBoldItalic("y","s","(","","l","1",")",g, state.font12, (x_left + 73*Length_A/100),(y_fig + 28*height_A/100));
        //subsubSerifBoldItalic(String str1, String str2, String str3, String str4, String str5, String str6, String str7, Graphics g, int fsize, int x, int y)
        
        MaestroG.SerifBoldItalic("M",g,state.font12,x_left+Length_A-4*fmNormal.stringWidth("M")/10,y_fig-38*Radius/10);
        MaestroG.SerifBoldItalic("M'",g,state.font12,x_left+Length_A-fmNormal.stringWidth("M")/2,y_fig+height_A+3*Radius);
        MaestroG.SerifBoldItalic("A",g,state.font12,x_left+Length_A+Length_B+Length_C-4*fmNormal.stringWidth("A")/10,y_fig-38*Radius/10);
        MaestroG.SerifBoldItalic("A'",g,state.font12,x_left+Length_A+Length_B+Length_C-fmNormal.stringWidth("A")/2,y_fig+height_A+3*Radius);
        
        g.setColor(Color.red);
        MaestroG.subSerifBoldItalic("d","1","",g,state.font12,x_left+Length_A+Length_B+Length_C/2,y_fig-31*Radius/10);
        MaestroG.subSerifBoldItalic("l","1","",g,state.font12,x_left + Length_A + Length_B + 45*Length_C/100,loady+load_wy/4 + 16*height_A/10);
        MaestroG.subscripter4("Feedline","","",g,state.font10,x_left,y_fig-Radius);
        
        
        //g.setColor(Color.red);
        //drawArrowScaled(x_left+Length_A, loady, 3, state.sfactor, g);
        //drawLineThick(g,(double)(x_left+Length_A),(double)loady,
        //        (double)(x_left + Length_A - stem),(double)loady,state.s1,Color.red);
        
        g.setColor(Color.green.darker());
        drawArrowScaled(x_left+Length_A+Length_B, loady + stem/2, 5, state.sfactor, g);
        //drawLineThick(g,(double)(x_left + Length_A + Length_B - stem),(double)loady,
        //        (double)(x_left + Length_A + Length_B - stem),(double)loady + height_A,state.s1,Color.green.darker());
        drawLineThick(g,(double)(x_left+ Length_A+Length_B),(double)loady + stem/2,
                (double)(x_left + Length_A + Length_B - stem),(double)(loady - stem/2),state.s1,Color.green.darker());
        
        
        g.setColor(Color.black);
        g.drawLine(x_left+Length_A,y_fig-Radius,x_left+Length_A,y_fig-3*Radius);
        //g.drawLine(x_left+Length_A+Length_B,y_fig-Radius,x_left+Length_A+Length_B,y_fig-3*Radius);
        g.drawLine(x_left+Length_A+Length_B+Length_C,y_fig-Radius,x_left+Length_A+Length_B+Length_C,y_fig-3*Radius);
        
        //g.drawLine(x_left+Length_A,y_fig-2*Radius,x_left+Length_A+Length_B,y_fig-2*Radius);
        g.drawLine(x_left+Length_A+Length_B,y_fig-2*Radius,x_left+Length_A+Length_B+Length_C,y_fig-2*Radius);
        
        //drawArrowScaled(x_left+Length_A+state.s8, y_fig-2*Radius, 4, state.sfactor, g);
        //drawArrowScaled(x_left+Length_A+Length_B-state.s8, y_fig-2*Radius, 3, state.sfactor, g);
        drawArrowScaled(x_left+Length_A+Length_B+state.s8, y_fig-2*Radius, 4, state.sfactor, g);
        drawArrowScaled(x_left+Length_A+Length_B+Length_C-state.s8, y_fig-2*Radius, 3, state.sfactor, g);
        
        

        drawCopyRight(g);
        MaestroG.useBiggerFont = saveOldFlag;
    }

    public void drawCopyRight(Graphics g) {
        int deltaY = state.s20;
        int startingY = getSize().height - state.s70;
        int startingX = 0;
        FontMetrics fm;
        g.setColor(Color.black);
        g.setColor(Color.black);
        //g.setFont(normalfont14);
        g.setFont(state.ttfFont.deriveFont((float)state.font14));
        fm = g.getFontMetrics();
        g.drawString("Application Design: Umberto Ravaioli",
                     startingX+state.s15,startingY+deltaY);
        
        MaestroG.superscripter("Interactive Java","TM"," platform:  www.amanogawa.com",
                               g,state.font14,startingX+state.s15,startingY+2*deltaY);
        int lineLength = fm.stringWidth("Interactive JavaTM platform:  www.amanogawa.com");
        lineLength += state.s10;

        g.setFont(state.ttfFont.deriveFont((float)state.s14));
        g.drawString("All Rights Reserved",startingX+state.s15,startingY+3*deltaY);
        g.drawLine(startingX,startingY,
                   startingX+lineLength+state.s25,startingY);
        g.drawLine(startingX+lineLength+state.s25,startingY,
                   startingX+lineLength+state.s25,startingY+4*deltaY);
    }
    
    private void drawConnect(int x, int y, Graphics g){
        int tmp1, tmp2;
        tmp1 = state.s6;
        tmp2 = tmp1-state.s2;
        //drawRect(x,y,tmp1,tmp1,Color.white,g);
        //drawRect(x,y,tmp2,tmp2,Color.black,g);

        Graphics2D g2d = (Graphics2D)g;

        g2d.setStroke(new BasicStroke(2));

        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

        g2d.setPaint(Color.white);
        g.fillOval(x-tmp1/2,y-tmp1/2,tmp1,tmp1);
        g2d.setPaint(Color.cyan.darker());
        //g.fillOval(x-tmp2/2,y-tmp2/2,tmp2,tmp2);

        Arc2D.Double arc_zero = new Arc2D.Double((double)(x-tmp1/2),(double)(y-tmp1/2),
                (double)tmp1,(double)tmp1,0,360,0);
        g2d.draw(arc_zero);


        g2d.setStroke(new BasicStroke(1));
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    
    public void drawLineThick(Graphics g, double x1, double y1, double x2, double y2, int thick, Color color){
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        Line2D.Double line = new Line2D.Double(x1,y1,x2,y2);
        g2d.draw(line);
  
        g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    
    public void drawRectangleThick(Graphics g, double x1, double y1, double x2, double y2, int thick, Color color){
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        Rectangle2D rect = new Rectangle2D.Double(x1,y1,x2,y2);
        g2d.draw(rect);
  
        g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    
    public void fillRectangleThick(Graphics g, double x1, double y1, double x2, double y2, int thick, Color color){
	
        Graphics2D g2d = (Graphics2D)g;
        g2d.setPaint(color);
        g2d.setStroke(new BasicStroke(thick,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
        
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
        Rectangle2D rect = new Rectangle2D.Double(x1,y1,x2,y2);
        g2d.fill(rect);
  
        g2d.setStroke(new BasicStroke(1));
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    
    public void drawArrowScaled(int x, int y, int tipo, double sfactor, Graphics g){
	Graphics2D g2d = (Graphics2D)g;
        double s;
        s = sfactor;
        
        switch (tipo){
	   
          case 1://ArrowUpSmooth
               g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
                g.drawLine(x,y,x,y-(int)(s*8));
		//draw oblique arrow head
		Polygon pH = new Polygon();
		pH.addPoint(x-(int)(s*2), y-(int)(s*2));
		pH.addPoint(x+(int)(s*2), y-(int)(s*2));
		pH.addPoint(x,y-(int)(s*8));
		g.drawPolygon(pH);
		g.fillPolygon(pH);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
        
          break;
          
          case 2://ArrowDownSmooth
               g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
                g.drawLine(x,y,x,y+(int)(s*8));
		//draw oblique arrow head
		Polygon pJ = new Polygon();
		pJ.addPoint(x-(int)(s*2), y+(int)(s*2));
		pJ.addPoint(x+(int)(s*2), y+(int)(s*2));
		pJ.addPoint(x,y+(int)(s*8));
		g.drawPolygon(pJ);
		g.fillPolygon(pJ);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
	   break;
           
           case 3://ArrowRightSmooth
               g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
                g.drawLine(x,y,x+(int)(s*8),y);
		//draw oblique arrow head
		Polygon pK = new Polygon();
		pK.addPoint(x+(int)(s*2), y-(int)(s*2));
		pK.addPoint(x+(int)(s*2), y+(int)(s*2));
		pK.addPoint(x+(int)(s*8),y);
		g.drawPolygon(pK);
		g.fillPolygon(pK);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
	   
	   break;
           
           case 4://ArrowLeftSmooth
               g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
                g.drawLine(x,y,x-(int)(s*8),y);
		//draw oblique arrow head
		Polygon pL = new Polygon();
		pL.addPoint(x-(int)(s*2), y-(int)(s*2));
		pL.addPoint(x-(int)(s*2), y+(int)(s*2));
		pL.addPoint(x-(int)(s*8),y);
		g.drawPolygon(pL);
		g.fillPolygon(pL);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
 
	   break;
           
           case 5://ArrowOblique 45 degrees SE
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
		//draw oblique arrow head
		Polygon pM = new Polygon();
                //draw oblique arrow head
                
                pM.addPoint(x+(int)(s*5),y+(int)(s*5));
		pM.addPoint(x+(int)(s*2),y-(int)(s*3));
		pM.addPoint(x-(int)(s*3),y+(int)(s*2));
		
                g.drawPolygon(pM);
		g.fillPolygon(pM);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
                 
           break;
           
           case 6://ArrowOblique 45 degrees NE
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
        
		//draw oblique arrow head
		Polygon pX = new Polygon();
                //draw oblique arrow head
                
		pX.addPoint(x+5,y-5);
		pX.addPoint(x-2,y-3);
		pX.addPoint(x+3,y+2);
		
                g.drawPolygon(pX);
		g.fillPolygon(pX);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
                 
           break;

	}
    }
    public void itemStateChanged(ItemEvent evt){
	if(evt.getSource()==ch1){//Open
	    setopen = true;
            state.setOpen(true);
            repaint();
	}
	else if(evt.getSource()==ch2){//Short
	    setopen = false;
            state.setOpen(false);
            repaint();
	}
    }
//----------------------------------------------------------------------------------------    
}//End
    

