⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 areacode.java

📁 图象输出(--------------------------)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    static int coord=0,x,y,crd=0,rct,Y=0,X=0,w=8,h=10,n,count=0, mLine=0; // coord  表格数组大小   // crd 曲线数组大小   // rct 直方图书组大小
    static int [][] vec=new int[1400][4];     // 保存画表格线的数据
    static int [][] LN=new int[500][2];       // ln 保存画曲线的数据  for '.'
    static int [][] ln=new int[500][2];       // LN保存画曲线的数据   LN for *
    static int [][] rect=new int[500][2];     // rect保存画柱状图的数据 for '=='
    static String[] Labels=new String[150];

    //--------转换文本字符图形数据为图形绘制数据----------------------
  public static int getDataOfDraw(InputStream is) {
       //    String fnm="",s="";
           rct=-1;
           try {
           int b=0,h=12,w=8,row=0;
           for(w=0;w<500;w++) ln[w][0]=0;
           w=5;
           count=getLineOfStream(textLine,is);
           int filePointer = 0;
           String cc="";
           char c;
           coord=0; y=0; crd=-1; Y=0;
           do {
               y+=h;
               if(textLine[Y].length()==2) textLine[Y]="";
               if(textLine[Y].indexOf(" . ")>1 &&                            //---從圓點 .獲取垂直綫坐標數據--------------------
                 (textLine[Y].lastIndexOf(".")-textLine[Y].indexOf(" .")>10)) textLine[Y]=columnLine(textLine[Y]);
                 else
               if(textLine[Y].indexOf("..")>1 || textLine[Y].lastIndexOf("--")>1)
                 {
                   if(textLine[Y].indexOf("..")>1)
                      {
                       n=textLine[Y].indexOf("..");
                       c='.';
                      } else {
                       n=textLine[Y].indexOf("--");
                       c='-';
                      }
                   if(textLine[Y].indexOf("**-")<0 )
                     textLine[Y]=getLine(textLine[Y],c,n);                //---從 "--" 或 ".." 獲取水平綫坐標--------------------
                  }

               if(textLine[Y].indexOf("|")>=0 || textLine[Y].indexOf(" I")>=0)
                 {
                     if(textLine[Y].indexOf("|")>1)
                       {;
                        n=textLine[Y].indexOf("|");
                        cc="|";
                       } else {
                        n=textLine[Y].indexOf("I");
                        cc="I";
                       }
                     if(textLine[Y-1].indexOf("**-")>0 || textLine[Y].indexOf("**-")>1 ) textLine[Y]=textLine[Y].replace('I','|');
                       else
                      textLine[Y]=getLine(textLine[Y],cc,n,(byte)0);     //---從 | 獲取垂綫座檦數據--------------------
                  } else
               if(textLine[Y].indexOf("I ")>=0) textLine[Y]=textLine[Y].replace('I','|');
               Y++;
              } while(Y<count);
            if(crd>0) crd++;
            } catch (Exception e) {
              System.out.println(Y+" error?! "+textLine[Y]);
			//  if(Y<10) canvas.request(3); //重新初始化接口管理sasManage
            }
          System.out.println("coord="+coord+" crd="+crd+" rct="+rct+" Y="+Y+" X="+X+" y="+y+" Y*h="+(Y*h)+" in getDataOfDraw() of forOut");
      //     if(Y<3) canvas.request(3); //重新初始化接口管理sasManage
           return Y+1;
         }

   public static int getLineOfStream(String [] textLine,InputStream is) {
            int Last=0;
            int m=0,i=0,w=0,end=0;
            String nm=textLine[0];
            try{
            byte [] buffer=new byte[8096];

            i=is.read();
            while(i!=-1 && Last<1879){
                if(i==13) {
                  i=is.read();
                  i=is.read();
                  if(m<1) textLine[Last]="";
                 textLine[Last]=new String(buffer,0,m);
                  if(textLine[Last].indexOf('0')==0)
                    if(mLine==0) mLine=Last;
                     else
                    end=Last;
                   m=0;
                  if(Last>5998) break;
                   else
                  if(textLine[Last].length()>0) Last++;
                  }
                  buffer[m++]=(byte)i;
                  i=is.read();
                }
              is.close();
              if(Last>=1800) return 0;
              if(m>1) textLine[Last]=new String(buffer,0,m);
               else Last--;
             }catch(IOException ioe) {
              System.out.println("IO Exception!");
             }
           return Last;
        }


    //---從 "--" 或 ".." 獲取水平綫坐標--------------------
  public static String getLine(String s,char c,int n) {
    String cc="";
    if(c=='-') cc="-";
     else cc="..";
    while(s.indexOf(cc,n)>0)
     {
     coord++;
     vec[coord][0]=n*w;
     vec[coord][1]=y;
     do {
      n++;
     } while(s.indexOf(cc,n)>0);
     vec[coord][2]=n*w+w;
     vec[coord][3]=y;
     n++;
    }
  //  s=s.replace(c,' ');
      if(s.indexOf("+")>0) s=s.replace('+','-');
  //   s=s.replace(c,' ');
     if(s.indexOf("|")>=0) s=getLine(s,"|",s.indexOf("|"),(byte)0);
      else
     if(s.indexOf(" I")>=0) s=getLine(s," I ",s.indexOf("I"),(byte)0);
    return s;
   }

  //---從 | 獲取垂綫座檦數據--------------------
  public static String getLine(String s,String c,int i,byte k) {
    while(s.indexOf(c,n)>0) {
     coord++;
     n=s.indexOf(c,n);
     vec[coord][0]=n*w;
     vec[coord][1]=y;
     vec[coord][2]=n*w;
     vec[coord][3]=y+h;
     n++;
    }
// System.out.println(Y+"|curve "+s+"|");

    if(s.indexOf(" I")>=0) s=s.replace('I',' '); //??
     else
    if(s.indexOf("|")>=0) s=s.replace('|',' '); //??
    if(s.indexOf("*")>1) {
     String ss=s.trim();
  //   if(ss.charAt(0)<'@' && s.indexOf("**")<0) s=getLine(s);
     if(s.indexOf("**")<0) s=getLine(s);
     } // else
    if(s.indexOf("==")>=0) s=rectangle(s);     //---獲取直方圖數據-----------------------
    return s;
    }

  //---從 * 和 .獲取曲綫坐標數據 --------------------
  public static String getLine(String s) {
     crd++;
     int m=-1;
     m=s.indexOf(" . ");
     if(m<1) m=s.indexOf(".*");
      else
     if(m<1) m=s.indexOf("*.");
     if((m>1) || (m<1 && s.indexOf("*")>1)) {
           n=s.indexOf("*");
           LN[crd][0]=35+n*(w-2);
           LN[crd][1]=y;
           if(m>1) ln[crd][0]=m*(w-2)+35;
            else
           if(crd>0 && ln[crd-1][0]>0) ln[crd][0]=ln[crd-1][0];
             else
            ln[crd][0]=0;
           ln[crd][1]=y;
           s=s.replace('*',' ');
       }
 //System.out.println(Y+"|curve "+s+"|");
     return "curve "+s;
    }

  //---從圓點 .獲取垂直綫坐標數據--------------------
  public static String columnLine(String s) {
     coord++;
     n=s.indexOf(" .")+1;
       vec[coord][0]=n*w;
       vec[coord][1]=y;
       vec[coord][2]=n*w;
       vec[coord][3]=y+h;
       coord++;
       n=s.lastIndexOf(".");
       vec[coord][0]=n*w;
       vec[coord][1]=y;
       vec[coord][2]=n*w;
       vec[coord][3]=y+h;
  //     s=s.replace('.',' ');
      return s;
    }
//---獲取直方圖數據-----------------------
  public static String rectangle(String s) {
      rct++;
      n=s.lastIndexOf("=");
      n++;
      rect[rct][0]=n*(w-1);
      rect[rct][1]=y;
      s=s.replace('=',' ');
      Labels[rct]=s.trim();
      float p=Float.valueOf(Labels[rct].substring(Labels[rct].lastIndexOf(" ")+1)).floatValue();
      Labels[rct]=Labels[rct].substring(0,Labels[rct].lastIndexOf(" "))+p;
      return "rectangle";
     }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -