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

📄 axis.java

📁 java 作图的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package graph;import java.awt.*;import java.applet.*;import java.util.Vector;import java.util.Enumeration;import java.lang.*;/*******************************************************************************    Class  Axis            ******************************************************************************    Copyright (C) 1995, 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 is designed to be used in conjunction with **    the Graph2D class and DataSet class for plotting 2D graphs.***************************************************************************//** * This class controls the look and feel of axes.  * It is designed to be used in conjunction with  * the Graph2D class and DataSet class for plotting 2D graphs. * * To work with the other classes a system of registration is used. * The axes have to be attached to the controlling Graph2D class * and the DataSet's have to be attached to both the Graph2D class * and the Axis class. * * This way the 3 main classes Graph2D, Axis and DataSet know of each * others existence. * * This does not mean the classes cannot be used independently, they can * but in this mode nothing is automated, the user must code everything * manually * * @version  $Revision: 1.12 $, $Date: 1996/09/12 03:27:07 $. * @author   Leigh Brookshaw */ public class Axis extends Object {    /****************************** Public Static Values     **************************//** *    Constant flagging Horizontal Axis */      static final int  HORIZONTAL = 0;/** *    Constant flagging Vertical Axis */      static final int  VERTICAL   = 1;/** *    Constant flagging Axis position on the graph.  *    Left side => Vertical */      public static final int  LEFT       = 2;/** *    Constant flagging Axis position on the graph.  *    Right side => Vertical */      public static final int  RIGHT      = 3;/** *    Constant flagging Axis position on the graph.  *    Top side => Horizontal */      public static final int  TOP        = 4;/** *    Constant flagging Axis position on the graph.  *    Bottom side => Horizontal */      public static final int  BOTTOM     = 5;/** *    The first guess on the number of Labeled Major tick marks. */      static final int  NUMBER_OF_TICS = 4;/************************** Public Variables      **********************/  /**   *    If <i>true</i> draw a grid positioned on major ticks over the graph   */      public boolean  drawgrid        = false;  /**   *    If <i>true</i> draw a line positioned on the Zero label tick mark.   */      public boolean  drawzero        = false;  /**   * Color of the grid   */      public Color   gridcolor        = null;  /**   * Color of the line at the Zero label   */      public Color   zerocolor        = null;  /**   * Default value <i>true</i>. Normally never changed. If set <i>false</I>   * the Axis draw method exits without drawing the axis.   * @see Axis#drawAxis()   */      public boolean redraw           = true;  /**   * Rescale the axis so that labels fall at the end of the Axis. Default   * value <i>false</i>.   */      public boolean force_end_labels = false;  /**   * Size in pixels of the major tick marks   */      public int     major_tic_size = 10;  /**   * Size in pixels of the minor tick marks   */      public int     minor_tic_size  = 5;  /**   * Number of minor tick marks between major tick marks   */      public int     minor_tic_count = 1;  /**   * Color of the Axis.   */      public Color   axiscolor;  /**   * Minimum data value of the axis. This is the value used to scale   * data into the data window. This is the value to alter to force   * a rescaling of the data window.   */      public double minimum;  /**   * Maximum data value of the axis. This is the value used to scale   * data into the data window. This is the value to alter to force   * a rescaling of the data window.   */      public double maximum;  /**   * Before the Axis can be positioned correctly and drawn the data window   * needs to be calculated and passed to the Axis.   */      public Dimension data_window = new Dimension(0,0);  /**   * The graph canvas this axis is attached to (if it is attached to any)   * @see graph.Graph2D   */      public Graph2D g2d = null;/************************** Protected Variables      **********************/  /**   * The position in pixels of the minimum point of the axis line   */      protected Point amin;  /**   * The position in pixels of the maximum point of the axis line   */      protected Point amax;  /**   * The orientation of the axis. Either Axis.HORIZONTAL or   * Axis.VERTICAL   */      protected int orientation;  /**   * The position of the axis. Either Axis.LEFT, Axis.RIGHT, Axis.TOP, or   * Axis.BOTTOM   */      protected int position;  /**   * The width of the Axis. Where width for a horizontal axis is really    * the height   */      protected int width = 0;  /**   * Textline class to contain the title of the axis.   */      protected RTextLine title    = new RTextLine();  /**   * Textline class to hold the labels before printing.   */      protected RTextLine label    = new RTextLine("0");  /**   * Textline class to hold the label's exponent (if it has one).   */      protected RTextLine exponent = new RTextLine();  /**   * The width of the maximum label. Used to position a Vertical Axis.   */      protected int max_label_width     = 0;  /**   * Vector containing a list of attached DataSets   */      protected Vector dataset = new Vector();  /**   * String to contain the labels.   */        protected String label_string[]     = null;  /**   * The actual values of the axis labels   */      protected float  label_value[]      = null;  /**   * The starting value of the labels   */      protected double label_start        = 0.0;  /**   * The increment between labels   */      protected double label_step         = 0.0;  /**   * The label exponent   */      protected int    label_exponent     = 0;  /**   * The number of labels required   */      protected int    label_count        = 0;  /**   * Initial guess for the number of labels required   */      protected int    guess_label_number = 4;  /**   * If true the axis range must be manually set by setting the   * Axis.minimum and Axis.maximum variables. The default is false.   * The default action is for the axis range to be calculated everytime   * a dataset is attached.   */     protected boolean manualRange = false;/************************ Constructors********************/  /**   *  Instantiate the class. The defalt type is a Horizontal axis   *  positioned at the bottom of the graph.   */      public Axis() {                 orientation = HORIZONTAL;                 position    = BOTTOM;      }             /**   * Instantiate the class. Setting the position.   * @param p Set the axis position. Must be one of Axis.BOTTOM,   * Axis.TOP, Axis.LEFT, Axis.RIGHT, Axis.HORIZONTAL or Axis.VERTICAL.   * If one of the latter two are used then Axis.BOTTOM or    * Axis.LEFT is assumed.   */      public Axis(int p) {           setPosition(p);           switch (position) {              case LEFT: case VERTICAL:                          title.setRotation(90);                          break;              case RIGHT:                          title.setRotation(-90);                          break;              default:                          title.setRotation(0);                          break;           }      }/********************** Public Methods******************/  /**   * Set the axis position.   * @param p Must be one of Axis.BOTTOM,   * Axis.TOP, Axis.LEFT, Axis.RIGHT, Axis.HORIZONTAL or Axis.VERTICAL.   * If one of the latter two are used then Axis.BOTTOM or    * Axis.LEFT is assumed.   */      public void setPosition(int p) {           position = p;           switch (position) {              case LEFT:                          orientation = VERTICAL;                          break;              case RIGHT:                          orientation = VERTICAL;                          break;              case TOP:                          orientation = HORIZONTAL;                          break;              case BOTTOM:                          orientation = HORIZONTAL;                          break;              case HORIZONTAL:                          orientation = HORIZONTAL;                          position    = BOTTOM;                          break;              case VERTICAL:                          orientation = VERTICAL;                          position    = LEFT;                          break;              default:                          orientation = HORIZONTAL;                          position    = BOTTOM;                          break;           }      }        /**   * Attach a DataSet for the Axis to manage.   * @param d dataSet to attach   * @see graph.DataSet   */      public void attachDataSet( DataSet d ) {            if( orientation == HORIZONTAL )   attachXdata( d );            else                              attachYdata( d );      }  /**   * Detach an attached DataSet   * @param d dataSet to detach   * @see graph.DataSet   */      public void detachDataSet( DataSet d ) {           int i = 0;           if( d == null ) return;           if( orientation == HORIZONTAL ) {               d.xaxis = null;           } else {               d.yaxis = null;           }           dataset.removeElement(d);           if(!manualRange) resetRange();      }  /**

⌨️ 快捷键说明

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