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

📄 buildgraph.java

📁 java 作图的程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
*/                                        case STYLE:	                       if( !isContext(MARKER) && !isContext(FONT))  {	                       	   errorAtLine(	                       	   "STYLE should only appear in MARKER or FONT context");	                       	   return;	                       }                           token = nextWord();                           if( token == PLAIN ) {                                nobj = new NamedObject(PLAIN);                           } else                            if( token == BOLD ) {                                nobj = new NamedObject(BOLD);                           } else                            if( token == ITALIC ) {                                nobj = new NamedObject(PLAIN);                           } else                            if( token == TT_NUMBER ) {                                nobj = new NamedObject(new Integer((int)(nval+0.01)), STYLE);                           } else {                                errorAtLine(                             "STYLE should be followed an integer or Keyword");                                return;                           }                           object.push(nobj);                           break;/***                         Size of font or marker. Size should be followed by an integer*/             case SIZE:	                       if( !isContext(MARKER) && !isContext(FONT))  {	                       	   errorAtLine(	                       	   "SIZE should only appear in MARKER or FONT context");	                       	   return;	                       }                           token = nextWord();                           if( token == TT_NUMBER ) {                                nobj = new NamedObject(new Integer((int)(nval+0.01)), SIZE);                           } else {                                errorAtLine("SIZE should be followed by an integer");                                return;                           }                           object.push(nobj);                           break;                           /*                           ** Which contour levels are to get labels.                           */             case LLEVELS:	                       if( !isContext(CONTOUR))  {	                       	   errorAtLine(	                       	   "LLEVELS should only appear in CONTOUR context");	                       	   return;	                       }                           token = nextWord();                           if( token == TT_NUMBER ) {                                nobj = new NamedObject(new Integer((int)(nval+0.01)), LLEVELS);                           } else {                                errorAtLine("LLEVELS should be followed by an integer");                                return;                           }                           object.push(nobj);                           break;/***                         Parse a color. Color should be followed by 3 integers in**                         the range 0-255*/             case COLOR: case BACKGROUND:                           int i;                           int rgb[]={-1,-1,-1};                           for(i=0; i<3; i++) {                              int t = nextWord();                              if(t != TT_NUMBER || nval <0 || nval > 255) {                                 errorAtLine("Incorrect Color definition");                                 return;                              }                           rgb[i] = (int)(nval+0.001);                           }                           if(token == COLOR)  {                                nobj = new NamedObject(new Color(rgb[0], rgb[1], rgb[2]), COLOR);                                object.push(nobj);                           } else {                                if( isContext(DATA) || isContext(CDATA) ) {                                	((Graph2D)graph).setDataBackground(                                	                  new Color(rgb[0], rgb[1], rgb[2]) );                                } else {                                	((Graph2D)graph).setGraphBackground(                                	                  new Color(rgb[0], rgb[1], rgb[2]) );                                }                           }                           break;/***                         Name the current context or the string to be used as a label**                         or title. Name should be followed by a string*/             case NAME:                           token = nextWord();                           if( token == STRING ) {                                nobj = new NamedObject(sval,NAME);                           } else {                                errorAtLine("NAME should be followed by a string");                                return;                           }                           object.push(nobj);                           break;             case FUNCTION:                           token = nextWord();                           if( token == STRING ) {                                nobj = new NamedObject(sval,FUNCTION);                           } else {                                errorAtLine("FUNCTION should be followed by a string");                                return;                           }                           object.push(nobj);                           break;             case NUMBER:                           token = nextWord();                           if( token == TT_NUMBER ) {                                nobj = new NamedObject(                                       new Integer((int)(nval+0.01)), NUMBER);                           } else {                                errorAtLine("NUMBER should be followed by an integer");                                return;                           }                           object.push(nobj);                           break;              case XRANGE: case YRANGE:                           boolean error = false;                           double min = 0.0;                           double max = 0.0;                           int    num = 0;	                           int t = nextWord();                           if( t == TT_NUMBER ) {                             num = (int)(nval+0.001);                             t = nextWord();                             if( t == TT_NUMBER ) {                                min = nval;                                t = nextWord();                                if( t == TT_NUMBER ) {                           	        max = nval;                           	     } else {                           	    	error = true;                           	     }                           	  } else {                           	    error = true;                           	  }                           } else {                           	    error = true;                           }                                                      if(error) {                                errorAtLine(                                "Range limits must be followed by 3 numbers");                                return;                           }                           if(min == max) {                                errorAtLine(                                "Range limits must not be the same");                                return;                           }                           if(num <= 1) {                                errorAtLine(                                "Number of points must be greater than 1");                                return;                           }                           if(min > max ) {                                            double tmp = max;                                            max = min;                                            min = tmp;                                            }                           if(token == XRANGE) {                              nobj = new NamedObject(new Integer(num),XNUMBER);                              object.push(nobj);                              nobj = new NamedObject(new Double(min),XMIN);                              object.push(nobj);                              nobj = new NamedObject(new Double(max),XMAX);                              object.push(nobj);                           } else {                              nobj = new NamedObject(new Integer(num),YNUMBER);                              object.push(nobj);                              nobj = new NamedObject(new Double(min),YMIN);                              object.push(nobj);                              nobj = new NamedObject(new Double(max),YMAX);                              object.push(nobj);                           }                           break;                           /***                         unknown keyword!*/             case UNKNOWN:                           errorAtLine("Unknown keyword!!");                           break;/***                         begin a new group or context. The object to be built**                         should be the last thing pushed onto the object stack.**                         Move it to the build stack and push BEGIN onto the object**                         stack to act as a delimiter on the stack*/             case BEGIN:                           level++;                           build.push(object.pop());                           object.push(new NamedObject(BEGIN));                           break;/***                         End of a group or context. Everything on the object stack**                         down to the BEGIN object relate to the current build object**                         Build the object and push this built object onto the**                         object stack.*/             case END:                           level--;                           build((NamedObject)(build.pop()));                           break;/***                         Whatever it is push it onto the object stack.*/             default:                           object.push(new NamedObject(token));                           break;             }          }/***        Finished - lets see if anything major was not defined*/          closeStream();                    if(graph == null) {              System.out.println("Graph never defined! Cannot build graph!");              return;          }                    if(level != 0 ) {              System.out.println("Mismatched Braces!! Will try and build graph.");          }/***        Errors could have occured - but lets try and repaint and keep going*/          if( graph instanceof Graph2D ) {                      ((Graph2D)graph).repaint();	  } else          if( graph instanceof G2Dint ) {                      ((G2Dint)graph).repaint();	  } else          if( graph instanceof Contour ) {                      ((Contour)graph).repaint();	  } else {             System.out.println("Unknown graph type - totally confused!");          }       }     /************************** Protected Methods***********************/  /**   * Check if the object is on the "to be built" stack. This way context can be   *   checked so potential errors flagged.   * @param token is this the object we are currently building?   * @return <i>true</i> if the token matches current object being built   */     protected boolean isContext(int token)  {     	int i;     	     	for(i=0; i<build.size(); i++)  {     		if( ((NamedObject)(build.elementAt(i))).id == token )                                                              return true;     	}     	     	return false;     }       /**   *  Based on the parsed object build something.   * @param nobj The object to be built   * @return <i>true</i> if the build was successful.   */     protected boolean build(NamedObject nobj) {              switch(nobj.id) {           case FONT:       return buildFont();           case MARKER:     return buildMarker();           case TITLE:      return buildTitle();           case LABEL:      return buildLabel();           case DATA: case CDATA:      return buildData(nobj.id);           case AXIS:       return buildAxis();           case GRID:       return buildGrid();           case ZERO:       return buildZero();           case G2DINT: case GRAPH2D: case CONTOUR:         	             return buildGraph(nobj.id);           default:                                       errorAtLine("Incorrect keyword followed by braces");                          return false;           }     }  /**   * Pop things off the object stack and build the graph   * @param type Type of graph to build, Graph2D, G2Dint, Contour.   * @return <i>true</i> if the build was successful   */     protected boolean buildGraph(int type) {           NamedObject nobj;           Axis axis;           String dname;           if(type==CONTOUR) dname = "Contour";           else           if(type==G2DINT)  dname = "G2Dint";           else                             dname = "Graph";                      while( true ) {              nobj = (NamedObject)(object.pop());                            debugMessage(dname,nobj.id);                                          switch (nobj.id) {              case AXIS:                          axis = (Axis)(nobj.getObject());                          if(type == GRAPH2D) {             	                 ((Graph2D)graph).attachAxis(axis);             	          } else {             	                 ((G2Dint)graph).attachAxis(axis);             	          }                          break;              case DATA:                          ((Graph2D)graph).attachDataSet(                                            (DataSet)(nobj.getObject()));                          break;              case ATTACH:                          axis = (Axis)(nobj.getObject());                          String name = nobj.getName();                          boolean attach = false;                          for(int i=0; i<datasets.size(); i++) {                             nobj = (NamedObject)(datasets.elementAt(i));                             if( name.equals(nobj.getName())) {                                 axis.attachDataSet((DataSet)(nobj.getObject()));                                 attach = true;                                 break;                             }                          }                                                    if(!attach) {                             errorAtLine("Data name not found for Attach keyword");                          }                          break;              case GRID_COLOR:                          ((Graph2D)graph).gridcolor = (Color)(nobj.getObject());                          break;              case GRID_OFF:                          ((Graph2D)graph).drawgrid = false;                          break;              case GRID_ON:                          ((Graph2D)graph).drawgrid = true;                          break;              case ZERO_COLOR:                          ((Graph2D)graph).zerocolor = (Color)(nobj.getObject());                          break;              case ZERO_OFF:                          ((Graph2D)graph).drawzero = false;                           break;              case ZERO_ON:                          ((Graph2D)graph).drawzero = true;                           break;              case MARKER:                          ((Graph2D)graph).setMarkers(                                      (Markers)(nobj.getObject()));                          break;              case TITLE:                            graphtitle = (TextLine)(nobj.getObject());                          built.addElement(graphtitle);                          break;              case LEFT:                          ((Graph2D)graph).borderLeft =                                            ((Integer)(nobj.getObject())).intValue();                          break;              case RIGHT:                          ((Graph2D)graph).borderRight =                                            ((Integer)(nobj.getObject())).intValue();                          break;              case TOP:                          ((Graph2D)graph).borderTop =                                            ((Integer)(nobj.getObject())).intValue();                          break;              case BOTTOM:                          ((Graph2D)graph).borderBottom =                                            ((Integer)(nobj.getObject())).intValue();                          break;              case SQUARE:                          ((Graph2D)graph).square = true;                          break;              case BEGIN:                          built.addElement(graph);                          applet.showStatus("BuildGraph: Built Graph!!!");                          return true;               default:                          if( type == CONTOUR ) {                             if(!buildContour(nobj) )  {

⌨️ 快捷键说明

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