public String getCode() {
        String newLine = System.getProperty("line.separator");
        String code = "%" + newLine;
        code += "%PSTricks Graph Editor" + newLine;        
        code += "%\\usepackage{pstricks-add} % PSTricks package" + newLine;
        code += "%\\usepackage{graphicx} % Graphicx package, used for rescale the graph" + newLine;
        code += "%" + newLine;
        double maxX = 0;
        double maxY = 0;
        double minX = 0;
        double minY = 0;
        double[] graphSize = PSTricksGraphEditor.canvas.getGraphSize();
        if(graphSize != null){
            maxX = graphSize[0]/50;
            maxY = graphSize[1]/50;
            minX = graphSize[2]/50;
            minY = graphSize[3]/50;
        }
        //String gridStr = "\\psgrid(0,0)(-1,"+(int)(0-1-(maxY-minY)/2)+")("+
        //        (int)(maxX-minX+1)+","+(int)(((maxY-minY)/2)+1)+")" + newLine;
        String gridStr = "\\psgrid(0,0)(-1,-1)("+
                (int)(Math.floor(maxX-minX+1))+","+(int)(Math.floor(maxY-minY+1))+")" + newLine;
        
        if(!PSTricksGraphEditor.canvas.grid.gridOn){
            gridStr = "%" + gridStr;
        }
        code += "\\psset{}" + newLine;
        code += "\\scalebox{1} % Rescale the Graph." + newLine;
        code += "{" + newLine;
        //String codeStart = "\\begin{pspicture}("+ 0 +"," + ((maxY-minY)/2) + ")(" +
        //        (maxX-minX) + "," + (0-(maxY-minY)/2) + ")";
        String codeStart = "\\begin{pspicture}(-1,-1)(" +
                (int)(Math.floor(maxX-minX+1)) + "," + (int)(Math.floor(maxY-minY+1)) + ")";
        
        code += codeStart + newLine;
        code += gridStr;
        
        if(graphSize != null){
            for(int i = 0; i < getNodes().size(); i++){
                code += ((Node)getNodes().get(i)).getCode() + newLine;
            }

            for(int i = 0; i < getEdges().size(); i++){
                code += ((Edge) getEdges().get(i)).getCode() + newLine;
            }
            
            for(int i = 0; i < getLabels().size(); i++){
                code += ((PSTLabel) getLabels().get(i)).getCode() +newLine;
            }
            
        }
        
        String codeEnd = "\\end{pspicture}" + newLine;
        code += codeEnd;
        code += "}";
        
        return code;
    }