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

📄 buildgraph.java

📁 java 作图的程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
package graph;import java.awt.*;import java.util.*;import java.lang.*;import java.io.StreamTokenizer;import java.io.InputStream;import java.io.IOException;import java.net.URL;import java.applet.Applet;/*******************************************************************************    Class  BuildGraph            ******************************************************************************    Copyright (C) 1996 Leigh Brookshaw****    This program is free software; you can redistribute it and/or modify**    it under the terms of the GNU General Public License as published by**    the Free Software Foundation; either version 2 of the License, or**    (at your option) any later version.****    This program is distributed in the hope that it will be useful,**    but WITHOUT ANY WARRANTY; without even the implied warranty of**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the**    GNU General Public License for more details.****    You should have received a copy of the GNU General Public License**    along with this program; if not, write to the Free Software**    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.******************************************************************************    This class will parse a description file and build the**    plot based on the instructions in the file***************************************************************************//** * This class will parse a description file and build a * plot based on the instructions in the file. * The build Graph class, with attached Axes and DataSets can be accessed * though methods in the class * * @version $Revision: 1.14 $, $Date: 1996/09/06 00:08:49 $ * @author Leigh Brookshaw */public class BuildGraph extends ScanWord {/*************************  Constants*********************//***   Specifiy the integer values associated with keywords. Every integer **   in this list is associated with keyword used in the input file*/     static final int BEGIN     = 256;     static final int GRAPH2D   = 257;     static final int MARKER    = 258;     static final int AXIS      = 259;     static final int URL       = 260;     static final int DATA      = 261;     static final int SIZE      = 262;     static final int COLOR     = 263;     static final int NAME      = 264;     static final int TITLE     = 265;     static final int LABEL     = 266;     static final int FONT      = 267;     static final int STYLE     = 268;     static final int BOTTOM    = 269;     static final int TOP       = 270;     static final int LEFT      = 271;     static final int RIGHT     = 272;     static final int END       = 273;     static final int G2DINT    = 274;     static final int OFF       = 275;     static final int ON        = 276;     static final int ATTACH    = 277;     static final int PLAIN     = 278;     static final int BOLD      = 279;     static final int ITALIC    = 280;     static final int DEBUG     = 281;     static final int GRID      = 282;     static final int ZERO      = 283;     static final int CONTOUR   = 284;     static final int LLEVELS   = 285;     static final int NUMBER    = 286;     static final int CDATA     = 287;     static final int FUNCTION  = 288;     static final int XRANGE    = 289;     static final int YRANGE    = 290;     static final int BACKGROUND = 291;     static final int LOGCONTOURS = 292;     static final int CLABELS    = 293;     static final int SQUARE     = 294;     /***    Specify Internal interger values. These constants are associated**    with objects nolonger in the context of the input file. But have**    been constructed by the program from a number of keyword commands.*/     static final int MARKER_STYLE  = 512;     static final int MARKER_COLOR  = 513;     static final int MARKER_SIZE   = 514;     static final int LABEL_COLOR   = 515;     static final int LABEL_FONT    = 517;     static final int GRID_COLOR    = 520;     static final int GRID_OFF      = 521;     static final int ZERO_COLOR    = 522;     static final int ZERO_OFF      = 523;     static final int MARKER_URL    = 524;     static final int GRID_ON       = 525;     static final int ZERO_ON       = 526;     static final int XMIN          = 527;     static final int XMAX          = 528;     static final int YMIN          = 529;     static final int YMAX          = 530;     static final int XNUMBER       = 531;     static final int YNUMBER       = 532;     static final int LABEL_OFF     = 533;  /**   * The BUILD stack. Everything pushed on this stack has to be    * built from other objects. An example would be a Font, which   * is constructed from Logical name, style and size.   */     protected Stack build = new Stack();  /**   *   The Object stack. All input tokens get pushed onto and    *    popped off this stack.   */     protected Stack object = new Stack();  /**   * The class vector. This contains final class objects that cannot be    * deleted. That is   * we don't want these classes unnattached and collected into the garbage.    * The obvious classes here are the main Graph2D class, the Axes of the plot   * DataSets etc.   */     protected Vector built = new Vector();  /**   * The constructed Graph Object    */     protected Object graph = null;  /**   *   The TextLine containing the title   */     protected TextLine graphtitle = null;  /**   *   The Calling Applet   */     protected Applet applet;  /**   * Debug. If true output copious debug messages. Though unless you know   * what is going on with the code most messages will probably be    * meaningless   */     protected boolean debug = false;       /*  ** This vector contains all the datasets as they are built.  ** the data sets in this lists are then searched so that they can  ** be attached to axis.  */     private Vector datasets = new Vector();/************************ Public Variables********************/  /**   * Current line being parsed   */     public int lineno = 1;  /**   * The current brace level. At the end of the input if all    * braces are matched the level should be back to zero.   */     public int level = 0;  /************************ Constructors*******************/  /**   * Instantiate the class   * @param in The inputstream to be read   * @param ap the driving applet.   */     public BuildGraph( InputStream in, Applet ap ) {        super(in);        applet = ap;/***   Specifiy The Key Words and associate them with the integer Values*/        addKeyWord("{",       BEGIN);        addKeyWord("}",       END);        addKeyWord("graph2d", GRAPH2D);        addKeyWord("g2dint",  G2DINT);        addKeyWord("marker",  MARKER);        addKeyWord("axis",    AXIS);        addKeyWord("url",     URL);        addKeyWord("data",    DATA);        addKeyWord("size",    SIZE);        addKeyWord("color",   COLOR);        addKeyWord("name",    NAME);        addKeyWord("title",   TITLE);        addKeyWord("label",   LABEL);        addKeyWord("font",    FONT);        addKeyWord("style",   STYLE);        addKeyWord("bottom",  BOTTOM);        addKeyWord("top",     TOP);        addKeyWord("left",    LEFT);        addKeyWord("right",   RIGHT);        addKeyWord("on",      ON);        addKeyWord("off",     OFF);        addKeyWord("attach",  ATTACH);        addKeyWord("plain",   PLAIN);        addKeyWord("bold",    BOLD);        addKeyWord("italic",  ITALIC);        addKeyWord("debug",   DEBUG);        addKeyWord("grid",    GRID);        addKeyWord("zero",    ZERO);        addKeyWord("contour", CONTOUR);        addKeyWord("number",  NUMBER);        addKeyWord("cdata",    CDATA);         addKeyWord("function", FUNCTION);        addKeyWord("xrange",   XRANGE);        addKeyWord("yrange",   YRANGE);        addKeyWord("background", BACKGROUND);        addKeyWord("llevels",   LLEVELS);        addKeyWord("square",    SQUARE);        addKeyWord("log",       LOGCONTOURS);             }/************************  Public Methods**********************/  /**   * Get the Graph object that has been built!   */         public Object   getGraph() {                                             return graph;                                      }  /**   * Get the title of the Graph   */         public TextLine getGraphTitle() {                                             return  graphtitle;                                      }  /**   *  Get a vector of all the built Classes.   *  Ie the DataSets, Axis, Graph etc.   *  This can be used by an applet to override anything specified in the   *       input file   */         public Vector   getBuilt()      { return built; }  /**   * This is THE method that parses the input file and constructs the plot.   */     public void parse() {          int token;          Object o;          NamedObject nobj;          boolean cont = true;          while( cont ) {/***           Grab a word from the stream and Do something with it!*/             token = nextWord();             debugMessage("Main",token);             switch (token) {/***                         Turn on the debug messages.*/             case DEBUG:                           debug = !debug;                           break;/***                         Instantiate the Graph class and push it onto**                         the object stack!*/             case CONTOUR:                           if(graph != null) {                              errorAtLine("Graph already defined.");                              return;                           }                           graph = new Contour();                           nobj = new NamedObject(graph, CONTOUR);                           object.push(nobj);                           break;             case G2DINT:                           if(graph != null) {                              errorAtLine("Graph already defined.");                              return;                           }                           graph = new G2Dint();                           nobj = new NamedObject(graph, G2DINT);                           object.push(nobj);                           break;             case GRAPH2D:                           if(graph != null) {                              errorAtLine("Graph already defined.");                              return;                           }                           graph = new Graph2D();                           nobj = new NamedObject(graph, GRAPH2D);                           object.push(nobj);                           break;/***                         End of the file. Exit the loop*/             case TT_EOF:                           cont = false;                           break;/***                         End of Line - Increment the line counter*/	         case TT_EOL:                           lineno++;                           if( lineno == (lineno/10)*10 ) {                            applet.showStatus("Reading input: Line "+lineno);			               }                           break;/***  LEFT, RIGHT, BOTTOM and TOP perform different tasks based on Context.**  Inside an AXIS group they position the axis and are standalone keywords**  Inside a GRAPH context they are followed by an integer and are the **  border widths in pixels.*/             case LEFT: case RIGHT: case TOP: case BOTTOM:                           if( isContext(AXIS) )  {                             nobj = new NamedObject(token);                           } else {                             int toke = nextWord();                             if( toke == TT_NUMBER ) {                                nobj = new NamedObject(                                       new Integer((int)(nval+0.01)), token);                             } else {                                 errorAtLine(                             "In this context LEFT, RIGHT, TOP or BOTTOM should be followed an integer");                                return;                             }                           }                                                      object.push(nobj);                           break;/***                         Build a URL object and push it onto the object stack**                         The URL keyword MUST be followed by a string*/             case URL:                           token = nextWord();                           if( token == STRING ) {                                try {                                      URL url = new URL(applet.getDocumentBase(),sval);                                      nobj = new NamedObject(url,URL);                                } catch(Exception e) {                                     errorAtLine("Failed to build URL!");                                     return;                                }                            } else {                                errorAtLine("URL should be followed by a string");                                return;                           }                           object.push(nobj);                           break;/***                         The ATTACH keyword is followed by the name of the**                         DataSet to be attached. Attach only appears**                         inside an AXIS group.*/             case ATTACH:	                       if( !isContext(AXIS) )  {	                       	   errorAtLine("ATTACH should only appear in AXIS context");	                       	   return;	                       }	                                                  token = nextWord();                           if( token == STRING ) {                                      nobj = new NamedObject(sval,ATTACH);                           } else {                                errorAtLine("ATTACH should be followed by a string");                                return;                           }                           object.push(nobj);                           break;/***                         Marker style, or font style depending on context

⌨️ 快捷键说明

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