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

📄 axis.java

📁 著名IT公司ILog的APS高级排产优化引擎
💻 JAVA
字号:
package com.power.util.graph2D;import java.awt.*;import java.util.*;import java.awt.geom.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: Paraster ,INC</p> * @author Huang Yu * @version 1.0 */public class axis {   /** *    Constant flagging Horizontal Axis */      static final int  HORIZONTAL = 0;/** *    Constant flagging Vertical Axis */      static final int  VERTICAL   = 1;/** *    define the color of the axis*/      private Color axisColor = null ;/** *    The number of label */      private int label_count = 0;/** *    The direction of the axis */      private int orientation = 0;/** *    The title of the axis */      private String axisTitle ;/** *    The length of the axis */      private double axisLength = 400 ;/** *    The original point the axis */      private Point2D original = null;  /************************ Constructors********************/ /**   *  Instantiate the class. The default type is a Horizontal axis   *  The default label_count is 10.   *  The default axistitle is 'X axis'   *  positioned at the bottom of the graph.   */      public  axis(){        this.axisColor = Color.black ;        this.label_count = 10 ;        this.orientation = HORIZONTAL ;        this.axisTitle = "X axis";      }  /**   * a constructor with param   * @param i integer  which indicates the type of axis is VERTICAL   */      public  axis(int i) {        this.orientation = VERTICAL ;        this.label_count =10 ;        this.axisColor = Color.black ;        this.axisTitle = "Y axis";      }  /**   * set the color of the axis   * @param color   */      public  void setAxisColor(Color color){        this.axisColor = color;      }      public Color getAxisColor(){        return this.axisColor ;      }/** * set the number of the label * @param i */      public void setLabelCount(int i){        this.label_count = i ;      }      public int getLabelCount(){        return this.label_count ;      }  /**   * set the title of the axis   * @param s   */      public void setAxisTitle(String s){        this.axisTitle = s;      }      public String getAxisTitle(){        return this.axisTitle ;      } /**  * set the length of the axis  * @param length  */      public void setAxisLength(double length){        this.axisLength = length ;      }      public double getAxisLength(){        return this.axisLength ;      }/** * set the original point of the axis * @param point  Point2D  type */      public void setOriginal(Point2D point){        this.original = point ;      }      public Point2D getOriginal(){        return this.original  ;      }/** *    draw the axis * @param g */      public void drawAxis(Graphics g){        Graphics2D g2=(Graphics2D)g ;        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);        Point2D endPoint;        g2.setColor(this.axisColor);        if(this.orientation==HORIZONTAL){          endPoint = new Point2D.Double(this.original.getX()+ this.axisLength , this.original .getY() );        }else{          endPoint = new Point2D.Double(this.original.getX() ,this.original.getY()- this.axisLength );       }        g2.draw(new Line2D.Double(this.original ,endPoint));        int i=1;        double sizeUnit = this.axisLength / this.label_count ;        while(i<=this.label_count ) {            if(this.orientation == HORIZONTAL){                 Line2D xLine = new Line2D.Double(original.getX()+sizeUnit*i ,original.getY(),original.getX()+sizeUnit*i ,original.getY()-5);                 g2.draw(xLine);            }            else{                   Line2D yLine = new Line2D.Double(original.getX(),original.getY()-sizeUnit*i,original.getX()+5,original.getY()-sizeUnit*i);                   g2.draw(yLine);            }              i++;          }        if(this.orientation == HORIZONTAL){            g2.drawString(this.axisTitle ,(float)(original.getX()+ this.axisLength/2), (float)(original.getY() + 20));        }        else{            g2.drawString(this.axisTitle ,(float)(original.getX()-30), (float)(original.getY() - this.axisLength-2));        }      }}

⌨️ 快捷键说明

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