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

📄 buildgraph.java

📁 java 作图的程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                                 errorAtLine(                                 "Incorrect keyword in Contour specification");                                 return false;                             } else {                                 return true;                             }                          } else {                             errorAtLine("Incorrect keyword in Graph specification");                             return false;                          }              }          }      }   /**   * @return <i>true</i> if the build was successful   */      protected boolean buildContour(NamedObject nobj) {          switch (nobj.id) {                            case NUMBER:                            ((Contour)graph).setNLevels(                                          ((Integer)(nobj.getObject())).intValue() );                            break;                                          case LLEVELS:                            ((Contour)graph).setLabelLevels(                                          ((Integer)(nobj.getObject())).intValue() );                            break;  	      case COLOR:                            ((Contour)graph).setContourColor(                                          (Color)(nobj.getObject()));                            break;  	      case LOGCONTOURS:                            ((Contour)graph).logLevels = true;                            break;              default:                       return false;          }          return true;      }       /**   * @return <i>true</i> if the build was successful   */      protected boolean buildFont() {           String name = "TimesRoman";           int style   = Font.PLAIN;           int size    = 20;           NamedObject nobj;           Font f;                      while( true ) {              nobj = (NamedObject)(object.pop());                            debugMessage("Font",nobj.id);              switch (nobj.id) {                            case NAME:                          name = (String)(nobj.getObject());                          break;              case SIZE:                          size = ((Integer)(nobj.getObject())).intValue();                          break;              case PLAIN:                          style += Font.PLAIN;                          break;              case BOLD:                          style += Font.BOLD;                          break;              case ITALIC:                          style += Font.ITALIC;                          break;              case BEGIN:                          try {                                f = new Font(name,style,size);                                nobj = new NamedObject(f,FONT);                                object.push(nobj);                               applet.showStatus("BuildGraph: Built Font!");                                return true;                          } catch(Exception e) {                              errorAtLine("Ill formed font specification");                              return false;                          }               default:                          errorAtLine("Incorrect keyword in Font specification");                          return false;              }          }      }  /**   * @return <i>true</i> if the build was successful   */      protected boolean buildTitle() {           NamedObject nobj;                      TextLine title = new RTextLine();                      while( true ) {              nobj = (NamedObject)(object.pop());              debugMessage("Title",nobj.id);                                          switch (nobj.id) {                            case NAME:                          title.setText((String)(nobj.getObject()));                          break;              case FONT:                          title.setFont((Font)(nobj.getObject()));                          break;              case COLOR:                          title.setColor((Color)(nobj.getObject()));                          break;              case BEGIN:                          nobj = new NamedObject(title,TITLE);                          object.push(nobj);                          applet.showStatus("BuildGraph: Built Title!");                          return true;               default:                          errorAtLine("Incorrect keyword in Title specification");                          return false;              }          }      }  /**   * @return <i>true</i> if the build was successful   */         protected boolean buildLabel() {           NamedObject nobj;           NamedObject color = null;           NamedObject font = null;                 while( true ) {              nobj = (NamedObject)(object.pop());              debugMessage("Label",nobj.id);                                          switch (nobj.id) {                            case FONT:                          font = nobj;                          font.setId(LABEL_FONT);                          break;              case COLOR:                          color = nobj;                          color.setId(LABEL_COLOR);                          break;              case BEGIN:                          if(color != null) object.push(color);                          if(font != null) object.push(font);                          applet.showStatus("BuildGraph: Built Axis Label!");                          return true;               default:                          errorAtLine("Incorrect keyword in Label specification");                          return false;              }          }      }  /*   * @return <i>true</i> if the build was successful   */      protected boolean buildMarker() {           NamedObject nobj;           Markers m = null;           NamedObject size  = null;           NamedObject color = null;           NamedObject style = null;                            while( true ) {              nobj = (NamedObject)(object.pop());                            debugMessage("Marker",nobj.id);                            switch (nobj.id) {                            case SIZE:                          size = nobj;                          size.setId(MARKER_SIZE);                          break;              case COLOR:                          color = nobj;                          color.setId(MARKER_COLOR);                          break;              case STYLE:                          style = nobj;                          if( style.getObject() instanceof Integer) {                                 style.setId(MARKER_STYLE);                          } else {                                 errorAtLine("Style should be an Integer in MARKER");                                 return false;                          }                          break;              case URL:		          try {                               m = new Markers( (URL)nobj.getObject() );                          } catch(Exception e) {                             errorAtLine("Failed to load markers: "+                                        e.getMessage());                          }                          break;              case BEGIN:		          if(m != null) {                            nobj = new NamedObject(m,MARKER);                            object.push(nobj);                            built.addElement(m);                            applet.showStatus(                               "BuildGraph: Loaded Marker file!");                            return true;                          } else {                            if(color != null) object.push(color);                            if(size != null)  object.push(size);                            if(style != null) object.push(style);                            applet.showStatus("BuildGraph: Built Marker!");                            return true;                          }               default:                          errorAtLine("Incorrect keyword in MARKER specification");                          return false;              }          }      }  /**            * @return <i>true</i> if the build was successful   */         protected boolean buildData(int type) {           NamedObject nobj;           DataSet data = new DataSet();           NamedObject ndata = new NamedObject(data,DATA);           ParseFunction parsef = null;           LoadData load = null;           double xmin = 0.0;           double xmax = 0.0;           double ymin = 0.0;           double ymax = 0.0;           int nx = 0;           int ny = 0;           if(type == CDATA && !(graph instanceof Contour)) {               errorAtLine("CDATA can only be used in CONTOUR!");           }                      while( true ) {              nobj = (NamedObject)(object.pop());              debugMessage("Data",nobj.id);                                          switch (nobj.id) {                            case NAME:                          ndata.setName((String)(nobj.getObject()));                          break;              case MARKER_STYLE:                          data.marker = ((Integer)(nobj.getObject())).intValue();                          break;              case MARKER_SIZE:                          data.markerscale = (double)(((Integer)(nobj.getObject())).intValue());                          break;              case MARKER_COLOR:                          data.markercolor = (Color)(nobj.getObject());                          break;              case OFF:                          data.linestyle = 0;                          break;              case ON:                          data.linestyle = 1;                          break;              case COLOR:		          if(type == CDATA) {                              ((Contour)graph).setContourColor(                                      (Color)(nobj.getObject()));                          } else {                               data.linecolor = (Color)(nobj.getObject());                          }                          break;              case URL:                          load = new LoadData(data);                          load.loadDataSet( (URL)(nobj.getObject()), graph);                          break;              case FUNCTION:                          parsef = new ParseFunction((String)(nobj.getObject()));                          if(!parsef.parse())  {                          	errorAtLine("Error in function definition!");                          	return false;                          }                          break;              case XNUMBER:                          nx = ((Integer)(nobj.getObject())).intValue();                          break;              case XMIN:                          xmin = ((Double)(nobj.getObject())).doubleValue();                          break;              case XMAX:                          xmax = ((Double)(nobj.getObject())).doubleValue();                          break;              case YNUMBER:                          ny = ((Integer)(nobj.getObject())).intValue();                          break;              case YMIN:                          ymin = ((Double)(nobj.getObject())).doubleValue();                          break;              case YMAX:                          ymax = ((Double)(nobj.getObject())).doubleValue();                          break;              case BEGIN:		          if( parsef != null && type == CDATA ) {		              if( !(graph instanceof Contour) )  {                          	errorAtLine("CDATA should only be used for Contours!");                          	return false;		              }                      double array[] = arrayFromFunction(parsef,nx,xmin,xmax,                                                                ny,ymin,ymax);                      if(array == null)  {                          	errorAtLine("Unable to build Data from Function");                          	return false;		              }                      ((Contour)graph).setRange(xmin,xmax,ymin,ymax);                      ((Contour)graph).setGrid(array,nx,ny);                      return true;		          		          } else		          if( parsef != null ) {                      double array[] = arrayFromFunction(parsef,nx,xmin,xmax);                      if(array == null)  {                          	errorAtLine("Unable to build Data from Function");                          	return false;                      }                      try  {   		          	         data.append(array,nx);   		          	         object.push(ndata);   		          	         datasets.addElement(ndata);   		          	         built.addElement(data);   		          	         return true;                      } catch(Exception e)  {                      	    return false;                      }		          } else                  if( load == null )  {                          	errorAtLine("No URL has been defined for Data!");                          	return false;                  }                          	                  object.push(ndata);                  built.addElement(data);                  built.addElement(load);                  datasets.addElement(ndata);                  applet.showStatus("BuildGraph: Loading Data!");                  return true;                                         default:                          errorAtLine("Incorrect keyword in Data specification");                          return false;              }          }      }      protected double[] arrayFromFunction(ParseFunction f, int nx,                                             double xmin, double xmax)  {                              double x;                 double y;                 double array[] = new double[2*nx];                 double xinc = (xmax-xmin)/(nx-1);                 int count = 0;                                                   for(int i=0; i<nx; i++) {                 	 x = xmin + i*xinc;                     try {                     	y = f.getResult(x);                     	array[count++] = x;                     	array[count++] = y;                     }                     catch (Exception e) {                     }                 }                                  if(count == 0) return null;                                  return array;      }      protected double[] arrayFromFunction(ParseFunction f,                                              int nx, double xmin, double xmax,                                            int ny, double ymin, double ymax)  {                	                 double x;                 double y;                 double array[] = new double[ny*nx];                 double xinc = (xmax-xmin)/(nx-1);                 double yinc = (ymax-ymin)/(ny-1);                                  int count = 0;                                  for(int j=0; j<ny; j++) {                 	 y = ymin + j*yinc;                     for(int i=0; i<nx; i++) {                   	    x = xmin + i*xinc;                        try {                     	   array[count++] = f.getResult(x,y);                        }                        catch (Exception e) {                           array[count++] = 0.0;                        }                     }                                      }                                  if(count == 0) return null;                 

⌨️ 快捷键说明

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